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/CdsServicesTest.java58
-rw-r--r--src/test/java/org/onap/clamp/clds/tosca/ToscaYamlToJsonConvertorTestItCase.java85
-rw-r--r--src/test/java/org/onap/clamp/loop/PolicyComponentTest.java17
-rw-r--r--src/test/java/org/onap/clamp/policy/operational/OperationalPolicyRepresentationBuilderTest.java13
4 files changed, 132 insertions, 41 deletions
diff --git a/src/test/java/org/onap/clamp/clds/client/CdsServicesTest.java b/src/test/java/org/onap/clamp/clds/client/CdsServicesTest.java
new file mode 100644
index 000000000..ec39fc3db
--- /dev/null
+++ b/src/test/java/org/onap/clamp/clds/client/CdsServicesTest.java
@@ -0,0 +1,58 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2020 Huawei Technologies Co., Ltd.
+ * ================================================================================
+ * 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 com.google.gson.JsonObject;
+
+import java.io.IOException;
+
+import org.junit.Test;
+import org.onap.clamp.clds.util.JsonUtils;
+import org.onap.clamp.clds.util.ResourceFileUtil;
+import org.skyscreamer.jsonassert.JSONAssert;
+
+public class CdsServicesTest {
+
+ @Test
+ public void testParseCdsListTypeProperties() throws IOException {
+ String cdsResponse = ResourceFileUtil
+ .getResourceAsString("example/cds-response/vFW-CDS-resource-assignment-workflow.json");
+ CdsServices services = new CdsServices();
+ JsonObject output = services.parseCdsResponse(cdsResponse);
+ JSONAssert.assertEquals(ResourceFileUtil
+ .getResourceAsString("example/cds-response/vFW-CDS-resource-assignment-wf-expected-result.json"),
+ JsonUtils.GSON.toJson(output), true);
+ }
+
+ @Test
+ public void testParseCdsResponse() throws IOException {
+ String cdsResponse = ResourceFileUtil
+ .getResourceAsString("example/cds-response/vFW-CDS-modify-config-workflow.json");
+ CdsServices services = new CdsServices();
+ JsonObject output = services.parseCdsResponse(cdsResponse);
+ JSONAssert.assertEquals(ResourceFileUtil
+ .getResourceAsString("example/cds-response/vFW-CDS-modify-config-wf-expected-result.json"),
+ JsonUtils.GSON.toJson(output), true);
+ }
+
+} \ No newline at end of file
diff --git a/src/test/java/org/onap/clamp/clds/tosca/ToscaYamlToJsonConvertorTestItCase.java b/src/test/java/org/onap/clamp/clds/tosca/ToscaYamlToJsonConvertorTestItCase.java
index a32d4995e..b26f3ede8 100644
--- a/src/test/java/org/onap/clamp/clds/tosca/ToscaYamlToJsonConvertorTestItCase.java
+++ b/src/test/java/org/onap/clamp/clds/tosca/ToscaYamlToJsonConvertorTestItCase.java
@@ -57,7 +57,7 @@ public class ToscaYamlToJsonConvertorTestItCase {
* Schema.
*
* @throws IOException In case of issue when opening the tosca yaml file and
- * converted json file
+ * converted json file
*/
@Test
public final void testParseToscaYaml() throws IOException {
@@ -65,11 +65,11 @@ public class ToscaYamlToJsonConvertorTestItCase {
ToscaYamlToJsonConvertor convertor = new ToscaYamlToJsonConvertor();
String parsedJsonSchema =
- convertor.parseToscaYaml(toscaModelYaml, "onap.policies.monitoring.cdap.tca.hi.lo.app");
+ convertor.parseToscaYaml(toscaModelYaml, "onap.policies.monitoring.cdap.tca.hi.lo.app");
assertNotNull(parsedJsonSchema);
JSONAssert.assertEquals(
- ResourceFileUtil.getResourceAsString("tosca/policy-yaml-to-json.json"),
- parsedJsonSchema, true);
+ ResourceFileUtil.getResourceAsString("tosca/policy-yaml-to-json.json"),
+ parsedJsonSchema, true);
}
/**
@@ -77,20 +77,20 @@ public class ToscaYamlToJsonConvertorTestItCase {
* based on JSON Editor Schema.
*
* @throws IOException In case of issue when opening the tosca yaml file and
- * converted json file
+ * converted json file
*/
@Test
public final void testParseToscaYamlWithConstraints() throws IOException {
String toscaModelYaml =
- ResourceFileUtil.getResourceAsString("tosca/tosca-with-constraints.yaml");
+ ResourceFileUtil.getResourceAsString("tosca/tosca-with-constraints.yaml");
ToscaYamlToJsonConvertor convertor = new ToscaYamlToJsonConvertor();
String parsedJsonSchema =
- convertor.parseToscaYaml(toscaModelYaml, "onap.policies.monitoring.example.app");
+ convertor.parseToscaYaml(toscaModelYaml, "onap.policies.monitoring.example.app");
assertNotNull(parsedJsonSchema);
JSONAssert.assertEquals(
- ResourceFileUtil.getResourceAsString("tosca/policy-yaml-to-json-with-constraints.json"),
- parsedJsonSchema, true);
+ ResourceFileUtil.getResourceAsString("tosca/policy-yaml-to-json-with-constraints.json"),
+ parsedJsonSchema, true);
}
/**
@@ -98,20 +98,20 @@ public class ToscaYamlToJsonConvertorTestItCase {
* conversion based on JSON Editor Schema.
*
* @throws IOException In case of issue when opening the tosca yaml file and
- * converted json file
+ * converted json file
*/
@Test
public final void testParseToscaYamlWithTypes() throws IOException {
String toscaModelYaml =
- ResourceFileUtil.getResourceAsString("tosca/tosca-with-datatypes.yaml");
+ ResourceFileUtil.getResourceAsString("tosca/tosca-with-datatypes.yaml");
ToscaYamlToJsonConvertor convertor = new ToscaYamlToJsonConvertor();
String parsedJsonSchema =
- convertor.parseToscaYaml(toscaModelYaml, "onap.policies.monitoring.example.app");
+ convertor.parseToscaYaml(toscaModelYaml, "onap.policies.monitoring.example.app");
assertNotNull(parsedJsonSchema);
JSONAssert.assertEquals(
- ResourceFileUtil.getResourceAsString("tosca/policy-yaml-to-json-with-datatypes.json"),
- parsedJsonSchema, true);
+ ResourceFileUtil.getResourceAsString("tosca/policy-yaml-to-json-with-datatypes.json"),
+ parsedJsonSchema, true);
}
/**
@@ -119,11 +119,35 @@ public class ToscaYamlToJsonConvertorTestItCase {
* parameters which defines the Tosca Policy name and its short name.
*
* @throws IOException In case of issue when opening the tosca yaml file and
- * converted json file
+ * converted json file
*/
@Test
@Transactional
public final void testMetadataClampPossibleValues() throws IOException {
+ setupDictionary();
+ String toscaModelYaml =
+ ResourceFileUtil.getResourceAsString("tosca/tosca_metadata_clamp_possible_values.yaml");
+
+ JsonObject jsonObject = toscaYamlToJsonConvertor.validateAndConvertToJson(toscaModelYaml);
+ assertNotNull(jsonObject);
+ String policyModelType = toscaYamlToJsonConvertor.getValueFromMetadata(jsonObject,
+ ToscaSchemaConstants.METADATA_POLICY_MODEL_TYPE);
+ String acronym = toscaYamlToJsonConvertor.getValueFromMetadata(jsonObject,
+ ToscaSchemaConstants.METADATA_ACRONYM);
+ String parsedJsonSchema =
+ toscaYamlToJsonConvertor.parseToscaYaml(toscaModelYaml, policyModelType);
+
+ assertNotNull(parsedJsonSchema);
+ assertEquals("onap.policies.monitoring.cdap.tca.hi.lo.app", policyModelType);
+ assertEquals("tca", acronym);
+ JSONAssert.assertEquals(
+ ResourceFileUtil
+ .getResourceAsString("tosca/tosca_metadata_clamp_possible_values_json_schema.json"),
+ parsedJsonSchema, true);
+
+ }
+
+ private void setupDictionary() {
// Set up dictionary elements
Dictionary dictionaryTest = new Dictionary();
@@ -150,6 +174,15 @@ public class ToscaYamlToJsonConvertorTestItCase {
element1.setDescription("Alarm Condition");
dictionaryTest1.addDictionaryElements(element1);
+ dictionaryTest1 = dictionaryService.saveOrUpdateDictionary(dictionaryTest1);
+
+ DictionaryElement element3 = new DictionaryElement();
+ element3.setName("timeEpoch");
+ element3.setShortName("timeEpoch");
+ element3.setType("datetime");
+ element3.setDescription("Time Epoch");
+ dictionaryTest1.addDictionaryElements(element3);
+
dictionaryService.saveOrUpdateDictionary(dictionaryTest1);
Dictionary dictionaryTest2 = new Dictionary();
@@ -159,30 +192,10 @@ public class ToscaYamlToJsonConvertorTestItCase {
DictionaryElement element2 = new DictionaryElement();
element2.setName("equals");
element2.setShortName("equals");
- element2.setType("string");
+ element2.setType("string|datetime");
element2.setDescription("equals");
dictionaryTest2.addDictionaryElements(element2);
dictionaryService.saveOrUpdateDictionary(dictionaryTest2);
-
- String toscaModelYaml =
- ResourceFileUtil.getResourceAsString("tosca/tosca_metadata_clamp_possible_values.yaml");
-
- JsonObject jsonObject = toscaYamlToJsonConvertor.validateAndConvertToJson(toscaModelYaml);
- assertNotNull(jsonObject);
- String policyModelType = toscaYamlToJsonConvertor.getValueFromMetadata(jsonObject,
- ToscaSchemaConstants.METADATA_POLICY_MODEL_TYPE);
- String acronym = toscaYamlToJsonConvertor.getValueFromMetadata(jsonObject,
- ToscaSchemaConstants.METADATA_ACRONYM);
- String parsedJsonSchema =
- toscaYamlToJsonConvertor.parseToscaYaml(toscaModelYaml, policyModelType);
-
- assertNotNull(parsedJsonSchema);
- assertEquals("onap.policies.monitoring.cdap.tca.hi.lo.app", policyModelType);
- assertEquals("tca", acronym);
- JSONAssert.assertEquals(
- ResourceFileUtil
- .getResourceAsString("tosca/tosca_metadata_clamp_possible_values_json_schema.json"),
- parsedJsonSchema, true);
}
}
diff --git a/src/test/java/org/onap/clamp/loop/PolicyComponentTest.java b/src/test/java/org/onap/clamp/loop/PolicyComponentTest.java
index 432de6065..6449a8966 100644
--- a/src/test/java/org/onap/clamp/loop/PolicyComponentTest.java
+++ b/src/test/java/org/onap/clamp/loop/PolicyComponentTest.java
@@ -24,7 +24,6 @@
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;
@@ -32,6 +31,7 @@ import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.junit.Test;
import org.mockito.Mockito;
+import org.onap.clamp.clds.config.LegacyOperationalPolicyController;
import org.onap.clamp.clds.util.ResourceFileUtil;
import org.onap.clamp.loop.components.external.ExternalComponentState;
import org.onap.clamp.loop.components.external.PolicyComponent;
@@ -267,7 +267,8 @@ public class PolicyComponentTest {
new Gson().fromJson("{\"configtype\":\"json\"}", JsonObject.class), null, "pdpGroup2", "pdpSubgroup1");
loopTest.addMicroServicePolicy(microServicePolicy2);
- PolicyModel policyModel2 = new PolicyModel("onap.policies.controlloop.Operational", null, "1.0.0");
+ PolicyModel policyModel2 = new PolicyModel(LegacyOperationalPolicyController.OPERATIONAL_POLICY_LEGACY, null,
+ "1.0.0");
OperationalPolicy opPolicy =
new OperationalPolicy("opPolicy", new Gson().fromJson("{\"configtype\":\"json\"}", JsonObject.class),
new Gson().fromJson("{\"jsonschema\":\"schema\"}", JsonObject.class), policyModel2, null,
@@ -275,16 +276,22 @@ public class PolicyComponentTest {
"pdpSubgroup2");
loopTest.addOperationalPolicy(opPolicy);
+ OperationalPolicy opLegacyPolicy =
+ new OperationalPolicy("opLegacyPolicy", new Gson().fromJson(
+ "{\"guard_policies\":[{\"policy-id\":\"guard1\"}]}", JsonObject.class),
+ new Gson().fromJson("{\"jsonschema\":\"schema\"}", JsonObject.class), policyModel2, null,
+ "pdpGroup2",
+ "pdpSubgroup2");
+
+ loopTest.addOperationalPolicy(opLegacyPolicy);
LoopTemplate loopTemplate = new LoopTemplate("test", "yaml", "svg", 1, null);
loopTemplate.setDcaeBlueprintId("UUID-blueprint");
loopTest.setLoopTemplate(loopTemplate);
- String payload = PolicyComponent.createPoliciesPayloadPdpGroup(loopTest);
+ String payload = PolicyComponent.createPoliciesPayloadPdpGroup(loopTest, "POST");
String expectedRes = ResourceFileUtil.getResourceAsString("tosca/pdp-group-policy-payload.json");
assertThat(payload).isEqualTo(expectedRes);
-
- assertThat(PolicyComponent.listPolicyNamesPdpGroup(loopTest)).containsExactlyInAnyOrder("opPolicy","configPolicyTest","configPolicyTest2");
}
}
diff --git a/src/test/java/org/onap/clamp/policy/operational/OperationalPolicyRepresentationBuilderTest.java b/src/test/java/org/onap/clamp/policy/operational/OperationalPolicyRepresentationBuilderTest.java
index 4e9b56206..a6a496821 100644
--- a/src/test/java/org/onap/clamp/policy/operational/OperationalPolicyRepresentationBuilderTest.java
+++ b/src/test/java/org/onap/clamp/policy/operational/OperationalPolicyRepresentationBuilderTest.java
@@ -50,4 +50,17 @@ public class OperationalPolicyRepresentationBuilderTest {
new GsonBuilder().create().toJson(jsonSchema), false);
}
+ @Test
+ public void testOperationalPolicyPayloadConstructionForCds() throws IOException {
+ JsonObject jsonModel = new GsonBuilder().create()
+ .fromJson(ResourceFileUtil.getResourceAsString("tosca/model-properties-cds.json"), JsonObject.class);
+ Service service = new Service(jsonModel.get("serviceDetails").getAsJsonObject(),
+ jsonModel.get("resourceDetails").getAsJsonObject(),
+ "1.0");
+
+ JsonObject jsonSchema = OperationalPolicyRepresentationBuilder.generateOperationalPolicySchema(service);
+ assertThat(jsonSchema).isNotNull();
+ JSONAssert.assertEquals(ResourceFileUtil.getResourceAsString("tosca/operational-policy-cds-payload-with-list.json"),
+ new GsonBuilder().create().toJson(jsonSchema), false);
+ }
}