Search in sources :

Example 91 with IBindingManager

use of org.whole.lang.bindings.IBindingManager in project whole by wholeplatform.

the class WorkflowsInterpreterVisitorTest method testInvokeOperation.

@Test
public void testInvokeOperation() throws Exception {
    IEntity invokeOperationTest = WorkflowsTestTemplateManager.instance().create("invokeOperationTest");
    IBindingManager args = BindingManagerFactory.instance.createArguments();
    TestDecorationManager dm = new TestDecorationManager();
    args.wDefValue("decorationManager", dm);
    StringWriter writer = new StringWriter();
    args.wDefValue("printWriter", new PrintWriter(writer));
    InterpreterOperation.interpret(invokeOperationTest, args);
    Assert.assertTrue(args.wIsSet("model"));
    Assert.assertTrue(args.wIsSet("modelCopy"));
    // validate assertions
    Assert.assertNotNull(dm.messages);
    Assert.assertFalse(dm.messages.isEmpty());
    Assert.assertEquals(1, dm.messages.size());
    Assert.assertTrue(dm.messages.contains("Reference to the undeclared type: IType"));
    // normalize assertions
    IEntity modelCopy = args.wGet("modelCopy");
    Assert.assertFalse(Matcher.match(args.wGet("model"), modelCopy));
    Assert.assertTrue(Matcher.match(args.wGet("model"), NormalizerOperation.normalize(EntityUtils.clone(modelCopy))));
    // pretty print assertions
    String ls = System.getProperty("line.separator");
    String TEXT_MODEL = "model SampleM" + ls + ls + ls + "entity Type types IType" + ls + "    feature DataStr data" + ls + ls + "entity DataStr" + ls + "    value <String>" + ls + ls + "abstract entity IType" + ls;
    Assert.assertEquals(TEXT_MODEL, writer.toString());
    // pretty print assertions
    ILanguageKit languageKit = ReflectionFactory.getLanguageKit("http://lang.whole.org/SampleM");
    Assert.assertNotNull(languageKit);
    EntityDescriptor<? extends IEntity> ed = languageKit.getEntityDescriptorEnum().valueOf("Type");
    Assert.assertNotNull(ed);
    Assert.assertEquals(1, ed.featureSize());
    // generate assertions
    File file = new File("./data/SampleM.xwl");
    Assert.assertTrue(file.exists());
    IEntity entity = XmlBuilderPersistenceKit.instance().readModel(new FilePersistenceProvider(file));
    Assert.assertTrue(Matcher.match(args.wGet("model"), entity));
    Assert.assertFalse(args.wIsSet("fileArtifact"));
}
Also used : StringWriter(java.io.StringWriter) IEntity(org.whole.lang.model.IEntity) FilePersistenceProvider(org.whole.lang.codebase.FilePersistenceProvider) IBindingManager(org.whole.lang.bindings.IBindingManager) File(java.io.File) ILanguageKit(org.whole.lang.reflect.ILanguageKit) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 92 with IBindingManager

use of org.whole.lang.bindings.IBindingManager in project whole by wholeplatform.

the class XmlNormalizerBuilderTest method testNormalizationWithCDataSectMerge.

@Test
public void testNormalizationWithCDataSectMerge() {
    try {
        // create queries
        Path findNestedContent = (Path) XmlNormalizerBuilderTemplateManager.instance().create("findNestedContent");
        Path findMissingContentEntities = (Path) XmlNormalizerBuilderTemplateManager.instance().create("findMissingContentEntities");
        Path findConsecutiveCharDataOrCDataSect = (Path) XmlNormalizerBuilderTemplateManager.instance().create("findConsecutiveCharDataOrCDataSect");
        // create normalized sample xml model
        SampleXmlModel sampleXmlModelTemplate = new SampleXmlModel();
        Document xmlDocument = sampleXmlModelTemplate.create();
        IBindingManager parameters = BindingManagerFactory.instance.createArguments();
        parameters.wDefValue("mergeCDataSect", true);
        ModelBuilderOperation mop = new ModelBuilderOperation();
        XmlNormalizerBuilderOperation xnop = new XmlNormalizerBuilderOperation(mop, parameters);
        sampleXmlModelTemplate.apply(xnop);
        Document normalizedXmlDocument = (Document) mop.wGetResult();
        // no nested Content
        IEntityIterator<IEntity> iterator = BehaviorUtils.compileAndLazyEvaluate(findNestedContent, normalizedXmlDocument);
        assertFalse(iterator.hasNext());
        // no nested implied Content
        iterator = BehaviorUtils.compileAndLazyEvaluate(findMissingContentEntities, normalizedXmlDocument);
        assertFalse(iterator.hasNext());
        // no consecutive CharData
        iterator = BehaviorUtils.compileAndLazyEvaluate(findConsecutiveCharDataOrCDataSect, normalizedXmlDocument);
        assertFalse(iterator.hasNext());
        // no CDataSect at all
        iterator = IteratorFactory.descendantOrSelfMatcherIterator().withPattern(XmlEntityDescriptorEnum.CDataSect);
        iterator.reset(normalizedXmlDocument);
        assertFalse(iterator.hasNext());
        // both normalization strategies must yield the same result
        assertTrue(Matcher.match(normalizedXmlDocument, NormalizerOperation.normalize(xmlDocument, parameters)));
    } catch (Exception e) {
        fail();
    }
}
Also used : Path(org.whole.lang.queries.model.Path) ModelBuilderOperation(org.whole.lang.builders.ModelBuilderOperation) XmlNormalizerBuilderOperation(org.whole.lang.xml.codebase.XmlNormalizerBuilderOperation) IEntity(org.whole.lang.model.IEntity) IBindingManager(org.whole.lang.bindings.IBindingManager) Document(org.whole.lang.xml.model.Document) Test(org.junit.Test)

Example 93 with IBindingManager

use of org.whole.lang.bindings.IBindingManager in project whole by wholeplatform.

the class XsdModelBuilderTest method testBuilderAPI.

@Category(KnownFailingTests.class)
@Test
public void testBuilderAPI() throws Exception {
    Schema xsdFromInputStream = (Schema) XsdPersistenceKit.instance().readModel(new StreamPersistenceProvider(getInputStream("datatypes.xsd")));
    Document document = (Document) XmlSourcePersistenceKit.instance().readModel(new StreamPersistenceProvider(getInputStream("datatypes.xsd")));
    IBindingManager bm = BindingManagerFactory.instance.createBindingManager();
    bm.wDefValue("mergeCDataSect", true);
    XsdDeployStrategies.setDeployStrategy(bm, XsdDeployStrategies.ALL);
    ModelBuilderOperation mop = new ModelBuilderOperation();
    IBuilderOperation xsdBuilderOperation = new XmlSpecific2XsdBuilderAdapterOperation(mop, bm);
    XmlNormalizerBuilderOperation normalizerOp = new XmlNormalizerBuilderOperation(xsdBuilderOperation, bm);
    ModelTemplate template = new ModelTemplate(document);
    template.apply(new XmlGenericBuilderAdapter((IXmlBuilder) normalizerOp.wGetBuilder(XmlLanguageKit.URI)));
    Schema xsdFromXmlModel = (Schema) mop.wGetResult();
    Assert.assertTrue(Matcher.match(xsdFromInputStream, xsdFromXmlModel));
}
Also used : ModelBuilderOperation(org.whole.lang.builders.ModelBuilderOperation) ModelTemplate(org.whole.lang.templates.ModelTemplate) IBuilderOperation(org.whole.lang.builders.IBuilderOperation) XmlNormalizerBuilderOperation(org.whole.lang.xml.codebase.XmlNormalizerBuilderOperation) XmlGenericBuilderAdapter(org.whole.lang.xml.builders.XmlGenericBuilderAdapter) Schema(org.whole.lang.xsd.model.Schema) IBindingManager(org.whole.lang.bindings.IBindingManager) IXmlBuilder(org.whole.lang.xml.builders.IXmlBuilder) StreamPersistenceProvider(org.whole.lang.codebase.StreamPersistenceProvider) Document(org.whole.lang.xml.model.Document) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Example 94 with IBindingManager

use of org.whole.lang.bindings.IBindingManager in project whole by wholeplatform.

the class XsdMappingTest method testModelsToXmlSchemaXXX.

@Test
public void testModelsToXmlSchemaXXX() throws Exception {
    IBindingManager bm = BindingManagerFactory.instance.createArguments();
    PathExpression path = new ModelToXmlSchemaQuery().create();
    Model model = (Model) ModelsTemplateManager.instance().create("Models model");
    String uri = model.getUri().getValue();
    ILanguageKit lk = ReflectionFactory.getLanguageKit(uri);
    IEntity tuple = BehaviorUtils.evaluateFirstResult(path, model, bm);
    Assert.assertNotNull(tuple);
    InterpreterOperation.interpret(tuple.wGet(1));
    ITemplateManager tm = lk.getTemplateManager();
    IEntity entity = tm.create("Editors model");
    IPersistenceProvider pp = new StringPersistenceProvider();
    XsiPersistenceKit.instance().writeModel(entity, pp);
    IEntity entity2 = XsiPersistenceKit.instance().readModel(pp);
    boolean matches = Matcher.match(entity, entity2);
    Assert.assertTrue(matches);
}
Also used : ModelToXmlSchemaQuery(org.whole.lang.xsd.codebase.ModelToXmlSchemaQuery) PathExpression(org.whole.lang.queries.model.PathExpression) StringPersistenceProvider(org.whole.lang.codebase.StringPersistenceProvider) IEntity(org.whole.lang.model.IEntity) IBindingManager(org.whole.lang.bindings.IBindingManager) Model(org.whole.lang.models.model.Model) ITemplateManager(org.whole.lang.templates.ITemplateManager) IPersistenceProvider(org.whole.lang.codebase.IPersistenceProvider) ILanguageKit(org.whole.lang.reflect.ILanguageKit) Test(org.junit.Test)

Example 95 with IBindingManager

use of org.whole.lang.bindings.IBindingManager in project whole by wholeplatform.

the class DBSchemaTemplateFactoryTest method testRDBUtils.

@Category(KnownFailingTests.class)
@Test
public void testRDBUtils() throws Exception {
    IBindingManager bm = BindingManagerFactory.instance.createArguments();
    bm.wDefValue("connection", connection);
    bm.wDefValue("generateDropStatements", false);
    Database database = new SampleDatabase().create();
    InterpreterOperation.interpret(database, bm);
    DBSchemaTemplateFactory dbSchemaTemplateFactory = new DBSchemaTemplateFactory(connection, "DBNAME", null);
    Database generatedDatabase = dbSchemaTemplateFactory.create();
    HashMap<EntityDescriptor<?>, Comparator<IEntity>> comparatorsMap = new HashMap<EntityDescriptor<?>, Comparator<IEntity>>();
    comparatorsMap.put(RDBEntityDescriptorEnum.Tables, new OrderedMatcher.SimpleFeatureComparator(RDBFeatureDescriptorEnum.name));
    Assert.assertTrue(OrderedMatcher.match(database, generatedDatabase, comparatorsMap));
    Assert.fail();
}
Also used : EntityDescriptor(org.whole.lang.reflect.EntityDescriptor) HashMap(java.util.HashMap) IEntity(org.whole.lang.model.IEntity) IBindingManager(org.whole.lang.bindings.IBindingManager) Database(org.whole.lang.rdb.model.Database) Comparator(java.util.Comparator) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Aggregations

IBindingManager (org.whole.lang.bindings.IBindingManager)223 IEntity (org.whole.lang.model.IEntity)141 Test (org.junit.Test)91 PathExpression (org.whole.lang.queries.model.PathExpression)49 ITemplateManager (org.whole.lang.templates.ITemplateManager)40 Grammar (org.whole.lang.grammars.model.Grammar)28 TestXmlGrammar (org.whole.lang.grammars.util.TestXmlGrammar)27 ESelectionService (org.eclipse.e4.ui.workbench.modeling.ESelectionService)17 Model (org.whole.lang.models.model.Model)15 Production (org.whole.lang.grammars.model.Production)14 IEntityPartViewer (org.whole.lang.ui.viewers.IEntityPartViewer)14 File (java.io.File)12 QueriesGrammar (org.whole.lang.grammars.codebase.QueriesGrammar)12 XmlModel (org.whole.lang.models.codebase.XmlModel)11 SimpleEntity (org.whole.lang.models.model.SimpleEntity)10 VisitException (org.whole.lang.visitors.VisitException)9 IBindingScope (org.whole.lang.bindings.IBindingScope)6 ModelBuilderOperation (org.whole.lang.builders.ModelBuilderOperation)6 HashMap (java.util.HashMap)5 IFile (org.eclipse.core.resources.IFile)5