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"));
}
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"));
}
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());
}
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));
}
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));
}
Aggregations