Search in sources :

Example 26 with Generated

use of org.eclipse.vorto.plugin.generator.utils.Generated in project vorto by eclipse.

the class EclipseHonoPythonGeneratorTest method checkAPIGenerationOfEntityModel.

/*
   * Test case for checking whether the entity/enum values specified in the input datatype file are
   * available.
   * 
   */
@Test
public void checkAPIGenerationOfEntityModel() throws Exception {
    IGenerationResult generationResult = pythonGenerator.generate(modelProvider(), InvocationContext.simpleInvocationContext());
    Generated generatedfile = zipFileReader(generationResult, "MySensorApp", ".py");
    assertEquals(true, new String(generatedfile.getContent(), "utf-8").contains("unitEnum"));
}
Also used : Generated(org.eclipse.vorto.plugin.generator.utils.Generated) IGenerationResult(org.eclipse.vorto.plugin.generator.IGenerationResult) AbstractGeneratorTest(org.eclipse.vorto.plugin.AbstractGeneratorTest) Test(org.junit.Test)

Example 27 with Generated

use of org.eclipse.vorto.plugin.generator.utils.Generated in project vorto by eclipse.

the class AbstractGeneratorTest method zipFileReader.

public Generated zipFileReader(IGenerationResult generationResult, String inputTypeName, String fileExtension) throws IOException {
    ZipInputStream zipStream = new ZipInputStream(new ByteArrayInputStream(generationResult.getContent()));
    ZipEntry entry = null;
    Generated generated = null;
    while ((entry = zipStream.getNextEntry()) != null) {
        String entryName = entry.getName();
        if (entryName.contains(inputTypeName)) {
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            byte[] byteBuff = new byte[4096];
            int bytesRead = 0;
            while ((bytesRead = zipStream.read(byteBuff)) != -1) {
                out.write(byteBuff, 0, bytesRead);
            }
            out.close();
            generated = new Generated(inputTypeName + fileExtension, null, out.toByteArray());
            zipStream.closeEntry();
        }
    }
    zipStream.close();
    return generated;
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) Generated(org.eclipse.vorto.plugin.generator.utils.Generated) ByteArrayInputStream(java.io.ByteArrayInputStream) ZipEntry(java.util.zip.ZipEntry) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Aggregations

Generated (org.eclipse.vorto.plugin.generator.utils.Generated)27 AbstractGeneratorTest (org.eclipse.vorto.plugin.AbstractGeneratorTest)26 IGenerationResult (org.eclipse.vorto.plugin.generator.IGenerationResult)26 Test (org.junit.Test)26 File (java.io.File)16 InvocationContext (org.eclipse.vorto.plugin.generator.InvocationContext)3 HashMap (java.util.HashMap)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ZipEntry (java.util.zip.ZipEntry)1 ZipInputStream (java.util.zip.ZipInputStream)1