aboutsummaryrefslogtreecommitdiffstats
path: root/models-tosca/src/test
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@est.tech>2019-04-01 00:34:34 +0000
committerliamfallon <liam.fallon@est.tech>2019-04-01 00:34:34 +0000
commit2e9186e1eb441b3ec47cf2a959e34b9409134aba (patch)
treea83a9e904c767db38ffc3f7d34aca6ece395e0f6 /models-tosca/src/test
parentfbed360c0acdc127fdf56a99401c1aea691ce57e (diff)
Refactor to authorative TOSCA serializtion
This review refactors the TOSCA support to use authorative serialization and mapping. It removes the JPA entities from the Proider interface It brings the mapping support from and to authorative concepts out of the JSON serialization classes directly into the JPA classes It adapts the unit tests to work with the refactored structure. Apologies for the review size but it all had to be done in a single block of work. Issue-ID: POLICY-1095 Change-Id: I4827d1dc67ef7aac98cba230ffcd79c6de71e805 Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'models-tosca/src/test')
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/mapping/ToscaServiceTemplateMappingTest.java (renamed from models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/mapping/PlainToscaServiceTemplateMapperTest.java)32
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogicalKeyTest.java136
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogicalStringTest.java135
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogicalTest.java124
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataTypeTest.java15
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEntrySchemaTest.java36
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypeTest.java15
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPropertyTest.java21
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTriggerTest.java7
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/TestPojos.java15
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/testconcepts/DummyToscaConstraint.java26
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProviderTest.java53
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicySerializationTest.java30
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicyTypeSerializationTest.java187
14 files changed, 224 insertions, 608 deletions
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/mapping/PlainToscaServiceTemplateMapperTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/mapping/ToscaServiceTemplateMappingTest.java
index 6ec91238f..1bac0b973 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/mapping/PlainToscaServiceTemplateMapperTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/mapping/ToscaServiceTemplateMappingTest.java
@@ -3,6 +3,7 @@
* ONAP Policy Model
* ================================================================================
* Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications 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.
@@ -22,6 +23,7 @@
package org.onap.policy.models.tosca.authorative.mapping;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -30,8 +32,11 @@ import org.junit.Test;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.models.base.PfValidationResult;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.yaml.snakeyaml.Yaml;
/**
@@ -39,15 +44,14 @@ import org.yaml.snakeyaml.Yaml;
*
* @author Chenfei Gao (cgao@research.att.com)
*/
-public class PlainToscaServiceTemplateMapperTest {
+public class ToscaServiceTemplateMappingTest {
+ private static final Logger LOGGER = LoggerFactory.getLogger(ToscaServiceTemplateMappingTest.class);
private StandardCoder standardCoder;
- private PlainToscaServiceTemplateMapper mapper;
@Before
public void setUp() {
standardCoder = new StandardCoder();
- mapper = new PlainToscaServiceTemplateMapper();
}
@Test
@@ -56,12 +60,19 @@ public class PlainToscaServiceTemplateMapperTest {
String inputJson = ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json");
ToscaServiceTemplate plainPolicies = standardCoder.decode(inputJson, ToscaServiceTemplate.class);
- JpaToscaServiceTemplate internalPolicies = mapper.toToscaServiceTemplate(plainPolicies);
+ JpaToscaServiceTemplate internalPolicies = new JpaToscaServiceTemplate();
+ internalPolicies.fromAuthorative(plainPolicies);
+
assertTrue(internalPolicies.validate(new PfValidationResult()).isValid());
- ToscaServiceTemplate plainPolicies2 = mapper.fromToscaServiceTemplate(internalPolicies);
- assertTrue(plainPolicies.equals(plainPolicies2));
+ ToscaServiceTemplate plainPolicies2 = internalPolicies.toAuthorative();
+
+ ToscaPolicy pp1 = plainPolicies.getToscaTopologyTemplate().getPolicies().get(0).values().iterator().next();
+ ToscaPolicy pp2 = plainPolicies2.getToscaTopologyTemplate().getPolicies().get(0).values().iterator().next();
+
+ assertEquals(pp1.getProperties().keySet(), pp2.getProperties().keySet());
} catch (Exception e) {
+ LOGGER.warn("no exception should be thrown", e);
fail("no exception should be thrown");
}
}
@@ -77,14 +88,17 @@ public class PlainToscaServiceTemplateMapperTest {
ToscaServiceTemplate plainPolicyTypes = standardCoder.decode(yamlAsJsonString,
ToscaServiceTemplate.class);
- JpaToscaServiceTemplate internalPolicyTypes = mapper.toToscaServiceTemplate(plainPolicyTypes);
+ JpaToscaServiceTemplate internalPolicyTypes = new JpaToscaServiceTemplate();
+ internalPolicyTypes.fromAuthorative(plainPolicyTypes);
assertTrue(internalPolicyTypes.validate(new PfValidationResult()).isValid());
- ToscaServiceTemplate plainPolicyTypes2 = mapper.fromToscaServiceTemplate(internalPolicyTypes);
- JpaToscaServiceTemplate internalPolicyTypes2 = mapper.toToscaServiceTemplate(plainPolicyTypes2);
+ ToscaServiceTemplate plainPolicyTypes2 = internalPolicyTypes.toAuthorative();
+ JpaToscaServiceTemplate internalPolicyTypes2 = new JpaToscaServiceTemplate();
+ internalPolicyTypes2.fromAuthorative(plainPolicyTypes2);
assertTrue(internalPolicyTypes2.validate(new PfValidationResult()).isValid());
assertTrue(internalPolicyTypes.compareTo(internalPolicyTypes2) == 0);
} catch (Exception e) {
+ LOGGER.warn("no exception should be thrown", e);
fail("no exception should be thrown");
}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogicalKeyTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogicalKeyTest.java
deleted file mode 100644
index 98d7dcfea..000000000
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogicalKeyTest.java
+++ /dev/null
@@ -1,136 +0,0 @@
-/*-
- * ============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.simple.concepts;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-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;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraintLogicalKey;
-
-/**
- * DAO test for ToscaConstraintLogicalKey.
- *
- * @author Liam Fallon (liam.fallon@est.tech)
- */
-public class JpaToscaConstraintLogicalKeyTest {
-
- @Test
- public void testConstraintLogicalKeyPojo() {
- assertNotNull(new JpaToscaConstraintLogicalKey());
- assertNotNull(new JpaToscaConstraintLogicalKey(new PfReferenceKey()));
- assertNotNull(new JpaToscaConstraintLogicalKey(new PfReferenceKey(), JpaToscaConstraintLogicalKey.Operation.EQ,
- new PfConceptKey()));
-
- try {
- new JpaToscaConstraintLogicalKey((PfReferenceKey) null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("key is marked @NonNull but is null", exc.getMessage());
- }
-
- try {
- new JpaToscaConstraintLogicalKey((JpaToscaConstraintLogicalKey) null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage());
- }
-
- PfConceptKey tclParentKey = new PfConceptKey("tParentKey", "0.0.1");
- PfReferenceKey tclKey = new PfReferenceKey(tclParentKey, "trigger0");
- PfConceptKey constraintKey = new PfConceptKey("tParentKey", "0.0.1");
- JpaToscaConstraintLogicalKey tcl =
- new JpaToscaConstraintLogicalKey(tclKey, JpaToscaConstraintLogicalKey.Operation.EQ, constraintKey);
-
- try {
- new JpaToscaConstraintLogicalKey(tcl);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("cannot copy an immutable constraint", exc.getMessage());
- }
-
- JpaToscaConstraintLogicalKey tclClone1 = new JpaToscaConstraintLogicalKey();
- try {
- tcl.copyTo(tclClone1);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("cannot copy an immutable constraint", exc.getMessage());
- }
- tclClone1 = new JpaToscaConstraintLogicalKey(tclKey, JpaToscaConstraintLogicalKey.Operation.EQ, constraintKey);
-
- assertEquals(tcl, tclClone1);
- assertEquals(0, tcl.compareTo(tclClone1));
-
- assertEquals(-1, tcl.compareTo(null));
- assertEquals(0, tcl.compareTo(tcl));
- assertFalse(tcl.compareTo(tcl.getKey()) == 0);
-
- JpaToscaConstraintLogicalKey differentTcl = new JpaToscaConstraintLogicalKey(new PfReferenceKey(),
- JpaToscaConstraintLogicalKey.Operation.EQ, constraintKey);
- assertFalse(tcl.compareTo(differentTcl) == 0);
-
- JpaToscaConstraintLogicalKey otherTc =
- new JpaToscaConstraintLogicalKey(tclKey, JpaToscaConstraintLogicalKey.Operation.EQ, constraintKey);
- assertEquals(0, tcl.compareTo(otherTc));
-
- try {
- tcl.copyTo(null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("target is marked @NonNull but is null", exc.getMessage());
- }
-
- assertEquals(2, tcl.getKeys().size());
- assertEquals(2, new JpaToscaConstraintLogicalKey().getKeys().size());
-
- new JpaToscaConstraintLogicalKey().clean();
- tcl.clean();
- assertEquals(tclClone1, tcl);
-
- assertFalse(new JpaToscaConstraintLogicalKey().validate(new PfValidationResult()).isValid());
- assertTrue(tcl.validate(new PfValidationResult()).isValid());
-
- try {
- tcl.validate(null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("resultIn is marked @NonNull but is null", exc.getMessage());
- }
-
- try {
- new JpaToscaConstraintLogicalKey(tclKey, JpaToscaConstraintLogicalKey.Operation.EQ, null)
- .validate(new PfValidationResult());
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("compareToKey is marked @NonNull but is null", exc.getMessage());
- }
-
- assertFalse(
- new JpaToscaConstraintLogicalKey(tclKey, JpaToscaConstraintLogicalKey.Operation.EQ, new PfConceptKey())
- .validate(new PfValidationResult()).isValid());
- }
-}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogicalStringTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogicalStringTest.java
deleted file mode 100644
index c27ec2660..000000000
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogicalStringTest.java
+++ /dev/null
@@ -1,135 +0,0 @@
-/*-
- * ============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.simple.concepts;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-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;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraintLogicalString;
-
-/**
- * DAO test for ToscaConstraintLogicalString.
- *
- * @author Liam Fallon (liam.fallon@est.tech)
- */
-public class JpaToscaConstraintLogicalStringTest {
-
- @Test
- public void testConstraintLogicalStringPojo() {
- assertNotNull(new JpaToscaConstraintLogicalString());
- assertNotNull(new JpaToscaConstraintLogicalString(new PfReferenceKey()));
- assertNotNull(new JpaToscaConstraintLogicalString(new PfReferenceKey(),
- JpaToscaConstraintLogicalString.Operation.EQ, "Constraint"));
-
- try {
- new JpaToscaConstraintLogicalString((PfReferenceKey) null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("key is marked @NonNull but is null", exc.getMessage());
- }
-
- try {
- new JpaToscaConstraintLogicalString((JpaToscaConstraintLogicalString) null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage());
- }
-
- PfConceptKey tclParentKey = new PfConceptKey("tParentKey", "0.0.1");
- PfReferenceKey tclKey = new PfReferenceKey(tclParentKey, "trigger0");
- JpaToscaConstraintLogicalString tcl =
- new JpaToscaConstraintLogicalString(tclKey, JpaToscaConstraintLogicalString.Operation.EQ, "Constraint");
-
- try {
- new JpaToscaConstraintLogicalString(tcl);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("cannot copy an immutable constraint", exc.getMessage());
- }
-
- JpaToscaConstraintLogicalString tclClone1 = new JpaToscaConstraintLogicalString();
- try {
- tcl.copyTo(tclClone1);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("cannot copy an immutable constraint", exc.getMessage());
- }
- tclClone1 =
- new JpaToscaConstraintLogicalString(tclKey, JpaToscaConstraintLogicalString.Operation.EQ, "Constraint");
-
- assertEquals(tcl, tclClone1);
- assertEquals(0, tcl.compareTo(tclClone1));
-
- assertEquals(-1, tcl.compareTo(null));
- assertEquals(0, tcl.compareTo(tcl));
- assertFalse(tcl.compareTo(tcl.getKey()) == 0);
-
- JpaToscaConstraintLogicalString differentTcl = new JpaToscaConstraintLogicalString(new PfReferenceKey(),
- JpaToscaConstraintLogicalString.Operation.EQ, "Constraint");
- assertFalse(tcl.compareTo(differentTcl) == 0);
-
- JpaToscaConstraintLogicalString otherTc =
- new JpaToscaConstraintLogicalString(tclKey, JpaToscaConstraintLogicalString.Operation.EQ, "Constraint");
- assertEquals(0, tcl.compareTo(otherTc));
-
- try {
- tcl.copyTo(null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("target is marked @NonNull but is null", exc.getMessage());
- }
-
- assertEquals(1, tcl.getKeys().size());
- assertEquals(1, new JpaToscaConstraintLogicalString().getKeys().size());
-
- new JpaToscaConstraintLogicalString().clean();
- tcl.clean();
- assertEquals(tclClone1, tcl);
-
- assertFalse(new JpaToscaConstraintLogicalString().validate(new PfValidationResult()).isValid());
- assertTrue(tcl.validate(new PfValidationResult()).isValid());
-
- try {
- tcl.validate(null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("resultIn is marked @NonNull but is null", exc.getMessage());
- }
-
- try {
- new JpaToscaConstraintLogicalString(tclKey, JpaToscaConstraintLogicalString.Operation.EQ, null)
- .validate(new PfValidationResult());
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("compareToString is marked @NonNull but is null", exc.getMessage());
- }
-
- assertFalse(new JpaToscaConstraintLogicalString(tclKey, JpaToscaConstraintLogicalString.Operation.EQ, "")
- .validate(new PfValidationResult()).isValid());
- }
-}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogicalTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogicalTest.java
index 2da46a71e..de0c813e2 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogicalTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogicalTest.java
@@ -21,148 +21,44 @@
package org.onap.policy.models.tosca.simple.concepts;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
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;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraintLogical;
-import org.onap.policy.models.tosca.simple.concepts.testconcepts.DummyToscaConstraint;
/**
- * DAO test for ToscaConstraintLogical.
+ * DAO test for ToscaConstraintLogicalString.
*
* @author Liam Fallon (liam.fallon@est.tech)
*/
public class JpaToscaConstraintLogicalTest {
@Test
- public void testConstraintLogicalPojo() {
- assertNotNull(new JpaToscaConstraintLogical());
- assertNotNull(new JpaToscaConstraintLogical(new PfReferenceKey()));
+ public void testConstraintLogicalStringPojo() {
+ assertNotNull(new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, "Constraint"));
try {
- new JpaToscaConstraintLogical((PfReferenceKey) null);
+ new JpaToscaConstraintLogical((JpaToscaConstraintOperation) null, null);
fail("test should throw an exception");
} catch (Exception exc) {
- assertEquals("key is marked @NonNull but is null", exc.getMessage());
+ assertEquals("operation is marked @NonNull but is null", exc.getMessage());
}
try {
- new JpaToscaConstraintLogical((JpaToscaConstraintLogical) null);
+ new JpaToscaConstraintLogical((JpaToscaConstraintOperation) null, "Hello");
fail("test should throw an exception");
} catch (Exception exc) {
- assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage());
+ assertEquals("operation is marked @NonNull but is null", exc.getMessage());
}
- PfConceptKey tclParentKey = new PfConceptKey("tParentKey", "0.0.1");
- PfReferenceKey tclKey = new PfReferenceKey(tclParentKey, "trigger0");
- JpaToscaConstraintLogical tcl = new JpaToscaConstraintLogical(tclKey, JpaToscaConstraintLogical.Operation.EQ);
-
- try {
- new JpaToscaConstraintLogical(tcl);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("cannot copy an immutable constraint", exc.getMessage());
- }
-
- JpaToscaConstraintLogical tclClone1 = new JpaToscaConstraintLogical();
- try {
- tcl.copyTo(tclClone1);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("cannot copy an immutable constraint", exc.getMessage());
- }
- tclClone1 = new JpaToscaConstraintLogical(tclKey, JpaToscaConstraintLogical.Operation.EQ);
-
- assertEquals(tcl, tclClone1);
- assertEquals(0, tcl.compareTo(tclClone1));
-
- assertEquals(-1, tcl.compareTo(null));
- assertEquals(0, tcl.compareTo(tcl));
- assertFalse(tcl.compareTo(tcl.getKey()) == 0);
-
- JpaToscaConstraintLogical differentTcl =
- new JpaToscaConstraintLogical(new PfReferenceKey(), JpaToscaConstraintLogical.Operation.EQ);
- assertFalse(tcl.compareTo(differentTcl) == 0);
-
- JpaToscaConstraintLogical otherTc =
- new JpaToscaConstraintLogical(tclKey, JpaToscaConstraintLogical.Operation.EQ);
- assertEquals(0, tcl.compareTo(otherTc));
-
- try {
- tcl.copyTo(null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("target is marked @NonNull but is null", exc.getMessage());
- }
-
- assertEquals(1, tcl.getKeys().size());
- assertEquals(1, new JpaToscaConstraintLogical().getKeys().size());
-
- JpaToscaConstraintLogical tclClone0 = new JpaToscaConstraintLogical();
- new JpaToscaConstraintLogical().clean();
- tcl.clean();
- assertEquals(tclClone0, tcl);
-
- assertFalse(new JpaToscaConstraintLogical().validate(new PfValidationResult()).isValid());
- assertTrue(tcl.validate(new PfValidationResult()).isValid());
-
- try {
- tcl.validate(null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("resultIn is marked @NonNull but is null", exc.getMessage());
- }
-
- DummyToscaConstraint dtc = new DummyToscaConstraint();
- try {
- new DummyToscaConstraint(dtc);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("cannot copy an immutable constraint", exc.getMessage());
- }
-
- try {
- new DummyToscaConstraint((PfReferenceKey) null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("key is marked @NonNull but is null", exc.getMessage());
- }
-
- try {
- new DummyToscaConstraint((DummyToscaConstraint) null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage());
- }
-
- DummyToscaConstraint dtcClone = new DummyToscaConstraint();
-
- assertEquals(dtc, dtcClone);
- assertEquals(dtc, dtc);
- assertEquals(0, dtc.compareTo(dtcClone));
- assertEquals(0, dtc.compareTo(dtc));
- assertEquals(-1, dtc.compareTo(null));
- assertEquals(0, dtc.compareTo(dtcClone));
- assertFalse(dtc.compareTo(dtcClone.getKey()) == 0);
-
try {
- dtc.copyTo(null);
+ new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, null);
fail("test should throw an exception");
} catch (Exception exc) {
- assertEquals("target is marked @NonNull but is null", exc.getMessage());
+ assertEquals("compareTo is marked @NonNull but is null", exc.getMessage());
}
- try {
- dtc.copyTo(dtcClone);
- fail("target should throw an exception");
- } catch (Exception exc) {
- assertEquals("cannot copy an immutable constraint", exc.getMessage());
- }
+ assertNotNull(new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, "Constraint"));
}
}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataTypeTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataTypeTest.java
index bf710e881..efdddccb0 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataTypeTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataTypeTest.java
@@ -27,15 +27,15 @@ import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.ArrayList;
+import java.util.LinkedHashMap;
import java.util.List;
+import java.util.Map;
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;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraint;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraintLogical.Operation;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraintLogicalString;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaDataType;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaProperty;
@@ -70,15 +70,14 @@ public class JpaToscaDataTypeTest {
JpaToscaDataType tdt = new JpaToscaDataType(dtKey);
List<JpaToscaConstraint> constraints = new ArrayList<>();
- JpaToscaConstraintLogicalString lsc =
- new JpaToscaConstraintLogicalString(new PfReferenceKey(dtKey, "sc"), Operation.EQ, "hello");
+ JpaToscaConstraintLogical lsc = new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, "hello");
constraints.add(lsc);
tdt.setConstraints(constraints);
assertEquals(constraints, tdt.getConstraints());
- List<JpaToscaProperty> properties = new ArrayList<>();
+ Map<String, JpaToscaProperty> properties = new LinkedHashMap<>();
JpaToscaProperty tp = new JpaToscaProperty(new PfReferenceKey(dtKey, "pr"), new PfConceptKey("type", "0.0.1"));
- properties.add(tp);
+ properties.put(tp.getKey().getLocalName(), tp);
tdt.setProperties(properties);
assertEquals(properties, tdt.getProperties());
@@ -113,7 +112,7 @@ public class JpaToscaDataTypeTest {
assertEquals("target is marked @NonNull but is null", exc.getMessage());
}
- assertEquals(4, tdt.getKeys().size());
+ assertEquals(3, tdt.getKeys().size());
assertEquals(1, new JpaToscaDataType().getKeys().size());
new JpaToscaDataType().clean();
@@ -128,7 +127,7 @@ public class JpaToscaDataTypeTest {
tdt.getConstraints().remove(null);
assertTrue(tdt.validate(new PfValidationResult()).isValid());
- tdt.getProperties().add(null);
+ tdt.getProperties().put(null, null);
assertFalse(tdt.validate(new PfValidationResult()).isValid());
tdt.getProperties().remove(null);
assertTrue(tdt.validate(new PfValidationResult()).isValid());
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEntrySchemaTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEntrySchemaTest.java
index a69b9a777..4a9bdbe2e 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEntrySchemaTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEntrySchemaTest.java
@@ -31,11 +31,8 @@ import java.util.List;
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;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraint;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraintLogical.Operation;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraintLogicalString;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaEntrySchema;
/**
@@ -47,16 +44,14 @@ public class JpaToscaEntrySchemaTest {
@Test
public void testEntrySchemaPojo() {
- assertNotNull(new JpaToscaEntrySchema());
- assertNotNull(new JpaToscaEntrySchema(new PfReferenceKey()));
- assertNotNull(new JpaToscaEntrySchema(new PfReferenceKey(), new PfConceptKey()));
- assertNotNull(new JpaToscaEntrySchema(new JpaToscaEntrySchema()));
+ assertNotNull(new JpaToscaEntrySchema(new PfConceptKey()));
+ assertNotNull(new JpaToscaEntrySchema(new JpaToscaEntrySchema(new PfConceptKey())));
try {
- new JpaToscaEntrySchema((PfReferenceKey) null);
+ new JpaToscaEntrySchema((PfConceptKey) null);
fail("test should throw an exception");
} catch (Exception exc) {
- assertEquals("key is marked @NonNull but is null", exc.getMessage());
+ assertEquals("type is marked @NonNull but is null", exc.getMessage());
}
try {
@@ -66,16 +61,14 @@ public class JpaToscaEntrySchemaTest {
assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage());
}
- PfReferenceKey esKey = new PfReferenceKey("entrySchemaParent", "0.0.1", "entrySchema");
PfConceptKey typeKey = new PfConceptKey("type", "0.0.1");
- JpaToscaEntrySchema tes = new JpaToscaEntrySchema(esKey, typeKey);
+ JpaToscaEntrySchema tes = new JpaToscaEntrySchema(typeKey);
tes.setDescription("A Description");
assertEquals("A Description", tes.getDescription());
List<JpaToscaConstraint> constraints = new ArrayList<>();
- JpaToscaConstraintLogicalString lsc =
- new JpaToscaConstraintLogicalString(new PfReferenceKey(esKey, "sc"), Operation.EQ, "hello");
+ JpaToscaConstraintLogical lsc = new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, "hello");
constraints.add(lsc);
tes.setConstraints(constraints);
assertEquals(constraints, tes.getConstraints());
@@ -84,21 +77,16 @@ public class JpaToscaEntrySchemaTest {
assertEquals(tes, tdtClone0);
assertEquals(0, tes.compareTo(tdtClone0));
- JpaToscaEntrySchema tdtClone1 = new JpaToscaEntrySchema();
- tes.copyTo(tdtClone1);
+ JpaToscaEntrySchema tdtClone1 = new JpaToscaEntrySchema(tes);
assertEquals(tes, tdtClone1);
assertEquals(0, tes.compareTo(tdtClone1));
assertEquals(-1, tes.compareTo(null));
assertEquals(0, tes.compareTo(tes));
- assertFalse(tes.compareTo(tes.getKey()) == 0);
- PfReferenceKey otherEsKey = new PfReferenceKey("entrySchemaParent", "0.0.1", "otherEntrySchema");
- JpaToscaEntrySchema otherEs = new JpaToscaEntrySchema(otherEsKey);
+ JpaToscaEntrySchema otherEs = new JpaToscaEntrySchema(typeKey);
assertFalse(tes.compareTo(otherEs) == 0);
- otherEs.setKey(esKey);
- assertFalse(tes.compareTo(otherEs) == 0);
otherEs.setType(typeKey);
assertFalse(tes.compareTo(otherEs) == 0);
otherEs.setDescription("A Description");
@@ -113,14 +101,14 @@ public class JpaToscaEntrySchemaTest {
assertEquals("target is marked @NonNull but is null", exc.getMessage());
}
- assertEquals(3, tes.getKeys().size());
- assertEquals(2, new JpaToscaEntrySchema().getKeys().size());
+ assertEquals(1, tes.getKeys().size());
+ assertEquals(1, new JpaToscaEntrySchema(typeKey).getKeys().size());
- new JpaToscaEntrySchema().clean();
+ new JpaToscaEntrySchema(typeKey).clean();
tes.clean();
assertEquals(tdtClone0, tes);
- assertFalse(new JpaToscaEntrySchema().validate(new PfValidationResult()).isValid());
+ assertTrue(new JpaToscaEntrySchema(typeKey).validate(new PfValidationResult()).isValid());
assertTrue(tes.validate(new PfValidationResult()).isValid());
tes.setType(PfConceptKey.getNullKey());
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypeTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypeTest.java
index 7dac2684f..870640e75 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypeTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypeTest.java
@@ -28,6 +28,7 @@ import static org.junit.Assert.fail;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -35,6 +36,7 @@ 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;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaEntityType;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyType;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaProperty;
@@ -46,7 +48,6 @@ import org.onap.policy.models.tosca.simple.concepts.JpaToscaTrigger;
* @author Liam Fallon (liam.fallon@est.tech)
*/
public class JpaToscaPolicyTypeTest {
-
@Test
public void testPolicyTypePojo() {
assertNotNull(new JpaToscaPolicyType());
@@ -81,9 +82,9 @@ public class JpaToscaPolicyTypeTest {
tpt.setDescription("A Description");
PfConceptKey propTypeKey = new PfConceptKey("propType", "0.0.1");
- List<JpaToscaProperty> properties = new ArrayList<>();
+ Map<String, JpaToscaProperty> properties = new LinkedHashMap<>();
JpaToscaProperty tp = new JpaToscaProperty(new PfReferenceKey(ptKey, "aProp"), propTypeKey);
- properties.add(tp);
+ properties.put(tp.getKey().getLocalName(), tp);
tpt.setProperties(properties);
assertEquals(properties, tpt.getProperties());
@@ -148,7 +149,7 @@ public class JpaToscaPolicyTypeTest {
assertFalse(new JpaToscaPolicyType().validate(new PfValidationResult()).isValid());
assertTrue(tpt.validate(new PfValidationResult()).isValid());
- tpt.getProperties().add(null);
+ tpt.getProperties().put(null, null);
assertFalse(tpt.validate(new PfValidationResult()).isValid());
tpt.getProperties().remove(null);
assertTrue(tpt.validate(new PfValidationResult()).isValid());
@@ -191,20 +192,20 @@ public class JpaToscaPolicyTypeTest {
}
try {
- new JpaToscaEntityType((PfConceptKey) null);
+ new JpaToscaEntityType<ToscaPolicy>((PfConceptKey) null);
fail("test should throw an exception");
} catch (Exception exc) {
assertEquals("key is marked @NonNull but is null", exc.getMessage());
}
try {
- new JpaToscaEntityType((JpaToscaEntityType) null);
+ new JpaToscaEntityType<ToscaPolicy>((JpaToscaEntityType<ToscaPolicy>) null);
fail("test should throw an exception");
} catch (Exception exc) {
assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage());
}
- JpaToscaEntityType tet = new JpaToscaEntityType(tpt.getKey());
+ JpaToscaEntityType<ToscaPolicy> tet = new JpaToscaEntityType<ToscaPolicy>(tpt.getKey());
assertEquals(-1, tet.compareTo(null));
assertEquals(0, tet.compareTo(tet));
assertFalse(tet.compareTo(tet.getKey()) == 0);
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPropertyTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPropertyTest.java
index 8d46c9533..83100cc3c 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPropertyTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPropertyTest.java
@@ -33,11 +33,8 @@ 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;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraint;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraintLogical.Operation;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraintLogicalString;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaEntrySchema;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaProperty;
/**
* DAO test for ToscaProperty.
@@ -101,18 +98,16 @@ public class JpaToscaPropertyTest {
tp.setDefaultValue("defaultKey");
- tp.setStatus(JpaToscaProperty.Status.SUPPORTED);
+ tp.setStatus(ToscaProperty.Status.SUPPORTED);
List<JpaToscaConstraint> constraints = new ArrayList<>();
- JpaToscaConstraintLogicalString lsc =
- new JpaToscaConstraintLogicalString(new PfReferenceKey(pkey, "sc"), Operation.EQ, "hello");
+ JpaToscaConstraintLogical lsc = new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, "hello");
constraints.add(lsc);
tp.setConstraints(constraints);
assertEquals(constraints, tp.getConstraints());
- PfReferenceKey esKey = new PfReferenceKey(pkey, "entrySchema");
PfConceptKey typeKey = new PfConceptKey("type", "0.0.1");
- JpaToscaEntrySchema tes = new JpaToscaEntrySchema(esKey, typeKey);
+ JpaToscaEntrySchema tes = new JpaToscaEntrySchema(typeKey);
tp.setEntrySchema(tes);
JpaToscaProperty tdtClone0 = new JpaToscaProperty(tp);
@@ -142,7 +137,7 @@ public class JpaToscaPropertyTest {
assertFalse(tp.compareTo(otherDt) == 0);
otherDt.setDefaultValue("defaultKey");
assertFalse(tp.compareTo(otherDt) == 0);
- otherDt.setStatus(JpaToscaProperty.Status.SUPPORTED);
+ otherDt.setStatus(ToscaProperty.Status.SUPPORTED);
assertFalse(tp.compareTo(otherDt) == 0);
assertFalse(tp.compareTo(otherDt) == 0);
otherDt.setConstraints(constraints);
@@ -155,9 +150,9 @@ public class JpaToscaPropertyTest {
otherDt.setRequired(false);
assertEquals(0, tp.compareTo(otherDt));
- otherDt.setStatus(JpaToscaProperty.Status.UNSUPPORTED);
+ otherDt.setStatus(ToscaProperty.Status.UNSUPPORTED);
assertFalse(tp.compareTo(otherDt) == 0);
- otherDt.setStatus(JpaToscaProperty.Status.SUPPORTED);
+ otherDt.setStatus(ToscaProperty.Status.SUPPORTED);
assertEquals(0, tp.compareTo(otherDt));
try {
@@ -167,7 +162,7 @@ public class JpaToscaPropertyTest {
assertEquals("target is marked @NonNull but is null", exc.getMessage());
}
- assertEquals(5, tp.getKeys().size());
+ assertEquals(3, tp.getKeys().size());
assertEquals(2, new JpaToscaProperty().getKeys().size());
new JpaToscaProperty().clean();
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTriggerTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTriggerTest.java
index 661882a3f..0f69cb3c9 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTriggerTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTriggerTest.java
@@ -33,8 +33,6 @@ 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;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraintLogical.Operation;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraintLogicalString;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaEventFilter;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaTimeInterval;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaTrigger;
@@ -128,8 +126,7 @@ public class JpaToscaTriggerTest {
new JpaToscaEventFilter(new PfReferenceKey(tkey, "filter"), new PfConceptKey("NodeName", "0.0.1"));
tdt.setTargetFilter(targetFilter);
- JpaToscaConstraintLogicalString lsc =
- new JpaToscaConstraintLogicalString(new PfReferenceKey(tkey, "sc"), Operation.EQ, "hello");
+ JpaToscaConstraintLogical lsc = new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, "hello");
tdt.setCondition(lsc);
assertEquals(lsc, tdt.getCondition());
tdt.setConstraint(lsc);
@@ -194,7 +191,7 @@ public class JpaToscaTriggerTest {
assertEquals("target is marked @NonNull but is null", exc.getMessage());
}
- assertEquals(6, tdt.getKeys().size());
+ assertEquals(4, tdt.getKeys().size());
assertEquals(1, new JpaToscaTrigger().getKeys().size());
new JpaToscaTrigger().clean();
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/TestPojos.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/TestPojos.java
index b3bdedf1c..e5be49860 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/TestPojos.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/TestPojos.java
@@ -3,6 +3,7 @@
* ONAP Policy Model
* ================================================================================
* Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications 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.
@@ -26,7 +27,6 @@ import com.openpojo.reflection.filters.FilterPackageInfo;
import com.openpojo.validation.Validator;
import com.openpojo.validation.ValidatorBuilder;
import com.openpojo.validation.rule.impl.GetterMustExistRule;
-import com.openpojo.validation.rule.impl.SetterMustExistRule;
import com.openpojo.validation.test.impl.GetterTester;
import com.openpojo.validation.test.impl.SetterTester;
@@ -45,9 +45,16 @@ public class TestPojos {
@Test
public void testPojos() {
- final Validator validator = ValidatorBuilder.create().with(new ToStringTester())
- .with(new SetterMustExistRule()).with(new GetterMustExistRule()).with(new SetterTester())
- .with(new GetterTester()).build();
+ // @formatter:off
+ final Validator validator = ValidatorBuilder
+ .create()
+ .with(new ToStringTester())
+ .with(new GetterMustExistRule())
+ .with(new SetterTester())
+ .with(new GetterTester())
+ .build();
+ // @formatter:on
+
validator.validate(POJO_PACKAGE, new FilterPackageInfo());
}
}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/testconcepts/DummyToscaConstraint.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/testconcepts/DummyToscaConstraint.java
index a743e2834..b13cb4b0b 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/testconcepts/DummyToscaConstraint.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/testconcepts/DummyToscaConstraint.java
@@ -20,10 +20,7 @@
package org.onap.policy.models.tosca.simple.concepts.testconcepts;
-import javax.ws.rs.core.Response;
-
-import org.onap.policy.models.base.PfModelRuntimeException;
-import org.onap.policy.models.base.PfReferenceKey;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConstraint;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraint;
/**
@@ -38,25 +35,14 @@ public class DummyToscaConstraint extends JpaToscaConstraint {
* The Default Constructor creates a {@link DummyToscaConstraint} object with a null key.
*/
public DummyToscaConstraint() {
- super(new PfReferenceKey());
}
- /**
- * The Key Constructor creates a {@link DummyToscaConstraint} object with the given concept key.
- *
- * @param key the key of the constraint
- */
- public DummyToscaConstraint(final PfReferenceKey key) {
- super(key);
+ @Override
+ public ToscaConstraint toAuthorative() {
+ return null;
}
- /**
- * Copy constructor.
- *
- * @param copyConcept the concept to copy from
- */
- public DummyToscaConstraint(final DummyToscaConstraint copyConcept) {
- super(copyConcept);
- throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, "cannot copy an immutable constraint");
+ @Override
+ public void fromAuthorative(ToscaConstraint authorativeConcept) {
}
}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProviderTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProviderTest.java
index 029c7a7e1..ebbebce1c 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProviderTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProviderTest.java
@@ -24,14 +24,13 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
-import com.google.gson.Gson;
-
import java.sql.Connection;
import java.sql.DriverManager;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfModelException;
@@ -39,10 +38,10 @@ import org.onap.policy.models.dao.DaoParameters;
import org.onap.policy.models.dao.PfDao;
import org.onap.policy.models.dao.PfDaoFactory;
import org.onap.policy.models.dao.impl.DefaultPfDao;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicies;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaTopologyTemplate;
-import org.onap.policy.models.tosca.simple.serialization.ToscaServiceTemplateMessageBodyHandler;
/**
* Test the {@link SimpleToscaProvider} class.
@@ -52,7 +51,7 @@ import org.onap.policy.models.tosca.simple.serialization.ToscaServiceTemplateMes
public class SimpleToscaProviderTest {
private Connection connection;
private PfDao pfDao;
- private Gson gson;
+ private StandardCoder standardCoder;
/**
@@ -82,7 +81,7 @@ public class SimpleToscaProviderTest {
*/
@Before
public void setupGson() {
- gson = new ToscaServiceTemplateMessageBodyHandler().getGson();
+ standardCoder = new StandardCoder();
}
@After
@@ -92,7 +91,7 @@ public class SimpleToscaProviderTest {
}
@Test
- public void testPoliciesGet() throws PfModelException {
+ public void testPoliciesGet() throws Exception {
try {
new SimpleToscaProvider().getPolicies(null, null);
fail("test should throw an exception here");
@@ -114,9 +113,12 @@ public class SimpleToscaProviderTest {
assertEquals("policyKey is marked @NonNull but is null", exc.getMessage());
}
- JpaToscaServiceTemplate originalServiceTemplate =
- gson.fromJson(ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"),
- JpaToscaServiceTemplate.class);
+ ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(
+ ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"),
+ ToscaServiceTemplate.class);
+
+ JpaToscaServiceTemplate originalServiceTemplate = new JpaToscaServiceTemplate();
+ originalServiceTemplate.fromAuthorative(toscaServiceTemplate);
assertNotNull(originalServiceTemplate);
JpaToscaServiceTemplate createdServiceTemplate =
@@ -135,7 +137,7 @@ public class SimpleToscaProviderTest {
}
@Test
- public void testPolicyCreate() throws PfModelException {
+ public void testPolicyCreate() throws Exception {
try {
new SimpleToscaProvider().createPolicies(null, null);
fail("test should throw an exception here");
@@ -157,9 +159,12 @@ public class SimpleToscaProviderTest {
assertEquals("serviceTemplate is marked @NonNull but is null", exc.getMessage());
}
- JpaToscaServiceTemplate originalServiceTemplate =
- gson.fromJson(ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"),
- JpaToscaServiceTemplate.class);
+ ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(
+ ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"),
+ ToscaServiceTemplate.class);
+
+ JpaToscaServiceTemplate originalServiceTemplate = new JpaToscaServiceTemplate();
+ originalServiceTemplate.fromAuthorative(toscaServiceTemplate);
assertNotNull(originalServiceTemplate);
JpaToscaServiceTemplate createdServiceTemplate =
@@ -169,7 +174,7 @@ public class SimpleToscaProviderTest {
}
@Test
- public void testPolicyUpdate() throws PfModelException {
+ public void testPolicyUpdate() throws Exception {
try {
new SimpleToscaProvider().updatePolicies(null, null);
fail("test should throw an exception here");
@@ -191,9 +196,12 @@ public class SimpleToscaProviderTest {
assertEquals("serviceTemplate is marked @NonNull but is null", exc.getMessage());
}
- JpaToscaServiceTemplate originalServiceTemplate =
- gson.fromJson(ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"),
- JpaToscaServiceTemplate.class);
+ ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(
+ ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"),
+ ToscaServiceTemplate.class);
+
+ JpaToscaServiceTemplate originalServiceTemplate = new JpaToscaServiceTemplate();
+ originalServiceTemplate.fromAuthorative(toscaServiceTemplate);
assertNotNull(originalServiceTemplate);
JpaToscaServiceTemplate updatedServiceTemplate =
@@ -203,7 +211,7 @@ public class SimpleToscaProviderTest {
}
@Test
- public void testPoliciesDelete() throws PfModelException {
+ public void testPoliciesDelete() throws Exception {
try {
new SimpleToscaProvider().deletePolicies(null, null);
fail("test should throw an exception here");
@@ -225,9 +233,12 @@ public class SimpleToscaProviderTest {
assertEquals("policyKey is marked @NonNull but is null", exc.getMessage());
}
- JpaToscaServiceTemplate originalServiceTemplate =
- gson.fromJson(ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"),
- JpaToscaServiceTemplate.class);
+ ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(
+ ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"),
+ ToscaServiceTemplate.class);
+
+ JpaToscaServiceTemplate originalServiceTemplate = new JpaToscaServiceTemplate();
+ originalServiceTemplate.fromAuthorative(toscaServiceTemplate);
assertNotNull(originalServiceTemplate);
JpaToscaServiceTemplate createdServiceTemplate =
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicySerializationTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicySerializationTest.java
index 1f17a43bf..5f0cbb355 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicySerializationTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicySerializationTest.java
@@ -26,23 +26,21 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
-import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
-import com.google.gson.JsonSyntaxException;
-import java.io.IOException;
import java.util.Map;
import org.junit.Before;
import org.junit.Test;
+import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfValidationResult;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
-import org.onap.policy.models.tosca.simple.serialization.ToscaServiceTemplateMessageBodyHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yaml.snakeyaml.Yaml;
@@ -64,11 +62,11 @@ public class MonitoringPolicySerializationTest {
private static final String VFW_MON_INPUT_JSON = "policies/vFirewall.policy.monitoring.input.tosca.json";
private static final String VFW_MON_INPUT_YAML = "policies/vFirewall.policy.monitoring.input.tosca.yaml";
- private Gson gson;
+ private StandardCoder standardCoder;
@Before
public void setUp() {
- gson = new ToscaServiceTemplateMessageBodyHandler().getGson();
+ standardCoder = new StandardCoder();
}
@Test
@@ -93,6 +91,7 @@ public class MonitoringPolicySerializationTest {
assertTrue(serviceTemplateFromJson.compareTo(serviceTemplateFromYaml) == 0);
} catch (Exception e) {
+ LOGGER.warn("No exception should be thrown", e);
fail("No exception should be thrown");
}
}
@@ -122,11 +121,13 @@ public class MonitoringPolicySerializationTest {
}
private JpaToscaServiceTemplate deserializeMonitoringInputJson(String resourcePath)
- throws JsonSyntaxException, IOException {
+ throws Exception {
String policyJson = ResourceUtils.getResourceAsString(resourcePath);
- JpaToscaServiceTemplate serviceTemplate = gson.fromJson(policyJson, JpaToscaServiceTemplate.class);
- return serviceTemplate;
+ ToscaServiceTemplate serviceTemplate = standardCoder.decode(policyJson, ToscaServiceTemplate.class);
+ JpaToscaServiceTemplate jpaToscaServiceTemplate = new JpaToscaServiceTemplate();
+ jpaToscaServiceTemplate.fromAuthorative(serviceTemplate);
+ return jpaToscaServiceTemplate;
}
private JpaToscaServiceTemplate deserializeMonitoringInputYaml(String resourcePath)
@@ -136,12 +137,15 @@ public class MonitoringPolicySerializationTest {
String policyYaml = ResourceUtils.getResourceAsString(resourcePath);
Object yamlObject = yaml.load(policyYaml);
String yamlAsJsonString = new StandardCoder().encode(yamlObject);
- JpaToscaServiceTemplate serviceTemplate = gson.fromJson(yamlAsJsonString, JpaToscaServiceTemplate.class);
- return serviceTemplate;
+ ToscaServiceTemplate serviceTemplate = standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class);
+
+ JpaToscaServiceTemplate jpaToscaServiceTemplate = new JpaToscaServiceTemplate();
+ jpaToscaServiceTemplate.fromAuthorative(serviceTemplate);
+ return jpaToscaServiceTemplate;
}
- private String serializeMonitoringServiceTemplate(JpaToscaServiceTemplate serviceTemplate) {
- return gson.toJson(serviceTemplate);
+ private String serializeMonitoringServiceTemplate(JpaToscaServiceTemplate serviceTemplate) throws CoderException {
+ return standardCoder.encode(serviceTemplate.toAuthorative());
}
private void verifyVcpeMonitoringInputDeserialization(JpaToscaServiceTemplate serviceTemplate) {
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicyTypeSerializationTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicyTypeSerializationTest.java
index b494199e8..569e1ad41 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicyTypeSerializationTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicyTypeSerializationTest.java
@@ -26,26 +26,24 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
-import com.google.gson.Gson;
-import com.google.gson.JsonSyntaxException;
-
-import java.io.IOException;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import org.junit.Before;
import org.junit.Test;
+import org.onap.policy.common.utils.coder.CoderException;
+import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfValidationResult;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraintLogicalString;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
+import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraintLogical;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraintValidValues;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaDataType;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaEntrySchema;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyType;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaProperty;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
-import org.onap.policy.models.tosca.simple.serialization.ToscaServiceTemplateMessageBodyHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yaml.snakeyaml.Yaml;
@@ -63,11 +61,11 @@ public class MonitoringPolicyTypeSerializationTest {
private static final String MONITORING_COLLECTORS_YAML =
"policytypes/onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server.yaml";
- private Gson gson;
+ private StandardCoder coder;
@Before
public void setUp() {
- gson = new ToscaServiceTemplateMessageBodyHandler().getGson();
+ coder = new StandardCoder();
}
@Test
@@ -82,6 +80,7 @@ public class MonitoringPolicyTypeSerializationTest {
verifyCollectorInputDeserialization(serviceTemplateFromYaml);
} catch (Exception e) {
+ LOGGER.warn("No exception should be thrown", e);
fail("No exception should be thrown");
}
}
@@ -90,34 +89,47 @@ public class MonitoringPolicyTypeSerializationTest {
public void testSerialization() {
try {
// TCA
- JpaToscaServiceTemplate serviceTemplateFromYaml = deserializeMonitoringInputYaml(MONITORING_TCA_YAML);
- String serializedServiceTemplate1 = serializeMonitoringServiceTemplate(serviceTemplateFromYaml);
- JpaToscaServiceTemplate serviceTemplateFromJson = gson.fromJson(serializedServiceTemplate1,
- JpaToscaServiceTemplate.class);
- String serializedServiceTemplate2 = serializeMonitoringServiceTemplate(serviceTemplateFromJson);
- assertEquals(serializedServiceTemplate1, serializedServiceTemplate2);
+ JpaToscaServiceTemplate tcaServiceTemplateFromYaml = deserializeMonitoringInputYaml(MONITORING_TCA_YAML);
+ String serializedServiceTemplateTca = serializeMonitoringServiceTemplate(tcaServiceTemplateFromYaml);
+
+ ToscaServiceTemplate toscaServiceTemplateFromJsonTca =
+ coder.decode(serializedServiceTemplateTca, ToscaServiceTemplate.class);
+
+ JpaToscaServiceTemplate serviceTemplateFromJsonTca = new JpaToscaServiceTemplate();
+ serviceTemplateFromJsonTca.fromAuthorative(toscaServiceTemplateFromJsonTca);
+ String serializedServiceTemplateTcaOut = serializeMonitoringServiceTemplate(serviceTemplateFromJsonTca);
+ assertEquals(serializedServiceTemplateTca, serializedServiceTemplateTcaOut);
// Collector
- serviceTemplateFromYaml = deserializeMonitoringInputYaml(MONITORING_COLLECTORS_YAML);
- serializedServiceTemplate1 = serializeMonitoringServiceTemplate(serviceTemplateFromYaml);
- serviceTemplateFromJson = gson.fromJson(serializedServiceTemplate1, JpaToscaServiceTemplate.class);
- serializedServiceTemplate2 = serializeMonitoringServiceTemplate(serviceTemplateFromJson);
- assertEquals(serializedServiceTemplate1, serializedServiceTemplate2);
+ JpaToscaServiceTemplate collectorServiceTemplateFromYaml =
+ deserializeMonitoringInputYaml(MONITORING_COLLECTORS_YAML);
+ String serializedServiceTemplateCollector =
+ serializeMonitoringServiceTemplate(collectorServiceTemplateFromYaml);
+ ToscaServiceTemplate toscaServiceTemplateFromJsonCollector =
+ coder.decode(serializedServiceTemplateCollector, ToscaServiceTemplate.class);
+ JpaToscaServiceTemplate serviceTemplateFromJsonCollector = new JpaToscaServiceTemplate();
+ serviceTemplateFromJsonCollector.fromAuthorative(toscaServiceTemplateFromJsonCollector);
+ String serializedServiceTemplateCollectorsOut =
+ serializeMonitoringServiceTemplate(serviceTemplateFromJsonCollector);
+ assertEquals(serializedServiceTemplateCollector, serializedServiceTemplateCollectorsOut);
} catch (Exception e) {
+ LOGGER.warn("No exception should be thrown", e);
fail("No exception should be thrown");
}
}
- private JpaToscaServiceTemplate deserializeMonitoringInputYaml(String resourcePath)
- throws JsonSyntaxException, IOException {
+ private JpaToscaServiceTemplate deserializeMonitoringInputYaml(String resourcePath) throws Exception {
Yaml yaml = new Yaml();
String policyTypeYaml = ResourceUtils.getResourceAsString(resourcePath);
Object yamlObject = yaml.load(policyTypeYaml);
- String yamlAsJsonString = new Gson().toJson(yamlObject);
- JpaToscaServiceTemplate serviceTemplate = gson.fromJson(yamlAsJsonString, JpaToscaServiceTemplate.class);
- return serviceTemplate;
+ String yamlAsJsonString = coder.encode(yamlObject);
+ ToscaServiceTemplate serviceTemplate = coder.decode(yamlAsJsonString, ToscaServiceTemplate.class);
+
+ JpaToscaServiceTemplate jpaToscaServiceTemplate = new JpaToscaServiceTemplate();
+ jpaToscaServiceTemplate.fromAuthorative(serviceTemplate);
+ return jpaToscaServiceTemplate;
}
private void verifyTcaInputDeserialization(JpaToscaServiceTemplate serviceTemplate) {
@@ -137,7 +149,7 @@ public class MonitoringPolicyTypeSerializationTest {
Entry<PfConceptKey, JpaToscaPolicyType> firstPolicyType = policyTypesIter.next();
assertEquals("onap.policies.Monitoring", firstPolicyType.getKey().getName());
- assertEquals("1.0.0", firstPolicyType.getKey().getVersion());
+ assertEquals("0.0.0", firstPolicyType.getKey().getVersion());
assertEquals("tosca.policies.Root", firstPolicyType.getValue().getDerivedFrom().getName());
assertEquals("a base policy type for all policies that governs monitoring provisioning",
firstPolicyType.getValue().getDescription());
@@ -148,7 +160,7 @@ public class MonitoringPolicyTypeSerializationTest {
assertEquals("onap.policies.Monitoring", secondPolicyType.getValue().getDerivedFrom().getName());
assertTrue(secondPolicyType.getValue().getProperties().size() == 1);
- JpaToscaProperty property = secondPolicyType.getValue().getProperties().iterator().next();
+ JpaToscaProperty property = secondPolicyType.getValue().getProperties().values().iterator().next();
assertEquals("onap.policy.monitoring.cdap.tca.hi.lo.app", property.getKey().getParentKeyName());
assertEquals("1.0.0", property.getKey().getParentKeyVersion());
assertEquals("tca_policy", property.getKey().getLocalName());
@@ -156,9 +168,6 @@ public class MonitoringPolicyTypeSerializationTest {
assertEquals("TCA Policy JSON", property.getDescription());
JpaToscaEntrySchema entrySchema = property.getEntrySchema();
- assertEquals("map", entrySchema.getKey().getParentKeyName());
- assertEquals("1.0.0", entrySchema.getKey().getParentKeyVersion());
- assertEquals("entry_schema", entrySchema.getKey().getLocalName());
assertEquals("onap.datatypes.monitoring.tca_policy", entrySchema.getType().getName());
// Check data_types
@@ -170,81 +179,74 @@ public class MonitoringPolicyTypeSerializationTest {
assertEquals("onap.datatypes.monitoring.metricsPerEventName", firstDataType.getKey().getName());
JpaToscaDataType firstDataTypeVal = firstDataType.getValue();
assertEquals("tosca.datatypes.Root", firstDataTypeVal.getDerivedFrom().getName());
- assertEquals("1.0.0", firstDataTypeVal.getDerivedFrom().getVersion());
+ assertEquals("0.0.0", firstDataTypeVal.getDerivedFrom().getVersion());
assertTrue(firstDataTypeVal.getProperties().size() == 6);
- Iterator<JpaToscaProperty> firstDataTypePropertiesIter = firstDataTypeVal.getProperties().iterator();
+ Iterator<JpaToscaProperty> firstDataTypePropertiesIter = firstDataTypeVal.getProperties().values().iterator();
JpaToscaProperty firstDataTypeFirstProperty = firstDataTypePropertiesIter.next();
- assertEquals("onap.datatypes.monitoring.metricsPerEventName", firstDataTypeFirstProperty.getKey()
- .getParentKeyName());
+ assertEquals("onap.datatypes.monitoring.metricsPerEventName",
+ firstDataTypeFirstProperty.getKey().getParentKeyName());
assertEquals("controlLoopSchemaType", firstDataTypeFirstProperty.getKey().getLocalName());
assertEquals("string", firstDataTypeFirstProperty.getType().getName());
assertTrue(firstDataTypeFirstProperty.isRequired());
assertEquals("Specifies Control Loop Schema Type for the event Name e.g. VNF, VM",
firstDataTypeFirstProperty.getDescription());
assertTrue(firstDataTypeFirstProperty.getConstraints().size() == 1);
- assertEquals("valid_values", firstDataTypeFirstProperty.getConstraints().iterator().next().getKey()
- .getLocalName());
- assertEquals("string", firstDataTypeFirstProperty.getConstraints().iterator().next().getKey()
- .getParentKeyName());
- assertTrue(firstDataTypeFirstProperty.getConstraints().iterator().next()
- instanceof JpaToscaConstraintValidValues);
- assertTrue(((JpaToscaConstraintValidValues)(firstDataTypeFirstProperty.getConstraints().iterator().next()))
+ assertEquals("org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraintValidValues",
+ firstDataTypeFirstProperty.getConstraints().iterator().next().getClass().getCanonicalName());
+ assertTrue(((JpaToscaConstraintValidValues) (firstDataTypeFirstProperty.getConstraints().iterator().next()))
.getValidValues().size() == 2);
JpaToscaProperty firstDataTypeSecondProperty = firstDataTypePropertiesIter.next();
- assertEquals("onap.datatypes.monitoring.metricsPerEventName", firstDataTypeSecondProperty.getKey()
- .getParentKeyName());
+ assertEquals("onap.datatypes.monitoring.metricsPerEventName",
+ firstDataTypeSecondProperty.getKey().getParentKeyName());
assertEquals("eventName", firstDataTypeSecondProperty.getKey().getLocalName());
assertEquals("string", firstDataTypeSecondProperty.getType().getName());
assertTrue(firstDataTypeSecondProperty.isRequired());
- assertEquals("Event name to which thresholds need to be applied", firstDataTypeSecondProperty
- .getDescription());
+ assertEquals("Event name to which thresholds need to be applied", firstDataTypeSecondProperty.getDescription());
JpaToscaProperty firstDataTypeThirdProperty = firstDataTypePropertiesIter.next();
- assertEquals("onap.datatypes.monitoring.metricsPerEventName", firstDataTypeThirdProperty.getKey()
- .getParentKeyName());
+ assertEquals("onap.datatypes.monitoring.metricsPerEventName",
+ firstDataTypeThirdProperty.getKey().getParentKeyName());
assertEquals("policyName", firstDataTypeThirdProperty.getKey().getLocalName());
assertEquals("string", firstDataTypeThirdProperty.getType().getName());
assertTrue(firstDataTypeThirdProperty.isRequired());
assertEquals("TCA Policy Scope Name", firstDataTypeThirdProperty.getDescription());
JpaToscaProperty firstDataTypeFourthProperty = firstDataTypePropertiesIter.next();
- assertEquals("onap.datatypes.monitoring.metricsPerEventName", firstDataTypeFourthProperty.getKey()
- .getParentKeyName());
+ assertEquals("onap.datatypes.monitoring.metricsPerEventName",
+ firstDataTypeFourthProperty.getKey().getParentKeyName());
assertEquals("policyScope", firstDataTypeFourthProperty.getKey().getLocalName());
assertEquals("string", firstDataTypeFourthProperty.getType().getName());
assertTrue(firstDataTypeFourthProperty.isRequired());
assertEquals("TCA Policy Scope", firstDataTypeFourthProperty.getDescription());
JpaToscaProperty firstDataTypeFifthProperty = firstDataTypePropertiesIter.next();
- assertEquals("onap.datatypes.monitoring.metricsPerEventName", firstDataTypeFifthProperty.getKey()
- .getParentKeyName());
+ assertEquals("onap.datatypes.monitoring.metricsPerEventName",
+ firstDataTypeFifthProperty.getKey().getParentKeyName());
assertEquals("policyVersion", firstDataTypeFifthProperty.getKey().getLocalName());
assertEquals("string", firstDataTypeFifthProperty.getType().getName());
assertTrue(firstDataTypeFifthProperty.isRequired());
assertEquals("TCA Policy Scope Version", firstDataTypeFifthProperty.getDescription());
JpaToscaProperty firstDataTypeSixthProperty = firstDataTypePropertiesIter.next();
- assertEquals("onap.datatypes.monitoring.metricsPerEventName", firstDataTypeSixthProperty.getKey()
- .getParentKeyName());
+ assertEquals("onap.datatypes.monitoring.metricsPerEventName",
+ firstDataTypeSixthProperty.getKey().getParentKeyName());
assertEquals("thresholds", firstDataTypeSixthProperty.getKey().getLocalName());
assertEquals("list", firstDataTypeSixthProperty.getType().getName());
assertTrue(firstDataTypeSixthProperty.isRequired());
assertEquals("Thresholds associated with eventName", firstDataTypeSixthProperty.getDescription());
assertNotNull(firstDataTypeSixthProperty.getEntrySchema());
- assertEquals("entry_schema", firstDataTypeSixthProperty.getEntrySchema().getKey().getLocalName());
- assertEquals("list", firstDataTypeSixthProperty.getEntrySchema().getKey().getParentKeyName());
- assertEquals("onap.datatypes.monitoring.thresholds", firstDataTypeSixthProperty.getEntrySchema().getType()
- .getName());
+ assertEquals("onap.datatypes.monitoring.thresholds",
+ firstDataTypeSixthProperty.getEntrySchema().getType().getName());
Entry<PfConceptKey, JpaToscaDataType> secondDataType = dataTypesIter.next();
assertEquals("onap.datatypes.monitoring.tca_policy", secondDataType.getKey().getName());
JpaToscaDataType secondDataTypeVal = secondDataType.getValue();
assertEquals("tosca.datatypes.Root", secondDataTypeVal.getDerivedFrom().getName());
- assertEquals("1.0.0", secondDataTypeVal.getDerivedFrom().getVersion());
+ assertEquals("0.0.0", secondDataTypeVal.getDerivedFrom().getVersion());
assertTrue(secondDataTypeVal.getProperties().size() == 2);
- Iterator<JpaToscaProperty> secondDataTypePropertiesIter = secondDataTypeVal.getProperties().iterator();
+ Iterator<JpaToscaProperty> secondDataTypePropertiesIter = secondDataTypeVal.getProperties().values().iterator();
JpaToscaProperty secondDataTypeFirstProperty = secondDataTypePropertiesIter.next();
assertEquals("onap.datatypes.monitoring.tca_policy", secondDataTypeFirstProperty.getKey().getParentKeyName());
@@ -254,13 +256,10 @@ public class MonitoringPolicyTypeSerializationTest {
assertEquals("Domain name to which TCA needs to be applied", secondDataTypeFirstProperty.getDescription());
assertEquals("measurementsForVfScaling", secondDataTypeFirstProperty.getDefaultValue());
assertTrue(secondDataTypeFirstProperty.getConstraints().size() == 1);
- assertEquals("string", secondDataTypeFirstProperty.getConstraints().iterator().next().getKey()
- .getParentKeyName());
- assertEquals("equal", secondDataTypeFirstProperty.getConstraints().iterator().next().getKey().getLocalName());
- assertTrue(secondDataTypeFirstProperty.getConstraints().iterator().next()
- instanceof JpaToscaConstraintLogicalString);
- assertEquals("measurementsForVfScaling", ((JpaToscaConstraintLogicalString)(secondDataTypeFirstProperty
- .getConstraints().iterator().next())).getCompareToString());
+ assertTrue(secondDataTypeFirstProperty.getConstraints().iterator().next() instanceof JpaToscaConstraintLogical);
+ assertEquals("measurementsForVfScaling",
+ ((JpaToscaConstraintLogical) (secondDataTypeFirstProperty.getConstraints().iterator().next()))
+ .getCompareTo());
JpaToscaProperty secondDataTypeSecondProperty = secondDataTypePropertiesIter.next();
assertEquals("onap.datatypes.monitoring.tca_policy", secondDataTypeSecondProperty.getKey().getParentKeyName());
@@ -270,26 +269,24 @@ public class MonitoringPolicyTypeSerializationTest {
assertEquals("Contains eventName and threshold details that need to be applied to given eventName",
secondDataTypeSecondProperty.getDescription());
assertNotNull(secondDataTypeSecondProperty.getEntrySchema());
- assertEquals("list", secondDataTypeSecondProperty.getEntrySchema().getKey().getParentKeyName());
assertEquals("onap.datatypes.monitoring.metricsPerEventName",
secondDataTypeSecondProperty.getEntrySchema().getType().getName());
- assertEquals("entry_schema", secondDataTypeSecondProperty.getEntrySchema().getKey().getLocalName());
Entry<PfConceptKey, JpaToscaDataType> thirdDataType = dataTypesIter.next();
assertEquals("onap.datatypes.monitoring.thresholds", thirdDataType.getKey().getName());
JpaToscaDataType thirdDataTypeVal = thirdDataType.getValue();
assertEquals("tosca.datatypes.Root", thirdDataTypeVal.getDerivedFrom().getName());
- assertEquals("1.0.0", thirdDataTypeVal.getDerivedFrom().getVersion());
+ assertEquals("0.0.0", thirdDataTypeVal.getDerivedFrom().getVersion());
assertTrue(thirdDataTypeVal.getProperties().size() == 7);
- Iterator<JpaToscaProperty> thirdDataTypePropertiesIter = thirdDataTypeVal.getProperties().iterator();
+ Iterator<JpaToscaProperty> thirdDataTypePropertiesIter = thirdDataTypeVal.getProperties().values().iterator();
JpaToscaProperty thirdDataTypeFirstProperty = thirdDataTypePropertiesIter.next();
assertEquals("onap.datatypes.monitoring.thresholds", thirdDataTypeFirstProperty.getKey().getParentKeyName());
assertEquals("closedLoopControlName", thirdDataTypeFirstProperty.getKey().getLocalName());
assertEquals("string", thirdDataTypeFirstProperty.getType().getName());
assertTrue(thirdDataTypeFirstProperty.isRequired());
- assertEquals("Closed Loop Control Name associated with the threshold", thirdDataTypeFirstProperty
- .getDescription());
+ assertEquals("Closed Loop Control Name associated with the threshold",
+ thirdDataTypeFirstProperty.getDescription());
JpaToscaProperty thirdDataTypeSecondProperty = thirdDataTypePropertiesIter.next();
assertEquals("onap.datatypes.monitoring.thresholds", thirdDataTypeSecondProperty.getKey().getParentKeyName());
@@ -299,13 +296,11 @@ public class MonitoringPolicyTypeSerializationTest {
assertEquals("Closed Loop Event Status of the threshold", thirdDataTypeSecondProperty.getDescription());
assertNotNull(thirdDataTypeSecondProperty.getConstraints());
assertTrue(thirdDataTypeSecondProperty.getConstraints().size() == 1);
- assertEquals("string", thirdDataTypeSecondProperty.getConstraints().iterator().next().getKey()
- .getParentKeyName());
- assertEquals("valid_values", thirdDataTypeSecondProperty.getConstraints().iterator().next().getKey()
- .getLocalName());
- assertTrue(thirdDataTypeSecondProperty.getConstraints().iterator().next()
- instanceof JpaToscaConstraintValidValues);
- assertTrue(((JpaToscaConstraintValidValues)(thirdDataTypeSecondProperty.getConstraints().iterator().next()))
+ assertEquals("JpaToscaConstraintValidValues(validValues=[ONSET, ABATED])",
+ thirdDataTypeSecondProperty.getConstraints().iterator().next().toString());
+ assertTrue(thirdDataTypeSecondProperty.getConstraints().iterator()
+ .next() instanceof JpaToscaConstraintValidValues);
+ assertTrue(((JpaToscaConstraintValidValues) (thirdDataTypeSecondProperty.getConstraints().iterator().next()))
.getValidValues().size() == 2);
JpaToscaProperty thirdDataTypeThirdProperty = thirdDataTypePropertiesIter.next();
@@ -316,11 +311,10 @@ public class MonitoringPolicyTypeSerializationTest {
assertEquals("Direction of the threshold", thirdDataTypeThirdProperty.getDescription());
assertNotNull(thirdDataTypeThirdProperty.getConstraints());
assertTrue(thirdDataTypeThirdProperty.getConstraints().size() == 1);
- assertEquals("string", thirdDataTypeThirdProperty.getConstraints().iterator().next().getKey()
- .getParentKeyName());
- assertEquals("valid_values", thirdDataTypeThirdProperty.getConstraints().iterator().next().getKey()
- .getLocalName());
- assertTrue(((JpaToscaConstraintValidValues)(thirdDataTypeThirdProperty.getConstraints().iterator().next()))
+ assertEquals(
+ "JpaToscaConstraintValidValues(validValues=[LESS, LESS_OR_EQUAL, GREATER, GREATER_OR_EQUAL, EQUAL])",
+ thirdDataTypeThirdProperty.getConstraints().iterator().next().toString());
+ assertTrue(((JpaToscaConstraintValidValues) (thirdDataTypeThirdProperty.getConstraints().iterator().next()))
.getValidValues().size() == 5);
JpaToscaProperty thirdDataTypeFourthProperty = thirdDataTypePropertiesIter.next();
@@ -332,11 +326,7 @@ public class MonitoringPolicyTypeSerializationTest {
thirdDataTypeFourthProperty.getDescription());
assertNotNull(thirdDataTypeFourthProperty.getConstraints());
assertTrue(thirdDataTypeFourthProperty.getConstraints().size() == 1);
- assertEquals("string", thirdDataTypeFourthProperty.getConstraints().iterator().next().getKey()
- .getParentKeyName());
- assertEquals("valid_values", thirdDataTypeFourthProperty.getConstraints().iterator().next().getKey()
- .getLocalName());
- assertTrue(((JpaToscaConstraintValidValues)(thirdDataTypeFourthProperty.getConstraints().iterator().next()))
+ assertTrue(((JpaToscaConstraintValidValues) (thirdDataTypeFourthProperty.getConstraints().iterator().next()))
.getValidValues().size() == 43);
JpaToscaProperty thirdDataTypeFifthProperty = thirdDataTypePropertiesIter.next();
@@ -347,11 +337,9 @@ public class MonitoringPolicyTypeSerializationTest {
assertEquals("Threshold Event Severity", thirdDataTypeFifthProperty.getDescription());
assertNotNull(thirdDataTypeFifthProperty.getConstraints());
assertTrue(thirdDataTypeFifthProperty.getConstraints().size() == 1);
- assertEquals("string", thirdDataTypeFifthProperty.getConstraints().iterator().next().getKey()
- .getParentKeyName());
- assertEquals("valid_values", thirdDataTypeFifthProperty.getConstraints().iterator().next().getKey()
- .getLocalName());
- assertTrue(((JpaToscaConstraintValidValues)(thirdDataTypeFifthProperty.getConstraints().iterator().next()))
+ assertEquals("JpaToscaConstraintValidValues(validValues=[CRITICAL, MAJOR, MINOR, WARNING, NORMAL])",
+ thirdDataTypeFifthProperty.getConstraints().iterator().next().toString());
+ assertTrue(((JpaToscaConstraintValidValues) (thirdDataTypeFifthProperty.getConstraints().iterator().next()))
.getValidValues().size() == 5);;
JpaToscaProperty thirdDataTypeSixthProperty = thirdDataTypePropertiesIter.next();
@@ -359,8 +347,8 @@ public class MonitoringPolicyTypeSerializationTest {
assertEquals("thresholdValue", thirdDataTypeSixthProperty.getKey().getLocalName());
assertEquals("integer", thirdDataTypeSixthProperty.getType().getName());
assertTrue(thirdDataTypeSixthProperty.isRequired());
- assertEquals("Threshold value for the field Path inside CEF message", thirdDataTypeSixthProperty
- .getDescription());
+ assertEquals("Threshold value for the field Path inside CEF message",
+ thirdDataTypeSixthProperty.getDescription());
JpaToscaProperty thirdDataTypeSeventhProperty = thirdDataTypePropertiesIter.next();
assertEquals("onap.datatypes.monitoring.thresholds", thirdDataTypeSeventhProperty.getKey().getParentKeyName());
@@ -399,7 +387,7 @@ public class MonitoringPolicyTypeSerializationTest {
assertEquals("policy.nodes.Root", secondPolicyType.getValue().getDerivedFrom().getName());
assertTrue(secondPolicyType.getValue().getProperties().size() == 2);
- Iterator<JpaToscaProperty> propertiesIter = secondPolicyType.getValue().getProperties().iterator();
+ Iterator<JpaToscaProperty> propertiesIter = secondPolicyType.getValue().getProperties().values().iterator();
JpaToscaProperty firstProperty = propertiesIter.next();
assertEquals("onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server",
@@ -418,7 +406,8 @@ public class MonitoringPolicyTypeSerializationTest {
assertEquals("datafile Policy JSON as string", secondProperty.getDescription());
}
- private String serializeMonitoringServiceTemplate(JpaToscaServiceTemplate serviceTemplate) {
- return gson.toJson(serviceTemplate);
+ private String serializeMonitoringServiceTemplate(JpaToscaServiceTemplate serviceTemplate) throws CoderException {
+ ToscaServiceTemplate toscaServiceTemplate = serviceTemplate.toAuthorative();
+ return coder.encode(toscaServiceTemplate);
}
-} \ No newline at end of file
+}