Search in sources :

Example 6 with Ds3Param

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"));
}
Also used : Ds3Param(com.spectralogic.ds3autogen.api.models.apispec.Ds3Param) Arguments(com.spectralogic.ds3autogen.api.models.Arguments) Test(org.junit.Test)

Example 7 with Ds3Param

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();
}
Also used : Ds3Param(com.spectralogic.ds3autogen.api.models.apispec.Ds3Param) ImmutableList(com.google.common.collect.ImmutableList) Parameter(com.spectralogic.ds3autogen.c.models.Parameter)

Example 8 with Ds3Param

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);
}
Also used : Ds3Param(com.spectralogic.ds3autogen.api.models.apispec.Ds3Param) TestFileUtilsImpl(com.spectralogic.ds3autogen.utils.TestFileUtilsImpl) HashMap(java.util.HashMap) Ds3Request(com.spectralogic.ds3autogen.api.models.apispec.Ds3Request) Request(com.spectralogic.ds3autogen.c.models.Request) Ds3Request(com.spectralogic.ds3autogen.api.models.apispec.Ds3Request) Ds3DocSpecEmptyImpl(com.spectralogic.ds3autogen.docspec.Ds3DocSpecEmptyImpl) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 9 with Ds3Param

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)));
}
Also used : Ds3Param(com.spectralogic.ds3autogen.api.models.apispec.Ds3Param) Test(org.junit.Test)

Example 10 with Ds3Param

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))));
}
Also used : Ds3Param(com.spectralogic.ds3autogen.api.models.apispec.Ds3Param) WithConstructor(com.spectralogic.ds3autogen.go.models.request.WithConstructor) Test(org.junit.Test)

Aggregations

Ds3Param (com.spectralogic.ds3autogen.api.models.apispec.Ds3Param)39 Test (org.junit.Test)37 Ds3Request (com.spectralogic.ds3autogen.api.models.apispec.Ds3Request)10 Arguments (com.spectralogic.ds3autogen.api.models.Arguments)8 RequestGeneratorTestHelper.createSimpleTestDs3Request (com.spectralogic.ds3autogen.java.test.helpers.RequestGeneratorTestHelper.createSimpleTestDs3Request)8 NetNullableVariable (com.spectralogic.ds3autogen.net.model.common.NetNullableVariable)8 Ds3DocSpecEmptyImpl (com.spectralogic.ds3autogen.docspec.Ds3DocSpecEmptyImpl)5 QueryParam (com.spectralogic.ds3autogen.java.models.QueryParam)5 Ds3ModelPartialDataFixture.createEmptyDs3Request (com.spectralogic.ds3autogen.testutil.Ds3ModelPartialDataFixture.createEmptyDs3Request)5 ImmutableList (com.google.common.collect.ImmutableList)3 Parameter (com.spectralogic.ds3autogen.c.models.Parameter)3 SimpleVariable (com.spectralogic.ds3autogen.go.models.request.SimpleVariable)3 WithConstructor (com.spectralogic.ds3autogen.go.models.request.WithConstructor)3 RequestConstructor (com.spectralogic.ds3autogen.java.models.RequestConstructor)3 Request (com.spectralogic.ds3autogen.c.models.Request)2 Variable (com.spectralogic.ds3autogen.go.models.request.Variable)2 TestFileUtilsImpl (com.spectralogic.ds3autogen.utils.TestFileUtilsImpl)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 HashMap (java.util.HashMap)2 Ds3Type (com.spectralogic.ds3autogen.api.models.apispec.Ds3Type)1