Add more unit tests 57/16957/1 1.0.0-Amsterdam 1.0.0-ONAP v1.0.0 v1.2.0
authorMichael Hwang <mhwang@research.att.com>
Mon, 2 Oct 2017 23:40:06 +0000 (19:40 -0400)
committerMichael Hwang <mhwang@research.att.com>
Tue, 3 Oct 2017 00:06:10 +0000 (20:06 -0400)
Change-Id: Ib8e586a5aa7d31756751776015bbb76f68a0cafc
Issue-Id: DCAEGEN2-60
Signed-off-by: Michael Hwang <mhwang@research.att.com>
src/main/java/org/openecomp/dcae/inventory/daos/DCAEServiceTransactionDAO.java
src/test/java/org/openecomp/dcae/inventory/dbthings/daos/DCAEServiceTransactionDAOTests.java [new file with mode: 0644]
src/test/java/org/openecomp/dcae/inventory/dbthings/mappers/DCAEServiceComponentObjectMapperTests.java [new file with mode: 0644]
src/test/java/org/openecomp/dcae/inventory/dbthings/mappers/DCAEServiceObjectMapperTests.java [new file with mode: 0644]
src/test/java/org/openecomp/dcae/inventory/dbthings/mappers/DCAEServiceTypeObjectMapperTests.java [new file with mode: 0644]
src/test/java/org/openecomp/dcae/inventory/providers/NotFoundExceptionMapperTests.java [new file with mode: 0644]

index f0fca86..c9d6dc8 100644 (file)
@@ -120,13 +120,13 @@ public abstract class DCAEServiceTransactionDAO {
     }
 
     @CreateSqlObject
-    abstract DCAEServicesDAO getServicesDAO();
+    abstract public DCAEServicesDAO getServicesDAO();
 
     @CreateSqlObject
-    abstract DCAEServicesComponentsMapsDAO getServicesComponentsMappingDAO();
+    abstract public DCAEServicesComponentsMapsDAO getServicesComponentsMappingDAO();
 
     @CreateSqlObject
-    abstract DCAEServiceComponentsDAO getComponentsDAO();
+    abstract public DCAEServiceComponentsDAO getComponentsDAO();
 
     @Transaction
     public void insert(DCAEServiceTransactionContext context) {
diff --git a/src/test/java/org/openecomp/dcae/inventory/dbthings/daos/DCAEServiceTransactionDAOTests.java b/src/test/java/org/openecomp/dcae/inventory/dbthings/daos/DCAEServiceTransactionDAOTests.java
new file mode 100644 (file)
index 0000000..2a909f4
--- /dev/null
@@ -0,0 +1,85 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * dcae-inventory
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. 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.dcae.inventory.dbthings.daos;
+
+import org.joda.time.DateTime;
+import org.junit.Test;
+import org.openecomp.dcae.inventory.daos.DCAEServiceComponentsDAO;
+import org.openecomp.dcae.inventory.daos.DCAEServiceTransactionDAO;
+import org.openecomp.dcae.inventory.daos.DCAEServicesComponentsMapsDAO;
+import org.openecomp.dcae.inventory.daos.DCAEServicesDAO;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
+
+/**
+ * Created by mhwang on 10/2/17.
+ */
+public class DCAEServiceTransactionDAOTests {
+
+    @Test
+    public void testCreateDCAEServiceTransactionContext() {
+        String serviceId = "service-foo";
+        DateTime modifiedTime = new DateTime();
+        DCAEServiceTransactionDAO.DCAEServiceTransactionContext context
+                = new DCAEServiceTransactionDAO.DCAEServiceTransactionContext(serviceId, modifiedTime);
+
+        assertEquals(context.getServiceId(), serviceId);
+        assertEquals(context.getModified(), modifiedTime);
+    }
+
+    @Test
+    public void testInsert() {
+        String serviceId = "service-foo";
+        DateTime modifiedTime = new DateTime();
+        DCAEServiceTransactionDAO.DCAEServiceTransactionContext context
+                = new DCAEServiceTransactionDAO.DCAEServiceTransactionContext(serviceId, modifiedTime);
+
+        DCAEServicesDAO servicesDAO = mock(DCAEServicesDAO.class);
+        DCAEServicesComponentsMapsDAO componentsMapsDAO = mock(DCAEServicesComponentsMapsDAO.class);
+        DCAEServiceComponentsDAO componentsDAO = mock(DCAEServiceComponentsDAO.class);
+
+        DCAEServiceTransactionDAO transactionDAO = new DCAEServiceTransactionDAO() {
+
+            public DCAEServicesDAO getServicesDAO() {
+                return servicesDAO;
+            }
+
+            public DCAEServicesComponentsMapsDAO getServicesComponentsMappingDAO() {
+                return componentsMapsDAO;
+            }
+
+            public DCAEServiceComponentsDAO getComponentsDAO() {
+                return componentsDAO;
+            }
+        };
+
+        try {
+            transactionDAO.insert(context);
+            assertTrue(true);
+        } catch(Exception e) {
+            fail("Unexpected error");
+        }
+
+    }
+}
diff --git a/src/test/java/org/openecomp/dcae/inventory/dbthings/mappers/DCAEServiceComponentObjectMapperTests.java b/src/test/java/org/openecomp/dcae/inventory/dbthings/mappers/DCAEServiceComponentObjectMapperTests.java
new file mode 100644 (file)
index 0000000..cb3c7f1
--- /dev/null
@@ -0,0 +1,48 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * dcae-inventory
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. 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.dcae.inventory.dbthings.mappers;
+
+import org.junit.Test;
+
+import java.sql.ResultSet;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
+
+/**
+ * Created by mhwang on 10/2/17.
+ */
+public class DCAEServiceComponentObjectMapperTests {
+
+    @Test
+    public void testMap() {
+        ResultSet resultSet = mock(ResultSet.class);
+        DCAEServiceComponentObjectMapper mapper = new DCAEServiceComponentObjectMapper();
+
+        try {
+            assertNotNull(mapper.map(0, resultSet, null));
+        } catch(Exception e) {
+            fail("Unexpected exception");
+        }
+    }
+
+}
diff --git a/src/test/java/org/openecomp/dcae/inventory/dbthings/mappers/DCAEServiceObjectMapperTests.java b/src/test/java/org/openecomp/dcae/inventory/dbthings/mappers/DCAEServiceObjectMapperTests.java
new file mode 100644 (file)
index 0000000..1946343
--- /dev/null
@@ -0,0 +1,50 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * dcae-inventory
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. 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.dcae.inventory.dbthings.mappers;
+
+import org.junit.Test;
+
+import java.sql.ResultSet;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+/**
+ * Created by mhwang on 10/2/17.
+ */
+public class DCAEServiceObjectMapperTests {
+
+    @Test
+    public void testMap() {
+        ResultSet resultSet = mock(ResultSet.class);
+        DCAEServiceObjectMapper mapper = new DCAEServiceObjectMapper();
+
+        try {
+            when(resultSet.getString("status")).thenReturn("RUNNING");
+            assertNotNull(mapper.map(0, resultSet, null));
+        } catch(Exception e) {
+            fail("Unexpected exception");
+        }
+    }
+
+}
diff --git a/src/test/java/org/openecomp/dcae/inventory/dbthings/mappers/DCAEServiceTypeObjectMapperTests.java b/src/test/java/org/openecomp/dcae/inventory/dbthings/mappers/DCAEServiceTypeObjectMapperTests.java
new file mode 100644 (file)
index 0000000..f8c2428
--- /dev/null
@@ -0,0 +1,109 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * dcae-inventory
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. 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.dcae.inventory.dbthings.mappers;
+
+import org.junit.Test;
+
+import java.sql.Array;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Map;
+
+import static junit.framework.TestCase.assertNotNull;
+import static org.junit.Assert.fail;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.mock;
+import static org.powermock.api.mockito.PowerMockito.when;
+
+/**
+ * Created by mhwang on 10/2/17.
+ */
+public class DCAEServiceTypeObjectMapperTests {
+
+    @Test
+    public void testMap() {
+        ResultSet resultSet = mock(ResultSet.class);
+        DCAEServiceTypeObjectMapper mapper = new DCAEServiceTypeObjectMapper();
+
+        try {
+            when(resultSet.getArray(anyString())).thenReturn(new Array() {
+                @Override
+                public String getBaseTypeName() throws SQLException {
+                    return null;
+                }
+
+                @Override
+                public int getBaseType() throws SQLException {
+                    return 0;
+                }
+
+                @Override
+                public Object getArray() throws SQLException {
+                    return new String[10];
+                }
+
+                @Override
+                public Object getArray(Map<String, Class<?>> map) throws SQLException {
+                    return null;
+                }
+
+                @Override
+                public Object getArray(long index, int count) throws SQLException {
+                    return null;
+                }
+
+                @Override
+                public Object getArray(long index, int count, Map<String, Class<?>> map) throws SQLException {
+                    return null;
+                }
+
+                @Override
+                public ResultSet getResultSet() throws SQLException {
+                    return null;
+                }
+
+                @Override
+                public ResultSet getResultSet(Map<String, Class<?>> map) throws SQLException {
+                    return null;
+                }
+
+                @Override
+                public ResultSet getResultSet(long index, int count) throws SQLException {
+                    return null;
+                }
+
+                @Override
+                public ResultSet getResultSet(long index, int count, Map<String, Class<?>> map) throws SQLException {
+                    return null;
+                }
+
+                @Override
+                public void free() throws SQLException {
+
+                }
+            });
+            assertNotNull(mapper.map(0, resultSet, null));
+        } catch(Exception e) {
+            fail("Unexpected exception");
+        }
+    }
+
+}
diff --git a/src/test/java/org/openecomp/dcae/inventory/providers/NotFoundExceptionMapperTests.java b/src/test/java/org/openecomp/dcae/inventory/providers/NotFoundExceptionMapperTests.java
new file mode 100644 (file)
index 0000000..083b237
--- /dev/null
@@ -0,0 +1,42 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * dcae-inventory
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. 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.dcae.inventory.providers;
+
+import io.swagger.api.NotFoundException;
+import org.junit.Test;
+
+import javax.ws.rs.core.Response;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Created by mhwang on 10/2/17.
+ */
+public class NotFoundExceptionMapperTests {
+
+    @Test
+    public void testNotFoundExceptionMapper() {
+        NotFoundExceptionMapper mapper = new NotFoundExceptionMapper();
+        Response response = mapper.toResponse(new NotFoundException(100, "Some error message"));
+        assertEquals(response.getStatus(), 404);
+    }
+
+}