aboutsummaryrefslogtreecommitdiffstats
path: root/runtime/src/test
diff options
context:
space:
mode:
authorLiam Fallon <liam.fallon@est.tech>2021-07-05 07:54:46 +0000
committerGerrit Code Review <gerrit@onap.org>2021-07-05 07:54:46 +0000
commit68599cace010d09d3a0a8a767241186df078a49d (patch)
tree1b1a9e8cec0fcd774c70fa497826c24cf0214efa /runtime/src/test
parent72d882f65031518e9d1b1a6d6e53c7d42ab8495f (diff)
parentc19601d2080baa401cd17286985b6a0ee47d9a07 (diff)
Merge "Added ITs for Commissioning Camel Endpoints"
Diffstat (limited to 'runtime/src/test')
-rw-r--r--runtime/src/test/java/org/onap/policy/clamp/policy/downloader/PolicyEngineControllerTestItCase.java14
-rw-r--r--runtime/src/test/java/org/onap/policy/clamp/runtime/RuntimeCommissioningResponseTestItCase.java91
-rw-r--r--runtime/src/test/resources/application.properties5
-rw-r--r--runtime/src/test/resources/http-cache/third_party_proxy.py61
4 files changed, 146 insertions, 25 deletions
diff --git a/runtime/src/test/java/org/onap/policy/clamp/policy/downloader/PolicyEngineControllerTestItCase.java b/runtime/src/test/java/org/onap/policy/clamp/policy/downloader/PolicyEngineControllerTestItCase.java
index 4dd620c4b..8fbd2712b 100644
--- a/runtime/src/test/java/org/onap/policy/clamp/policy/downloader/PolicyEngineControllerTestItCase.java
+++ b/runtime/src/test/java/org/onap/policy/clamp/policy/downloader/PolicyEngineControllerTestItCase.java
@@ -72,15 +72,15 @@ public class PolicyEngineControllerTestItCase {
List<PolicyModel> policyModelsList = policyModelsRepository.findAll();
assertThat(policyModelsList.size()).isGreaterThanOrEqualTo(5);
assertThat(policyModelsList).contains(new PolicyModel("onap.policies.controlloop.operational.common.Drools",
- null, "1.0.0"));
+ null, "1.0.0"));
assertThat(policyModelsList).contains(new PolicyModel("onap.policies.controlloop.operational.common.Apex",
- null, "1.0.0"));
+ null, "1.0.0"));
assertThat(policyModelsList)
- .contains(new PolicyModel("onap.policies.controlloop.guard.common.FrequencyLimiter", null, "1.0.0"));
+ .contains(new PolicyModel("onap.policies.controlloop.guard.common.FrequencyLimiter", null, "1.0.0"));
assertThat(policyModelsList)
- .contains(new PolicyModel("onap.policies.controlloop.guard.common.Blacklist", null, "1.0.0"));
+ .contains(new PolicyModel("onap.policies.controlloop.guard.common.Blacklist", null, "1.0.0"));
assertThat(policyModelsList)
- .contains(new PolicyModel("onap.policies.controlloop.guard.common.MinMax", null, "2.0.0"));
+ .contains(new PolicyModel("onap.policies.controlloop.guard.common.MinMax", null, "2.0.0"));
// Re-do it to check that there is no issue with duplicate key
policyController.synchronizeAllPolicies();
@@ -104,9 +104,9 @@ public class PolicyEngineControllerTestItCase {
assertThat(policyModelsList.size()).isGreaterThanOrEqualTo(2);
PolicyModel policy1 = policyModelsRepository
- .getOne(new PolicyModelId("onap.policies.monitoring.test", "1.0.0"));
+ .getOne(new PolicyModelId("onap.policies.monitoring.test", "1.0.0"));
PolicyModel policy2 = policyModelsRepository
- .getOne(new PolicyModelId("onap.policies.controlloop.Operational", "1.0.0"));
+ .getOne(new PolicyModelId("onap.policies.controlloop.Operational", "1.0.0"));
String expectedRes1 = "{\"supportedPdpGroups\":[{\"monitoring\":[\"xacml\"]}]}";
JsonObject expectedJson1 = JsonUtils.GSON.fromJson(expectedRes1, JsonObject.class);
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
new file mode 100644
index 000000000..0ba1486bb
--- /dev/null
+++ b/runtime/src/test/java/org/onap/policy/clamp/runtime/RuntimeCommissioningResponseTestItCase.java
@@ -0,0 +1,91 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.runtime;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.ExchangeBuilder;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.onap.policy.clamp.clds.Application;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.http.HttpStatus;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes = Application.class)
+public class RuntimeCommissioningResponseTestItCase {
+ @Autowired
+ CamelContext camelContext;
+
+ private static final String SAMPLE_TOSCA_TEMPLATE =
+ "{\"tosca_definitions_version\": \"tosca_simple_yaml_1_1_0\","
+ + "\"data_types\": {},\"node_types\": {}, \"policy_types\": {},"
+ + " \"topology_template\": {},"
+ + " \"name\": \"ToscaServiceTemplateSimple\", \"version\": \"1.0.0\", \"metadata\": {}}";
+
+ @Test
+ public void testToscaServiceTemplateStatus() {
+ ProducerTemplate prodTemplate = camelContext.createProducerTemplate();
+
+ Exchange exchangeResponse =
+ prodTemplate.send("direct:get-service-template", ExchangeBuilder.anExchange(camelContext)
+ .withProperty("name", "ToscaServiceTemplate")
+ .withProperty("version", "1.0.0")
+ .withProperty("raiseHttpExceptionFlag", "true")
+ .build());
+
+ assertThat(HttpStatus.valueOf((Integer) exchangeResponse.getIn().getHeader(Exchange.HTTP_RESPONSE_CODE))
+ .is2xxSuccessful()).isTrue();
+ }
+
+ @Test
+ public void testToscaServiceTemplateGetResponseBody() {
+ ProducerTemplate prodTemplate = camelContext.createProducerTemplate();
+
+ Exchange exchangeResponse =
+ prodTemplate.send("direct:get-service-template", ExchangeBuilder.anExchange(camelContext)
+ .withProperty("name", "ToscaServiceTemplate")
+ .withProperty("version", "1.0.0")
+ .withProperty("raiseHttpExceptionFlag", "true")
+ .build());
+
+ assertThat(exchangeResponse.getIn().getBody().toString()).isEqualTo(SAMPLE_TOSCA_TEMPLATE);
+ }
+
+ @Test
+ public void testCommissioningOfToscaServiceTemplateStatus() {
+ ProducerTemplate prodTemplate = camelContext.createProducerTemplate();
+
+ Exchange exchangeResponse =
+ prodTemplate.send("direct:commission-service-template", ExchangeBuilder.anExchange(camelContext)
+ .withBody(SAMPLE_TOSCA_TEMPLATE)
+ .withProperty("raiseHttpExceptionFlag", "true")
+ .build());
+
+ assertThat(HttpStatus.valueOf((Integer) exchangeResponse.getIn().getHeader(Exchange.HTTP_RESPONSE_CODE))
+ .is2xxSuccessful()).isTrue();
+ }
+}
diff --git a/runtime/src/test/resources/application.properties b/runtime/src/test/resources/application.properties
index 60704acf5..54a89078d 100644
--- a/runtime/src/test/resources/application.properties
+++ b/runtime/src/test/resources/application.properties
@@ -4,6 +4,7 @@
# ================================================================================
# Copyright (C) 2017-2018, 2021 AT&T Intellectual Property. All rights
# reserved.
+# Modifications Copyright (C) 2021 Nordix Foundation.
# ================================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -16,6 +17,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
+#
+# SPDX-License-Identifier: Apache-2.0
# ============LICENSE_END============================================
# ===================================================================
#
@@ -180,6 +183,6 @@ clamp.config.tosca.converter.default.datatypes=classpath:/clds/tosca-converter/d
clamp.config.tosca.converter.dictionary.support.enabled=true
# Configuration settings for ControlLoop Runtime Rest API
-clamp.config.controlloop.runtime.url=http://localhost:6969
+clamp.config.controlloop.runtime.url=http://localhost:${docker.http-cache.port.host}
clamp.config.controlloop.runtime.userName=healthcheck
clamp.config.controlloop.runtime.password=zb!XztG34
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 7fe316852..50bd43a35 100644
--- a/runtime/src/test/resources/http-cache/third_party_proxy.py
+++ b/runtime/src/test/resources/http-cache/third_party_proxy.py
@@ -5,6 +5,7 @@
# ================================================================================
# Copyright (C) 2018 AT&T Intellectual Property. All rights
# reserved.
+# Modifications Copyright (C) 2021 Nordix Foundation.
# ================================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -17,6 +18,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
+#
+# SPDX-License-Identifier: Apache-2.0
# ============LICENSE_END============================================
# ===================================================================
#
@@ -94,23 +97,23 @@ class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler):
def _get_cached_file_folder_name(self,folder):
cached_file_folder = '%s/%s' % (folder, self.path,)
print("Cached file name before escaping : %s" % cached_file_folder)
- cached_file_folder = cached_file_folder.replace('<','&#60;').replace('>','&#62;').replace('?','&#63;').replace('*','&#42;').replace('\\','&#42;').replace(':','&#58;').replace('|','&#124;')
+ cached_file_folder = cached_file_folder.replace('+','').replace('<','&#60;').replace('>','&#62;').replace('?','&#63;').replace('*','&#42;').replace('\\','&#42;').replace(':','&#58;').replace('|','&#124;')
print("Cached file name after escaping (used for cache storage) : %s" % cached_file_folder)
return cached_file_folder
-
+
def _get_cached_content_file_name(self,cached_file_folder):
return "%s/.file" % (cached_file_folder,)
-
+
def _get_cached_header_file_name(self,cached_file_folder):
return "%s/.header" % (cached_file_folder,)
-
+
def _execute_content_generated_cases(self,http_type):
print("Testing special cases, cache files will be sent to :" +TMP_ROOT)
cached_file_folder = self._get_cached_file_folder_name(TMP_ROOT)
cached_file_content = self._get_cached_content_file_name(cached_file_folder)
cached_file_header = self._get_cached_header_file_name(cached_file_folder)
_file_available = os.path.exists(cached_file_content)
-
+
if self.path.startswith("/dcae-service-types?asdcResourceId=") and http_type == "GET":
if not _file_available:
print "self.path start with /dcae-service-types?asdcResourceId=, generating response json..."
@@ -120,7 +123,7 @@ class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler):
print "typeId generated: " + typeName + " and typeName: "+ typeId
jsonGenerated = "{\"totalCount\":1, \"items\":[{\"typeId\":\"" + typeId + "\", \"typeName\":\"" + typeName +"\"}]}"
print "jsonGenerated: " + jsonGenerated
-
+
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\"}")
@@ -132,14 +135,14 @@ class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler):
print "self.path start with /dcae-operationstatus/install, generating response json..."
jsonGenerated = "{\"operationType\": \"install\", \"status\": \"succeeded\"}"
print "jsonGenerated: " + jsonGenerated
-
+
try:
os.makedirs(cached_file_folder, 0777)
except OSError as e:
if e.errno != errno.EEXIST:
raise
print(cached_file_folder+" already exists")
-
+
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:
@@ -150,14 +153,14 @@ class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler):
print "self.path start with /dcae-operationstatus/uninstall, generating response json..."
jsonGenerated = "{\"operationType\": \"uninstall\", \"status\": \"succeeded\"}"
print "jsonGenerated: " + jsonGenerated
-
+
try:
os.makedirs(cached_file_folder, 0777)
except OSError as e:
if e.errno != errno.EEXIST:
raise
print(cached_file_folder+" already exists")
-
+
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:
@@ -169,7 +172,7 @@ class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler):
jsondata = json.loads(self.data_string)
jsonGenerated = "{\"artifactName\":\"" + jsondata['artifactName'] + "\",\"artifactType\":\"" + jsondata['artifactType'] + "\",\"artifactURL\":\"" + self.path + "\",\"artifactDescription\":\"" + jsondata['description'] + "\",\"artifactChecksum\":\"ZjJlMjVmMWE2M2M1OTM2MDZlODlmNTVmZmYzNjViYzM=\",\"artifactUUID\":\"" + str(uuid.uuid4()) + "\",\"artifactVersion\":\"1\"}"
print "jsonGenerated: " + jsonGenerated
-
+
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\"}")
@@ -187,7 +190,7 @@ class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler):
f.write("{\"Content-Length\": \"" + str(len(jsonGenerated)) + "\", \"Content-Type\": \"application/json\"}")
with open(cached_file_content, 'w+') as f:
f.write(jsonGenerated)
- return True
+ return True
elif self.path.startswith("/dcae-deployments/") and http_type == "DELETE":
print "self.path start with /dcae-deployments/ UNDEPLOY, generating response json..."
#jsondata = json.loads(self.data_string)
@@ -222,7 +225,7 @@ class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler):
print "self.path start with DELETE new policy API /policy/api/v1/policytypes/ ..."
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("")) + "\", \"Content-Type\": \""+str("")+"\"}")
with open(cached_file_content, 'w+') as f:
@@ -265,10 +268,34 @@ class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler):
with open(cached_file_content, 'w') as f:
f.write(response)
return True
+ elif (self.path.startswith("/onap/controlloop/v2/commission/toscaservicetemplate")) 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):
+ os.makedirs(cached_file_folder, 0777)
+ with open(cached_file_header, 'w+') as f:
+ f.write("{\"Content-Length\": \"" + str(len(self.data_string)) + "\", \"Content-Type\": \""+str(self.headers['Content-Type'])+"\"}")
+ with open(cached_file_content, 'w+') as f:
+ f.write(self.data_string)
+ return True
else:
return False
-
+
def do_GET(self):
cached_file_folder = ""
cached_file_content =""
@@ -352,7 +379,7 @@ class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler):
_file_available = os.path.exists(cached_file_content)
if not _file_available:
-
+
if not HOST:
self.send_response(404)
self.end_headers()
@@ -492,6 +519,6 @@ class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler):
httpd = SocketServer.ForkingTCPServer(('', PORT), Proxy)
httpd.allow_reuse_address = True
print "Listening on port "+ str(PORT) + "(Press Ctrl+C/Ctrl+Z to stop HTTPD Caching script)"
-print "Caching folder " + CACHE_ROOT + ", Tmp folder for generated files " + TMP_ROOT
+print "Caching folder " + CACHE_ROOT + ", Tmp folder for generated files " + TMP_ROOT
signal.signal(signal.SIGINT, signal_handler)
-httpd.serve_forever() \ No newline at end of file
+httpd.serve_forever()