/** * Test of getSelectedComponents method, of class * org.netbeans.modules.vmd.api.model.DesignDocument. */ public void testGetSetSelectedComponents() { System.out.println( "getSetSelectedComponents, setSelectedComponents, getSelectionSourceID"); // NOI18N document .getTransactionManager() .writeAccess( new Runnable() { public void run() { String sourceID = "TestSorceId"; // NOI18N DesignComponent comp1 = document.createComponent(FirstCD.TYPEID_CLASS); DesignComponent comp2 = document.createComponent(SecondCD.TYPEID_CLASS); Collection<DesignComponent> selectedComponents = new HashSet<DesignComponent>(); selectedComponents.add(comp1); selectedComponents.add(comp2); document.setSelectedComponents(sourceID, selectedComponents); // NOI18N for (DesignComponent comp : selectedComponents) { boolean result = document.getSelectedComponents().contains(comp); assertTrue(result); } String result = document.getSelectionSourceID(); String expResult = sourceID; assertEquals(expResult, result); } }); }
/** * Test of getTransactionManager method, of class * org.netbeans.modules.vmd.api.model.DesignDocument. */ public void testGetTransactionManager() { System.out.println("getTransactionManager"); // NOI18N1 final long compID = 0; TransactionManager result = document.getTransactionManager(); assertNotNull(result); result.writeAccess( new Runnable() { public void run() { document.createComponent(FirstCD.TYPEID_CLASS); } }); result.readAccess( new Runnable() { public void run() { document.getComponentByUID(compID); } }); }
/** * Test of getDeleteComponent method, of class org.netbeans.modules.vmd.api.model.DesignDocument. */ @SuppressWarnings("deprecation") // NOI18N public void testDeleteComponent() { // TODO Right now there is no way to tested if document is deleted or not. This test only check // if there is any exception rise when component is deleted System.out.println("deleteComponent"); // NOI18N document .getTransactionManager() .writeAccess( new Runnable() { public void run() { // createComponent DesignComponent comp = document.createComponent(FirstCD.TYPEID_CLASS); DesignComponent comp2 = document.createComponent(SecondCD.TYPEID_CLASS); document.setRootComponent(comp); comp.addComponent(comp2); document.deleteComponent(comp2); } }); }
/** * Complex test (addDocument, addComponent, getRootComponent, setRootComponent, createComponent, * of class org.netbeans.modules.vmd.api.model.DesignDocument. */ public void testComplex() { System.out.println( "addDocument, addComponent, getRootComponent, setRootComponent," + // NOI18N " createComponent,getComponentByID" + "getComponentByID"); // NOI18N final DesignDocument instance = ModelTestUtil.createTestDesignDocument(ModelTestUtil.PROJECT_ID); instance .getTransactionManager() .writeAccess( new Runnable() { public void run() { DesignComponent comp1 = instance.createComponent(FirstCD.TYPEID_CLASS); DesignComponent comp2 = instance.createComponent(SecondCD.TYPEID_CLASS); // setRooComponent, addComponent instance.setRootComponent(comp1); comp1.addComponent(comp2); // getComponentByID DesignComponent resultComp2ByID = instance.getComponentByUID(comp2.getComponentID()); DesignComponent expComp2 = comp2; assertEquals(expComp2, resultComp2ByID); // setRootComponent getRootComponent DesignComponent expGetComp = comp1; DesignComponent resultGetComp = instance.getRootComponent(); assertEquals(expGetComp, resultGetComp); // writeProperty to Component comp1.writeProperty( FirstCD.PROPERTY_REFERENCE, PropertyValue.createComponentReference(comp2)); } }); }