From ccf9b0dc2858265e3a3d7da28a653f6bc7e2e8a3 Mon Sep 17 00:00:00 2001 From: "saul.gill" Date: Fri, 9 Jul 2021 12:10:46 +0100 Subject: Added get json schema endpoints Added runtime-controlloop endpoint to return Json Schema Schema returned can be for specified type within Tosca Service Template Added Camel in runtime endpoint to proxy the Schema endpoint Dependency added to pom for the json schema generation Issue-ID: POLICY-3439 Change-Id: I2a98ce16dfb3761a174c90f4b965d1a37a0d8576 Signed-off-by: saul.gill --- .../runtime/RuntimeCommissioningResponseTestItCase.java | 14 ++++++++++++++ .../src/test/resources/http-cache/third_party_proxy.py | 15 +++++++++++++++ 2 files changed, 29 insertions(+) (limited to 'runtime/src/test') diff --git a/runtime/src/test/java/org/onap/policy/clamp/runtime/RuntimeCommissioningResponseTestItCase.java b/runtime/src/test/java/org/onap/policy/clamp/runtime/RuntimeCommissioningResponseTestItCase.java index 0ba1486bb..7616d7a49 100644 --- a/runtime/src/test/java/org/onap/policy/clamp/runtime/RuntimeCommissioningResponseTestItCase.java +++ b/runtime/src/test/java/org/onap/policy/clamp/runtime/RuntimeCommissioningResponseTestItCase.java @@ -46,6 +46,20 @@ public class RuntimeCommissioningResponseTestItCase { + " \"topology_template\": {}," + " \"name\": \"ToscaServiceTemplateSimple\", \"version\": \"1.0.0\", \"metadata\": {}}"; + @Test + public void testToscaServiceTemplateSchemaStatus() { + ProducerTemplate prodTemplate = camelContext.createProducerTemplate(); + + Exchange exchangeResponse = + prodTemplate.send("direct:get-json-schema", ExchangeBuilder.anExchange(camelContext) + .withProperty("section", "data_types") + .withProperty("raiseHttpExceptionFlag", "true") + .build()); + + assertThat(HttpStatus.valueOf((Integer) exchangeResponse.getIn().getHeader(Exchange.HTTP_RESPONSE_CODE)) + .is2xxSuccessful()).isTrue(); + } + @Test public void testToscaServiceTemplateStatus() { ProducerTemplate prodTemplate = camelContext.createProducerTemplate(); diff --git a/runtime/src/test/resources/http-cache/third_party_proxy.py b/runtime/src/test/resources/http-cache/third_party_proxy.py index 50bd43a35..1aaf4024d 100644 --- a/runtime/src/test/resources/http-cache/third_party_proxy.py +++ b/runtime/src/test/resources/http-cache/third_party_proxy.py @@ -283,6 +283,21 @@ class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler): with open(cached_file_content, 'w+') as f: f.write(jsonGenerated) return True + elif (self.path.startswith("/onap/controlloop/v2/commission/toscaServiceTemplateSchema")) and http_type == "GET": + if not _file_available: + cached_file_folder = cached_file_folder.split('bridgeEndpoint')[0] + print ("cached file folder for onap is %s: ", cached_file_folder) + print "self.path start with /onap/controlloop/v2/commission/, generating response json..." + jsonGenerated = "{\"tosca_definitions_version\": \"tosca_simple_yaml_1_1_0\",\"data_types\": {},\"node_types\": {}, \"policy_types\": {}, \"topology_template\": {}, \"name\": \"ToscaServiceTemplateSimple\", \"version\": \"1.0.0\", \"metadata\": {}}" + print "jsonGenerated: " + jsonGenerated + if not os.path.exists(cached_file_folder): + os.makedirs(cached_file_folder, 0777) + + with open(cached_file_header, 'w+') as f: + f.write("{\"Content-Length\": \"" + str(len(jsonGenerated)) + "\", \"Content-Type\": \"application/json\"}") + with open(cached_file_content, 'w+') as f: + f.write(jsonGenerated) + return True elif (self.path.startswith("/onap/controlloop/v2/commission")) and http_type == "POST": print "self.path start with POST /onap/controlloop/v2/commission, copying body to response ..." if not os.path.exists(cached_file_folder): -- cgit 1.2.3-korg