summaryrefslogtreecommitdiffstats
path: root/models-base/src/test/java/org
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-base/src/test/java/org
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-base/src/test/java/org')
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/PfConceptContainerTest.java47
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyAuthorativeConcept.java52
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyBadPfConcept.java56
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyBadPfConceptContainer.java77
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfConcept.java21
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfConceptContainer.java2
6 files changed, 243 insertions, 12 deletions
diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfConceptContainerTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfConceptContainerTest.java
index 0ed04c4e6..3ae7c4c9d 100644
--- a/models-base/src/test/java/org/onap/policy/models/base/PfConceptContainerTest.java
+++ b/models-base/src/test/java/org/onap/policy/models/base/PfConceptContainerTest.java
@@ -20,18 +20,23 @@
package org.onap.policy.models.base;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
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 java.util.ArrayList;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import org.junit.Test;
+import org.onap.policy.models.base.testconcepts.DummyAuthorativeConcept;
+import org.onap.policy.models.base.testconcepts.DummyBadPfConceptContainer;
import org.onap.policy.models.base.testconcepts.DummyPfConcept;
import org.onap.policy.models.base.testconcepts.DummyPfConceptContainer;
import org.onap.policy.models.base.testconcepts.DummyPfConceptSub;
@@ -44,7 +49,7 @@ import org.onap.policy.models.base.testconcepts.DummyPfConceptSub;
public class PfConceptContainerTest {
@Test
- public void test() {
+ public void testConceptContainer() {
DummyPfConceptContainer container = new DummyPfConceptContainer();
assertNotNull(container);
@@ -179,16 +184,38 @@ public class PfConceptContainerTest {
assertEquals(conceptKey, returnSet.iterator().next().getKey());
container.getConceptMap().put(conceptKey, new DummyPfConceptSub(conceptKey));
+ }
- DummyPfConceptContainer exceptionOnCopyContainer = new DummyPfConceptContainer();
- try {
- container.copyTo(exceptionOnCopyContainer);
- fail("test should throw an exception here");
- } catch (Exception exc) {
- assertEquals(
- "Failed to create a clone of class \"org.onap.policy.models.base.testconcepts.DummyPfConceptSub\"",
- exc.getMessage());
- }
+ @Test
+ public void testAuthorative() {
+ Map<String, DummyAuthorativeConcept> dacMap = new LinkedHashMap<>();
+ dacMap.put("name0", new DummyAuthorativeConcept("name0", "1.2.3", "Hello"));
+ dacMap.put("name1", new DummyAuthorativeConcept("name1", "1.2.3", "Hi"));
+ dacMap.put("name2", new DummyAuthorativeConcept("name2", "1.2.3", "Howdy"));
+
+ List<Map<String, DummyAuthorativeConcept>> authorativeList = new ArrayList<>();
+ authorativeList.add(dacMap);
+
+ DummyPfConceptContainer container = new DummyPfConceptContainer();
+ container.fromAuthorative(authorativeList);
+
+ assertEquals("Hello", container.getConceptMap().get(new PfConceptKey("name0:1.2.3")).getDescription());
+ assertEquals("Hi", container.getConceptMap().get(new PfConceptKey("name1:1.2.3")).getDescription());
+ assertEquals("Howdy", container.getConceptMap().get(new PfConceptKey("name2:1.2.3")).getDescription());
+
+ List<Map<String, DummyAuthorativeConcept>> outMapList = container.toAuthorative();
+
+ assertEquals(dacMap, outMapList.get(0));
+
+ DummyBadPfConceptContainer badContainer = new DummyBadPfConceptContainer();
+ assertThatThrownBy(() -> {
+ badContainer.fromAuthorative(authorativeList);
+ }).hasMessage("failed to instantiate instance of container concept class");
+
+ authorativeList.clear();
+ assertThatThrownBy(() -> {
+ container.fromAuthorative(authorativeList);
+ }).hasMessage("An incoming list of concepts must have at least one entry");
}
@Test(expected = NullPointerException.class)
diff --git a/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyAuthorativeConcept.java b/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyAuthorativeConcept.java
new file mode 100644
index 000000000..02ff75061
--- /dev/null
+++ b/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyAuthorativeConcept.java
@@ -0,0 +1,52 @@
+/*-
+ * ============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.base.testconcepts;
+
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import org.onap.policy.models.base.PfNameVersion;
+
+/**
+ * Dummy authorative concept.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+@Data
+@NoArgsConstructor
+public class DummyAuthorativeConcept implements PfNameVersion {
+ private String name;
+ private String version;
+ private String description;
+
+ /**
+ * Constructor.
+ *
+ * @param name the name
+ * @param version the version
+ * @param description the description
+ */
+ public DummyAuthorativeConcept(final String name, final String version, final String description) {
+ this.name = name;
+ this.version = version;
+ this.description = description;
+ }
+}
diff --git a/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyBadPfConcept.java b/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyBadPfConcept.java
new file mode 100644
index 000000000..05fd5992b
--- /dev/null
+++ b/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyBadPfConcept.java
@@ -0,0 +1,56 @@
+/*-
+ * ============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.base.testconcepts;
+
+import lombok.NonNull;
+
+import org.onap.policy.models.base.PfConceptKey;
+
+/**
+ * Bad dummy concept throws exception on default constructor.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+public class DummyBadPfConcept extends DummyPfConcept {
+ private static final long serialVersionUID = 1L;
+
+ public DummyBadPfConcept() {
+ throw new NumberFormatException();
+ }
+
+ /**
+ * The Key Constructor creates a {@link DummyPfConcept} object with the given concept key.
+ *
+ * @param key the key
+ */
+ public DummyBadPfConcept(@NonNull final PfConceptKey key) {
+ throw new NumberFormatException();
+ }
+
+ /**
+ * Copy constructor.
+ *
+ * @param copyConcept the concept to copy from
+ */
+ public DummyBadPfConcept(final DummyBadPfConcept copyConcept) {
+ throw new NumberFormatException();
+ }
+}
diff --git a/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyBadPfConceptContainer.java b/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyBadPfConceptContainer.java
new file mode 100644
index 000000000..c328a01aa
--- /dev/null
+++ b/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyBadPfConceptContainer.java
@@ -0,0 +1,77 @@
+/*-
+ * ============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.base.testconcepts;
+
+import java.util.Map;
+
+import lombok.NonNull;
+
+import org.onap.policy.models.base.PfConceptContainer;
+import org.onap.policy.models.base.PfConceptKey;
+
+/**
+ * Dummy container for PF concepts.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+public class DummyBadPfConceptContainer extends PfConceptContainer<DummyBadPfConcept, DummyAuthorativeConcept> {
+ private static final long serialVersionUID = -3018432331484294280L;
+
+
+ /**
+ * The Default Constructor creates a {@link DummyBadPfConceptContainer} object with a null artifact key
+ * and creates an empty concept map.
+ */
+ public DummyBadPfConceptContainer() {
+ super();
+ }
+
+ /**
+ * The Key Constructor creates a {@link DummyBadPfConceptContainer} object with the given artifact key and
+ * creates an empty concept map.
+ *
+ * @param key the concept key
+ */
+ public DummyBadPfConceptContainer(@NonNull final PfConceptKey key) {
+ super(key);
+ }
+
+ /**
+ * This Constructor creates an concept container with all of its fields defined.
+ *
+ * @param key the concept container key
+ * @param conceptMap the concepts to be stored in the concept container
+ */
+ public DummyBadPfConceptContainer(@NonNull final PfConceptKey key,
+ @NonNull final Map<PfConceptKey, DummyBadPfConcept> conceptMap) {
+ super(key, conceptMap);
+ }
+
+ /**
+ * Copy constructor.
+ *
+ * @param copyConcept the concept to copy from
+ */
+ public DummyBadPfConceptContainer(@NonNull final DummyBadPfConceptContainer copyConcept) {
+ super(copyConcept);
+ }
+
+}
diff --git a/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfConcept.java b/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfConcept.java
index 9fb6b5793..5e74fb2f9 100644
--- a/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfConcept.java
+++ b/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfConcept.java
@@ -30,6 +30,7 @@ import lombok.NonNull;
import org.apache.commons.lang3.ObjectUtils;
import org.onap.policy.common.utils.validation.Assertions;
+import org.onap.policy.models.base.PfAuthorative;
import org.onap.policy.models.base.PfConcept;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfKey;
@@ -39,13 +40,31 @@ import org.onap.policy.models.base.PfValidationResult.ValidationResult;
@Data
@EqualsAndHashCode(callSuper = false)
-public class DummyPfConcept extends PfConcept {
+public class DummyPfConcept extends PfConcept implements PfAuthorative<DummyAuthorativeConcept> {
private static final long serialVersionUID = 1L;
@EmbeddedId
private PfConceptKey key;
private String description;
+
+ @Override
+ public DummyAuthorativeConcept toAuthorative() {
+ DummyAuthorativeConcept dac = new DummyAuthorativeConcept();
+ dac.setName(key.getName());
+ dac.setVersion(key.getVersion());
+ dac.setDescription(description);
+
+ return dac;
+ }
+
+ @Override
+ public void fromAuthorative(DummyAuthorativeConcept dac) {
+ key.setName(dac.getName());
+ key.setVersion(dac.getVersion());
+ description = dac.getDescription();
+ }
+
/**
* The Default Constructor creates a {@link DummyPfConcept} object with a null key.
*/
diff --git a/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfConceptContainer.java b/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfConceptContainer.java
index ac72ef8f6..45de69e68 100644
--- a/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfConceptContainer.java
+++ b/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfConceptContainer.java
@@ -32,7 +32,7 @@ import org.onap.policy.models.base.PfConceptKey;
*
* @author Liam Fallon (liam.fallon@est.tech)
*/
-public class DummyPfConceptContainer extends PfConceptContainer<DummyPfConcept> {
+public class DummyPfConceptContainer extends PfConceptContainer<DummyPfConcept, DummyAuthorativeConcept> {
private static final long serialVersionUID = -3018432331484294280L;