aboutsummaryrefslogtreecommitdiffstats
path: root/runtime
diff options
context:
space:
mode:
authorbrunomilitzer <bruno.militzer@est.tech>2021-11-22 17:42:40 +0000
committerbrunomilitzer <bruno.militzer@est.tech>2021-11-22 17:45:22 +0000
commitbb4a2a1b856bce7ea3d9ede8f8fe8e279f3f0d75 (patch)
tree86da4ee82e747266775a732735ce06bec48c39ec /runtime
parent226d4c344baa504d90ba7a3a4f3e17733ebc1df8 (diff)
Added Camel Unit Tests
Added two camel unit tests related to deleting tosca instance properties and the other to change the order state. Removed name and version paramaters in create instance properties camel rest endpoint. Issue-ID: POLICY-3568 Change-Id: I6cec03545263055eb7c6be2798dd5c8fe5a646b6 Signed-off-by: brunomilitzer <bruno.militzer@est.tech>
Diffstat (limited to 'runtime')
-rw-r--r--runtime/src/main/resources/clds/camel/rest/clamp-api-v2.xml3
-rw-r--r--runtime/src/main/resources/clds/camel/routes/controlloop-flows.xml10
-rw-r--r--runtime/src/test/java/org/onap/policy/clamp/runtime/RuntimeInstantiationResponseItTestCase.java42
-rw-r--r--runtime/src/test/resources/http-cache/third_party_proxy.py10
4 files changed, 52 insertions, 13 deletions
diff --git a/runtime/src/main/resources/clds/camel/rest/clamp-api-v2.xml b/runtime/src/main/resources/clds/camel/rest/clamp-api-v2.xml
index e7ba1283f..8c9824ef7 100644
--- a/runtime/src/main/resources/clds/camel/rest/clamp-api-v2.xml
+++ b/runtime/src/main/resources/clds/camel/rest/clamp-api-v2.xml
@@ -1648,8 +1648,7 @@
<get uri="/v2/toscaControlLoop/getToscaInstantiation" outType="java.lang.String" bindingMode="off" produces="application/json">
<route>
- <removeHeaders pattern="*"
- excludePattern="name|version|requestId"/>
+ <removeHeaders pattern="*"/>
<doTry>
<to uri="bean:org.onap.policy.clamp.flow.log.FlowLogOperation?method=startLog(*, 'GET Tosca Instantiation ')"/>
<to uri="bean:org.onap.policy.clamp.authorization.AuthorizationController?method=authorize(*,'cl','','read')"/>
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 200eac780..146ab14d5 100644
--- a/runtime/src/main/resources/clds/camel/routes/controlloop-flows.xml
+++ b/runtime/src/main/resources/clds/camel/routes/controlloop-flows.xml
@@ -98,16 +98,10 @@
<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?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"/>
+ 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"/>
<convertBodyTo type="java.lang.String"/>
<doFinally>
<to uri="direct:reset-raise-http-exception-flag"/>
@@ -163,7 +157,7 @@
<log loggingLevel="INFO"
message="Endpoint to send Tosca Instance Properties: {{clamp.config.controlloop.runtime.url}}/onap/controlloop/v2/instanceProperties"></log>
<toD
- uri="{{clamp.config.controlloop.runtime.url}}/onap/controlloop/v2/instanceProperties? 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/instanceProperties?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
index fdb815d75..cc08ea0a6 100644
--- a/runtime/src/test/java/org/onap/policy/clamp/runtime/RuntimeInstantiationResponseItTestCase.java
+++ b/runtime/src/test/java/org/onap/policy/clamp/runtime/RuntimeInstantiationResponseItTestCase.java
@@ -41,7 +41,11 @@ public class RuntimeInstantiationResponseItTestCase {
private static final String DIRECT_GET_TOSCA_INSTANTIATION = "direct:get-tosca-instantiation";
- private static final String DIRECT_POST_TOSCA_INSTANTANCE_PROPERTIES = "direct:post-tosca-instance-properties";
+ private static final String DIRECT_POST_TOSCA_INSTANCE_PROPERTIES = "direct:post-tosca-instance-properties";
+
+ private static final String DIRECT_DELETE_TOSCA_INSTANCE_PROPERTIES = "direct:delete-tosca-instance-properties";
+
+ private static final String DIRECT_PUT_TOSCA_INSTANCE_PROPERTIES = "direct:put-tosca-instantiation";
private static final String SERVICE_TEMPLATE_NAME = "name";
@@ -59,6 +63,9 @@ public class RuntimeInstantiationResponseItTestCase {
+ " \"topology_template\": {},"
+ " \"name\": \"ToscaServiceTemplateSimple\", \"version\": \"1.0.0\", \"metadata\": {}}";
+ private static final String SAMPLE_TOSCA_CHANGE_ORDER_STATE = "{\"orderedState\":\"PASSIVE\","
+ + "\"controlLoopIdentifierList\":[{\"name\":\"PMSH_Instance1\",\"version\":\"2.3.1\"}]}";
+
@Test
public void testToscaServiceTemplateStatus() {
ProducerTemplate prodTemplate = camelContext.createProducerTemplate();
@@ -103,11 +110,11 @@ public class RuntimeInstantiationResponseItTestCase {
}
@Test
- public void testCommissioningOfToscaServiceTemplateStatus() {
+ public void testCreateToscaInstancePropertiesStatus() {
ProducerTemplate prodTemplate = camelContext.createProducerTemplate();
Exchange exchangeResponse =
- prodTemplate.send(DIRECT_POST_TOSCA_INSTANTANCE_PROPERTIES, ExchangeBuilder.anExchange(camelContext)
+ prodTemplate.send(DIRECT_POST_TOSCA_INSTANCE_PROPERTIES, ExchangeBuilder.anExchange(camelContext)
.withBody(SAMPLE_TOSCA_TEMPLATE)
.withProperty("raiseHttpExceptionFlag", "true")
.build());
@@ -115,4 +122,33 @@ public class RuntimeInstantiationResponseItTestCase {
assertThat(HttpStatus.valueOf((Integer) exchangeResponse.getIn().getHeader(Exchange.HTTP_RESPONSE_CODE))
.is2xxSuccessful()).isTrue();
}
+
+ @Test
+ public void testDeleteToscaInstancePropertiesStatus() {
+ ProducerTemplate prodTemplate = camelContext.createProducerTemplate();
+
+ Exchange exchangeResponse =
+ prodTemplate.send(DIRECT_DELETE_TOSCA_INSTANCE_PROPERTIES, ExchangeBuilder.anExchange(camelContext)
+ .withProperty("name", "PMSH_Instance1")
+ .withProperty("version", "2.3.1")
+ .withProperty("raiseHttpExceptionFlag", "true")
+ .build());
+
+ assertThat(HttpStatus.valueOf((Integer) exchangeResponse.getIn().getHeader(Exchange.HTTP_RESPONSE_CODE))
+ .is2xxSuccessful()).isTrue();
+ }
+
+ @Test
+ public void testChangeOrderStateStatus() {
+ ProducerTemplate prodTemplate = camelContext.createProducerTemplate();
+
+ Exchange exchangeResponse =
+ prodTemplate.send(DIRECT_PUT_TOSCA_INSTANCE_PROPERTIES, ExchangeBuilder.anExchange(camelContext)
+ .withBody(SAMPLE_TOSCA_CHANGE_ORDER_STATE)
+ .withProperty("raiseHttpExceptionFlag", "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 67af21470..786c366e0 100644
--- a/runtime/src/test/resources/http-cache/third_party_proxy.py
+++ b/runtime/src/test/resources/http-cache/third_party_proxy.py
@@ -340,6 +340,16 @@ class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler):
with open(cached_file_content, 'w+') as f:
f.write(self.data_string)
return True
+ elif (self.path.startswith("/onap/controlloop/v2/instanceProperties")) and http_type == "DELETE":
+ print("self.path start with /instanceProperties Deleting instance properties, generating response json...")
+ jsonGenerated = "{\"errorDetails\": null,\"affectedControlLoopDefinitions\": [{ \"name\": \"PMSH_Instance1\", \"version\": \"2.3.1\" }]}"
+ self._create_cache(jsonGenerated, cached_file_folder, cached_file_header, cached_file_content)
+ return True
+ elif (self.path.startswith("/onap/controlloop/v2/instantiation/command")) and http_type == "PUT":
+ print("self.path start with /instantiation/command Changing order state, generating response json...")
+ jsonGenerated = "{\"orderedState\":\"PASSIVE\",\"controlLoopIdentifierList\":[{\"name\":\"PMSH_Instance1\",\"version\":\"2.3.1\"}]}"
+ self._create_cache(jsonGenerated, cached_file_folder, cached_file_header, cached_file_content)
+ return True
else:
return False