Reduce usage of outdated library JMockit (catalog-dao) 73/122173/3
authorvasraz <vasyl.razinkov@est.tech>
Sat, 19 Jun 2021 12:53:06 +0000 (13:53 +0100)
committerChristophe Closset <christophe.closset@intl.att.com>
Mon, 5 Jul 2021 09:21:17 +0000 (09:21 +0000)
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech>
Issue-ID: SDC-3379
Change-Id: I6b46049b71eafbfedfd3d40c68c743efff13ef54

catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/tables/DistribStatusEventTableDesc.java
catalog-dao/src/main/java/org/openecomp/sdc/be/dao/utils/JsonUtil.java
catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/CategoryData.java
catalog-dao/src/test/java/org/openecomp/sdc/be/dao/cassandra/schema/tables/DistribStatusEventTableDescTest.java
catalog-dao/src/test/java/org/openecomp/sdc/be/dao/graph/GraphElementFactoryTest.java
catalog-dao/src/test/java/org/openecomp/sdc/be/dao/utils/JsonUtilTest.java
catalog-dao/src/test/java/org/openecomp/sdc/be/resources/data/ServiceCategoryDataTest.java

index 7e64605..ff40d06 100644 (file)
@@ -21,14 +21,16 @@ package org.openecomp.sdc.be.dao.cassandra.schema.tables;
 
 import com.datastax.driver.core.DataType;
 import java.util.Map;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
 import org.apache.commons.lang3.tuple.ImmutablePair;
 import org.openecomp.sdc.be.resources.data.auditing.AuditingTypesConstants;
 
 public class DistribStatusEventTableDesc extends DistribBaseEventTableDesc {
 
     @Override
-    protected void updateColumnDistribDescription(Map<String, ImmutablePair<DataType, Boolean>> columns) {
-        for (DSEFieldsDescription field : DSEFieldsDescription.values()) {
+    protected void updateColumnDistribDescription(final Map<String, ImmutablePair<DataType, Boolean>> columns) {
+        for (final DSEFieldsDescription field : DSEFieldsDescription.values()) {
             columns.put(field.getName(), new ImmutablePair<>(field.type, field.indexed));
         }
     }
@@ -38,7 +40,9 @@ public class DistribStatusEventTableDesc extends DistribBaseEventTableDesc {
         return AuditingTypesConstants.DISTRIBUTION_STATUS_EVENT_TYPE;
     }
 
-    enum DSEFieldsDescription {
+    @Getter
+    @AllArgsConstructor
+    private enum DSEFieldsDescription {
         // @formatter:off
         DID("did", DataType.varchar(), true),
         CONSUMER_ID("consumer_id", DataType.varchar(), false),
@@ -47,26 +51,9 @@ public class DistribStatusEventTableDesc extends DistribBaseEventTableDesc {
         STATUS_TIME("status_time", DataType.varchar(), false);
         // @formatter:on
 
-        private String name;
-        private DataType type;
-        private boolean indexed;
+        private final String name;
+        private final DataType type;
+        private final boolean indexed;
 
-        DSEFieldsDescription(String name, DataType type, boolean indexed) {
-            this.name = name;
-            this.type = type;
-            this.indexed = indexed;
-        }
-
-        public String getName() {
-            return name;
-        }
-
-        public DataType getType() {
-            return type;
-        }
-
-        public boolean isIndexed() {
-            return indexed;
-        }
     }
 }
index ebcb1d5..8153d44 100644 (file)
@@ -139,10 +139,4 @@ public final class JsonUtil {
         return mapper.readValue(json, type);
     }
 
-    public static <T> List<T> toList(String json, Class<T> elementClass, Class<?> elementGenericClass) throws IOException {
-        ObjectMapper mapper = getOneObjectMapper();
-        JavaType elementType = mapper.getTypeFactory().constructParametricType(elementClass, elementGenericClass);
-        JavaType listType = mapper.getTypeFactory().constructCollectionType(List.class, elementType);
-        return mapper.readValue(json, listType);
-    }
 }
index 229d774..f4f9294 100644 (file)
@@ -21,10 +21,16 @@ package org.openecomp.sdc.be.resources.data;
 
 import java.util.HashMap;
 import java.util.Map;
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
 import org.openecomp.sdc.be.dao.graph.datatype.GraphNode;
 import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
 
+@Getter
+@Setter
+@ToString
 public abstract class CategoryData extends GraphNode {
 
     private String name;
@@ -59,38 +65,9 @@ public abstract class CategoryData extends GraphNode {
         return map;
     }
 
-    public String getName() {
-        return name;
-    }
-
-    public void setName(String name) {
-        this.name = name;
-    }
-
-    public String getNormalizedName() {
-        return normalizedName;
-    }
-
-    public void setNormalizedName(String normalizedName) {
-        this.normalizedName = normalizedName;
-    }
-
-    @Override
-    public String toString() {
-        return "CategoryData [name=" + name + ", normalizedName=" + normalizedName + "uniqueId=" + uniqueId + "]";
-    }
-
     @Override
     public String getUniqueIdKey() {
         return GraphPropertiesDictionary.UNIQUE_ID.getProperty();
     }
 
-    @Override
-    public String getUniqueId() {
-        return uniqueId;
-    }
-
-    public void setUniqueId(String uniqueId) {
-        this.uniqueId = uniqueId;
-    }
 }
index 34529f2..036b86e 100644 (file)
@@ -7,9 +7,9 @@
  * 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.
 package org.openecomp.sdc.be.dao.cassandra.schema.tables;
 
 import com.datastax.driver.core.DataType;
-import mockit.Deencapsulation;
-import org.apache.commons.lang3.tuple.ImmutablePair;
-import org.junit.Test;
-import org.openecomp.sdc.be.dao.cassandra.schema.tables.DistribStatusEventTableDesc.DSEFieldsDescription;
-
-import java.util.HashMap;
 import java.util.Map;
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingTypesConstants;
+
+class DistribStatusEventTableDescTest {
+
+    private DistribStatusEventTableDesc createTestSubject() {
+        return new DistribStatusEventTableDesc();
+    }
+
+    @Test
+    void testUpdateColumnDistribDescription() throws Exception {
+        final DistribStatusEventTableDesc testSubject = createTestSubject();
+        final Map<String, ImmutablePair<DataType, Boolean>> columnDescription = testSubject.getColumnDescription();
+        Assertions.assertNotNull(columnDescription);
+        Assertions.assertEquals(10, columnDescription.size());
+    }
+
+    @Test
+    void testGetTableName() throws Exception {
+        final DistribStatusEventTableDesc testSubject = createTestSubject();
+        Assertions.assertEquals(AuditingTypesConstants.DISTRIBUTION_STATUS_EVENT_TYPE, testSubject.getTableName());
+    }
 
-public class DistribStatusEventTableDescTest {
-
-       private DistribStatusEventTableDesc createTestSubject() {
-               return new DistribStatusEventTableDesc();
-       }
-
-       @Test
-       public void testUpdateColumnDistribDescription() throws Exception {
-               DistribStatusEventTableDesc testSubject;
-               Map<String, ImmutablePair<DataType, Boolean>> columns = new HashMap<>();
-
-               // default test
-               testSubject = createTestSubject();
-               Deencapsulation.invoke(testSubject, "updateColumnDistribDescription", columns);
-       }
-
-       @Test
-       public void testGetTableName() throws Exception {
-               DistribStatusEventTableDesc testSubject;
-               String result;
-
-               // default test
-               testSubject = createTestSubject();
-               result = testSubject.getTableName();
-       }
-       
-       @Test
-       public void testDSEFieldsDescription() throws Exception {
-               DSEFieldsDescription testSubject = DistribStatusEventTableDesc.DSEFieldsDescription.CONSUMER_ID;
-               
-               testSubject.getName();
-               testSubject.getType();
-               testSubject.isIndexed();
-       }
 }
index 931186d..4156c41 100644 (file)
@@ -7,9 +7,9 @@
  * 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.
 
 package org.openecomp.sdc.be.dao.graph;
 
-import mockit.Deencapsulation;
-import org.junit.Test;
+import static org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum.AnnotationType;
+import static org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum.Component;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
 import org.mockito.Mockito;
 import org.openecomp.sdc.be.config.ConfigurationManager;
 import org.openecomp.sdc.be.dao.graph.datatype.GraphElementTypeEnum;
 import org.openecomp.sdc.be.dao.graph.datatype.GraphNode;
 import org.openecomp.sdc.be.dao.graph.datatype.GraphRelation;
+import org.openecomp.sdc.be.dao.graph.datatype.RelationEndPoint;
 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
 import org.openecomp.sdc.common.api.ConfigurationSource;
 import org.openecomp.sdc.common.impl.ExternalConfiguration;
 import org.openecomp.sdc.common.impl.FSConfigurationSource;
 
-import java.util.HashMap;
-import java.util.Map;
-
-public class GraphElementFactoryTest {
-
-       private static ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(),
-                       "src/test/resources/config/catalog-dao");
-       private static ConfigurationManager configurationManager = new ConfigurationManager(configurationSource);
-
-       @Test
-       public void testCreateElement() throws Exception {
-               String label = "mock";
-               Map<String, Object> properties = new HashMap<>();
-               Class<GraphNode> clazz = (Class<GraphNode>) (Mockito.mock(GraphNode.class)).getClass();
-
-               // default test
-               GraphElementFactory.createElement(label, GraphElementTypeEnum.Node, properties, clazz);
-       }
-
-       @Test
-       public void testCreateElement_1() throws Exception {
-               String label = "mock";
-               GraphElementTypeEnum type = null;
-               Map<String, Object> properties = new HashMap<>();
-               GraphNode result;
+class GraphElementFactoryTest {
 
-               // default test
-               result = GraphElementFactory.createElement(label, GraphElementTypeEnum.Node, properties);
-       }
+    private static ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(),
+        "src/test/resources/config/catalog-dao");
+    private static ConfigurationManager configurationManager = new ConfigurationManager(configurationSource);
 
-       @Test
-       public void testCreateRelation() throws Exception {
-               String type = "";
-               Map<String, Object> properties = new HashMap<>();
-               GraphNode from = Mockito.mock(GraphNode.class);
-               GraphNode to = Mockito.mock(GraphNode.class);
-               ;
-               GraphRelation result;
+    @Test
+    void testCreateElement() throws Exception {
+        Map<String, Object> properties = new HashMap<>();
+        Arrays.stream(NodeTypeEnum.values()).filter(nodeTypeEnum -> !nodeTypeEnum.equals(AnnotationType) && !nodeTypeEnum.equals(Component))
+            .forEach(nodeTypeEnum -> {
+                Assertions.assertTrue(GraphElementFactory
+                    .createElement(nodeTypeEnum.getName(), GraphElementTypeEnum.Node, properties, GraphNode.class) instanceof GraphNode);
+            });
+        Assertions.assertNull(GraphElementFactory.createElement(Component.getName(), GraphElementTypeEnum.Node, properties, GraphNode.class));
+        Assertions.assertThrows(NullPointerException.class,
+            () -> GraphElementFactory.createElement(AnnotationType.getName(), GraphElementTypeEnum.Node, properties, GraphNode.class));
+    }
 
-               // default test
-               result = GraphElementFactory.createRelation(type, properties, from, to);
-       }
+    @Test
+    void testCreateRelation() throws Exception {
+        GraphRelation result = GraphElementFactory.createRelation("", new HashMap<>(), Mockito.mock(GraphNode.class), Mockito.mock(GraphNode.class));
+        Assertions.assertTrue(result instanceof GraphRelation);
+        Assertions.assertTrue(result.getFrom() instanceof RelationEndPoint);
+        Assertions.assertTrue(result.getTo() instanceof RelationEndPoint);
+    }
 
-       @Test
-       public void testCreateNode() throws Exception {
-               Map<String, Object> properties = new HashMap<>();
-               GraphNode result;
+    @Test
+    void testCreateNode() throws Exception {
+        Map<String, Object> properties = new HashMap<>();
+        GraphNode result;
 
-               result = Deencapsulation.invoke(GraphElementFactory.class, "createNode", NodeTypeEnum.User.getName(),
-                               properties);
-               result = Deencapsulation.invoke(GraphElementFactory.class, "createNode",
-                               NodeTypeEnum.ResourceCategory.getName(), properties);
-               result = Deencapsulation.invoke(GraphElementFactory.class, "createNode", NodeTypeEnum.ServiceCategory.getName(),
-                               properties);
-               result = Deencapsulation.invoke(GraphElementFactory.class, "createNode", NodeTypeEnum.Tag.getName(),
-                               properties);
-               result = Deencapsulation.invoke(GraphElementFactory.class, "createNode", NodeTypeEnum.Service.getName(),
-                               properties);
-               result = Deencapsulation.invoke(GraphElementFactory.class, "createNode", NodeTypeEnum.Property.getName(),
-                               properties);
-               result = Deencapsulation.invoke(GraphElementFactory.class, "createNode", NodeTypeEnum.HeatParameter.getName(),
-                               properties);
-               result = Deencapsulation.invoke(GraphElementFactory.class, "createNode",
-                               NodeTypeEnum.HeatParameterValue.getName(), properties);
-       }
+        result = GraphElementFactory.createElement(NodeTypeEnum.User.getName(), GraphElementTypeEnum.Node, properties);
+        Assertions.assertNotNull(result);
+        Assertions.assertTrue(result instanceof GraphNode);
+        result = GraphElementFactory.createElement(NodeTypeEnum.ResourceCategory.getName(), GraphElementTypeEnum.Node, properties);
+        Assertions.assertNotNull(result);
+        Assertions.assertTrue(result instanceof GraphNode);
+        result = GraphElementFactory.createElement(NodeTypeEnum.ServiceCategory.getName(), GraphElementTypeEnum.Node, properties);
+        Assertions.assertNotNull(result);
+        result = GraphElementFactory.createElement(NodeTypeEnum.Tag.getName(), GraphElementTypeEnum.Node, properties);
+        Assertions.assertTrue(result instanceof GraphNode);
+        Assertions.assertNotNull(result);
+        result = GraphElementFactory.createElement(NodeTypeEnum.Service.getName(), GraphElementTypeEnum.Node, properties);
+        Assertions.assertNotNull(result);
+        Assertions.assertTrue(result instanceof GraphNode);
+        result = GraphElementFactory.createElement(NodeTypeEnum.Property.getName(), GraphElementTypeEnum.Node, properties);
+        Assertions.assertNotNull(result);
+        result = GraphElementFactory.createElement(NodeTypeEnum.Resource.getName(), GraphElementTypeEnum.Node, properties);
+        Assertions.assertTrue(result instanceof GraphNode);
+        Assertions.assertNotNull(result);
+        result = GraphElementFactory.createElement(NodeTypeEnum.HeatParameter.getName(), GraphElementTypeEnum.Node, properties);
+        Assertions.assertNotNull(result);
+        Assertions.assertTrue(result instanceof GraphNode);
+        result = GraphElementFactory.createElement(NodeTypeEnum.HeatParameterValue.getName(), GraphElementTypeEnum.Node, properties);
+        Assertions.assertNotNull(result);
+        Assertions.assertTrue(result instanceof GraphNode);
+    }
 }
index 5eccc78..98dda47 100644 (file)
  */
 package org.openecomp.sdc.be.dao.utils;
 
-import com.fasterxml.jackson.databind.ObjectMapper;
-import mockit.Deencapsulation;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.mockito.Mockito;
-
-import java.io.InputStream;
 import java.util.List;
 import java.util.Map;
-
-public class JsonUtilTest {
-       
-       @Test
-       public void testGetOneObjectMapper() throws Exception {
-               ObjectMapper result;
-
-               // default test
-               result = Deencapsulation.invoke(JsonUtil.class, "getOneObjectMapper");
-       }
-
-       @Test
-       public void testReadObject() throws Exception {
-               String objectText = "{}";
-               Class objectClass = Object.class;
-               Object result;
-
-               // default test
-               result = JsonUtil.readObject(objectText, objectClass);
-       }
-
-       @Test
-       public void testReadObject_2() throws Exception {
-               String objectText = "{}";
-               Object result;
-
-               // default test
-               result = JsonUtil.readObject(objectText);
-       }
-
-       @Test
-       public void testToMap() throws Exception {
-               String json = "{\"name\":\"mock\",\"age\":0}";
-               Map<String, Object> result;
-
-               // default test
-               result = JsonUtil.toMap(json);
-       }
-
-       @Test
-       public void testToMap_1() throws Exception {
-               String json = "{\"name\":\"mock\",\"age\":0}";
-               Class keyTypeClass = Object.class;
-               Class valueTypeClass = Object.class;
-               Map result;
-
-               // default test
-               result = JsonUtil.toMap(json, keyTypeClass, valueTypeClass);
-       }
-
-       @Test
-       public void testToArray() throws Exception {
-               String json = "[]";
-               Class valueTypeClass = Object.class;
-               Object[] result;
-
-               // default test
-               result = JsonUtil.toArray(json, valueTypeClass);
-       }
-
-       @Test
-       public void testToList() throws Exception {
-               String json = "[]";
-               Class clazz = Object.class;
-               List result;
-
-               // default test
-               result = JsonUtil.toList(json, clazz);
-       }
-}
\ No newline at end of file
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+class JsonUtilTest {
+
+    @Test
+    void testReadObject_1() throws Exception {
+        final String objectText = "{}";
+        final Class objectClass = Object.class;
+        final Object result = JsonUtil.readObject(objectText, objectClass);
+        Assertions.assertNotNull(result);
+        Assertions.assertTrue(result instanceof Map);
+        Assertions.assertEquals(0, ((Map) result).size());
+    }
+
+    @Test
+    void testReadObject_2() throws Exception {
+        final String objectText = "{}";
+        final Object result = JsonUtil.readObject(objectText);
+        Assertions.assertNotNull(result);
+        Assertions.assertTrue(result instanceof Map);
+        Assertions.assertEquals(0, ((Map) result).size());
+    }
+
+    @Test
+    void testToMap_1() throws Exception {
+        final String json = "{\"name\":\"mock\",\"age\":0}";
+        final Map<String, Object> result = JsonUtil.toMap(json);
+        Assertions.assertNotNull(result);
+        Assertions.assertEquals(2, result.size());
+    }
+
+    @Test
+    void testToMap_2() throws Exception {
+        final String json = "{\"name\":\"mock\",\"age\":0}";
+        final Class keyTypeClass = Object.class;
+        final Class valueTypeClass = Object.class;
+        final Map result = JsonUtil.toMap(json, keyTypeClass, valueTypeClass);
+        Assertions.assertNotNull(result);
+        Assertions.assertEquals(2, result.size());
+    }
+
+    @Test
+    void testToArray() throws Exception {
+        final String json = "[]";
+        final Class valueTypeClass = Object.class;
+        final Object[] result = JsonUtil.toArray(json, valueTypeClass);
+        Assertions.assertNotNull(result);
+    }
+
+    @Test
+    void testToList_1() throws Exception {
+        final String json = "[]";
+        final Class clazz = Object.class;
+        final List result = JsonUtil.toList(json, clazz);
+        Assertions.assertNotNull(result);
+        Assertions.assertEquals(0, result.size());
+    }
+
+}
index da0239a..ba1f735 100644 (file)
@@ -7,9 +7,9 @@
  * 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.
 
 package org.openecomp.sdc.be.resources.data;
 
-import mockit.Deencapsulation;
-import org.apache.commons.collections.map.HashedMap;
-import org.junit.Test;
 
-public class ServiceCategoryDataTest {
+import java.util.HashMap;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
 
-       private ServiceCategoryData createTestSubject() {
-               return new ServiceCategoryData();
-       }
+class ServiceCategoryDataTest {
 
-       @Test
-       public void testCtor() throws Exception {
-               new ServiceCategoryData(new HashedMap());
-               new ServiceCategoryData("mock");
-       }
-       
-       @Test
-       public void testCreateUniqueId() throws Exception {
-               ServiceCategoryData testSubject;
+    @Test
+    void testCtor() throws Exception {
+        Assertions.assertNotNull(new ServiceCategoryData());
+        Assertions.assertNotNull(new ServiceCategoryData(new HashMap()));
+        Assertions.assertNotNull(new ServiceCategoryData("mock"));
+    }
 
-               // default test
-               testSubject = createTestSubject();
-               Deencapsulation.invoke(testSubject, "createUniqueId");
-       }
 }