aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/org')
-rw-r--r--src/test/java/org/onap/clamp/clds/client/GuardPolicyDeleteDelegateTest.java117
-rw-r--r--src/test/java/org/onap/clamp/clds/client/HolmesPolicyDelegateTest.java183
-rw-r--r--src/test/java/org/onap/clamp/clds/client/HolmesPolicyDeleteDelegateTest.java104
-rw-r--r--src/test/java/org/onap/clamp/clds/client/ModelDeleteDelegateTest.java63
-rw-r--r--src/test/java/org/onap/clamp/clds/client/OperationalPolicyDelegateTest.java125
-rw-r--r--src/test/java/org/onap/clamp/clds/client/OperationalPolicyDeleteDelegateTest.java108
-rw-r--r--src/test/java/org/onap/clamp/clds/client/TcaPolicyDeleteDelegateTest.java103
-rw-r--r--src/test/java/org/onap/clamp/clds/config/CldsUserJsonDecoderTest.java13
-rw-r--r--src/test/java/org/onap/clamp/clds/it/CldsHealthcheckServiceItCase.java2
-rw-r--r--src/test/java/org/onap/clamp/clds/it/CldsServiceItCase.java1
-rw-r--r--src/test/java/org/onap/clamp/clds/it/CldsToscaServiceItCase.java2
-rw-r--r--src/test/java/org/onap/clamp/clds/it/sdc/controller/installer/CsarInstallerItCase.java13
-rw-r--r--src/test/java/org/onap/clamp/clds/sdc/controller/installer/BlueprintParserTest.java16
-rw-r--r--src/test/java/org/onap/clamp/clds/sdc/controller/installer/ChainGeneratorTest.java24
-rw-r--r--src/test/java/org/onap/clamp/clds/sdc/controller/installer/LoopCsarInstallerTest.java (renamed from src/test/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImplTest.java)2
-rw-r--r--src/test/java/org/onap/clamp/clds/util/CryptoUtilsTest.java48
-rw-r--r--src/test/java/org/onap/clamp/clds/util/JsonUtilsTest.java7
-rw-r--r--src/test/java/org/onap/clamp/clds/util/drawing/ClampGraphBuilderTest.java14
-rw-r--r--src/test/java/org/onap/clamp/clds/util/drawing/DocumentBuilderTest.java3
-rw-r--r--src/test/java/org/onap/clamp/flow/FlowLogOperationTest.java99
-rw-r--r--src/test/java/org/onap/clamp/loop/CsarInstallerItCase.java45
-rw-r--r--src/test/java/org/onap/clamp/loop/LoopOperationTestItCase.java244
-rw-r--r--src/test/java/org/onap/clamp/policy/microservice/MicroServicePayloadTest.java2
-rw-r--r--src/test/java/org/onap/clamp/policy/microservice/OperationalPolicyPayloadTest.java15
24 files changed, 1301 insertions, 52 deletions
diff --git a/src/test/java/org/onap/clamp/clds/client/GuardPolicyDeleteDelegateTest.java b/src/test/java/org/onap/clamp/clds/client/GuardPolicyDeleteDelegateTest.java
new file mode 100644
index 00000000..2ff8166b
--- /dev/null
+++ b/src/test/java/org/onap/clamp/clds/client/GuardPolicyDeleteDelegateTest.java
@@ -0,0 +1,117 @@
+/*-
+ * ============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 GuardPolicyDeleteDelegateTest {
+
+ 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 EVENT_ACTION_KEY = "eventAction";
+
+ private static final String POLICY_ID_FROM_JSON = "{policy:[{id:Policy_7,from:''}]}";
+ private static final String TCA_ID_FROM_JSON = "{tca:[{id:'',from:''}]}";
+ private static final String ID_JSON = "{Policy_7:{r:["
+ + "{name:pid,value:pid334},"
+ + "{name:timeout,value:50},"
+ + "{name:policyType,value:pt},"
+ + "{policyConfigurations:[["
+ + "{name:_id,value:ret345},"
+ + "{name:recipe,value:make},"
+ + "{name:maxRetries,value:5},"
+ + "{name:retryTimeLimit,value:100},"
+ + "{name:enableGuardPolicy,value:on}]]}]}}";
+ private static final String NOT_JSON = "not json";
+ private static final String EVENT_ACTION_VALUE = "action";
+
+ @Mock
+ private Exchange exchange;
+
+ @Mock
+ private PolicyClient policyClient;
+
+ @InjectMocks
+ private GuardPolicyDeleteDelegate guardPolicyDeleteDelegate;
+
+ @Test
+ public void shouldExecuteSuccessfully() {
+ // given
+ when(exchange.getProperty(eq(MODEL_BPMN_KEY))).thenReturn(POLICY_ID_FROM_JSON);
+ when(exchange.getProperty(eq(MODEL_PROP_KEY))).thenReturn(ID_JSON);
+ when(exchange.getProperty(eq(TEST_KEY))).thenReturn(false);
+ when(exchange.getProperty(eq(EVENT_ACTION_KEY))).thenReturn(EVENT_ACTION_VALUE);
+
+ // when
+ guardPolicyDeleteDelegate.execute(exchange);
+
+ // then
+ verify(policyClient).deleteGuard(any());
+ }
+
+ @Test
+ public void shouldExecutePolicyNotFound() {
+ // 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(exchange.getProperty(eq(EVENT_ACTION_KEY))).thenReturn(EVENT_ACTION_VALUE);
+
+ // when
+ guardPolicyDeleteDelegate.execute(exchange);
+
+ // then
+ verify(policyClient, never()).deleteGuard(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
+ guardPolicyDeleteDelegate.execute(exchange);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void shouldThrowNullPointerException() {
+ // when
+ guardPolicyDeleteDelegate.execute(exchange);
+ }
+}
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 00000000..1d3f1ce6
--- /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 00000000..ccebbfbe
--- /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 00000000..06b94225
--- /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/client/OperationalPolicyDelegateTest.java b/src/test/java/org/onap/clamp/clds/client/OperationalPolicyDelegateTest.java
new file mode 100644
index 00000000..75be799b
--- /dev/null
+++ b/src/test/java/org/onap/clamp/clds/client/OperationalPolicyDelegateTest.java
@@ -0,0 +1,125 @@
+/*-
+ * ============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.Matchers.any;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.io.UnsupportedEncodingException;
+
+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.exception.ModelBpmnException;
+import org.onap.policy.controlloop.policy.builder.BuilderException;
+
+@RunWith(MockitoJUnitRunner.class)
+public class OperationalPolicyDelegateTest {
+
+ private static final String TEST_KEY = "isTest";
+ private static final String MODEL_BPMN_KEY = "modelBpmnProp";
+ private static final String MODEL_PROP_KEY = "modelProp";
+ private static final String RECIPE_TOPIC_KEY = "op.recipeTopic";
+ private static final String MESSAGE_KEY = "operationalPolicyResponseMessage";
+ private static final String SERVICE_NAME = "service.name";
+ private static final String POLICY_ID_FROM_JSON = "{policy:[{id:Oper12,from:''}]}";
+ private static final String ID_WITH_CHAIN_JSON = "{Oper12:{ab:["
+ + "{name:timeout,value:500},"
+ + "{policyConfigurations:["
+ + "[{name:maxRetries,value:5},"
+ + "{name:retryTimeLimit,value:1000},"
+ + "{name:recipe,value:go},"
+ + "{name:targetResourceId,"
+ + "value:resid234}]]}]},"
+ + "global:[{name:service,value:" + SERVICE_NAME + "}]}";
+ private static final String SIMPLE_JSON = "{}";
+ private static final String NOT_JSON = "not json";
+ private static final String MESSAGE_VALUE = "message";
+ private static final String RECIPE_TOPIC_VALUE = "recipe.topic";
+
+ @Mock
+ private Exchange exchange;
+
+ @Mock
+ private PolicyClient policyClient;
+
+ @Mock
+ private ClampProperties refProp;
+
+ @InjectMocks
+ private OperationalPolicyDelegate operationalPolicyDelegate;
+
+ @Test
+ public void shouldExecuteSuccessfully() throws BuilderException, UnsupportedEncodingException {
+ // given
+ when(exchange.getProperty(eq(TEST_KEY))).thenReturn(true);
+ when(exchange.getProperty(eq(MODEL_BPMN_KEY))).thenReturn(POLICY_ID_FROM_JSON);
+ when(exchange.getProperty(eq(MODEL_PROP_KEY))).thenReturn(ID_WITH_CHAIN_JSON);
+ when(policyClient.sendBrmsPolicy(any(), any(), any())).thenReturn(MESSAGE_VALUE);
+ when(refProp.getStringValue(eq(RECIPE_TOPIC_KEY), eq(SERVICE_NAME))).thenReturn(RECIPE_TOPIC_VALUE);
+
+ // when
+ operationalPolicyDelegate.execute(exchange);
+
+ // then
+ verify(exchange).setProperty(eq(MESSAGE_KEY), eq(MESSAGE_VALUE.getBytes()));
+ }
+
+ @Test
+ public void shouldExecutePolicyNotFound() throws BuilderException, UnsupportedEncodingException {
+ // given
+ when(exchange.getProperty(eq(TEST_KEY))).thenReturn(false);
+ when(exchange.getProperty(eq(MODEL_BPMN_KEY))).thenReturn(SIMPLE_JSON);
+ when(exchange.getProperty(eq(MODEL_PROP_KEY))).thenReturn(SIMPLE_JSON);
+
+ // when
+ operationalPolicyDelegate.execute(exchange);
+
+ // then
+ verify(policyClient, never()).sendBrmsPolicy(any(), any(), any());
+ }
+
+ @Test(expected = ModelBpmnException.class)
+ public void shouldThrowModelBpmnException() throws BuilderException, UnsupportedEncodingException {
+ // given
+ when(exchange.getProperty(eq(TEST_KEY))).thenReturn(true);
+ when(exchange.getProperty(eq(MODEL_BPMN_KEY))).thenReturn(NOT_JSON);
+
+ // when
+ operationalPolicyDelegate.execute(exchange);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void shouldThrowNullPointerException() throws BuilderException, UnsupportedEncodingException {
+ // when
+ operationalPolicyDelegate.execute(exchange);
+ }
+}
diff --git a/src/test/java/org/onap/clamp/clds/client/OperationalPolicyDeleteDelegateTest.java b/src/test/java/org/onap/clamp/clds/client/OperationalPolicyDeleteDelegateTest.java
new file mode 100644
index 00000000..9d87e7e9
--- /dev/null
+++ b/src/test/java/org/onap/clamp/clds/client/OperationalPolicyDeleteDelegateTest.java
@@ -0,0 +1,108 @@
+/*-
+ * ============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.Matchers.any;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
+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;
+import org.onap.clamp.clds.model.properties.ModelProperties;
+
+@RunWith(MockitoJUnitRunner.class)
+public class OperationalPolicyDeleteDelegateTest {
+
+ private static final String TEST_KEY = "isTest";
+ private static final String MODEL_BPMN_KEY = "modelBpmnProp";
+ private static final String MODEL_PROP_KEY = "modelProp";
+ private static final String EVENT_ACTION_KEY = "eventAction";
+ private static final String POLICY_ID_FROM_JSON = "{policy:[{id:Poli2,from:''}]}";
+ private static final String ID_WITH_CHAIN_JSON = "{Poli2:{ab:c,xy:z}}";
+ private static final String ID_NO_CHAIN_JSON = "{Poli2:{}}";
+ private static final String EVENT_ACTION_VALUE = "still";
+ private static final String NOT_JSON = "23e";
+
+ @Mock
+ private Exchange exchange;
+
+ @Mock
+ private PolicyClient policyClient;
+
+ @InjectMocks
+ private OperationalPolicyDeleteDelegate operationalPolicyDeleteDelegate;
+
+ @Test
+ public void shouldExecuteSuccessfully() {
+ // given
+ when(exchange.getProperty(eq(TEST_KEY))).thenReturn(false);
+ when(exchange.getProperty(eq(MODEL_BPMN_KEY))).thenReturn(POLICY_ID_FROM_JSON);
+ when(exchange.getProperty(eq(MODEL_PROP_KEY))).thenReturn(ID_WITH_CHAIN_JSON);
+ when(exchange.getProperty(eq(EVENT_ACTION_KEY))).thenReturn(EVENT_ACTION_VALUE);
+
+ // when
+ operationalPolicyDeleteDelegate.execute(exchange);
+
+ // then
+ verify(policyClient, times(2)).deleteBrms(any(ModelProperties.class));
+ }
+
+ @Test
+ public void shouldExecuteTcaNotFound() {
+ // given
+ when(exchange.getProperty(eq(TEST_KEY))).thenReturn(true);
+ when(exchange.getProperty(eq(MODEL_BPMN_KEY))).thenReturn(POLICY_ID_FROM_JSON);
+ when(exchange.getProperty(eq(MODEL_PROP_KEY))).thenReturn(ID_NO_CHAIN_JSON);
+
+ // when
+ operationalPolicyDeleteDelegate.execute(exchange);
+
+ // then
+ verify(policyClient, never()).deleteBrms(any(ModelProperties.class));
+ }
+
+ @Test(expected = ModelBpmnException.class)
+ public void shouldThrowModelBpmnException() {
+ // given
+ when(exchange.getProperty(eq(TEST_KEY))).thenReturn(false);
+ when(exchange.getProperty(eq(MODEL_BPMN_KEY))).thenReturn(NOT_JSON);
+
+ // when
+ operationalPolicyDeleteDelegate.execute(exchange);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void shouldThrowNullPointerException() {
+ // when
+ operationalPolicyDeleteDelegate.execute(exchange);
+ }
+}
diff --git a/src/test/java/org/onap/clamp/clds/client/TcaPolicyDeleteDelegateTest.java b/src/test/java/org/onap/clamp/clds/client/TcaPolicyDeleteDelegateTest.java
new file mode 100644
index 00000000..70edabe6
--- /dev/null
+++ b/src/test/java/org/onap/clamp/clds/client/TcaPolicyDeleteDelegateTest.java
@@ -0,0 +1,103 @@
+/*-
+ * ============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 org.apache.camel.Exchange;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+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 TcaPolicyDeleteDelegateTest {
+
+ private static final String TCA_ID_FROM_JSON = "{\"tca\":[{\"id\":\"\",\"from\":\"\"}]}";
+ private static final String HOLMES_ID_FROM_JSON = "{\"holmes\":[{\"id\":\"\",\"from\":\"\"}]}";
+ private static final String ID_JSON = "{\"id\":\"\"}";
+ 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 TEST_KEY = "isTest";
+ private static final String PROPERTY_NAME = "tcaPolicyDeleteResponseMessage";
+ private static final String MESSAGE = "message";
+
+ @Mock
+ private Exchange camelExchange;
+
+ @Mock
+ private PolicyClient policyClient;
+
+ @InjectMocks
+ private TcaPolicyDeleteDelegate tcaPolicyDeleteDelegate;
+
+ @Test
+ public void shouldExecuteSuccessfully() {
+ //given
+ Mockito.when(camelExchange.getProperty(MODEL_BPMN_KEY)).thenReturn(TCA_ID_FROM_JSON);
+ Mockito.when(camelExchange.getProperty(MODEL_PROP_KEY)).thenReturn(ID_JSON);
+ Mockito.when(camelExchange.getProperty(TEST_KEY)).thenReturn(false);
+
+ Mockito.when(policyClient.deleteMicrosService(Mockito.any())).thenReturn(MESSAGE);
+
+ //when
+ tcaPolicyDeleteDelegate.execute(camelExchange);
+
+ //then
+ Mockito.verify(camelExchange).setProperty(PROPERTY_NAME, MESSAGE.getBytes());
+ }
+
+ @Test
+ public void shouldExecuteTcaNotFound() {
+ //given
+ Mockito.when(camelExchange.getProperty(MODEL_BPMN_KEY)).thenReturn(HOLMES_ID_FROM_JSON);
+ Mockito.when(camelExchange.getProperty(MODEL_PROP_KEY)).thenReturn(ID_JSON);
+ Mockito.when(camelExchange.getProperty(TEST_KEY)).thenReturn(false);
+
+ //when
+ tcaPolicyDeleteDelegate.execute(camelExchange);
+
+ //then
+ Mockito.verify(policyClient, Mockito.never()).deleteMicrosService(Mockito.any());
+ Mockito.verify(camelExchange, Mockito.never()).setProperty(Mockito.any(), Mockito.any());
+ }
+
+ @Test(expected = ModelBpmnException.class)
+ public void shouldThrowModelBpmnException() {
+ //given
+ Mockito.when(camelExchange.getProperty(MODEL_BPMN_KEY)).thenReturn(NOT_JSON);
+ Mockito.when(camelExchange.getProperty(TEST_KEY)).thenReturn(false);
+
+ //when
+ tcaPolicyDeleteDelegate.execute(camelExchange);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void shouldThrowNullPointerException() {
+ //when
+ tcaPolicyDeleteDelegate.execute(camelExchange);
+ }
+}
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 a32a6035..549c9132 100644
--- a/src/test/java/org/onap/clamp/clds/config/CldsUserJsonDecoderTest.java
+++ b/src/test/java/org/onap/clamp/clds/config/CldsUserJsonDecoderTest.java
@@ -5,6 +5,8 @@
* Copyright (C) 2017 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
@@ -25,10 +27,11 @@
package org.onap.clamp.clds.config;
import static org.assertj.core.api.Assertions.assertThat;
-
import org.junit.Test;
+import org.onap.clamp.clds.exception.CldsUsersException;
import org.onap.clamp.clds.service.CldsUser;
+
public class CldsUserJsonDecoderTest {
private String user1 = "admin1";
@@ -92,4 +95,12 @@ public class CldsUserJsonDecoderTest {
assertThat(user.getPassword()).isEqualTo(password);
assertThat(user.getPermissionsString()).isEqualTo(incompletePermissionsArray);
}
+
+ @Test(expected = CldsUsersException.class)
+ public void shouldThrowCldsUsersException() {
+ //when
+ CldsUserJsonDecoder
+ .decodeJson(this.getClass().getResourceAsStream("/clds/clds-parse-exception.json"));
+ }
+
}
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 5d891035..1dbea376 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 347de4a7..faeb0418 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 7d48086c..992c06e8 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/it/sdc/controller/installer/CsarInstallerItCase.java b/src/test/java/org/onap/clamp/clds/it/sdc/controller/installer/CsarInstallerItCase.java
index d3a823fb..e1b963cc 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
@@ -5,6 +5,8 @@
* Copyright (C) 2018 AT&T Intellectual Property. All rights
* reserved.
* ================================================================================
+ * Modifications copyright (c) 2019 Nokia
+ * ===================================================================
* 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
@@ -60,6 +62,7 @@ import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException;
import org.onap.sdc.toscaparser.api.elements.Metadata;
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.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
@@ -74,8 +77,11 @@ public class CsarInstallerItCase {
private static final String INVARIANT_RESOURCE2_UUID = "023a3f0d-1161-45ff-b4cf-8918a8ccf3ad";
private static final String RESOURCE_INSTANCE_NAME_RESOURCE1 = "ResourceInstanceName1";
private static final String RESOURCE_INSTANCE_NAME_RESOURCE2 = "ResourceInstanceName2";
+
@Autowired
+ @Qualifier("oldModelInstaller")
private CsarInstaller csarInstaller;
+
@Autowired
private CldsDao cldsDao;
@@ -173,10 +179,9 @@ public class CsarInstallerItCase {
ResourceFileUtil.getResourceAsStream("example/sdc/blueprint-dcae/prop-text-for-tca-2.json"),
StandardCharsets.UTF_8), 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"),
- StandardCharsets.UTF_8),
- cldsModel3.getPropText(), true);
+ JSONAssert.assertEquals(IOUtils.toString(
+ ResourceFileUtil.getResourceAsStream("example/sdc/blueprint-dcae/prop-text-for-tca-3.json"),
+ StandardCharsets.UTF_8), cldsModel3.getPropText(), true);
}
private CldsModel verifyClosedLoopModelLoadedInDb(CsarHandler csar, String artifactName)
diff --git a/src/test/java/org/onap/clamp/clds/sdc/controller/installer/BlueprintParserTest.java b/src/test/java/org/onap/clamp/clds/sdc/controller/installer/BlueprintParserTest.java
index e86fb27d..dec63977 100644
--- a/src/test/java/org/onap/clamp/clds/sdc/controller/installer/BlueprintParserTest.java
+++ b/src/test/java/org/onap/clamp/clds/sdc/controller/installer/BlueprintParserTest.java
@@ -142,18 +142,18 @@ public class BlueprintParserTest {
public void getNodeRepresentationFromCompleteYaml() {
final JsonObject jsonObject = jsonObjectBlueprintValid;
- MicroService expected = new MicroService(SECOND_APPP, MODEL_TYPE1, FIRST_APPP, "", SECOND_APPP);
+ MicroService expected = new MicroService(SECOND_APPP, MODEL_TYPE1, FIRST_APPP, "");
Entry<String, JsonElement> entry = jsonObject.entrySet().iterator().next();
- MicroService actual = new BlueprintParser().getNodeRepresentation(entry);
+ MicroService actual = new BlueprintParser().getNodeRepresentation(entry, jsonObject, null);
Assert.assertEquals(expected, actual);
}
@Test
public void getMicroServicesFromBlueprintTest() {
- MicroService thirdApp = new MicroService(THIRD_APPP, MODEL_TYPE3, "", "", THIRD_APPP);
- MicroService firstApp = new MicroService(FIRST_APPP, MODEL_TYPE1, THIRD_APPP, "", FIRST_APPP);
- MicroService secondApp = new MicroService(SECOND_APPP, MODEL_TYPE2, FIRST_APPP, "", SECOND_APPP);
+ MicroService thirdApp = new MicroService(THIRD_APPP, MODEL_TYPE3, "", "");
+ MicroService firstApp = new MicroService(FIRST_APPP, MODEL_TYPE1, THIRD_APPP, "");
+ MicroService secondApp = new MicroService(SECOND_APPP, MODEL_TYPE2, FIRST_APPP, "");
Set<MicroService> expected = new HashSet<>(Arrays.asList(firstApp, secondApp, thirdApp));
Set<MicroService> actual = new BlueprintParser().getMicroServices(microServiceTheWholeBlueprintValid);
@@ -163,7 +163,7 @@ public class BlueprintParserTest {
@Test
public void fallBackToOneMicroServiceTCATest() {
- MicroService tcaMS = new MicroService(BlueprintParser.TCA, "onap.policy.monitoring.cdap.tca.hi.lo.app", "", "",
+ MicroService tcaMS = new MicroService(BlueprintParser.TCA, "onap.policies.monitoring.cdap.tca.hi.lo.app", "",
"");
List<MicroService> expected = Collections.singletonList(tcaMS);
@@ -174,8 +174,8 @@ public class BlueprintParserTest {
@Test
public void fallBackToOneMicroServiceHolmesTest() {
- MicroService holmesMS = new MicroService(BlueprintParser.HOLMES, "onap.policy.monitoring.cdap.tca.hi.lo.app",
- "", "", "");
+ MicroService holmesMS = new MicroService(BlueprintParser.HOLMES, "onap.policies.monitoring.cdap.tca.hi.lo.app",
+ "", "");
List<MicroService> expected = Collections.singletonList(holmesMS);
List<MicroService> actual = new BlueprintParser()
diff --git a/src/test/java/org/onap/clamp/clds/sdc/controller/installer/ChainGeneratorTest.java b/src/test/java/org/onap/clamp/clds/sdc/controller/installer/ChainGeneratorTest.java
index 1eb66ead..4b41ee81 100644
--- a/src/test/java/org/onap/clamp/clds/sdc/controller/installer/ChainGeneratorTest.java
+++ b/src/test/java/org/onap/clamp/clds/sdc/controller/installer/ChainGeneratorTest.java
@@ -38,10 +38,10 @@ public class ChainGeneratorTest {
@Test
public void getChainOfMicroServicesTest() {
- MicroService ms1 = new MicroService(FIRST_APPP, "", "", "", "");
- MicroService ms2 = new MicroService(SECOND_APPP, "", FIRST_APPP, "", "");
- MicroService ms3 = new MicroService(THIRD_APPP, "", SECOND_APPP, "", "");
- MicroService ms4 = new MicroService(FOURTH_APPP, "", THIRD_APPP, "", "");
+ MicroService ms1 = new MicroService(FIRST_APPP, "", "", "");
+ MicroService ms2 = new MicroService(SECOND_APPP, "", FIRST_APPP, "");
+ MicroService ms3 = new MicroService(THIRD_APPP, "", SECOND_APPP, "");
+ MicroService ms4 = new MicroService(FOURTH_APPP, "", THIRD_APPP, "");
List<MicroService> expectedList = Arrays.asList(ms1, ms2, ms3, ms4);
Set<MicroService> inputSet = new HashSet<>(expectedList);
@@ -52,10 +52,10 @@ public class ChainGeneratorTest {
@Test
public void getChainOfMicroServicesTwiceNoInputTest() {
- MicroService ms1 = new MicroService(FIRST_APPP, "", "", "", "");
- MicroService ms2 = new MicroService(SECOND_APPP, "", "", "", "");
- MicroService ms3 = new MicroService(THIRD_APPP, "", SECOND_APPP, "", "");
- MicroService ms4 = new MicroService(FOURTH_APPP, "", FIRST_APPP, "", "");
+ MicroService ms1 = new MicroService(FIRST_APPP, "", "", "");
+ MicroService ms2 = new MicroService(SECOND_APPP, "", "", "");
+ MicroService ms3 = new MicroService(THIRD_APPP, "", SECOND_APPP, "");
+ MicroService ms4 = new MicroService(FOURTH_APPP, "", FIRST_APPP, "");
Set<MicroService> inputSet = new HashSet<>(Arrays.asList(ms1, ms2, ms3, ms4));
List<MicroService> actualList = new ChainGenerator().getChainOfMicroServices(inputSet);
@@ -64,10 +64,10 @@ public class ChainGeneratorTest {
@Test
public void getChainOfMicroServicesBranchingTest() {
- MicroService ms1 = new MicroService(FIRST_APPP, "", "", "", "");
- MicroService ms2 = new MicroService(SECOND_APPP, "", FIRST_APPP, "", "");
- MicroService ms3 = new MicroService(THIRD_APPP, "", FIRST_APPP, "", "");
- MicroService ms4 = new MicroService(FOURTH_APPP, "", FIRST_APPP, "", "");
+ MicroService ms1 = new MicroService(FIRST_APPP, "", "", "");
+ MicroService ms2 = new MicroService(SECOND_APPP, "", FIRST_APPP, "");
+ MicroService ms3 = new MicroService(THIRD_APPP, "", FIRST_APPP, "");
+ MicroService ms4 = new MicroService(FOURTH_APPP, "", FIRST_APPP, "");
Set<MicroService> inputSet = new HashSet<>(Arrays.asList(ms1, ms2, ms3, ms4));
List<MicroService> actualList = new ChainGenerator().getChainOfMicroServices(inputSet);
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/LoopCsarInstallerTest.java
index 17e27d51..e462455f 100644
--- a/src/test/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImplTest.java
+++ b/src/test/java/org/onap/clamp/clds/sdc/controller/installer/LoopCsarInstallerTest.java
@@ -53,7 +53,7 @@ import org.springframework.context.ApplicationContext;
import org.springframework.core.io.Resource;
@RunWith(MockitoJUnitRunner.class)
-public class CsarInstallerImplTest {
+public class LoopCsarInstallerTest {
@Mock
private CsarHandler csarHandler;
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 603d2d28..1e6742c9 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 82c2162a..d1adc166 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/ClampGraphBuilderTest.java b/src/test/java/org/onap/clamp/clds/util/drawing/ClampGraphBuilderTest.java
index f7d2fe76..ff6e1b5d 100644
--- a/src/test/java/org/onap/clamp/clds/util/drawing/ClampGraphBuilderTest.java
+++ b/src/test/java/org/onap/clamp/clds/util/drawing/ClampGraphBuilderTest.java
@@ -56,10 +56,10 @@ public class ClampGraphBuilderTest {
@Test
public void clampGraphBuilderCompleteChainTest() {
String collector = "VES";
- MicroService ms1 = new MicroService("ms1", "", "", "ms1_jpa_id", "");
- MicroService ms2 = new MicroService("ms2", "", "", "ms2_jpa_id", "");
- ;
- String policy = "Policy";
+ MicroService ms1 = new MicroService("ms1", "", "", "ms1_jpa_id");
+ MicroService ms2 = new MicroService("ms2", "", "", "ms2_jpa_id");
+
+ String policy = "OperationalPolicy";
List<MicroService> microServices = Arrays.asList(ms1, ms2);
ClampGraphBuilder clampGraphBuilder = new ClampGraphBuilder(mockPainter);
@@ -76,8 +76,8 @@ public class ClampGraphBuilderTest {
@Test(expected = InvalidStateException.class)
public void clampGraphBuilderNoPolicyGivenTest() {
String collector = "VES";
- MicroService ms1 = new MicroService("ms1", "", "", "ms1_jpa_id", "");
- MicroService ms2 = new MicroService("ms2", "", "", "ms2_jpa_id", "");
+ MicroService ms1 = new MicroService("ms1", "", "", "ms1_jpa_id");
+ MicroService ms2 = new MicroService("ms2", "", "", "ms2_jpa_id");
ClampGraphBuilder clampGraphBuilder = new ClampGraphBuilder(mockPainter);
clampGraphBuilder.collector(collector).addMicroService(ms1).addMicroService(ms2).build();
@@ -86,7 +86,7 @@ public class ClampGraphBuilderTest {
@Test(expected = InvalidStateException.class)
public void clampGraphBuilderNoMicroServiceGivenTest() {
String collector = "VES";
- String policy = "Policy";
+ String policy = "OperationalPolicy";
ClampGraphBuilder clampGraphBuilder = new ClampGraphBuilder(mockPainter);
clampGraphBuilder.collector(collector).policy(policy).build();
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 6546553c..63a1fa3e 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/flow/FlowLogOperationTest.java b/src/test/java/org/onap/clamp/flow/FlowLogOperationTest.java
new file mode 100644
index 00000000..16136ae2
--- /dev/null
+++ b/src/test/java/org/onap/clamp/flow/FlowLogOperationTest.java
@@ -0,0 +1,99 @@
+/*-
+ * ============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.flow;
+
+import static junit.framework.Assert.assertEquals;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.impl.DefaultExchange;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.onap.clamp.clds.util.LoggingUtils;
+import org.onap.clamp.clds.util.ONAPLogConstants;
+import org.onap.clamp.flow.log.FlowLogOperation;
+import org.slf4j.MDC;
+import org.slf4j.spi.MDCAdapter;
+import org.springframework.test.util.ReflectionTestUtils;
+
+public class FlowLogOperationTest {
+
+ private FlowLogOperation flowLogOperation = new FlowLogOperation();
+
+ @Test
+ public void testStratLog() {
+ //given
+ Exchange exchange = new DefaultExchange(mock(CamelContext.class));
+ LoggingUtils loggingUtils = mock(LoggingUtils.class);
+ ReflectionTestUtils.setField(flowLogOperation, "util", loggingUtils);
+
+ //when
+ Mockito.when(loggingUtils.getProperties(ONAPLogConstants.MDCs.REQUEST_ID)).thenReturn("MockRequestId");
+ Mockito.when(loggingUtils.getProperties(ONAPLogConstants.MDCs.INVOCATION_ID)).thenReturn("MockInvocationId");
+ Mockito.when(loggingUtils.getProperties(ONAPLogConstants.MDCs.PARTNER_NAME)).thenReturn("MockPartnerName");
+ flowLogOperation.startLog(exchange, "serviceName");
+
+ //then
+ assertThat(exchange.getProperty(ONAPLogConstants.Headers.REQUEST_ID)).isEqualTo("MockRequestId");
+ assertThat(exchange.getProperty(ONAPLogConstants.Headers.INVOCATION_ID)).isEqualTo("MockInvocationId");
+ assertThat(exchange.getProperty(ONAPLogConstants.Headers.PARTNER_NAME)).isEqualTo("MockPartnerName");
+ }
+
+ @Test
+ public void testInvokeLog() {
+ //given
+ final String mockEntity = "mockEntity";
+ final String mockServiceName = "mockSerivceName";
+ MDCAdapter mdcAdapter = MDC.getMDCAdapter();
+ //when
+ flowLogOperation.invokeLog(mockEntity, mockServiceName);
+ //then
+ String entity = mdcAdapter.get(ONAPLogConstants.MDCs.TARGET_ENTITY);
+ String serviceName = mdcAdapter.get(ONAPLogConstants.MDCs.TARGET_SERVICE_NAME);
+ assertEquals(entity,mockEntity);
+ assertEquals(serviceName,mockServiceName);
+ }
+
+ @Test
+ public void testEndLog() {
+ //given
+ MDC.put(ONAPLogConstants.MDCs.ENTRY_TIMESTAMP, "2019-05-19T00:00:00.007Z");
+ MDCAdapter mdcAdapter = MDC.getMDCAdapter();
+ ///when
+ flowLogOperation.endLog();
+ //then
+ assertThat(mdcAdapter.get(ONAPLogConstants.MDCs.ENTRY_TIMESTAMP)).isNull();
+ }
+
+ @Test
+ public void testErrorLog() {
+ //given
+ MDC.put(ONAPLogConstants.MDCs.ENTRY_TIMESTAMP, "2019-05-19T00:00:00.007Z");
+ MDCAdapter mdcAdapter = MDC.getMDCAdapter();
+ //when
+ flowLogOperation.errorLog();
+ //then
+ assertThat(mdcAdapter.get(ONAPLogConstants.MDCs.ENTRY_TIMESTAMP)).isNull();
+ }
+} \ No newline at end of file
diff --git a/src/test/java/org/onap/clamp/loop/CsarInstallerItCase.java b/src/test/java/org/onap/clamp/loop/CsarInstallerItCase.java
index 0cadef9a..ed912831 100644
--- a/src/test/java/org/onap/clamp/loop/CsarInstallerItCase.java
+++ b/src/test/java/org/onap/clamp/loop/CsarInstallerItCase.java
@@ -5,6 +5,9 @@
* Copyright (C) 2019 AT&T Intellectual Property. All rights
* 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
@@ -24,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;
@@ -47,7 +51,9 @@ import org.onap.clamp.clds.exception.sdc.controller.SdcArtifactInstallerExceptio
import org.onap.clamp.clds.sdc.controller.installer.BlueprintArtifact;
import org.onap.clamp.clds.sdc.controller.installer.CsarHandler;
import org.onap.clamp.clds.sdc.controller.installer.CsarInstaller;
+import org.onap.clamp.clds.util.JsonUtils;
import org.onap.clamp.clds.util.ResourceFileUtil;
+import org.onap.clamp.policy.microservice.MicroServicePolicy;
import org.onap.sdc.api.notification.IArtifactInfo;
import org.onap.sdc.api.notification.INotificationData;
import org.onap.sdc.api.notification.IResourceInstance;
@@ -55,9 +61,10 @@ import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException;
import org.onap.sdc.tosca.parser.impl.SdcToscaParserFactory;
import org.onap.sdc.toscaparser.api.elements.Metadata;
+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;
@@ -66,7 +73,7 @@ import org.springframework.test.context.junit4.SpringRunner;
@ActiveProfiles(profiles = "clamp-default,clamp-default-user,clamp-sdc-controller-new")
public class CsarInstallerItCase {
- private static final String CSAR_ARTIFACT_NAME = "example/sdc/service-Vloadbalancerms-csar.csar";
+ private static final String CSAR_ARTIFACT_NAME = "example/sdc/service_Vloadbalancerms_csar.csar";
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";
@@ -77,6 +84,7 @@ public class CsarInstallerItCase {
private LoopsRepository loopsRepo;
@Autowired
+ @Qualifier("loopInstaller")
private CsarInstaller csarInstaller;
private BlueprintArtifact buildFakeBuildprintArtifact(String instanceName, String invariantResourceUuid,
@@ -133,8 +141,7 @@ public class CsarInstallerItCase {
// set
SdcToscaParserFactory factory = SdcToscaParserFactory.getInstance();
String path = Thread.currentThread().getContextClassLoader().getResource(CSAR_ARTIFACT_NAME).getFile();
- ISdcCsarHelper sdcHelper = factory
- .getSdcCsarHelper(path);
+ ISdcCsarHelper sdcHelper = factory.getSdcCsarHelper(path);
Mockito.when(csarHandler.getSdcCsarHelper()).thenReturn(sdcHelper);
// Mockito.when(csarHandler.getSdcCsarHelper()).thenReturn(csarHelper);
@@ -154,11 +161,11 @@ public class CsarInstallerItCase {
Mockito.when(notificationData.getServiceArtifacts()).thenReturn(serviceArtifactsList);
CsarHandler csarHandler = new CsarHandler(notificationData, "", "");
- csarHandler.setFilePath(Thread.currentThread().getContextClassLoader()
- .getResource(CSAR_ARTIFACT_NAME).getFile());
+ csarHandler
+ .setFilePath(Thread.currentThread().getContextClassLoader().getResource(CSAR_ARTIFACT_NAME).getFile());
Optional<String> testyaml = csarHandler.getPolicyModelYaml();
- Assert.assertEquals(testyaml, Optional.ofNullable(ResourceFileUtil
- .getResourceAsString("example/sdc/expected-result/policy-data.yaml")));
+ Assert.assertEquals(testyaml,
+ Optional.ofNullable(ResourceFileUtil.getResourceAsString("example/sdc/expected-result/policy-data.yaml")));
}
@Test
@@ -174,6 +181,7 @@ public class CsarInstallerItCase {
@Test
@Transactional
+ @Rollback(value = false)
public void testInstallTheCsarTca() throws SdcArtifactInstallerException, SdcToscaParserException,
CsarHandlerException, IOException, JSONException, InterruptedException, PolicyModelException {
String generatedName = RandomStringUtils.randomAlphanumeric(5);
@@ -198,6 +206,27 @@ public class CsarInstallerItCase {
assertThat(loop.getOperationalPolicies()).hasSize(1);
assertThat(loop.getModelPropertiesJson().get("serviceDetails")).isNotNull();
assertThat(loop.getModelPropertiesJson().get("resourceDetails")).isNotNull();
+ JSONAssert.assertEquals(ResourceFileUtil.getResourceAsString("tosca/model-properties.json"),
+ JsonUtils.GSON.toJson(loop.getModelPropertiesJson()), true);
+ assertThat(((MicroServicePolicy) (loop.getMicroServicePolicies().toArray()[0])).getModelType()).isNotEmpty();
+
+ loop = loopsRepo
+ .findById(Loop.generateLoopName(generatedName, "1.0", RESOURCE_INSTANCE_NAME_RESOURCE1, "tca_3.yaml"))
+ .get();
+ assertThat(((MicroServicePolicy) (loop.getMicroServicePolicies().toArray()[0])).getModelType()).isNotEmpty();
+
+ loop = loopsRepo
+ .findById(Loop.generateLoopName(generatedName, "1.0", RESOURCE_INSTANCE_NAME_RESOURCE2, "tca_2.yaml"))
+ .get();
+ 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/loop/LoopOperationTestItCase.java b/src/test/java/org/onap/clamp/loop/LoopOperationTestItCase.java
new file mode 100644
index 00000000..a2c97e0c
--- /dev/null
+++ b/src/test/java/org/onap/clamp/loop/LoopOperationTestItCase.java
@@ -0,0 +1,244 @@
+/*-
+ * ============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.loop;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonObject;
+
+import java.io.IOException;
+import java.util.HashSet;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.json.simple.parser.ParseException;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.onap.clamp.clds.Application;
+import org.onap.clamp.loop.LoopOperation.TempLoopState;
+import org.onap.clamp.policy.microservice.MicroServicePolicy;
+import org.onap.clamp.policy.operational.OperationalPolicy;
+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(classes = Application.class)
+public class LoopOperationTestItCase {
+
+ private Gson gson = new GsonBuilder().setPrettyPrinting().excludeFieldsWithoutExposeAnnotation().create();
+ @Autowired
+ LoopService loopService;
+
+ private Loop createTestLoop() {
+ String yaml = "imports:\n" + " - \"http://www.getcloudify.org/spec/cloudify/3.4/types.yaml\"\n"
+ + "node_templates:\n" + " docker_service_host:\n" + " type: dcae.nodes.SelectedDockerHost";
+
+ Loop loopTest = new Loop("ControlLoopTest", yaml, "<xml></xml>");
+ loopTest.setGlobalPropertiesJson(
+ new Gson().fromJson("{\"dcaeDeployParameters\":" + "{\"policy_id\": \"name\"}}", JsonObject.class));
+ loopTest.setLastComputedState(LoopState.DESIGN);
+ loopTest.setDcaeDeploymentId("123456789");
+ loopTest.setDcaeDeploymentStatusUrl("http4://localhost:8085");
+ loopTest.setDcaeBlueprintId("UUID-blueprint");
+
+ MicroServicePolicy microServicePolicy = new MicroServicePolicy("configPolicyTest", "",
+ "tosca_definitions_version: tosca_simple_yaml_1_0_0", true,
+ gson.fromJson("{\"configtype\":\"json\"}", JsonObject.class), new HashSet<>());
+ microServicePolicy.setProperties(new Gson().fromJson("{\"param1\":\"value1\"}", JsonObject.class));
+
+ loopTest.addMicroServicePolicy(microServicePolicy);
+ return loopTest;
+ }
+
+ @Test
+ public void testAnalysePolicyResponse() {
+ LoopOperation loopOp = new LoopOperation(loopService);
+ String status1 = loopOp.analysePolicyResponse(200);
+ String status2 = loopOp.analysePolicyResponse(404);
+ String status3 = loopOp.analysePolicyResponse(500);
+ String status4 = loopOp.analysePolicyResponse(503);
+
+ // then
+ assertThat(status1).isEqualTo("SUBMITTED");
+ assertThat(status2).isEqualTo("NOT_SUBMITTED");
+ assertThat(status3).isEqualTo("IN_ERROR");
+ assertThat(status4).isEqualTo("IN_ERROR");
+ }
+
+ @Test
+ public void testGetOperationalPolicyName() {
+ LoopOperation loopOp = new LoopOperation(loopService);
+ Loop loop = this.createTestLoop();
+ String opName1 = loopOp.getOperationalPolicyName(loop);
+ assertThat(opName1).isNull();
+
+ OperationalPolicy opPolicy1 = new OperationalPolicy("OperationalPolicyTest1", null,
+ gson.fromJson("{\"type\":\"Operational\"}", JsonObject.class));
+ loop.addOperationalPolicy(opPolicy1);
+ String opName2 = loopOp.getOperationalPolicyName(loop);
+ assertThat(opName2).isEqualTo("OperationalPolicyTest1");
+ }
+
+ @Test
+ public void testAnalyseDcaeResponse() throws ParseException {
+ LoopOperation loopOp = new LoopOperation(loopService);
+ String dcaeStatus1 = loopOp.analyseDcaeResponse(null, null);
+ assertThat(dcaeStatus1).isEqualTo("NOT_DEPLOYED");
+
+ String dcaeStatus2 = loopOp.analyseDcaeResponse(null, 500);
+ assertThat(dcaeStatus2).isEqualTo("IN_ERROR");
+
+ String dcaeStatus3 = loopOp.analyseDcaeResponse(null, 404);
+ assertThat(dcaeStatus3).isEqualTo("NOT_DEPLOYED");
+
+ Exchange camelExchange = Mockito.mock(Exchange.class);
+ Message mockMessage = Mockito.mock(Message.class);
+ Mockito.when(camelExchange.getIn()).thenReturn(mockMessage);
+ Mockito.when(mockMessage.getBody(String.class))
+ .thenReturn("{\"operationType\":\"install\",\"status\":\"succeeded\"}");
+ String dcaeStatus4 = loopOp.analyseDcaeResponse(camelExchange, 200);
+ assertThat(dcaeStatus4).isEqualTo("DEPLOYED");
+
+ Mockito.when(mockMessage.getBody(String.class))
+ .thenReturn("{\"operationType\":\"install\",\"status\":\"processing\"}");
+ String dcaeStatus5 = loopOp.analyseDcaeResponse(camelExchange, 200);
+ assertThat(dcaeStatus5).isEqualTo("PROCESSING");
+
+ Mockito.when(mockMessage.getBody(String.class))
+ .thenReturn("{\"operationType\":\"install\",\"status\":\"failed\"}");
+ String dcaeStatus6 = loopOp.analyseDcaeResponse(camelExchange, 200);
+ assertThat(dcaeStatus6).isEqualTo("IN_ERROR");
+
+ Mockito.when(mockMessage.getBody(String.class))
+ .thenReturn("{\"operationType\":\"uninstall\",\"status\":\"succeeded\"}");
+ String dcaeStatus7 = loopOp.analyseDcaeResponse(camelExchange, 200);
+ assertThat(dcaeStatus7).isEqualTo("NOT_DEPLOYED");
+
+ Mockito.when(mockMessage.getBody(String.class))
+ .thenReturn("{\"operationType\":\"uninstall\",\"status\":\"processing\"}");
+ String dcaeStatus8 = loopOp.analyseDcaeResponse(camelExchange, 200);
+ assertThat(dcaeStatus8).isEqualTo("PROCESSING");
+
+ Mockito.when(mockMessage.getBody(String.class))
+ .thenReturn("{\"operationType\":\"uninstall\",\"status\":\"failed\"}");
+ String dcaeStatus9 = loopOp.analyseDcaeResponse(camelExchange, 200);
+ assertThat(dcaeStatus9).isEqualTo("IN_ERROR");
+ }
+
+ @Test
+ public void testUpdateLoopStatus() {
+ LoopOperation loopOp = new LoopOperation(loopService);
+ Loop loop = this.createTestLoop();
+ loopService.saveOrUpdateLoop(loop);
+ LoopState newState1 = loopOp.updateLoopStatus(loop, TempLoopState.SUBMITTED, TempLoopState.DEPLOYED);
+ LoopState dbState1 = loopService.getLoop(loop.getName()).getLastComputedState();
+ assertThat(newState1).isEqualTo(LoopState.DEPLOYED);
+ assertThat(dbState1).isEqualTo(LoopState.DEPLOYED);
+
+ LoopState newState2 = loopOp.updateLoopStatus(loop, TempLoopState.SUBMITTED, TempLoopState.NOT_DEPLOYED);
+ LoopState dbState2 = loopService.getLoop(loop.getName()).getLastComputedState();
+ assertThat(newState2).isEqualTo(LoopState.SUBMITTED);
+ assertThat(dbState2).isEqualTo(LoopState.SUBMITTED);
+
+ LoopState newState3 = loopOp.updateLoopStatus(loop, TempLoopState.SUBMITTED, TempLoopState.PROCESSING);
+ assertThat(newState3).isEqualTo(LoopState.WAITING);
+
+ LoopState newState4 = loopOp.updateLoopStatus(loop, TempLoopState.SUBMITTED, TempLoopState.IN_ERROR);
+ assertThat(newState4).isEqualTo(LoopState.IN_ERROR);
+
+ LoopState newState5 = loopOp.updateLoopStatus(loop, TempLoopState.NOT_SUBMITTED, TempLoopState.DEPLOYED);
+ assertThat(newState5).isEqualTo(LoopState.IN_ERROR);
+
+ LoopState newState6 = loopOp.updateLoopStatus(loop, TempLoopState.NOT_SUBMITTED, TempLoopState.PROCESSING);
+ assertThat(newState6).isEqualTo(LoopState.IN_ERROR);
+
+ LoopState newState7 = loopOp.updateLoopStatus(loop, TempLoopState.NOT_SUBMITTED, TempLoopState.NOT_DEPLOYED);
+ assertThat(newState7).isEqualTo(LoopState.DESIGN);
+
+ LoopState newState8 = loopOp.updateLoopStatus(loop, TempLoopState.IN_ERROR, TempLoopState.DEPLOYED);
+ assertThat(newState8).isEqualTo(LoopState.IN_ERROR);
+
+ LoopState newState9 = loopOp.updateLoopStatus(loop, TempLoopState.IN_ERROR, TempLoopState.NOT_DEPLOYED);
+ assertThat(newState9).isEqualTo(LoopState.IN_ERROR);
+
+ LoopState newState10 = loopOp.updateLoopStatus(loop, TempLoopState.IN_ERROR, TempLoopState.PROCESSING);
+ assertThat(newState10).isEqualTo(LoopState.IN_ERROR);
+
+ LoopState newState11 = loopOp.updateLoopStatus(loop, TempLoopState.IN_ERROR, TempLoopState.IN_ERROR);
+ assertThat(newState11).isEqualTo(LoopState.IN_ERROR);
+ }
+
+ @Test
+ public void testUpdateLoopInfo() throws ParseException {
+ Loop loop = this.createTestLoop();
+ loopService.saveOrUpdateLoop(loop);
+
+ Exchange camelExchange = Mockito.mock(Exchange.class);
+ Message mockMessage = Mockito.mock(Message.class);
+ Mockito.when(camelExchange.getIn()).thenReturn(mockMessage);
+ Mockito.when(mockMessage.getBody(String.class))
+ .thenReturn("{\"links\":{\"status\":\"http://testhost/dcae-operationstatus\",\"test2\":\"test2\"}}");
+
+ LoopOperation loopOp = new LoopOperation(loopService);
+ loopOp.updateLoopInfo(camelExchange, loop, "testNewId");
+
+ Loop newLoop = loopService.getLoop(loop.getName());
+ String newDeployId = newLoop.getDcaeDeploymentId();
+ String newDeploymentStatusUrl = newLoop.getDcaeDeploymentStatusUrl();
+
+ assertThat(newDeployId).isEqualTo("testNewId");
+ assertThat(newDeploymentStatusUrl).isEqualTo("http4://testhost/dcae-operationstatus");
+ }
+
+ @Test
+ public void testGetDeploymentId() {
+ Loop loop = this.createTestLoop();
+ LoopOperation loopOp = new LoopOperation(loopService);
+ String deploymentId1 = loopOp.getDeploymentId(loop);
+ assertThat(deploymentId1).isEqualTo("123456789");
+
+ loop.setDcaeDeploymentId(null);
+ String deploymentId2 = loopOp.getDeploymentId(loop);
+ assertThat(deploymentId2).startsWith("CLAMP_");
+
+ loop.setDcaeDeploymentId("");
+ String deploymentId3 = loopOp.getDeploymentId(loop);
+ assertThat(deploymentId3).startsWith("CLAMP_");
+ assertThat(deploymentId3).isNotEqualTo(deploymentId2);
+ }
+
+ @Test
+ public void testGetDeployPayload() throws IOException {
+ Loop loop = this.createTestLoop();
+ LoopOperation loopOp = new LoopOperation(loopService);
+ String deploymentPayload = loopOp.getDeployPayload(loop);
+
+ String expectedPayload = "{\"serviceTypeId\":\"UUID-blueprint\",\"inputs\":{\"policy_id\":\"name\"}}";
+ assertThat(deploymentPayload).isEqualTo(expectedPayload);
+ }
+} \ No newline at end of file
diff --git a/src/test/java/org/onap/clamp/policy/microservice/MicroServicePayloadTest.java b/src/test/java/org/onap/clamp/policy/microservice/MicroServicePayloadTest.java
index c511f341..68925a91 100644
--- a/src/test/java/org/onap/clamp/policy/microservice/MicroServicePayloadTest.java
+++ b/src/test/java/org/onap/clamp/policy/microservice/MicroServicePayloadTest.java
@@ -37,7 +37,7 @@ public class MicroServicePayloadTest {
@Test
public void testPayloadConstruction() throws IOException {
- MicroServicePolicy policy = new MicroServicePolicy("testPolicy", "onap.policy.monitoring.cdap.tca.hi.lo.app",
+ MicroServicePolicy policy = new MicroServicePolicy("testPolicy", "onap.policies.monitoring.cdap.tca.hi.lo.app",
ResourceFileUtil.getResourceAsString("tosca/tosca_example.yaml"), false, new HashSet<>());
policy.setProperties(JsonUtils.GSON.fromJson(
ResourceFileUtil.getResourceAsString("tosca/micro-service-policy-properties.json"), JsonObject.class));
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 76e29c31..8972e511 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,8 +44,20 @@ 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.createPolicyPayload())
+
+ 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