Search in sources :

Example 21 with TestGenerateCode

use of com.spectralogic.ds3autogen.net.utils.TestGenerateCode in project ds3_autogen by SpectraLogic.

the class NetCodeGenerator_Test method createObjectRequest.

@Test
public void createObjectRequest() throws IOException, TemplateModelException {
    final String requestName = "PutObjectRequest";
    final FileUtils fileUtils = mock(FileUtils.class);
    final TestGenerateCode codeGenerator = new TestGenerateCode(fileUtils, requestName, "./Ds3/Calls/");
    codeGenerator.generateCode(fileUtils, "/input/createObjectRequest.xml");
    final String requestCode = codeGenerator.getRequestCode();
    CODE_LOGGER.logFile(requestCode, FileTypeToLog.REQUEST);
    assertTrue(TestHelper.extendsClass(requestName, "Ds3Request", requestCode));
    assertTrue(TestHelper.hasProperty("Verb", "HttpVerb", requestCode));
    assertTrue(TestHelper.hasProperty("Path", "string", requestCode));
    assertTrue(TestHelper.hasRequiredParam("BucketName", "string", requestCode));
    assertTrue(TestHelper.hasRequiredParam("ObjectName", "string", requestCode));
    assertTrue(TestHelper.hasOptionalParam(requestName, "Job", "Guid", requestCode));
    assertTrue(TestHelper.hasOptionalParam(requestName, "Offset", "long", requestCode));
    assertTrue(requestCode.contains("private readonly Stream RequestPayload;"));
    assertTrue(requestCode.contains("internal override Stream GetContentStream()"));
    assertTrue(hasOptionalChecksum(requestName, requestCode));
    assertTrue(hasOptionalMetadata(requestName, requestCode));
    final ImmutableList.Builder<Arguments> constructorArgs = ImmutableList.builder();
    constructorArgs.add(new Arguments("String", "BucketName"));
    constructorArgs.add(new Arguments("String", "ObjectName"));
    constructorArgs.add(new Arguments("Stream", "RequestPayload"));
    assertTrue(TestHelper.hasConstructor(requestName, constructorArgs.build(), requestCode));
    constructorArgs.add(new Arguments("long", "Length"));
    assertTrue(TestHelper.hasConstructor(requestName, constructorArgs.build(), requestCode));
    //Generate Client code
    final String commandName = requestName.replace("Request", "");
    final String clientCode = codeGenerator.getClientCode();
    CODE_LOGGER.logFile(clientCode, FileTypeToLog.CLIENT);
    assertTrue(TestHelper.hasVoidCommand(commandName, clientCode));
    final String idsClientCode = codeGenerator.getIdsClientCode();
    CODE_LOGGER.logFile(idsClientCode, FileTypeToLog.CLIENT);
    assertTrue(TestHelper.hasIDsCommand(commandName, idsClientCode));
    //Generate Responses (should be empty due to no response payload)
    final String responseCode = codeGenerator.getResponseCode();
    assertTrue(isEmpty(responseCode));
    //Generate Parser
    final String parserCode = codeGenerator.getParserCode();
    CODE_LOGGER.logFile(parserCode, FileTypeToLog.PARSER);
    assertTrue(isEmpty(parserCode));
}
Also used : TestGenerateCode(com.spectralogic.ds3autogen.net.utils.TestGenerateCode) FileUtils(com.spectralogic.ds3autogen.api.FileUtils) ImmutableList(com.google.common.collect.ImmutableList) Arguments(com.spectralogic.ds3autogen.api.models.Arguments) Test(org.junit.Test)

Example 22 with TestGenerateCode

use of com.spectralogic.ds3autogen.net.utils.TestGenerateCode in project ds3_autogen by SpectraLogic.

the class NetCodeGenerator_Test method simpleRequest.

@Test
public void simpleRequest() throws IOException, TemplateModelException {
    final String requestName = "GetObjectRequest";
    final FileUtils fileUtils = mock(FileUtils.class);
    final TestGenerateCode codeGenerator = new TestGenerateCode(fileUtils, requestName, "./Ds3/Calls/");
    codeGenerator.generateCode(fileUtils, "/input/singleRequestHandler.xml");
    final String requestCode = codeGenerator.getRequestCode();
    CODE_LOGGER.logFile(requestCode, FileTypeToLog.REQUEST);
    assertTrue(TestHelper.extendsClass("GetObjectRequest", "Ds3Request", requestCode));
    assertTrue(TestHelper.hasProperty("Verb", "HttpVerb", requestCode));
    assertTrue(TestHelper.hasProperty("Path", "string", requestCode));
    //Generate Parser
    final String parserCode = codeGenerator.getParserCode();
    CODE_LOGGER.logFile(parserCode, FileTypeToLog.PARSER);
    assertTrue(hasContent(parserCode));
}
Also used : TestGenerateCode(com.spectralogic.ds3autogen.net.utils.TestGenerateCode) FileUtils(com.spectralogic.ds3autogen.api.FileUtils) Test(org.junit.Test)

Example 23 with TestGenerateCode

use of com.spectralogic.ds3autogen.net.utils.TestGenerateCode in project ds3_autogen by SpectraLogic.

the class NetCodeGenerator_Test method getJobsRequest_Test.

@Test
public void getJobsRequest_Test() throws IOException, TemplateModelException {
    final String requestName = "GetJobsSpectraS3Request";
    final FileUtils fileUtils = mock(FileUtils.class);
    final TestGenerateCode codeGenerator = new TestGenerateCode(fileUtils, requestName, "./Ds3/Calls/", "JobList");
    codeGenerator.generateCode(fileUtils, "/input/getJobsRequest.xml");
    //Generate Request code
    final String requestCode = codeGenerator.getRequestCode();
    CODE_LOGGER.logFile(requestCode, FileTypeToLog.REQUEST);
    assertTrue(TestHelper.extendsClass(requestName, "Ds3Request", requestCode));
    assertTrue(TestHelper.hasProperty("Verb", "HttpVerb", requestCode));
    assertTrue(TestHelper.hasProperty("Path", "string", requestCode));
    assertTrue(TestHelper.hasOptionalParam(requestName, "BucketId", "Guid", requestCode));
    assertTrue(TestHelper.hasOptionalParam(requestName, "FullDetails", "bool", requestCode));
    assertTrue(TestHelper.hasConstructor(requestName, ImmutableList.of(), requestCode));
    //Generate Client code
    final String commandName = requestName.replace("Request", "");
    final String clientCode = codeGenerator.getClientCode();
    CODE_LOGGER.logFile(clientCode, FileTypeToLog.CLIENT);
    assertTrue(TestHelper.hasPayloadCommand(commandName, clientCode));
    final String idsClientCode = codeGenerator.getIdsClientCode();
    CODE_LOGGER.logFile(idsClientCode, FileTypeToLog.CLIENT);
    assertTrue(TestHelper.hasIDsCommand(commandName, idsClientCode));
    //Generate Responses
    final String responseCode = codeGenerator.getResponseCode();
    CODE_LOGGER.logFile(responseCode, FileTypeToLog.RESPONSE);
    final String responseName = NormalizingContractNamesUtil.toResponseName(requestName);
    final String responsePayloadType = "JobList";
    assertTrue(TestHelper.hasConstructor(responseName, ImmutableList.of(new Arguments(responsePayloadType, "ResponsePayload")), responseCode));
    assertTrue(TestHelper.hasRequiredParam("ResponsePayload", responsePayloadType, responseCode));
    //Generate Parser
    final String parserCode = codeGenerator.getParserCode();
    CODE_LOGGER.logFile(parserCode, FileTypeToLog.PARSER);
    assertTrue(parserHasResponseCode(200, parserCode));
    assertTrue(parserHasPayload("JobList", "Jobs", parserCode));
}
Also used : TestGenerateCode(com.spectralogic.ds3autogen.net.utils.TestGenerateCode) FileUtils(com.spectralogic.ds3autogen.api.FileUtils) Arguments(com.spectralogic.ds3autogen.api.models.Arguments) Test(org.junit.Test)

Example 24 with TestGenerateCode

use of com.spectralogic.ds3autogen.net.utils.TestGenerateCode in project ds3_autogen by SpectraLogic.

the class NetCodeGenerator_Test method getObjectsDetailsSpectraS3Request_Test.

@Test
public void getObjectsDetailsSpectraS3Request_Test() throws IOException, TemplateModelException {
    final String requestName = "GetObjectsDetailsSpectraS3Request";
    final FileUtils fileUtils = mock(FileUtils.class);
    final TestGenerateCode codeGenerator = new TestGenerateCode(fileUtils, requestName, "./Ds3/Calls/", "S3ObjectList");
    codeGenerator.generateCode(fileUtils, "/input/getObjectsDetailsRequest.xml");
    //Generate Request code
    final String requestCode = codeGenerator.getRequestCode();
    CODE_LOGGER.logFile(requestCode, FileTypeToLog.REQUEST);
    assertTrue(TestHelper.extendsClass(requestName, "Ds3Request", requestCode));
    assertTrue(TestHelper.hasProperty("Verb", "HttpVerb", requestCode));
    assertTrue(TestHelper.hasProperty("Path", "string", requestCode));
    assertTrue(TestHelper.hasOptionalParam(requestName, "BucketId", "string", requestCode));
    assertTrue(TestHelper.hasOptionalParam(requestName, "Folder", "string", requestCode));
    assertTrue(TestHelper.hasOptionalParam(requestName, "LastPage", "bool?", requestCode));
    assertTrue(TestHelper.hasOptionalParam(requestName, "Latest", "bool?", requestCode));
    assertTrue(TestHelper.hasOptionalParam(requestName, "Name", "string", requestCode));
    assertTrue(TestHelper.hasOptionalParam(requestName, "PageLength", "int?", requestCode));
    assertTrue(TestHelper.hasOptionalParam(requestName, "PageOffset", "int?", requestCode));
    assertTrue(TestHelper.hasOptionalParam(requestName, "PageStartMarker", "string", requestCode));
    assertTrue(TestHelper.hasOptionalParam(requestName, "Type", "S3ObjectType", requestCode));
    assertTrue(TestHelper.hasOptionalParam(requestName, "Version", "long?", requestCode));
    assertTrue(TestHelper.hasConstructor(requestName, ImmutableList.of(), requestCode));
    //Generate Client code
    final String commandName = requestName.replace("Request", "");
    final String clientCode = codeGenerator.getClientCode();
    CODE_LOGGER.logFile(clientCode, FileTypeToLog.CLIENT);
    assertTrue(TestHelper.hasPayloadCommand(commandName, clientCode));
    final String idsClientCode = codeGenerator.getIdsClientCode();
    CODE_LOGGER.logFile(idsClientCode, FileTypeToLog.CLIENT);
    assertTrue(TestHelper.hasIDsCommand(commandName, idsClientCode));
    //Generate Responses
    final String responseCode = codeGenerator.getResponseCode();
    CODE_LOGGER.logFile(responseCode, FileTypeToLog.RESPONSE);
    assertTrue(responseCode.contains("public GetObjectsDetailsSpectraS3Response(S3ObjectList responsePayload, int? pagingTruncated, int? pagingTotalResultCount)"));
    //Generate Parser
    final String parserCode = codeGenerator.getParserCode();
    CODE_LOGGER.logFile(parserCode, FileTypeToLog.PARSER);
    assertTrue(parserHasResponseCode(200, parserCode));
    assertTrue(parserHasPayload("S3ObjectList", "Data", parserCode));
}
Also used : TestGenerateCode(com.spectralogic.ds3autogen.net.utils.TestGenerateCode) FileUtils(com.spectralogic.ds3autogen.api.FileUtils) Test(org.junit.Test)

Example 25 with TestGenerateCode

use of com.spectralogic.ds3autogen.net.utils.TestGenerateCode in project ds3_autogen by SpectraLogic.

the class NetCodeGenerator_ModelParsers_Test method bucketObjectApiBean_Test.

@Test
public void bucketObjectApiBean_Test() throws IOException, TemplateModelException {
    final FileUtils fileUtils = mock(FileUtils.class);
    final TestGenerateCode codeGenerator = new TestGenerateCode(fileUtils, "GetBucketRequest", "./Ds3/Calls/", "ListBucketResult");
    codeGenerator.generateCode(fileUtils, "/input/modelparsing/modelParsingSimpleType.xml");
    final String typeParserCode = codeGenerator.getTypeParser();
    CODE_LOGGER.logFile(typeParserCode, FileTypeToLog.MODEL_PARSERS);
    assertTrue(typeParserCode.contains("public static ListBucketResult ParseListBucketResult(XElement element)"));
    assertTrue(typeParserCode.contains("public static ListBucketResult ParseNullableListBucketResult(XElement element)"));
    assertTrue(typeParserCode.contains("BucketName = ParseNullableString(element.AttributeTextOrNull(\"BucketName\"))"));
    assertTrue(typeParserCode.contains("Truncated = ParseBool(element.Element(\"IsTruncated\"))"));
    assertTrue(typeParserCode.contains("TruncatedNullable = ParseNullableBool(element.Element(\"IsTruncated\"))"));
    assertTrue(typeParserCode.contains("MaxKeys = ParseInt(element.Element(\"MaxKeys\"))"));
    assertTrue(typeParserCode.contains("MaxKeysNullable = ParseNullableInt(element.Element(\"MaxKeysNullable\"))"));
    assertTrue(typeParserCode.contains("CreationDate = ParseDateTime(element.Element(\"CreationDate\"))"));
    assertTrue(typeParserCode.contains("CreationDateNullable = ParseNullableDateTime(element.Element(\"CreationDateNullable\"))"));
    assertTrue(typeParserCode.contains("Delimiter = ParseNullableString(element.Element(\"Delimiter\"))"));
    assertTrue(typeParserCode.contains("CommonPrefixes = ParseEncapsulatedList(element, \"Prefix\", \"CommonPrefixes\", ParseString)"));
    assertTrue(typeParserCode.contains("Objects = element.Elements(\"Contents\").Select(ParseContents).ToList()"));
    assertTrue(typeParserCode.contains("Buckets = ParseEncapsulatedList(element, \"Bucket\", \"Buckets\", ParseBucketDetails)"));
}
Also used : TestGenerateCode(com.spectralogic.ds3autogen.net.utils.TestGenerateCode) FileUtils(com.spectralogic.ds3autogen.api.FileUtils) Test(org.junit.Test)

Aggregations

FileUtils (com.spectralogic.ds3autogen.api.FileUtils)34 TestGenerateCode (com.spectralogic.ds3autogen.net.utils.TestGenerateCode)34 Test (org.junit.Test)34 Arguments (com.spectralogic.ds3autogen.api.models.Arguments)21 ImmutableList (com.google.common.collect.ImmutableList)1 Ds3DocSpec (com.spectralogic.ds3autogen.api.models.docspec.Ds3DocSpec)1 Ds3DocSpecImpl (com.spectralogic.ds3autogen.docspec.Ds3DocSpecImpl)1