Search in sources :

Example 6 with ExmlToModelParser

use of net.jangaroo.exml.parser.ExmlToModelParser in project jangaroo-tools by CoreMedia.

the class ExmlToModelParserTest method testParseTestTrueFalse.

@Test
public void testParseTestTrueFalse() throws Exception {
    setUp("exmlparser.config");
    ExmlToModelParser exmlToModelParser = new ExmlToModelParser(getConfigClassRegistry());
    ExmlModel model = exmlToModelParser.parse(getFile("/exmlparser/TestTrueFalse.exml"));
    Assert.assertEquals("ext.Panel", model.getSuperClassName());
    JsonObject expectedJsonObject = new JsonObject("items", new JsonArray(new JsonObject("xtype", "panel", "id", "foo", "visible", true), new JsonObject("xtype", "panel", "id", "foo", "visible", false), new JsonObject("xtype", "panel", "id", "foo", "visible", true), new JsonObject("xtype", "panel", "id", "foo", "visible", false)));
    System.out.println(model.getJsonObject().toString(2));
    Assert.assertEquals(expectedJsonObject.toString(2), model.getJsonObject().toString(2));
}
Also used : JsonArray(net.jangaroo.exml.json.JsonArray) ExmlModel(net.jangaroo.exml.model.ExmlModel) JsonObject(net.jangaroo.exml.json.JsonObject) ExmlToModelParser(net.jangaroo.exml.parser.ExmlToModelParser) Test(org.junit.Test)

Example 7 with ExmlToModelParser

use of net.jangaroo.exml.parser.ExmlToModelParser in project jangaroo-tools by CoreMedia.

the class ExmlToModelParserTest method testParseArrayAttribute.

@Test
public void testParseArrayAttribute() throws Exception {
    setUp("exmlparser.config");
    ExmlToModelParser exmlToModelParser = new ExmlToModelParser(getConfigClassRegistry());
    ExmlModel model = exmlToModelParser.parse(getFile("/exmlparser/TestArrayAttribute.exml"));
    Assert.assertEquals("ext.Panel", model.getSuperClassName());
    JsonObject expectedJsonObject = new JsonObject("items", JsonObject.code("config.myItems"), "tools", new JsonArray("tools"));
    System.out.println(model.getJsonObject().toString(2));
    Assert.assertEquals(expectedJsonObject.toString(2), model.getJsonObject().toString(2));
}
Also used : JsonArray(net.jangaroo.exml.json.JsonArray) ExmlModel(net.jangaroo.exml.model.ExmlModel) JsonObject(net.jangaroo.exml.json.JsonObject) ExmlToModelParser(net.jangaroo.exml.parser.ExmlToModelParser) Test(org.junit.Test)

Example 8 with ExmlToModelParser

use of net.jangaroo.exml.parser.ExmlToModelParser in project jangaroo-tools by CoreMedia.

the class ExmlToModelParserTest method testBaseClass.

@Test
public void testBaseClass() throws Exception {
    setUp("exmlparser.config");
    ExmlToModelParser exmlToModelParser = new ExmlToModelParser(getConfigClassRegistry());
    ExmlModel model = exmlToModelParser.parse(getFile("/exmlparser/TestBaseClassUnqualified.exml"));
    Assert.assertEquals("BaseClass", model.getSuperClassName());
    model = exmlToModelParser.parse(getFile("/exmlparser/TestBaseClass.exml"));
    Assert.assertEquals("someOtherPackage.base.BaseClass", model.getSuperClassName());
}
Also used : ExmlModel(net.jangaroo.exml.model.ExmlModel) ExmlToModelParser(net.jangaroo.exml.parser.ExmlToModelParser) Test(org.junit.Test)

Example 9 with ExmlToModelParser

use of net.jangaroo.exml.parser.ExmlToModelParser in project jangaroo-tools by CoreMedia.

the class ExmlToModelParserTest method testConstants.

@Test
public void testConstants() throws Exception {
    setUp("exmlparser.config");
    ExmlToModelParser exmlToModelParser = new ExmlToModelParser(getConfigClassRegistry());
    ExmlModel model = exmlToModelParser.parse(getFile("/exmlparser/TestConstants.exml"));
    Declaration aConstant = model.getConfigClass().getConstants().get(0);
    Assert.assertEquals("A_CONSTANT", aConstant.getName());
    Assert.assertEquals("\"One two three\"", aConstant.getValue());
    Assert.assertEquals("String", aConstant.getType());
    Assert.assertEquals("This is some constant", aConstant.getDescription().trim());
    Declaration bConstant = model.getConfigClass().getConstants().get(1);
    Assert.assertEquals("B_CONSTANT", bConstant.getName());
    Assert.assertEquals("456", bConstant.getValue());
    Assert.assertEquals("uint", bConstant.getType());
    Assert.assertNull(bConstant.getDescription());
    Declaration cConstant = model.getConfigClass().getConstants().get(2);
    Assert.assertEquals("C_CONSTANT", cConstant.getName());
    Assert.assertEquals("new Object()", cConstant.getValue());
    Assert.assertEquals("Object", cConstant.getType());
    Assert.assertNull(cConstant.getDescription());
    Declaration dConstant = model.getConfigClass().getConstants().get(3);
    Assert.assertEquals("D_CONSTANT", dConstant.getName());
    Assert.assertEquals("new button()", dConstant.getValue());
    Assert.assertEquals("ext.config.button", dConstant.getType());
    Assert.assertTrue(model.getImports().contains("ext.config.button"));
    Assert.assertNull(dConstant.getDescription());
    Declaration eConstant = model.getConfigClass().getConstants().get(4);
    Assert.assertEquals("E_CONSTANT", eConstant.getName());
    Assert.assertEquals("new Container()", eConstant.getValue());
    Assert.assertEquals("ext.Component", eConstant.getType());
    Assert.assertTrue(model.getImports().contains("ext.Component"));
    Assert.assertTrue(model.getImports().contains("ext.Container"));
    Assert.assertNull(eConstant.getDescription());
}
Also used : ExmlModel(net.jangaroo.exml.model.ExmlModel) ExmlToModelParser(net.jangaroo.exml.parser.ExmlToModelParser) Declaration(net.jangaroo.exml.model.Declaration) Test(org.junit.Test)

Example 10 with ExmlToModelParser

use of net.jangaroo.exml.parser.ExmlToModelParser in project jangaroo-tools by CoreMedia.

the class ExmlToModelParserTest method testConfigDefaultValues.

@Test
public void testConfigDefaultValues() throws Exception {
    setUp("testNamespace.config");
    ExmlToModelParser exmlToModelParser = new ExmlToModelParser(getConfigClassRegistry());
    ExmlModel model = exmlToModelParser.parse(getFile("/testPackage/TestComponentWithCfgDefaults.exml"));
    List<ConfigAttribute> cfgs = model.getConfigClass().getDirectCfgs();
    Assert.assertEquals(9, cfgs.size());
    JsonObject expectedJsonObject = new JsonObject("propertyWithLiteralDefault", "foobar", "propertyWithExpressionDefault", JsonObject.code("'foo' + 'bar'"), "propertyWithDefaultElement", new JsonObject("xtype", "button", "text", "click me!"), "propertyWithDefaultElementUsingConfig", new JsonObject("xtype", "button", "text", JsonObject.code("config.title + '!'")), "arrayPropertyWithDefaultElement", new JsonArray(new JsonObject("xtype", "button", "text", "button1"), new JsonObject("xtype", "button", "text", "button2")), "propertyWithInterfaceAndDefault", JsonObject.code(" new TestImpl() "), "propertyFromOtherPackage", JsonObject.code(" new SomeOtherClass('lala') "));
    System.out.println(model.getJsonObject().toString(2));
    Assert.assertEquals(expectedJsonObject.toString(2), model.getCfgDefaults().toString(2));
}
Also used : JsonArray(net.jangaroo.exml.json.JsonArray) ExmlModel(net.jangaroo.exml.model.ExmlModel) ConfigAttribute(net.jangaroo.exml.model.ConfigAttribute) JsonObject(net.jangaroo.exml.json.JsonObject) ExmlToModelParser(net.jangaroo.exml.parser.ExmlToModelParser) Test(org.junit.Test)

Aggregations

ExmlModel (net.jangaroo.exml.model.ExmlModel)17 ExmlToModelParser (net.jangaroo.exml.parser.ExmlToModelParser)17 Test (org.junit.Test)16 JsonObject (net.jangaroo.exml.json.JsonObject)11 JsonArray (net.jangaroo.exml.json.JsonArray)10 File (java.io.File)4 ExmlSourceFile (net.jangaroo.exml.model.ExmlSourceFile)4 Declaration (net.jangaroo.exml.model.Declaration)2 FileOutputStream (java.io.FileOutputStream)1 PrintStream (java.io.PrintStream)1 StringWriter (java.io.StringWriter)1 ExmlComponentClassGenerator (net.jangaroo.exml.generator.ExmlComponentClassGenerator)1 ConfigAttribute (net.jangaroo.exml.model.ConfigAttribute)1