Search in sources :

Example 21 with IGenerationResult

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

the class EclipseDittoGeneratorTest method checkAPIConfigPropertiesInFunctionBlock.

/*
   * Test case for checking whether the config properties are reflected in json
   */
@Test
public void checkAPIConfigPropertiesInFunctionBlock() throws Exception {
    Map<String, String> params = new HashMap<>();
    params.put("target", "jsonSchema");
    IGenerationResult generationResult = eclipseDittoGenerator.generate(modelProvider("MultiplTypeIm.infomodel", "MultipleTypeFb.functionblock"), InvocationContext.simpleInvocationContext(params));
    Generated generatedfile = zipFileReader(generationResult, "properties-configuration.schema", ".json");
    File defaultFile = new File(getClass().getClassLoader().getResource("defaultFileFormat/properties-configuration.schema.json").toURI());
    assertEquals(IOUtils.toString(FileUtils.openInputStream(defaultFile)), new String(generatedfile.getContent(), "utf-8"));
}
Also used : Generated(org.eclipse.vorto.plugin.generator.utils.Generated) HashMap(java.util.HashMap) IGenerationResult(org.eclipse.vorto.plugin.generator.IGenerationResult) File(java.io.File) AbstractGeneratorTest(org.eclipse.vorto.plugin.AbstractGeneratorTest) Test(org.junit.Test)

Example 22 with IGenerationResult

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

the class EclipseDittoGeneratorTest method testFunctionBlockInheritance.

/**
 * Tests function block inheritance over two levels.
 *
 * (please be aware that the inherited properties are missing in the
 * expected result because they are added by the flattening
 * mechanism which takes place on repository side. Its not relevant for
 * this test.)
 *
 * @throws Exception
 */
@Test
public void testFunctionBlockInheritance() throws Exception {
    Map<String, String> params = new HashMap<>();
    params.put("target", "thingJson");
    IGenerationResult generationResult = eclipseDittoGenerator.generate(inheritanceFunctionBlockProvider("SubTestFb", "ParentFbToBeExtended.functionblock", "SubTestFb.functionblock", "TestFb.functionblock"), InvocationContext.simpleInvocationContext(params));
    assertEquals("application/json", generationResult.getMediatype());
    String expectedResult = "{\n" + "  \"definition\": \"vortotest:SubTestFbIM:1.0.0\",\n" + "  \"attributes\": {\n" + " \t\"modelDisplayName\": \"SubTestFb\"\n" + " \t },\n" + " \t\"features\": {\n" + " \t\"subtestfb\" : {\n" + " \t\"definition\": [\n" + " \t\t\"vortotest:SubTestFb:1.0.0\",\n" + " \t\t\"vortotest:TestFb:1.0.0\",\n" + " \t\t\"vortotest:ParentFbToBeExtended:1.0.0\"\n" + " \t],\n" + " \t\"properties\": {\n" + " \t\t\"status\": {\n" + " \t\t\t\"myFloatInSubTestFb\" : 0.0\n" + " \t\t},\n" + "\t\"configuration\": {\n" + "\t\t\"temperatureSub\" : 0.0\n" + "}\n" + " \t}\n" + " \t}\n" + "}\n" + "}";
    JSONAssert.assertEquals(expectedResult, new String(generationResult.getContent()), true);
}
Also used : HashMap(java.util.HashMap) IGenerationResult(org.eclipse.vorto.plugin.generator.IGenerationResult) AbstractGeneratorTest(org.eclipse.vorto.plugin.AbstractGeneratorTest) Test(org.junit.Test)

Example 23 with IGenerationResult

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

the class EclipseDittoGeneratorTest method checkMultipleKeywordInFunctionBlock.

/*
   * Test case for checking whether the multiple keyword generates corresponding array type in json
   *
   */
@Test
public void checkMultipleKeywordInFunctionBlock() throws Exception {
    Map<String, String> params = new HashMap<>();
    params.put("target", "jsonSchema");
    IGenerationResult generationResult = eclipseDittoGenerator.generate(modelProvider("MultiplTypeIm.infomodel", "MultipleTypeFb.functionblock"), InvocationContext.simpleInvocationContext(params));
    Generated generatedfile = zipFileReader(generationResult, "properties-status.schema", ".json");
    File defaultFile = new File(getClass().getClassLoader().getResource("defaultFileFormat/properties-status.schema.json").toURI());
    assertEquals(IOUtils.toString(FileUtils.openInputStream(defaultFile)), new String(generatedfile.getContent(), "utf-8"));
}
Also used : Generated(org.eclipse.vorto.plugin.generator.utils.Generated) HashMap(java.util.HashMap) IGenerationResult(org.eclipse.vorto.plugin.generator.IGenerationResult) File(java.io.File) AbstractGeneratorTest(org.eclipse.vorto.plugin.AbstractGeneratorTest) Test(org.junit.Test)

Example 24 with IGenerationResult

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

the class EclipseDittoGeneratorTest method testFunctionBlockInheritanceMultipleFunctionBlocks.

/**
 * Tests function block inheritance with multiple function blocks.
 * (please be aware that the inherited properties are missing in the
 * expected result because they are added by the flattening
 * mechanism which takes place on repository side. Its not relevant for
 * this test.)
 *
 * @throws Exception
 */
@Test
public void testFunctionBlockInheritanceMultipleFunctionBlocks() throws Exception {
    Map<String, String> params = new HashMap<>();
    params.put("target", "thingJson");
    IGenerationResult generationResult = eclipseDittoGenerator.generate(modelProvider("Battery.fbmodel", "Location.fbmodel", "Percentage.type", "RaspberryPi.infomodel", "SensorValue.type", "Temperature.fbmodel", "Voltage.fbmodel"), InvocationContext.simpleInvocationContext(params));
    assertEquals("application/json", generationResult.getMediatype());
    String expectedResult = "{\n" + "  \"definition\": \"org.eclipse.vorto.tutorials:RaspberryPi:1.0.0\",\n" + "  \"attributes\": {\n" + " \t\"modelDisplayName\": \"RaspberryPi\"\n" + " \t },\n" + " \t\"features\": {\n" + " \t\"location\" : {\n" + " \t\"definition\": [\n" + " \t \t\t\"org.eclipse.vorto:Location:1.0.0\"\n" + " \t],\n" + " \t\"properties\": {\n" + " \t\t\"status\": {\n" + " \t\t\t\"latitude\" : 0.0,\n" + " \t\t\t\"longitude\" : 0.0\n" + " \t\t}\n" + " \t}\n" + " \t},\n" + " \t\"battery\" : {\n" + " \t\"definition\": [\n" + " \t \t\t\"org.eclipse.vorto:Battery:1.0.0\",\n" + " \t \t\t\"org.eclipse.vorto:Voltage:1.0.0\"\n" + " \t],\n" + " \t\"properties\": {\n" + " \t\t\"status\": {\n" + " \t\t\t\"remainingCapacity\" : {\n" + " \t\t\t\t\"value\" : 0.0\n" + " \t\t\t}\n" + " \t\t},\n" + "\t\"configuration\": {\n" + "\t\t\"remainingCapacityAmpHour\" : 0.0\n" + "}\n" + " \t}\n" + " \t},\n" + " \t\"cpuTemperature\" : {\n" + " \t\"definition\": [\n" + " \t \t\t\"org.eclipse.vorto:Temperature:1.0.0\"\n" + " \t],\n" + " \t\"properties\": {\n" + " \t\t\"status\": {\n" + " \t\t\t\"value\" : {\n" + " \t\t\t\t\"currentMeasured\" : 0.0,\n" + " \t\t\t\t\"minMeasured\" : 0.0,\n" + " \t\t\t\t\"maxMeasured\" : 0.0\n" + " \t\t\t}\n" + " \t\t}\n" + " \t}\n" + " \t}\n" + "}\n" + "}";
    JSONAssert.assertEquals(expectedResult, new String(generationResult.getContent()), true);
}
Also used : HashMap(java.util.HashMap) IGenerationResult(org.eclipse.vorto.plugin.generator.IGenerationResult) AbstractGeneratorTest(org.eclipse.vorto.plugin.AbstractGeneratorTest) Test(org.junit.Test)

Example 25 with IGenerationResult

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

the class EclipseDittoGeneratorTest method testNonInheritanceFunctionBlock.

@Test
public void testNonInheritanceFunctionBlock() throws GeneratorException, JSONException {
    Map<String, String> params = new HashMap<>();
    params.put("target", "thingJson");
    BuilderUtils.EnumBuilder enumBuilder = BuilderUtils.newEnum(new ModelId(org.eclipse.vorto.core.api.model.model.ModelType.Datatype, "Units", "org.eclipse.vorto.types", "1.0.0"));
    enumBuilder.withLiterals("F", "C");
    FunctionblockModel fbm = BuilderUtils.newFunctionblock(new ModelId(org.eclipse.vorto.core.api.model.model.ModelType.Functionblock, "Temperature", "org.eclipse.vorto", "1.0.0")).withStatusProperty("unit", enumBuilder.build()).build();
    BuilderUtils.InformationModelBuilder informationModelBuilder = BuilderUtils.newInformationModel(new ModelId(org.eclipse.vorto.core.api.model.model.ModelType.InformationModel, "RPi", "org.eclipse.vorto", "1.0.0"));
    informationModelBuilder.withFunctionBlock(fbm, "cpuTemperature", null, false);
    IGenerationResult generationResult = eclipseDittoGenerator.generate(informationModelBuilder.build(), InvocationContext.simpleInvocationContext(params));
    String expectedResult = "{\n" + "  \"definition\": \"org.eclipse.vorto:RPi:1.0.0\",\n" + "  \"attributes\": {\n" + " \t\"modelDisplayName\": \"RPi\"\n" + " \t },\n" + " \t\"features\": {\n" + " \t\"cpuTemperature\" : {\n" + " \t\"definition\": [\n" + " \t\t\"org.eclipse.vorto:Temperature:1.0.0\"\n" + " \t],\n" + " \t\"properties\": {\n" + " \t\t\"status\": {\n" + " \t\t\t\"unit\" : \"F\"\n" + " \t\t}\n" + " \t}\n" + " \t}\n" + "}\n" + "}";
    JSONAssert.assertEquals(expectedResult, new String(generationResult.getContent()), true);
}
Also used : FunctionblockModel(org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) HashMap(java.util.HashMap) IGenerationResult(org.eclipse.vorto.plugin.generator.IGenerationResult) BuilderUtils(org.eclipse.vorto.core.api.model.BuilderUtils) ModelId(org.eclipse.vorto.core.api.model.model.ModelId) 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