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"));
}
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();
}
}
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));
}
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);
}
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();
}
Aggregations