Search in sources :

Example 1 with Struct

use of com.spectralogic.ds3autogen.c.models.Struct in project ds3_autogen by SpectraLogic.

the class CCodeGeneratorAmazonS3Requests_Test method testGenerateAmazonS3GetBucketsRequest.

@Test
public void testGenerateAmazonS3GetBucketsRequest() throws IOException, ParseException, TemplateModelException {
    final String inputSpecFile = "/input/AmazonS3GetBucketsRequest_WithResponsePayload.xml";
    final TestFileUtilsImpl fileUtils = new TestFileUtilsImpl();
    final Ds3SpecParser parser = new Ds3SpecParserImpl();
    final Ds3ApiSpec spec = parser.getSpec(CCodeGenerator_Test.class.getResourceAsStream(inputSpecFile));
    final ImmutableList<Request> allRequests = CCodeGenerator.getAllRequests(spec, new Ds3DocSpecEmptyImpl());
    final ImmutableList<Enum> allEnums = CCodeGenerator.getAllEnums(spec);
    final ImmutableSet<String> enumNames = EnumHelper.getEnumNamesSet(allEnums);
    final ImmutableSet<String> arrayMemberTypes = CCodeGenerator.getArrayMemberTypes(spec, enumNames);
    final ImmutableSet<String> responseTypes = RequestHelper.getResponseTypes(allRequests);
    final ImmutableList<Struct> allStructs = CCodeGenerator.getAllStructs(spec, enumNames, responseTypes, arrayMemberTypes, ImmutableSet.of(), ImmutableSet.of());
    final ImmutableList<Struct> allOrderedStructs = StructHelper.getStructsOrderedList(allStructs, enumNames);
    final Source source = SourceConverter.toSource(allEnums, allOrderedStructs, allRequests);
    final CCodeGenerator codeGenerator = new CCodeGenerator();
    codeGenerator.processTemplate(source, "source-templates/ds3_c.ftl", fileUtils.getOutputStream());
    final ByteArrayOutputStream bstream = (ByteArrayOutputStream) fileUtils.getOutputStream();
    final String output = new String(bstream.toByteArray());
    assertTrue(output.contains("ds3_error* ds3_get_service_request(const ds3_client* client, const ds3_request* request, ds3_list_all_my_buckets_result_response** response) {"));
    assertTrue(output.contains("    return _parse_top_level_ds3_list_all_my_buckets_result_response(client, request, response, xml_blob);"));
    assertTrue(output.contains("}"));
}
Also used : Enum(com.spectralogic.ds3autogen.c.models.Enum) Ds3SpecParser(com.spectralogic.ds3autogen.api.Ds3SpecParser) Request(com.spectralogic.ds3autogen.c.models.Request) Ds3SpecParserImpl(com.spectralogic.ds3autogen.Ds3SpecParserImpl) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Source(com.spectralogic.ds3autogen.c.models.Source) Ds3ApiSpec(com.spectralogic.ds3autogen.api.models.apispec.Ds3ApiSpec) Struct(com.spectralogic.ds3autogen.c.models.Struct) TestFileUtilsImpl(com.spectralogic.ds3autogen.utils.TestFileUtilsImpl) Ds3DocSpecEmptyImpl(com.spectralogic.ds3autogen.docspec.Ds3DocSpecEmptyImpl) Test(org.junit.Test)

Example 2 with Struct

use of com.spectralogic.ds3autogen.c.models.Struct in project ds3_autogen by SpectraLogic.

the class StructConverter_Test method testConvertNameToMarshallJobsListSpecialCase.

@Test
public void testConvertNameToMarshallJobsListSpecialCase() throws ParseException {
    final Ds3Element testElement1 = new Ds3Element("BoolElement", "boolean", null, false);
    final Ds3Element testElement2 = new Ds3Element("BeanElement", "com.spectralogic.s3.server.domain.UserApiBean", null, false);
    final ImmutableList<Ds3Element> elementsList = ImmutableList.of(testElement1, testElement2);
    final Ds3Type ds3Type = new Ds3Type("ds3JobList", "overrideMarshallName", elementsList, ImmutableList.of());
    final Struct testStruct = StructConverter.toStruct(ds3Type, ImmutableSet.of(), ImmutableSet.of(), ImmutableSet.of(), ImmutableSet.of(), ImmutableSet.of());
    assertThat(testStruct.getNameToMarshall(), is("Jobs"));
}
Also used : Ds3Type(com.spectralogic.ds3autogen.api.models.apispec.Ds3Type) Ds3Element(com.spectralogic.ds3autogen.api.models.apispec.Ds3Element) Struct(com.spectralogic.ds3autogen.c.models.Struct) Test(org.junit.Test)

Example 3 with Struct

use of com.spectralogic.ds3autogen.c.models.Struct in project ds3_autogen by SpectraLogic.

the class StructConverter_Test method testConvertNameToMarshallCommonPrefixSpecialCase.

@Test
public void testConvertNameToMarshallCommonPrefixSpecialCase() throws ParseException {
    final Ds3Element testElement1 = new Ds3Element("CommonPrefixes", "array", "java.lang.String", false);
    final ImmutableList<Ds3Element> elementsList = ImmutableList.of(testElement1);
    final Ds3Type ds3Type = new Ds3Type("com.spectralogic.s3.server.domain.BucketObjectsApiBean", "ListBucketResult", elementsList, ImmutableList.of());
    final Struct testStruct = StructConverter.toStruct(ds3Type, ImmutableSet.of(), ImmutableSet.of(), ImmutableSet.of(), ImmutableSet.of(), ImmutableSet.of());
    assertThat(testStruct.getNameToMarshall(), is("ListBucketResult"));
    assertThat(testStruct.getStructMembers().get(0).getNameToMarshall(), is("CommonPrefixes"));
}
Also used : Ds3Type(com.spectralogic.ds3autogen.api.models.apispec.Ds3Type) Ds3Element(com.spectralogic.ds3autogen.api.models.apispec.Ds3Element) Struct(com.spectralogic.ds3autogen.c.models.Struct) Test(org.junit.Test)

Example 4 with Struct

use of com.spectralogic.ds3autogen.c.models.Struct in project ds3_autogen by SpectraLogic.

the class StructHelper method getStructsOrderedList.

/**
     * Return Structs which contain only primitive types first, and then cascade for Complex Structs that contain other Structs
     *
     * @throws java.text.ParseException
     */
public static ImmutableList<Struct> getStructsOrderedList(final ImmutableList<Struct> allStructs, final ImmutableSet<String> enumNames) throws ParseException {
    final Queue<Struct> structsQueue = new LinkedList<>(allStructs);
    final Set<String> existingStructs = new HashSet<>();
    final ImmutableList.Builder<Struct> orderedStructsBuilder = ImmutableList.builder();
    int skippedStructsCount = 0;
    while (!structsQueue.isEmpty()) {
        final int structsQueueSize = structsQueue.size();
        final Struct structEntry = structsQueue.remove();
        if (!StructHelper.requiresNewCustomParser(structEntry, existingStructs, enumNames)) {
            existingStructs.add(structEntry.getName());
            LOG.info(structEntry.toString());
            orderedStructsBuilder.add(structEntry);
        } else {
            // move to end to come back to
            structsQueue.add(structEntry);
        }
        if (structsQueueSize == structsQueue.size()) {
            skippedStructsCount++;
            if (skippedStructsCount == structsQueueSize) {
                LOG.warn("Unable to progress on remaining structs, aborting!");
                LOG.warn("  Remaining structs[" + structsQueue.size() + "]");
                for (final Struct struct : allStructs) {
                    LOG.warn("    " + struct.toString() + "\n");
                }
                throw new ParseException("Unable to Order provided structs.", 0);
            }
        } else {
            skippedStructsCount = 0;
        }
    }
    return orderedStructsBuilder.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) ParseException(java.text.ParseException) LinkedList(java.util.LinkedList) Struct(com.spectralogic.ds3autogen.c.models.Struct) HashSet(java.util.HashSet)

Example 5 with Struct

use of com.spectralogic.ds3autogen.c.models.Struct in project ds3_autogen by SpectraLogic.

the class StructConverter_Test method testConvertNameToMarshallEmpty.

@Test
public void testConvertNameToMarshallEmpty() throws ParseException {
    final Ds3Element testElement1 = new Ds3Element("BoolElement", "boolean", null, false);
    final Ds3Element testElement2 = new Ds3Element("BeanElement", "com.spectralogic.s3.server.domain.UserApiBean", null, false);
    final ImmutableList<Ds3Element> elementsList = ImmutableList.of(testElement1, testElement2);
    final Ds3Type ds3Type = new Ds3Type("testDs3Type", elementsList);
    final Struct testStruct = StructConverter.toStruct(ds3Type, ImmutableSet.of(), ImmutableSet.of(), ImmutableSet.of(), ImmutableSet.of(), ImmutableSet.of());
    assertThat(testStruct.getNameToMarshall(), is("Data"));
}
Also used : Ds3Type(com.spectralogic.ds3autogen.api.models.apispec.Ds3Type) Ds3Element(com.spectralogic.ds3autogen.api.models.apispec.Ds3Element) Struct(com.spectralogic.ds3autogen.c.models.Struct) Test(org.junit.Test)

Aggregations

Struct (com.spectralogic.ds3autogen.c.models.Struct)6 Test (org.junit.Test)5 Ds3Element (com.spectralogic.ds3autogen.api.models.apispec.Ds3Element)4 Ds3Type (com.spectralogic.ds3autogen.api.models.apispec.Ds3Type)4 ImmutableList (com.google.common.collect.ImmutableList)1 Ds3SpecParserImpl (com.spectralogic.ds3autogen.Ds3SpecParserImpl)1 Ds3SpecParser (com.spectralogic.ds3autogen.api.Ds3SpecParser)1 Ds3ApiSpec (com.spectralogic.ds3autogen.api.models.apispec.Ds3ApiSpec)1 Enum (com.spectralogic.ds3autogen.c.models.Enum)1 Request (com.spectralogic.ds3autogen.c.models.Request)1 Source (com.spectralogic.ds3autogen.c.models.Source)1 Ds3DocSpecEmptyImpl (com.spectralogic.ds3autogen.docspec.Ds3DocSpecEmptyImpl)1 TestFileUtilsImpl (com.spectralogic.ds3autogen.utils.TestFileUtilsImpl)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ParseException (java.text.ParseException)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1