summaryrefslogtreecommitdiffstats
path: root/catalog-model/src/test
diff options
context:
space:
mode:
authorTomasz Golabek <tomasz.golabek@nokia.com>2019-09-03 10:02:44 +0200
committerTomasz Golabek <tomasz.golabek@nokia.com>2019-09-03 08:41:42 +0000
commite0e8abb537d1230e4278f47db6c41e7121cd19f4 (patch)
tree6b18b0ad82f49a72a91adab873b85da46a5dc9f5 /catalog-model/src/test
parent6c4fe4d6157352eadc47ef72b9a76b0cbdb0f94e (diff)
unit tests - catalog-model
Additional junit tests for be-model Change-Id: I7364cd33411d7f6eb69f9a02b2aea889c594ea7b Issue-ID: SDC-2326 Signed-off-by: Tomasz Golabek <tomasz.golabek@nokia.com>
Diffstat (limited to 'catalog-model/src/test')
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/CapabilityDefinitionTest.java143
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/CapabilityTypeDefinitionTest.java92
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/ComponentInstListInputTest.java32
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/UploadNodeFilterInfoTest.java32
4 files changed, 182 insertions, 117 deletions
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/CapabilityDefinitionTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/CapabilityDefinitionTest.java
index b82c0c634b..41de118272 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/CapabilityDefinitionTest.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/CapabilityDefinitionTest.java
@@ -16,92 +16,113 @@
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
+ * Modifications copyright (c) 2019 Nokia
+ * ================================================================================
*/
-
package org.openecomp.sdc.be.model;
-import org.junit.Test;
-import org.openecomp.sdc.be.datatypes.elements.CapabilityDataDefinition;
-
-import java.util.LinkedList;
-import java.util.List;
+import static com.google.code.beanmatchers.BeanMatchers.hasValidBeanEqualsFor;
+import static com.google.code.beanmatchers.BeanMatchers.hasValidBeanHashCodeFor;
+import static com.google.code.beanmatchers.BeanMatchers.hasValidBeanToStringFor;
+import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSettersExcluding;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+import java.util.ArrayList;
+import java.util.HashMap;
+import org.junit.Test;
+import org.openecomp.sdc.be.datatypes.elements.CapabilityDataDefinition.OwnerType;
+import org.openecomp.sdc.be.model.tosca.constraints.EqualConstraint;
public class CapabilityDefinitionTest {
- private CapabilityDefinition createTestSubject() {
- return new CapabilityDefinition();
- }
+ private static final String OWNER_NAME = "OWNER";
+ private static final String OWNER_ID = "OWNER_ID";
+ private static final String NAME = "NAME";
+ private static final OwnerType OWNER_TYPE = OwnerType.COMPONENT_INSTANCE;
+ private static final String PROP = "PROP";
+ private static final String EQ = "eq";
+ private static final String PROPERTIES = "properties";
+ private static final String VALUE = "VALUE";
@Test
- public void testCtor() throws Exception {
- CapabilityDefinition other = new CapabilityDefinition();
- new CapabilityDefinition(other);
- other.setProperties(new LinkedList<>());
- new CapabilityDefinition(other);
- new CapabilityDefinition(new CapabilityDataDefinition());
+ public void hasValidGettersAndSettersTest() {
+ assertThat(CapabilityDefinition.class,
+ hasValidGettersAndSettersExcluding("empty", "ownerIdIfEmpty", "version"));
}
-
- @Test
- public void testHashCode() throws Exception {
- CapabilityDefinition testSubject;
- int result;
- // default test
- testSubject = createTestSubject();
- result = testSubject.hashCode();
+ @Test
+ public void shouldHaveValidToString() {
+ assertThat(CapabilityDefinition.class, hasValidBeanToStringFor(PROPERTIES));
}
-
@Test
- public void testEquals() throws Exception {
- CapabilityDefinition testSubject;
- Object obj = null;
- boolean result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.equals(obj);
- result = testSubject.equals(new Object());
- result = testSubject.equals(testSubject);
- CapabilityDefinition createTestSubject = createTestSubject();
- result = testSubject.equals(createTestSubject);
- createTestSubject.setProperties(new LinkedList<>());
- result = testSubject.equals(createTestSubject);
- testSubject.setProperties(new LinkedList<>());
- result = testSubject.equals(createTestSubject);
+ public void shouldHaveEquals() {
+ assertThat(CapabilityDefinition.class, hasValidBeanEqualsFor(PROPERTIES));
}
-
@Test
- public void testToString() throws Exception {
- CapabilityDefinition testSubject;
- String result;
+ public void shouldHaveHashCode() {
+ assertThat(CapabilityDefinition.class, hasValidBeanHashCodeFor(PROPERTIES));
+ }
- // default test
- testSubject = createTestSubject();
- result = testSubject.toString();
+ @Test
+ public void testParamConstructor() {
+ EqualConstraint equalConstraint = new EqualConstraint(EQ);
+ CapabilityDefinition capabilityDefinition = createCapabilityDefinition(equalConstraint);
+ assertEquals(capabilityDefinition.getOwnerName(), OWNER_NAME);
+ assertEquals(capabilityDefinition.getProperties().get(0).getConstraints().get(0), equalConstraint);
+ assertEquals(capabilityDefinition.getName(), NAME);
+ assertEquals(capabilityDefinition.getOwnerType(), OWNER_TYPE);
}
-
@Test
- public void testGetProperties() throws Exception {
- CapabilityDefinition testSubject;
- List<ComponentInstanceProperty> result;
+ public void testCopyConstructor() {
+ EqualConstraint equalConstraint = new EqualConstraint(EQ);
+ CapabilityDefinition capabilityDefinition = createCapabilityDefinition(equalConstraint);
+ CapabilityDefinition copiedCapabilityDefinition = new CapabilityDefinition(capabilityDefinition);
+ assertEquals(copiedCapabilityDefinition.getOwnerName(), OWNER_NAME);
+ assertEquals(copiedCapabilityDefinition.getProperties().get(0).getConstraints().get(0), equalConstraint);
+ assertEquals(copiedCapabilityDefinition.getName(), NAME);
+ assertEquals(copiedCapabilityDefinition.getOwnerType(), OWNER_TYPE);
+ }
- // default test
- testSubject = createTestSubject();
- result = testSubject.getProperties();
+ @Test
+ public void shouldUpdateCapabilityProperties() {
+ EqualConstraint equalConstraint = new EqualConstraint(EQ);
+ CapabilityDefinition referenceCapabilityDefinition = createCapabilityDefinition(equalConstraint);
+ CapabilityDefinition capabilityDefinition = new CapabilityDefinition();
+ ArrayList<ComponentInstanceProperty> properties = new ArrayList<>();
+ ComponentInstanceProperty componentInstanceProperty = new ComponentInstanceProperty();
+ componentInstanceProperty.setName(NAME);
+ properties.add(componentInstanceProperty);
+ capabilityDefinition.setProperties(properties);
+ capabilityDefinition.updateCapabilityProperties(referenceCapabilityDefinition);
+ assertEquals(capabilityDefinition.getProperties().get(0).getValue(), VALUE);
}
-
@Test
- public void testSetProperties() throws Exception {
- CapabilityDefinition testSubject;
- List<ComponentInstanceProperty> properties = null;
+ public void shouldUpdateEmptyCapabilityOwnerFields() {
+ CapabilityDefinition capabilityDefinition = new CapabilityDefinition();
+ capabilityDefinition.updateEmptyCapabilityOwnerFields(OWNER_ID, OWNER_NAME, OWNER_TYPE);
+ assertEquals(capabilityDefinition.getOwnerName(), OWNER_NAME);
+ assertEquals(capabilityDefinition.getOwnerType(), OWNER_TYPE);
+ assertEquals(capabilityDefinition.getOwnerId(), OWNER_ID);
+ }
- // default test
- testSubject = createTestSubject();
- testSubject.setProperties(properties);
+ private CapabilityDefinition createCapabilityDefinition(EqualConstraint equalConstraint){
+ CapabilityTypeDefinition capabilityTypeDefinition = new CapabilityTypeDefinition();
+ HashMap<String, PropertyDefinition> properties = new HashMap<>();
+ PropertyDefinition propertyDefinition = new PropertyDefinition();
+ ArrayList<PropertyConstraint> constraints = new ArrayList<>();
+ constraints.add(equalConstraint);
+ propertyDefinition.setConstraints(constraints);
+ propertyDefinition.setName(NAME);
+ propertyDefinition.setValue(VALUE);
+ properties.put(PROP, propertyDefinition);
+ capabilityTypeDefinition.setProperties(properties);
+ return new CapabilityDefinition(capabilityTypeDefinition, OWNER_NAME, NAME,
+ OWNER_TYPE);
}
+
}
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/CapabilityTypeDefinitionTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/CapabilityTypeDefinitionTest.java
index 9195750f5a..2a90d937dc 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/CapabilityTypeDefinitionTest.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/CapabilityTypeDefinitionTest.java
@@ -16,78 +16,58 @@
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
+ * Modifications copyright (c) 2019 Nokia
+ * ================================================================================
*/
package org.openecomp.sdc.be.model;
+import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSettersExcluding;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+
+import java.util.Collections;
import org.junit.Test;
+import org.openecomp.sdc.be.datatypes.elements.CapabilityDataDefinition.OwnerType;
import org.openecomp.sdc.be.datatypes.elements.CapabilityTypeDataDefinition;
-
-import java.util.Map;
-
+import org.openecomp.sdc.be.resources.data.CapabilityTypeData;
public class CapabilityTypeDefinitionTest {
- private CapabilityTypeDefinition createTestSubject() {
- return new CapabilityTypeDefinition();
- }
-
- @Test
- public void testCtor() throws Exception {
- new CapabilityTypeDefinition(new CapabilityTypeDataDefinition());
- }
-
- @Test
- public void testGetDerivedFrom() throws Exception {
- CapabilityTypeDefinition testSubject;
- String result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getDerivedFrom();
- }
+ private static final String OWNER_NAME = "ownerName";
+ private static final String NAME = "name";
+ private static final OwnerType RESOURCE = OwnerType.RESOURCE;
+ private static final String TYPE = "TYPE";
+ private static final String DESCRIPTION = "DESCRIPTION";
+ private static final String UNIQUE_ID = "UNIQUE_ID";
-
@Test
- public void testSetDerivedFrom() throws Exception {
- CapabilityTypeDefinition testSubject;
- String derivedFrom = "";
-
- // default test
- testSubject = createTestSubject();
- testSubject.setDerivedFrom(derivedFrom);
+ public void hasValidGettersAndSettersTest() {
+ assertThat(CapabilityTypeDefinition.class,
+ hasValidGettersAndSettersExcluding("empty", "ownerIdIfEmpty"));
}
-
@Test
- public void testGetProperties() throws Exception {
- CapabilityTypeDefinition testSubject;
- Map<String, PropertyDefinition> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getProperties();
+ public void shouldHaveValidToString() {
+ CapabilityDefinition capabilityDefinition = new CapabilityDefinition(
+ new CapabilityTypeDefinition(), OWNER_NAME, NAME, RESOURCE);
+ capabilityDefinition.setProperties(Collections.emptyList());
+ capabilityDefinition.setType(TYPE);
+ capabilityDefinition.setDescription(DESCRIPTION);
+ CapabilityTypeDefinition capabilityTypeDefinitionTest = new CapabilityTypeDefinition(capabilityDefinition);
+ String toStringRepr = capabilityTypeDefinitionTest.toString();
+ assertEquals(toStringRepr, "CapabilityTypeDataDefinition [uniqueId=null, description=DESCRIPTION, type=TYPE, validSourceTypes=[], version=null, creationTime=null, modificationTime=null] [ derivedFrom=null, properties={} ]");
}
-
@Test
- public void testSetProperties() throws Exception {
- CapabilityTypeDefinition testSubject;
- Map<String, PropertyDefinition> properties = null;
-
- // default test
- testSubject = createTestSubject();
- testSubject.setProperties(properties);
- }
-
-
- @Test
- public void testToString() throws Exception {
- CapabilityTypeDefinition testSubject;
- String result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.toString();
+ public void shouldCreateCapabilityTypeDefinitionFromCapabilityTypeData() {
+ CapabilityTypeData capabilityTypeData = new CapabilityTypeData();
+ CapabilityTypeDataDefinition capabilityTypeDataDefinition = new CapabilityTypeDataDefinition();
+ capabilityTypeDataDefinition.setUniqueId(UNIQUE_ID);
+ capabilityTypeDataDefinition.setType(TYPE);
+ capabilityTypeData.setCapabilityTypeDataDefinition(capabilityTypeDataDefinition);
+ CapabilityTypeDefinition capabilityTypeDefinition = new CapabilityTypeDefinition(capabilityTypeData);
+ assertEquals(capabilityTypeDefinition.getType(), capabilityTypeData.getCapabilityTypeDataDefinition().getType());
+ assertEquals(capabilityTypeDefinition.getUniqueId(), capabilityTypeData.getCapabilityTypeDataDefinition().getUniqueId());
}
}
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/ComponentInstListInputTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/ComponentInstListInputTest.java
new file mode 100644
index 0000000000..46ba49d259
--- /dev/null
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/ComponentInstListInputTest.java
@@ -0,0 +1,32 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2019 Nokia. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.openecomp.sdc.be.model;
+
+import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSetters;
+import static org.junit.Assert.assertThat;
+
+import org.junit.Test;
+
+public class ComponentInstListInputTest {
+ @Test
+ public void shouldHaveValidGettersAndSetters() {
+ assertThat(ComponentInstListInput.class, hasValidGettersAndSetters());
+ }
+} \ No newline at end of file
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/UploadNodeFilterInfoTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/UploadNodeFilterInfoTest.java
new file mode 100644
index 0000000000..c412fd2598
--- /dev/null
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/UploadNodeFilterInfoTest.java
@@ -0,0 +1,32 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2019 Nokia. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.openecomp.sdc.be.model;
+
+import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSetters;
+import static org.junit.Assert.assertThat;
+
+import org.junit.Test;
+
+public class UploadNodeFilterInfoTest {
+ @Test
+ public void shouldHaveValidGettersAndSetters() {
+ assertThat(UploadNodeFilterInfo.class, hasValidGettersAndSetters());
+ }
+} \ No newline at end of file