Search in sources :

Example 1 with TestGeneratedModelCode

use of com.spectralogic.ds3autogen.java.utils.TestGeneratedModelCode in project ds3_autogen by SpectraLogic.

the class JavaFunctionalModels_Test method bulkObject_Test.

@Test
public void bulkObject_Test() throws IOException, TemplateModelException {
    final String modelName = "BulkObject";
    final FileUtils fileUtils = mock(FileUtils.class);
    final TestGeneratedModelCode testGeneratedModelCode = new TestGeneratedModelCode(fileUtils, modelName, "./ds3-sdk/src/main/java/com/spectralogic/ds3client/models/");
    testGeneratedModelCode.generateCode(fileUtils, "/input/bulkObjectType.xml");
    final String modelGeneratedCode = testGeneratedModelCode.getModelGeneratedCode();
    CODE_LOGGER.logFile(modelGeneratedCode, FileTypeToLog.MODEL);
    assertTrue(hasCopyright(modelGeneratedCode));
    assertTrue(isOfPackage("com.spectralogic.ds3client.models", modelGeneratedCode));
    assertTrue(hasParamAttribute("InCache", "Boolean", modelGeneratedCode));
    assertTrue(hasParamAttribute("Latest", "boolean", modelGeneratedCode));
    assertTrue(hasParamAttribute("Length", "long", modelGeneratedCode));
    assertTrue(hasParamAttribute("Name", "String", modelGeneratedCode));
    assertTrue(hasParamAttribute("Offset", "long", modelGeneratedCode));
    assertTrue(hasModelVariable("PhysicalPlacement", "PhysicalPlacement", modelGeneratedCode));
    assertTrue(hasParamAttribute("Version", "long", modelGeneratedCode));
    assertTrue(hasImport("com.fasterxml.jackson.annotation.JsonProperty", modelGeneratedCode));
    assertTrue(hasImport("com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement", modelGeneratedCode));
    assertTrue(hasImport("com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty", modelGeneratedCode));
    assertTrue(hasModelConstructor(modelName, ImmutableList.<Element>of(), modelGeneratedCode));
    assertTrue(modelGeneratedCode.contains("public int hashCode()"));
    assertTrue(modelGeneratedCode.contains("public boolean equals(final Object obj)"));
    assertTrue(modelGeneratedCode.contains("public String toString()"));
}
Also used : FileUtils(com.spectralogic.ds3autogen.api.FileUtils) TestGeneratedModelCode(com.spectralogic.ds3autogen.java.utils.TestGeneratedModelCode) Element(com.spectralogic.ds3autogen.java.models.Element) Test(org.junit.Test)

Example 2 with TestGeneratedModelCode

use of com.spectralogic.ds3autogen.java.utils.TestGeneratedModelCode in project ds3_autogen by SpectraLogic.

the class JavaFunctionalModels_Test method unusedType.

@Test
public void unusedType() throws IOException, TemplateModelException {
    final String modelName = "RequestType";
    final FileUtils fileUtils = mock(FileUtils.class);
    final TestGeneratedModelCode testGeneratedModelCode = new TestGeneratedModelCode(fileUtils, modelName, "./ds3-sdk/src/main/java/com/spectralogic/ds3client/models/");
    testGeneratedModelCode.generateCode(fileUtils, "/input/unusedType.xml");
    final String modelGeneratedCode = testGeneratedModelCode.getModelGeneratedCode();
    CODE_LOGGER.logFile(modelGeneratedCode, FileTypeToLog.MODEL);
    assertTrue(modelGeneratedCode.isEmpty());
}
Also used : FileUtils(com.spectralogic.ds3autogen.api.FileUtils) TestGeneratedModelCode(com.spectralogic.ds3autogen.java.utils.TestGeneratedModelCode) Test(org.junit.Test)

Example 3 with TestGeneratedModelCode

use of com.spectralogic.ds3autogen.java.utils.TestGeneratedModelCode in project ds3_autogen by SpectraLogic.

the class JavaFunctionalModels_Test method s3Object_Test.

@Test
public void s3Object_Test() throws IOException, TemplateModelException {
    final String modelName = "S3Object";
    final FileUtils fileUtils = mock(FileUtils.class);
    final TestGeneratedModelCode testGeneratedModelCode = new TestGeneratedModelCode(fileUtils, modelName, "./ds3-sdk/src/main/java/com/spectralogic/ds3client/models/");
    testGeneratedModelCode.generateCode(fileUtils, "/input/s3objectType.xml");
    final String modelGeneratedCode = testGeneratedModelCode.getModelGeneratedCode();
    CODE_LOGGER.logFile(modelGeneratedCode, FileTypeToLog.MODEL);
    assertTrue(hasCopyright(modelGeneratedCode));
    assertTrue(isOfPackage("com.spectralogic.ds3client.models", modelGeneratedCode));
    assertTrue(hasModelVariable("BucketId", "UUID", modelGeneratedCode));
    assertTrue(hasModelVariable("CreationDate", "Date", modelGeneratedCode));
    assertTrue(hasModelVariable("Id", "UUID", modelGeneratedCode));
    assertTrue(hasModelVariable("Latest", "boolean", modelGeneratedCode));
    assertTrue(hasModelVariable("Name", "String", modelGeneratedCode));
    assertTrue(hasModelVariable("Type", "S3ObjectType", modelGeneratedCode));
    assertTrue(hasModelVariable("Version", "long", modelGeneratedCode));
    assertTrue(hasImport("com.fasterxml.jackson.annotation.JsonProperty", modelGeneratedCode));
    assertTrue(hasImport("com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement", modelGeneratedCode));
    assertTrue(hasImport("java.util.Objects", modelGeneratedCode));
    assertTrue(hasImport("java.util.UUID", modelGeneratedCode));
    assertTrue(hasImport("java.util.Date", modelGeneratedCode));
    assertTrue(hasModelConstructor(modelName, ImmutableList.<Element>of(), modelGeneratedCode));
    assertTrue(modelGeneratedCode.contains("public int hashCode()"));
    assertTrue(modelGeneratedCode.contains("public boolean equals(final Object obj)"));
}
Also used : FileUtils(com.spectralogic.ds3autogen.api.FileUtils) TestGeneratedModelCode(com.spectralogic.ds3autogen.java.utils.TestGeneratedModelCode) Element(com.spectralogic.ds3autogen.java.models.Element) Test(org.junit.Test)

Example 4 with TestGeneratedModelCode

use of com.spectralogic.ds3autogen.java.utils.TestGeneratedModelCode in project ds3_autogen by SpectraLogic.

the class JavaFunctionalModels_Test method JobsApiBean_Test.

@Test
public void JobsApiBean_Test() throws IOException, TemplateModelException {
    //This Type is special cased AND renamed: generation relies on name detection in isJobsApiBean within JavaCodeGenerator
    final String modelName = "JobList";
    final FileUtils fileUtils = mock(FileUtils.class);
    final TestGeneratedModelCode testGeneratedModelCode = new TestGeneratedModelCode(fileUtils, modelName, "./ds3-sdk/src/main/java/com/spectralogic/ds3client/models/");
    testGeneratedModelCode.generateCode(fileUtils, "/input/jobsApiBean.xml");
    final String modelGeneratedCode = testGeneratedModelCode.getModelGeneratedCode();
    CODE_LOGGER.logFile(modelGeneratedCode, FileTypeToLog.MODEL);
    assertTrue(hasCopyright(modelGeneratedCode));
    assertTrue(isOfPackage("com.spectralogic.ds3client.models", modelGeneratedCode));
    assertTrue(modelGeneratedCode.contains("@JacksonXmlRootElement(namespace = \"Jobs\")"));
    assertTrue(modelGeneratedCode.contains("public class JobList {"));
    assertTrue(modelGeneratedCode.contains("@JsonProperty(\"Job\")"));
    assertTrue(modelGeneratedCode.contains("@JacksonXmlElementWrapper(useWrapping = false)"));
    assertTrue(modelGeneratedCode.contains("private List<Job> jobs = new ArrayList<>();"));
}
Also used : FileUtils(com.spectralogic.ds3autogen.api.FileUtils) TestGeneratedModelCode(com.spectralogic.ds3autogen.java.utils.TestGeneratedModelCode) Test(org.junit.Test)

Example 5 with TestGeneratedModelCode

use of com.spectralogic.ds3autogen.java.utils.TestGeneratedModelCode in project ds3_autogen by SpectraLogic.

the class JavaFunctionalModels_Test method emptyType.

@Test(expected = IllegalArgumentException.class)
public void emptyType() throws IOException, TemplateModelException {
    final String modelName = "EmptyType";
    final FileUtils fileUtils = mock(FileUtils.class);
    final TestGeneratedModelCode testGeneratedModelCode = new TestGeneratedModelCode(fileUtils, modelName, "./ds3-sdk/src/main/java/com/spectralogic/ds3client/models/");
    testGeneratedModelCode.generateCode(fileUtils, "/input/emptyType.xml");
}
Also used : FileUtils(com.spectralogic.ds3autogen.api.FileUtils) TestGeneratedModelCode(com.spectralogic.ds3autogen.java.utils.TestGeneratedModelCode) Test(org.junit.Test)

Aggregations

FileUtils (com.spectralogic.ds3autogen.api.FileUtils)11 TestGeneratedModelCode (com.spectralogic.ds3autogen.java.utils.TestGeneratedModelCode)11 Test (org.junit.Test)11 Element (com.spectralogic.ds3autogen.java.models.Element)4