Search in sources :

Example 11 with IModelWorkspace

use of org.eclipse.vorto.utilities.reader.IModelWorkspace in project vorto by eclipse.

the class ModelReaderTest method testReadMultipleZipFiles.

@Test
public void testReadMultipleZipFiles() {
    IModelWorkspace workspace = IModelWorkspace.newReader().addZip(new ZipInputStream(getClass().getClassLoader().getResourceAsStream("mappings.zip"))).addZip(new ZipInputStream(getClass().getClassLoader().getResourceAsStream("models.zip"))).read();
    assertEquals(10, workspace.get().size());
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) IModelWorkspace(org.eclipse.vorto.utilities.reader.IModelWorkspace) Test(org.junit.Test)

Example 12 with IModelWorkspace

use of org.eclipse.vorto.utilities.reader.IModelWorkspace in project vorto by eclipse.

the class ModelReaderTest method testFlatInheritanceWithFbSuperType.

/*
   * Test to check whether properties are flattened recursively when functionblocks are extended
   */
@Test
public void testFlatInheritanceWithFbSuperType() {
    IModelWorkspace workspace = IModelWorkspace.newReader().addFile(getClass().getClassLoader().getResourceAsStream("dsls/superTypeTestCases/TestInfomodelWithEntity.infomodel"), ModelType.InformationModel).addFile(getClass().getClassLoader().getResourceAsStream("dsls/superTypeTestCases/TestFunctionBlockWithEntity.fbmodel"), ModelType.Functionblock).addFile(getClass().getClassLoader().getResourceAsStream("dsls/superTypeTestCases/SecondFunctionBlock.fbmodel"), ModelType.Functionblock).addFile(getClass().getClassLoader().getResourceAsStream("dsls/superTypeTestCases/GenericFunctionBlock.fbmodel"), ModelType.Functionblock).read();
    InformationModel infomodel = ModelConversionUtils.convertToFlatHierarchy((InformationModel) workspace.get().get(0));
    FunctionblockModel infoModelFbType = infomodel.getProperties().get(0).getType();
    FunctionBlock functionBlock = infoModelFbType.getFunctionblock();
    List<Property> statusProperties = functionBlock.getStatus().getProperties();
    int statusPropertySize = statusProperties.size();
    assertEquals(3, statusPropertySize);
}
Also used : FunctionblockModel(org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) InformationModel(org.eclipse.vorto.core.api.model.informationmodel.InformationModel) Property(org.eclipse.vorto.core.api.model.datatype.Property) IModelWorkspace(org.eclipse.vorto.utilities.reader.IModelWorkspace) FunctionBlock(org.eclipse.vorto.core.api.model.functionblock.FunctionBlock) Test(org.junit.Test)

Example 13 with IModelWorkspace

use of org.eclipse.vorto.utilities.reader.IModelWorkspace in project vorto by eclipse.

the class ModelSerializerTest method testSerializeMappingWithVortolang.

@Test
public void testSerializeMappingWithVortolang() throws Exception {
    final Injector injector = new MappingStandaloneSetup().createInjectorAndDoEMFRegistration();
    final XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class);
    ModelWorkspaceReader.init();
    IModelWorkspace workspace = IModelWorkspace.newReader().addFile(getClass().getClassLoader().getResourceAsStream("dsls/sample.mapping"), org.eclipse.vorto.model.ModelType.Mapping).read();
    Model model = workspace.get().get(0);
    final Resource resource = resourceSet.createResource(URI.createURI(model.getName() + ".mapping"));
    resource.getContents().add(model);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final Map<Object, Object> optionsMap = SaveOptions.newBuilder().format().getOptions().toOptionsMap();
    optionsMap.put(XtextResource.OPTION_ENCODING, StandardCharsets.UTF_8);
    resource.save(baos, optionsMap);
    assertTrue(equalsIgnoreNewlineStyle(IOUtils.toString(Thread.currentThread().getContextClassLoader().getResourceAsStream("dsls/sample.mapping")), new String(baos.toByteArray(), StandardCharsets.UTF_8)));
}
Also used : MappingStandaloneSetup(org.eclipse.vorto.editor.mapping.MappingStandaloneSetup) Injector(com.google.inject.Injector) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) InformationModel(org.eclipse.vorto.core.api.model.informationmodel.InformationModel) Model(org.eclipse.vorto.core.api.model.model.Model) FunctionblockModel(org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IModelWorkspace(org.eclipse.vorto.utilities.reader.IModelWorkspace) Test(org.junit.Test)

Example 14 with IModelWorkspace

use of org.eclipse.vorto.utilities.reader.IModelWorkspace in project vorto by eclipse.

the class EclipseDittoGeneratorTest method modelProvider.

public InformationModel modelProvider(String... filenames) {
    ModelWorkspaceReader mwr = IModelWorkspace.newReader();
    for (String filename : filenames) {
        mwr.addFile(getClass().getClassLoader().getResourceAsStream(folderPath + filename), FILENAME_TO_TYPE_MAP.get(FilenameUtils.getExtension(filename)));
    }
    IModelWorkspace workspace = mwr.read();
    InformationModel model = (InformationModel) workspace.get().stream().filter(p -> p instanceof InformationModel).findAny().get();
    return model;
}
Also used : InformationModel(org.eclipse.vorto.core.api.model.informationmodel.InformationModel) BeforeClass(org.junit.BeforeClass) HashMap(java.util.HashMap) JSONAssert(org.skyscreamer.jsonassert.JSONAssert) EclipseDittoGenerator(org.eclipse.vorto.codegen.ditto.EclipseDittoGenerator) JSONException(org.json.JSONException) IModelWorkspace(org.eclipse.vorto.utilities.reader.IModelWorkspace) Map(java.util.Map) ICodeGenerator(org.eclipse.vorto.plugin.generator.ICodeGenerator) IGenerationResult(org.eclipse.vorto.plugin.generator.IGenerationResult) Utils(org.eclipse.vorto.plugin.utils.Utils) AbstractGeneratorTest(org.eclipse.vorto.plugin.AbstractGeneratorTest) ModelId(org.eclipse.vorto.core.api.model.model.ModelId) FileUtils(org.apache.commons.io.FileUtils) Test(org.junit.Test) BuilderUtils(org.eclipse.vorto.core.api.model.BuilderUtils) GeneratorException(org.eclipse.vorto.plugin.generator.GeneratorException) ModelType(org.eclipse.vorto.model.ModelType) File(java.io.File) IOUtils(org.apache.commons.io.IOUtils) FunctionblockModel(org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) InvocationContext(org.eclipse.vorto.plugin.generator.InvocationContext) ModelWorkspaceReader(org.eclipse.vorto.utilities.reader.ModelWorkspaceReader) Generated(org.eclipse.vorto.plugin.generator.utils.Generated) FilenameUtils(org.apache.commons.io.FilenameUtils) Assert.assertEquals(org.junit.Assert.assertEquals) ModelWorkspaceReader(org.eclipse.vorto.utilities.reader.ModelWorkspaceReader) InformationModel(org.eclipse.vorto.core.api.model.informationmodel.InformationModel) IModelWorkspace(org.eclipse.vorto.utilities.reader.IModelWorkspace)

Example 15 with IModelWorkspace

use of org.eclipse.vorto.utilities.reader.IModelWorkspace in project vorto by eclipse.

the class RefactoringWorkspaceTest method testChangeNamespaceWithManyReferencesAlreadyBelongingToTargetNamespace.

@Test
public void testChangeNamespaceWithManyReferencesAlreadyBelongingToTargetNamespace() {
    IModelWorkspace workspace = IModelWorkspace.newReader().addFile(getClass().getClassLoader().getResourceAsStream("dsls/Unit.type"), ModelType.Datatype).addFile(getClass().getClassLoader().getResourceAsStream("dsls/ConnectivityStatus.type"), ModelType.Datatype).addFile(getClass().getClassLoader().getResourceAsStream("dsls/Connectivity.fbmodel"), ModelType.Functionblock).read();
    ChangeSet changeSet = RefactoringTask.from(workspace).toNamespaceForAllModels("org.eclipse.vorto").execute();
    assertEquals(3, changeSet.get().size());
    assertEquals(0, changeSet.getChanges().size());
    Model fbmodel = changeSet.get().stream().filter(c -> c.getName().equals("Connectivity")).findAny().get();
    assertEquals("org.eclipse.vorto", fbmodel.getNamespace());
    assertEquals("org.eclipse.vorto.types.ConnectivityStatus", fbmodel.getReferences().get(0).getImportedNamespace());
    assertEquals("org.eclipse.vorto.types.SomeUnit", fbmodel.getReferences().get(1).getImportedNamespace());
}
Also used : FunctionblockModel(org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) Model(org.eclipse.vorto.core.api.model.model.Model) IModelWorkspace(org.eclipse.vorto.utilities.reader.IModelWorkspace) Test(org.junit.Test)

Aggregations

IModelWorkspace (org.eclipse.vorto.utilities.reader.IModelWorkspace)27 Test (org.junit.Test)19 FunctionblockModel (org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel)16 Model (org.eclipse.vorto.core.api.model.model.Model)15 InformationModel (org.eclipse.vorto.core.api.model.informationmodel.InformationModel)13 ModelWorkspaceReader (org.eclipse.vorto.utilities.reader.ModelWorkspaceReader)11 ZipInputStream (java.util.zip.ZipInputStream)10 MappingModel (org.eclipse.vorto.core.api.model.mapping.MappingModel)8 ModelType (org.eclipse.vorto.model.ModelType)8 BeforeClass (org.junit.BeforeClass)8 ByteArrayInputStream (java.io.ByteArrayInputStream)7 Entity (org.eclipse.vorto.core.api.model.datatype.Entity)7 ObjectPropertyType (org.eclipse.vorto.core.api.model.datatype.ObjectPropertyType)7 Property (org.eclipse.vorto.core.api.model.datatype.Property)7 ArrayList (java.util.ArrayList)6 List (java.util.List)6 Optional (java.util.Optional)6 ModelConversionUtils (org.eclipse.vorto.core.api.model.ModelConversionUtils)6 Collectors (java.util.stream.Collectors)5 FunctionBlock (org.eclipse.vorto.core.api.model.functionblock.FunctionBlock)5