/** Tests the Registration of an Event Hanlder in the event broker of the eclpse context. */ @Test public void testEventBrokerEventHanlderRegistration() { TestProtocolService protocolService = new TestProtocolService(); IEclipseContext context = EclipseContextFactory.create(); final Map<String, EventHandler> topics = new HashMap<String, EventHandler>(); context.set( IEventBroker.class, new IEventBroker() { @Override public boolean send(String topic, Object data) { return false; } @Override public boolean post(String topic, Object data) { return false; } @Override public boolean subscribe(String topic, EventHandler eventHandler) { topics.put(topic, eventHandler); return true; } @Override public boolean subscribe( String topic, String filter, EventHandler eventHandler, boolean headless) { return false; } @Override public boolean unsubscribe(EventHandler eventHandler) { return false; } }); protocolService.compute(context, null); EventHandler handler = topics.get(TestEditorCoreEventConstants.TESTSTRUCTURE_MODEL_CHANGED_DELETED); assertNotNull("Hanlder should be registered", handler); TestCase testCase = new TestCase(); testCase.setName("TestCase1"); protocolService.set(testCase, new TestResult()); assertNotNull(protocolService.get(testCase)); Map<String, String> properties = new HashMap<String, String>(); properties.put("org.eclipse.e4.data", testCase.getFullName()); Event event = new Event(TestEditorCoreEventConstants.TESTSTRUCTURE_MODEL_CHANGED_DELETED, properties); handler.handleEvent(event); assertNull(protocolService.get(testCase)); }
/** Test Protocol on execute a TestSuite that has Children. */ @Test public void testRunSuiteWithChildren() { TestProtocolService protocolService = new TestProtocolService(); TestCase testCase = new TestCase(); testCase.setName("MyName"); TestSuite testSuite = new TestSuite(); testSuite.addChild(testCase); TestResult testResult = new TestResult(); TestResult tcTestResult = new TestResult(); tcTestResult.setFullName(testCase.getFullName()); testResult.add(tcTestResult); assertTrue(testResult.isSuite()); protocolService.set(testSuite, testResult); assertNotNull(protocolService.get(testSuite)); assertNotNull(protocolService.get(testCase)); }
/** * Test delete of elements with fullqualified name and removing child elements on removing their * parent. */ @Test public void testDeleteEventHandlerOnFullNameAndParentName() { TestProtocolService protocolService = new TestProtocolService(); TestProject tp = new TestProject(); tp.setName("TP"); TestCase tc = new TestCase(); tp.addChild(tc); protocolService.set(tc, new TestResult()); assertNotNull(protocolService.get(tc)); Map<String, String> properties = new HashMap<String, String>(); properties.put("org.eclipse.e4.data", tc.getFullName()); Event event = new Event(TestEditorCoreEventConstants.TESTSTRUCTURE_MODEL_CHANGED_DELETED, properties); protocolService.getDeletedTestStructureEventHandler().handleEvent(event); assertNull(protocolService.get(tc)); protocolService.set(tc, new TestResult()); assertNotNull(protocolService.get(tc)); properties.put("org.eclipse.e4.data", tp.getFullName()); event = new Event(TestEditorCoreEventConstants.TESTSTRUCTURE_MODEL_CHANGED_DELETED, properties); protocolService.getDeletedTestStructureEventHandler().handleEvent(event); assertNull("Deleting project also deletes child testcase.", protocolService.get(tc)); }