use of com.spectralogic.ds3autogen.api.models.apispec.Ds3Param 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.apispec.Ds3Param in project ds3_autogen by SpectraLogic.
the class RequestConverter method getRequiredQueryParams.
private static ImmutableList<Parameter> getRequiredQueryParams(final Ds3Request ds3Request, final Ds3DocSpec docSpec) {
final ImmutableList.Builder<Parameter> requiredArgsBuilder = ImmutableList.builder();
if (hasContent(ds3Request.getRequiredQueryParams())) {
for (final Ds3Param ds3Param : ds3Request.getRequiredQueryParams()) {
if (ds3Param == null)
continue;
if (ds3Request.getClassification() == Classification.spectrads3 && ds3Request.getOperation() != null && ds3Param.getName().equalsIgnoreCase("Operation")) {
// Special Case - Parameter.Type needs to be Request.Operation value
LOG.debug("\tRequired QueryParam: " + ds3Param.getName() + "=" + ds3Request.getOperation().name());
requiredArgsBuilder.add(new Parameter(ParameterModifier.CONST, "operation", ds3Request.getOperation().name(), ParameterPointerType.NONE, true));
} else {
final Parameter requiredParam = ParameterConverter.toParameter(ds3Param, true, toParamDocs(Helper.unqualifiedName(ds3Param.getName()), docSpec));
LOG.debug("\tRequired QueryParam: " + requiredParam.toString());
requiredArgsBuilder.add(requiredParam);
}
}
}
// Add 'length' if 'offset' is given
if (hasContent(ds3Request.getOptionalQueryParams())) {
for (final Ds3Param ds3Param : ds3Request.getOptionalQueryParams()) {
if (ds3Param == null)
continue;
if (ds3Param.getName().equalsIgnoreCase("Offset")) {
final Parameter lengthParam = new Parameter(ParameterModifier.CONST, "uint64_t", "length", ParameterPointerType.NONE, true);
LOG.debug("\tFound Optional Offset, adding Length QueryParam:\n" + lengthParam.toString());
requiredArgsBuilder.add(lengthParam);
}
}
}
return requiredArgsBuilder.build();
}
use of com.spectralogic.ds3autogen.api.models.apispec.Ds3Param in project ds3_autogen by SpectraLogic.
the class CCodeGeneratorAmazonS3InitRequests_Test method testGenerateInitAmazonS3WithOptionalQueryParams.
@Test
public void testGenerateInitAmazonS3WithOptionalQueryParams() throws IOException, ParseException, TemplateModelException {
final Map<String, Object> testMap = new HashMap<>();
final Request testRequest = RequestConverter.toRequest(new Ds3Request("com.spectralogic.s3.server.handler.reqhandler.amazons3.CreateObjectRequestHandler", HttpVerb.PUT, Classification.amazons3, Requirement.REQUIRED, Requirement.REQUIRED, null, null, null, null, false, null, ImmutableList.of(new Ds3Param("Job", "java.util.UUID", true), new Ds3Param("Offset", "long", false)), ImmutableList.of()), new Ds3DocSpecEmptyImpl());
testMap.put("requestEntry", testRequest);
final CCodeGenerator codeGenerator = new CCodeGenerator();
final TestFileUtilsImpl fileUtils = new TestFileUtilsImpl();
codeGenerator.processTemplate(testMap, "request-templates/InitRequest.ftl", fileUtils.getOutputStream());
final ByteArrayOutputStream bstream = (ByteArrayOutputStream) fileUtils.getOutputStream();
final String output = new String(bstream.toByteArray());
final String expectedOutput = "ds3_request* ds3_init_create_object(const char *const bucket_name, const char *const object_name, const uint64_t length) {" + "\n" + " struct _ds3_request* request = _common_request_init(HTTP_PUT, _build_path(\"/\", bucket_name, object_name));" + "\n" + " request->length = length;" + "\n" + "\n" + " return (ds3_request*) request;" + "\n" + "}\n";
assertEquals(expectedOutput, output);
}
use of com.spectralogic.ds3autogen.api.models.apispec.Ds3Param in project ds3_autogen by SpectraLogic.
the class RequestGeneratorUtil_Test method removeVoidAndOperationDs3Params_FullList_Test.
@Test
public void removeVoidAndOperationDs3Params_FullList_Test() {
final ImmutableList<Ds3Param> expected = ImmutableList.of(new Ds3Param("Param1", "Type1", false), new Ds3Param("Param3", "int", false));
final ImmutableList<Ds3Param> params = ImmutableList.of(new Ds3Param("Param1", "Type1", false), new Ds3Param("Param2", "void", false), new Ds3Param("Param3", "int", false), new Ds3Param("Param4", "VOID", false), new Ds3Param("Operation", "RestOperationType", false));
final ImmutableList<Ds3Param> result = removeVoidAndOperationDs3Params(params);
assertThat(result.size(), is(expected.size()));
expected.forEach(param -> assertThat(result, hasItem(param)));
}
use of com.spectralogic.ds3autogen.api.models.apispec.Ds3Param in project ds3_autogen by SpectraLogic.
the class RequestGeneratorUtil_Test method toWithConstructor_Test.
@Test
public void toWithConstructor_Test() {
final ImmutableList<WithConstructor> expected = ImmutableList.of(new WithConstructor("ParamOne", "Type1", "param_one", "paramOne.String()"), new WithConstructor("ParamTwo", "int", "param_two", "strconv.Itoa(paramTwo)"), new WithConstructor("TypeName", "TypeName", "type", "typeName.String()"));
final ImmutableList<Ds3Param> params = ImmutableList.of(new Ds3Param("ParamOne", "Type1", false), new Ds3Param("ParamTwo", "int", false), new Ds3Param("Type", "com.test.TypeName", false));
assertThat(params.size(), is(expected.size()));
params.forEach(param -> assertThat(expected, hasItem(toWithConstructor(param))));
}
Aggregations