aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/onap/clamp/clds/it/CldsDictionaryServiceItCase.java72
-rw-r--r--src/test/java/org/onap/clamp/loop/LoopToJsonTest.java34
-rw-r--r--src/test/java/org/onap/clamp/policy/microservice/OperationalPolicyPayloadTest.java20
-rw-r--r--src/test/java/org/onap/clamp/policy/operational/OperationalPolicyRepresentationBuilderTest.java52
4 files changed, 123 insertions, 55 deletions
diff --git a/src/test/java/org/onap/clamp/clds/it/CldsDictionaryServiceItCase.java b/src/test/java/org/onap/clamp/clds/it/CldsDictionaryServiceItCase.java
index d31d5a01..5218c925 100644
--- a/src/test/java/org/onap/clamp/clds/it/CldsDictionaryServiceItCase.java
+++ b/src/test/java/org/onap/clamp/clds/it/CldsDictionaryServiceItCase.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
@@ -29,7 +31,6 @@ import static org.junit.Assert.assertNotNull;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
-import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
@@ -63,23 +64,21 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class CldsDictionaryServiceItCase {
- protected static final EELFLogger logger = EELFManager.getInstance().getLogger(CldsDictionaryServiceItCase.class);
+ private static final EELFLogger logger = EELFManager.getInstance().getLogger(CldsDictionaryServiceItCase.class);
@Autowired
private CldsDictionaryService cldsDictionaryService;
- private Authentication authentication;
private CldsDictionary cldsDictionary;
private CldsDictionaryItem cldsDictionaryItem;
- private List<GrantedAuthority> authList = new LinkedList<GrantedAuthority>();
- private LoggingUtils util;
+ private List<GrantedAuthority> authList = new LinkedList<>();
+
+ private static final String DICTIONARY_NAME = "TestDictionary";
/**
* Setup the variable before the tests execution.
*
- * @throws IOException
- * In case of issues when opening the files
*/
@Before
- public void setupBefore() throws IOException {
+ public void setupBefore() {
authList.add(new SimpleGrantedAuthority("permission-type-cl|dev|read"));
authList.add(new SimpleGrantedAuthority("permission-type-cl|dev|update"));
authList.add(new SimpleGrantedAuthority("permission-type-template|dev|read"));
@@ -87,22 +86,19 @@ public class CldsDictionaryServiceItCase {
authList.add(new SimpleGrantedAuthority("permission-type-filter-vf|dev|*"));
authList.add(new SimpleGrantedAuthority("permission-type-tosca|dev|read"));
authList.add(new SimpleGrantedAuthority("permission-type-tosca|dev|update"));
- authentication = new UsernamePasswordAuthenticationToken(new User("admin", "", authList), "", authList);
+ Authentication authentication =
+ new UsernamePasswordAuthenticationToken(new User("admin", "", authList), "", authList);
SecurityContext securityContext = Mockito.mock(SecurityContext.class);
Mockito.when(securityContext.getAuthentication()).thenReturn(authentication);
- util = Mockito.mock(LoggingUtils.class);
+ LoggingUtils util = Mockito.mock(LoggingUtils.class);
Mockito.doNothing().when(util).entering(Matchers.any(HttpServletRequest.class), Matchers.any(String.class));
cldsDictionaryService.setLoggingUtil(util);
cldsDictionaryService.setSecurityContext(securityContext);
- cldsDictionary = new CldsDictionary();
-
- cldsDictionary.setDictionaryName("TestDictionary");
- ResponseEntity entity = cldsDictionaryService.createOrUpdateDictionary("TestDictionary", cldsDictionary);
- cldsDictionary = (CldsDictionary) entity.getBody();
+ cldsDictionary = cldsDictionaryService.createDictionary(DICTIONARY_NAME);
cldsDictionaryItem = new CldsDictionaryItem();
cldsDictionaryItem.setDictElementShortName("TestDictionaryItemShortName");
@@ -110,23 +106,43 @@ public class CldsDictionaryServiceItCase {
cldsDictionaryItem.setDictElementType("string");
cldsDictionaryItem.setDictionaryId(cldsDictionary.getDictionaryId());
cldsDictionaryItem.setDictElementDesc("TestDictionaryItemDesc");
- cldsDictionaryService.createOrUpdateDictionaryElements("TestDictionary", cldsDictionaryItem);
+ cldsDictionaryService.createOrUpdateDictionaryElements(DICTIONARY_NAME, cldsDictionaryItem);
logger.info("Initial Clds Dictionary uploaded in DB:" + cldsDictionaryItem);
}
@Test
- public void testCreateOrUpdateDictionary() throws Exception {
- ResponseEntity<CldsDictionary> responseEntity = cldsDictionaryService.createOrUpdateDictionary("TestDictionary",
- cldsDictionary);
- CldsDictionary dictionary = responseEntity.getBody();
+ public void testCreateDictionaryFromString() {
+ String dictionaryName = "TestDefaultDictionary";
+ CldsDictionary dictionary = cldsDictionaryService.createDictionary(dictionaryName);
assertNotNull(dictionary);
- logger.info("CLDS Dictionary is:" + dictionary);
- assertEquals("TestDictionary", dictionary.getDictionaryName());
+ logger.info("CLDS Default Dictionary is:" + dictionary);
+ assertEquals(dictionaryName, dictionary.getDictionaryName());
+ }
+
+ @Test
+ public void testCreateOrUpdateDictionaryUsedByFrontend() {
+ ResponseEntity<CldsDictionary> responseEntity =
+ cldsDictionaryService.createOrUpdateDictionary(DICTIONARY_NAME, null);
+ CldsDictionary dictionary1 = responseEntity.getBody();
+
+ responseEntity = cldsDictionaryService.createOrUpdateDictionary(DICTIONARY_NAME, cldsDictionary);
+ CldsDictionary dictionary2 = responseEntity.getBody();
+
+ responseEntity = cldsDictionaryService.createOrUpdateDictionary(DICTIONARY_NAME, new CldsDictionary());
+ CldsDictionary dictionary3 = responseEntity.getBody();
+
+ assertNotNull(dictionary1);
+ assertNotNull(dictionary2);
+ assertNotNull(dictionary3);
+ assertEquals(DICTIONARY_NAME, dictionary1.getDictionaryName());
+ assertEquals(DICTIONARY_NAME, dictionary2.getDictionaryName());
+ assertNotNull(dictionary3.getDictionaryName());
+ assertEquals(DICTIONARY_NAME, dictionary3.getDictionaryName());
}
@Test
- public void testCreateOrUpdateDictionaryElements() throws Exception {
+ public void testCreateOrUpdateDictionaryElements() {
cldsDictionaryItem = new CldsDictionaryItem();
cldsDictionaryItem.setDictElementShortName("TestDictionaryItemShortName1");
cldsDictionaryItem.setDictElementName("TestDictionaryItemName1");
@@ -135,7 +151,7 @@ public class CldsDictionaryServiceItCase {
cldsDictionaryItem.setDictElementDesc("TestDictionaryItemDesc1");
ResponseEntity<CldsDictionaryItem> responseEntity = cldsDictionaryService
- .createOrUpdateDictionaryElements("TestDictionary", cldsDictionaryItem);
+ .createOrUpdateDictionaryElements(DICTIONARY_NAME, cldsDictionaryItem);
CldsDictionaryItem dictionaryItem = responseEntity.getBody();
assertNotNull(dictionaryItem);
logger.info("CLDS Dictionary Item is:" + dictionaryItem);
@@ -143,7 +159,7 @@ public class CldsDictionaryServiceItCase {
}
@Test
- public void testGetAllDictionaryNames() throws Exception {
+ public void testGetAllDictionaryNames() {
ResponseEntity<List<CldsDictionary>> responseEntity = cldsDictionaryService.getAllDictionaryNames();
List<CldsDictionary> dictionaries = responseEntity.getBody();
assertNotNull(dictionaries);
@@ -151,11 +167,11 @@ public class CldsDictionaryServiceItCase {
}
@Test
- public void testGetDictionaryElementsByName() throws Exception {
+ public void testGetDictionaryElementsByName() {
ResponseEntity<List<CldsDictionaryItem>> responseEntity = cldsDictionaryService
- .getDictionaryElementsByName("TestDictionary");
+ .getDictionaryElementsByName(DICTIONARY_NAME);
List<CldsDictionaryItem> dictionaryItems = responseEntity.getBody();
assertNotNull(dictionaryItems);
logger.info("CLDS Dictionary Item LIst is:" + dictionaryItems);
}
-}
+} \ No newline at end of file
diff --git a/src/test/java/org/onap/clamp/loop/LoopToJsonTest.java b/src/test/java/org/onap/clamp/loop/LoopToJsonTest.java
index c9350c61..3010fe50 100644
--- a/src/test/java/org/onap/clamp/loop/LoopToJsonTest.java
+++ b/src/test/java/org/onap/clamp/loop/LoopToJsonTest.java
@@ -54,7 +54,7 @@ public class LoopToJsonTest {
}
private Loop getLoop(String name, String svgRepresentation, String blueprint, String globalPropertiesJson,
- String dcaeId, String dcaeUrl, String dcaeBlueprintId) {
+ String dcaeId, String dcaeUrl, String dcaeBlueprintId) {
Loop loop = new Loop(name, blueprint, svgRepresentation);
loop.setGlobalPropertiesJson(new Gson().fromJson(globalPropertiesJson, JsonObject.class));
loop.setLastComputedState(LoopState.DESIGN);
@@ -65,9 +65,9 @@ public class LoopToJsonTest {
}
private MicroServicePolicy getMicroServicePolicy(String name, String modelType, String jsonRepresentation,
- String policyTosca, String jsonProperties, boolean shared) {
+ String policyTosca, String jsonProperties, boolean shared) {
MicroServicePolicy microService = new MicroServicePolicy(name, modelType, policyTosca, shared,
- gson.fromJson(jsonRepresentation, JsonObject.class), new HashSet<>());
+ gson.fromJson(jsonRepresentation, JsonObject.class), new HashSet<>());
microService.setProperties(new Gson().fromJson(jsonProperties, JsonObject.class));
return microService;
@@ -82,13 +82,13 @@ public class LoopToJsonTest {
@Test
public void loopGsonTest() throws IOException {
Loop loopTest = getLoop("ControlLoopTest", "<xml></xml>", "yamlcontent", "{\"testname\":\"testvalue\"}",
- "123456789", "https://dcaetest.org", "UUID-blueprint");
+ "123456789", "https://dcaetest.org", "UUID-blueprint");
OperationalPolicy opPolicy = this.getOperationalPolicy(
- ResourceFileUtil.getResourceAsString("tosca/operational-policy-properties.json"), "GuardOpPolicyTest");
+ ResourceFileUtil.getResourceAsString("tosca/operational-policy-properties.json"), "GuardOpPolicyTest");
loopTest.addOperationalPolicy(opPolicy);
MicroServicePolicy microServicePolicy = getMicroServicePolicy("configPolicyTest", "",
- "{\"configtype\":\"json\"}", "tosca_definitions_version: tosca_simple_yaml_1_0_0",
- "{\"param1\":\"value1\"}", true);
+ "{\"configtype\":\"json\"}", "tosca_definitions_version: tosca_simple_yaml_1_0_0",
+ "{\"param1\":\"value1\"}", true);
loopTest.addMicroServicePolicy(microServicePolicy);
LoopLog loopLog = getLoopLog(LogType.INFO, "test message", loopTest);
loopTest.addLog(loopLog);
@@ -99,11 +99,11 @@ public class LoopToJsonTest {
Loop loopTestDeserialized = JsonUtils.GSON_JPA_MODEL.fromJson(jsonSerialized, Loop.class);
assertNotNull(loopTestDeserialized);
assertThat(loopTestDeserialized).isEqualToIgnoringGivenFields(loopTest, "svgRepresentation", "blueprint",
- "components");
+ "components");
assertThat(loopTestDeserialized.getComponent("DCAE").getState())
- .isEqualToComparingFieldByField(loopTest.getComponent("DCAE").getState());
- assertThat(loopTestDeserialized.getComponent("POLICY").getState())
- .isEqualToComparingFieldByField(loopTest.getComponent("POLICY").getState());
+ .isEqualToComparingFieldByField(loopTest.getComponent("DCAE").getState());
+ assertThat(loopTestDeserialized.getComponent("POLICY").getState()).isEqualToComparingOnlyGivenFields(
+ loopTest.getComponent("POLICY").getState(), "stateName", "description");
// svg and blueprint not exposed so wont be deserialized
assertThat(loopTestDeserialized.getBlueprint()).isEqualTo(null);
assertThat(loopTestDeserialized.getSvgRepresentation()).isEqualTo(null);
@@ -112,22 +112,22 @@ public class LoopToJsonTest {
assertThat(loopTestDeserialized.getMicroServicePolicies()).containsExactly(microServicePolicy);
assertThat(loopTestDeserialized.getLoopLogs()).containsExactly(loopLog);
assertThat((LoopLog) loopTestDeserialized.getLoopLogs().toArray()[0]).isEqualToIgnoringGivenFields(loopLog,
- "loop");
+ "loop");
}
@Test
public void createPoliciesPayloadPdpGroupTest() throws IOException {
Loop loopTest = getLoop("ControlLoopTest", "<xml></xml>", "yamlcontent", "{\"testname\":\"testvalue\"}",
- "123456789", "https://dcaetest.org", "UUID-blueprint");
+ "123456789", "https://dcaetest.org", "UUID-blueprint");
OperationalPolicy opPolicy = this.getOperationalPolicy(
- ResourceFileUtil.getResourceAsString("tosca/operational-policy-properties.json"), "GuardOpPolicyTest");
+ ResourceFileUtil.getResourceAsString("tosca/operational-policy-properties.json"), "GuardOpPolicyTest");
loopTest.addOperationalPolicy(opPolicy);
MicroServicePolicy microServicePolicy = getMicroServicePolicy("configPolicyTest", "",
- "{\"configtype\":\"json\"}", "tosca_definitions_version: tosca_simple_yaml_1_0_0",
- "{\"param1\":\"value1\"}", true);
+ "{\"configtype\":\"json\"}", "tosca_definitions_version: tosca_simple_yaml_1_0_0",
+ "{\"param1\":\"value1\"}", true);
loopTest.addMicroServicePolicy(microServicePolicy);
JSONAssert.assertEquals(ResourceFileUtil.getResourceAsString("tosca/pdp-group-policy-payload.json"),
- PolicyComponent.createPoliciesPayloadPdpGroup(loopTest), false);
+ PolicyComponent.createPoliciesPayloadPdpGroup(loopTest), false);
}
}
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 8972e511..728b61cc 100644
--- a/src/test/java/org/onap/clamp/policy/microservice/OperationalPolicyPayloadTest.java
+++ b/src/test/java/org/onap/clamp/policy/microservice/OperationalPolicyPayloadTest.java
@@ -42,29 +42,29 @@ public class OperationalPolicyPayloadTest {
@Test
public void testOperationalPolicyPayloadConstruction() throws IOException {
JsonObject jsonConfig = new GsonBuilder().create().fromJson(
- ResourceFileUtil.getResourceAsString("tosca/operational-policy-properties.json"), JsonObject.class);
+ ResourceFileUtil.getResourceAsString("tosca/operational-policy-properties.json"), JsonObject.class);
OperationalPolicy policy = new OperationalPolicy("testPolicy", null, jsonConfig);
assertThat(policy.createPolicyPayloadYaml())
- .isEqualTo(ResourceFileUtil.getResourceAsString("tosca/operational-policy-payload.yaml"));
+ .isEqualTo(ResourceFileUtil.getResourceAsString("tosca/operational-policy-payload.yaml"));
assertThat(policy.createPolicyPayload())
- .isEqualTo(ResourceFileUtil.getResourceAsString("tosca/operational-policy-payload.json"));
+ .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);
+ 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"));
+ .isEqualTo(ResourceFileUtil.getResourceAsString("tosca/operational-policy-payload-legacy.yaml"));
}
@Test
public void testGuardPolicyEmptyPayloadConstruction() throws IOException {
JsonObject jsonConfig = new GsonBuilder().create().fromJson(
- ResourceFileUtil.getResourceAsString("tosca/operational-policy-no-guard-properties.json"),
- JsonObject.class);
+ ResourceFileUtil.getResourceAsString("tosca/operational-policy-no-guard-properties.json"),
+ JsonObject.class);
OperationalPolicy policy = new OperationalPolicy("testPolicy", null, jsonConfig);
Map<String, String> guardsMap = policy.createGuardPolicyPayloads();
assertThat(guardsMap).isEmpty();
@@ -74,15 +74,15 @@ public class OperationalPolicyPayloadTest {
@Test
public void testGuardPolicyPayloadConstruction() throws IOException {
JsonObject jsonConfig = new GsonBuilder().create().fromJson(
- ResourceFileUtil.getResourceAsString("tosca/operational-policy-properties.json"), JsonObject.class);
+ ResourceFileUtil.getResourceAsString("tosca/operational-policy-properties.json"), JsonObject.class);
OperationalPolicy policy = new OperationalPolicy("testPolicy", null, jsonConfig);
Map<String, String> guardsMap = policy.createGuardPolicyPayloads();
JSONAssert.assertEquals(ResourceFileUtil.getResourceAsString("tosca/guard1-policy-payload.json"),
- guardsMap.get("guard1"), false);
+ guardsMap.get("guard.minmax.new"), false);
JSONAssert.assertEquals(ResourceFileUtil.getResourceAsString("tosca/guard2-policy-payload.json"),
- guardsMap.get("guard2"), false);
+ guardsMap.get("guard.frequency.new"), false);
}
}
diff --git a/src/test/java/org/onap/clamp/policy/operational/OperationalPolicyRepresentationBuilderTest.java b/src/test/java/org/onap/clamp/policy/operational/OperationalPolicyRepresentationBuilderTest.java
new file mode 100644
index 00000000..904525be
--- /dev/null
+++ b/src/test/java/org/onap/clamp/policy/operational/OperationalPolicyRepresentationBuilderTest.java
@@ -0,0 +1,52 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END============================================
+ * ===================================================================
+ *
+ */
+
+package org.onap.clamp.policy.operational;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonObject;
+
+import java.io.IOException;
+
+import org.junit.Test;
+import org.onap.clamp.clds.util.ResourceFileUtil;
+import org.skyscreamer.jsonassert.JSONAssert;
+
+public class OperationalPolicyRepresentationBuilderTest {
+
+ @Test
+ public void testOperationalPolicyPayloadConstruction() throws IOException {
+ JsonObject jsonModel = new GsonBuilder().create()
+ .fromJson(ResourceFileUtil.getResourceAsString("tosca/model-properties.json"), JsonObject.class);
+
+ JsonObject jsonSchema = OperationalPolicyRepresentationBuilder.generateOperationalPolicySchema(jsonModel);
+
+ assertThat(jsonSchema).isNotNull();
+
+ JSONAssert.assertEquals(ResourceFileUtil.getResourceAsString("tosca/operational-policy-json-schema.json"),
+ new GsonBuilder().create().toJson(jsonSchema), false);
+ }
+
+}