001: /*
002: * WLMModelCommonTest.java
003: * JUnit based test
004: *
005: * Created on May 31, 2007, 3:10 PM
006: */
007:
008: package org.netbeans.modules.iep.model.common;
009:
010: import java.io.InputStream;
011: import java.net.URI;
012: import java.util.Iterator;
013: import java.util.List;
014:
015: import junit.framework.TestCase;
016: import org.netbeans.modules.iep.model.Component;
017: import org.netbeans.modules.iep.model.IEPComponent;
018: import org.netbeans.modules.iep.model.IEPComponentFactory;
019: import org.netbeans.modules.iep.model.IEPModel;
020: import org.netbeans.modules.iep.model.Property;
021: import org.netbeans.modules.iep.model.impl.IEPComponentFactoryImpl;
022: import org.netbeans.modules.iep.model.util.XmlUtil;
023:
024: import org.netbeans.modules.xml.wsdl.model.Operation;
025: import org.netbeans.modules.xml.wsdl.model.WSDLModel;
026: import org.netbeans.modules.xml.xam.dom.AbstractDocumentModel;
027: import org.w3c.dom.Element;
028: import org.xml.sax.InputSource;
029:
030: /**
031: *
032: *
033: */
034: public class IEPModelCommonTest extends TestCase {
035:
036: public IEPModelCommonTest(String testName) {
037: super (testName);
038: }
039:
040: protected void setUp() throws Exception {
041: super .setUp();
042: }
043:
044: protected void tearDown() throws Exception {
045:
046: }
047:
048: public void testModification() throws Exception {
049: URI wfFile = getClass().getResource("data/test.iep").toURI();
050: InputStream is = getClass()
051: .getResourceAsStream("data/test.iep");
052: IEPModelProvider provider = new IEPModelProviderInsideIde();
053: IEPModel model = provider.getWLMModel(wfFile);
054:
055: IEPComponentFactory factory = new IEPComponentFactoryImpl(model);
056:
057: Component component = factory.createComponent(model);
058: component.setName("test");
059: component.setTitle("test");
060: component.setType("/IEP/Model/Plan|Metadata");
061: Property p1 = factory.createProperty(model);
062: p1.setName("p1");
063: p1.setValue("v1");
064: component.addProperty(p1);
065:
066: Property p2 = factory.createProperty(model);
067: p2.setName("p1");
068: p2.setValue("v1");
069: component.addProperty(p2);
070:
071: model.startTransaction();
072: model.getPlanComponent().addChildComponent(component);
073: model.endTransaction();
074:
075: //assert child components on the root component
076: assertEquals(5, model.getPlanComponent().getChildComponents()
077: .size());
078:
079: Component c = model.getPlanComponent().getChildComponents()
080: .get(4);
081: assertEquals(component, c);
082:
083: }
084:
085: public void testCreateModel() throws Exception {
086: URI wfFile = getClass().getResource("data/test.iep").toURI();
087: InputStream is = getClass()
088: .getResourceAsStream("data/test.iep");
089: InputSource source = new InputSource(is);
090: Element rootEl = XmlUtil.createDocument(true, source)
091: .getDocumentElement();
092: IEPModelProvider provider = new IEPModelProviderInsideIde();
093: IEPModel model = provider.getWLMModel(wfFile);
094: model.sync();
095: assertNotNull(model);
096: IEPComponent root = ((AbstractDocumentModel<IEPComponent>) model)
097: .createRootComponent(rootEl);
098:
099: //assert properites on the root component
100: assertEquals(1, model.getPlanComponent().getProperties().size());
101:
102: //assert child components on the root component
103: assertEquals(4, model.getPlanComponent().getChildComponents()
104: .size());
105:
106: List<Component> childComponents = model.getPlanComponent()
107: .getChildComponents();
108:
109: Component metadataComponent = childComponents.get(0);
110: assertEquals("Metadata", metadataComponent.getName());
111: assertEquals("Metadata", metadataComponent.getTitle());
112: assertEquals("/IEP/Model/Plan|Metadata", metadataComponent
113: .getType());
114:
115: List<Component> metadataComponentChildren = metadataComponent
116: .getChildComponents();
117: assertEquals(1, metadataComponentChildren.size());
118:
119: Component viewComponent = metadataComponentChildren.get(0);
120: assertEquals("View", viewComponent.getName());
121: assertEquals("View", viewComponent.getTitle());
122: assertEquals("/IEP/Model/Plan|Metadata|View", viewComponent
123: .getType());
124:
125: List<Property> viewComponentProperties = viewComponent
126: .getProperties();
127: assertEquals(1, viewComponentProperties.size());
128:
129: Property property1_1 = viewComponentProperties.get(0);
130: assertEquals("orthoflow", property1_1.getName());
131: assertEquals("true", property1_1.getValue());
132:
133: Component schemaComponent = childComponents.get(1);
134: assertEquals("Schemas", schemaComponent.getName());
135: assertEquals("Schemas", schemaComponent.getTitle());
136: assertEquals("/IEP/Model/Plan|Schemas", schemaComponent
137: .getType());
138: List<Component> schemaComponentChildren = schemaComponent
139: .getChildComponents();
140: assertEquals(0, schemaComponentChildren.size());
141:
142: Component componentOperators = childComponents.get(2);
143: assertEquals("Operators", componentOperators.getName());
144: assertEquals("Operators", componentOperators.getTitle());
145: assertEquals("/IEP/Model/Plan|Operators", componentOperators
146: .getType());
147:
148: List<Component> operatorComponentChildren = componentOperators
149: .getChildComponents();
150: assertEquals(16, operatorComponentChildren.size());
151:
152: Component componentRelationAggregatorOperator = operatorComponentChildren
153: .get(0);
154: assertEquals("o0", componentRelationAggregatorOperator
155: .getName());
156: assertEquals("o0", componentRelationAggregatorOperator
157: .getTitle());
158: assertEquals("/IEP/Operator/RelationAggregator",
159: componentRelationAggregatorOperator.getType());
160:
161: //RelationAggregator Operator properites
162: List<Property> relationAggregatorComponentProperties = componentRelationAggregatorOperator
163: .getProperties();
164:
165: //1
166: Property relationAggregatorComponentProperty1 = relationAggregatorComponentProperties
167: .get(0);
168: assertEquals("x", relationAggregatorComponentProperty1
169: .getName());
170: assertEquals("285", relationAggregatorComponentProperty1
171: .getValue());
172:
173: //2
174: Property relationAggregatorComponentProperty2 = relationAggregatorComponentProperties
175: .get(1);
176: assertEquals("y", relationAggregatorComponentProperty2
177: .getName());
178: assertEquals("46", relationAggregatorComponentProperty2
179: .getValue());
180:
181: //3
182: Property relationAggregatorComponentProperty3 = relationAggregatorComponentProperties
183: .get(2);
184: assertEquals("z", relationAggregatorComponentProperty3
185: .getName());
186: assertEquals("0", relationAggregatorComponentProperty3
187: .getValue());
188:
189: //4
190: Property relationAggregatorComponentProperty4 = relationAggregatorComponentProperties
191: .get(3);
192: assertEquals("id", relationAggregatorComponentProperty4
193: .getName());
194: assertEquals("o0", relationAggregatorComponentProperty4
195: .getValue());
196:
197: //5
198: Property relationAggregatorComponentProperty5 = relationAggregatorComponentProperties
199: .get(4);
200: assertEquals("name", relationAggregatorComponentProperty5
201: .getName());
202: assertEquals("RelationAggregator0",
203: relationAggregatorComponentProperty5.getValue());
204:
205: //6
206: Property relationAggregatorComponentProperty6 = relationAggregatorComponentProperties
207: .get(5);
208: assertEquals("inputSchemaIdList",
209: relationAggregatorComponentProperty6.getName());
210: assertEquals("", relationAggregatorComponentProperty6
211: .getValue());
212:
213: //7
214: Property relationAggregatorComponentProperty7 = relationAggregatorComponentProperties
215: .get(6);
216: assertEquals("outputSchemaId",
217: relationAggregatorComponentProperty7.getName());
218: assertEquals("", relationAggregatorComponentProperty7
219: .getValue());
220:
221: //8
222: Property relationAggregatorComponentProperty8 = relationAggregatorComponentProperties
223: .get(7);
224: assertEquals("description",
225: relationAggregatorComponentProperty8.getName());
226: assertEquals("", relationAggregatorComponentProperty8
227: .getValue());
228:
229: //9
230: Property relationAggregatorComponentProperty9 = relationAggregatorComponentProperties
231: .get(8);
232: assertEquals("topoScore", relationAggregatorComponentProperty9
233: .getName());
234: assertEquals("2", relationAggregatorComponentProperty9
235: .getValue());
236:
237: //10
238: Property relationAggregatorComponentProperty10 = relationAggregatorComponentProperties
239: .get(9);
240: assertEquals("inputType", relationAggregatorComponentProperty10
241: .getName());
242: assertEquals("i18n.IEP.IOType.relation",
243: relationAggregatorComponentProperty10.getValue());
244:
245: //11
246: Property relationAggregatorComponentProperty11 = relationAggregatorComponentProperties
247: .get(10);
248: assertEquals("inputIdList",
249: relationAggregatorComponentProperty11.getName());
250: assertEquals("o3", relationAggregatorComponentProperty11
251: .getValue());
252:
253: //12
254: Property relationAggregatorComponentProperty12 = relationAggregatorComponentProperties
255: .get(11);
256: assertEquals("staticInputIdList",
257: relationAggregatorComponentProperty12.getName());
258: assertEquals("", relationAggregatorComponentProperty12
259: .getValue());
260:
261: //13
262: Property relationAggregatorComponentProperty13 = relationAggregatorComponentProperties
263: .get(12);
264: assertEquals("outputType",
265: relationAggregatorComponentProperty13.getName());
266: assertEquals("i18n.IEP.IOType.relation",
267: relationAggregatorComponentProperty13.getValue());
268:
269: //14
270: Property relationAggregatorComponentProperty14 = relationAggregatorComponentProperties
271: .get(13);
272: assertEquals("isGlobal", relationAggregatorComponentProperty14
273: .getName());
274: assertEquals("false", relationAggregatorComponentProperty14
275: .getValue());
276:
277: //15
278: Property relationAggregatorComponentProperty15 = relationAggregatorComponentProperties
279: .get(14);
280: assertEquals("globalId", relationAggregatorComponentProperty15
281: .getName());
282: assertEquals("", relationAggregatorComponentProperty15
283: .getValue());
284:
285: //16
286: Property relationAggregatorComponentProperty16 = relationAggregatorComponentProperties
287: .get(15);
288: assertEquals("batchMode", relationAggregatorComponentProperty16
289: .getName());
290: assertEquals("false", relationAggregatorComponentProperty16
291: .getValue());
292:
293: //17
294: Property relationAggregatorComponentProperty17 = relationAggregatorComponentProperties
295: .get(16);
296: assertEquals("fromColumnList",
297: relationAggregatorComponentProperty17.getName());
298: assertEquals("", relationAggregatorComponentProperty17
299: .getValue());
300:
301: //18
302: Property relationAggregatorComponentProperty18 = relationAggregatorComponentProperties
303: .get(17);
304: assertEquals("toColumnList",
305: relationAggregatorComponentProperty18.getName());
306: assertEquals("", relationAggregatorComponentProperty18
307: .getValue());
308:
309: //19
310: Property relationAggregatorComponentProperty19 = relationAggregatorComponentProperties
311: .get(18);
312: assertEquals("groupByColumnList",
313: relationAggregatorComponentProperty19.getName());
314: assertEquals("", relationAggregatorComponentProperty19
315: .getValue());
316:
317: //20
318: Property relationAggregatorComponentProperty20 = relationAggregatorComponentProperties
319: .get(19);
320: assertEquals("whereClause",
321: relationAggregatorComponentProperty20.getName());
322: assertEquals("", relationAggregatorComponentProperty20
323: .getValue());
324:
325: //links
326:
327: Component linksComponent = childComponents.get(3);
328: assertEquals("Links", linksComponent.getName());
329: assertEquals("Links", linksComponent.getTitle());
330: assertEquals("/IEP/Model/Plan|Links", linksComponent.getType());
331:
332: List<Component> linksComponentChildren = linksComponent
333: .getChildComponents();
334: assertEquals(6, linksComponentChildren.size());
335:
336: Component linksComponentLink0 = linksComponentChildren.get(0);
337: assertEquals("link0", linksComponentLink0.getName());
338: assertEquals("link0", linksComponentLink0.getTitle());
339: assertEquals("/IEP/Model/Link", linksComponentLink0.getType());
340:
341: //link0 properites
342: List<Property> linksComponentLink0Properties = linksComponentLink0
343: .getProperties();
344:
345: //1
346: Property linksComponentLink0Property1 = linksComponentLink0Properties
347: .get(0);
348: assertEquals("name", linksComponentLink0Property1.getName());
349: assertEquals("link0", linksComponentLink0Property1.getValue());
350:
351: //2
352: Property linksComponentLink0Property2 = linksComponentLink0Properties
353: .get(1);
354: assertEquals("from", linksComponentLink0Property2.getName());
355: assertEquals("o1", linksComponentLink0Property2.getValue());
356:
357: //3
358: Property linksComponentLink0Property3 = linksComponentLink0Properties
359: .get(2);
360: assertEquals("to", linksComponentLink0Property3.getName());
361: assertEquals("o3", linksComponentLink0Property3.getValue());
362:
363: }
364:
365: }
|