diff options
Diffstat (limited to 'src/test')
16 files changed, 487 insertions, 22 deletions
diff --git a/src/test/java/org/onap/clamp/clds/client/HolmesPolicyDelegateTest.java b/src/test/java/org/onap/clamp/clds/client/HolmesPolicyDelegateTest.java new file mode 100644 index 000000000..1d3f1ce61 --- /dev/null +++ b/src/test/java/org/onap/clamp/clds/client/HolmesPolicyDelegateTest.java @@ -0,0 +1,183 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP CLAMP + * ================================================================================ + * Copyright (C) 2019 Samsung. 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; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.any; +import static org.mockito.Mockito.anyString; +import static org.mockito.Mockito.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; + +import java.io.IOException; + +import org.apache.camel.Exchange; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.onap.clamp.clds.client.req.policy.PolicyClient; +import org.onap.clamp.clds.config.ClampProperties; +import org.onap.clamp.clds.dao.CldsDao; +import org.onap.clamp.clds.exception.ModelBpmnException; +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.util.JsonUtils; + +@RunWith(MockitoJUnitRunner.class) +public class HolmesPolicyDelegateTest { + + private static final String ID_JSON = "{\"id\":{\"r\":[{},{\"serviceConfigurations\":" + + "[[\"x\",\"+\",\"2\",\"y\"]]}]}}"; + private static final String METRICS_JSON = "{\"metricsPerEventName\":[{\"thresholds\":[]}]}"; + private static final String CONTENT_JSON = "{\"content\":{}}"; + private static final String NULL_JSON = "{}"; + private static final String HOLMES_ID_FROM_JSON = "{\"holmes\":[{\"id\":\"id\",\"from\":\"\"}]}"; + private static final String TCA_ID_FROM_JSON = "{\"tca\":[{\"id\":\"\",\"from\":\"\"}]}"; + private static final String CORRELATION_LOGIC_JSON = "{\"name\":\"correlationalLogic\"}"; + private static final String NOT_JSON = "not json"; + private static final String MODEL_BPMN_KEY = "modelBpmnProp"; + private static final String MODEL_PROP_KEY = "modelProp"; + private static final String MODEL_NAME_KEY = "modelName"; + private static final String TEST_KEY = "isTest"; + private static final String USERID_KEY = "userid"; + private static final String TCA_TEMPLATE_KEY = "tca.template"; + private static final String TCA_POLICY_TEMPLATE_KEY = "tca.policy.template"; + private static final String TCA_THRESHOLDS_TEMPLATE_KEY = "tca.thresholds.template"; + private static final String HOLMES_POLICY_RESPONSE_MESSAGE_KEY = "holmesPolicyResponseMessage"; + private static final String RESPONSE_MESSAGE_VALUE = "responseMessage"; + private static final String MODEL_NAME_VALUE = "model.name"; + private static final String CONTROL_NAME_VALUE = "control.name"; + private static final String USERID_VALUE = "user"; + private static final String CLDS_MODEL_ID = "id"; + private static final String CLDS_MODEL_PROP_TEXT = "propText"; + + @Mock + private Exchange exchange; + + @Mock + private PolicyClient policyClient; + + @Mock + private ClampProperties clampProperties; + + @Mock + private CldsDao cldsDao; + + @InjectMocks + private HolmesPolicyDelegate holmesPolicyDelegateTest; + + @Test + public void shouldExecuteSuccessfully() throws IOException { + // given + when(exchange.getProperty(eq(MODEL_BPMN_KEY))).thenReturn(HOLMES_ID_FROM_JSON); + when(exchange.getProperty(eq(MODEL_PROP_KEY))).thenReturn(ID_JSON); + when(exchange.getProperty(eq(MODEL_NAME_KEY))).thenReturn(MODEL_NAME_VALUE); + when(exchange.getProperty(eq(TEST_KEY))).thenReturn(false); + when(exchange.getProperty(eq(USERID_KEY))).thenReturn(USERID_VALUE); + + JsonElement jsonTemplateA = mock(JsonElement.class); + when(clampProperties.getJsonTemplate(eq(TCA_TEMPLATE_KEY), anyString())).thenReturn(jsonTemplateA); + when(jsonTemplateA.getAsJsonObject()).thenReturn(getJsonObject(METRICS_JSON)); + + JsonElement jsonTemplateB = mock(JsonElement.class); + when(clampProperties.getJsonTemplate(eq(TCA_POLICY_TEMPLATE_KEY), anyString())).thenReturn(jsonTemplateB); + when(jsonTemplateB.getAsJsonObject()).thenReturn(getJsonObject(CONTENT_JSON)); + + JsonElement jsonTemplateC = mock(JsonElement.class); + when(clampProperties.getJsonTemplate(eq(TCA_THRESHOLDS_TEMPLATE_KEY), anyString())).thenReturn(jsonTemplateC); + when(jsonTemplateC.getAsJsonObject()).thenReturn(getJsonObject(NULL_JSON)); + + when(policyClient.sendBasePolicyInOther(anyString(), anyString(), any(), anyString())) + .thenReturn(RESPONSE_MESSAGE_VALUE); + + CldsModel cldsModel = new CldsModel(); + cldsModel.setId(CLDS_MODEL_ID); + cldsModel.setPropText(CLDS_MODEL_PROP_TEXT); + when(cldsDao.getModelTemplate(eq(MODEL_NAME_VALUE))).thenReturn(cldsModel); + + // when + holmesPolicyDelegateTest.execute(exchange); + + // then + verify(exchange).setProperty(eq(HOLMES_POLICY_RESPONSE_MESSAGE_KEY), eq(RESPONSE_MESSAGE_VALUE.getBytes())); + verify(cldsDao).setModel(eq(cldsModel), eq(USERID_VALUE)); + } + + @Test + public void shouldExecuteHolmesNotFound() { + // given + when(exchange.getProperty(eq(MODEL_BPMN_KEY))).thenReturn(TCA_ID_FROM_JSON); + when(exchange.getProperty(eq(MODEL_PROP_KEY))).thenReturn(ID_JSON); + when(exchange.getProperty(eq(TEST_KEY))).thenReturn(false); + + // when + holmesPolicyDelegateTest.execute(exchange); + + // then + verify(policyClient, never()).sendBasePolicyInOther(anyString(), anyString(), any(), anyString()); + verify(exchange, never()).setProperty(eq(HOLMES_POLICY_RESPONSE_MESSAGE_KEY), any()); + verify(cldsDao, never()).setModel(any(), anyString()); + } + + @Test(expected = ModelBpmnException.class) + public void shouldThrowModelBpmnException() { + // given + when(exchange.getProperty(eq(MODEL_BPMN_KEY))).thenReturn(NOT_JSON); + when(exchange.getProperty(eq(TEST_KEY))).thenReturn(false); + + // when + holmesPolicyDelegateTest.execute(exchange); + } + + @Test(expected = NullPointerException.class) + public void shouldThrowNullPointerException() { + // when + holmesPolicyDelegateTest.execute(exchange); + } + + @Test + public void shouldDoFormatHolmesConfigBodySuccessfully() { + // given + ModelProperties prop = new ModelProperties(null, CONTROL_NAME_VALUE, null, false, + HOLMES_ID_FROM_JSON, "{\"id\":" + CORRELATION_LOGIC_JSON + "}"); + Holmes holmes = prop.getType(Holmes.class); + + // when + String result = HolmesPolicyDelegate.formatHolmesConfigBody(prop, holmes); + + // then + assertEquals(CONTROL_NAME_VALUE + "$$$" + CORRELATION_LOGIC_JSON, result); + } + + private static JsonObject getJsonObject(String jsonText) { + return JsonUtils.GSON.fromJson(jsonText, JsonObject.class); + } +} diff --git a/src/test/java/org/onap/clamp/clds/client/HolmesPolicyDeleteDelegateTest.java b/src/test/java/org/onap/clamp/clds/client/HolmesPolicyDeleteDelegateTest.java new file mode 100644 index 000000000..ccebbfbe3 --- /dev/null +++ b/src/test/java/org/onap/clamp/clds/client/HolmesPolicyDeleteDelegateTest.java @@ -0,0 +1,104 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP CLAMP + * ================================================================================ + * Copyright (C) 2019 Samsung. 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; + +import static org.mockito.Mockito.any; +import static org.mockito.Mockito.eq; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import org.apache.camel.Exchange; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.onap.clamp.clds.client.req.policy.PolicyClient; +import org.onap.clamp.clds.exception.ModelBpmnException; + +@RunWith(MockitoJUnitRunner.class) +public class HolmesPolicyDeleteDelegateTest { + + private static final String MODEL_BPMN_KEY = "modelBpmnProp"; + private static final String MODEL_PROP_KEY = "modelProp"; + private static final String TEST_KEY = "isTest"; + + private static final String HOLMES_ID_FROM_JSON = "{\"holmes\":[{\"id\":\"\",\"from\":\"\"}]}"; + private static final String TCA_ID_FROM_JSON = "{\"tca\":[{\"id\":\"\",\"from\":\"\"}]}"; + private static final String ID_JSON = "{\"id\":\"\"}"; + private static final String NOT_JSON = "not json"; + + @Mock + private Exchange exchange; + + @Mock + private PolicyClient policyClient; + + @InjectMocks + private HolmesPolicyDeleteDelegate holmesPolicyDeleteDelegate; + + @Test + public void shouldExecuteSuccessfully() { + // given + when(exchange.getProperty(eq(MODEL_BPMN_KEY))).thenReturn(HOLMES_ID_FROM_JSON); + when(exchange.getProperty(eq(MODEL_PROP_KEY))).thenReturn(ID_JSON); + when(exchange.getProperty(eq(TEST_KEY))).thenReturn(false); + + // when + holmesPolicyDeleteDelegate.execute(exchange); + + // then + verify(policyClient).deleteBasePolicy(any()); + } + + @Test + public void shouldExecuteHolmesNotFound() { + // given + when(exchange.getProperty(eq(MODEL_BPMN_KEY))).thenReturn(TCA_ID_FROM_JSON); + when(exchange.getProperty(eq(MODEL_PROP_KEY))).thenReturn(ID_JSON); + when(exchange.getProperty(eq(TEST_KEY))).thenReturn(false); + + // when + holmesPolicyDeleteDelegate.execute(exchange); + + // then + verify(policyClient, never()).deleteBasePolicy(any()); + } + + @Test(expected = ModelBpmnException.class) + public void shouldThrowModelBpmnException() { + // given + when(exchange.getProperty(eq(MODEL_BPMN_KEY))).thenReturn(NOT_JSON); + when(exchange.getProperty(eq(TEST_KEY))).thenReturn(false); + + // when + holmesPolicyDeleteDelegate.execute(exchange); + } + + @Test(expected = NullPointerException.class) + public void shouldThrowNullPointerException() { + // when + holmesPolicyDeleteDelegate.execute(exchange); + } +} diff --git a/src/test/java/org/onap/clamp/clds/client/ModelDeleteDelegateTest.java b/src/test/java/org/onap/clamp/clds/client/ModelDeleteDelegateTest.java new file mode 100644 index 000000000..06b94225d --- /dev/null +++ b/src/test/java/org/onap/clamp/clds/client/ModelDeleteDelegateTest.java @@ -0,0 +1,63 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP CLAMP + * ================================================================================ + * Copyright (C) 2019 Samsung. 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; + +import static org.mockito.Mockito.eq; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import org.apache.camel.Exchange; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.onap.clamp.clds.dao.CldsDao; + +@RunWith(MockitoJUnitRunner.class) +public class ModelDeleteDelegateTest { + + private static final String NAME_KEY = "modelName"; + private static final String NAME_VALUE = "model.name"; + + @Mock + private Exchange exchange; + + @Mock + private CldsDao cldsDao; + + @InjectMocks + private ModelDeleteDelegate modelDeleteDelegate; + + @Test + public void shouldExecuteSuccessfully() { + // given + when(exchange.getProperty(eq(NAME_KEY))).thenReturn(NAME_VALUE); + + // when + modelDeleteDelegate.execute(exchange); + + // then + verify(cldsDao).deleteModel(eq(NAME_VALUE)); + } +} diff --git a/src/test/java/org/onap/clamp/clds/it/CldsHealthcheckServiceItCase.java b/src/test/java/org/onap/clamp/clds/it/CldsHealthcheckServiceItCase.java index 5d8910352..1dbea376d 100644 --- a/src/test/java/org/onap/clamp/clds/it/CldsHealthcheckServiceItCase.java +++ b/src/test/java/org/onap/clamp/clds/it/CldsHealthcheckServiceItCase.java @@ -25,8 +25,6 @@ package org.onap.clamp.clds.it; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import javax.ws.rs.core.Response; - import org.junit.Test; import org.junit.runner.RunWith; import org.onap.clamp.clds.model.CldsHealthCheck; 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 347de4a78..faeb04182 100644 --- a/src/test/java/org/onap/clamp/clds/it/CldsServiceItCase.java +++ b/src/test/java/org/onap/clamp/clds/it/CldsServiceItCase.java @@ -149,6 +149,7 @@ public class CldsServiceItCase { Properties prop = new Properties(); InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("clds-version.properties"); prop.load(in); + assertNotNull(in); in.close(); assertEquals(cldsInfo.getCldsVersion(), prop.getProperty("clds.version")); assertEquals(cldsInfo.getUserName(), "admin"); diff --git a/src/test/java/org/onap/clamp/clds/it/CldsToscaServiceItCase.java b/src/test/java/org/onap/clamp/clds/it/CldsToscaServiceItCase.java index 7d48086cb..992c06e8c 100644 --- a/src/test/java/org/onap/clamp/clds/it/CldsToscaServiceItCase.java +++ b/src/test/java/org/onap/clamp/clds/it/CldsToscaServiceItCase.java @@ -69,7 +69,7 @@ public class CldsToscaServiceItCase { private String toscaModelYaml; private Authentication authentication; private CldsToscaModel cldsToscaModel; - private List<GrantedAuthority> authList = new LinkedList<GrantedAuthority>(); + private List<GrantedAuthority> authList = new LinkedList<>(); private LoggingUtils util; /** diff --git a/src/test/java/org/onap/clamp/clds/util/CryptoUtilsTest.java b/src/test/java/org/onap/clamp/clds/util/CryptoUtilsTest.java index 603d2d28f..1e6742c98 100644 --- a/src/test/java/org/onap/clamp/clds/util/CryptoUtilsTest.java +++ b/src/test/java/org/onap/clamp/clds/util/CryptoUtilsTest.java @@ -5,7 +5,9 @@ * Copyright (C) 2017 AT&T Intellectual Property. All rights * reserved. * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); + * Modifications Copyright (c) 2019 Samsung + * ================================================================================ + * 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 * @@ -26,17 +28,30 @@ package org.onap.clamp.clds.util; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; +import static org.mockito.Matchers.eq; + +import java.security.InvalidKeyException; + +import javax.crypto.KeyGenerator; +import javax.crypto.SecretKey; import org.apache.commons.codec.binary.Hex; import org.apache.commons.lang3.ArrayUtils; import org.junit.Test; +import org.junit.runner.RunWith; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PowerMockIgnore; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; - +@RunWith(PowerMockRunner.class) +@PowerMockIgnore({"javax.crypto.*"}) public class CryptoUtilsTest { private final String data = "This is a test string"; @Test + @PrepareForTest({CryptoUtils.class}) public final void testEncryption() throws Exception { String encodedString = CryptoUtils.encrypt(data); assertNotNull(encodedString); @@ -44,6 +59,7 @@ public class CryptoUtilsTest { } @Test + @PrepareForTest({CryptoUtils.class}) public final void testEncryptedStringIsDifferent() throws Exception { String encodedString1 = CryptoUtils.encrypt(data); String encodedString2 = CryptoUtils.encrypt(data); @@ -56,4 +72,30 @@ public class CryptoUtilsTest { byte[] subData2 = ArrayUtils.subarray(encryptedMessage2, 16, encryptedMessage2.length); assertNotEquals(subData1, subData2); } -}
\ No newline at end of file + + @Test + @PrepareForTest({CryptoUtils.class}) + public final void testEncryptionBaseOnRandomKey() throws Exception { + SecretKey secretKey = KeyGenerator.getInstance("AES").generateKey(); + final String encryptionKey = String.valueOf(Hex.encodeHex(secretKey.getEncoded())); + setAesEncryptionKeyEnv(encryptionKey); + + String encodedString = CryptoUtils.encrypt(data); + String decodedString = CryptoUtils.decrypt(encodedString); + assertEquals(data, decodedString); + } + + @Test(expected = InvalidKeyException.class) + @PrepareForTest({CryptoUtils.class}) + public final void testEncryptionBadKey() throws Exception { + final String badEncryptionKey = "93210sd"; + setAesEncryptionKeyEnv(badEncryptionKey); + + CryptoUtils.encrypt(data); + } + + private static void setAesEncryptionKeyEnv(String value) { + PowerMockito.mockStatic(System.class); + PowerMockito.when(System.getenv(eq("AES_ENCRYPTION_KEY"))).thenReturn(value); + } +} diff --git a/src/test/java/org/onap/clamp/clds/util/JsonUtilsTest.java b/src/test/java/org/onap/clamp/clds/util/JsonUtilsTest.java index 82c2162a5..d1adc166f 100644 --- a/src/test/java/org/onap/clamp/clds/util/JsonUtilsTest.java +++ b/src/test/java/org/onap/clamp/clds/util/JsonUtilsTest.java @@ -5,6 +5,8 @@ * Copyright (C) 2018 AT&T Intellectual Property. All rights * reserved. * ================================================================================ + * Modifications Copyright (c) 2019 Samsung + * ================================================================================ * 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 @@ -155,4 +157,9 @@ public class JsonUtilsTest { // then assertThat(timeoutValue).isEqualTo(500); } + + @Test(expected = IllegalArgumentException.class) + public void shouldThrowExceptionFileNotExists() throws IOException { + ResourceFileUtil.getResourceAsString("example/notExist.json"); + } } diff --git a/src/test/java/org/onap/clamp/clds/util/drawing/DocumentBuilderTest.java b/src/test/java/org/onap/clamp/clds/util/drawing/DocumentBuilderTest.java index 6546553c7..63a1fa3e7 100644 --- a/src/test/java/org/onap/clamp/clds/util/drawing/DocumentBuilderTest.java +++ b/src/test/java/org/onap/clamp/clds/util/drawing/DocumentBuilderTest.java @@ -47,9 +47,6 @@ public class DocumentBuilderTest { @Mock private SVGGraphics2D mockG2d; - @Mock - private Document mockDomImpl; - @Test public void pushChangestoDocumentTest() throws IOException, ParserConfigurationException, SAXException { String dataElementId = "someId"; diff --git a/src/test/java/org/onap/clamp/loop/CsarInstallerItCase.java b/src/test/java/org/onap/clamp/loop/CsarInstallerItCase.java index cd6db68db..ed912831e 100644 --- a/src/test/java/org/onap/clamp/loop/CsarInstallerItCase.java +++ b/src/test/java/org/onap/clamp/loop/CsarInstallerItCase.java @@ -6,7 +6,8 @@ * reserved. * ================================================================================ * Modifications copyright (c) 2019 Nokia - * =================================================================== + * Modifications Copyright (c) 2019 Samsung + * ================================================================================ * 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 @@ -26,6 +27,7 @@ package org.onap.clamp.loop; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Matchers.any; import java.io.IOException; import java.util.ArrayList; @@ -63,7 +65,6 @@ import org.skyscreamer.jsonassert.JSONAssert; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.annotation.Rollback; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; @@ -220,4 +221,12 @@ public class CsarInstallerItCase { assertThat(((MicroServicePolicy) (loop.getMicroServicePolicies().toArray()[0])).getModelType()).isNotEmpty(); } + @Test(expected = SdcArtifactInstallerException.class) + @Transactional + public void shouldThrowSdcArtifactInstallerException() throws SdcArtifactInstallerException, SdcToscaParserException, IOException, InterruptedException, PolicyModelException { + String generatedName = RandomStringUtils.randomAlphanumeric(5); + CsarHandler csarHandler = buildFakeCsarHandler(generatedName); + Mockito.when(csarHandler.getMapOfBlueprints()).thenThrow(IOException.class); + csarInstaller.installTheCsar(csarHandler); + } } diff --git a/src/test/java/org/onap/clamp/policy/microservice/OperationalPolicyPayloadTest.java b/src/test/java/org/onap/clamp/policy/microservice/OperationalPolicyPayloadTest.java index b12ca89f5..8972e5117 100644 --- a/src/test/java/org/onap/clamp/policy/microservice/OperationalPolicyPayloadTest.java +++ b/src/test/java/org/onap/clamp/policy/microservice/OperationalPolicyPayloadTest.java @@ -33,6 +33,7 @@ import java.util.Map; import org.junit.Test; import org.onap.clamp.clds.util.ResourceFileUtil; +import org.onap.clamp.policy.operational.LegacyOperationalPolicy; import org.onap.clamp.policy.operational.OperationalPolicy; import org.skyscreamer.jsonassert.JSONAssert; @@ -43,13 +44,23 @@ public class OperationalPolicyPayloadTest { JsonObject jsonConfig = new GsonBuilder().create().fromJson( ResourceFileUtil.getResourceAsString("tosca/operational-policy-properties.json"), JsonObject.class); OperationalPolicy policy = new OperationalPolicy("testPolicy", null, jsonConfig); + assertThat(policy.createPolicyPayloadYaml()) .isEqualTo(ResourceFileUtil.getResourceAsString("tosca/operational-policy-payload.yaml")); + assertThat(policy.createPolicyPayload()) .isEqualTo(ResourceFileUtil.getResourceAsString("tosca/operational-policy-payload.json")); } @Test + public void testLegacyOperationalPolicyPayloadConstruction() throws IOException { + JsonObject jsonConfig = new GsonBuilder().create().fromJson( + ResourceFileUtil.getResourceAsString("tosca/operational-policy-properties.json"), JsonObject.class); + assertThat(LegacyOperationalPolicy.createPolicyPayloadYamlLegacy(jsonConfig.get("operational_policy"))) + .isEqualTo(ResourceFileUtil.getResourceAsString("tosca/operational-policy-payload-legacy.yaml")); + } + + @Test public void testGuardPolicyEmptyPayloadConstruction() throws IOException { JsonObject jsonConfig = new GsonBuilder().create().fromJson( ResourceFileUtil.getResourceAsString("tosca/operational-policy-no-guard-properties.json"), diff --git a/src/test/resources/tosca/operational-policy-no-guard-properties.json b/src/test/resources/tosca/operational-policy-no-guard-properties.json index 30c044044..fdb1906a4 100644 --- a/src/test/resources/tosca/operational-policy-no-guard-properties.json +++ b/src/test/resources/tosca/operational-policy-no-guard-properties.json @@ -22,7 +22,7 @@ "failure_guard": "", "target": { "type": "VM", - "resourceId": "", + "resourceID": "", "modelInvariantId": "", "modelVersionId": "", "modelName": "", diff --git a/src/test/resources/tosca/operational-policy-payload-legacy.yaml b/src/test/resources/tosca/operational-policy-payload-legacy.yaml new file mode 100644 index 000000000..41184c9c9 --- /dev/null +++ b/src/test/resources/tosca/operational-policy-payload-legacy.yaml @@ -0,0 +1,39 @@ +controlLoop: + abatement: true + controlLoopName: control loop + timeout: 30 + trigger_policy: new1 + version: 2.0.0 +policies: +- actor: SO + failure: new2 + failure_exception: new2 + failure_guard: new2 + failure_retries: new2 + failure_timeout: new2 + id: new1 + payload: + configurationParameters: '[{"ip-addr":"$.vf-module-topology.vf-module-parameters.param[10].value","oam-ip-addr":"$.vf-module-topology.vf-module-parameters.param[15].value","enabled":"$.vf-module-topology.vf-module-parameters.param[22].value"}]' + requestParameters: '{"usePreload":true,"userParams":[]}' + recipe: Rebuild + retry: 10 + success: new2 + target: + resourceTargetId: test + type: VFC + timeout: 20 +- actor: SDNC + failure: final_failure + failure_exception: final_failure_exception + failure_guard: final_failure_guard + failure_retries: final_failure_retries + failure_timeout: final_failure_timeout + id: new2 + payload: '' + recipe: Migrate + retry: 30 + success: final_success + target: + resourceTargetId: test + type: VFC + timeout: 40 diff --git a/src/test/resources/tosca/operational-policy-payload.json b/src/test/resources/tosca/operational-policy-payload.json index 1017d0a2c..5097654da 100644 --- a/src/test/resources/tosca/operational-policy-payload.json +++ b/src/test/resources/tosca/operational-policy-payload.json @@ -1,4 +1,4 @@ { "policy-id": "testPolicy", - "content": "tosca_definitions_version%3A+tosca_simple_yaml_1_0_0%0Atopology_template%3A%0A++policies%3A%0A++-+testPolicy%3A%0A++++++type%3A+onap.policies.controlloop.Operational%0A++++++version%3A+1.0.0%0A++++++metadata%3A+%7Bpolicy-id%3A+testPolicy%7D%0A++++++properties%3A%0A++++++++controlLoop%3A+%7BcontrolLoopName%3A+control+loop%2C+version%3A+2.0.0%2C+trigger_policy%3A+new1%2C%0A++++++++++timeout%3A+%2730%27%2C+abatement%3A+%27true%27%7D%0A++++++++policies%3A%0A++++++++-+id%3A+new1%0A++++++++++recipe%3A+Rebuild%0A++++++++++retry%3A+%2710%27%0A++++++++++timeout%3A+%2720%27%0A++++++++++actor%3A+SO%0A++++++++++payload%3A+test%0A++++++++++success%3A+new2%0A++++++++++failure%3A+new2%0A++++++++++failure_timeout%3A+new2%0A++++++++++failure_retries%3A+new2%0A++++++++++failure_exception%3A+new2%0A++++++++++failure_guard%3A+new2%0A++++++++++target%3A+%7Btype%3A+VFC%2C+resourceTargetId%3A+test%7D%0A++++++++-+id%3A+new2%0A++++++++++recipe%3A+Migrate%0A++++++++++retry%3A+%2730%27%0A++++++++++timeout%3A+%2740%27%0A++++++++++actor%3A+SDNC%0A++++++++++payload%3A+test%0A++++++++++target%3A+%7Btype%3A+VFC%2C+resourceTargetId%3A+test%7D%0A" + "content": "controlLoop%3A%0A++abatement%3A+true%0A++controlLoopName%3A+control+loop%0A++timeout%3A+30%0A++trigger_policy%3A+new1%0A++version%3A+2.0.0%0Apolicies%3A%0A-+actor%3A+SO%0A++failure%3A+new2%0A++failure_exception%3A+new2%0A++failure_guard%3A+new2%0A++failure_retries%3A+new2%0A++failure_timeout%3A+new2%0A++id%3A+new1%0A++payload%3A%0A++++configurationParameters%3A+%27%5B%7B%22ip-addr%22%3A%22%24.vf-module-topology.vf-module-parameters.param%5B10%5D.value%22%2C%22oam-ip-addr%22%3A%22%24.vf-module-topology.vf-module-parameters.param%5B15%5D.value%22%2C%22enabled%22%3A%22%24.vf-module-topology.vf-module-parameters.param%5B22%5D.value%22%7D%5D%27%0A++++requestParameters%3A+%27%7B%22usePreload%22%3Atrue%2C%22userParams%22%3A%5B%5D%7D%27%0A++recipe%3A+Rebuild%0A++retry%3A+10%0A++success%3A+new2%0A++target%3A%0A++++resourceTargetId%3A+test%0A++++type%3A+VFC%0A++timeout%3A+20%0A-+actor%3A+SDNC%0A++failure%3A+final_failure%0A++failure_exception%3A+final_failure_exception%0A++failure_guard%3A+final_failure_guard%0A++failure_retries%3A+final_failure_retries%0A++failure_timeout%3A+final_failure_timeout%0A++id%3A+new2%0A++payload%3A+%27%27%0A++recipe%3A+Migrate%0A++retry%3A+30%0A++success%3A+final_success%0A++target%3A%0A++++resourceTargetId%3A+test%0A++++type%3A+VFC%0A++timeout%3A+40%0A" }
\ No newline at end of file diff --git a/src/test/resources/tosca/operational-policy-payload.yaml b/src/test/resources/tosca/operational-policy-payload.yaml index 68116b00b..c3a6b5c23 100644 --- a/src/test/resources/tosca/operational-policy-payload.yaml +++ b/src/test/resources/tosca/operational-policy-payload.yaml @@ -4,28 +4,39 @@ topology_template: - testPolicy: type: onap.policies.controlloop.Operational version: 1.0.0 - metadata: {policy-id: testPolicy} + metadata: + policy-id: testPolicy properties: - controlLoop: {controlLoopName: control loop, version: 2.0.0, trigger_policy: new1, - timeout: '30', abatement: 'true'} + controlLoop: + controlLoopName: control loop + version: 2.0.0 + trigger_policy: new1 + timeout: '30' + abatement: 'true' policies: - id: new1 recipe: Rebuild retry: '10' timeout: '20' actor: SO - payload: test + payload: + requestParameters: '{"usePreload":true,"userParams":[]}' + configurationParameters: '[{"ip-addr":"$.vf-module-topology.vf-module-parameters.param[10].value","oam-ip-addr":"$.vf-module-topology.vf-module-parameters.param[15].value","enabled":"$.vf-module-topology.vf-module-parameters.param[22].value"}]' success: new2 failure: new2 failure_timeout: new2 failure_retries: new2 failure_exception: new2 failure_guard: new2 - target: {type: VFC, resourceTargetId: test} + target: + type: VFC + resourceTargetId: test - id: new2 recipe: Migrate retry: '30' timeout: '40' actor: SDNC - payload: test - target: {type: VFC, resourceTargetId: test} + payload: '' + target: + type: VFC + resourceTargetId: test diff --git a/src/test/resources/tosca/operational-policy-properties.json b/src/test/resources/tosca/operational-policy-properties.json index 52eabb8aa..bfce6b331 100644 --- a/src/test/resources/tosca/operational-policy-properties.json +++ b/src/test/resources/tosca/operational-policy-properties.json @@ -42,7 +42,7 @@ "retry": "10", "timeout": "20", "actor": "SO", - "payload": "test", + "payload": "requestParameters: '{\"usePreload\":true,\"userParams\":[]}'\r\nconfigurationParameters: '[{\"ip-addr\":\"$.vf-module-topology.vf-module-parameters.param[10].value\",\"oam-ip-addr\":\"$.vf-module-topology.vf-module-parameters.param[15].value\",\"enabled\":\"$.vf-module-topology.vf-module-parameters.param[22].value\"}]'", "success": "new2", "failure": "new2", "failure_timeout": "new2", @@ -60,7 +60,7 @@ "retry": "30", "timeout": "40", "actor": "SDNC", - "payload": "test", + "payload": "", "target": { "type": "VFC", "resourceTargetId": "test" |