EclipseHonoJavaGenerator implements ICodeGenerator { @Override public IGenerationResult generate(InformationModel model, InvocationContext context) throws GeneratorException { GenerationResultZip output = new GenerationResultZip(model, "hono-java"); GenerationResultBuilder result = GenerationResultBuilder.from(output); result.append(generateJava(model, context)); return output; }  @Override IGenerationResult generate(InformationModel model, InvocationContext context); @Override GeneratorPluginInfo getMeta();  }
@Test public void checkAPIStatusPropertiesInFunctionBlock() throws Exception { IGenerationResult generationResult = eclipseHonoJavaGenerator.generate(modelProvider(), InvocationContext.simpleInvocationContext()); Generated generatedfile = zipFileReader(generationResult, "StatusPropertiesFunctionBlock", ".java"); File defaultFile = new File(getClass().getClassLoader() .getResource("defaultFileFormat/StatusPropertiesFunctionBlock.java").toURI()); assertEquals(IOUtils.toString(FileUtils.openInputStream(defaultFile)), new String(generatedfile.getContent(), "utf-8")); }
@Test public void checkAPIConfigPropertiesInFunctionBlock() throws Exception { IGenerationResult generationResult = eclipseHonoJavaGenerator.generate(modelProvider(), InvocationContext.simpleInvocationContext()); Generated generatedfile = zipFileReader(generationResult, "ConfigPropertiesFunctionBlock", ".java"); File defaultFile = new File(getClass().getClassLoader() .getResource("defaultFileFormat/ConfigPropertiesFunctionBlock.java").toURI()); assertEquals(IOUtils.toString(FileUtils.openInputStream(defaultFile)), new String(generatedfile.getContent(), "utf-8")); }
@Test public void checkAPIGenerationOfEnumModel() throws Exception { IGenerationResult generationResult = eclipseHonoJavaGenerator.generate(modelProvider(), InvocationContext.simpleInvocationContext()); Generated generatedfile = zipFileReader(generationResult, "UnitEnum", ".java"); File defaultFile = new File( getClass().getClassLoader().getResource("defaultFileFormat/ValidEnum.java").toURI()); assertEquals(IOUtils.toString(FileUtils.openInputStream(defaultFile)), new String(generatedfile.getContent(), "utf-8")); }
@Test public void checkAPIGenerationOfEntityModel() throws Exception { IGenerationResult generationResult = eclipseHonoJavaGenerator.generate(modelProvider(), InvocationContext.simpleInvocationContext()); Generated generatedfile = zipFileReader(generationResult, "UnitEntity", ".java"); File defaultFile = new File( getClass().getClassLoader().getResource("defaultFileFormat/ValidEntity.java").toURI()); assertEquals(IOUtils.toString(FileUtils.openInputStream(defaultFile)), new String(generatedfile.getContent(), "utf-8")); }
@Test public void testAPIFunctionBlockWithEvents() throws Exception { IGenerationResult generationResult = eclipseHonoJavaGenerator.generate(modelProvider(), InvocationContext.simpleInvocationContext()); Generated generatedfile = zipFileReader(generationResult, "eventsAndOperationsFunctionBlock", ".java"); assertEquals(false, new String(generatedfile.getContent(), "utf-8").contains("testEvent")); }
@Test public void testAPIFunctionBlockWithOperations() throws Exception { IGenerationResult generationResult = eclipseHonoJavaGenerator.generate(modelProvider(), InvocationContext.simpleInvocationContext()); Generated generatedfile = zipFileReader(generationResult, "eventsAndOperationsFunctionBlock", ".java"); assertEquals(false, new String(generatedfile.getContent(), "utf-8").contains("testOperation")); }
@Test public void testConnectorGeneratedMQTTClient() throws GeneratorException, IOException, URISyntaxException { IGenerationResult generationResult = eclipseHonoJavaGenerator.generate(modelProvider(), InvocationContext.simpleInvocationContext()); File defaultFileHonoDataService = new File(getClass().getClassLoader() .getResource("defaultFileFormat/HonoDataService_MQTT.java").toURI()); File defaultFileHonoMqttClient = new File( getClass().getClassLoader().getResource("defaultFileFormat/HonoMqttClient.java").toURI()); Generated generatedFileHonoDataService = zipFileReader(generationResult, "HonoDataService", ".java"); Generated generatedFileHonoMqttClient = zipFileReader(generationResult, "HonoMqttClient", ".java"); assertEquals(IOUtils.toString(FileUtils.openInputStream(defaultFileHonoMqttClient)), new String(generatedFileHonoMqttClient.getContent(), "utf-8")); }
@Test public void testClientAppGeneratedModels() throws GeneratorException, IOException, URISyntaxException { IGenerationResult generationResult = eclipseHonoJavaGenerator.generate(modelProvider(), InvocationContext.simpleInvocationContext()); Generated generatedfile = zipFileReader(generationResult, "MySensorApp", ".java"); File defaultFile = new File(getClass().getClassLoader().getResource("defaultFileFormat/MainApp.java").toURI()); assertEquals(IOUtils.toString(FileUtils.openInputStream(defaultFile)), new String(generatedfile.getContent(), "utf-8")); }
@Ignore @Test(expected = ParsingException.class) public void checkAPIEmptyNamespaceInfomodelHono() throws Exception { InformationModel emptyNameSpaceInfomodel = BuilderUtils.newInformationModel( new ModelId(org.eclipse.vorto.core.api.model.model.ModelType.InformationModel, "emptyNameSpaceInfomodel", "", "1.0.0")) .build(); IGenerationResult generationResult = eclipseHonoJavaGenerator.generate(emptyNameSpaceInfomodel, InvocationContext.simpleInvocationContext()); }