summaryrefslogtreecommitdiffstats
path: root/models-tosca/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'models-tosca/src/test')
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaWithTypeAndObjectPropertiesTest.java (renamed from models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaWithObjectPropertiesTest.java)13
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityAssignmentTest.java28
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTest.java5
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaWithStringPropertiesTest.java28
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProviderTest.java16
5 files changed, 58 insertions, 32 deletions
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaWithObjectPropertiesTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaWithTypeAndObjectPropertiesTest.java
index 7186a3ff0..79fb26540 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaWithObjectPropertiesTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaWithTypeAndObjectPropertiesTest.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2021 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,19 +28,19 @@ import static org.junit.Assert.assertNotEquals;
import java.util.Map;
import org.junit.Test;
-public class ToscaWithObjectPropertiesTest {
+public class ToscaWithTypeAndObjectPropertiesTest {
@Test
public void testCopyConstructor() {
- ToscaWithObjectProperties tosca = new ToscaWithObjectProperties();
- assertEquals(tosca, new ToscaWithObjectProperties(tosca));
+ ToscaWithTypeAndObjectProperties tosca = new ToscaWithTypeAndObjectProperties();
+ assertEquals(tosca, new ToscaWithTypeAndObjectProperties(tosca));
tosca.setProperties(Map.of("abc", 10, "def", "world"));
- assertEquals(tosca, new ToscaWithObjectProperties(tosca));
+ assertEquals(tosca, new ToscaWithTypeAndObjectProperties(tosca));
- assertNotEquals(tosca, new ToscaWithObjectProperties());
+ assertNotEquals(tosca, new ToscaWithTypeAndObjectProperties());
- assertThatThrownBy(() -> new ToscaWithObjectProperties(null)).hasMessageContaining("copyObject")
+ assertThatThrownBy(() -> new ToscaWithTypeAndObjectProperties(null)).hasMessageContaining("copyObject")
.hasMessageContaining("is null");
}
}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityAssignmentTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityAssignmentTest.java
index 9637d4252..4fcdd8c0d 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityAssignmentTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityAssignmentTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2020 Nordix Foundation.
+ * Copyright (C) 2020-2021 Nordix Foundation.
* Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -44,10 +44,16 @@ public class JpaToscaCapabilityAssignmentTest {
@Test
public void testPropertyPojo() {
+ ToscaCapabilityAssignment tca = new ToscaCapabilityAssignment();
+ tca.setName("world");
+ tca.setVersion("1.2.3");
+ tca.setType("planet");
+ tca.setTypeVersion("4.5.6");
+
assertNotNull(new JpaToscaCapabilityAssignment());
assertNotNull(new JpaToscaCapabilityAssignment(new PfConceptKey()));
assertNotNull(new JpaToscaCapabilityAssignment(new JpaToscaCapabilityAssignment()));
- assertNotNull(new JpaToscaCapabilityAssignment(new ToscaCapabilityAssignment()));
+ assertNotNull(new JpaToscaCapabilityAssignment(tca));
assertThatThrownBy(() -> new JpaToscaCapabilityAssignment((PfConceptKey) null)).hasMessageMatching(KEY_IS_NULL);
assertThatThrownBy(() -> new JpaToscaCapabilityAssignment((JpaToscaCapabilityAssignment) null))
@@ -149,11 +155,19 @@ public class JpaToscaCapabilityAssignmentTest {
@Test
public void testAuthorative() {
- ToscaCapabilityAssignment tca =
- new JpaToscaCapabilityAssignment(new ToscaCapabilityAssignment()).toAuthorative();
+ ToscaCapabilityAssignment tca = new ToscaCapabilityAssignment();
+ tca.setName("world");
+ tca.setVersion("1.2.3");
+ tca.setType("planet");
+ tca.setTypeVersion("4.5.6");
+
+ ToscaCapabilityAssignment tcaConsTo =
+ new JpaToscaCapabilityAssignment(tca).toAuthorative();
+
+ assertEquals(tca, tcaConsTo);
- JpaToscaCapabilityAssignment jtca = new JpaToscaCapabilityAssignment(tca);
- ToscaCapabilityAssignment tca2 = jtca.toAuthorative();
- assertEquals(tca, tca2);
+ JpaToscaCapabilityAssignment jtca = new JpaToscaCapabilityAssignment(tcaConsTo);
+ ToscaCapabilityAssignment tcaFromTo = jtca.toAuthorative();
+ assertEquals(tca, tcaFromTo);
}
}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTest.java
index 48bcb0bee..b9adce195 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019-2020 Nordix Foundation.
+ * Copyright (C) 2019-2021 Nordix Foundation.
* Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -61,8 +61,7 @@ public class JpaToscaPolicyTest {
assertThatThrownBy(() -> {
new JpaToscaPolicy(pol);
}).hasMessage(
- "PolicyType version not specified, the version of the PolicyType for this policy must be specified in"
- + " the type_version field");
+ "Version not specified, the version of this TOSCA entity must be specified in the type_version field");
assertThatThrownBy(() -> {
new JpaToscaPolicy((PfConceptKey) null);
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaWithStringPropertiesTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaWithStringPropertiesTest.java
index 7cd6facf0..f232fcb7b 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaWithStringPropertiesTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaWithStringPropertiesTest.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2021 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -32,7 +33,7 @@ import org.junit.Before;
import org.junit.Test;
import org.onap.policy.common.parameters.annotations.NotNull;
import org.onap.policy.models.base.PfConceptKey;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaWithObjectProperties;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaWithTypeAndObjectProperties;
public class JpaToscaWithStringPropertiesTest {
private static final String SOME_DESCRIPTION = "some description";
@@ -53,13 +54,14 @@ public class JpaToscaWithStringPropertiesTest {
@Test
public void testGetKeys() {
PfConceptKey key = new PfConceptKey("bye", "9.8.7");
+ PfConceptKey typeKey = new PfConceptKey("type", "6.5.4");
- jpa = new MyJpa(key);
+ jpa = new MyJpa(key, typeKey);
jpa.setDescription(SOME_DESCRIPTION);
jpa.setProperties(Map.of(KEY1, STRING1, KEY2, STRING2));
// properties should be ignored
- assertThat(jpa.getKeys()).isEqualTo(List.of(key));
+ assertThat(jpa.getKeys()).isEqualTo(List.of(key, typeKey));
}
@Test
@@ -85,6 +87,8 @@ public class JpaToscaWithStringPropertiesTest {
@Test
public void testFromAuthorative() {
MyTosca tosca = new MyTosca();
+ tosca.setType("type");
+ tosca.setTypeVersion("1.2.3");
tosca.setDescription(SOME_DESCRIPTION);
jpa.fromAuthorative(tosca);
@@ -144,6 +148,8 @@ public class JpaToscaWithStringPropertiesTest {
MyTosca tosca = new MyTosca();
tosca.setName("world");
tosca.setVersion("3.2.1");
+ tosca.setType("planet");
+ tosca.setTypeVersion("6.5.4");
tosca.setDescription(SOME_DESCRIPTION);
tosca.setProperties(Map.of(KEY1, INT1, KEY2, INT2));
@@ -151,6 +157,7 @@ public class JpaToscaWithStringPropertiesTest {
assertEquals(SOME_DESCRIPTION, jpa.getDescription());
assertThat(jpa.getProperties()).isEqualTo(Map.of(KEY1, STRING1, KEY2, STRING2));
assertEquals(new PfConceptKey("world", "3.2.1"), jpa.getKey());
+ assertEquals(new PfConceptKey("planet", "6.5.4"), jpa.getType());
}
@Test
@@ -159,8 +166,12 @@ public class JpaToscaWithStringPropertiesTest {
jpa.setText("some text");
assertThat(jpa.validateWithKey("fieldA").isValid()).isFalse();
- // valid
+ // not valid, type is not set
jpa.setKey(new PfConceptKey("xyz", "2.3.4"));
+ assertThat(jpa.validateWithKey("fieldB").isValid()).isFalse();
+
+ // valid, type is set
+ jpa.setType(new PfConceptKey("uvw", "5.6.7"));
assertThat(jpa.validateWithKey("fieldB").isValid()).isTrue();
// null text - bean validator should fail
@@ -168,12 +179,11 @@ public class JpaToscaWithStringPropertiesTest {
assertThat(jpa.validateWithKey("fieldA").isValid()).isFalse();
}
- private static class MyTosca extends ToscaWithObjectProperties {
-
+ private static class MyTosca extends ToscaWithTypeAndObjectProperties {
}
@NoArgsConstructor
- protected static class MyJpa extends JpaToscaWithStringProperties<MyTosca> {
+ protected static class MyJpa extends JpaToscaWithTypeAndStringProperties<MyTosca> {
private static final long serialVersionUID = 1L;
@NotNull
@@ -189,6 +199,10 @@ public class JpaToscaWithStringPropertiesTest {
super(key);
}
+ public MyJpa(PfConceptKey key, PfConceptKey type) {
+ super(key, type);
+ }
+
public MyJpa(MyTosca tosca) {
super(tosca);
}
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 a926ca149..07624aeee 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
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019-2020 Nordix Foundation.
+ * Copyright (C) 2019-2021 Nordix Foundation.
* Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -400,13 +400,12 @@ public class SimpleToscaProviderTest {
assertThatThrownBy(() -> {
originalServiceTemplate.fromAuthorative(toscaServiceTemplate);
- }).hasMessage("PolicyType type not specified, the type of the PolicyType for this policy must be "
- + "specified in the type field");
+ }).hasMessage("Type not specified, the type of this TOSCA entity must be specified in the type field");
toscaPolicy.setType("IDontExist");
assertThatThrownBy(() -> {
originalServiceTemplate.fromAuthorative(toscaServiceTemplate);
- }).hasMessage("PolicyType version not specified, the version of the PolicyType for this policy must be "
+ }).hasMessage("Version not specified, the version of this TOSCA entity must be "
+ "specified in the type_version field");
toscaPolicy.setTypeVersion("hello");
@@ -420,7 +419,7 @@ public class SimpleToscaProviderTest {
assertThatThrownBy(() -> {
new SimpleToscaProvider().createPolicies(pfDao, originalServiceTemplate);
}).hasMessageContaining("policy type").hasMessageContaining("IDontExist:99.100.101")
- .hasMessageContaining(Validated.NOT_FOUND);
+ .hasMessageContaining(Validated.NOT_FOUND);
toscaPolicy.setType("IDontExist");
originalServiceTemplate.fromAuthorative(toscaServiceTemplate);
@@ -429,8 +428,7 @@ public class SimpleToscaProviderTest {
assertThatThrownBy(() -> {
originalServiceTemplate.fromAuthorative(toscaServiceTemplate);
- }).hasMessage("PolicyType type not specified, the type of the PolicyType for this policy must be "
- + "specified in the type field");
+ }).hasMessage("Type not specified, the type of this TOSCA entity must be specified in the type field");
toscaPolicy.setType(originalPolicyType);
toscaPolicy.setTypeVersion(originalPolicyTypeVersion);
@@ -525,8 +523,8 @@ public class SimpleToscaProviderTest {
serviceTemplateFragment.getPolicyTypes().getConceptMap().put(badPt.getKey(), badPt);
assertThatThrownBy(() -> new SimpleToscaProvider().appendToServiceTemplate(pfDao, serviceTemplateFragment))
- .hasMessageContaining("key on concept entry").hasMessageContaining("NULL:0.0.0")
- .hasMessageContaining(Validated.IS_A_NULL_KEY);
+ .hasMessageContaining("key on concept entry").hasMessageContaining("NULL:0.0.0")
+ .hasMessageContaining(Validated.IS_A_NULL_KEY);
}
@Test