Search in sources :

Example 76 with Arguments

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

the class BaseRequestGenerator_Test method toOptionalArgumentsList_List_Test.

@Test
public void toOptionalArgumentsList_List_Test() {
    final ImmutableList<Ds3Param> params = ImmutableList.of(new Ds3Param("ArgOne", "TypeOne", true), new Ds3Param("ArgTwo", "TypeTwo", false));
    final ImmutableList<Arguments> result = generator.toOptionalArgumentsList(params);
    assertThat(result.size(), is(2));
    assertThat(result.get(0).getName(), is("ArgOne"));
    assertThat(result.get(0).getType(), is("TypeOne"));
    assertThat(result.get(1).getName(), is("ArgTwo"));
    assertThat(result.get(1).getType(), is("TypeTwo"));
}
Also used : Ds3Param(com.spectralogic.ds3autogen.api.models.apispec.Ds3Param) Arguments(com.spectralogic.ds3autogen.api.models.Arguments) Test(org.junit.Test)

Example 77 with Arguments

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

the class BaseRequestGenerator_Test method toQueryParam_VoidParam_Test.

@Test
public void toQueryParam_VoidParam_Test() {
    final Arguments arg = new Arguments("void", "VoidArg");
    final QueryParam result = toQueryParam(arg);
    assertThat(result, instanceOf(VoidQueryParam.class));
    assertThat(result.getName(), is("void_arg"));
    assertThat(result.getAssignment(), is("None"));
}
Also used : BaseQueryParam(com.spectralogic.ds3autogen.python.model.request.queryparam.BaseQueryParam) VoidQueryParam(com.spectralogic.ds3autogen.python.model.request.queryparam.VoidQueryParam) OperationQueryParam(com.spectralogic.ds3autogen.python.model.request.queryparam.OperationQueryParam) QueryParam(com.spectralogic.ds3autogen.python.model.request.queryparam.QueryParam) Arguments(com.spectralogic.ds3autogen.api.models.Arguments) VoidQueryParam(com.spectralogic.ds3autogen.python.model.request.queryparam.VoidQueryParam) Test(org.junit.Test)

Example 78 with Arguments

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

the class PutObjectRequestGenerator method toRequiredConstructorParams.

/**
     * Gets the sorted list of required constructor params, including stream and length
     */
@Override
public ImmutableList<ConstructorParam> toRequiredConstructorParams(final Ds3Request ds3Request) {
    final ImmutableList.Builder<Arguments> builder = ImmutableList.builder();
    builder.addAll(getNonVoidArgsFromParamList(ds3Request.getRequiredQueryParams()));
    builder.addAll(getAssignmentArguments(ds3Request));
    builder.add(new Arguments("", "stream"));
    builder.add(new Arguments("", "length"));
    return builder.build().stream().sorted(new CustomArgumentComparator()).map(arg -> new ConstructorParam(camelToUnderscore(arg.getName()), false)).collect(GuavaCollectors.immutableList());
}
Also used : Arguments(com.spectralogic.ds3autogen.api.models.Arguments) RequestConverterUtil.getNonVoidArgsFromParamList(com.spectralogic.ds3autogen.utils.RequestConverterUtil.getNonVoidArgsFromParamList) Helper.camelToUnderscore(com.spectralogic.ds3autogen.utils.Helper.camelToUnderscore) Ds3Request(com.spectralogic.ds3autogen.api.models.apispec.Ds3Request) GuavaCollectors(com.spectralogic.ds3autogen.utils.collections.GuavaCollectors) ImmutableList(com.google.common.collect.ImmutableList) PythonHelper.pythonIndent(com.spectralogic.ds3autogen.python.helpers.PythonHelper.pythonIndent) ConstructorParam(com.spectralogic.ds3autogen.python.model.request.ConstructorParam) CustomArgumentComparator(com.spectralogic.ds3autogen.utils.comparators.CustomArgumentComparator) ConstructorParam(com.spectralogic.ds3autogen.python.model.request.ConstructorParam) ImmutableList(com.google.common.collect.ImmutableList) CustomArgumentComparator(com.spectralogic.ds3autogen.utils.comparators.CustomArgumentComparator) Arguments(com.spectralogic.ds3autogen.api.models.Arguments)

Example 79 with Arguments

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

the class NetCodeGenerator_Test method getObjectRequest_Test.

@Test
public void getObjectRequest_Test() 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/getObjectRequest.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.hasRequiredParam("BucketName", "string", requestCode));
    assertTrue(TestHelper.hasRequiredParam("ObjectName", "string", requestCode));
    assertTrue(TestHelper.hasRequiredParam("Job", "string", requestCode));
    assertTrue(TestHelper.hasRequiredParam("Offset", "long", requestCode));
    final ImmutableList<Arguments> constructorArgs = ImmutableList.of(new Arguments("String", "BucketName"), new Arguments("String", "ObjectName"), new Arguments("Stream", "DestinationStream"), new Arguments("UUID", "Job"), new Arguments("long", "Offset"));
    assertTrue(TestHelper.hasConstructor(requestName, constructorArgs, requestCode));
    assertTrue(TestHelper.hasConstructor(requestName, modifyType(constructorArgs, "Guid", "string"), requestCode));
    assertTrue(requestCode.contains("QueryParams.Add(\"job\", job.ToString());"));
    assertTrue(requestCode.contains("QueryParams.Add(\"offset\", offset.ToString());"));
    //Generate Client code
    final String commandName = requestName.replace("Request", "");
    final String clientCode = codeGenerator.getClientCode();
    CODE_LOGGER.logFile(clientCode, FileTypeToLog.CLIENT);
    assertTrue(clientCode.contains("public GetObjectResponse GetObject(GetObjectRequest request)"));
    assertTrue(clientCode.contains("return new GetObjectResponseParser(_netLayer.CopyBufferSize).Parse(request, _netLayer.Invoke(request));"));
    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();
    CODE_LOGGER.logFile(responseCode, FileTypeToLog.RESPONSE);
    assertTrue(hasContent(responseCode));
    assertTrue(responseCode.contains("public GetObjectResponse(IDictionary<string, string> metadata)"));
    //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) Arguments(com.spectralogic.ds3autogen.api.models.Arguments) Test(org.junit.Test)

Example 80 with Arguments

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

the class NetCodeGenerator_Test method verifyPhysicalPlacementForObjectsRequestHandler.

@Test
public void verifyPhysicalPlacementForObjectsRequestHandler() throws IOException, TemplateModelException {
    final String requestName = "VerifyPhysicalPlacementForObjectsSpectraS3Request";
    final FileUtils fileUtils = mock(FileUtils.class);
    final TestGenerateCode codeGenerator = new TestGenerateCode(fileUtils, requestName, "./Ds3/Calls/", "PhysicalPlacement");
    codeGenerator.generateCode(fileUtils, "/input/verifyPhysicalPlacementForObjects.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("Objects", "IEnumerable<Ds3Object>", requestCode));
    assertTrue(TestHelper.hasOptionalParam(requestName, "StorageDomainId", "Guid", requestCode));
    final ImmutableList<Arguments> constructorArgs = ImmutableList.of(new Arguments("string", "BucketName"), new Arguments("IEnumerable<Ds3Object>", "Objects"));
    assertTrue(TestHelper.hasConstructor(requestName, constructorArgs, 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 = "PhysicalPlacement";
    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(hasContent(parserCode));
    assertTrue(parserHasResponseCode(200, parserCode));
    assertTrue(parserHasPayload("PhysicalPlacement", "Data", 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)

Aggregations

Arguments (com.spectralogic.ds3autogen.api.models.Arguments)188 Test (org.junit.Test)144 FileUtils (com.spectralogic.ds3autogen.api.FileUtils)46 ImmutableList (com.google.common.collect.ImmutableList)40 RequestConstructor (com.spectralogic.ds3autogen.java.models.RequestConstructor)33 Ds3Request (com.spectralogic.ds3autogen.api.models.apispec.Ds3Request)25 Ds3DocSpecEmptyImpl (com.spectralogic.ds3autogen.docspec.Ds3DocSpecEmptyImpl)25 TestGeneratedCode (com.spectralogic.ds3autogen.java.utils.TestGeneratedCode)25 TestGenerateCode (com.spectralogic.ds3autogen.net.utils.TestGenerateCode)21 QueryParam (com.spectralogic.ds3autogen.java.models.QueryParam)19 Helper.removeVoidArguments (com.spectralogic.ds3autogen.utils.Helper.removeVoidArguments)15 BaseParseResponse (com.spectralogic.ds3autogen.java.models.parseresponse.BaseParseResponse)14 RequestGeneratorTestHelper.createSimpleTestDs3Request (com.spectralogic.ds3autogen.java.test.helpers.RequestGeneratorTestHelper.createSimpleTestDs3Request)13 Ds3Param (com.spectralogic.ds3autogen.api.models.apispec.Ds3Param)9 GuavaCollectors (com.spectralogic.ds3autogen.utils.collections.GuavaCollectors)8 CustomArgumentComparator (com.spectralogic.ds3autogen.utils.comparators.CustomArgumentComparator)8 ConstructorParam (com.spectralogic.ds3autogen.python.model.request.ConstructorParam)7 Helper.camelToUnderscore (com.spectralogic.ds3autogen.utils.Helper.camelToUnderscore)7 RequestConverterUtil.getNonVoidArgsFromParamList (com.spectralogic.ds3autogen.utils.RequestConverterUtil.getNonVoidArgsFromParamList)6 Ds3ResponseType (com.spectralogic.ds3autogen.api.models.apispec.Ds3ResponseType)5