Search in sources :

Example 11 with IGenerationResult

use of org.eclipse.vorto.plugin.generator.IGenerationResult in project vorto by eclipse.

the class EclipseHonoPythonGeneratorTest method testConnectorGeneratedMQTTClient.

/*
   * -----Below test cases are specific to Connector related files-------
   */
/*
   * Test case for checking whether the MQTT client generated contains the models which are listed
   * in the information model
   * 
   */
@Test
public void testConnectorGeneratedMQTTClient() throws GeneratorException, IOException, URISyntaxException {
    IGenerationResult generationResult = pythonGenerator.generate(modelProvider(), InvocationContext.simpleInvocationContext());
    Generated generatedFileHonoMqttClient = zipFileReader(generationResult, "DittoSerializer", ".py");
    File defaultFileHonoMqttClient = new File(getClass().getClassLoader().getResource("defaultFileFormat/DittoSerializer.py").toURI());
    assertEquals(IOUtils.toString(FileUtils.openInputStream(defaultFileHonoMqttClient)), new String(generatedFileHonoMqttClient.getContent(), "utf-8"));
}
Also used : Generated(org.eclipse.vorto.plugin.generator.utils.Generated) IGenerationResult(org.eclipse.vorto.plugin.generator.IGenerationResult) File(java.io.File) AbstractGeneratorTest(org.eclipse.vorto.plugin.AbstractGeneratorTest) Test(org.junit.Test)

Example 12 with IGenerationResult

use of org.eclipse.vorto.plugin.generator.IGenerationResult in project vorto by eclipse.

the class HonoGeneratorTest method testGenerateHonoForPython.

@Test
public void testGenerateHonoForPython() throws Exception {
    EclipseHonoGenerator generator = new EclipseHonoGenerator();
    ModelId batteryFb = ModelIdFactory.newInstance(ModelType.InformationModel, "org.eclipse.vorto", "1.0.0", "Battery");
    FunctionblockModel fbm = BuilderUtils.newFunctionblock(ModelIdFactory.newInstance(ModelType.InformationModel, "org.eclipse.vorto", "1.0.0", "Battery")).withDescription("Battery description").build();
    InformationModel infomodel = BuilderUtils.newInformationModel(ModelIdFactory.newInstance(ModelType.InformationModel, "org.eclipse.vorto", "1.0.0", "MyDevice")).withFunctionBlock(fbm, "battery", "battery prop", false).withReference(batteryFb).build();
    Map<String, String> properties = new HashMap<String, String>();
    properties.put("language", "python");
    IGenerationResult result = generator.generate(infomodel, InvocationContext.simpleInvocationContext(properties));
    assertNotNull(result);
    ZipInputStream zis = new ZipInputStream(new ByteArrayInputStream(result.getContent()));
    ZipEntry entry = null;
    Set<String> filePaths = new HashSet<>();
    while ((entry = zis.getNextEntry()) != null) {
        filePaths.add(entry.getName());
    }
    assertTrue(filePaths.contains("MyDeviceApp.py"));
}
Also used : HashMap(java.util.HashMap) ZipEntry(java.util.zip.ZipEntry) InformationModel(org.eclipse.vorto.core.api.model.informationmodel.InformationModel) IGenerationResult(org.eclipse.vorto.plugin.generator.IGenerationResult) FunctionblockModel(org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) ZipInputStream(java.util.zip.ZipInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ModelId(org.eclipse.vorto.core.api.model.model.ModelId) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 13 with IGenerationResult

use of org.eclipse.vorto.plugin.generator.IGenerationResult in project vorto by eclipse.

the class BoschIoTSuiteGeneratorTest method generateArduino.

/*
   * Check if cpp file is generated when language is passed as arduino to BoschIOTSuiteGenerator
   */
@Test
public void generateArduino() throws Exception {
    configProperties.put("language", "arduino");
    InvocationContext context = new InvocationContext(mappingModels, configProperties);
    IGenerationResult iGenerationResult = boschIOTSuiteGenerator.generate(modelProvider(), context);
    Generated generatedfile = zipFileReader(iGenerationResult, "StatusPropertiesFunctionBlock", ".cpp");
    assertEquals("StatusPropertiesFunctionBlock.cpp", generatedfile.getFileName());
}
Also used : Generated(org.eclipse.vorto.plugin.generator.utils.Generated) InvocationContext(org.eclipse.vorto.plugin.generator.InvocationContext) IGenerationResult(org.eclipse.vorto.plugin.generator.IGenerationResult) AbstractGeneratorTest(org.eclipse.vorto.plugin.AbstractGeneratorTest) Test(org.junit.Test)

Example 14 with IGenerationResult

use of org.eclipse.vorto.plugin.generator.IGenerationResult in project vorto by eclipse.

the class BoschIoTSuiteGeneratorTest method generateJava.

/*
   * Check if java file is generated when language is passed as java to BoschIOTSuiteGenerator
   */
@Test
public void generateJava() throws Exception {
    configProperties.put("language", "python");
    InvocationContext context = new InvocationContext(mappingModels, configProperties);
    IGenerationResult iGenerationResult = boschIOTSuiteGenerator.generate(modelProvider(), context);
    Generated generatedfile = zipFileReader(iGenerationResult, "StatusPropertiesFunctionBlock", ".java");
    assertEquals("StatusPropertiesFunctionBlock.java", generatedfile.getFileName());
}
Also used : Generated(org.eclipse.vorto.plugin.generator.utils.Generated) InvocationContext(org.eclipse.vorto.plugin.generator.InvocationContext) IGenerationResult(org.eclipse.vorto.plugin.generator.IGenerationResult) AbstractGeneratorTest(org.eclipse.vorto.plugin.AbstractGeneratorTest) Test(org.junit.Test)

Example 15 with IGenerationResult

use of org.eclipse.vorto.plugin.generator.IGenerationResult in project vorto by eclipse.

the class EclipseHonoArduinoGeneratorTest method checkAPIStatusPropertiesInFunctionBlock.

/*
   * -----Below test cases are specific to API related files-------
   */
/*
   * Test case for checking whether the functionblock related file has the status properties both
   * primitive and object with the setters and getters
   * 
   */
@Test
public void checkAPIStatusPropertiesInFunctionBlock() throws Exception {
    IGenerationResult generationResult = eclipseArduinoGenerator.generate(modelProvider(), InvocationContext.simpleInvocationContext());
    org.eclipse.vorto.plugin.generator.utils.Generated generatedfile = zipFileReader(generationResult, "StatusPropertiesFunctionBlock.cpp", ".cpp");
    File defaultFile = new File(getClass().getClassLoader().getResource("defaultFileFormat/StatusPropertiesFunctionBlock.cpp").toURI());
    assertEquals(TestUtils.normalizeEOL(IOUtils.toString(FileUtils.openInputStream(defaultFile))), TestUtils.normalizeEOL(new String(generatedfile.getContent(), "utf-8")));
}
Also used : Generated(org.eclipse.vorto.plugin.generator.utils.Generated) IGenerationResult(org.eclipse.vorto.plugin.generator.IGenerationResult) File(java.io.File) AbstractGeneratorTest(org.eclipse.vorto.plugin.AbstractGeneratorTest) Test(org.junit.Test)

Aggregations

IGenerationResult (org.eclipse.vorto.plugin.generator.IGenerationResult)34 Test (org.junit.Test)33 AbstractGeneratorTest (org.eclipse.vorto.plugin.AbstractGeneratorTest)32 Generated (org.eclipse.vorto.plugin.generator.utils.Generated)27 File (java.io.File)17 HashMap (java.util.HashMap)7 InvocationContext (org.eclipse.vorto.plugin.generator.InvocationContext)4 InformationModel (org.eclipse.vorto.core.api.model.informationmodel.InformationModel)3 ModelId (org.eclipse.vorto.core.api.model.model.ModelId)3 HashSet (java.util.HashSet)2 FunctionblockModel (org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel)2 Context (com.amazonaws.services.lambda.runtime.Context)1 RequestStreamHandler (com.amazonaws.services.lambda.runtime.RequestStreamHandler)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Optional (java.util.Optional)1