Search in sources :

Example 86 with FileUtils

use of com.spectralogic.ds3autogen.api.FileUtils in project ds3_autogen by SpectraLogic.

the class JavaFunctionalTests method singleRequestHandler.

@Test
public void singleRequestHandler() throws IOException, TemplateModelException {
    final String requestName = "GetObjectRequest";
    final FileUtils fileUtils = mock(FileUtils.class);
    final TestGeneratedCode testGeneratedCode = new TestGeneratedCode(fileUtils, requestName, "./ds3-sdk/src/main/java/com/spectralogic/ds3client/commands/");
    testGeneratedCode.generateCode(fileUtils, "/input/singleRequestHandler.xml");
    final String requestGeneratedCode = testGeneratedCode.getRequestGeneratedCode();
    CODE_LOGGER.logFile(requestGeneratedCode, FileTypeToLog.REQUEST);
    assertTrue(extendsClass(requestName, "AbstractRequest", requestGeneratedCode));
    final String responseGeneratedCode = testGeneratedCode.getResponseGeneratedCode();
    CODE_LOGGER.logFile(responseGeneratedCode, FileTypeToLog.RESPONSE);
    final String responseName = requestName.replace("Request", "Response");
    assertTrue(extendsClass(responseName, "AbstractResponse", responseGeneratedCode));
    final String ds3ClientGeneratedCode = testGeneratedCode.getDs3ClientGeneratedCode();
    CODE_LOGGER.logFile(ds3ClientGeneratedCode, FileTypeToLog.CLIENT);
    testDs3Client(requestName, ds3ClientGeneratedCode);
    final String ds3ClientImplGeneratedCode = testGeneratedCode.getDs3ClientImplGeneratedCode();
    CODE_LOGGER.logFile(ds3ClientImplGeneratedCode, FileTypeToLog.CLIENT);
    testDs3ClientImpl(requestName, ds3ClientImplGeneratedCode);
    final String responseParserCode = testGeneratedCode.getResponseParserGeneratedCode();
    CODE_LOGGER.logFile(responseParserCode, FileTypeToLog.PARSER);
    assertTrue(isOfPackage("com.spectralogic.ds3client.commands.parsers", responseParserCode));
}
Also used : TestGeneratedCode(com.spectralogic.ds3autogen.java.utils.TestGeneratedCode) FileUtils(com.spectralogic.ds3autogen.api.FileUtils) Test(org.junit.Test)

Example 87 with FileUtils

use of com.spectralogic.ds3autogen.api.FileUtils in project ds3_autogen by SpectraLogic.

the class JavaFunctionalTests method getBucketsSpectraS3_Test.

@Test
public void getBucketsSpectraS3_Test() throws IOException, TemplateModelException {
    final String requestName = "GetBucketsSpectraS3Request";
    final FileUtils fileUtils = mock(FileUtils.class);
    final TestGeneratedComponentResponseCode testGeneratedCode = new TestGeneratedComponentResponseCode(fileUtils, requestName, "./ds3-sdk/src/main/java/com/spectralogic/ds3client/commands/spectrads3/", "./ds3-sdk/src/main/java/com/spectralogic/ds3client/models/BucketList.java");
    testGeneratedCode.generateCode(fileUtils, "/input/getBucketsSpectraS3.xml");
    final String requestGeneratedCode = testGeneratedCode.getRequestGeneratedCode();
    CODE_LOGGER.logFile(requestGeneratedCode, FileTypeToLog.REQUEST);
    //Verify that name mapped from GetBuckets to GetService
    assertTrue(extendsClass(requestName, "AbstractPaginationRequest", requestGeneratedCode));
    //Test the generated response
    final String responseGeneratedCode = testGeneratedCode.getResponseGeneratedCode();
    CODE_LOGGER.logFile(responseGeneratedCode, FileTypeToLog.RESPONSE);
    final String responseName = requestName.replace("Request", "Response");
    assertTrue(extendsClass(responseName, "AbstractPaginationResponse", responseGeneratedCode));
    assertTrue(isReqParamOfType("bucketListResult", "BucketList", responseName, responseGeneratedCode, false));
    assertTrue(isReqParamOfType("pagingTotalResultCount", "Integer", responseName, responseGeneratedCode, true));
    assertTrue(isReqParamOfType("pagingTruncated", "Integer", responseName, responseGeneratedCode, true));
    //Test the Ds3Client
    final String ds3ClientGeneratedCode = testGeneratedCode.getDs3ClientGeneratedCode();
    CODE_LOGGER.logFile(ds3ClientGeneratedCode, FileTypeToLog.CLIENT);
    testDs3Client(requestName, ds3ClientGeneratedCode);
    assertTrue(ds3ClientGeneratedCode.contains("@ResponsePayloadModel(\"BucketList\")"));
    assertTrue(ds3ClientGeneratedCode.contains("@Action(\"LIST\")"));
    assertTrue(ds3ClientGeneratedCode.contains("@Resource(\"BUCKET\")"));
    final String ds3ClientImplGeneratedCode = testGeneratedCode.getDs3ClientImplGeneratedCode();
    CODE_LOGGER.logFile(ds3ClientImplGeneratedCode, FileTypeToLog.CLIENT);
    testDs3ClientImpl(requestName, ds3ClientImplGeneratedCode);
    //Test the response parser
    final String responseParserCode = testGeneratedCode.getResponseParserGeneratedCode();
    CODE_LOGGER.logFile(responseParserCode, FileTypeToLog.PARSER);
    assertTrue(isOfPackage("com.spectralogic.ds3client.commands.parsers", responseParserCode));
    assertTrue(hasImport("com.spectralogic.ds3client.commands.spectrads3." + responseName, responseParserCode));
    assertTrue(hasImport("com.spectralogic.ds3client.commands.parsers.interfaces.AbstractResponseParser", responseParserCode));
    assertTrue(hasImport("com.spectralogic.ds3client.models.BucketList", responseParserCode));
    assertTrue(hasImport("com.spectralogic.ds3client.networking.WebResponse", responseParserCode));
    assertTrue(hasImport("com.spectralogic.ds3client.serializer.XmlOutput", responseParserCode));
    assertTrue(hasImport("java.io.IOException", responseParserCode));
    assertTrue(hasImport("java.io.InputStream", responseParserCode));
    assertTrue(hasImport("com.spectralogic.ds3client.commands.parsers.utils.ResponseParserUtils", responseParserCode));
    final BaseParseResponse expectedParsing = new BaseParseResponse(responseName, "BucketList", true);
    assertTrue(responseParserCode.contains(expectedParsing.toJavaCode()));
    assertTrue(responseParserCode.contains("private final int[] expectedStatusCodes = new int[]{200};"));
}
Also used : TestGeneratedComponentResponseCode(com.spectralogic.ds3autogen.java.utils.TestGeneratedComponentResponseCode) FileUtils(com.spectralogic.ds3autogen.api.FileUtils) BaseParseResponse(com.spectralogic.ds3autogen.java.models.parseresponse.BaseParseResponse) Test(org.junit.Test)

Example 88 with FileUtils

use of com.spectralogic.ds3autogen.api.FileUtils in project ds3_autogen by SpectraLogic.

the class JavaFunctionalModels_Test method physicalPlacementApiBeanModel.

@Test
public void physicalPlacementApiBeanModel() throws IOException, TemplateModelException {
    final String modelName = "PhysicalPlacement";
    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/PhysicalPlacementApiBeanType.xml");
    final String modelGeneratedCode = testGeneratedModelCode.getModelGeneratedCode();
    CODE_LOGGER.logFile(modelGeneratedCode, FileTypeToLog.MODEL);
    assertTrue(hasCopyright(modelGeneratedCode));
    assertTrue(isOfPackage("com.spectralogic.ds3client.models", modelGeneratedCode));
    assertTrue(hasModelVariable("Pools", "Pools", "List<Pool>", true, modelGeneratedCode));
    assertTrue(hasModelVariable("Tapes", "Tapes", "List<Tape>", true, modelGeneratedCode));
    assertTrue(hasImport("com.fasterxml.jackson.annotation.JsonProperty", modelGeneratedCode));
    assertTrue(hasImport("com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper", modelGeneratedCode));
    assertFalse(hasImport("com.spectralogic.ds3client.models.Pool", modelGeneratedCode));
    assertFalse(hasImport("com.spectralogic.ds3client.models.Tape", modelGeneratedCode));
    assertTrue(hasImport("java.util.List", modelGeneratedCode));
    final ImmutableList<Element> constructorArgs = ImmutableList.of(new Element("Pools", "array", "Pool"), new Element("Tapes", "array", "Tape"));
    assertFalse(hasModelConstructor(modelName, constructorArgs, modelGeneratedCode));
    assertTrue(hasModelConstructor(modelName, ImmutableList.<Element>of(), modelGeneratedCode));
}
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 89 with FileUtils

use of com.spectralogic.ds3autogen.api.FileUtils in project ds3_autogen by SpectraLogic.

the class JavaFunctionalModels_Test method blobStoreTaskPriority.

@Test
public void blobStoreTaskPriority() throws IOException, TemplateModelException {
    final String modelName = "Priority";
    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/BlobStoreTaskPriorityType.xml");
    final String modelGeneratedCode = testGeneratedModelCode.getModelGeneratedCode();
    CODE_LOGGER.logFile(modelGeneratedCode, FileTypeToLog.MODEL);
    assertTrue(hasCopyright(modelGeneratedCode));
    assertTrue(isOfPackage("com.spectralogic.ds3client.models", modelGeneratedCode));
    assertTrue(TestHelper.isEnumClass(modelName, modelGeneratedCode));
    assertTrue(TestHelper.enumContainsValue("CRITICAL", modelGeneratedCode));
    assertTrue(TestHelper.enumContainsValue("URGENT", modelGeneratedCode));
    assertTrue(TestHelper.enumContainsValue("HIGH", modelGeneratedCode));
    assertTrue(TestHelper.enumContainsValue("NORMAL", modelGeneratedCode));
    assertTrue(TestHelper.enumContainsValue("LOW", modelGeneratedCode));
    assertTrue(TestHelper.enumContainsValue("BACKGROUND", modelGeneratedCode));
}
Also used : FileUtils(com.spectralogic.ds3autogen.api.FileUtils) TestGeneratedModelCode(com.spectralogic.ds3autogen.java.utils.TestGeneratedModelCode) Test(org.junit.Test)

Example 90 with FileUtils

use of com.spectralogic.ds3autogen.api.FileUtils in project ds3_autogen by SpectraLogic.

the class JavaFunctionalModels_Test method httpErrorResultApiBean_Test.

@Test
public void httpErrorResultApiBean_Test() throws IOException, TemplateModelException {
    final String modelName = "Error";
    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/httpErrorResultApiBean.xml");
    final String modelGeneratedCode = testGeneratedModelCode.getModelGeneratedCode();
    CODE_LOGGER.logFile(modelGeneratedCode, FileTypeToLog.MODEL);
    assertTrue(hasCopyright(modelGeneratedCode));
    assertTrue(isOfPackage("com.spectralogic.ds3client.models", modelGeneratedCode));
    assertTrue(hasModelVariable("Code", "String", modelGeneratedCode));
    assertTrue(hasModelVariable("HttpErrorCode", "int", modelGeneratedCode));
    assertTrue(hasModelVariable("Message", "String", modelGeneratedCode));
    assertTrue(hasModelVariable("Resource", "String", modelGeneratedCode));
    assertTrue(hasModelVariable("ResourceId", "long", modelGeneratedCode));
    assertTrue(hasImport("com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement", modelGeneratedCode));
    assertTrue(hasImport("com.fasterxml.jackson.annotation.JsonProperty", modelGeneratedCode));
    assertTrue(hasImport("com.fasterxml.jackson.annotation.JsonIgnoreProperties", modelGeneratedCode));
    assertTrue(modelGeneratedCode.contains("@JsonIgnoreProperties(ignoreUnknown = true)"));
    assertTrue(modelGeneratedCode.contains("public String toString()"));
}
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)113 Test (org.junit.Test)112 Arguments (com.spectralogic.ds3autogen.api.models.Arguments)46 TestGenerateCode (com.spectralogic.ds3autogen.net.utils.TestGenerateCode)34 TestGeneratedCode (com.spectralogic.ds3autogen.java.utils.TestGeneratedCode)30 GoTestCodeUtil (com.spectralogic.ds3autogen.go.utils.GoTestCodeUtil)19 BaseParseResponse (com.spectralogic.ds3autogen.java.models.parseresponse.BaseParseResponse)18 TestGeneratedModelCode (com.spectralogic.ds3autogen.java.utils.TestGeneratedModelCode)11 TestPythonGeneratedCode (com.spectralogic.ds3autogen.python.utils.TestPythonGeneratedCode)10 EmptyParseResponse (com.spectralogic.ds3autogen.java.models.parseresponse.EmptyParseResponse)5 TypeContent (com.spectralogic.ds3autogen.python.model.type.TypeContent)5 TypeElementList (com.spectralogic.ds3autogen.python.model.type.TypeElementList)5 ImmutableList (com.google.common.collect.ImmutableList)4 Ds3DocSpec (com.spectralogic.ds3autogen.api.models.docspec.Ds3DocSpec)4 Element (com.spectralogic.ds3autogen.java.models.Element)4 TestGeneratedComponentResponseCode (com.spectralogic.ds3autogen.java.utils.TestGeneratedComponentResponseCode)4 Ds3DocSpecImpl (com.spectralogic.ds3autogen.docspec.Ds3DocSpecImpl)3 TypeElement (com.spectralogic.ds3autogen.python.model.type.TypeElement)3 Ds3SpecParserImpl (com.spectralogic.ds3autogen.Ds3SpecParserImpl)2 CodeGenerator (com.spectralogic.ds3autogen.api.CodeGenerator)2