public void doTestCreateModelElement() throws Exception { ActionTestGenerics test = new ActionTestGenerics(); test.setUp(); modelRoot = BaseTest.getDefaultTestInstance(); Ooaofooa.getDefaultInstance().addModelChangeListener(instantListener); Ooaofooa.getDefaultInstance().addModelChangeListener(batchedListener); Ooaofgraphics c = Ooaofgraphics.getInstance(modelRoot.getId()); c.addModelChangeListener(instantListener); c.addModelChangeListener(batchedListener); try { // Test add Instance State Machine // Must turn off ConsistencyTransactionListener - the test will check the // consistency of the relevant individual components Ooaofooa.setConsistencyEnabled(false); test.testNewO_OBJInstanceStateMachine(); // Turn consistency checking back on. Ooaofooa.setConsistencyEnabled(true); Display d = Display.getDefault(); while (d.readAndDispatch()) {} } catch (Exception e) { fail("Test creation of model Element Failed: " + e.toString()); // $NON-NLS-1$ } // Comparing Events assertTrue( "No events heard by instant listener", instantListener.eventsList.size() > 0); // $NON-NLS-1$ assertTrue( "No events heard by batched listener", batchedListener.eventsList.size() > 0); // $NON-NLS-1$ // the number of events will be different by one // this is due to the fact that deltas that affect // the same element's name are not collected only the // first delta found is updated. This test collects // events that were fired, in the case of an instant // listener the update needs to be fired, for a batched // listener it does not. assertEquals( "Number of Events in the instant Listener: " + instantListener.eventsList.size() + " is not same as in batched listener: " + batchedListener.eventsList.size(), instantListener.eventsList.size() - 1, batchedListener.eventsList.size()); // $NON-NLS-1$//$NON-NLS-2$ // the events should be in a different order, the instant listener updates Model_c.OOA_ID // at a different time that the batch listener assertFalse( "Batched events are in same order as instance events", instantListener.eventsList.equals(batchedListener.eventsList)); // $NON-NLS-1$//$NON-NLS-2$ Ooaofooa.getDefaultInstance().removeModelChangeListener(instantListener); Ooaofooa.getDefaultInstance().removeModelChangeListener(batchedListener); }
public void doTestDeleteModelElement() throws Exception { BaseTest.dispatchEvents(0); ActionTestGenerics delAction = new ActionTestGenerics(); delAction.setUp(); modelRoot = BaseTest.getDefaultTestInstance(); Ooaofooa.getDefaultInstance().addModelChangeListener(instantListener); Ooaofooa.getDefaultInstance().addModelChangeListener(batchedListener); Ooaofgraphics c = Ooaofgraphics.getInstance(modelRoot.getId()); c.addModelChangeListener(instantListener); c.addModelChangeListener(batchedListener); try { delAction.testDeleteEP_PKG(); BaseTest.dispatchEvents(0); } catch (Exception e) { fail("Test deletion of model Element Failed: " + e.toString()); // $NON-NLS-1$ } // Comparing Events assertTrue( "No events heard by instant listener", instantListener.eventsList.size() > 0); // $NON-NLS-1$ assertTrue( "No events heard by batched listener", batchedListener.eventsList.size() > 0); // $NON-NLS-1$ // the number of events will be different by one // this is due to the fact that deltas that affect // the same element's name are not collected only the // first delta found is updated. This test collects // events that were fired, in the case of an instant // listener the update needs to be fired, for a batched // listener it does not. assertEquals( "Number of Events in the instant Listener: " + instantListener.eventsList.size() // $NON-NLS-1$ + " is not same as in batched listener: " + batchedListener.eventsList.size(), // $NON-NLS-1$ instantListener.eventsList.size(), batchedListener.eventsList.size() + 1); Ooaofooa.getDefaultInstance().removeModelChangeListener(instantListener); Ooaofooa.getDefaultInstance().removeModelChangeListener(batchedListener); }