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