Search in sources :

Example 1 with MappingStandaloneSetup

use of org.eclipse.vorto.editor.mapping.MappingStandaloneSetup 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)

Aggregations

Injector (com.google.inject.Injector)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 FunctionblockModel (org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel)1 InformationModel (org.eclipse.vorto.core.api.model.informationmodel.InformationModel)1 Model (org.eclipse.vorto.core.api.model.model.Model)1 MappingStandaloneSetup (org.eclipse.vorto.editor.mapping.MappingStandaloneSetup)1 IModelWorkspace (org.eclipse.vorto.utilities.reader.IModelWorkspace)1 XtextResource (org.eclipse.xtext.resource.XtextResource)1 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)1 Test (org.junit.Test)1