Remove usage of outdated library JMockit (catalog-dao)
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / components / impl / ImportUtilsTest.java
index e47cdc9..9cd095b 100644 (file)
 
 package org.openecomp.sdc.be.components.impl;
 
+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 com.google.common.collect.Lists;
 import fj.data.Either;
+import java.io.IOException;
+import java.nio.file.FileSystems;
+import java.nio.file.Files;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
 import org.junit.Test;
 import org.mockito.Mockito;
 import org.openecomp.sdc.be.components.impl.ImportUtils.ResultStatusEnum;
 import org.openecomp.sdc.be.components.impl.ImportUtils.ToscaElementTypeEnum;
+import org.openecomp.sdc.be.datatypes.elements.AttributeDataDefinition;
 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
 import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
+import org.openecomp.sdc.be.model.AttributeDefinition;
 import org.openecomp.sdc.be.model.HeatParameterDefinition;
 import org.openecomp.sdc.be.model.InputDefinition;
 import org.openecomp.sdc.be.model.PropertyConstraint;
@@ -38,21 +54,6 @@ import org.openecomp.sdc.be.utils.TypeUtils;
 import org.openecomp.sdc.common.api.ArtifactTypeEnum;
 import org.yaml.snakeyaml.Yaml;
 
-import java.io.IOException;
-import java.nio.file.FileSystems;
-import java.nio.file.Files;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
 public class ImportUtilsTest {
 
 
@@ -301,17 +302,6 @@ public class ImportUtilsTest {
 
     }
 
-    @Test
-    public void testGetAttributesFromYml() throws IOException {
-
-        Map<String, Object> toscaJson = (Map<String, Object>) loadJsonFromFile("importToscaWithAttribute.yml");
-        Either<Map<String, PropertyDefinition>, ResultStatusEnum> actualAttributes = ImportUtils.getAttributes(toscaJson);
-        assertTrue(actualAttributes.isLeft());
-        Map<String, Map<String, Object>> expectedAttributes = getElements(toscaJson, TypeUtils.ToscaTagNamesEnum.ATTRIBUTES);
-        compareAttributes(expectedAttributes, actualAttributes.left().value());
-
-    }
-
     @Test
     public void testGetPropertiesFromYml() throws IOException {
 
@@ -334,7 +324,7 @@ public class ImportUtilsTest {
         PropertyDefinition property = properties.get("service_type");
         assertTrue(property.getConstraints()!= null && property.getConstraints().size() == 1);
         assertTrue(property.getConstraints().get(0) instanceof ValidValuesConstraint);
-        assertTrue(((ValidValuesConstraint) property.getConstraints().get(0)).getValidValues() != null);
+        assertNotNull(((ValidValuesConstraint) property.getConstraints().get(0)).getValidValues());
         List<String> validValues = ((ValidValuesConstraint) property.getConstraints().get(0)).getValidValues();
         assertTrue(validValues.containsAll(Lists.newArrayList("firewall", "analyzer", "source-nat", "loadbalancer")));
 
@@ -344,7 +334,7 @@ public class ImportUtilsTest {
         PropertyDefinition innerProperty = new PropertyDefinition(property.getSchema().getProperty());
         List<PropertyConstraint> innerConstraints = innerProperty.getConstraints();
         assertTrue(innerConstraints.get(0) instanceof ValidValuesConstraint);
-        assertTrue(((ValidValuesConstraint) innerConstraints.get(0)).getValidValues() != null);
+        assertNotNull(((ValidValuesConstraint) innerConstraints.get(0)).getValidValues());
         validValues = ((ValidValuesConstraint) innerConstraints.get(0)).getValidValues();
         assertTrue(validValues.containsAll(Lists.newArrayList("management", "left", "right", "other")));
     }
@@ -362,12 +352,16 @@ public class ImportUtilsTest {
         Map<String, Map<String, Object>> expectedProperties = getElements(toscaJson, TypeUtils.ToscaTagNamesEnum.INPUTS);
         compareProperties(expectedProperties, actualInputs.left().value());
 
+        actualInputs = ImportUtils.getInputs(toscaJson);
+        assertTrue(actualInputs.isLeft());
+        expectedProperties = getElements(toscaJson, TypeUtils.ToscaTagNamesEnum.INPUTS);
+        compareProperties(expectedProperties, actualInputs.left().value());
     }
 
-    private void compareAttributes(Map<String, Map<String, Object>> expected, Map<String, PropertyDefinition> actual) {
+    private void compareAttributes(Map<String, Map<String, Object>> expected, Map<String, AttributeDataDefinition> actual) {
 
         Map<String, Object> singleExpectedAttribute;
-        PropertyDefinition actualAttribute, expectedAttributeModel;
+        AttributeDataDefinition actualAttribute, expectedAttributeModel;
         // attributes of resource
         for (Map.Entry<String, Map<String, Object>> expectedAttribute : expected.entrySet()) {
 
@@ -379,11 +373,11 @@ public class ImportUtilsTest {
             expectedAttributeModel = ImportUtils.createModuleAttribute(singleExpectedAttribute);
             expectedAttributeModel.setName(expectedAttribute.getKey().toString());
 
-            assertEquals(expectedAttributeModel.getDefaultValue(), actualAttribute.getDefaultValue());
-            assertEquals(expectedAttributeModel.getDescription(), actualAttribute.getDescription());
-            assertEquals(expectedAttributeModel.getName(), actualAttribute.getName());
-            assertEquals(expectedAttributeModel.getStatus(), actualAttribute.getStatus());
-            assertEquals(expectedAttributeModel.getType(), actualAttribute.getType());
+            assertEquals(((AttributeDefinition)expectedAttributeModel).getDefaultValue(), ((AttributeDefinition)actualAttribute).getDefaultValue());
+            assertEquals(((AttributeDefinition)expectedAttributeModel).getDescription(), ((AttributeDefinition)actualAttribute).getDescription());
+            assertEquals(((AttributeDefinition)expectedAttributeModel).getName(), ((AttributeDefinition)actualAttribute).getName());
+            assertEquals(((AttributeDefinition)expectedAttributeModel).getStatus(), ((AttributeDefinition)actualAttribute).getStatus());
+            assertEquals(((AttributeDefinition)expectedAttributeModel).getType(), ((AttributeDefinition)actualAttribute).getType());
 
             compareSchemas(expectedAttributeModel.getSchema(), actualAttribute.getSchema());