Search in sources :

Example 16 with ModelBuilderOperation

use of org.whole.lang.builders.ModelBuilderOperation 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 17 with ModelBuilderOperation

use of org.whole.lang.builders.ModelBuilderOperation in project whole by wholeplatform.

the class ResourceTemplateTest method getMetadataPattern.

private IEntity getMetadataPattern() {
    ModelBuilderOperation op = new ModelBuilderOperation();
    IArtifactsBuilder ab = (IArtifactsBuilder) op.wGetBuilder(ArtifactsLanguageKit.URI);
    ICommonsBuilder cb = (ICommonsBuilder) op.wGetBuilder(CommonsLanguageKit.URI);
    ab.Metadata_();
    cb.Resolver();
    cb.Resolver();
    cb.Resolver();
    ab.Attributes_(1);
    ab.Attribute(AttributeEnum.readonly);
    ab._Attributes();
    cb.Resolver();
    ab._Metadata();
    return op.wGetResult();
}
Also used : ModelBuilderOperation(org.whole.lang.builders.ModelBuilderOperation) IArtifactsBuilder(org.whole.lang.artifacts.builders.IArtifactsBuilder) ICommonsBuilder(org.whole.lang.commons.builders.ICommonsBuilder)

Example 18 with ModelBuilderOperation

use of org.whole.lang.builders.ModelBuilderOperation in project whole by wholeplatform.

the class ResourceTemplateTest method getFilesystemPattern.

private IEntity getFilesystemPattern() {
    ModelBuilderOperation op = new ModelBuilderOperation();
    IArtifactsBuilder ab = (IArtifactsBuilder) op.wGetBuilder(ArtifactsLanguageKit.URI);
    ICommonsBuilder cb = (ICommonsBuilder) op.wGetBuilder(CommonsLanguageKit.URI);
    ab.FolderArtifact_();
    ab.Name("testfolder");
    cb.Resolver();
    ab.Artifacts_(3);
    ab.FolderArtifact_();
    ab.Name("empty.folder");
    cb.Resolver();
    ab.Artifacts();
    ab._FolderArtifact();
    ab.FolderArtifact_();
    ab.Name("subfolder");
    cb.Resolver();
    ab.Artifacts_(1);
    ab.FileArtifact_();
    ab.NameWithExtension_();
    ab.Name("test");
    ab.Extension("txt");
    ab._NameWithExtension();
    cb.Resolver();
    cb.Resolver();
    ab._FileArtifact();
    ab._Artifacts();
    ab._FolderArtifact();
    ab.FileArtifact_();
    ab.NameWithExtension_();
    ab.Name("test.extensions");
    ab.Extension("txt");
    ab._NameWithExtension();
    cb.Resolver();
    cb.Resolver();
    ab._FileArtifact();
    ab.FileArtifact_();
    ab.Name("withoutext");
    cb.Resolver();
    cb.Resolver();
    ab._FileArtifact();
    return op.wGetResult();
}
Also used : ModelBuilderOperation(org.whole.lang.builders.ModelBuilderOperation) IArtifactsBuilder(org.whole.lang.artifacts.builders.IArtifactsBuilder) ICommonsBuilder(org.whole.lang.commons.builders.ICommonsBuilder)

Example 19 with ModelBuilderOperation

use of org.whole.lang.builders.ModelBuilderOperation in project whole by wholeplatform.

the class ResourceTemplateTest method testSubtreeArtifacts.

@Test
public void testSubtreeArtifacts() {
    File testfolder = new File("data/testfolder");
    File testsubfolder = new File("data/testfolder/subfolder");
    ResourceTemplate template = new ResourceTemplate(testfolder);
    ModelBuilderOperation op = new ModelBuilderOperation();
    template.apply(op);
    IEntity testFolder = op.wGetResult();
    template = new ResourceTemplate(testsubfolder);
    op = new ModelBuilderOperation();
    template.apply(op);
    IEntity testSubFolder = op.wGetResult();
    FolderArtifact compareTo = null;
    IEntityIterator<FolderArtifact> iterator = IteratorFactory.<FolderArtifact>childMatcherIterator().withPattern(ArtifactsEntityDescriptorEnum.FolderArtifact);
    iterator.reset(testFolder.wGet(ArtifactsFeatureDescriptorEnum.artifacts));
    while (iterator.hasNext()) {
        FolderArtifact folder = iterator.next();
        if (folder.getName().wEquals(testSubFolder.wGet(ArtifactsFeatureDescriptorEnum.name))) {
            compareTo = folder;
            break;
        }
    }
    assertNotNull(compareTo);
    assertTrue(OrderedMatcher.match(testSubFolder, compareTo, comparatorsMap));
}
Also used : ModelBuilderOperation(org.whole.lang.builders.ModelBuilderOperation) IEntity(org.whole.lang.model.IEntity) ResourceTemplate(org.whole.lang.artifacts.templates.ResourceTemplate) FolderArtifact(org.whole.lang.artifacts.model.FolderArtifact) File(java.io.File) Test(org.junit.Test)

Example 20 with ModelBuilderOperation

use of org.whole.lang.builders.ModelBuilderOperation in project whole by wholeplatform.

the class ResourceTemplateTest method testReadOnlyArtifact.

@Test
public void testReadOnlyArtifact() throws IOException {
    IEntity readOnlyMetadata = getMetadataPattern();
    File tempFile = File.createTempFile("whole", null);
    tempFile.deleteOnExit();
    ResourceTemplate template = new ResourceTemplate(tempFile);
    ModelBuilderOperation op = new ModelBuilderOperation();
    template.apply(op);
    IEntity readWriteArtifact = op.wGetResult();
    assertFalse(Matcher.match(readOnlyMetadata, readWriteArtifact));
    tempFile.setReadOnly();
    template = new ResourceTemplate(tempFile);
    op = new ModelBuilderOperation();
    template.apply(op);
    IEntity readOnlyArtifact = op.wGetResult();
    assertFalse(Matcher.match(readOnlyMetadata, readOnlyArtifact));
}
Also used : ModelBuilderOperation(org.whole.lang.builders.ModelBuilderOperation) IEntity(org.whole.lang.model.IEntity) ResourceTemplate(org.whole.lang.artifacts.templates.ResourceTemplate) File(java.io.File) Test(org.junit.Test)

Aggregations

ModelBuilderOperation (org.whole.lang.builders.ModelBuilderOperation)41 IEntity (org.whole.lang.model.IEntity)21 Test (org.junit.Test)18 ICommonsBuilder (org.whole.lang.commons.builders.ICommonsBuilder)8 File (java.io.File)6 ModelTemplate (org.whole.lang.templates.ModelTemplate)6 XmlNormalizerBuilderOperation (org.whole.lang.xml.codebase.XmlNormalizerBuilderOperation)6 ResourceTemplate (org.whole.lang.artifacts.templates.ResourceTemplate)5 IBindingManager (org.whole.lang.bindings.IBindingManager)5 IXmlBuilder (org.whole.lang.xml.builders.IXmlBuilder)5 IArtifactsBuilder (org.whole.lang.artifacts.builders.IArtifactsBuilder)4 StreamPersistenceProvider (org.whole.lang.codebase.StreamPersistenceProvider)4 Document (org.whole.lang.xml.model.Document)4 XmlStoreProducerBuilderOperation (org.whole.lang.xml.util.XmlStoreProducerBuilderOperation)4 XmlStoreConsumerVisitor (org.whole.lang.xml.util.XmlStoreConsumerVisitor)3 Category (org.junit.experimental.categories.Category)2 WorkspaceTemplate (org.whole.lang.artifacts.templates.WorkspaceTemplate)2 IBuilderOperation (org.whole.lang.builders.IBuilderOperation)2 JavaStoreProducerBuilder (org.whole.lang.java.util.JavaStoreProducerBuilder)2 JavaStoreProducerBuilderOperation (org.whole.lang.java.util.JavaStoreProducerBuilderOperation)2