import traceback

class Application:
	"""
	Demo for bug-injection.
	Use  application-integration.py to build osgi jar
	that is also capable of bug-injection.
	"""
	def main(self, argv):
		try:
			test_injection.main(True)
		except StateException, ex:
			print ex.message
			if not TRANSLATED: traceback.print_exc()
		except ServerStateException, ex:
			print ex.message
			if not TRANSLATED: traceback.print_exc()
		
		
		try:
			test_injection.main(False)
		except StateException, ex:
			print ex.message
			if not TRANSLATED: traceback.print_exc()
		except ServerStateException, ex:
			print ex.message
			if not TRANSLATED: traceback.print_exc()
		
		print "Injection Done."	
		return 0
	def main(self, argv):
		try:
			test_injection.main(True)
		except StateException, ex:
			print ex.message
			if not TRANSLATED: traceback.print_exc()
		try:
			print "=Simple integration"
			test_integration.main()
		except StateException, ex:
			print ex.message
			if not TRANSLATED: traceback.print_exc()
		except ServerStateException, ex:
			print ex.message
			if not TRANSLATED: traceback.print_exc()
		
		print "=Wiring..."
		print test_integration.wiring()
		
		print "=Injected bug..."
		try:
			test_injection.main(True)
		except StateException, ex:
			print "Expected exception, Ok."
		
		try:
			test_injection.main(False) #suppress aggresive optimization
		except StateException, ex:
			print "Expected exception, Ok."
		
		print "=Random part..."
		try:
			test_random.main()
		except StateException, ex:
			print "Exception is randomly possible"