Search in sources :

Example 21 with IModelWorkspace

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

the class UtilsTest method setup.

@Before
public void setup() {
    ModelWorkspaceReader.init();
    IModelWorkspace workspace = IModelWorkspace.newReader().addFile(getClass().getClassLoader().getResourceAsStream("SomeFb.fbmodel"), ModelType.Functionblock).addFile(getClass().getClassLoader().getResourceAsStream("SuperFb.fbmodel"), ModelType.Functionblock).addFile(getClass().getClassLoader().getResourceAsStream("com.ipso.smartobjects_Push_button_0_0_1.fbmodel"), ModelType.Functionblock).addFile(getClass().getClassLoader().getResourceAsStream("SuperSuperFb.fbmodel"), ModelType.Functionblock).read();
    fbms.add(ModelConversionUtils.convertToFlatHierarchy((FunctionblockModel) workspace.get().get(0)));
    fbms.add(ModelConversionUtils.convertToFlatHierarchy((FunctionblockModel) workspace.get().get(1)));
    fbms.add(ModelConversionUtils.convertToFlatHierarchy((FunctionblockModel) workspace.get().get(2)));
    fbms.add(ModelConversionUtils.convertToFlatHierarchy((FunctionblockModel) workspace.get().get(3)));
}
Also used : FunctionblockModel(org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) IModelWorkspace(org.eclipse.vorto.utilities.reader.IModelWorkspace) Before(org.junit.Before)

Example 22 with IModelWorkspace

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

the class ModelReaderTest method testReadFromFile_Encoding.

@Test
public void testReadFromFile_Encoding() {
    IModelWorkspace workspace = IModelWorkspace.newReader().addFile(getClass().getClassLoader().getResourceAsStream("dsls/Color_encoding.type"), ModelType.Datatype).read();
    Entity model = (Entity) workspace.get().stream().filter(p -> p instanceof Entity).findAny().get();
    assertNotNull(model);
    assertEquals("Überraschung", model.getProperties().get(0).getDescription());
}
Also used : InformationModel(org.eclipse.vorto.core.api.model.informationmodel.InformationModel) ZipInputStream(java.util.zip.ZipInputStream) BeforeClass(org.junit.BeforeClass) MappingModel(org.eclipse.vorto.core.api.model.mapping.MappingModel) Test(org.junit.Test) Configuration(org.eclipse.vorto.core.api.model.functionblock.Configuration) Entity(org.eclipse.vorto.core.api.model.datatype.Entity) Collectors(java.util.stream.Collectors) ModelType(org.eclipse.vorto.model.ModelType) ModelConversionUtils(org.eclipse.vorto.core.api.model.ModelConversionUtils) Model(org.eclipse.vorto.core.api.model.model.Model) ArrayList(java.util.ArrayList) List(java.util.List) FunctionblockModel(org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) Property(org.eclipse.vorto.core.api.model.datatype.Property) IModelWorkspace(org.eclipse.vorto.utilities.reader.IModelWorkspace) Status(org.eclipse.vorto.core.api.model.functionblock.Status) ModelWorkspaceReader(org.eclipse.vorto.utilities.reader.ModelWorkspaceReader) ObjectPropertyType(org.eclipse.vorto.core.api.model.datatype.ObjectPropertyType) Optional(java.util.Optional) FunctionBlock(org.eclipse.vorto.core.api.model.functionblock.FunctionBlock) Assert(org.junit.Assert) Entity(org.eclipse.vorto.core.api.model.datatype.Entity) IModelWorkspace(org.eclipse.vorto.utilities.reader.IModelWorkspace) Test(org.junit.Test)

Example 23 with IModelWorkspace

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

the class ModelReaderTest method testReadFromFile.

@Test
public void testReadFromFile() {
    IModelWorkspace workspace = IModelWorkspace.newReader().addFile(getClass().getClassLoader().getResourceAsStream("dsls/com.example_AWSIoTButton_1_0_0.infomodel"), ModelType.InformationModel).addFile(getClass().getClassLoader().getResourceAsStream("dsls/com.example.aws_AWSButtonMapping_1_0_0.mapping"), ModelType.Mapping).addFile(getClass().getClassLoader().getResourceAsStream("dsls/com.example.aws_Button1Mapping_1_0_0.mapping"), ModelType.Mapping).addFile(getClass().getClassLoader().getResourceAsStream("dsls/com.example.aws_Button2Mapping_1_0_0.mapping"), ModelType.Mapping).addFile(getClass().getClassLoader().getResourceAsStream("dsls/com.ipso.smartobjects_Push_button_0_0_1.fbmodel"), ModelType.Functionblock).read();
    InformationModel model = (InformationModel) workspace.get().stream().filter(p -> p instanceof InformationModel).findAny().get();
    assertNotNull(model);
    assertEquals("AWSIoTButton", model.getName());
    assertEquals("AWSButtonMapping", workspace.get().stream().filter(p -> p.getName().equals("AWSButtonMapping")).findAny().get().getName());
}
Also used : InformationModel(org.eclipse.vorto.core.api.model.informationmodel.InformationModel) ZipInputStream(java.util.zip.ZipInputStream) BeforeClass(org.junit.BeforeClass) MappingModel(org.eclipse.vorto.core.api.model.mapping.MappingModel) Test(org.junit.Test) Configuration(org.eclipse.vorto.core.api.model.functionblock.Configuration) Entity(org.eclipse.vorto.core.api.model.datatype.Entity) Collectors(java.util.stream.Collectors) ModelType(org.eclipse.vorto.model.ModelType) ModelConversionUtils(org.eclipse.vorto.core.api.model.ModelConversionUtils) Model(org.eclipse.vorto.core.api.model.model.Model) ArrayList(java.util.ArrayList) List(java.util.List) FunctionblockModel(org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) Property(org.eclipse.vorto.core.api.model.datatype.Property) IModelWorkspace(org.eclipse.vorto.utilities.reader.IModelWorkspace) Status(org.eclipse.vorto.core.api.model.functionblock.Status) ModelWorkspaceReader(org.eclipse.vorto.utilities.reader.ModelWorkspaceReader) ObjectPropertyType(org.eclipse.vorto.core.api.model.datatype.ObjectPropertyType) Optional(java.util.Optional) FunctionBlock(org.eclipse.vorto.core.api.model.functionblock.FunctionBlock) Assert(org.junit.Assert) InformationModel(org.eclipse.vorto.core.api.model.informationmodel.InformationModel) IModelWorkspace(org.eclipse.vorto.utilities.reader.IModelWorkspace) Test(org.junit.Test)

Example 24 with IModelWorkspace

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

the class ModelReaderTest method testMappingFromZipFile.

@Test
public void testMappingFromZipFile() {
    IModelWorkspace workspace = IModelWorkspace.newReader().addZip(new ZipInputStream(getClass().getClassLoader().getResourceAsStream("mappings.zip"))).read();
    Model model = workspace.get().stream().filter(p -> p instanceof MappingModel).findAny().get();
    assertNotNull(model);
    assertTrue(model instanceof MappingModel);
    assertEquals("Accelerometer_Mapping", model.getName());
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) InformationModel(org.eclipse.vorto.core.api.model.informationmodel.InformationModel) MappingModel(org.eclipse.vorto.core.api.model.mapping.MappingModel) Model(org.eclipse.vorto.core.api.model.model.Model) FunctionblockModel(org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) IModelWorkspace(org.eclipse.vorto.utilities.reader.IModelWorkspace) MappingModel(org.eclipse.vorto.core.api.model.mapping.MappingModel) Test(org.junit.Test)

Example 25 with IModelWorkspace

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

the class ModelReaderTest method testFlatInheritanceFB.

@Test
public void testFlatInheritanceFB() {
    IModelWorkspace workspace = IModelWorkspace.newReader().addFile(getClass().getClassLoader().getResourceAsStream("dsls/SomeFb.fbmodel"), ModelType.Functionblock).addFile(getClass().getClassLoader().getResourceAsStream("dsls/SuperFb.fbmodel"), ModelType.Functionblock).addFile(getClass().getClassLoader().getResourceAsStream("dsls/SuperSuperFb.fbmodel"), ModelType.Functionblock).read();
    FunctionblockModel fbm = ModelConversionUtils.convertToFlatHierarchy((FunctionblockModel) workspace.get().get(0));
    assertEquals("SomeFb", fbm.getName());
    assertEquals(4, fbm.getFunctionblock().getStatus().getProperties().size());
    assertEquals(3, fbm.getFunctionblock().getConfiguration().getProperties().size());
    assertEquals(2, fbm.getFunctionblock().getOperations().size());
}
Also used : FunctionblockModel(org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) 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