aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLiam Fallon <liam.fallon@est.tech>2021-11-17 15:15:23 +0000
committerGerrit Code Review <gerrit@onap.org>2021-11-17 15:15:23 +0000
commitc724c6e29c6abae7a53aa77ae05500cdcfaa42f9 (patch)
treef37f9fa44441444cf232242c81ba1287f4a9eb84
parent225dcb4d6f801d88094a9512d79c82c4189c07f6 (diff)
parentaa498ca1fce0d8a267a56bbce4f98f524a0008db (diff)
Merge "Added Camel Unit Tests For Monitoring"
-rw-r--r--runtime/src/main/resources/clds/camel/routes/controlloop-flows.xml8
-rw-r--r--runtime/src/test/java/org/onap/policy/clamp/runtime/RuntimeInstantiationResponseItTestCase.java96
-rw-r--r--runtime/src/test/resources/http-cache/third_party_proxy.py2
3 files changed, 104 insertions, 2 deletions
diff --git a/runtime/src/main/resources/clds/camel/routes/controlloop-flows.xml b/runtime/src/main/resources/clds/camel/routes/controlloop-flows.xml
index ac83ffd7a..200eac780 100644
--- a/runtime/src/main/resources/clds/camel/routes/controlloop-flows.xml
+++ b/runtime/src/main/resources/clds/camel/routes/controlloop-flows.xml
@@ -98,10 +98,16 @@
<setHeader name="Content-Type">
<constant>application/json</constant>
</setHeader>
+ <setProperty name="name">
+ <simple>${header.name}</simple>
+ </setProperty>
+ <setProperty name="version">
+ <simple>${header.version}</simple>
+ </setProperty>
<log loggingLevel="INFO"
message="Endpoint to get Tosca Instantiation: {{clamp.config.controlloop.runtime.url}}/onap/controlloop/v2/instantiation"></log>
<toD
- uri="{{clamp.config.controlloop.runtime.url}}/onap/controlloop/v2/instantiation?bridgeEndpoint=true&amp;useSystemProperties=true&amp;throwExceptionOnFailure=${exchangeProperty[raiseHttpExceptionFlag]}&amp;authMethod=Basic&amp;authUsername={{clamp.config.controlloop.runtime.userName}}&amp;authPassword={{clamp.config.controlloop.runtime.password}}&amp;authenticationPreemptive=true&amp;connectionClose=true"/>
+ uri="{{clamp.config.controlloop.runtime.url}}/onap/controlloop/v2/instantiation?name=${exchangeProperty[name]}&amp;version=${exchangeProperty[version]}&amp;bridgeEndpoint=true&amp;useSystemProperties=true&amp;throwExceptionOnFailure=${exchangeProperty[raiseHttpExceptionFlag]}&amp;authMethod=Basic&amp;authUsername={{clamp.config.controlloop.runtime.userName}}&amp;authPassword={{clamp.config.controlloop.runtime.password}}&amp;authenticationPreemptive=true&amp;connectionClose=true"/>
<convertBodyTo type="java.lang.String"/>
<doFinally>
<to uri="direct:reset-raise-http-exception-flag"/>
diff --git a/runtime/src/test/java/org/onap/policy/clamp/runtime/RuntimeInstantiationResponseItTestCase.java b/runtime/src/test/java/org/onap/policy/clamp/runtime/RuntimeInstantiationResponseItTestCase.java
new file mode 100644
index 000000000..ae80d0498
--- /dev/null
+++ b/runtime/src/test/java/org/onap/policy/clamp/runtime/RuntimeInstantiationResponseItTestCase.java
@@ -0,0 +1,96 @@
+/*
+ * ============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 RuntimeInstantiationResponseItTestCase {
+ @Autowired
+ CamelContext camelContext;
+
+ private static final String DIRECT_GET_TOSCA_INSTANTIATION = "direct:get-tosca-instantiation";
+
+ private static final String SERVICE_TEMPLATE_NAME = "name";
+
+ private static final String SERVICE_TEMPLATE_VERSION = "version";
+
+ private static final String RAISE_HTTP_EXCEPTION_FLAG = "raiseHttpExceptionFlag";
+
+ private static final String SAMPLE_CONTROL_LOOP_LIST = "{\"controlLoopList\": [{\"name\": \"PMSHInstance0\","
+ + "\"version\": \"1.0.1\",\"definition\": {},\"state\": \"UNINITIALISED\",\"orderedState\": \"UNINITIALISED\","
+ + "\"description\": \"PMSH control loop instance 0\",\"elements\": {}}]}";
+
+ @Test
+ public void testToscaServiceTemplateStatus() {
+ ProducerTemplate prodTemplate = camelContext.createProducerTemplate();
+
+ Exchange exchangeResponse =
+ prodTemplate.send(DIRECT_GET_TOSCA_INSTANTIATION, ExchangeBuilder.anExchange(camelContext)
+ .withProperty(SERVICE_TEMPLATE_NAME, "ToscaServiceTemplate")
+ .withProperty(SERVICE_TEMPLATE_VERSION, "1.0.0")
+ .withProperty(RAISE_HTTP_EXCEPTION_FLAG, "true")
+ .build());
+
+ assertThat(HttpStatus.valueOf((Integer) exchangeResponse.getIn().getHeader(Exchange.HTTP_RESPONSE_CODE))
+ .is2xxSuccessful()).isTrue();
+ }
+
+ @Test
+ public void testToscaInstantiationGetResponseBody() {
+ ProducerTemplate prodTemplate = camelContext.createProducerTemplate();
+
+ Exchange exchangeResponse =
+ prodTemplate.send(DIRECT_GET_TOSCA_INSTANTIATION, ExchangeBuilder.anExchange(camelContext)
+ .withProperty(SERVICE_TEMPLATE_NAME, "ToscaServiceTemplate")
+ .withProperty(SERVICE_TEMPLATE_VERSION, "1.0.0")
+ .withProperty(RAISE_HTTP_EXCEPTION_FLAG, "true")
+ .build());
+
+ assertThat(exchangeResponse.getIn().getBody()).hasToString(SAMPLE_CONTROL_LOOP_LIST);
+ }
+
+ @Test
+ public void testToscaInstantiationStatus() {
+ ProducerTemplate prodTemplate = camelContext.createProducerTemplate();
+
+ Exchange exchangeResponse =
+ prodTemplate.send(DIRECT_GET_TOSCA_INSTANTIATION, ExchangeBuilder.anExchange(camelContext)
+ .withBody(SAMPLE_CONTROL_LOOP_LIST)
+ .withProperty(RAISE_HTTP_EXCEPTION_FLAG, "true")
+ .build());
+
+ assertThat(HttpStatus.valueOf((Integer) exchangeResponse.getIn().getHeader(Exchange.HTTP_RESPONSE_CODE))
+ .is2xxSuccessful()).isTrue();
+ }
+}
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 d6628535d..5c80cdda4 100644
--- a/runtime/src/test/resources/http-cache/third_party_proxy.py
+++ b/runtime/src/test/resources/http-cache/third_party_proxy.py
@@ -328,7 +328,7 @@ class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler):
return True
elif (self.path.startswith("/onap/controlloop/v2/instantiation")) and http_type == "GET":
print("self.path start with /instantiation Retrieving Instantiation, generating response json...")
- jsonGenerated = "{\"errorDetails\": null,\"affectedControlLoopDefinitions\": [{ \"name\": \"ToscaServiceTemplateSimple\", \"version\": \"1.0.0\" }]}"
+ jsonGenerated = "{\"controlLoopList\": [{\"name\": \"PMSHInstance0\",\"version\": \"1.0.1\",\"definition\": {},\"state\": \"UNINITIALISED\",\"orderedState\": \"UNINITIALISED\",\"description\": \"PMSH control loop instance 0\",\"elements\": {}}]}";
self._create_cache(jsonGenerated, cached_file_folder, cached_file_header, cached_file_content)
return True
else: