diff options
Diffstat (limited to 'src/test')
28 files changed, 1080 insertions, 751 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/CldsDaoItCase.java b/src/test/java/org/onap/clamp/clds/it/CldsDaoItCase.java index 12fa2932..d4172c24 100644 --- a/src/test/java/org/onap/clamp/clds/it/CldsDaoItCase.java +++ b/src/test/java/org/onap/clamp/clds/it/CldsDaoItCase.java @@ -25,30 +25,24 @@ package org.onap.clamp.clds.it; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; import java.io.IOException; -import java.security.GeneralSecurityException; import java.util.ArrayList; import java.util.List; import javax.ws.rs.NotFoundException; -import org.apache.commons.codec.DecoderException; import org.apache.commons.lang3.RandomStringUtils; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.onap.clamp.clds.client.req.sdc.SdcCatalogServices; import org.onap.clamp.clds.dao.CldsDao; -import org.onap.clamp.clds.model.CldsDbServiceCache; import org.onap.clamp.clds.model.CldsEvent; import org.onap.clamp.clds.model.CldsModel; import org.onap.clamp.clds.model.CldsMonitoringDetails; -import org.onap.clamp.clds.model.CldsServiceData; import org.onap.clamp.clds.model.CldsTemplate; import org.onap.clamp.clds.util.ResourceFileUtil; import org.springframework.beans.factory.annotation.Autowired; @@ -69,8 +63,6 @@ public class CldsDaoItCase { private String bpmnText; private String imageText; private String bpmnPropText; - @Autowired - private SdcCatalogServices sdcCatalogServices; /** * Setup the variable before the tests execution. @@ -165,30 +157,4 @@ public class CldsDaoItCase { }); } - @Test - public void testCldsServiceCache() throws GeneralSecurityException, DecoderException, IOException { - CldsServiceData cldsServiceData = sdcCatalogServices - .getCldsServiceDataWithAlarmConditions("4cc5b45a-1f63-4194-8100-cd8e14248c92"); - // Test not in cache so should be null - CldsServiceData cldsServiceDataCache = cldsDao.getCldsServiceCache("4cc5b45a-1f63-4194-8100-cd8e14248c92"); - assertNull(cldsServiceDataCache); - cldsDao.setCldsServiceCache(new CldsDbServiceCache(cldsServiceData)); - cldsServiceDataCache = cldsDao.getCldsServiceCache("4cc5b45a-1f63-4194-8100-cd8e14248c92"); - assertNotNull(cldsServiceDataCache); - assertEquals("56441b4b-0467-41dc-9a0e-e68613838219", cldsServiceDataCache.getServiceUUID()); - assertEquals("4cc5b45a-1f63-4194-8100-cd8e14248c92", cldsServiceDataCache.getServiceInvariantUUID()); - assertEquals(2, cldsServiceDataCache.getCldsVfs().size()); - assertNotNull(cldsServiceDataCache.getAgeOfRecord()); - assertEquals(4, cldsServiceDataCache.getCldsVfs().get(0).getCldsVfcs().size()); - assertEquals("07e266fc-49ab-4cd7-8378-ca4676f1b9ec", - cldsServiceDataCache.getCldsVfs().get(0).getVfInvariantResourceUUID()); - assertEquals(0, cldsServiceDataCache.getCldsVfs().get(0).getCldsKPIList().size()); - // Second update - cldsServiceData.setCldsVfs(null); - cldsDao.setCldsServiceCache(new CldsDbServiceCache(cldsServiceData)); - cldsServiceDataCache = cldsDao.getCldsServiceCache("4cc5b45a-1f63-4194-8100-cd8e14248c92"); - assertNotNull(cldsServiceDataCache); - assertNull(cldsServiceDataCache.getCldsVfs()); - cldsDao.clearServiceCache(); - } } 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..347de4a7 100644 --- a/src/test/java/org/onap/clamp/clds/it/CldsServiceItCase.java +++ b/src/test/java/org/onap/clamp/clds/it/CldsServiceItCase.java @@ -26,12 +26,10 @@ package org.onap.clamp.clds.it; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import java.io.IOException; import java.io.InputStream; -import java.security.GeneralSecurityException; import java.util.LinkedList; import java.util.List; import java.util.Properties; @@ -40,9 +38,7 @@ import javax.servlet.http.HttpServletRequest; import javax.ws.rs.NotFoundException; import javax.xml.transform.TransformerException; -import org.apache.commons.codec.DecoderException; import org.apache.commons.lang3.RandomStringUtils; -import org.json.JSONException; import org.json.simple.parser.ParseException; import org.junit.Before; import org.junit.Test; @@ -54,7 +50,6 @@ import org.onap.clamp.clds.model.CldsEvent; import org.onap.clamp.clds.model.CldsInfo; import org.onap.clamp.clds.model.CldsModel; import org.onap.clamp.clds.model.CldsMonitoringDetails; -import org.onap.clamp.clds.model.CldsServiceData; import org.onap.clamp.clds.model.CldsTemplate; import org.onap.clamp.clds.model.DcaeEvent; import org.onap.clamp.clds.service.CldsService; @@ -160,7 +155,7 @@ public class CldsServiceItCase { } @Test - public void testGetCLDSDetails() throws IOException { + public void testGetCldsDetails() throws IOException { List<CldsMonitoringDetails> cldsMonitoringDetailsList = cldsService.getCldsDetails(); assertNotNull(cldsMonitoringDetailsList); } @@ -281,35 +276,4 @@ public class CldsServiceItCase { ResourceFileUtil.getResourceAsString("example/sdc/expected-result/sdc-properties-global.json"), cldsService.getSdcProperties(), true); } - - @Test - public void testGetSdcServices() throws GeneralSecurityException, DecoderException, JSONException, IOException { - String result = cldsService.getSdcServices(); - JSONAssert.assertEquals( - ResourceFileUtil.getResourceAsString("example/sdc/expected-result/all-sdc-services.json"), result, true); - } - - @Test - public void testGetSdcPropertiesByServiceUuidForRefresh() - throws GeneralSecurityException, DecoderException, JSONException, IOException { - SecurityContext securityContext = Mockito.mock(SecurityContext.class); - Mockito.when(securityContext.getAuthentication()).thenReturn(authentication); - - cldsService.setSecurityContext(securityContext); - // Test basic functionalities - String result = cldsService.getSdcPropertiesByServiceUUIDForRefresh("4cc5b45a-1f63-4194-8100-cd8e14248c92", - false); - JSONAssert.assertEquals( - ResourceFileUtil.getResourceAsString("example/sdc/expected-result/sdc-properties-4cc5b45a.json"), result, - true); - // Now test the Cache effect - CldsServiceData cldsServiceDataCache = cldsDao.getCldsServiceCache("c95b0e7c-c1f0-4287-9928-7964c5377a46"); - // Should not be there, so should be null - assertNull(cldsServiceDataCache); - cldsService.getSdcPropertiesByServiceUUIDForRefresh("c95b0e7c-c1f0-4287-9928-7964c5377a46", true); - // Should be there now, so should NOT be null - cldsServiceDataCache = cldsDao.getCldsServiceCache("c95b0e7c-c1f0-4287-9928-7964c5377a46"); - assertNotNull(cldsServiceDataCache); - cldsDao.clearServiceCache(); - } } 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/SdcCatalogServicesItCase.java b/src/test/java/org/onap/clamp/clds/it/SdcCatalogServicesItCase.java deleted file mode 100644 index d36e14c2..00000000 --- a/src/test/java/org/onap/clamp/clds/it/SdcCatalogServicesItCase.java +++ /dev/null @@ -1,305 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP CLAMP - * ================================================================================ - * Copyright (C) 2017-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) 2018 Nokia - * =================================================================== - * - */ - -package org.onap.clamp.clds.it; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertTrue; - -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; - -import org.apache.commons.io.IOUtils; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mockito; -import org.onap.clamp.clds.client.req.sdc.SdcCatalogServices; -import org.onap.clamp.clds.config.ClampProperties; -import org.onap.clamp.clds.model.CldsAlarmCondition; -import org.onap.clamp.clds.model.CldsServiceData; -import org.onap.clamp.clds.model.sdc.SdcResource; -import org.onap.clamp.clds.model.sdc.SdcResourceBasicInfo; -import org.onap.clamp.clds.model.sdc.SdcServiceInfo; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -/** - * Test SDC Catalog Service class by mocking the SDC answers. - */ -@RunWith(SpringRunner.class) -@SpringBootTest -public class SdcCatalogServicesItCase { - - @Autowired - private ClampProperties refProp; - @Autowired - private SdcCatalogServices sdcCatalogWired = new SdcCatalogServices(); - - @Test - public void removeDuplicateServicesTest() { - SdcServiceInfo service1a = new SdcServiceInfo(); - service1a.setName("service1"); - service1a.setVersion("1.0"); - service1a.setInvariantUUID("invariantUUID1.0"); - List<SdcServiceInfo> rawCldsSdcServiceList = new LinkedList<>(); - rawCldsSdcServiceList.add(service1a); - rawCldsSdcServiceList.add(service1a); - SdcServiceInfo service1b = new SdcServiceInfo(); - service1b.setName("service1"); - service1b.setVersion("1.1"); - service1b.setInvariantUUID("invariantUUID1.1"); - rawCldsSdcServiceList.add(service1b); - SdcServiceInfo service1c = new SdcServiceInfo(); - service1c.setName("service1"); - service1c.setVersion("1.2"); - service1c.setInvariantUUID("invariantUUID1.2"); - rawCldsSdcServiceList.add(service1c); - SdcServiceInfo service2 = new SdcServiceInfo(); - service2.setName("service2"); - service2.setVersion("1.0"); - service2.setInvariantUUID("invariantUUID2.0"); - rawCldsSdcServiceList.add(service2); - SdcCatalogServices catalogServices = new SdcCatalogServices(); - List<SdcServiceInfo> resultList = catalogServices.removeDuplicateServices(rawCldsSdcServiceList); - assertTrue(resultList.size() == 2); - SdcServiceInfo res1; - SdcServiceInfo res2; - if ("service1".equals(resultList.get(0).getName())) { - res1 = resultList.get(0); - res2 = resultList.get(1); - } else { - res1 = resultList.get(1); - res2 = resultList.get(0); - } - assertTrue("service1".equals(res1.getName())); - assertTrue("1.2".equals(res1.getVersion())); - assertTrue("service2".equals(res2.getName())); - assertTrue("1.0".equals(res2.getVersion())); - } - - @Test - public void removeDuplicateSdcResourceInstancesTest() { - List<SdcResource> rawCldsSdcResourceList = new LinkedList<>(); - SdcResource sdcResource1a = new SdcResource(); - sdcResource1a.setResourceInstanceName("resource1"); - sdcResource1a.setResourceVersion("1.0"); - rawCldsSdcResourceList.add(sdcResource1a); - SdcResource sdcResource1b = new SdcResource(); - sdcResource1b.setResourceInstanceName("resource1"); - sdcResource1b.setResourceVersion("1.1"); - rawCldsSdcResourceList.add(sdcResource1b); - SdcResource sdcResource1c = new SdcResource(); - sdcResource1c.setResourceInstanceName("resource1"); - sdcResource1c.setResourceVersion("1.2"); - rawCldsSdcResourceList.add(sdcResource1c); - SdcResource sdcResource2 = new SdcResource(); - sdcResource2.setResourceInstanceName("resource2"); - sdcResource2.setResourceVersion("1.0"); - rawCldsSdcResourceList.add(sdcResource2); - SdcCatalogServices catalogServices = new SdcCatalogServices(); - List<SdcResource> resultList = catalogServices.removeDuplicateSdcResourceInstances(rawCldsSdcResourceList); - SdcResource res1; - SdcResource res2; - if ("resource1".equals(resultList.get(0).getResourceInstanceName())) { - res1 = resultList.get(0); - res2 = resultList.get(1); - } else { - res1 = resultList.get(1); - res2 = resultList.get(0); - } - assertTrue("resource1".equals(res1.getResourceInstanceName())); - assertTrue("1.2".equals(res1.getResourceVersion())); - assertTrue("resource2".equals(res2.getResourceInstanceName())); - assertTrue("1.0".equals(res2.getResourceVersion())); - } - - @Test - public void removeDuplicateSdcResourceBasicInfoTest() { - List<SdcResourceBasicInfo> rawCldsSdcResourceList = new LinkedList<>(); - SdcResourceBasicInfo sdcResource1a = new SdcResourceBasicInfo(); - sdcResource1a.setName("resource1"); - sdcResource1a.setVersion("1.0"); - rawCldsSdcResourceList.add(sdcResource1a); - SdcResourceBasicInfo sdcResource1b = new SdcResourceBasicInfo(); - sdcResource1b.setName("resource1"); - sdcResource1b.setVersion("1.1"); - rawCldsSdcResourceList.add(sdcResource1b); - SdcResourceBasicInfo sdcResource1c = new SdcResourceBasicInfo(); - sdcResource1c.setName("resource1"); - sdcResource1c.setVersion("1.2"); - rawCldsSdcResourceList.add(sdcResource1c); - SdcResourceBasicInfo sdcResource2 = new SdcResourceBasicInfo(); - sdcResource2.setName("resource2"); - sdcResource2.setVersion("1.0"); - rawCldsSdcResourceList.add(sdcResource2); - SdcCatalogServices catalogServices = new SdcCatalogServices(); - List<SdcResourceBasicInfo> resultList = catalogServices - .removeDuplicateSdcResourceBasicInfo(rawCldsSdcResourceList); - SdcResourceBasicInfo res1; - SdcResourceBasicInfo res2; - if ("resource1".equals(resultList.get(0).getName())) { - res1 = resultList.get(0); - res2 = resultList.get(1); - } else { - res1 = resultList.get(1); - res2 = resultList.get(0); - } - assertTrue("resource1".equals(res1.getName())); - assertTrue("1.2".equals(res1.getVersion())); - assertTrue("resource2".equals(res2.getName())); - assertTrue("1.0".equals(res2.getVersion())); - } - - @Test - public void removeDuplicateSdcFunctionShouldNotReturnNull() { - // given - SdcCatalogServices catalogServices = new SdcCatalogServices(); - - // when - List<SdcResourceBasicInfo> firstResult = catalogServices.removeDuplicateSdcResourceBasicInfo(null); - List<SdcResourceBasicInfo> secondResult = catalogServices - .removeDuplicateSdcResourceBasicInfo(new ArrayList<>()); - - // then - assertThat(firstResult).isEmpty(); - assertThat(secondResult).isEmpty(); - } - - @Test - public void getServiceUuidFromServiceInvariantIdTest() throws Exception { - SdcCatalogServices spy = Mockito.spy(sdcCatalogWired); - Mockito.doReturn(IOUtils.toString( - SdcCatalogServicesItCase.class.getResourceAsStream("/example/sdc/sdcServicesListExample.json"), "UTF-8")) - .when(spy).getSdcServicesInformation(null); - // Try the vcts4 version 1.0, this one should be replaced by 1.1 so it - // should not exist, returning empty string - String resUuidVcts4Null = spy.getServiceUuidFromServiceInvariantId("a33ed748-3477-4434-b3f3-b5560f5e7d9b"); - assertTrue("".equals(resUuidVcts4Null)); - // Try the vcts4 version 1.1, this one should be there as it replaces - // the vcts4 v1.0 - String resUuidVcts4Latest = spy.getServiceUuidFromServiceInvariantId("a33ed748-3477-4434-b3f3-b5560f5e7d9c"); - assertTrue("29018914-966c-442d-9d08-251b9dc45b8f".equals(resUuidVcts4Latest)); - // Try the vcts5 version 1.0, this one should be there - String resUuidVcts5 = spy.getServiceUuidFromServiceInvariantId("a33ed748-3477-4434-b3f3-b5560f5e7d8c"); - assertTrue("29018914-966c-442d-9d08-251b9dc45b7f".equals(resUuidVcts5)); - // try one that does not exist at all - String resUuidUnknown = spy.getServiceUuidFromServiceInvariantId("testuuid"); - assertTrue("".equals(resUuidUnknown)); - } - - @Test - public void getCldsServiceDataWithAlarmConditionsTest() throws Exception { - SdcCatalogServices spy = Mockito.spy(sdcCatalogWired); - Mockito.doReturn(IOUtils.toString( - SdcCatalogServicesItCase.class.getResourceAsStream("/example/sdc/sdcServicesListExample.json"), "UTF-8")) - .when(spy).getSdcServicesInformation(null); - // This invariant uuid is the one from vcts4 v1.1 - String serviceResourceDetailUrl = refProp.getStringValue("sdc.serviceUrl") - + "/29018914-966c-442d-9d08-251b9dc45b8f/metadata"; - Mockito.doReturn(IOUtils.toString( - SdcCatalogServicesItCase.class.getResourceAsStream("/example/sdc/sdcServiceDetailsExample.json"), "UTF-8")) - .when(spy).getCldsServicesOrResourcesBasedOnURL(serviceResourceDetailUrl); - String resourceDetailUrl = refProp.getStringValue("sdc.catalog.url") - + "resources/585822c7-4027-4f84-ba50-e9248606f136/metadata"; - Mockito.doReturn(IOUtils.toString( - SdcCatalogServicesItCase.class.getResourceAsStream("/example/sdc/sdcResourceDetailsExample.json"), "UTF-8")) - .when(spy).getCldsServicesOrResourcesBasedOnURL(resourceDetailUrl); - String securityRulesDetailUrl = refProp.getStringValue("sdc.catalog.url") - + "resources/d57e57d2-e3c6-470d-8d16-e6ea05f536c5/metadata"; - Mockito - .doReturn(IOUtils.toString( - SdcCatalogServicesItCase.class.getResourceAsStream("/example/sdc/sdcSecurityRules.json"), "UTF-8")) - .when(spy).getCldsServicesOrResourcesBasedOnURL(securityRulesDetailUrl); - String cinderVolumeDetailUrl = refProp.getStringValue("sdc.catalog.url") - + "resources/b4288e07-597a-44a2-aa98-ad36e551a39d/metadata"; - Mockito - .doReturn(IOUtils.toString( - SdcCatalogServicesItCase.class.getResourceAsStream("/example/sdc/sdcCinderVolume.json"), "UTF-8")) - .when(spy).getCldsServicesOrResourcesBasedOnURL(cinderVolumeDetailUrl); - String vfcGenericDetailUrl = refProp.getStringValue("sdc.catalog.url") - + "resources/2c8f1219-8000-4001-aa13-496a0396d40f/metadata"; - Mockito.doReturn(IOUtils.toString( - SdcCatalogServicesItCase.class.getResourceAsStream("/example/sdc/sdcVFCGenericWithAlarms.json"), "UTF-8")) - .when(spy).getCldsServicesOrResourcesBasedOnURL(vfcGenericDetailUrl); - String csvAlarmsDetailUrl = refProp.getStringValue("sdc.catalog.url") - + "resources/2c8f1219-8000-4001-aa13-496a0396d40f/resourceInstances/virc_fe_be/" - + "artifacts/5138e316-0237-49aa-817a-b3d8eaf77392"; - Mockito - .doReturn(IOUtils.toString( - SdcCatalogServicesItCase.class.getResourceAsStream("/example/sdc/sdcAlarmsList.csv"), "UTF-8")) - .when(spy).getCldsServicesOrResourcesBasedOnURL(csvAlarmsDetailUrl); - Mockito - .doReturn(IOUtils.toString( - SdcCatalogServicesItCase.class.getResourceAsStream("/example/sdc/sdcAlarmsList.csv"), "UTF-8")) - .when(spy).getCldsServicesOrResourcesBasedOnURL(csvAlarmsDetailUrl); - String csvAlarmsDetailUrl2 = refProp.getStringValue("sdc.catalog.url") - + "resources/d7646638-2572-4a94-b497-c028ac15f9ca/artifacts/5138e316-0237-49aa-817a-b3d8eaf77392"; - Mockito - .doReturn(IOUtils.toString( - SdcCatalogServicesItCase.class.getResourceAsStream("/example/sdc/sdcAlarmsList.csv"), "UTF-8")) - .when(spy).getCldsServicesOrResourcesBasedOnURL(csvAlarmsDetailUrl2); - String allVfResourcesDetailUrl = refProp.getStringValue("sdc.catalog.url") + "resources?resourceType=VF"; - Mockito - .doReturn(IOUtils.toString( - SdcCatalogServicesItCase.class.getResourceAsStream("/example/sdc/sdcVFResources.json"), "UTF-8")) - .when(spy).getCldsServicesOrResourcesBasedOnURL(allVfResourcesDetailUrl); - String vfcResourcesDetailUrl = refProp.getStringValue("sdc.catalog.url") - + "resources/a0475018-1e7e-4ddd-8bee-33cbf958c2e6/metadata"; - Mockito.doReturn(IOUtils.toString( - SdcCatalogServicesItCase.class.getResourceAsStream("/example/sdc/sdcCVFCResourceExample.json"), "UTF-8")) - .when(spy).getCldsServicesOrResourcesBasedOnURL(vfcResourcesDetailUrl); - String allVfcResourcesDetailUrl = refProp.getStringValue("sdc.catalog.url") + "resources?resourceType=VFC"; - Mockito - .doReturn(IOUtils.toString( - SdcCatalogServicesItCase.class.getResourceAsStream("/example/sdc/sdcVFCResources.json"), "UTF-8")) - .when(spy).getCldsServicesOrResourcesBasedOnURL(allVfcResourcesDetailUrl); - String allCvfcResourcesDetailUrl = refProp.getStringValue("sdc.catalog.url") + "resources?resourceType=CVFC"; - Mockito - .doReturn(IOUtils.toString( - SdcCatalogServicesItCase.class.getResourceAsStream("/example/sdc/sdcCVFCResources.json"), "UTF-8")) - .when(spy).getCldsServicesOrResourcesBasedOnURL(allCvfcResourcesDetailUrl); - String allVfAlarms = refProp.getStringValue("sdc.catalog.url") - + "resources/84855843-5247-4e97-a2bd-5395a510253b/artifacts/d57ac7ec-f3c3-4793-983a-c75ac3a43153"; - Mockito - .doReturn(IOUtils.toString( - SdcCatalogServicesItCase.class.getResourceAsStream("/example/sdc/sdcMeasurementsList.csv"), "UTF-8")) - .when(spy).getCldsServicesOrResourcesBasedOnURL(allVfAlarms); - String vfcResourceExample = refProp.getStringValue("sdc.catalog.url") - + "resources/d7646638-2572-4a94-b497-c028ac15f9ca/metadata"; - Mockito - .doReturn(IOUtils.toString( - SdcCatalogServicesItCase.class.getResourceAsStream("/example/sdc/sdcVFCResourceExample.json"), "UTF-8")) - .when(spy).getCldsServicesOrResourcesBasedOnURL(vfcResourceExample); - CldsServiceData cldsServiceData = spy - .getCldsServiceDataWithAlarmConditions("a33ed748-3477-4434-b3f3-b5560f5e7d9c"); - assertTrue("a33ed748-3477-4434-b3f3-b5560f5e7d9c".equals(cldsServiceData.getServiceInvariantUUID())); - assertTrue("29018914-966c-442d-9d08-251b9dc45b8f".equals(cldsServiceData.getServiceUUID())); - assertTrue(cldsServiceData.getCldsVfs().size() == 1); - List<CldsAlarmCondition> alarmsList = spy.getAllAlarmConditionsFromCldsServiceData(cldsServiceData, - "alarmCondition"); - assertTrue(alarmsList.size() == 12); - } -} diff --git a/src/test/java/org/onap/clamp/clds/it/SdcReqItCase.java b/src/test/java/org/onap/clamp/clds/it/SdcReqItCase.java deleted file mode 100644 index 971b36f6..00000000 --- a/src/test/java/org/onap/clamp/clds/it/SdcReqItCase.java +++ /dev/null @@ -1,106 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP CLAMP - * ================================================================================ - * Copyright (C) 2017-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.it; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import java.io.IOException; -import java.security.GeneralSecurityException; -import java.util.List; - -import org.apache.commons.codec.DecoderException; -import org.json.JSONException; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.onap.clamp.clds.client.req.sdc.SdcRequests; -import org.onap.clamp.clds.model.CldsEvent; -import org.onap.clamp.clds.model.properties.ModelProperties; -import org.onap.clamp.clds.util.ResourceFileUtil; -import org.skyscreamer.jsonassert.JSONAssert; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -@RunWith(SpringRunner.class) -@SpringBootTest -public class SdcReqItCase { - - @Autowired - private SdcRequests sdcReq; - private String modelBpmnProp; - private String modelBpmn; - private String modelName; - private String controlName; - private ModelProperties modelProperties; - private String jsonWithYamlInside; - - /** - * Initialize Test. - */ - @Before - public void setUp() throws IOException { - modelBpmnProp = ResourceFileUtil.getResourceAsString("example/model-properties/tca/modelBpmnProperties.json"); - modelBpmn = ResourceFileUtil.getResourceAsString("example/model-properties/tca/modelBpmn.json"); - modelName = "example-model01"; - controlName = "ClosedLoop_FRWL_SIG_fad4dcae_e498_11e6_852e_0050568c4ccf"; - modelProperties = new ModelProperties(modelName, controlName, CldsEvent.ACTION_SUBMIT, false, modelBpmn, - modelBpmnProp); - jsonWithYamlInside = ResourceFileUtil.getResourceAsString("example/tca-policy-req/prop-text.json"); - } - - @Test - public void formatBlueprintTest() throws IOException { - String blueprintFormatted = sdcReq.formatBlueprint(modelProperties, jsonWithYamlInside); - assertEquals(ResourceFileUtil.getResourceAsString("example/tca-policy-req/blueprint-expected.yaml"), - blueprintFormatted); - } - - @Test - public void formatSdcLocationsReqTest() { - String blueprintFormatted = sdcReq.formatSdcLocationsReq(modelProperties, "testos"); - assertEquals( - "{\"artifactName\":\"testos\",\"locations\":[\"SNDGCA64\",\"ALPRGAED\",\"LSLEILAA\",\"MDTWNJC1\"]}", - blueprintFormatted); - } - - @Test - public void formatSdcReqTest() throws JSONException { - String jsonResult = sdcReq.formatSdcReq("payload", "artifactName", "artifactLabel", "artifactType"); - JSONAssert.assertEquals("{\"payloadData\" : \"cGF5bG9hZA==\",\"artifactLabel\" : \"artifactLabel\"," - + "\"artifactName\" :\"artifactName\",\"artifactType\" : \"artifactType\"," - + "\"artifactGroupType\" : \"DEPLOYMENT\",\"description\" : \"from CLAMP Cockpit\"}", jsonResult, true); - } - - @Test - public void getSdcReqUrlsListTest() throws GeneralSecurityException, DecoderException { - List<String> listUrls = sdcReq.getSdcReqUrlsList(modelProperties); - assertNotNull(listUrls); - assertTrue(listUrls.size() == 1); - assertTrue(listUrls.get(0).contains( - "/sdc/v1/catalog/services/56441b4b-0467-41dc-9a0e-e68613838219/resourceInstances/vpacketgen0/artifacts")); - } -} 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..65aa9b44 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); } @@ -91,11 +101,12 @@ public class CldsReferencePropertiesItCase { */ @Test public void testGetFileContent() throws IOException { - String content = refProp.getFileContent("sdc.decode.service_ids"); - assertEquals("{}", content); + String location = "{\n\t\"DC1\": \"Data Center 1\",\n\t\"DC2\": \"Data Center 2\",\n\t\"DC3\": \"Data Center 3\"\n}\n"; + String content = refProp.getFileContent("ui.location.default"); + assertEquals(location, content); // Test composite key - content = refProp.getFileContent("sdc.decode", "service_ids"); - assertEquals("{}", content); + content = refProp.getFileContent("ui.location", "default"); + assertEquals(location, content); } @Test 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/it/sdc/controller/installer/CsarInstallerItCase.java b/src/test/java/org/onap/clamp/clds/it/sdc/controller/installer/CsarInstallerItCase.java index 276f5091..2c24dcb5 100644 --- a/src/test/java/org/onap/clamp/clds/it/sdc/controller/installer/CsarInstallerItCase.java +++ b/src/test/java/org/onap/clamp/clds/it/sdc/controller/installer/CsarInstallerItCase.java @@ -69,8 +69,8 @@ public class CsarInstallerItCase { private static final String INVARIANT_SERVICE_UUID = "4cc5b45a-1f63-4194-8100-cd8e14248c92"; private static final String INVARIANT_RESOURCE1_UUID = "07e266fc-49ab-4cd7-8378-ca4676f1b9ec"; private static final String INVARIANT_RESOURCE2_UUID = "023a3f0d-1161-45ff-b4cf-8918a8ccf3ad"; - private static final String INSTANCE_NAME_RESOURCE1 = "ResourceInstanceName1"; - private static final String INSTANCE_NAME_RESOURCE2 = "ResourceInstanceName2"; + private static final String RESOURCE_INSTANCE_NAME_RESOURCE1 = "ResourceInstanceName1"; + private static final String RESOURCE_INSTANCE_NAME_RESOURCE2 = "ResourceInstanceName2"; @Autowired private CsarInstaller csarInstaller; @Autowired @@ -92,14 +92,14 @@ public class CsarInstallerItCase { } private BlueprintArtifact buildFakeBuildprintArtifact(String instanceName, String invariantResourceUuid, - String blueprintFilePath, String csarArtifactName, String invariantServiceUuid) throws IOException { + String blueprintFilePath, String artifactName, String invariantServiceUuid) throws IOException { IResourceInstance resource = Mockito.mock(IResourceInstance.class); Mockito.when(resource.getResourceInstanceName()).thenReturn(instanceName); Mockito.when(resource.getResourceInvariantUUID()).thenReturn(invariantResourceUuid); BlueprintArtifact blueprintArtifact = Mockito.mock(BlueprintArtifact.class); Mockito.when(blueprintArtifact.getDcaeBlueprint()) .thenReturn(ResourceFileUtil.getResourceAsString(blueprintFilePath)); - Mockito.when(blueprintArtifact.getBlueprintArtifactName()).thenReturn(csarArtifactName); + Mockito.when(blueprintArtifact.getBlueprintArtifactName()).thenReturn(artifactName); Mockito.when(blueprintArtifact.getBlueprintInvariantServiceUuid()).thenReturn(invariantServiceUuid); Mockito.when(blueprintArtifact.getResourceAttached()).thenReturn(resource); return blueprintArtifact; @@ -115,17 +115,23 @@ public class CsarInstallerItCase { Mockito.when(notificationData.getResources()).thenReturn(listResources); Map<String, BlueprintArtifact> blueprintMap = new HashMap<>(); Mockito.when(csarHandler.getMapOfBlueprints()).thenReturn(blueprintMap); - // Create fake blueprint artifact 1 - BlueprintArtifact blueprintArtifact = buildFakeBuildprintArtifact(INSTANCE_NAME_RESOURCE1, - INVARIANT_RESOURCE1_UUID, "example/sdc/blueprint-dcae/tca.yaml", CSAR_ARTIFACT_NAME, - INVARIANT_SERVICE_UUID); + // Create fake blueprint artifact 1 on resource1 + BlueprintArtifact blueprintArtifact = buildFakeBuildprintArtifact(RESOURCE_INSTANCE_NAME_RESOURCE1, + INVARIANT_RESOURCE1_UUID, "example/sdc/blueprint-dcae/tca.yaml", "tca.yaml", INVARIANT_SERVICE_UUID); listResources.add(blueprintArtifact.getResourceAttached()); - blueprintMap.put(blueprintArtifact.getResourceAttached().getResourceInstanceName(), blueprintArtifact); - // Create fake blueprint artifact 2 - blueprintArtifact = buildFakeBuildprintArtifact(INSTANCE_NAME_RESOURCE2, INVARIANT_RESOURCE2_UUID, - "example/sdc/blueprint-dcae/tca_2.yaml", CSAR_ARTIFACT_NAME, INVARIANT_SERVICE_UUID); + blueprintMap.put(blueprintArtifact.getBlueprintArtifactName(), blueprintArtifact); + // Create fake blueprint artifact 2 on resource2 + blueprintArtifact = buildFakeBuildprintArtifact(RESOURCE_INSTANCE_NAME_RESOURCE2, INVARIANT_RESOURCE2_UUID, + "example/sdc/blueprint-dcae/tca_2.yaml", "tca_2.yaml", INVARIANT_SERVICE_UUID); listResources.add(blueprintArtifact.getResourceAttached()); - blueprintMap.put(blueprintArtifact.getResourceAttached().getResourceInstanceName(), blueprintArtifact); + blueprintMap.put(blueprintArtifact.getBlueprintArtifactName(), blueprintArtifact); + + // Create fake blueprint artifact 3 on resource 1 so that it's possible to + // test multiple CL deployment per Service/vnf + blueprintArtifact = buildFakeBuildprintArtifact(RESOURCE_INSTANCE_NAME_RESOURCE1, INVARIANT_RESOURCE1_UUID, + "example/sdc/blueprint-dcae/tca_3.yaml", "tca_3.yaml", INVARIANT_SERVICE_UUID); + blueprintMap.put(blueprintArtifact.getBlueprintArtifactName(), blueprintArtifact); + // Build fake csarhandler Mockito.when(csarHandler.getSdcNotification()).thenReturn(notificationData); // Build fake csar Helper @@ -153,40 +159,45 @@ public class CsarInstallerItCase { String generatedName = RandomStringUtils.randomAlphanumeric(5); CsarHandler csar = buildFakeCsarHandler(generatedName); csarInstaller.installTheCsar(csar); - CldsModel cldsModel1 = verifyClosedLoopModelLoadedInDb(csar, generatedName, INSTANCE_NAME_RESOURCE1); + CldsModel cldsModel1 = verifyClosedLoopModelLoadedInDb(csar, "tca.yaml"); JSONAssert.assertEquals( IOUtils.toString(ResourceFileUtil.getResourceAsStream("example/sdc/blueprint-dcae/prop-text-for-tca.json")), cldsModel1.getPropText(), true); - CldsModel cldsModel2 = verifyClosedLoopModelLoadedInDb(csar, generatedName, INSTANCE_NAME_RESOURCE2); + CldsModel cldsModel2 = verifyClosedLoopModelLoadedInDb(csar, "tca_2.yaml"); JSONAssert.assertEquals( IOUtils .toString(ResourceFileUtil.getResourceAsStream("example/sdc/blueprint-dcae/prop-text-for-tca-2.json")), cldsModel2.getPropText(), true); + CldsModel cldsModel3 = verifyClosedLoopModelLoadedInDb(csar, "tca_3.yaml"); + JSONAssert.assertEquals( + IOUtils.toString(ResourceFileUtil.getResourceAsStream("example/sdc/blueprint-dcae/prop-text-for-tca.json")), + cldsModel3.getPropText(), true); } - private CldsModel verifyClosedLoopModelLoadedInDb(CsarHandler csar, String generatedName, - String instanceNameResource) throws SdcArtifactInstallerException { + private CldsModel verifyClosedLoopModelLoadedInDb(CsarHandler csar, String artifactName) + throws SdcArtifactInstallerException { + // Get the template back from DB - CldsTemplate templateFromDb = CldsTemplate.retrieve(cldsDao, - CsarInstallerImpl.TEMPLATE_NAME_PREFIX + CsarInstallerImpl.buildModelName(csar, instanceNameResource), - false); + CldsTemplate templateFromDb = CldsTemplate.retrieve(cldsDao, CsarInstallerImpl.TEMPLATE_NAME_PREFIX + + CsarInstallerImpl.buildModelName(csar, csar.getMapOfBlueprints().get(artifactName)), false); assertNotNull(templateFromDb); assertNotNull(templateFromDb.getBpmnText()); assertNotNull(templateFromDb.getImageText()); assertNotNull(templateFromDb.getPropText()); assertTrue(templateFromDb.getPropText().contains("global") && templateFromDb.getPropText().contains("node_templates:")); - assertEquals(templateFromDb.getName(), - CsarInstallerImpl.TEMPLATE_NAME_PREFIX + CsarInstallerImpl.buildModelName(csar, instanceNameResource)); + assertEquals(templateFromDb.getName(), CsarInstallerImpl.TEMPLATE_NAME_PREFIX + + CsarInstallerImpl.buildModelName(csar, csar.getMapOfBlueprints().get(artifactName))); // Get the Model back from DB CldsModel modelFromDb = CldsModel.retrieve(cldsDao, - CsarInstallerImpl.buildModelName(csar, instanceNameResource), true); + CsarInstallerImpl.buildModelName(csar, csar.getMapOfBlueprints().get(artifactName)), true); assertNotNull(modelFromDb); assertNotNull(modelFromDb.getBpmnText()); assertNotNull(modelFromDb.getImageText()); assertNotNull(modelFromDb.getPropText()); assertTrue(modelFromDb.getPropText().contains("policy_id")); - assertEquals(CsarInstallerImpl.buildModelName(csar, instanceNameResource), modelFromDb.getName()); + assertEquals(CsarInstallerImpl.buildModelName(csar, csar.getMapOfBlueprints().get(artifactName)), + modelFromDb.getName()); assertEquals(CsarInstallerImpl.CONTROL_NAME_PREFIX, modelFromDb.getControlNamePrefix()); return modelFromDb; } 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/CsarHandlerTest.java b/src/test/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandlerTest.java index 725b1ff1..bb4fd01f 100644 --- a/src/test/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandlerTest.java +++ b/src/test/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandlerTest.java @@ -57,6 +57,7 @@ public class CsarHandlerTest { private static final String RESOURCE1_INSTANCE_NAME = "sim-1802 0"; private static final String RESOURCE1_INSTANCE_NAME_IN_CSAR = "sim18020"; private static final String BLUEPRINT1_NAME = "FOI.Simfoimap223S0112.event_proc_bp.yaml"; + private static final String BLUEPRINT2_NAME = "FOI.Simfoimap223S0112.event_proc_bp2.yaml"; @Test public void testConstructor() throws CsarHandlerException { @@ -124,20 +125,26 @@ public class CsarHandlerTest { assertEquals(CSAR_ARTIFACT_NAME, csar.getArtifactElement().getArtifactName()); assertNotNull(csar.getSdcCsarHelper()); // Test dcaeBlueprint - String blueprint = csar.getMapOfBlueprints().get(RESOURCE1_INSTANCE_NAME).getDcaeBlueprint(); + String blueprint = csar.getMapOfBlueprints().get(BLUEPRINT1_NAME).getDcaeBlueprint(); assertNotNull(blueprint); assertTrue(!blueprint.isEmpty()); assertTrue(blueprint.contains("DCAE-VES-PM-EVENT-v1")); // Test additional properties from Sdc notif - assertEquals(BLUEPRINT1_NAME, - csar.getMapOfBlueprints().get(RESOURCE1_INSTANCE_NAME).getBlueprintArtifactName()); + assertEquals(BLUEPRINT1_NAME, csar.getMapOfBlueprints().get(BLUEPRINT1_NAME).getBlueprintArtifactName()); assertEquals(RESOURCE1_UUID, - csar.getMapOfBlueprints().get(RESOURCE1_INSTANCE_NAME).getResourceAttached().getResourceInvariantUUID()); - assertEquals(SERVICE_UUID, - csar.getMapOfBlueprints().get(RESOURCE1_INSTANCE_NAME).getBlueprintInvariantServiceUuid()); + csar.getMapOfBlueprints().get(BLUEPRINT1_NAME).getResourceAttached().getResourceInvariantUUID()); + assertEquals(SERVICE_UUID, csar.getMapOfBlueprints().get(BLUEPRINT1_NAME).getBlueprintInvariantServiceUuid()); + + // Just check the second one is there as well + assertEquals(BLUEPRINT2_NAME, csar.getMapOfBlueprints().get(BLUEPRINT2_NAME).getBlueprintArtifactName()); + blueprint = csar.getMapOfBlueprints().get(BLUEPRINT2_NAME).getDcaeBlueprint(); + assertNotNull(blueprint); + assertTrue(!blueprint.isEmpty()); + assertTrue(blueprint.contains("DCAE-VES-PM-EVENT-v1")); // Do some cleanup Path path = Paths.get(SDC_FOLDER + "/test-controller/" + CSAR_ARTIFACT_NAME); Files.deleteIfExists(path); + } @Test @@ -150,17 +157,15 @@ public class CsarHandlerTest { assertEquals(CSAR_ARTIFACT_NAME, csar.getArtifactElement().getArtifactName()); assertNotNull(csar.getSdcCsarHelper()); // Test dcaeBlueprint - String blueprint = csar.getMapOfBlueprints().get(RESOURCE1_INSTANCE_NAME).getDcaeBlueprint(); + String blueprint = csar.getMapOfBlueprints().get(BLUEPRINT1_NAME).getDcaeBlueprint(); assertNotNull(blueprint); assertTrue(!blueprint.isEmpty()); assertTrue(blueprint.contains("DCAE-VES-PM-EVENT-v1")); // Test additional properties from Sdc notif - assertEquals(BLUEPRINT1_NAME, - csar.getMapOfBlueprints().get(RESOURCE1_INSTANCE_NAME).getBlueprintArtifactName()); + assertEquals(BLUEPRINT1_NAME, csar.getMapOfBlueprints().get(BLUEPRINT1_NAME).getBlueprintArtifactName()); assertEquals(RESOURCE1_UUID, - csar.getMapOfBlueprints().get(RESOURCE1_INSTANCE_NAME).getResourceAttached().getResourceInvariantUUID()); - assertEquals(SERVICE_UUID, - csar.getMapOfBlueprints().get(RESOURCE1_INSTANCE_NAME).getBlueprintInvariantServiceUuid()); + csar.getMapOfBlueprints().get(BLUEPRINT1_NAME).getResourceAttached().getResourceInvariantUUID()); + assertEquals(SERVICE_UUID, csar.getMapOfBlueprints().get(BLUEPRINT1_NAME).getBlueprintInvariantServiceUuid()); Path path = Paths.get(SDC_FOLDER + "/test-controller/" + CSAR_ARTIFACT_NAME); // A double save should simply overwrite the existing csar.save(buildFakeSdcResut()); 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/application.properties b/src/test/resources/application.properties index d75c6086..f41b68df 100644 --- a/src/test/resources/application.properties +++ b/src/test/resources/application.properties @@ -124,11 +124,6 @@ clamp.config.files.sdcController=classpath:/clds/sdc-controllers-config.json clamp.config.dcae.template=classpath:/clds/templates/dcae-template.json
clamp.config.dcae.deployment.template=classpath:/clds/templates/dcae-deployment-template.json
#
-# SDC request blueprint properties
-#
-clamp.config.sdc.template=classpath:/clds/templates/sdc-template.json
-clamp.config.sdc.decode.service_ids=classpath:/clds/templates/sdc-decode-service_ids.json
-#
#
# Configuration Settings for Policy Engine Components
clamp.config.policy.pdpUrl1=http://localhost:${docker.http-cache.port.host}/pdp/ , testpdp, alpha123
@@ -178,18 +173,6 @@ clamp.config.op.controller=amsterdam clamp.config.op.policy.appc=APPC
#
# Sdc service properties
-clamp.config.sdc.catalog.url=http://localhost:${docker.http-cache.port.host}/sdc/v1/catalog/
-clamp.config.sdc.hostUrl=http://localhost:${docker.http-cache.port.host}
-clamp.config.sdc.serviceUrl=http://localhost:${docker.http-cache.port.host}/sdc/v1/catalog/services
-clamp.config.sdc.serviceUsername=clamp
-clamp.config.sdc.servicePassword=b7acccda32b98c5bb7acccda32b98c5b05D511BD6D93626E90D18E9D24D9B78CD34C7EE8012F0A189A28763E82271E50A5D4EC10C7D93E06E0A2D27CAE66B981
-clamp.config.sdc.artifactLabel=blueprintclampcockpit
-clamp.config.sdc.sdcX-InstanceID=CLAMP
-clamp.config.sdc.artifactType=DCAE_INVENTORY_BLUEPRINT
-clamp.config.sdc.locationArtifactLabel=locationclampcockpit
-clamp.config.sdc.locationArtifactType=DCAE_INVENTORY_JSON
-clamp.config.sdc.InstanceID=X-ECOMP-InstanceID
-clamp.config.sdc.header.requestId = X-ECOMP-RequestID
#
clamp.config.sdc.csarFolder = ${project.build.directory}/sdc-tests
clamp.config.sdc.blueprint.parser.mapping = classpath:/clds/blueprint-parser-mapping.json
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/example/sdc/blueprint-dcae/tca_3.yaml b/src/test/resources/example/sdc/blueprint-dcae/tca_3.yaml new file mode 100644 index 00000000..0ab83171 --- /dev/null +++ b/src/test/resources/example/sdc/blueprint-dcae/tca_3.yaml @@ -0,0 +1,104 @@ +tosca_definitions_version: cloudify_dsl_1_3 +imports: +- http://www.getcloudify.org/spec/cloudify/3.4/types.yaml +- https://onap.org:8443/repository/solutioning01-mte2-raw/type_files/docker/2.2.0/node-type.yaml +- https://onap.org:8443/repository/solutioning01-mte2-raw/type_files/relationship/1.0.0/node-type.yaml +- http://onap.org:8081/repository/solutioning01-mte2-raw/type_files/dmaap/dmaap_mr.yaml +inputs: + location_id: + type: string + service_id: + type: string + policy_id: + type: string +node_templates: + policy_0: + type: dcae.nodes.policy + properties: + policy_id: + get_input: policy_id + cdap_host_host: + type: dcae.nodes.StreamingAnalytics.SelectedCDAPInfrastructure + properties: + location_id: + get_input: location_id + scn_override: cdap_broker.solutioning-central.dcae.onap.org + interfaces: + cloudify.interfaces.lifecycle: { + } + tca_tca: + type: dcae.nodes.MicroService.cdap + properties: + app_config: + appDescription: DCAE Analytics Threshold Crossing Alert Application + appName: dcae-tca + tcaSubscriberOutputStreamName: TCASubscriberOutputStream + tcaVESAlertsTableName: TCAVESAlertsTable + tcaVESAlertsTableTTLSeconds: '1728000' + tcaVESMessageStatusTableName: TCAVESMessageStatusTable + tcaVESMessageStatusTableTTLSeconds: '86400' + thresholdCalculatorFlowletInstances: '2' + app_preferences: + publisherContentType: application/json + publisherHostName: mrlocal-mtnjftle01.onap.org + publisherHostPort: '3905' + publisherMaxBatchSize: '10' + publisherMaxRecoveryQueueSize: '100000' + publisherPollingInterval: '20000' + publisherProtocol: https + publisherTopicName: org.onap.dcae.dmaap.mtnje2.DcaeTestVESPub + publisherUserName: test@tca.af.dcae.onap.org + publisherUserPassword: password + subscriberConsumerGroup: OpenDCAE-c12 + subscriberConsumerId: c12 + subscriberContentType: application/json + subscriberHostName: mrlocal-mtnjftle01.onap.org + subscriberHostPort: '3905' + subscriberMessageLimit: '-1' + subscriberPollingInterval: '20000' + subscriberProtocol: https + subscriberTimeoutMS: '-1' + subscriberTopicName: org.onap.dcae.dmaap.mtnje2.DcaeTestVESSub + subscriberUserName: test@tca.af.dcae.onap.org + subscriberUserPassword: password + tca_policy: null + artifact_name: dcae-analytics-tca + artifact_version: 1.0.0 + connections: + streams_publishes: [ + ] + streams_subscribes: [ + ] + jar_url: http://somejar + location_id: + get_input: location_id + namespace: cdap_tca_hi_lo + programs: + - program_id: TCAVESCollectorFlow + program_type: flows + - program_id: TCADMaaPMRSubscriberWorker + program_type: workers + - program_id: TCADMaaPMRPublisherWorker + program_type: workers + service_component_type: cdap_app_tca + service_id: + get_input: service_id + streamname: TCASubscriberOutputStream + relationships: + - target: topic0 + type: dcae.relationships.subscribe_to_events + - target: topic1 + type: dcae.relationships.publish_events + - target: cdap_host_host + type: dcae.relationships.component_contained_in + - target: policy_0 + type: dcae.relationships.depends_on + topic0: + type: dcae.nodes.Topic + properties: + topic_name: '' + topic1: + type: dcae.nodes.Topic + properties: + topic_name: '' + diff --git a/src/test/resources/example/sdc/service-Simsfoimap0112.csar b/src/test/resources/example/sdc/service-Simsfoimap0112.csar Binary files differindex fac487ce..ea0e44a2 100644 --- a/src/test/resources/example/sdc/service-Simsfoimap0112.csar +++ b/src/test/resources/example/sdc/service-Simsfoimap0112.csar 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 |