public void testWithModelElementList() { final TestModelRoot root = TestModelRoot.TYPE.instantiate(); final ModelElementList<TestModelElementA> list = root.getList1(); final FunctionContext context = new ModelElementFunctionContext(root); TestModelElementA a; testForExpectedValue(context, "${ Avg( List1 ) }", new BigDecimal("0")); testForExpectedValue(context, "${ Avg( List1, 'Value1' ) }", new BigDecimal("0")); testForExpectedValue(context, "${ Avg( List1, 'Value2' ) }", new BigDecimal("0")); a = list.insert(); a.setValue1("1"); a.setValue2(2); testForExpectedValue(context, "${ Avg( List1 ) }", new BigDecimal("1")); testForExpectedValue(context, "${ Avg( List1, 'Value1' ) }", new BigDecimal("1")); testForExpectedValue(context, "${ Avg( List1, 'Value2' ) }", new BigDecimal("2")); a = list.insert(); a.setValue1("2"); a.setValue2(3); a = list.insert(); a.setValue1("3.5"); a.setValue2(4); testForExpectedValue(context, "${ Avg( List1 ) }", new BigDecimal("2.2")); testForExpectedValue(context, "${ Avg( List1, 'Value1' ) }", new BigDecimal("2.2")); testForExpectedValue(context, "${ Avg( List1, 'Value2' ) }", new BigDecimal("3")); testForExpectedError( context, "${ Avg( List1, 'abc' ) }", "Property TestModelElementA.abc could not be found."); testForExpectedError( context, "${ Avg( List1, 'Element1' ) }", "Property TestModelElementA.Element1 is not a value property."); testForExpectedError( context, "${ Avg( List2 ) }", "Element type TestModelElementB does not contain a value property."); final FunctionResult result = ExpressionLanguageParser.parse("${ Avg( List1, 'Value1' ) }").evaluate(context); assertEquals(new BigDecimal("2.2"), result.value()); list.get(0).setValue1("2"); list.get(1).setValue1("3.5"); assertEquals(new BigDecimal("3.0"), result.value()); a = list.insert(); a.setValue1("5.2"); assertEquals(new BigDecimal("3.6"), result.value()); }
public void test() throws Exception { final ByteArrayResourceStore byteArrayResourceStore = new ByteArrayResourceStore(loadResourceAsStream("initial.txt")); final XmlResourceStore xmlResourceStore = new XmlResourceStore(byteArrayResourceStore); final TestModelRoot root = TestModelRoot.TYPE.instantiate(new RootXmlResource(xmlResourceStore)); root.initialize(); root.resource().save(); assertEqualsIgnoreNewLineDiffs( loadResource("result.txt"), new String(byteArrayResourceStore.getContents(), UTF8)); }
@Test public void test() throws Exception { final ByteArrayResourceStore byteArrayResourceStore = new ByteArrayResourceStore(); final XmlResourceStore xmlResourceStore = new XmlResourceStore(byteArrayResourceStore); final TestModelRoot root = TestModelRoot.TYPE.instantiate(new RootXmlResource(xmlResourceStore)); final TestModelChild child = root.getChild(); child.setAaa("111"); child.setBbb("222"); child.setCcc("333"); root.resource().save(); assertEqualsIgnoreNewLineDiffs( loadResource("checkpoint-1.txt"), new String(byteArrayResourceStore.getContents(), UTF8)); child.setAaa(null); root.resource().save(); assertEqualsIgnoreNewLineDiffs( loadResource("checkpoint-2.txt"), new String(byteArrayResourceStore.getContents(), UTF8)); child.setBbb(null); root.resource().save(); assertEqualsIgnoreNewLineDiffs( loadResource("checkpoint-3.txt"), new String(byteArrayResourceStore.getContents(), UTF8)); child.setCcc(null); root.resource().save(); assertEqualsIgnoreNewLineDiffs( loadResource("checkpoint-4.txt"), new String(byteArrayResourceStore.getContents(), UTF8)); }