summaryrefslogtreecommitdiffstats
path: root/models-tosca/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'models-tosca/src/test/java')
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaServiceTemplateTest.java3
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaTopologyTemplateTest.java9
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/serialization/MonitoringPolicySerializationTest.java94
3 files changed, 101 insertions, 5 deletions
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaServiceTemplateTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaServiceTemplateTest.java
index 0fc7a0bf3..5d8615814 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaServiceTemplateTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaServiceTemplateTest.java
@@ -31,6 +31,7 @@ import java.util.TreeMap;
import org.junit.Test;
import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.base.PfReferenceKey;
import org.onap.policy.models.base.PfValidationResult;
/**
@@ -103,7 +104,7 @@ public class ToscaServiceTemplateTest {
tst.setPolicyTypes(policyTypes);
assertEquals(policyTypes, tst.getPolicyTypes());
- PfConceptKey tttKey = new PfConceptKey("TopologyTemplate", "0.0.1");
+ PfReferenceKey tttKey = new PfReferenceKey(tstKey, "TopologyTemplate");
ToscaTopologyTemplate ttt = new ToscaTopologyTemplate(tttKey);
tst.setTopologyTemplate(ttt);
assertEquals(ttt, tst.getTopologyTemplate());
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaTopologyTemplateTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaTopologyTemplateTest.java
index 4a288f183..97bbdbe71 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaTopologyTemplateTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaTopologyTemplateTest.java
@@ -31,6 +31,7 @@ import java.util.TreeMap;
import org.junit.Test;
import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.base.PfReferenceKey;
import org.onap.policy.models.base.PfValidationResult;
/**
@@ -43,11 +44,11 @@ public class ToscaTopologyTemplateTest {
@Test
public void testTopologyTemplatePojo() {
assertNotNull(new ToscaTopologyTemplate());
- assertNotNull(new ToscaTopologyTemplate(new PfConceptKey()));
+ assertNotNull(new ToscaTopologyTemplate(new PfReferenceKey()));
assertNotNull(new ToscaTopologyTemplate(new ToscaTopologyTemplate()));
try {
- new ToscaTopologyTemplate((PfConceptKey) null);
+ new ToscaTopologyTemplate((PfReferenceKey) null);
fail("test should throw an exception");
} catch (Exception exc) {
assertEquals("key is marked @NonNull but is null", exc.getMessage());
@@ -60,7 +61,7 @@ public class ToscaTopologyTemplateTest {
assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage());
}
- PfConceptKey tttKey = new PfConceptKey("ttt", "0.0.1");
+ PfReferenceKey tttKey = new PfReferenceKey("tst", "0.0.1", "ttt");
ToscaTopologyTemplate ttt = new ToscaTopologyTemplate(tttKey);
ttt.setDescription("A Description");
@@ -89,7 +90,7 @@ public class ToscaTopologyTemplateTest {
assertEquals(0, ttt.compareTo(ttt));
assertFalse(ttt.compareTo(ttt.getKey()) == 0);
- PfConceptKey otherDtKey = new PfConceptKey("otherDt", "0.0.1");
+ PfReferenceKey otherDtKey = new PfReferenceKey("otherSt", "0.0.1", "otherDt");
ToscaTopologyTemplate otherDt = new ToscaTopologyTemplate(otherDtKey);
assertFalse(ttt.compareTo(otherDt) == 0);
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/serialization/MonitoringPolicySerializationTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/serialization/MonitoringPolicySerializationTest.java
new file mode 100644
index 000000000..07f5bca7d
--- /dev/null
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/serialization/MonitoringPolicySerializationTest.java
@@ -0,0 +1,94 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.tosca.serialization;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import com.google.gson.Gson;
+import com.google.gson.JsonSyntaxException;
+
+import java.io.IOException;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.common.utils.resources.TextFileUtils;
+import org.onap.policy.models.base.PfValidationResult;
+import org.onap.policy.models.tosca.concepts.ToscaServiceTemplate;
+import org.onap.policy.models.tosca.serialization.simple.ToscaServiceTemplateMessageBodyHandler;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.yaml.snakeyaml.Yaml;
+
+/**
+ * Test serialization of monitoring policies.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+public class MonitoringPolicySerializationTest {
+ // Logger for this class
+ private static final Logger LOGGER = LoggerFactory.getLogger(MonitoringPolicySerializationTest.class);
+
+ private Gson gson;
+
+ @Before
+ public void setUp() {
+ gson = new ToscaServiceTemplateMessageBodyHandler().getGson();
+ }
+
+ @Test
+ public void testJsonDeserialization() throws JsonSyntaxException, IOException {
+ ToscaServiceTemplate serviceTemplate = gson.fromJson(
+ TextFileUtils
+ .getTextFileAsString("src/test/resources/policies/vCPE.policy.monitoring.input.tosca.json"),
+ ToscaServiceTemplate.class);
+
+ assertNotNull(serviceTemplate);
+ LOGGER.info(serviceTemplate.validate(new PfValidationResult()).toString());
+ assertTrue(serviceTemplate.validate(new PfValidationResult()).isValid());
+
+ assertEquals("onap.vcpe.tca:1.0.0",
+ serviceTemplate.getTopologyTemplate().getPolicies().get("onap.vcpe.tca").getId());
+ assertEquals("onap.vcpe.tca:1.0.0",
+ serviceTemplate.getTopologyTemplate().getPolicies().get("onap.vcpe.tca").getId());
+ }
+
+ @Test
+ public void testYamlDeserialization() throws JsonSyntaxException, IOException {
+ Yaml yaml = new Yaml();
+ Object yamlObject = yaml.load(TextFileUtils
+ .getTextFileAsString("src/test/resources/policies/vCPE.policy.monitoring.input.tosca.yaml"));
+
+ String yamlAsJsonString = new Gson().toJson(yamlObject);
+
+ ToscaServiceTemplate serviceTemplate = gson.fromJson(yamlAsJsonString, ToscaServiceTemplate.class);
+
+ assertNotNull(serviceTemplate);
+ LOGGER.info(serviceTemplate.validate(new PfValidationResult()).toString());
+ assertTrue(serviceTemplate.validate(new PfValidationResult()).isValid());
+
+ assertEquals("onap.vcpe.tca:1.0.0",
+ serviceTemplate.getTopologyTemplate().getPolicies().get("onap.vcpe.tca").getId());
+ assertEquals("onap.vcpe.tca:1.0.0",
+ serviceTemplate.getTopologyTemplate().getPolicies().get("onap.vcpe.tca").getId());
+ }
+}