use of com.spectralogic.ds3autogen.docspec.Ds3DocSpecEmptyImpl in project ds3_autogen by SpectraLogic.
the class CCodeGenerator_Test method testSimpleTypdefStructResponseParser.
@Test
public void testSimpleTypdefStructResponseParser() throws IOException, ParseException, TemplateModelException {
final String inputSpecFile = "/input/SimpleTypedefStruct.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("static ds3_error* _parse_top_level_ds3_bucket_response(const ds3_client* client, const ds3_request* request, ds3_bucket_response** _response, GByteArray* xml_blob) {"));
assertTrue(output.contains(" xmlNodePtr child_node;"));
assertTrue(output.contains(" ds3_error* error;"));
assertTrue(output.contains(" ds3_bucket_response* response;"));
assertTrue(output.contains(" error = _get_request_xml_nodes(xml_blob, &doc, &root, \"Data\");"));
assertTrue(output.contains(" if (error != NULL) {"));
assertTrue(output.contains(" return error;"));
assertTrue(output.contains(" }"));
assertTrue(output.contains(" response = g_new0(ds3_bucket_response, 1)"));
assertTrue(output.contains(" for (child_node = root->xmlChildrenNode; child_node != NULL; child_node = child_node->next) {"));
assertTrue(output.contains(" if (element_equal(child_node, \"CreationDate\")) {"));
assertTrue(output.contains(" response->creation_date = xml_get_string(doc, child_node);"));
assertTrue(output.contains(" } else if (element_equal(child_node, \"DataPolicyId\")) {"));
assertTrue(output.contains(" response->data_policy_id = xml_get_string(doc, child_node);"));
assertTrue(output.contains(" } else if (element_equal(child_node, \"Id\")) {"));
assertTrue(output.contains(" response->id = xml_get_string(doc, child_node);"));
assertTrue(output.contains(" } else if (element_equal(child_node, \"LastPreferredChunkSizeInBytes\")) {"));
assertTrue(output.contains(" response->last_preferred_chunk_size_in_bytes = xml_get_uint64(doc, child_node);"));
assertTrue(output.contains(" } else if (element_equal(child_node, \"LogicalUsedCapacity\")) {"));
assertTrue(output.contains(" response->logical_used_capacity = xml_get_uint64(doc, child_node);"));
assertTrue(output.contains(" } else if (element_equal(child_node, \"Name\")) {"));
assertTrue(output.contains(" response->name = xml_get_string(doc, child_node);"));
assertTrue(output.contains(" } else if (element_equal(child_node, \"UserId\")) {"));
assertTrue(output.contains(" response->user_id = xml_get_string(doc, child_node);"));
assertTrue(output.contains(" } else {"));
assertTrue(output.contains(" ds3_log_message(client->log, DS3_ERROR, \"Unknown node[%s] of ds3_bucket_response [%s]\\n\", child_node->name, root->name);"));
assertTrue(output.contains(" }"));
assertTrue(output.contains(" }"));
assertTrue(output.contains(" xmlFreeDoc(doc);"));
assertTrue(output.contains(" if (error == NULL) {"));
assertTrue(output.contains(" *_response = response;"));
assertTrue(output.contains(" } else {"));
assertTrue(output.contains(" ds3_bucket_response_free(response);"));
assertTrue(output.contains(" }"));
assertTrue(output.contains(" return error;"));
assertTrue(output.contains("}"));
}
use of com.spectralogic.ds3autogen.docspec.Ds3DocSpecEmptyImpl in project ds3_autogen by SpectraLogic.
the class CCodeGenerator_Test method testComplexResponseStructParserOrdering.
@Test
public void testComplexResponseStructParserOrdering() throws IOException, ParseException, TemplateModelException {
final String inputSpecFile = "/input/ComplexTypedefStruct.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("ds3_bucket_details_response", "ds3_list_all_my_buckets_result_response"), 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.indexOf("_parse_ds3_bucket_details_response_array") > output.indexOf("_parse_ds3_bucket_response"));
assertTrue(output.indexOf("_parse_ds3_list_all_my_buckets_result_response") > output.indexOf("_parse_ds3_bucket_response_array"));
}
use of com.spectralogic.ds3autogen.docspec.Ds3DocSpecEmptyImpl in project ds3_autogen by SpectraLogic.
the class CCodeGenerator_Test method testRequestDocumentationCommentBlockWithEmptyDocSpecNoOptionalParams.
@Test
public void testRequestDocumentationCommentBlockWithEmptyDocSpecNoOptionalParams() throws IOException, TemplateModelException {
final Request testRequest = RequestConverter.toRequest(Ds3ModelFixtures.getSystemInformationRequest(), new Ds3DocSpecEmptyImpl());
final Map<String, Object> testMap = new HashMap<>();
testMap.put("requestEntry", testRequest);
final CCodeGenerator codeGenerator = new CCodeGenerator();
final TestFileUtilsImpl fileUtils = new TestFileUtilsImpl();
codeGenerator.processTemplate(testMap, "header-templates/RequestCommentDocumentation.ftl", fileUtils.getOutputStream());
final ByteArrayOutputStream bstream = (ByteArrayOutputStream) fileUtils.getOutputStream();
final String output = new String(bstream.toByteArray());
assertEquals("", output);
}
use of com.spectralogic.ds3autogen.docspec.Ds3DocSpecEmptyImpl in project ds3_autogen by SpectraLogic.
the class CCodeGeneratorSpectraS3Requests_Test method testGenerateSpectraS3DeleteBucketRequest.
@Test
public void testGenerateSpectraS3DeleteBucketRequest() throws IOException, ParseException, TemplateModelException {
final String inputSpecFile = "/input/SpectraS3DeleteBucketRequest.xml";
final TestFileUtilsImpl fileUtils = new TestFileUtilsImpl();
final Ds3SpecParser parser = new Ds3SpecParserImpl();
final Ds3ApiSpec spec = parser.getSpec(CCodeGenerator_Test.class.getResourceAsStream(inputSpecFile));
final Source source = SourceConverter.toSource(CCodeGenerator.getAllEnums(spec), CCodeGenerator.getAllStructs(spec, ImmutableSet.of(), ImmutableSet.of(), ImmutableSet.of(), ImmutableSet.of(), ImmutableSet.of()), CCodeGenerator.getAllRequests(spec, new Ds3DocSpecEmptyImpl()));
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_delete_bucket_spectra_s3_request(const ds3_client* client, const ds3_request* request) {"));
assertTrue(output.contains(" int num_slashes = num_chars_in_ds3_str(request->path, '/');"));
assertTrue(output.contains(" if (num_slashes < 2 || ((num_slashes == 2) && ('/' == request->path->value[request->path->size-1]))) {"));
assertTrue(output.contains(" return ds3_create_error(DS3_ERROR_MISSING_ARGS, \"The resource id parameter is required.\");"));
assertTrue(output.contains(" } else if (g_ascii_strncasecmp(request->path->value, \"//\", 2) == 0) {"));
assertTrue(output.contains(" return ds3_create_error(DS3_ERROR_MISSING_ARGS, \"The resource type parameter is required.\");"));
assertTrue(output.contains(" }"));
assertTrue(output.contains(" return _internal_request_dispatcher(client, request, NULL, NULL, NULL, NULL, NULL);"));
assertTrue(output.contains("}"));
}
use of com.spectralogic.ds3autogen.docspec.Ds3DocSpecEmptyImpl in project ds3_autogen by SpectraLogic.
the class CCodeGeneratorSpectraS3Requests_Test method testGenerateSpectraS3GetBucketRequestPrototype.
@Test
public void testGenerateSpectraS3GetBucketRequestPrototype() throws IOException, TemplateModelException {
final TestFileUtilsImpl fileUtils = new TestFileUtilsImpl();
final Map<String, Object> testMap = new HashMap<>();
final String responseType = StructHelper.getResponseTypeName("ListBucketResult");
final Request requestEntry = new Request("get_bucket_request", Classification.spectrads3, HttpVerb.GET, "\"/_rest_/\", bucket_name, NULL", null, null, RequestConverter.getParamList(responseType, new Ds3DocSpecEmptyImpl()), ImmutableList.of(), ImmutableList.of(), true, false, null, responseType, false, null);
testMap.put("requestEntry", requestEntry);
final CCodeGenerator codeGenerator = new CCodeGenerator();
codeGenerator.processTemplate(testMap, "header-templates/RequestPrototype.ftl", fileUtils.getOutputStream());
final ByteArrayOutputStream bstream = (ByteArrayOutputStream) fileUtils.getOutputStream();
final String output = new String(bstream.toByteArray());
final String expectedOutput = "LIBRARY_API ds3_error* ds3_get_bucket_request(const ds3_client* client, const ds3_request* request, ds3_list_bucket_result_response** response);";
assertEquals(expectedOutput, output);
}
Aggregations