aboutsummaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/org/onap/clamp/clds/client/DcaeDispatcherServicesTest.java19
-rw-r--r--src/test/java/org/onap/clamp/clds/client/req/policy/GuardPolicyAttributesConstructorTest.java3
-rw-r--r--src/test/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyAttributesConstructorTest.java11
-rw-r--r--src/test/java/org/onap/clamp/clds/client/req/tca/TcaRequestFormatterTest.java98
-rw-r--r--src/test/java/org/onap/clamp/clds/config/CldsUserJsonDecoderTest.java3
-rw-r--r--src/test/java/org/onap/clamp/clds/config/sdc/SdcSingleControllerConfigurationTest.java26
-rw-r--r--src/test/java/org/onap/clamp/clds/it/CldsServiceItCase.java2
-rw-r--r--src/test/java/org/onap/clamp/clds/it/DcaeHttpConnectionManagerItCase.java24
-rw-r--r--src/test/java/org/onap/clamp/clds/it/PolicyClientItCase.java67
-rw-r--r--src/test/java/org/onap/clamp/clds/it/config/CldsReferencePropertiesItCase.java42
-rw-r--r--src/test/java/org/onap/clamp/clds/it/config/SdcControllersConfigurationItCase.java3
-rw-r--r--src/test/java/org/onap/clamp/clds/it/sdc/controller/SdcSingleControllerItCase.java6
-rw-r--r--src/test/java/org/onap/clamp/clds/model/prop/CustomModelElement.java12
-rw-r--r--src/test/java/org/onap/clamp/clds/model/prop/ModelPropertiesTest.java32
-rw-r--r--src/test/java/org/onap/clamp/clds/model/sdc/SdcResourceBasicInfoTest.java22
-rw-r--r--src/test/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImplTest.java66
-rw-r--r--src/test/java/org/onap/clamp/clds/util/JacksonUtilsTest.java96
-rw-r--r--src/test/java/org/onap/clamp/clds/util/JsonUtilsTest.java157
-rw-r--r--src/test/resources/example/model-properties/custom/modelBpmnPropertiesMultiVF.json273
-rw-r--r--src/test/resources/tosca/dcea_blueprint.yml170
20 files changed, 919 insertions, 213 deletions
diff --git a/src/test/java/org/onap/clamp/clds/client/DcaeDispatcherServicesTest.java b/src/test/java/org/onap/clamp/clds/client/DcaeDispatcherServicesTest.java
index c828f78a..1b01f544 100644
--- a/src/test/java/org/onap/clamp/clds/client/DcaeDispatcherServicesTest.java
+++ b/src/test/java/org/onap/clamp/clds/client/DcaeDispatcherServicesTest.java
@@ -23,9 +23,8 @@
package org.onap.clamp.clds.client;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableMap;
+import com.google.gson.JsonObject;
import java.io.IOException;
import org.assertj.core.api.Assertions;
import org.junit.Before;
@@ -61,9 +60,13 @@ public class DcaeDispatcherServicesTest {
@InjectMocks
DcaeDispatcherServices dcaeDispatcherServices;
- private final String STATUS_RESPONSE_PROCESSING = "{\"operationType\": \"deploy\",\"status\": \"processing\"}";
- private final String STATUS_RESPONSE_ACTIVE = "{\"operationType\": \"deploy\",\"status\": \"succeeded\"}";
+ private static final String STATUS_RESPONSE_PROCESSING = "{\"operationType\": \"deploy\","
+ + "\"status\": \"processing\"}";
+ private static final String STATUS_RESPONSE_ACTIVE = "{\"operationType\": \"deploy\",\"status\": \"succeeded\"}";
+ /**
+ * Setup method.
+ */
@Before
public void setUp() {
ImmutableMap.<String, String>builder()
@@ -126,10 +129,10 @@ public class DcaeDispatcherServicesTest {
@Test
public void shouldTriggerDeploymentCreation() throws IOException {
//given
- String deploymentID = "closedLoop_152367c8-b172-47b3-9e58-c53add75d869_deploymentId";
+ String deploymentId = "closedLoop_152367c8-b172-47b3-9e58-c53add75d869_deploymentId";
String serviceTypeId = "e2ba40f7-bf42-41e7-acd7-48fd07586d90";
Mockito.when(clampProperties.getJsonTemplate("dcae.deployment.template"))
- .thenReturn(new ObjectMapper().readTree("{}"));
+ .thenReturn(new JsonObject());
Mockito.when(dcaeHttpConnectionManager
.doDcaeHttpQuery(DCAE_URL
@@ -138,11 +141,11 @@ public class DcaeDispatcherServicesTest {
"{\"serviceTypeId\":\"e2ba40f7-bf42-41e7-acd7-48fd07586d90\",\"inputs\":{}}",
"application/json"))
.thenReturn(DEPLOY_RESPONSE_STRING);
- JsonNode blueprintInputJson = new ObjectMapper().readTree("{}");
+ JsonObject blueprintInputJson = new JsonObject();
//when
String operationStatus = dcaeDispatcherServices
- .createNewDeployment(deploymentID, serviceTypeId, blueprintInputJson);
+ .createNewDeployment(deploymentId, serviceTypeId, blueprintInputJson);
//then
Assertions.assertThat(operationStatus).isEqualTo("http://deployment-handler.onap:8443/"
diff --git a/src/test/java/org/onap/clamp/clds/client/req/policy/GuardPolicyAttributesConstructorTest.java b/src/test/java/org/onap/clamp/clds/client/req/policy/GuardPolicyAttributesConstructorTest.java
index f1634567..31785801 100644
--- a/src/test/java/org/onap/clamp/clds/client/req/policy/GuardPolicyAttributesConstructorTest.java
+++ b/src/test/java/org/onap/clamp/clds/client/req/policy/GuardPolicyAttributesConstructorTest.java
@@ -44,6 +44,9 @@ public class GuardPolicyAttributesConstructorTest {
private ModelProperties modelProperties;
private List<PolicyChain> policyChains;
+ /**
+ * @throws Exception thrown if resources not found.
+ */
@Before
public void setUp() throws Exception {
String modelProp = ResourceFileUtil
diff --git a/src/test/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyAttributesConstructorTest.java b/src/test/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyAttributesConstructorTest.java
index 293f0e62..4d78cf81 100644
--- a/src/test/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyAttributesConstructorTest.java
+++ b/src/test/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyAttributesConstructorTest.java
@@ -23,14 +23,11 @@
package org.onap.clamp.clds.client.req.policy;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableMap;
-
+import com.google.gson.JsonElement;
import java.io.IOException;
import java.net.URLDecoder;
import java.util.Map;
-
import org.assertj.core.api.Assertions;
import org.junit.Before;
import org.junit.Test;
@@ -39,6 +36,7 @@ import org.mockito.Mockito;
import org.onap.clamp.clds.config.ClampProperties;
import org.onap.clamp.clds.model.properties.ModelProperties;
import org.onap.clamp.clds.model.properties.PolicyChain;
+import org.onap.clamp.clds.util.JsonUtils;
import org.onap.clamp.clds.util.ResourceFileUtil;
import org.onap.policy.api.AttributeType;
import org.onap.policy.controlloop.policy.ControlLoopPolicy;
@@ -54,6 +52,9 @@ public class OperationalPolicyAttributesConstructorTest {
private ModelProperties modelProperties;
private PolicyChain policyChain;
+ /**
+ * @throws Exception thrown if resource not found.
+ */
@Before
public void setUp() throws Exception {
String modelProp = ResourceFileUtil
@@ -140,7 +141,7 @@ public class OperationalPolicyAttributesConstructorTest {
private PolicyChain readPolicyChainFromResources() throws IOException {
String policyChainText = ResourceFileUtil
.getResourceAsString("example/operational-policy/json-policy-chain.json");
- JsonNode policyChainNode = new ObjectMapper().readTree(policyChainText);
+ JsonElement policyChainNode = JsonUtils.GSON.fromJson(policyChainText, JsonElement.class);
return new PolicyChain(policyChainNode);
}
}
diff --git a/src/test/java/org/onap/clamp/clds/client/req/tca/TcaRequestFormatterTest.java b/src/test/java/org/onap/clamp/clds/client/req/tca/TcaRequestFormatterTest.java
new file mode 100644
index 00000000..095df9d8
--- /dev/null
+++ b/src/test/java/org/onap/clamp/clds/client/req/tca/TcaRequestFormatterTest.java
@@ -0,0 +1,98 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2019 Nokia Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END============================================
+ * ===================================================================
+ *
+ */
+
+package org.onap.clamp.clds.client.req.tca;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import com.google.gson.JsonObject;
+import java.io.IOException;
+import org.junit.Test;
+import org.onap.clamp.clds.config.ClampProperties;
+import org.onap.clamp.clds.model.properties.ModelProperties;
+import org.onap.clamp.clds.model.properties.Tca;
+import org.onap.clamp.clds.model.properties.TcaItem;
+import org.onap.clamp.clds.util.JsonUtils;
+
+public class TcaRequestFormatterTest {
+
+ private static final String TCA_POLICY_PROPERTIES_TEMPLATE = "{"
+ + " \"domain\": \"measurementsForVfScaling\","
+ + " \"metricsPerEventName\": ["
+ + " {"
+ + " \"eventName\": \"???\","
+ + " \"controlLoopSchemaType\": \"VNF\","
+ + " \"policyScope\": \"DCAE\","
+ + " \"policyName\": \"???\","
+ + " \"policyVersion\": \"v0.0.1\","
+ + " \"thresholds\": ["
+ + " ]"
+ + " }"
+ + " ]"
+ + "}";
+
+ @Test
+ public void shouldReturnFormattedTcaPolicyRequest() throws IOException {
+ //given
+ String service = "TestService";
+ String policy = "TestService_scope.PolicyName";
+ ClampProperties clampProperties = mock(ClampProperties.class);
+ String expectedRequestText =
+ "{ "
+ + " \"domain\": \"measurementsForVfScaling\", "
+ + " \"metricsPerEventName\": [ "
+ + " { "
+ + " \"eventName\": \"vLoadBalancer\", "
+ + " \"controlLoopSchemaType\": \"VNF\", "
+ + " \"policyScope\": \"DCAE\", "
+ + " \"policyName\": \"TestService_scope.PolicyName\", "
+ + " \"policyVersion\": \"v0.0.1\", "
+ + " \"thresholds\": [] "
+ + " } "
+ + " ] "
+ + "}";
+
+ JsonObject tcaPolicyPropertiesTemplate = JsonUtils.GSON
+ .fromJson(TCA_POLICY_PROPERTIES_TEMPLATE, JsonObject.class);
+
+ JsonObject expectedRequest = JsonUtils.GSON.fromJson(expectedRequestText, JsonObject.class);
+
+ ModelProperties modelProperties = mock(ModelProperties.class);
+ Tca tca = mock(Tca.class);
+ TcaItem tcaItem = mock(TcaItem.class);
+ when(clampProperties.getJsonTemplate(any(), any())).thenReturn(tcaPolicyPropertiesTemplate);
+ when(tca.getTcaItem()).thenReturn(tcaItem);
+ when(tcaItem.getEventName()).thenReturn("vLoadBalancer");
+ when(tcaItem.getControlLoopSchemaType()).thenReturn("VNF");
+
+ //when
+ JsonObject policyContent = TcaRequestFormatter
+ .createPolicyContent(clampProperties, modelProperties, service, policy, tca);
+
+ //then
+ assertThat(expectedRequest).isEqualTo(policyContent);
+ }
+} \ No newline at end of file
diff --git a/src/test/java/org/onap/clamp/clds/config/CldsUserJsonDecoderTest.java b/src/test/java/org/onap/clamp/clds/config/CldsUserJsonDecoderTest.java
index c04357de..a32a6035 100644
--- a/src/test/java/org/onap/clamp/clds/config/CldsUserJsonDecoderTest.java
+++ b/src/test/java/org/onap/clamp/clds/config/CldsUserJsonDecoderTest.java
@@ -25,10 +25,7 @@
package org.onap.clamp.clds.config;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import java.util.Collections;
import org.junit.Test;
import org.onap.clamp.clds.service.CldsUser;
diff --git a/src/test/java/org/onap/clamp/clds/config/sdc/SdcSingleControllerConfigurationTest.java b/src/test/java/org/onap/clamp/clds/config/sdc/SdcSingleControllerConfigurationTest.java
index 3f0a078b..d27690bf 100644
--- a/src/test/java/org/onap/clamp/clds/config/sdc/SdcSingleControllerConfigurationTest.java
+++ b/src/test/java/org/onap/clamp/clds/config/sdc/SdcSingleControllerConfigurationTest.java
@@ -29,13 +29,13 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
-
+import com.google.gson.JsonObject;
import java.io.IOException;
-
+import java.io.InputStreamReader;
+import java.nio.charset.StandardCharsets;
import org.junit.Test;
import org.onap.clamp.clds.exception.sdc.controller.SdcParametersException;
+import org.onap.clamp.clds.util.JsonUtils;
import org.onap.clamp.clds.util.ResourceFileUtil;
/**
@@ -43,13 +43,19 @@ import org.onap.clamp.clds.util.ResourceFileUtil;
*/
public class SdcSingleControllerConfigurationTest {
+ /**
+ * @param fileName file for sdc controller configuration.
+ * @param sdcControllerName sdc controller name.
+ * @return instance of SdcSingleControllerConfiguration.
+ */
public static SdcSingleControllerConfiguration loadControllerConfiguration(String fileName,
- String sdcControllerName) throws IOException {
- JsonNode jsonNode = new ObjectMapper().readValue(ResourceFileUtil.getResourceAsStream(fileName),
- JsonNode.class);
- SdcSingleControllerConfiguration sdcSingleControllerConfiguration = new SdcSingleControllerConfiguration(
- jsonNode, sdcControllerName);
- return sdcSingleControllerConfiguration;
+ String sdcControllerName) {
+
+ InputStreamReader streamReader = new InputStreamReader(ResourceFileUtil.getResourceAsStream(fileName),
+ StandardCharsets.UTF_8);
+ JsonObject jsonNode = JsonUtils.GSON.fromJson(streamReader, JsonObject.class);
+
+ return new SdcSingleControllerConfiguration(jsonNode, sdcControllerName);
}
@Test
diff --git a/src/test/java/org/onap/clamp/clds/it/CldsServiceItCase.java b/src/test/java/org/onap/clamp/clds/it/CldsServiceItCase.java
index 85218abb..6ab800b3 100644
--- a/src/test/java/org/onap/clamp/clds/it/CldsServiceItCase.java
+++ b/src/test/java/org/onap/clamp/clds/it/CldsServiceItCase.java
@@ -160,7 +160,7 @@ public class CldsServiceItCase {
}
@Test
- public void testGetCLDSDetails() throws IOException {
+ public void testGetCldsDetails() throws IOException {
List<CldsMonitoringDetails> cldsMonitoringDetailsList = cldsService.getCldsDetails();
assertNotNull(cldsMonitoringDetailsList);
}
diff --git a/src/test/java/org/onap/clamp/clds/it/DcaeHttpConnectionManagerItCase.java b/src/test/java/org/onap/clamp/clds/it/DcaeHttpConnectionManagerItCase.java
index 12e8dd90..8e03153a 100644
--- a/src/test/java/org/onap/clamp/clds/it/DcaeHttpConnectionManagerItCase.java
+++ b/src/test/java/org/onap/clamp/clds/it/DcaeHttpConnectionManagerItCase.java
@@ -69,22 +69,22 @@ public class DcaeHttpConnectionManagerItCase {
@Autowired
DcaeHttpConnectionManager dcaeHttpConnectionManager;
- private static TrustManager[] trustAllCerts = new TrustManager[] {
- new X509TrustManager() {
+ private static TrustManager[] trustAllCerts = new TrustManager[]{
+ new X509TrustManager() {
- @Override
- public java.security.cert.X509Certificate[] getAcceptedIssuers() {
- return null;
- }
+ @Override
+ public java.security.cert.X509Certificate[] getAcceptedIssuers() {
+ return null;
+ }
- @Override
- public void checkClientTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
- }
+ @Override
+ public void checkClientTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
+ }
- @Override
- public void checkServerTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
- }
+ @Override
+ public void checkServerTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
}
+ }
};
private void enableSslNoCheck() throws NoSuchAlgorithmException, KeyManagementException {
diff --git a/src/test/java/org/onap/clamp/clds/it/PolicyClientItCase.java b/src/test/java/org/onap/clamp/clds/it/PolicyClientItCase.java
index 31594cba..3acc439a 100644
--- a/src/test/java/org/onap/clamp/clds/it/PolicyClientItCase.java
+++ b/src/test/java/org/onap/clamp/clds/it/PolicyClientItCase.java
@@ -24,7 +24,9 @@
package org.onap.clamp.clds.it;
+import com.google.gson.reflect.TypeToken;
import java.io.IOException;
+import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;
@@ -47,7 +49,7 @@ import org.onap.clamp.clds.model.properties.Policy;
import org.onap.clamp.clds.model.properties.PolicyItem;
import org.onap.clamp.clds.model.properties.Tca;
import org.onap.clamp.clds.transform.XslTransformer;
-import org.onap.clamp.clds.util.JacksonUtils;
+import org.onap.clamp.clds.util.JsonUtils;
import org.onap.clamp.clds.util.LoggingUtils;
import org.onap.clamp.clds.util.ResourceFileUtil;
import org.onap.policy.api.AttributeType;
@@ -67,6 +69,8 @@ import org.springframework.test.context.junit4.SpringRunner;
@SpringBootTest
public class PolicyClientItCase {
+ private static final Type MAP_OF_STRING_TO_OBJECT_TYPE = new TypeToken<Map<String, Object>>() {}.getType();
+
@Autowired
private CldsDao cldsDao;
@Autowired
@@ -82,6 +86,11 @@ public class PolicyClientItCase {
String modelBpmnPropJson;
ModelProperties prop;
+ /**
+ * Setup method.
+ * @throws IOException thrown if resources not found
+ * @throws TransformerException thrown if invalid xml given to transformation
+ */
@Before
public void setUp() throws IOException, TransformerException {
modelProp = ResourceFileUtil.getResourceAsString("example/model-properties/tca_new/model-properties.json");
@@ -94,7 +103,7 @@ public class PolicyClientItCase {
}
@Test
- public void testSendGuardPolicy() throws TransformerException, IOException {
+ public void testSendGuardPolicy() {
// Normally there is only one Guard
List<PolicyItem> policyItems = GuardPolicyAttributesConstructor
.getAllPolicyGuardsFromPolicyChain(prop.getType(Policy.class).getPolicyChains().get(0));
@@ -105,8 +114,7 @@ public class PolicyClientItCase {
String response = policyClient.sendGuardPolicy(
GuardPolicyAttributesConstructor.formatAttributes(prop, policyItem), prop, LoggingUtils.getRequestId(),
policyItem);
- Map<String, Object> mapNodes = JacksonUtils.getObjectMapperInstance()
- .convertValue(JacksonUtils.getObjectMapperInstance().readTree(response), Map.class);
+ Map<String, Object> mapNodes = JsonUtils.GSON.fromJson(response, MAP_OF_STRING_TO_OBJECT_TYPE);
Assertions.assertThat(mapNodes).contains(Assertions.entry("policyClass", "Decision"),
Assertions.entry("policyName",
modelName.replace("-", "_") + "." + controlName + "_Policy_12lup3h_0_Guard_6TtHGPq"),
@@ -124,14 +132,13 @@ public class PolicyClientItCase {
}
@Test
- public void testSendBrmsPolicy()
- throws TransformerException, BuilderException, IllegalArgumentException, IOException {
+ public void testSendBrmsPolicy() throws BuilderException, IllegalArgumentException, IOException {
Map<AttributeType, Map<String, String>> attributes = OperationalPolicyAttributesConstructor.formatAttributes(
refProp, prop, prop.getType(Policy.class).getId(), prop.getType(Policy.class).getPolicyChains().get(0));
String response = policyClient.sendBrmsPolicy(attributes, prop, LoggingUtils.getRequestId());
- Map<String, Object> mapNodes = JacksonUtils.getObjectMapperInstance()
- .convertValue(JacksonUtils.getObjectMapperInstance().readTree(response), Map.class);
+ Map<String, Object> mapNodes = JsonUtils.GSON.fromJson(response, MAP_OF_STRING_TO_OBJECT_TYPE);
+
Assertions.assertThat(mapNodes).contains(Assertions.entry("policyClass", "Config"),
Assertions.entry("policyName", modelName.replace("-", "_") + "." + controlName + "_Policy_12lup3h_0"),
Assertions.entry("policyConfigType", PolicyConfigType.BRMS_PARAM.name()),
@@ -144,14 +151,13 @@ public class PolicyClientItCase {
}
@Test
- public void testSendMicroServiceInJson()
- throws TransformerException, BuilderException, IllegalArgumentException, IOException {
+ public void testSendMicroServiceInJson() throws IllegalArgumentException {
prop.setCurrentModelElementId(prop.getType(Policy.class).getId());
String jsonToSend = "{\"test\":\"test\"}";
String response = policyClient.sendMicroServiceInJson(jsonToSend, prop, LoggingUtils.getRequestId());
- Map<String, Object> mapNodes = JacksonUtils.getObjectMapperInstance()
- .convertValue(JacksonUtils.getObjectMapperInstance().readTree(response), Map.class);
+ Map<String, Object> mapNodes = JsonUtils.GSON.fromJson(response, MAP_OF_STRING_TO_OBJECT_TYPE);
+
Assertions.assertThat(mapNodes).contains(Assertions.entry("policyClass", "Config"),
Assertions.entry("policyName", modelName.replace("-", "_") + "." + controlName + "_Policy_12lup3h"),
Assertions.entry("policyConfigType", PolicyConfigType.MicroService.name()),
@@ -165,8 +171,8 @@ public class PolicyClientItCase {
public void testSendBasePolicyInOther() throws IllegalArgumentException, IOException {
String body = "test";
String response = policyClient.sendBasePolicyInOther(body, "myPolicy", prop, LoggingUtils.getRequestId());
- Map<String, Object> mapNodes = JacksonUtils.getObjectMapperInstance()
- .convertValue(JacksonUtils.getObjectMapperInstance().readTree(response), Map.class);
+ Map<String, Object> mapNodes = JsonUtils.GSON.fromJson(response, MAP_OF_STRING_TO_OBJECT_TYPE);
+
Assertions.assertThat(mapNodes).contains(Assertions.entry("policyClass", "Config"),
Assertions.entry("policyName", "myPolicy"),
Assertions.entry("policyConfigType", PolicyConfigType.Base.name()),
@@ -181,8 +187,8 @@ public class PolicyClientItCase {
String tcaJson = TcaRequestFormatter.createPolicyJson(refProp, prop);
String response = policyClient.sendMicroServiceInOther(tcaJson, prop);
- Map<String, Object> mapNodes = JacksonUtils.getObjectMapperInstance()
- .convertValue(JacksonUtils.getObjectMapperInstance().readTree(response), Map.class);
+ Map<String, Object> mapNodes = JsonUtils.GSON.fromJson(response, MAP_OF_STRING_TO_OBJECT_TYPE);
+
Assertions.assertThat(mapNodes).contains(Assertions.entry("policyClass", "Config"),
Assertions.entry("policyName", modelName.replace("-", "_") + "." + controlName + "_TCA_1d13unw"),
Assertions.entry("policyConfigType", PolicyConfigType.MicroService.name()),
@@ -196,10 +202,10 @@ public class PolicyClientItCase {
String[] responses = policyClient.deleteMicrosService(prop).split("\\}\\{");
// There are 2 responses appended to the result, one for PDP one for PAP !
- Map<String, Object> mapNodesPdp = JacksonUtils.getObjectMapperInstance()
- .convertValue(JacksonUtils.getObjectMapperInstance().readTree(responses[0] + "}"), Map.class);
- Map<String, Object> mapNodesPap = JacksonUtils.getObjectMapperInstance()
- .convertValue(JacksonUtils.getObjectMapperInstance().readTree("{" + responses[1]), Map.class);
+ Map<String, Object> mapNodesPdp = JsonUtils.GSON.fromJson(responses[0] + "}",
+ MAP_OF_STRING_TO_OBJECT_TYPE);
+ Map<String, Object> mapNodesPap = JsonUtils.GSON.fromJson("{" + responses[1],
+ MAP_OF_STRING_TO_OBJECT_TYPE);
Assertions.assertThat(mapNodesPdp).contains(
Assertions.entry("policyName", modelName.replace("-", "_") + "." + controlName + "_TCA_1d13unw"),
@@ -221,11 +227,10 @@ public class PolicyClientItCase {
prop.setGuardUniqueId(policyItems.get(0).getId());
String[] responses = policyClient.deleteGuard(prop).split("\\}\\{");
- // There are 2 responses appended to the result, one for PDP one for PAP !
- Map<String, Object> mapNodesPdp = JacksonUtils.getObjectMapperInstance()
- .convertValue(JacksonUtils.getObjectMapperInstance().readTree(responses[0] + "}"), Map.class);
- Map<String, Object> mapNodesPap = JacksonUtils.getObjectMapperInstance()
- .convertValue(JacksonUtils.getObjectMapperInstance().readTree("{" + responses[1]), Map.class);
+ Map<String, Object> mapNodesPdp = JsonUtils.GSON.fromJson(responses[0] + "}",
+ MAP_OF_STRING_TO_OBJECT_TYPE);
+ Map<String, Object> mapNodesPap = JsonUtils.GSON.fromJson("{" + responses[1],
+ MAP_OF_STRING_TO_OBJECT_TYPE);
Assertions.assertThat(mapNodesPdp).contains(
Assertions.entry("policyName",
@@ -245,11 +250,10 @@ public class PolicyClientItCase {
prop.setCurrentModelElementId(prop.getType(Policy.class).getId());
String[] responses = policyClient.deleteBrms(prop).split("\\}\\{");
- // There are 2 responses appended to the result, one for PDP one for PAP !
- Map<String, Object> mapNodesPdp = JacksonUtils.getObjectMapperInstance()
- .convertValue(JacksonUtils.getObjectMapperInstance().readTree(responses[0] + "}"), Map.class);
- Map<String, Object> mapNodesPap = JacksonUtils.getObjectMapperInstance()
- .convertValue(JacksonUtils.getObjectMapperInstance().readTree("{" + responses[1]), Map.class);
+ Map<String, Object> mapNodesPdp = JsonUtils.GSON.fromJson(responses[0] + "}",
+ MAP_OF_STRING_TO_OBJECT_TYPE);
+ Map<String, Object> mapNodesPap = JsonUtils.GSON.fromJson("{" + responses[1],
+ MAP_OF_STRING_TO_OBJECT_TYPE);
Assertions.assertThat(mapNodesPdp).contains(
Assertions.entry("policyName", modelName.replace("-", "_") + "." + controlName + "_Policy_12lup3h_0"),
@@ -273,7 +277,8 @@ public class PolicyClientItCase {
String tosca = policyClient.importToscaModel(cldsToscaModel);
Assertions.assertThat(tosca).contains(
- "{\"serviceName\":\"tca-policy-test\",\"description\":\"tca-policy-test\",\"requestID\":null,\"filePath\":\"/tmp/tosca-models/tca-policy-test.yml\",");
+ "{\"serviceName\":\"tca-policy-test\",\"description\":\"tca-policy-test\","
+ + "\"requestID\":null,\"filePath\":\"/tmp/tosca-models/tca-policy-test.yml\",");
Assertions.assertThat(tosca).contains(toscaModelYaml);
}
}
diff --git a/src/test/java/org/onap/clamp/clds/it/config/CldsReferencePropertiesItCase.java b/src/test/java/org/onap/clamp/clds/it/config/CldsReferencePropertiesItCase.java
index 9d58ba8f..630e8c02 100644
--- a/src/test/java/org/onap/clamp/clds/it/config/CldsReferencePropertiesItCase.java
+++ b/src/test/java/org/onap/clamp/clds/it/config/CldsReferencePropertiesItCase.java
@@ -28,8 +28,8 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
-import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.google.gson.JsonElement;
import java.io.IOException;
import java.util.List;
@@ -62,24 +62,34 @@ public class CldsReferencePropertiesItCase {
assertNull(refProp.getStringValue("does.not.exist"));
}
- /**
- * Test getting prop value as a JSON Node / template.
- *
- * @throws IOException
- * when JSON parsing fails
- */
@Test
- public void testGetJsonTemplate() throws IOException {
- // ui.location.default={"DC1":"Data Center 1","DC2":"Data Center
- // 2","DC3":"Data Center 3"}
- ObjectNode root = (ObjectNode) refProp.getJsonTemplate("ui.location.default");
+ public void shouldReturnJsonFromTemplate() throws IOException {
+ //when
+ JsonElement root = refProp.getJsonTemplate("ui.location.default");
+
+ //then
assertNotNull(root);
- assertEquals(root.get("DC1").asText(), "Data Center 1");
- // Test composite key
- root = (ObjectNode) refProp.getJsonTemplate("ui.location", "default");
+ assertTrue(root.isJsonObject());
+ assertEquals(root.getAsJsonObject().get("DC1").getAsString(), "Data Center 1");
+ }
+
+ @Test
+ public void shouldReturnJsonFromTemplate_2() throws IOException {
+ //when
+ JsonElement root = refProp.getJsonTemplate("ui.location", "default");
+
+ //then
assertNotNull(root);
- assertEquals(root.get("DC1").asText(), "Data Center 1");
- root = (ObjectNode) refProp.getJsonTemplate("ui.location", "");
+ assertTrue(root.isJsonObject());
+ assertEquals(root.getAsJsonObject().get("DC1").getAsString(), "Data Center 1");
+ }
+
+ @Test
+ public void shouldReturnNullIfPropertyNotFound() throws IOException {
+ //when
+ JsonElement root = refProp.getJsonTemplate("ui.location", "");
+
+ //then
assertNull(root);
}
diff --git a/src/test/java/org/onap/clamp/clds/it/config/SdcControllersConfigurationItCase.java b/src/test/java/org/onap/clamp/clds/it/config/SdcControllersConfigurationItCase.java
index 0cab4b9d..8fd817cb 100644
--- a/src/test/java/org/onap/clamp/clds/it/config/SdcControllersConfigurationItCase.java
+++ b/src/test/java/org/onap/clamp/clds/it/config/SdcControllersConfigurationItCase.java
@@ -24,6 +24,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+import com.google.gson.JsonSyntaxException;
import java.io.IOException;
import java.util.Map;
@@ -71,7 +72,7 @@ public class SdcControllersConfigurationItCase {
sdcControllersConfiguration.getSdcSingleControllerConfiguration("sdc-controller2").getSdcControllerName());
}
- @Test(expected = IOException.class)
+ @Test(expected = JsonSyntaxException.class)
public void testBadJsonLoading() throws IOException {
loadFile("classpath:/clds/sdc-controllers-config-bad.json");
fail("Should have raised an exception");
diff --git a/src/test/java/org/onap/clamp/clds/it/sdc/controller/SdcSingleControllerItCase.java b/src/test/java/org/onap/clamp/clds/it/sdc/controller/SdcSingleControllerItCase.java
index 9eaca5f7..c6dbce4c 100644
--- a/src/test/java/org/onap/clamp/clds/it/sdc/controller/SdcSingleControllerItCase.java
+++ b/src/test/java/org/onap/clamp/clds/it/sdc/controller/SdcSingleControllerItCase.java
@@ -23,7 +23,6 @@
package org.onap.clamp.clds.it.sdc.controller;
-import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@@ -89,8 +88,11 @@ public class SdcSingleControllerItCase {
return notifData;
}
+ /**
+ * Initialization method.
+ */
@Before
- public void init() throws IOException {
+ public void init() {
sdcSingleController = new SdcSingleController(clampProp, Mockito.mock(CsarInstaller.class),
SdcSingleControllerConfigurationTest.loadControllerConfiguration("clds/sdc-controller-config-TLS.json",
"sdc-controller1"),
diff --git a/src/test/java/org/onap/clamp/clds/model/prop/CustomModelElement.java b/src/test/java/org/onap/clamp/clds/model/prop/CustomModelElement.java
index 7d3a2158..871d0a65 100644
--- a/src/test/java/org/onap/clamp/clds/model/prop/CustomModelElement.java
+++ b/src/test/java/org/onap/clamp/clds/model/prop/CustomModelElement.java
@@ -18,16 +18,16 @@
* limitations under the License.
* ============LICENSE_END============================================
* ===================================================================
- *
+ *
*/
package org.onap.clamp.clds.model.prop;
-import com.fasterxml.jackson.databind.JsonNode;
-
+import com.google.gson.JsonObject;
import org.onap.clamp.clds.model.properties.AbstractModelElement;
import org.onap.clamp.clds.model.properties.ModelBpmn;
import org.onap.clamp.clds.model.properties.ModelProperties;
+import org.onap.clamp.clds.util.JsonUtils;
/**
* A CustomModelElement to test the capability to add new elements on the fly.
@@ -40,10 +40,10 @@ public class CustomModelElement extends AbstractModelElement {
/**
* Main Constructor.
*/
- public CustomModelElement(ModelProperties modelProp, ModelBpmn modelBpmn, JsonNode modelJson) {
+ public CustomModelElement(ModelProperties modelProp, ModelBpmn modelBpmn, JsonObject modelJson) {
super(CUSTOM_TYPE, modelProp, modelBpmn, modelJson);
- topicPublishes = getValueByName("topicPublishes");
- test = this.getValueByName("test");
+ topicPublishes = JsonUtils.getStringValueByName(modelElementJsonNode, "topicPublishes");
+ test = JsonUtils.getStringValueByName(modelElementJsonNode, "test");
}
public static final String getType() {
diff --git a/src/test/java/org/onap/clamp/clds/model/prop/ModelPropertiesTest.java b/src/test/java/org/onap/clamp/clds/model/prop/ModelPropertiesTest.java
index 295ccc59..4195f907 100644
--- a/src/test/java/org/onap/clamp/clds/model/prop/ModelPropertiesTest.java
+++ b/src/test/java/org/onap/clamp/clds/model/prop/ModelPropertiesTest.java
@@ -23,6 +23,7 @@
package org.onap.clamp.clds.model.prop;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
@@ -36,6 +37,7 @@ import org.onap.clamp.clds.model.CldsModel;
import org.onap.clamp.clds.model.properties.Holmes;
import org.onap.clamp.clds.model.properties.ModelProperties;
import org.onap.clamp.clds.model.properties.Policy;
+import org.onap.clamp.clds.model.properties.PolicyItem;
import org.onap.clamp.clds.model.properties.Tca;
import org.onap.clamp.clds.util.ResourceFileUtil;
@@ -61,11 +63,12 @@ public class ModelPropertiesTest {
assertEquals(1, policy.getPolicyChains().size());
assertEquals("0", policy.getPolicyChains().get(0).getPolicyId());
assertEquals(1, policy.getPolicyChains().get(0).getPolicyItems().size());
- assertEquals("resourceid", policy.getPolicyChains().get(0).getPolicyItems().get(0).getTargetResourceId());
- assertEquals(180, policy.getPolicyChains().get(0).getPolicyItems().get(0).getRetryTimeLimit());
- assertEquals(3, policy.getPolicyChains().get(0).getPolicyItems().get(0).getMaxRetries());
- assertEquals("", policy.getPolicyChains().get(0).getPolicyItems().get(0).getParentPolicy());
- assertEquals(null, policy.getPolicyChains().get(0).getPolicyItems().get(0).getParentPolicyConditions());
+ PolicyItem firstPolicyItem = policy.getPolicyChains().get(0).getPolicyItems().get(0);
+ assertEquals("resourceid", firstPolicyItem.getTargetResourceId());
+ assertEquals(180, firstPolicyItem.getRetryTimeLimit());
+ assertEquals(3, firstPolicyItem.getMaxRetries());
+ assertEquals("", firstPolicyItem.getParentPolicy());
+ assertThat(firstPolicyItem.getParentPolicyConditions()).isEmpty();
Tca tca = prop.getType(Tca.class);
assertNotNull(tca);
assertTrue(tca.isFound());
@@ -91,8 +94,8 @@ public class ModelPropertiesTest {
prop.getGlobal().getResourceVf().toArray()));
assertTrue(Arrays.equals(new String[] { "SNDGCA64", "ALPRGAED", "LSLEILAA", "MDTWNJC1" },
prop.getGlobal().getLocation().toArray()));
- assertEquals("value1", prop.getGlobal().getDeployParameters().get("input1").asText());
- assertEquals("value2", prop.getGlobal().getDeployParameters().get("input2").asText());
+ assertEquals("value1", prop.getGlobal().getDeployParameters().get("input1").getAsString());
+ assertEquals("value2", prop.getGlobal().getDeployParameters().get("input2").getAsString());
}
@Test
@@ -107,11 +110,12 @@ public class ModelPropertiesTest {
assertEquals(1, policy.getPolicyChains().size());
assertEquals("0", policy.getPolicyChains().get(0).getPolicyId());
assertEquals(1, policy.getPolicyChains().get(0).getPolicyItems().size());
- assertEquals("resourceid", policy.getPolicyChains().get(0).getPolicyItems().get(0).getTargetResourceId());
- assertEquals(180, policy.getPolicyChains().get(0).getPolicyItems().get(0).getRetryTimeLimit());
- assertEquals(3, policy.getPolicyChains().get(0).getPolicyItems().get(0).getMaxRetries());
- assertEquals("", policy.getPolicyChains().get(0).getPolicyItems().get(0).getParentPolicy());
- assertEquals(null, policy.getPolicyChains().get(0).getPolicyItems().get(0).getParentPolicyConditions());
+ PolicyItem firstPolicyItem = policy.getPolicyChains().get(0).getPolicyItems().get(0);
+ assertEquals("resourceid", firstPolicyItem.getTargetResourceId());
+ assertEquals(180, firstPolicyItem.getRetryTimeLimit());
+ assertEquals(3, firstPolicyItem.getMaxRetries());
+ assertEquals("", firstPolicyItem.getParentPolicy());
+ assertThat(firstPolicyItem.getParentPolicyConditions()).isEmpty();
Holmes holmes = prop.getType(Holmes.class);
assertNotNull(holmes);
assertTrue(holmes.isFound());
@@ -124,8 +128,8 @@ public class ModelPropertiesTest {
prop.getGlobal().getResourceVf().toArray()));
assertTrue(Arrays.equals(new String[] { "SNDGCA64", "ALPRGAED", "LSLEILAA", "MDTWNJC1" },
prop.getGlobal().getLocation().toArray()));
- assertEquals("value1", prop.getGlobal().getDeployParameters().get("input1").asText());
- assertEquals("value2", prop.getGlobal().getDeployParameters().get("input2").asText());
+ assertEquals("value1", prop.getGlobal().getDeployParameters().get("input1").getAsString());
+ assertEquals("value2", prop.getGlobal().getDeployParameters().get("input2").getAsString());
}
@Test
diff --git a/src/test/java/org/onap/clamp/clds/model/sdc/SdcResourceBasicInfoTest.java b/src/test/java/org/onap/clamp/clds/model/sdc/SdcResourceBasicInfoTest.java
index 119fd218..5adb0647 100644
--- a/src/test/java/org/onap/clamp/clds/model/sdc/SdcResourceBasicInfoTest.java
+++ b/src/test/java/org/onap/clamp/clds/model/sdc/SdcResourceBasicInfoTest.java
@@ -31,15 +31,17 @@ public class SdcResourceBasicInfoTest {
@Test
public void testHashCode() {
SdcResourceBasicInfo sdc1a = new SdcResourceBasicInfo();
- SdcResourceBasicInfo sdc1b = new SdcResourceBasicInfo();
- SdcResourceBasicInfo sdc2 = new SdcResourceBasicInfo();
sdc1a.setName("test1");
sdc1a.setVersion("1.0");
- sdc1b.setName("test1");
- sdc1b.setVersion("2.0");
+
+ SdcResourceBasicInfo sdc2 = new SdcResourceBasicInfo();
sdc2.setName("test2");
sdc2.setVersion("2.0");
+ SdcResourceBasicInfo sdc1b = new SdcResourceBasicInfo();
+ sdc1b.setName("test1");
+ sdc1b.setVersion("2.0");
+
Assertions.assertThat(sdc1a.hashCode()).isNotEqualTo(sdc1b.hashCode());
Assertions.assertThat(sdc1b.hashCode()).isNotEqualTo(sdc2.hashCode());
sdc1b.setVersion("1.0");
@@ -50,12 +52,14 @@ public class SdcResourceBasicInfoTest {
@Test
public void testCompareTo() {
SdcResourceBasicInfo sdc1a = new SdcResourceBasicInfo();
- SdcResourceBasicInfo sdc1b = new SdcResourceBasicInfo();
- SdcResourceBasicInfo sdc2 = new SdcResourceBasicInfo();
sdc1a.setName("test1");
sdc1a.setVersion("1.0");
+
+ SdcResourceBasicInfo sdc1b = new SdcResourceBasicInfo();
sdc1b.setName("test1");
sdc1b.setVersion("2.0");
+
+ SdcResourceBasicInfo sdc2 = new SdcResourceBasicInfo();
sdc2.setName("test2");
sdc2.setVersion("2.0");
@@ -68,12 +72,14 @@ public class SdcResourceBasicInfoTest {
@Test
public void testEquals() {
SdcResourceBasicInfo sdc1a = new SdcResourceBasicInfo();
- SdcResourceBasicInfo sdc1b = new SdcResourceBasicInfo();
- SdcResourceBasicInfo sdc2 = new SdcResourceBasicInfo();
sdc1a.setName("test1");
sdc1a.setVersion("1.0");
+
+ SdcResourceBasicInfo sdc1b = new SdcResourceBasicInfo();
sdc1b.setName("test1");
sdc1b.setVersion("2.0");
+
+ SdcResourceBasicInfo sdc2 = new SdcResourceBasicInfo();
sdc2.setName("test2");
sdc2.setVersion("2.0");
diff --git a/src/test/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImplTest.java b/src/test/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImplTest.java
new file mode 100644
index 00000000..a995c523
--- /dev/null
+++ b/src/test/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImplTest.java
@@ -0,0 +1,66 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2019 Nokia Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END============================================
+ * ===================================================================
+ *
+ */
+
+package org.onap.clamp.clds.sdc.controller.installer;
+
+import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import com.google.gson.JsonObject;
+import java.io.IOException;
+import org.junit.Test;
+import org.onap.clamp.clds.util.JsonUtils;
+import org.onap.clamp.clds.util.ResourceFileUtil;
+
+public class CsarInstallerImplTest {
+
+ @Test
+ public void shouldReturnInputParametersFromBlueprint() throws IOException {
+ //given
+ String expectedBlueprintInputsText = "{\"aaiEnrichmentHost\":\"aai.onap.svc.cluster.local\""
+ + ",\"aaiEnrichmentPort\":\"8443\""
+ + ",\"enableAAIEnrichment\":true"
+ + ",\"dmaap_host\":\"message-router\""
+ + ",\"dmaap_port\":\"3904\""
+ + ",\"enableRedisCaching\":false"
+ + ",\"redisHosts\":\"dcae-redis:6379\""
+ + ",\"tag_version\":\"nexus3.onap.org:10001/onap/org.onap.dcaegen2.deployments.tca-cdap-container:1.1.0\""
+ + ",\"consul_host\":\"consul-server\""
+ + ",\"consul_port\":\"8500\",\"cbs_host\":\"{\\\"test\\\":"
+ + "{\\\"test\\\":\\\"test\\\"}}\",\"cbs_port\":\"10000\""
+ + ",\"external_port\":\"32010\",\"policy_id\":\"AUTO_GENERATED_POLICY_ID_AT_SUBMIT\"}";
+
+ JsonObject expectedBlueprintInputs = JsonUtils.GSON.fromJson(expectedBlueprintInputsText, JsonObject.class);
+ String dceaBlueprint = ResourceFileUtil.getResourceAsString("tosca/dcea_blueprint.yml");
+ BlueprintArtifact blueprintArtifact = mock(BlueprintArtifact.class);
+ when(blueprintArtifact.getDcaeBlueprint()).thenReturn(dceaBlueprint);
+ CsarInstallerImpl csarInstaller = new CsarInstallerImpl();
+
+ //when
+ String parametersInJson = csarInstaller.getAllBlueprintParametersInJson(blueprintArtifact);
+
+ //then
+ assertThat(JsonUtils.GSON.fromJson(parametersInJson, JsonObject.class)).isEqualTo(expectedBlueprintInputs);
+ }
+} \ No newline at end of file
diff --git a/src/test/java/org/onap/clamp/clds/util/JacksonUtilsTest.java b/src/test/java/org/onap/clamp/clds/util/JacksonUtilsTest.java
deleted file mode 100644
index 1d9e4e79..00000000
--- a/src/test/java/org/onap/clamp/clds/util/JacksonUtilsTest.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP CLAMP
- * ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights
- * reserved.
- * ================================================================================
- * 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.
- * ============LICENSE_END============================================
- * ===================================================================
- *
- */
-
-package org.onap.clamp.clds.util;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-
-import com.fasterxml.jackson.core.JsonParseException;
-import com.fasterxml.jackson.databind.JsonMappingException;
-
-import java.io.IOException;
-
-import org.junit.Test;
-
-public class JacksonUtilsTest {
-
- public static class TestClass extends TestObject {
-
- String test2;
- TestObject2 object2;
-
- public TestClass(String value1, String value2) {
- super(value1);
- test2 = value2;
- }
-
- public TestClass() {
- }
-
- public String getTest2() {
- return test2;
- }
-
- public void setTest2(String test2) {
- this.test2 = test2;
- }
-
- public TestObject2 getObject2() {
- return object2;
- }
-
- public void setObject2(TestObject2 object2) {
- this.object2 = object2;
- }
- }
-
- @Test
- public void testGetObjectMapperInstance() {
- assertNotNull(JacksonUtils.getObjectMapperInstance());
- }
-
- /**
- * This method test that the security hole in Jackson is not enabled in the
- * default ObjectMapper.
- *
- * @throws JsonParseException
- * In case of issues
- * @throws JsonMappingException
- * In case of issues
- * @throws IOException
- * In case of issues
- */
- @Test
- public void testCreateBeanDeserializer() throws JsonParseException, JsonMappingException, IOException {
- TestClass test = new TestClass("value1", "value2");
- test.setObject2(new TestObject2("test3"));
- Object testObject = JacksonUtils.getObjectMapperInstance()
- .readValue("[\"org.onap.clamp.clds.util.JacksonUtilsTest$TestClass\""
- + ",{\"test\":\"value1\",\"test2\":\"value2\",\"object2\":[\"org.onap.clamp.clds.util.TestObject2\","
- + "{\"test3\":\"test3\"}]}]", Object.class);
- assertNotNull(testObject);
- assertFalse(testObject instanceof TestObject);
- assertFalse(testObject instanceof TestClass);
- }
-}
diff --git a/src/test/java/org/onap/clamp/clds/util/JsonUtilsTest.java b/src/test/java/org/onap/clamp/clds/util/JsonUtilsTest.java
new file mode 100644
index 00000000..3e11b8a2
--- /dev/null
+++ b/src/test/java/org/onap/clamp/clds/util/JsonUtilsTest.java
@@ -0,0 +1,157 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2018 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END============================================
+ * Modifications copyright (c) 2019 Nokia
+ * ===================================================================
+ *
+ */
+
+package org.onap.clamp.clds.util;
+
+import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import java.io.IOException;
+
+import java.util.List;
+import org.junit.Test;
+
+public class JsonUtilsTest {
+
+ public static class TestClass extends TestObject {
+
+ String test2;
+ TestObject2 object2;
+
+ TestClass(String value1, String value2) {
+ super(value1);
+ test2 = value2;
+ }
+
+ void setObject2(TestObject2 object2) {
+ this.object2 = object2;
+ }
+ }
+
+ private static final JsonObject DEPLOY_PARAMETERS = JsonUtils.GSON.fromJson(
+ "{\n"
+ + " \"aaiEnrichmentHost\": \"aai.onap.svc.cluster.local\",\n"
+ + " \"aaiEnrichmentPort\": \"8443\",\n"
+ + " \"enableAAIEnrichment\": true,\n"
+ + " \"dmaap_host\": \"message-router\",\n"
+ + " \"dmaap_port\": \"3904\",\n"
+ + " \"enableRedisCaching\": false,\n"
+ + " \"redisHosts\": \"dcae-redis:6379\",\n"
+ + " \"tag_version\": \"nexus3.onap.org:10001/onap/org.onap.dcaegen2."
+ + "deployments.tca-cdap-container:1.1.0\",\n"
+ + " \"consul_host\": \"consul-server\",\n"
+ + " \"consul_port\": \"8500\",\n"
+ + " \"cbs_host\": \"config-binding-service\",\n"
+ + " \"cbs_port\": \"10000\",\n"
+ + " \"external_port\": \"32010\",\n"
+ + " \"policy_id\": \"AUTO_GENERATED_POLICY_ID_AT_SUBMIT\"\n"
+ + " }", JsonObject.class);
+
+
+ @Test
+ public void testGetObjectMapperInstance() {
+ assertNotNull(JsonUtils.GSON);
+ }
+
+ /**
+ * This method test that the security hole in Jackson is not enabled in the default ObjectMapper.
+ */
+ @Test
+ public void testCreateBeanDeserializer() {
+ TestClass test = new TestClass("value1", "value2");
+ test.setObject2(new TestObject2("test3"));
+ Object testObject = JsonUtils.GSON.fromJson("[\"org.onap.clamp.clds.util.JsonUtilsTest$TestClass\""
+ + ",{\"test\":\"value1\",\"test2\":\"value2\",\"object2\":[\"org.onap.clamp.clds.util.TestObject2\","
+ + "{\"test3\":\"test3\"}]}]", Object.class);
+ assertNotNull(testObject);
+ assertFalse(testObject instanceof TestObject);
+ }
+
+
+ @Test
+ public void shouldReturnJsonValueByName() throws IOException {
+ //given
+ String modelProperties = ResourceFileUtil
+ .getResourceAsString("example/model-properties/custom/modelBpmnPropertiesMultiVF.json");
+ JsonElement globalElement = JsonUtils.GSON.fromJson(modelProperties, JsonObject.class).get("global");
+
+ //when
+ String locationName = JsonUtils.getStringValueByName(globalElement, "location");
+ String timeoutValue = JsonUtils.getStringValueByName(globalElement, "timeout");
+
+ //then
+ assertThat(locationName).isEqualTo("SNDGCA64");
+ assertThat(timeoutValue).isEqualTo("500");
+ }
+
+ @Test
+ public void shouldReturnJsonObjectByPropertyName() throws IOException {
+ //given
+ String modelProperties = ResourceFileUtil
+ .getResourceAsString("example/model-properties/custom/modelBpmnPropertiesMultiVF.json");
+ JsonElement globalElement = JsonUtils.GSON.fromJson(modelProperties, JsonObject.class).get("global");
+
+ //when
+ JsonObject deployParameters = JsonUtils.getJsonObjectByName(globalElement, "deployParameters");
+
+ //then
+ assertThat(deployParameters).isEqualToComparingFieldByField(DEPLOY_PARAMETERS);
+ }
+
+ @Test
+ public void shouldReturnJsonValuesByPropertyName() throws IOException {
+ //given
+ String modelProperties = ResourceFileUtil
+ .getResourceAsString("example/model-properties/custom/modelBpmnPropertiesMultiVF.json");
+ JsonElement globalElement = JsonUtils.GSON.fromJson(modelProperties, JsonObject.class).get("global");
+
+ //when
+ List<String> vfs = JsonUtils.getStringValuesByName(globalElement, "vf");
+
+ //then
+ assertThat(vfs).containsExactly(
+ "6c7aaec2-59eb-41d9-8681-b7f976ab668d",
+ "8sadsad0-a98s-6a7s-fd12-sadji9sa8d12",
+ "8sfd71ad-a90d-asd9-as87-8a7sd81adsaa"
+ );
+ }
+
+
+ @Test
+ public void shouldReturnJsonValueAsInteger() throws IOException {
+ //given
+ String modelProperties = ResourceFileUtil
+ .getResourceAsString("example/model-properties/custom/modelBpmnPropertiesMultiVF.json");
+ JsonElement globalElement = JsonUtils.GSON.fromJson(modelProperties, JsonObject.class).get("global");
+
+ //when
+ Integer timeoutValue = JsonUtils.getIntValueByName(globalElement, "timeout");
+
+ //then
+ assertThat(timeoutValue).isEqualTo(500);
+ }
+}
diff --git a/src/test/resources/example/model-properties/custom/modelBpmnPropertiesMultiVF.json b/src/test/resources/example/model-properties/custom/modelBpmnPropertiesMultiVF.json
new file mode 100644
index 00000000..211aaecf
--- /dev/null
+++ b/src/test/resources/example/model-properties/custom/modelBpmnPropertiesMultiVF.json
@@ -0,0 +1,273 @@
+{
+ "global":
+ [
+ {
+ "name": "service",
+ "value":
+ [
+ "0f983e18-4603-4bb4-a98c-e29691fb16a1"
+ ]
+ },
+
+ {
+ "name": "vf",
+ "value":
+ [
+ "6c7aaec2-59eb-41d9-8681-b7f976ab668d",
+ "8sadsad0-a98s-6a7s-fd12-sadji9sa8d12",
+ "8sfd71ad-a90d-asd9-as87-8a7sd81adsaa"
+ ]
+ },
+
+ {
+ "name": "actionSet",
+ "value":
+ [
+ "vnfRecipe"
+ ]
+ },
+
+ {
+ "name": "location",
+ "value":
+ [
+ "SNDGCA64"
+ ]
+ },
+ {
+ "name": "timeout",
+ "value": "500"
+ },
+ {
+ "name": "deployParameters",
+ "value": {
+ "aaiEnrichmentHost": "aai.onap.svc.cluster.local",
+ "aaiEnrichmentPort": "8443",
+ "enableAAIEnrichment": true,
+ "dmaap_host": "message-router",
+ "dmaap_port": "3904",
+ "enableRedisCaching": false,
+ "redisHosts": "dcae-redis:6379",
+ "tag_version": "nexus3.onap.org:10001/onap/org.onap.dcaegen2.deployments.tca-cdap-container:1.1.0",
+ "consul_host": "consul-server",
+ "consul_port": "8500",
+ "cbs_host": "config-binding-service",
+ "cbs_port": "10000",
+ "external_port": "32010",
+ "policy_id": "AUTO_GENERATED_POLICY_ID_AT_SUBMIT"
+ }
+ }
+ ],
+
+ "Policy_":
+ {
+ "Policy1":
+ [
+ {
+ "name": "pname",
+ "value": "Policy1"
+ },
+
+ {
+ "name": "pid",
+ "value": "1"
+ },
+
+ {
+ "name": "timeout",
+ "value": "500"
+ },
+
+ {
+ "policyConfigurations":
+ [
+ [
+ {
+ "name": "recipe",
+ "value":
+ [
+ "restart"
+ ]
+ },
+
+ {
+ "name": "maxRetries",
+ "value":
+ [
+ "3"
+ ]
+ },
+
+ {
+ "name": "retryTimeLimit",
+ "value":
+ [
+ "180"
+ ]
+ },
+
+ {
+ "name": "_id",
+ "value":
+ [
+ "n9bQ4t6"
+ ]
+ },
+
+ {
+ "name": "parentPolicy",
+ "value":
+ [
+ ""
+ ]
+ },
+ {
+ "name": "targetResourceId",
+ "value":
+ [
+ "resource-id"
+ ]
+ }
+ ],
+
+ [
+ {
+ "name": "recipe",
+ "value":
+ [
+ "rebuild"
+ ]
+ },
+
+ {
+ "name": "maxRetries",
+ "value":
+ [
+ "3"
+ ]
+ },
+
+ {
+ "name": "retryTimeLimit",
+ "value":
+ [
+ "180"
+ ]
+ },
+
+ {
+ "name": "_id",
+ "value":
+ [
+ "ItE5xKT"
+ ]
+ },
+
+ {
+ "name": "parentPolicy",
+ "value":
+ [
+ "n9bQ4t6"
+ ]
+ },
+
+ {
+ "name": "parentPolicyConditions",
+ "value":
+ [
+ "Failure_Retries",
+ "Failure_Timeout",
+ "Failure_Exception",
+ "Failure"
+ ]
+ },
+ {
+ "name": "targetResourceId",
+ "value":
+ [
+ "resource-id"
+ ]
+ }
+ ]
+ ]
+ }
+ ]
+ },
+
+ "TCA_":
+ {
+ "Narra":
+ [
+ {
+ "name": "tname",
+ "value": "Narra"
+ },
+
+ {
+ "name": "tuuid",
+ "value": "886be8da-14fe-tca1-d04b-d13b55d58df9"
+ },
+
+ {
+ "name": "tnfc",
+ "value": "ENBE"
+ },
+
+ {
+ "name": "tcaEnab",
+ "value": "on"
+ },
+
+ {
+ "name": "tcaPol",
+ "value": "Policy1"
+ },
+
+ {
+ "name": "tcaPolId",
+ "value": "1"
+ },
+
+ {
+ "name": "tcaInt",
+ "value": "2"
+ },
+
+ {
+ "name": "tcaSev",
+ "value": "Warning"
+ },
+
+ {
+ "name": "tcaVio",
+ "value": "3"
+ },
+
+ {
+ "serviceConfigurations":
+ [
+ [
+ "PMRRCCONNESTABFAILCELLLATENCY",
+ "LESS",
+ "4",
+ "$.event.measurementsForVfScalingFields.additionalMeasurements[*].arrayOfFields[?(@.Name == 'PMRRCCONNESTABFAILCELLLATENCY')].Value"
+ ],
+
+ [
+ "PMRAATTCBRA",
+ "GREATER",
+ "30",
+ "$.event.measurementsForVfScalingFields.additionalMeasurements[*].arrayOfFields[?(@.Name == 'PMRAATTCBRA')].Value"
+ ]
+ ]
+ }
+ ]
+ },
+
+ "CustomType_": [
+ {
+ "name": "test",
+ "value": "This is a test"
+ }
+ ]
+} \ No newline at end of file
diff --git a/src/test/resources/tosca/dcea_blueprint.yml b/src/test/resources/tosca/dcea_blueprint.yml
new file mode 100644
index 00000000..0d3ea046
--- /dev/null
+++ b/src/test/resources/tosca/dcea_blueprint.yml
@@ -0,0 +1,170 @@
+#
+# ============LICENSE_START====================================================
+# =============================================================================
+# Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
+# =============================================================================
+# 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.
+# ============LICENSE_END======================================================
+
+tosca_definitions_version: cloudify_dsl_1_3
+
+description: >
+ This blueprint deploys/manages the TCA module as a Docker container
+
+imports:
+ - http://www.getcloudify.org/spec/cloudify/3.4/types.yaml
+ - https://nexus.onap.org/service/local/repositories/raw/content/org.onap.dcaegen2.platform.plugins/R4/k8splugin/1.4.4/k8splugin_types.yaml
+ - https://nexus.onap.org/service/local/repositories/raw/content/org.onap.dcaegen2.platform.plugins/R4/dcaepolicyplugin/2.3.0/dcaepolicyplugin_types.yaml
+inputs:
+ aaiEnrichmentHost:
+ type: string
+ default: "aai.onap.svc.cluster.local"
+ aaiEnrichmentPort:
+ type: string
+ default: "8443"
+ enableAAIEnrichment:
+ type: string
+ default: true
+ dmaap_host:
+ type: string
+ default: message-router
+ dmaap_port:
+ type: string
+ default: "3904"
+ enableRedisCaching:
+ type: string
+ default: false
+ redisHosts:
+ type: string
+ default: dcae-redis:6379
+ tag_version:
+ type: string
+ default: "nexus3.onap.org:10001/onap/org.onap.dcaegen2.deployments.tca-cdap-container:1.1.0"
+ consul_host:
+ type: string
+ default: consul-server
+ consul_port:
+ type: string
+ default: "8500"
+ cbs_host:
+ type: string
+ default:
+ test:
+ test: test
+ cbs_port:
+ type: string
+ default: "10000"
+ policy_id:
+ type: string
+ default: "none"
+ external_port:
+ type: string
+ description: Kubernetes node port on which CDAPgui is exposed
+ default: "32010"
+
+node_templates:
+ tca_k8s:
+ type: dcae.nodes.ContainerizedServiceComponent
+ relationships:
+ - target: tca_policy
+ type: cloudify.relationships.depends_on
+ properties:
+ service_component_type: 'dcaegen2-analytics-tca'
+ docker_config: {}
+ image:
+ get_input: tag_version
+ log_info:
+ log_directory: "/opt/app/TCAnalytics/logs"
+ application_config:
+ app_config:
+ appDescription: DCAE Analytics Threshold Crossing Alert Application
+ appName: dcae-tca-ak-serv
+ tcaAlertsAbatementTableName: TCAAlertsAbatementTable
+ tcaAlertsAbatementTableTTLSeconds: '1728000'
+ tcaSubscriberOutputStreamName: TCASubscriberOutputStream
+ tcaVESAlertsTableName: TCAVESAlertsTable
+ tcaVESAlertsTableTTLSeconds: '1728000'
+ tcaVESMessageStatusTableName: TCAVESMessageStatusTable
+ tcaVESMessageStatusTableTTLSeconds: '86400'
+ thresholdCalculatorFlowletInstances: '2'
+ app_preferences:
+ aaiEnrichmentHost:
+ get_input: aaiEnrichmentHost
+ aaiEnrichmentIgnoreSSLCertificateErrors: 'true'
+ aaiEnrichmentPortNumber: '8443'
+ aaiEnrichmentProtocol: https
+ aaiEnrichmentUserName: DCAE
+ aaiEnrichmentUserPassword: DCAE
+ aaiVMEnrichmentAPIPath: /aai/v11/search/nodes-query
+ aaiVNFEnrichmentAPIPath: /aai/v11/network/generic-vnfs/generic-vnf
+ enableAAIEnrichment:
+ get_input: enableAAIEnrichment
+ enableRedisCaching:
+ get_input: enableRedisCaching
+ redisHosts:
+ get_input: redisHosts
+ enableAlertCEFFormat: 'false'
+ publisherContentType: application/json
+ publisherHostName:
+ get_input: dmaap_host
+ publisherHostPort:
+ get_input: dmaap_port
+ publisherMaxBatchSize: '1'
+ publisherMaxRecoveryQueueSize: '100000'
+ publisherPollingInterval: '20000'
+ publisherProtocol: http
+ publisherTopicName: unauthenticated.DCAE_CL_OUTPUT
+ subscriberConsumerGroup: OpenDCAE-c12
+ subscriberConsumerId: c12
+ subscriberContentType: application/json
+ subscriberHostName:
+ get_input: dmaap_host
+ subscriberHostPort:
+ get_input: dmaap_port
+ subscriberMessageLimit: '-1'
+ subscriberPollingInterval: '30000'
+ subscriberProtocol: http
+ subscriberTimeoutMS: '-1'
+ subscriberTopicName: unauthenticated.VES_MEASUREMENT_OUTPUT
+ tca_policy: '{"domain":"measurementsForVfScaling","metricsPerEventName":[{"eventName":"vFirewallBroadcastPackets","controlLoopSchemaType":"VNF","policyScope":"DCAE","policyName":"DCAE.Config_tca-hi-lo","policyVersion":"v0.0.1","thresholds":[{"closedLoopControlName":"ControlLoop-vFirewall-d0a1dfc6-94f5-4fd4-a5b5-4630b438850a","version":"1.0.2","fieldPath":"$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedTotalPacketsDelta","thresholdValue":300,"direction":"LESS_OR_EQUAL","severity":"MAJOR","closedLoopEventStatus":"ONSET"},{"closedLoopControlName":"ControlLoop-vFirewall-d0a1dfc6-94f5-4fd4-a5b5-4630b438850a","version":"1.0.2","fieldPath":"$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedTotalPacketsDelta","thresholdValue":700,"direction":"GREATER_OR_EQUAL","severity":"CRITICAL","closedLoopEventStatus":"ONSET"}]},{"eventName":"vLoadBalancer","controlLoopSchemaType":"VM","policyScope":"DCAE","policyName":"DCAE.Config_tca-hi-lo","policyVersion":"v0.0.1","thresholds":[{"closedLoopControlName":"ControlLoop-vDNS-6f37f56d-a87d-4b85-b6a9-cc953cf779b3","version":"1.0.2","fieldPath":"$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedTotalPacketsDelta","thresholdValue":300,"direction":"GREATER_OR_EQUAL","severity":"CRITICAL","closedLoopEventStatus":"ONSET"}]},{"eventName":"Measurement_vGMUX","controlLoopSchemaType":"VNF","policyScope":"DCAE","policyName":"DCAE.Config_tca-hi-lo","policyVersion":"v0.0.1","thresholds":[{"closedLoopControlName":"ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e","version":"1.0.2","fieldPath":"$.event.measurementsForVfScalingFields.additionalMeasurements[*].arrayOfFields[0].value","thresholdValue":0,"direction":"EQUAL","severity":"MAJOR","closedLoopEventStatus":"ABATED"},{"closedLoopControlName":"ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e","version":"1.0.2","fieldPath":"$.event.measurementsForVfScalingFields.additionalMeasurements[*].arrayOfFields[0].value","thresholdValue":0,"direction":"GREATER","severity":"CRITICAL","closedLoopEventStatus":"ONSET"}]}]}'
+ interfaces:
+ cloudify.interfaces.lifecycle:
+ start:
+ inputs:
+ envs:
+ DMAAPHOST:
+ { get_input: dmaap_host }
+ DMAAPPORT:
+ { get_input: dmaap_port }
+ DMAAPPUBTOPIC: "unauthenticated.DCAE_CL_OUTPUT"
+ DMAAPSUBTOPIC: "unauthenticated.VES_MEASUREMENT_OUTPUT"
+ AAIHOST:
+ { get_input: aaiEnrichmentHost }
+ AAIPORT:
+ { get_input: aaiEnrichmentPort }
+ CONSUL_HOST:
+ { get_input: consul_host }
+ CONSUL_PORT:
+ { get_input: consul_port }
+ CBS_HOST:
+ { get_input: cbs_host }
+ CBS_PORT:
+ { get_input: cbs_port }
+ CONFIG_BINDING_SERVICE: "config_binding_service"
+ ports:
+ - concat: ["11011:", { get_input: external_port }]
+ tca_policy:
+ type: dcae.nodes.policy
+ properties:
+ policy_id:
+ get_input: policy_id