summaryrefslogtreecommitdiffstats
path: root/src/test/java/org
diff options
context:
space:
mode:
authorsebdet <sebastien.determe@intl.att.com>2020-02-28 06:03:51 -0800
committersebdet <sebastien.determe@intl.att.com>2020-03-04 12:45:52 -0800
commit897a3e004a858ef68d989dad15dde91a69e151a5 (patch)
treef341b17cbc3a234b4b011bcf7cb7cc11ba99b0ea /src/test/java/org
parentf0e00e7c9ea8dd15a4aacdd880aa648539caf087 (diff)
Change json representation in op policy
Change the json generation for an operational policy instance and update all emulator response for all policy types Issue-ID: CLAMP-653 Change-Id: I68525be3d5bfbf5dd7a4bcf6d59853df07fd4dd9 Signed-off-by: sebdet <sebastien.determe@intl.att.com>
Diffstat (limited to 'src/test/java/org')
-rw-r--r--src/test/java/org/onap/clamp/clds/it/config/CldsReferencePropertiesItCase.java48
-rw-r--r--src/test/java/org/onap/clamp/loop/CsarInstallerItCase.java12
-rw-r--r--src/test/java/org/onap/clamp/loop/LoopRepositoriesItCase.java13
-rw-r--r--src/test/java/org/onap/clamp/loop/LoopToJsonTest.java4
-rw-r--r--src/test/java/org/onap/clamp/loop/PolicyComponentTest.java76
-rw-r--r--src/test/java/org/onap/clamp/loop/PolicyModelServiceItCase.java4
-rw-r--r--src/test/java/org/onap/clamp/policy/downloader/PolicyEngineControllerTestItCase.java9
-rw-r--r--src/test/java/org/onap/clamp/policy/microservice/OperationalPolicyPayloadTest.java6
8 files changed, 75 insertions, 97 deletions
diff --git a/src/test/java/org/onap/clamp/clds/it/config/CldsReferencePropertiesItCase.java b/src/test/java/org/onap/clamp/clds/it/config/CldsReferencePropertiesItCase.java
index c25415ecc..4bf2de030 100644
--- a/src/test/java/org/onap/clamp/clds/it/config/CldsReferencePropertiesItCase.java
+++ b/src/test/java/org/onap/clamp/clds/it/config/CldsReferencePropertiesItCase.java
@@ -24,17 +24,11 @@
package org.onap.clamp.clds.it.config;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
-import com.google.gson.JsonElement;
-
import java.io.IOException;
-
import org.junit.Test;
import org.junit.runner.RunWith;
import org.onap.clamp.clds.config.ClampProperties;
+import org.onap.clamp.clds.util.ResourceFileUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@@ -57,37 +51,6 @@ public class CldsReferencePropertiesItCase {
assertEquals("healthcheck", refProp.getStringValue("policy.api.userName"));
}
- @Test
- public void shouldReturnJsonFromTemplate() throws IOException {
- // when
- JsonElement root = refProp.getJsonTemplate("ui.location.default");
-
- // then
- assertNotNull(root);
- assertTrue(root.isJsonObject());
- assertEquals("Data Center 1", root.getAsJsonObject().get("DC1").getAsString());
- }
-
- @Test
- public void shouldReturnJsonFromTemplate_2() throws IOException {
- // when
- JsonElement root = refProp.getJsonTemplate("ui.location", "default");
-
- // then
- assertNotNull(root);
- assertTrue(root.isJsonObject());
- assertEquals("Data Center 1", root.getAsJsonObject().get("DC1").getAsString());
- }
-
- @Test
- public void shouldReturnNullIfPropertyNotFound() throws IOException {
- // when
- JsonElement root = refProp.getJsonTemplate("ui.location", "");
-
- // then
- assertNull(root);
- }
-
/**
* Test getting prop value as a JSON Node / template.
*
@@ -95,12 +58,9 @@ public class CldsReferencePropertiesItCase {
*/
@Test
public void testGetFileContent() throws IOException {
- String location = "{\n\t\"DC1\": \"Data Center 1\","
- + "\n\t\"DC2\": \"Data Center 2\",\n\t\"DC3\": \"Data Center 3\"\n}\n";
- String content = refProp.getFileContent("ui.location.default");
- assertEquals(location, content);
+ String users = ResourceFileUtil.getResourceAsString("clds/clds-users.json");
+ assertEquals(users, refProp.getFileContent("files.cldsUsers"));
// Test composite key
- content = refProp.getFileContent("ui.location", "default");
- assertEquals(location, content);
+ assertEquals(users, refProp.getFileContent("files", "cldsUsers"));
}
}
diff --git a/src/test/java/org/onap/clamp/loop/CsarInstallerItCase.java b/src/test/java/org/onap/clamp/loop/CsarInstallerItCase.java
index a1499f720..fd215dd39 100644
--- a/src/test/java/org/onap/clamp/loop/CsarInstallerItCase.java
+++ b/src/test/java/org/onap/clamp/loop/CsarInstallerItCase.java
@@ -34,9 +34,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
-
import javax.transaction.Transactional;
-
import org.apache.commons.lang3.RandomStringUtils;
import org.json.JSONException;
import org.junit.Assert;
@@ -44,6 +42,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.onap.clamp.clds.Application;
+import org.onap.clamp.clds.config.LegacyOperationalPolicy;
import org.onap.clamp.clds.exception.sdc.controller.BlueprintParserException;
import org.onap.clamp.clds.exception.sdc.controller.CsarHandlerException;
import org.onap.clamp.clds.exception.sdc.controller.SdcArtifactInstallerException;
@@ -74,7 +73,7 @@ import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class)
-@ActiveProfiles(profiles = "clamp-default,clamp-default-user,clamp-sdc-controller")
+@ActiveProfiles(profiles = "clamp-default,clamp-default-user,clamp-sdc-controller,legacy-operational-policy")
public class CsarInstallerItCase {
private static final String CSAR_ARTIFACT_NAME = "example/sdc/service_Vloadbalancerms_csar.csar";
@@ -162,6 +161,13 @@ public class CsarInstallerItCase {
@Test
@Transactional
+ public void testPolicyModelAddedAtStartup() {
+ assertThat(policyModelsRepository.findByPolicyModelType(
+ LegacyOperationalPolicy.OPERATIONAL_POLICY_LEGACY).get(0)).isNotNull();
+ }
+
+ @Test
+ @Transactional
public void testGetPolicyModelYaml() throws IOException, SdcToscaParserException, CsarHandlerException {
INotificationData notificationData = Mockito.mock(INotificationData.class);
IArtifactInfo serviceArtifacts = Mockito.mock(IArtifactInfo.class);
diff --git a/src/test/java/org/onap/clamp/loop/LoopRepositoriesItCase.java b/src/test/java/org/onap/clamp/loop/LoopRepositoriesItCase.java
index 47b4b65c3..164625fef 100644
--- a/src/test/java/org/onap/clamp/loop/LoopRepositoriesItCase.java
+++ b/src/test/java/org/onap/clamp/loop/LoopRepositoriesItCase.java
@@ -90,7 +90,8 @@ public class LoopRepositoriesItCase {
}
private OperationalPolicy getOperationalPolicy(String configJson, String name, PolicyModel policyModel) {
- return new OperationalPolicy(name, null, new Gson().fromJson(configJson, JsonObject.class), policyModel, null, null, null);
+ return new OperationalPolicy(name, null, new Gson().fromJson(configJson, JsonObject.class), policyModel,
+ null, null, null);
}
private LoopElementModel getLoopElementModel(String yaml, String name, String policyType, String createdBy,
@@ -105,11 +106,13 @@ public class LoopRepositoriesItCase {
return new PolicyModel(policyType, policyModelTosca, version, policyAcronym);
}
- private LoopTemplate getLoopTemplate(String name, String blueprint, String svgRepresentation, String createdBy,
- Integer maxInstancesAllowed) {
+ private LoopTemplate getLoopTemplates(String name, String blueprint, String svgRepresentation, String createdBy,
+ Integer maxInstancesAllowed) {
LoopTemplate template = new LoopTemplate(name, blueprint, svgRepresentation, maxInstancesAllowed, null);
template.addLoopElementModel(getLoopElementModel("yaml", "microService1", "org.onap.policy.drools", createdBy,
getPolicyModel("org.onap.policy.drools", "yaml", "1.0.0", "Drools")));
+ template.addLoopElementModel(getLoopElementModel("yaml", "oppolicy1", "org.onap.policy.drools.legacy",
+ createdBy, getPolicyModel("org.onap.policy.drools.legacy", "yaml", "1.0.0", "DroolsLegacy")));
loopTemplateRepository.save(template);
return template;
}
@@ -123,7 +126,7 @@ public class LoopRepositoriesItCase {
loop.setLastComputedState(LoopState.DESIGN);
loop.setDcaeDeploymentId(dcaeId);
loop.setDcaeDeploymentStatusUrl(dcaeUrl);
- loop.setLoopTemplate(getLoopTemplate("templateName", "yaml", "svg", "toto", 1));
+ loop.setLoopTemplate(getLoopTemplates("templateName", "yaml", "svg", "toto", 1));
return loop;
}
@@ -149,7 +152,7 @@ public class LoopRepositoriesItCase {
Loop loopTest = getLoop("ControlLoopTest", "<xml></xml>", "yamlcontent", "{\"testname\":\"testvalue\"}",
"123456789", "https://dcaetest.org", "UUID-blueprint");
OperationalPolicy opPolicy = this.getOperationalPolicy("{\"type\":\"GUARD\"}", "GuardOpPolicyTest",
- getPolicyModel("org.onap.policy.drools", "yaml", "1.0.0", "Drools"));
+ getPolicyModel("org.onap.policy.drools.legacy", "yaml", "1.0.0", "DroolsLegacy"));
loopTest.addOperationalPolicy(opPolicy);
MicroServicePolicy microServicePolicy = getMicroServicePolicy("configPolicyTest", "{\"configtype\":\"json\"}",
"{\"param1\":\"value1\"}", true, getPolicyModel("org.onap.policy.drools", "yaml", "1.0.0", "Drools"));
diff --git a/src/test/java/org/onap/clamp/loop/LoopToJsonTest.java b/src/test/java/org/onap/clamp/loop/LoopToJsonTest.java
index de2ef145a..6c7836e50 100644
--- a/src/test/java/org/onap/clamp/loop/LoopToJsonTest.java
+++ b/src/test/java/org/onap/clamp/loop/LoopToJsonTest.java
@@ -37,6 +37,7 @@ import java.util.Random;
import org.junit.Test;
import org.onap.clamp.clds.util.JsonUtils;
import org.onap.clamp.clds.util.ResourceFileUtil;
+import org.onap.clamp.loop.components.external.PolicyComponent;
import org.onap.clamp.loop.log.LogType;
import org.onap.clamp.loop.log.LoopLog;
import org.onap.clamp.loop.service.Service;
@@ -45,6 +46,7 @@ import org.onap.clamp.loop.template.LoopTemplate;
import org.onap.clamp.loop.template.PolicyModel;
import org.onap.clamp.policy.microservice.MicroServicePolicy;
import org.onap.clamp.policy.operational.OperationalPolicy;
+import org.skyscreamer.jsonassert.JSONAssert;
public class LoopToJsonTest {
@@ -52,7 +54,7 @@ public class LoopToJsonTest {
private OperationalPolicy getOperationalPolicy(String configJson, String name) {
return new OperationalPolicy(name, null, gson.fromJson(configJson, JsonObject.class),
- getPolicyModel("org.onap.policy.drools", "yaml", "1.0.0", "Drools", "type1"), null, null, null);
+ getPolicyModel("org.onap.policy.drools.legacy", "yaml", "1.0.0", "Drools", "type1"), null,null,null);
}
private Loop getLoop(String name, String svgRepresentation, String blueprint, String globalPropertiesJson,
diff --git a/src/test/java/org/onap/clamp/loop/PolicyComponentTest.java b/src/test/java/org/onap/clamp/loop/PolicyComponentTest.java
index 370c319b3..89d3e6172 100644
--- a/src/test/java/org/onap/clamp/loop/PolicyComponentTest.java
+++ b/src/test/java/org/onap/clamp/loop/PolicyComponentTest.java
@@ -24,9 +24,9 @@
package org.onap.clamp.loop;
import static org.assertj.core.api.Assertions.assertThat;
+
import com.google.gson.Gson;
import com.google.gson.JsonObject;
-
import java.io.IOException;
import java.util.HashSet;
import org.apache.camel.Exchange;
@@ -44,13 +44,13 @@ import org.onap.clamp.policy.operational.OperationalPolicy;
public class PolicyComponentTest {
/**
- * Test the computeState method.
- * oldState newState expectedFinalState
- * NOT_SENT SENT_AND_DEPLOYED NOT_SENT
- * NOT_SENT SENT NOT_SENT
- * NOT_SENT NOT_SENT NOT_SENT
- * NOT_SENT IN_ERROR IN_ERROR
- */
+ * Test the computeState method.
+ * oldState newState expectedFinalState
+ * NOT_SENT SENT_AND_DEPLOYED NOT_SENT
+ * NOT_SENT SENT NOT_SENT
+ * NOT_SENT NOT_SENT NOT_SENT
+ * NOT_SENT IN_ERROR IN_ERROR
+ */
@Test
public void computeStateTestOriginalStateUnknown() {
Exchange exchange = Mockito.mock(Exchange.class);
@@ -81,14 +81,15 @@ public class PolicyComponentTest {
ExternalComponentState state3 = policy.computeState(exchange);
assertThat(state3.getStateName()).isEqualTo("IN_ERROR");
}
+
/**
- * Test the computeState method.
- * oldState newState expectedFinalState
- * NOT_SENT SENT_AND_DEPLOYED NOT_SENT
- * NOT_SENT SENT NOT_SENT
- * NOT_SENT NOT_SENT NOT_SENT
- * NOT_SENT IN_ERROR IN_ERROR
- */
+ * Test the computeState method.
+ * oldState newState expectedFinalState
+ * NOT_SENT SENT_AND_DEPLOYED NOT_SENT
+ * NOT_SENT SENT NOT_SENT
+ * NOT_SENT NOT_SENT NOT_SENT
+ * NOT_SENT IN_ERROR IN_ERROR
+ */
@Test
public void computeStateTestOriginalStateNotSent() {
Exchange exchange = Mockito.mock(Exchange.class);
@@ -124,13 +125,13 @@ public class PolicyComponentTest {
/**
- * Test the computeState method.
- * oldState newState expectedFinalState
- * SENT SENT SENT
- * SENT SENT_AND_DEPLOYED SENT
- * SENT IN_ERROR IN_ERROR
- * SENT NOT_SENT NOT_SENT
- */
+ * Test the computeState method.
+ * oldState newState expectedFinalState
+ * SENT SENT SENT
+ * SENT SENT_AND_DEPLOYED SENT
+ * SENT IN_ERROR IN_ERROR
+ * SENT NOT_SENT NOT_SENT
+ */
@Test
public void computeStateTestOriginalStateSent() throws IOException {
Exchange exchange = Mockito.mock(Exchange.class);
@@ -166,13 +167,13 @@ public class PolicyComponentTest {
}
/**
- * Test the computeState method.
- * oldState newState expectedFinalState
- * SENT_AND_DEPLOYED SENT_AND_DEPLOYED SENT_AND_DEPLOYED
- * SENT_AND_DEPLOYED SENT SENT
- * SENT_AND_DEPLOYED IN_ERROR IN_ERROR
- * SENT_AND_DEPLOYED NOT_SENT NOT_SENT
- */
+ * Test the computeState method.
+ * oldState newState expectedFinalState
+ * SENT_AND_DEPLOYED SENT_AND_DEPLOYED SENT_AND_DEPLOYED
+ * SENT_AND_DEPLOYED SENT SENT
+ * SENT_AND_DEPLOYED IN_ERROR IN_ERROR
+ * SENT_AND_DEPLOYED NOT_SENT NOT_SENT
+ */
@Test
public void computeStateTestOriginalStateSentAndDeployed() throws IOException {
Exchange exchange = Mockito.mock(Exchange.class);
@@ -209,13 +210,13 @@ public class PolicyComponentTest {
/**
- * Test the computeState method.
- * oldState newState expectedFinalState
- * IN_ERROR SENT_AND_DEPLOYED IN_ERROR
- * IN_ERROR SENT IN_ERROR
- * IN_ERROR IN_ERROR IN_ERROR
- * IN_ERROR NOT_SENT IN_ERROR
- */
+ * Test the computeState method.
+ * oldState newState expectedFinalState
+ * IN_ERROR SENT_AND_DEPLOYED IN_ERROR
+ * IN_ERROR SENT IN_ERROR
+ * IN_ERROR IN_ERROR IN_ERROR
+ * IN_ERROR NOT_SENT IN_ERROR
+ */
@Test
public void computeStateTestOriginalStateInError() throws IOException {
Exchange exchange = Mockito.mock(Exchange.class);
@@ -265,7 +266,8 @@ public class PolicyComponentTest {
PolicyModel policyModel2 = new PolicyModel("onap.policies.controlloop.Operational", null, "1.0.0");
OperationalPolicy opPolicy = new OperationalPolicy("opPolicy", loopTest,
- new Gson().fromJson("{\"configtype\":\"json\"}", JsonObject.class), policyModel2, null, "pdpGroup2", "pdpSubgroup2");
+ new Gson().fromJson("{\"configtype\":\"json\"}", JsonObject.class), policyModel2, null, "pdpGroup2",
+ "pdpSubgroup2");
loopTest.addOperationalPolicy(opPolicy);
LoopTemplate loopTemplate = new LoopTemplate("test", "yaml", "svg", 1, null);
diff --git a/src/test/java/org/onap/clamp/loop/PolicyModelServiceItCase.java b/src/test/java/org/onap/clamp/loop/PolicyModelServiceItCase.java
index d918a8e6d..b16aa558d 100644
--- a/src/test/java/org/onap/clamp/loop/PolicyModelServiceItCase.java
+++ b/src/test/java/org/onap/clamp/loop/PolicyModelServiceItCase.java
@@ -119,7 +119,7 @@ public class PolicyModelServiceItCase {
/**
* This tests a create Policy Model from Tosca.
*
- * @throws IOException
+ * @throws IOException In case of failure
*/
@Test
@Transactional
@@ -137,7 +137,7 @@ public class PolicyModelServiceItCase {
/**
* This tests a update Policy Model.
*
- * @throws IOException
+ * @throws IOException In case of failure
*/
@Test
@Transactional
diff --git a/src/test/java/org/onap/clamp/policy/downloader/PolicyEngineControllerTestItCase.java b/src/test/java/org/onap/clamp/policy/downloader/PolicyEngineControllerTestItCase.java
index 3f502ff78..2cd301850 100644
--- a/src/test/java/org/onap/clamp/policy/downloader/PolicyEngineControllerTestItCase.java
+++ b/src/test/java/org/onap/clamp/policy/downloader/PolicyEngineControllerTestItCase.java
@@ -68,9 +68,12 @@ public class PolicyEngineControllerTestItCase {
Instant firstExecution = policyController.getLastInstantExecuted();
assertThat(firstExecution).isNotNull();
List<PolicyModel> policyModelsList = policyModelsRepository.findAll();
- assertThat(policyModelsList.size()).isGreaterThanOrEqualTo(8);
- assertThat(policyModelsList).contains(new PolicyModel("onap.policies.Monitoring", null, "1.0.0"));
- assertThat(policyModelsList).contains(new PolicyModel("onap.policies.controlloop.Operational", null, "1.0.0"));
+ assertThat(policyModelsList.size()).isGreaterThanOrEqualTo(5);
+ assertThat(policyModelsList).contains(new PolicyModel("onap.policies.controlloop.operational.Drools", null, "1.0.0"));
+ assertThat(policyModelsList).contains(new PolicyModel("onap.policies.controlloop.operational.Apex", null, "1.0.0"));
+ assertThat(policyModelsList).contains(new PolicyModel("onap.policies.controlloop.guard.FrequencyLimiter", null, "1.0.0"));
+ assertThat(policyModelsList).contains(new PolicyModel("onap.policies.controlloop.guard.Blacklist", null, "1.0.0"));
+ assertThat(policyModelsList).contains(new PolicyModel("onap.policies.controlloop.guard.MinMax", null, "2.0.0"));
// Re-do it to check that there is no issue with duplicate key
policyController.synchronizeAllPolicies();
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 5686bc161..4b8eee921 100644
--- a/src/test/java/org/onap/clamp/policy/microservice/OperationalPolicyPayloadTest.java
+++ b/src/test/java/org/onap/clamp/policy/microservice/OperationalPolicyPayloadTest.java
@@ -31,6 +31,7 @@ import java.io.IOException;
import java.util.Map;
import org.junit.Test;
import org.onap.clamp.clds.util.ResourceFileUtil;
+import org.onap.clamp.loop.template.PolicyModel;
import org.onap.clamp.policy.operational.LegacyOperationalPolicy;
import org.onap.clamp.policy.operational.OperationalPolicy;
import org.skyscreamer.jsonassert.JSONAssert;
@@ -38,10 +39,11 @@ import org.skyscreamer.jsonassert.JSONAssert;
public class OperationalPolicyPayloadTest {
@Test
- public void testOperationalPolicyPayloadConstruction() throws IOException {
+ public void testOperationalPolicyLegacyPayloadConstruction() throws IOException {
JsonObject jsonConfig = new GsonBuilder().create().fromJson(
ResourceFileUtil.getResourceAsString("tosca/operational-policy-properties.json"), JsonObject.class);
- OperationalPolicy policy = new OperationalPolicy("testPolicy", null, jsonConfig, null, null, null, null);
+ OperationalPolicy policy = new OperationalPolicy("testPolicy.legacy", null, jsonConfig,
+ new PolicyModel("onap.policies.controlloop.Operational.legacy","","1.0.0","test"), null,null,null);
assertThat(policy.createPolicyPayloadYaml())
.isEqualTo(ResourceFileUtil.getResourceAsString("tosca/operational-policy-payload.yaml"));