aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java
diff options
context:
space:
mode:
authorShadi Haidar <sh1986@att.com>2018-09-14 17:22:14 -0400
committerShadi Haidar <sh1986@att.com>2018-09-14 17:23:12 -0400
commitf8426d18257c33fa8a0267e4f96f7e53bb4a82ee (patch)
tree78aee264bca03560e43e03ccd2e65dabfef8b44c /src/test/java
parent4a81073bb3ce0e873bcf38853e66f8ae4150da67 (diff)
Address warnings
Change-Id: I953b71d130c78bb20cf602e101021e29b538088e Issue-ID: DCAEGEN2-605 Signed-off-by: Shadi Haidar <sh1986@att.com>
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/io/swagger/api/BootstrapTest.java6
-rw-r--r--src/test/java/io/swagger/api/Util.java15
-rw-r--r--src/test/java/io/swagger/api/factories/DcaeServiceTypesApiServiceFactoryTest.java4
-rw-r--r--src/test/java/io/swagger/api/factories/DcaeServicesApiServiceFactoryTest.java4
-rw-r--r--src/test/java/io/swagger/api/factories/DcaeServicesGroupbyApiServiceFactoryTest.java4
-rw-r--r--src/test/java/io/swagger/api/impl/DcaeServiceTypesApiServiceImplTests.java71
-rw-r--r--src/test/java/io/swagger/api/impl/DcaeServicesApiServiceImplH2Tests.java70
-rw-r--r--src/test/java/io/swagger/api/impl/DcaeServicesApiServiceImplTests.java99
-rw-r--r--src/test/java/io/swagger/api/impl/DcaeServicesGroupbyApiServiceImplTests.java26
-rw-r--r--src/test/java/org/onap/dcae/inventory/InventoryConfigurationTest.java28
-rw-r--r--src/test/java/org/onap/dcae/inventory/LinkSerializerTest.java15
-rw-r--r--src/test/java/org/onap/dcae/inventory/clients/DatabusControllerClientTest.java60
-rw-r--r--src/test/java/org/onap/dcae/inventory/daos/DCAEServicesDAOTest.java32
-rw-r--r--src/test/java/org/onap/dcae/inventory/daos/InventoryDAOManagerTests.java8
-rw-r--r--src/test/java/org/onap/dcae/inventory/dbthings/daos/DCAEServiceTransactionDAOTests.java28
-rw-r--r--src/test/java/org/onap/dcae/inventory/dbthings/mappers/DCAEServiceComponentObjectMapperTests.java10
-rw-r--r--src/test/java/org/onap/dcae/inventory/dbthings/mappers/DCAEServiceObjectMapperTests.java10
-rw-r--r--src/test/java/org/onap/dcae/inventory/dbthings/mappers/DCAEServiceTypeObjectMapperTests.java16
-rw-r--r--src/test/java/org/onap/dcae/inventory/dbthings/models/DCAEServiceComponentObjectTests.java7
-rw-r--r--src/test/java/org/onap/dcae/inventory/dbthings/models/DCAEServiceObjectTests.java7
-rw-r--r--src/test/java/org/onap/dcae/inventory/exceptions/mappers/DBIExceptionMapperTests.java42
-rw-r--r--src/test/java/org/onap/dcae/inventory/providers/NotFoundExceptionMapperTests.java7
22 files changed, 299 insertions, 270 deletions
diff --git a/src/test/java/io/swagger/api/BootstrapTest.java b/src/test/java/io/swagger/api/BootstrapTest.java
index 7c86d8c..7eaa2ec 100644
--- a/src/test/java/io/swagger/api/BootstrapTest.java
+++ b/src/test/java/io/swagger/api/BootstrapTest.java
@@ -20,11 +20,11 @@
package io.swagger.api;
-import org.junit.Test;
+import static org.junit.Assert.fail;
import javax.servlet.ServletException;
-import static org.junit.Assert.fail;
+import org.junit.Test;
/**
* Created by mhwang on 3/22/18.
@@ -35,7 +35,7 @@ public class BootstrapTest {
public void testNoServletConfig() {
try {
(new Bootstrap()).init(null);
- } catch(ServletException e) {
+ } catch (ServletException e) {
fail("This might be a valid failure. Should investigate.");
}
}
diff --git a/src/test/java/io/swagger/api/Util.java b/src/test/java/io/swagger/api/Util.java
index 8f9e09f..6e5a554 100644
--- a/src/test/java/io/swagger/api/Util.java
+++ b/src/test/java/io/swagger/api/Util.java
@@ -18,12 +18,13 @@ package io.swagger.api;/*-
* ============LICENSE_END=========================================================
*/
+import java.net.URI;
+import java.util.List;
+
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.PathSegment;
import javax.ws.rs.core.UriBuilder;
import javax.ws.rs.core.UriInfo;
-import java.net.URI;
-import java.util.List;
/**
* Created by mhwang on 9/25/17.
@@ -38,7 +39,7 @@ public class Util {
}
@Override
- public String getPath(boolean b) {
+ public String getPath(boolean bunused) {
return null;
}
@@ -48,7 +49,7 @@ public class Util {
}
@Override
- public List<PathSegment> getPathSegments(boolean b) {
+ public List<PathSegment> getPathSegments(boolean bunused) {
return null;
}
@@ -88,7 +89,7 @@ public class Util {
}
@Override
- public MultivaluedMap<String, String> getPathParameters(boolean b) {
+ public MultivaluedMap<String, String> getPathParameters(boolean bunused) {
return null;
}
@@ -98,7 +99,7 @@ public class Util {
}
@Override
- public MultivaluedMap<String, String> getQueryParameters(boolean b) {
+ public MultivaluedMap<String, String> getQueryParameters(boolean bunused) {
return null;
}
@@ -108,7 +109,7 @@ public class Util {
}
@Override
- public List<String> getMatchedURIs(boolean b) {
+ public List<String> getMatchedURIs(boolean bunused) {
return null;
}
diff --git a/src/test/java/io/swagger/api/factories/DcaeServiceTypesApiServiceFactoryTest.java b/src/test/java/io/swagger/api/factories/DcaeServiceTypesApiServiceFactoryTest.java
index 6b385df..32cf47f 100644
--- a/src/test/java/io/swagger/api/factories/DcaeServiceTypesApiServiceFactoryTest.java
+++ b/src/test/java/io/swagger/api/factories/DcaeServiceTypesApiServiceFactoryTest.java
@@ -20,10 +20,10 @@
package io.swagger.api.factories;
-import org.junit.Test;
-
import static junit.framework.TestCase.assertNotNull;
+import org.junit.Test;
+
/**
* Created by mhwang on 3/22/18.
*/
diff --git a/src/test/java/io/swagger/api/factories/DcaeServicesApiServiceFactoryTest.java b/src/test/java/io/swagger/api/factories/DcaeServicesApiServiceFactoryTest.java
index d9c6808..c1de64c 100644
--- a/src/test/java/io/swagger/api/factories/DcaeServicesApiServiceFactoryTest.java
+++ b/src/test/java/io/swagger/api/factories/DcaeServicesApiServiceFactoryTest.java
@@ -20,10 +20,10 @@
package io.swagger.api.factories;
-import org.junit.Test;
-
import static junit.framework.TestCase.assertNotNull;
+import org.junit.Test;
+
/**
* Created by mhwang on 3/22/18.
*/
diff --git a/src/test/java/io/swagger/api/factories/DcaeServicesGroupbyApiServiceFactoryTest.java b/src/test/java/io/swagger/api/factories/DcaeServicesGroupbyApiServiceFactoryTest.java
index 033c8a6..64e1060 100644
--- a/src/test/java/io/swagger/api/factories/DcaeServicesGroupbyApiServiceFactoryTest.java
+++ b/src/test/java/io/swagger/api/factories/DcaeServicesGroupbyApiServiceFactoryTest.java
@@ -20,10 +20,10 @@
package io.swagger.api.factories;
-import org.junit.Test;
-
import static junit.framework.TestCase.assertNotNull;
+import org.junit.Test;
+
/**
* Created by mhwang on 3/22/18.
*/
diff --git a/src/test/java/io/swagger/api/impl/DcaeServiceTypesApiServiceImplTests.java b/src/test/java/io/swagger/api/impl/DcaeServiceTypesApiServiceImplTests.java
index 4a47787..c1d200f 100644
--- a/src/test/java/io/swagger/api/impl/DcaeServiceTypesApiServiceImplTests.java
+++ b/src/test/java/io/swagger/api/impl/DcaeServiceTypesApiServiceImplTests.java
@@ -18,35 +18,36 @@ package io.swagger.api.impl;/*-
* ============LICENSE_END=========================================================
*/
-import org.onap.dcae.inventory.daos.DCAEServiceTypesDAO;
-import org.onap.dcae.inventory.daos.DCAEServicesDAO;
-import org.onap.dcae.inventory.daos.InventoryDAOManager;
-import org.onap.dcae.inventory.dbthings.models.DCAEServiceObject;
-import org.onap.dcae.inventory.dbthings.models.DCAEServiceTypeObject;
-import io.swagger.model.DCAEServiceType;
-import io.swagger.model.DCAEServiceTypeRequest;
-import org.joda.time.DateTime;
-import org.junit.Before;
-import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.Arrays;
+import java.util.Objects;
+import java.util.UUID;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder;
import javax.ws.rs.core.UriInfo;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.*;
-
+import org.joda.time.DateTime;
+import org.junit.Before;
+import org.junit.Test;
import org.junit.runner.RunWith;
+import org.onap.dcae.inventory.daos.DCAEServiceTypesDAO;
+import org.onap.dcae.inventory.daos.DCAEServicesDAO;
+import org.onap.dcae.inventory.daos.InventoryDAOManager;
+import org.onap.dcae.inventory.dbthings.models.DCAEServiceObject;
+import org.onap.dcae.inventory.dbthings.models.DCAEServiceTypeObject;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.Arrays;
-import java.util.Objects;
-import java.util.UUID;
+import io.swagger.model.DCAEServiceType;
+import io.swagger.model.DCAEServiceTypeRequest;
/**
@@ -56,35 +57,36 @@ import java.util.UUID;
@RunWith(PowerMockRunner.class)
public class DcaeServiceTypesApiServiceImplTests {
- private final static Logger LOG = LoggerFactory.getLogger(DcaeServiceTypesApiServiceImplTests.class);
+ private static final Logger log = LoggerFactory.getLogger(DcaeServiceTypesApiServiceImplTests.class);
- private final static String URL_PATH = "http://testing-is-good.com";
+ private static final String URL_PATH = "http://testing-is-good.com";
private DcaeServiceTypesApiServiceImpl api = null;
private UriInfo uriInfo = null;
- private DCAEServiceTypesDAO mockTypesDAO = null;
- private DCAEServicesDAO mockServicesDAO = null;
+ private DCAEServiceTypesDAO mockTypesDao = null;
+ private DCAEServicesDAO mockServicesDao = null;
@Before
public void setupClass() {
api = new DcaeServiceTypesApiServiceImpl();
uriInfo = mock(UriInfo.class);
- mockTypesDAO = mock(DCAEServiceTypesDAO.class);
- mockServicesDAO = mock(DCAEServicesDAO.class);
+ mockTypesDao = mock(DCAEServiceTypesDAO.class);
+ mockServicesDao = mock(DCAEServicesDAO.class);
// PowerMockito does bytecode magic to mock static methods and use final classes
PowerMockito.mockStatic(InventoryDAOManager.class);
- InventoryDAOManager mockDAOManager = mock(InventoryDAOManager.class);
+ InventoryDAOManager mockDaoManager = mock(InventoryDAOManager.class);
- when(InventoryDAOManager.getInstance()).thenReturn(mockDAOManager);
- when(mockDAOManager.getDCAEServiceTypesDAO()).thenReturn(mockTypesDAO);
- when(mockDAOManager.getDCAEServicesDAO()).thenReturn(mockServicesDAO);
+ when(InventoryDAOManager.getInstance()).thenReturn(mockDaoManager);
+ when(mockDaoManager.getDCAEServiceTypesDAO()).thenReturn(mockTypesDao);
+ when(mockDaoManager.getDCAEServicesDAO()).thenReturn(mockServicesDao);
when(uriInfo.getBaseUriBuilder()).thenReturn(UriBuilder.fromPath(URL_PATH));
}
- private static boolean matchTypeVsTypeObject(DCAEServiceType serviceType, DCAEServiceTypeObject serviceTypeObject, String prefixPath) {
+ private static boolean matchTypeVsTypeObject(DCAEServiceType serviceType, DCAEServiceTypeObject serviceTypeObject,
+ String prefixPath) {
return Objects.equals(serviceType.getTypeId(), serviceTypeObject.getTypeId())
&& Objects.equals(serviceType.getTypeName(), serviceTypeObject.getTypeName())
&& Objects.equals(serviceType.getTypeVersion(), serviceTypeObject.getTypeVersion())
@@ -125,7 +127,7 @@ public class DcaeServiceTypesApiServiceImplTests {
for (DCAEServiceTypeObject fixture : new DCAEServiceTypeObject[] {minimalFixture, fullFixture}) {
String someTypeId = fixture.getTypeId();
- when(mockTypesDAO.getByTypeId(someTypeId)).thenReturn(fixture);
+ when(mockTypesDao.getByTypeId(someTypeId)).thenReturn(fixture);
try {
Response response = api.dcaeServiceTypesTypeIdGet(someTypeId, uriInfo, null);
@@ -140,18 +142,19 @@ public class DcaeServiceTypesApiServiceImplTests {
@Test
public void testGetNotFound() {
String someTypeId = "abc:1";
- when(mockTypesDAO.getByTypeId(someTypeId)).thenReturn(null);
+ when(mockTypesDao.getByTypeId(someTypeId)).thenReturn(null);
try {
Response response = api.dcaeServiceTypesTypeIdGet(someTypeId, uriInfo, null);
assertEquals("GET - 404 test case failed", 404, response.getStatus());
- } catch(Exception e) {
+ } catch (Exception e) {
throw new RuntimeException("Unexpected exception: get 404", e);
}
}
// TODO: Update this to check type id again. Must mock dao calls deeper.
- private static boolean matchTypeVsTypeRequest(DCAEServiceType serviceType, DCAEServiceTypeRequest serviceTypeRequest, String prefixPath) {
+ private static boolean matchTypeVsTypeRequest(DCAEServiceType serviceType,
+ DCAEServiceTypeRequest serviceTypeRequest, String prefixPath) {
return Objects.equals(serviceType.getTypeName(), serviceTypeRequest.getTypeName())
&& Objects.equals(serviceType.getTypeVersion(), serviceTypeRequest.getTypeVersion())
&& Objects.equals(serviceType.getOwner(), serviceTypeRequest.getOwner())
@@ -208,8 +211,8 @@ public class DcaeServiceTypesApiServiceImplTests {
DCAEServiceTypeObject fakeExistingType = new DCAEServiceTypeObject();
fakeExistingType.setTypeId(expectedTypeIdUUID.toString());
- when(mockTypesDAO.getByRequestFromNotASDC(minimalFixture)).thenReturn(fakeExistingType);
- when(mockServicesDAO.countByType(DCAEServiceObject.DCAEServiceStatus.RUNNING, fakeExistingType.getTypeId())).thenReturn(10);
+ when(mockTypesDao.getByRequestFromNotASDC(minimalFixture)).thenReturn(fakeExistingType);
+ when(mockServicesDao.countByType(DCAEServiceObject.DCAEServiceStatus.RUNNING, fakeExistingType.getTypeId())).thenReturn(10);
try {
Response response = api.dcaeServiceTypesTypeIdPost(minimalFixture, uriInfo, null);
diff --git a/src/test/java/io/swagger/api/impl/DcaeServicesApiServiceImplH2Tests.java b/src/test/java/io/swagger/api/impl/DcaeServicesApiServiceImplH2Tests.java
index 0a3b777..cbdff7d 100644
--- a/src/test/java/io/swagger/api/impl/DcaeServicesApiServiceImplH2Tests.java
+++ b/src/test/java/io/swagger/api/impl/DcaeServicesApiServiceImplH2Tests.java
@@ -20,19 +20,23 @@
package io.swagger.api.impl;
-import com.codahale.metrics.MetricRegistry;
-import io.dropwizard.db.DataSourceFactory;
-import io.dropwizard.jackson.Jackson;
-import io.dropwizard.jdbi.DBIFactory;
-import io.dropwizard.setup.Environment;
-import io.swagger.api.Util;
-import io.swagger.model.DCAEServiceRequest;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.SecurityContext;
+import javax.ws.rs.core.UriInfo;
+
import org.joda.time.DateTime;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.onap.dcae.inventory.clients.DatabusControllerClient;
-import org.onap.dcae.inventory.daos.*;
+import org.onap.dcae.inventory.daos.DCAEServiceComponentsDAO;
+import org.onap.dcae.inventory.daos.DCAEServicesComponentsMapsDAO;
+import org.onap.dcae.inventory.daos.DCAEServicesDAO;
+import org.onap.dcae.inventory.daos.InventoryDAOManager;
import org.onap.dcae.inventory.dbthings.models.DCAEServiceObject;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
@@ -41,14 +45,14 @@ import org.skife.jdbi.v2.DBI;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.SecurityContext;
-import javax.ws.rs.core.UriInfo;
+import com.codahale.metrics.MetricRegistry;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
+import io.dropwizard.db.DataSourceFactory;
+import io.dropwizard.jackson.Jackson;
+import io.dropwizard.jdbi.DBIFactory;
+import io.dropwizard.setup.Environment;
+import io.swagger.api.Util;
+import io.swagger.model.DCAEServiceRequest;
/**
* Created by mhwang on 9/25/17.
@@ -62,16 +66,16 @@ import static org.mockito.Mockito.when;
@RunWith(PowerMockRunner.class)
public class DcaeServicesApiServiceImplH2Tests {
- private final static Logger LOG = LoggerFactory.getLogger(DcaeServicesApiServiceImplH2Tests.class);
+ private static final Logger log = LoggerFactory.getLogger(DcaeServicesApiServiceImplH2Tests.class);
- private DCAEServicesDAO mockServicesDAO = null;
- private DCAEServiceComponentsDAO mockComponentsDAO = null;
- private DCAEServicesComponentsMapsDAO mockComponentsMapsDAO = null;
+ private DCAEServicesDAO mockServicesDao = null;
+ private DCAEServiceComponentsDAO mockComponentsDao = null;
+ private DCAEServicesComponentsMapsDAO mockComponentsMapsDao = null;
// https://stackoverflow.com/questions/35825383/how-to-test-jdbi-daos-with-h2-in-memory-database
- // Caused by: java.lang.ClassNotFoundException: Unable to load class: org.h2.Driver from ClassLoader:sun.misc.Launcher$AppClassLoader@18b4aac2;ClassLoader:sun.misc.Launcher$AppClassLoader@18b4aac2
- protected DataSourceFactory getDataSourceFactory()
- {
+ // Caused by: java.lang.ClassNotFoundException: Unable to load class: org.h2.Driver from
+ // ClassLoader:sun.misc.Launcher$AppClassLoader@18b4aac2;ClassLoader:sun.misc.Launcher$AppClassLoader@18b4aac2
+ protected DataSourceFactory getDataSourceFactory() {
DataSourceFactory dataSourceFactory = new DataSourceFactory();
dataSourceFactory.setDriverClass( "org.h2.Driver" );
dataSourceFactory.setUrl( "jdbc:h2:mem:testDb" );
@@ -85,23 +89,23 @@ public class DcaeServicesApiServiceImplH2Tests {
public void setUp() {
Environment env = new Environment( "test-env", Jackson.newObjectMapper(), null, new MetricRegistry(), null );
DBI dbi = new DBIFactory().build( env, getDataSourceFactory(), "test" );
- mockServicesDAO = dbi.onDemand(DCAEServicesDAO.class);
- mockComponentsDAO = dbi.onDemand(DCAEServiceComponentsDAO.class);
- mockComponentsMapsDAO = dbi.onDemand(DCAEServicesComponentsMapsDAO.class);
+ mockServicesDao = dbi.onDemand(DCAEServicesDAO.class);
+ mockComponentsDao = dbi.onDemand(DCAEServiceComponentsDAO.class);
+ mockComponentsMapsDao = dbi.onDemand(DCAEServicesComponentsMapsDAO.class);
// PowerMockito does bytecode magic to mock static methods and use final classes
PowerMockito.mockStatic(InventoryDAOManager.class);
- InventoryDAOManager mockDAOManager = mock(InventoryDAOManager.class);
+ InventoryDAOManager mockDaoManager = mock(InventoryDAOManager.class);
- when(InventoryDAOManager.getInstance()).thenReturn(mockDAOManager);
- when(mockDAOManager.getHandle()).thenReturn(dbi.open());
+ when(InventoryDAOManager.getInstance()).thenReturn(mockDaoManager);
+ when(mockDaoManager.getHandle()).thenReturn(dbi.open());
}
@Test
- public void testDcaeServicesGet () {
- mockServicesDAO.createTable();
- mockComponentsDAO.createTable();
- mockComponentsMapsDAO.createTable();
+ public void testDcaeServicesGet() {
+ mockServicesDao.createTable();
+ mockComponentsDao.createTable();
+ mockComponentsMapsDao.createTable();
DCAEServiceRequest request = new DCAEServiceRequest();
request.setTypeId("some-type-id");
@@ -110,7 +114,7 @@ public class DcaeServicesApiServiceImplH2Tests {
request.setVnfLocation("some-vnf-location");
request.setDeploymentRef("some-deployment-ref");
DCAEServiceObject so = new DCAEServiceObject("some-service-id", request);
- mockServicesDAO.insert(so);
+ mockServicesDao.insert(so);
DatabusControllerClient dbcc = mock(DatabusControllerClient.class);
DcaeServicesApiServiceImpl api = new DcaeServicesApiServiceImpl(dbcc);
diff --git a/src/test/java/io/swagger/api/impl/DcaeServicesApiServiceImplTests.java b/src/test/java/io/swagger/api/impl/DcaeServicesApiServiceImplTests.java
index 64b7f88..0f5a0a8 100644
--- a/src/test/java/io/swagger/api/impl/DcaeServicesApiServiceImplTests.java
+++ b/src/test/java/io/swagger/api/impl/DcaeServicesApiServiceImplTests.java
@@ -18,10 +18,19 @@ package io.swagger.api.impl;/*-
* ============LICENSE_END=========================================================
*/
-import io.swagger.api.NotFoundException;
-import io.swagger.api.Util;
-import io.swagger.model.DCAEService;
-import io.swagger.model.DCAEServiceRequest;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -35,21 +44,13 @@ import org.onap.dcae.inventory.dbthings.models.DCAEServiceObject;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
-
-import static org.junit.Assert.assertEquals;
-import static org.mockito.Mockito.*;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.UriInfo;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-import static org.junit.Assert.fail;
+import io.swagger.api.NotFoundException;
+import io.swagger.api.Util;
+import io.swagger.model.DCAEService;
+import io.swagger.model.DCAEServiceRequest;
/**
* Created by mhwang on 9/25/17.
@@ -58,26 +59,26 @@ import static org.junit.Assert.fail;
@RunWith(PowerMockRunner.class)
public class DcaeServicesApiServiceImplTests {
- private final static Logger LOG = LoggerFactory.getLogger(DcaeServicesApiServiceImplTests.class);
+ private static final Logger log = LoggerFactory.getLogger(DcaeServicesApiServiceImplTests.class);
- private DCAEServiceTypesDAO mockTypesDAO = null;
- private DCAEServicesDAO mockServicesDAO = null;
- private DCAEServiceComponentsDAO mockComponentsDAO = null;
+ private DCAEServiceTypesDAO mockTypesDao = null;
+ private DCAEServicesDAO mockServicesDao = null;
+ private DCAEServiceComponentsDAO mockComponentsDao = null;
@Before
public void setupClass() {
- mockTypesDAO = mock(DCAEServiceTypesDAO.class);
- mockServicesDAO = mock(DCAEServicesDAO.class);
- mockComponentsDAO = mock(DCAEServiceComponentsDAO.class);
+ mockTypesDao = mock(DCAEServiceTypesDAO.class);
+ mockServicesDao = mock(DCAEServicesDAO.class);
+ mockComponentsDao = mock(DCAEServiceComponentsDAO.class);
// PowerMockito does bytecode magic to mock static methods and use final classes
PowerMockito.mockStatic(InventoryDAOManager.class);
- InventoryDAOManager mockDAOManager = mock(InventoryDAOManager.class);
+ InventoryDAOManager mockDaoManager = mock(InventoryDAOManager.class);
- when(InventoryDAOManager.getInstance()).thenReturn(mockDAOManager);
- when(mockDAOManager.getDCAEServicesDAO()).thenReturn(mockServicesDAO);
- when(mockDAOManager.getDCAEServiceComponentsDAO()).thenReturn(mockComponentsDAO);
- when(mockDAOManager.getDCAEServiceTypesDAO()).thenReturn(mockTypesDAO);
+ when(InventoryDAOManager.getInstance()).thenReturn(mockDaoManager);
+ when(mockDaoManager.getDCAEServicesDAO()).thenReturn(mockServicesDao);
+ when(mockDaoManager.getDCAEServiceComponentsDAO()).thenReturn(mockComponentsDao);
+ when(mockDaoManager.getDCAEServiceTypesDAO()).thenReturn(mockTypesDao);
}
@Test
@@ -86,10 +87,10 @@ public class DcaeServicesApiServiceImplTests {
// This block is a trick to make a private method accessible for testing
try {
- createDCAEService = DcaeServicesApiServiceImpl.class.getDeclaredMethod("createDCAEService", DCAEServiceObject.class,
- Collection.class, UriInfo.class);
+ createDCAEService = DcaeServicesApiServiceImpl.class.getDeclaredMethod("createDCAEService",
+ DCAEServiceObject.class, Collection.class, UriInfo.class);
createDCAEService.setAccessible(true);
- } catch(NoSuchMethodException e) {
+ } catch (NoSuchMethodException e) {
fail("Failed to do the reflection trick to test the private method: createDCAEService");
}
@@ -107,7 +108,7 @@ public class DcaeServicesApiServiceImplTests {
try {
DCAEService service = (DCAEService) createDCAEService.invoke(api, serviceObject, components, uriInfo);
assertEquals(service.getServiceId(), serviceObject.getServiceId());
- } catch(Exception e) {
+ } catch (Exception e) {
fail("Failed to execute the hacked createDCAEService method");
}
}
@@ -119,8 +120,8 @@ public class DcaeServicesApiServiceImplTests {
serviceRequest.setTypeId("type-id-abc");
serviceRequest.setVnfId("vnf-id-def");
DCAEServiceObject serviceObject = new DCAEServiceObject(serviceId, serviceRequest);
- when(mockServicesDAO.getByServiceId(DCAEServiceObject.DCAEServiceStatus.RUNNING, serviceId)).thenReturn(serviceObject);
- when(mockComponentsDAO.getByServiceId(serviceId)).thenReturn(new ArrayList<DCAEServiceComponentObject>());
+ when(mockServicesDao.getByServiceId(DCAEServiceObject.DCAEServiceStatus.RUNNING, serviceId)).thenReturn(serviceObject);
+ when(mockComponentsDao.getByServiceId(serviceId)).thenReturn(new ArrayList<DCAEServiceComponentObject>());
DatabusControllerClient dbcc = mock(DatabusControllerClient.class);
DcaeServicesApiServiceImpl api = new DcaeServicesApiServiceImpl(dbcc);
@@ -129,15 +130,15 @@ public class DcaeServicesApiServiceImplTests {
try {
Response response = api.dcaeServicesServiceIdGet(serviceId, uriInfo, null);
assertEquals(response.getStatus(), 200);
- } catch(NotFoundException e) {
+ } catch (NotFoundException e) {
fail("Service should have been found");
}
}
/*
- Commented this unit test because could not get past Nullpointer in the line trying to mock the explicit "bind" function
- call. Mockito does not handle mocking overloaded functions well so it goes into the actual method where an member variable
- called foreman is null.
+ Commented this unit test because could not get past Nullpointer in the line trying to mock the explicit "bind"
+ function call. Mockito does not handle mocking overloaded functions well so it goes into the actual method where
+ an member variable called foreman is null.
@Test
public void testDcaeServicesGet() {
Handle mockHandle = mock(Handle.class);
@@ -174,17 +175,17 @@ public class DcaeServicesApiServiceImplTests {
@Test
public void testDcaeServicesServiceIdPutMissingType() {
- String serviceId = "service-id-123";
DCAEServiceRequest serviceRequest = new DCAEServiceRequest();
serviceRequest.setTypeId("type-id-abc");
serviceRequest.setVnfId("vnf-id-def");
- when(mockTypesDAO.getByTypeIdActiveOnly(serviceRequest.getTypeId())).thenReturn(null);
+ when(mockTypesDao.getByTypeIdActiveOnly(serviceRequest.getTypeId())).thenReturn(null);
DatabusControllerClient dbcc = mock(DatabusControllerClient.class);
DcaeServicesApiServiceImpl api = new DcaeServicesApiServiceImpl(dbcc);
UriInfo uriInfo = new Util.FakeUriInfo();
+ String serviceId = "service-id-123";
Response response = api.dcaeServicesServiceIdPut(serviceId, serviceRequest, uriInfo, null);
assertEquals(response.getStatus(), 422);
}
@@ -196,7 +197,7 @@ public class DcaeServicesApiServiceImplTests {
serviceRequest.setTypeId("type-id-abc");
serviceRequest.setVnfId("vnf-id-def");
DCAEServiceObject serviceObject = new DCAEServiceObject(serviceId, serviceRequest);
- when(mockServicesDAO.getByServiceId(DCAEServiceObject.DCAEServiceStatus.RUNNING, serviceId)).thenReturn(serviceObject);
+ when(mockServicesDao.getByServiceId(DCAEServiceObject.DCAEServiceStatus.RUNNING, serviceId)).thenReturn(serviceObject);
DatabusControllerClient dbcc = mock(DatabusControllerClient.class);
DcaeServicesApiServiceImpl api = new DcaeServicesApiServiceImpl(dbcc);
@@ -205,10 +206,10 @@ public class DcaeServicesApiServiceImplTests {
try {
Response response = api.dcaeServicesServiceIdDelete(serviceId, null);
assertEquals(response.getStatus(), 200);
- } catch(NotFoundException e) {
+ } catch (NotFoundException e) {
fail("Should have NOT thrown a NotFoundException");
- } catch(Exception e) {
- LOG.error("Unexpected exception", e);
+ } catch (Exception e) {
+ log.error("Unexpected exception", e);
fail("Unexpected exception");
}
}
@@ -216,7 +217,7 @@ public class DcaeServicesApiServiceImplTests {
@Test
public void testDcaeServicesServiceIdDeleteMissingService() {
String serviceId = "service-id-123";
- when(mockServicesDAO.getByServiceId(DCAEServiceObject.DCAEServiceStatus.RUNNING, serviceId)).thenReturn(null);
+ when(mockServicesDao.getByServiceId(DCAEServiceObject.DCAEServiceStatus.RUNNING, serviceId)).thenReturn(null);
DatabusControllerClient dbcc = mock(DatabusControllerClient.class);
DcaeServicesApiServiceImpl api = new DcaeServicesApiServiceImpl(dbcc);
@@ -225,10 +226,10 @@ public class DcaeServicesApiServiceImplTests {
try {
api.dcaeServicesServiceIdDelete(serviceId, null);
fail("Should have thrown a NotFoundException");
- } catch(NotFoundException e) {
- LOG.info("NotFoundException successfully thrown");
- } catch(Exception e) {
- LOG.error("Unexpected exception", e);
+ } catch (NotFoundException e) {
+ log.info("NotFoundException successfully thrown");
+ } catch (Exception e) {
+ log.error("Unexpected exception", e);
fail("Unexpected exception");
}
}
diff --git a/src/test/java/io/swagger/api/impl/DcaeServicesGroupbyApiServiceImplTests.java b/src/test/java/io/swagger/api/impl/DcaeServicesGroupbyApiServiceImplTests.java
index 0ae2c3a..c2d0944 100644
--- a/src/test/java/io/swagger/api/impl/DcaeServicesGroupbyApiServiceImplTests.java
+++ b/src/test/java/io/swagger/api/impl/DcaeServicesGroupbyApiServiceImplTests.java
@@ -18,7 +18,13 @@ package io.swagger.api.impl;/*-
* ============LICENSE_END=========================================================
*/
-import io.swagger.api.Util;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -27,13 +33,7 @@ import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.UriInfo;
-
-import static org.junit.Assert.assertEquals;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
+import io.swagger.api.Util;
/**
* Created by mhwang on 9/27/17.
@@ -46,9 +46,9 @@ public class DcaeServicesGroupbyApiServiceImplTests {
public void setupClass() {
// PowerMockito does bytecode magic to mock static methods and use final classes
PowerMockito.mockStatic(InventoryDAOManager.class);
- InventoryDAOManager mockDAOManager = mock(InventoryDAOManager.class);
+ InventoryDAOManager mockDaoManager = mock(InventoryDAOManager.class);
- when(InventoryDAOManager.getInstance()).thenReturn(mockDAOManager);
+ when(InventoryDAOManager.getInstance()).thenReturn(mockDaoManager);
}
@Test
@@ -62,9 +62,9 @@ public class DcaeServicesGroupbyApiServiceImplTests {
}
/*
- Commented this unit test because could not get past Nullpointer in the line trying to mock the explicit "bind" function
- call. Mockito does not handle mocking overloaded functions well so it goes into the actual method where an member variable
- called foreman is null.
+ Commented this unit test because could not get past Nullpointer in the line trying to mock the explicit "bind"
+ function call. Mockito does not handle mocking overloaded functions well so it goes into the actual method where
+ an member variable called foreman is null.
@Test
public void testNoResults() {
DcaeServicesGroupbyApiServiceImpl api = new DcaeServicesGroupbyApiServiceImpl();
diff --git a/src/test/java/org/onap/dcae/inventory/InventoryConfigurationTest.java b/src/test/java/org/onap/dcae/inventory/InventoryConfigurationTest.java
index f9dadb8..1848a42 100644
--- a/src/test/java/org/onap/dcae/inventory/InventoryConfigurationTest.java
+++ b/src/test/java/org/onap/dcae/inventory/InventoryConfigurationTest.java
@@ -20,32 +20,36 @@
package org.onap.dcae.inventory;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import java.io.File;
+
+import javax.validation.Validator;
+
+import org.junit.Test;
+
import com.fasterxml.jackson.databind.ObjectMapper;
+
import io.dropwizard.configuration.YamlConfigurationFactory;
import io.dropwizard.jackson.Jackson;
import io.dropwizard.jersey.validation.Validators;
-import org.junit.Test;
-
-import javax.validation.Validator;
-import java.io.File;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
/**
* Created by mhwang on 3/22/18.
*/
public class InventoryConfigurationTest {
- final private ObjectMapper objectMapper = Jackson.newObjectMapper();
- final private Validator validator = Validators.newValidator();
- final private YamlConfigurationFactory<InventoryConfiguration> factory
+ private final ObjectMapper objectMapper = Jackson.newObjectMapper();
+ private final Validator validator = Validators.newValidator();
+ private final YamlConfigurationFactory<InventoryConfiguration> factory
= new YamlConfigurationFactory<>(InventoryConfiguration.class, validator, objectMapper, "dw");
@Test
public void testInventoryConfigurationLoad() {
try {
- final File yaml = new File(Thread.currentThread().getContextClassLoader().getResource("config-inventory.yaml").getPath());
+ final File yaml = new File(Thread.currentThread().getContextClassLoader().
+ getResource("config-inventory.yaml").getPath());
InventoryConfiguration configuration = factory.build(yaml);
assertEquals(configuration.getDatabusControllerConnection().getHost(), "databus-controller-hostname");
@@ -53,7 +57,7 @@ public class InventoryConfigurationTest {
assertEquals(configuration.getDatabusControllerConnection().getRequired(), true);
assertEquals(configuration.getDataSourceFactory().getUrl(), "jdbc:postgresql://127.0.0.1:5432/dcae_inv");
- } catch(Exception e) {
+ } catch (Exception e) {
fail("Failed to load config-inventory");
}
}
diff --git a/src/test/java/org/onap/dcae/inventory/LinkSerializerTest.java b/src/test/java/org/onap/dcae/inventory/LinkSerializerTest.java
index 81b0554..1afeefa 100644
--- a/src/test/java/org/onap/dcae/inventory/LinkSerializerTest.java
+++ b/src/test/java/org/onap/dcae/inventory/LinkSerializerTest.java
@@ -20,18 +20,19 @@
package org.onap.dcae.inventory;
-import com.fasterxml.jackson.core.JsonGenerator;
-import org.junit.Test;
-
-import javax.ws.rs.core.Link;
-import javax.ws.rs.core.UriBuilder;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
import java.net.URI;
import java.util.List;
import java.util.Map;
-import static org.junit.Assert.fail;
-import static org.mockito.Mockito.mock;
+import javax.ws.rs.core.Link;
+import javax.ws.rs.core.UriBuilder;
+
+import org.junit.Test;
+
+import com.fasterxml.jackson.core.JsonGenerator;
/**
* Created by mhwang on 3/25/18.
diff --git a/src/test/java/org/onap/dcae/inventory/clients/DatabusControllerClientTest.java b/src/test/java/org/onap/dcae/inventory/clients/DatabusControllerClientTest.java
index ae2f2ff..3b5f249 100644
--- a/src/test/java/org/onap/dcae/inventory/clients/DatabusControllerClientTest.java
+++ b/src/test/java/org/onap/dcae/inventory/clients/DatabusControllerClientTest.java
@@ -20,22 +20,12 @@
package org.onap.dcae.inventory.clients;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import io.dropwizard.configuration.ConfigurationException;
-import io.dropwizard.configuration.YamlConfigurationFactory;
-import io.dropwizard.jackson.Jackson;
-import io.dropwizard.jersey.validation.Validators;
-import org.junit.Before;
-import org.junit.Test;
-import org.onap.dcae.inventory.InventoryConfiguration;
-import org.onap.dcae.inventory.exceptions.DatabusControllerClientException;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.powermock.api.mockito.PowerMockito.when;
-import javax.validation.Validator;
-import javax.ws.rs.client.Client;
-import javax.ws.rs.client.Invocation;
-import javax.ws.rs.client.WebTarget;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
@@ -44,21 +34,35 @@ import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.mock;
-import static org.powermock.api.mockito.PowerMockito.when;
+import javax.validation.Validator;
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.Invocation;
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.dcae.inventory.InventoryConfiguration;
+import org.onap.dcae.inventory.exceptions.DatabusControllerClientException;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import io.dropwizard.configuration.ConfigurationException;
+import io.dropwizard.configuration.YamlConfigurationFactory;
+import io.dropwizard.jackson.Jackson;
+import io.dropwizard.jersey.validation.Validators;
/**
* Created by mhwang on 3/22/18.
*/
public class DatabusControllerClientTest {
- final private ObjectMapper objectMapper = Jackson.newObjectMapper();
- final private Validator validator = Validators.newValidator();
- final private YamlConfigurationFactory<InventoryConfiguration.DatabusControllerConnectionConfiguration> factory
- = new YamlConfigurationFactory<>(InventoryConfiguration.DatabusControllerConnectionConfiguration.class, validator, objectMapper, "dw");
+ private final ObjectMapper objectMapper = Jackson.newObjectMapper();
+ private final Validator validator = Validators.newValidator();
+ private final YamlConfigurationFactory<InventoryConfiguration.DatabusControllerConnectionConfiguration> factory
+ = new YamlConfigurationFactory<>(InventoryConfiguration.DatabusControllerConnectionConfiguration.class,
+ validator, objectMapper, "dw");
private InventoryConfiguration.DatabusControllerConnectionConfiguration configuration = null;
@@ -84,7 +88,7 @@ public class DatabusControllerClientTest {
URI uri = new URI("https://databus-controller-hostname:8443/some-component-id");
when(mockClient.target(uri)).thenReturn(mockWebTarget);
//when(mockClient.target(new URI(any()))).thenReturn(mockWebTarget);
- } catch(URISyntaxException e) {
+ } catch (URISyntaxException e) {
fail("URI syntax error");
}
@@ -107,7 +111,7 @@ public class DatabusControllerClientTest {
try {
assertEquals(client.isExists("some-component-id"), false);
- } catch(Exception e) {
+ } catch (Exception e) {
fail("Unexpected exception");
}
}
@@ -121,9 +125,9 @@ public class DatabusControllerClientTest {
try {
client.isExists("some-component-id");
fail("This was supposed to be a fail case. Exception not thrown.");
- } catch(DatabusControllerClientException e) {
+ } catch (DatabusControllerClientException e) {
// Expected exception
- } catch(Exception e) {
+ } catch (Exception e) {
fail("Unexpected exception");
}
}
diff --git a/src/test/java/org/onap/dcae/inventory/daos/DCAEServicesDAOTest.java b/src/test/java/org/onap/dcae/inventory/daos/DCAEServicesDAOTest.java
index af05704..cdafc4d 100644
--- a/src/test/java/org/onap/dcae/inventory/daos/DCAEServicesDAOTest.java
+++ b/src/test/java/org/onap/dcae/inventory/daos/DCAEServicesDAOTest.java
@@ -20,32 +20,32 @@
package org.onap.dcae.inventory.daos;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.dcae.inventory.dbthings.models.DCAEServiceObject;
+import org.skife.jdbi.v2.DBI;
+
import com.codahale.metrics.MetricRegistry;
+
import io.dropwizard.db.DataSourceFactory;
import io.dropwizard.jackson.Jackson;
import io.dropwizard.jdbi.DBIFactory;
import io.dropwizard.setup.Environment;
import io.swagger.model.DCAEServiceRequest;
-import org.junit.Before;
-import org.junit.Test;
-import org.onap.dcae.inventory.dbthings.models.DCAEServiceObject;
-import org.skife.jdbi.v2.DBI;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
/**
* Created by mhwang on 3/25/18.
*/
public class DCAEServicesDAOTest {
- private DCAEServicesDAO fooDAO;
+ private DCAEServicesDAO fooDao;
// Learned about the H2 approach from here:
// https://stackoverflow.com/questions/35825383/how-to-test-jdbi-daos-with-h2-in-memory-database
- protected DataSourceFactory getDataSourceFactory()
- {
+ protected DataSourceFactory getDataSourceFactory() {
DataSourceFactory dataSourceFactory = new DataSourceFactory();
dataSourceFactory.setDriverClass( "org.h2.Driver" );
dataSourceFactory.setUrl( "jdbc:h2:mem:testDb" );
@@ -59,13 +59,13 @@ public class DCAEServicesDAOTest {
public void setUp() {
Environment env = new Environment( "test-env", Jackson.newObjectMapper(), null, new MetricRegistry(), null );
DBI dbi = new DBIFactory().build( env, getDataSourceFactory(), "test" );
- fooDAO = dbi.onDemand(DCAEServicesDAO.class);
+ fooDao = dbi.onDemand(DCAEServicesDAO.class);
}
@Test
public void testSaveAndGet() {
try {
- fooDAO.createTable();
+ fooDao.createTable();
DCAEServiceRequest request = new DCAEServiceRequest();
request.setTypeId("some-type-id");
request.setVnfId("some-vnf-id");
@@ -73,11 +73,11 @@ public class DCAEServicesDAOTest {
request.setVnfLocation("some-vnf-location");
request.setDeploymentRef("some-deployment-ref");
DCAEServiceObject so = new DCAEServiceObject("some-service-id", request);
- fooDAO.insert(so);
+ fooDao.insert(so);
- DCAEServiceObject target = fooDAO.getByServiceId("some-service-id");
+ DCAEServiceObject target = fooDao.getByServiceId("some-service-id");
assertEquals(target.getServiceId(), so.getServiceId());
- } catch(Exception e) {
+ } catch (Exception e) {
fail("Failure at some point in this compound test.");
}
}
diff --git a/src/test/java/org/onap/dcae/inventory/daos/InventoryDAOManagerTests.java b/src/test/java/org/onap/dcae/inventory/daos/InventoryDAOManagerTests.java
index 8346372..50bb373 100644
--- a/src/test/java/org/onap/dcae/inventory/daos/InventoryDAOManagerTests.java
+++ b/src/test/java/org/onap/dcae/inventory/daos/InventoryDAOManagerTests.java
@@ -20,17 +20,19 @@
package org.onap.dcae.inventory.daos;
+import static org.mockito.Mockito.mock;
+
+import org.junit.Test;
import org.onap.dcae.inventory.InventoryConfiguration;
+
import io.dropwizard.setup.Environment;
-import org.junit.Test;
-import static org.mockito.Mockito.mock;
/**
* Created by mhwang on 3/8/17.
*/
public class InventoryDAOManagerTests {
- @Test(expected=InventoryDAOManager.InventoryDAOManagerSetupException.class)
+ @Test(expected = InventoryDAOManager.InventoryDAOManagerSetupException.class)
public void testInitializeStrictness() {
InventoryDAOManager daoManager = InventoryDAOManager.getInstance();
Environment environment = mock(Environment.class);
diff --git a/src/test/java/org/onap/dcae/inventory/dbthings/daos/DCAEServiceTransactionDAOTests.java b/src/test/java/org/onap/dcae/inventory/dbthings/daos/DCAEServiceTransactionDAOTests.java
index c0ad9b8..309560d 100644
--- a/src/test/java/org/onap/dcae/inventory/dbthings/daos/DCAEServiceTransactionDAOTests.java
+++ b/src/test/java/org/onap/dcae/inventory/dbthings/daos/DCAEServiceTransactionDAOTests.java
@@ -20,6 +20,11 @@
package org.onap.dcae.inventory.dbthings.daos;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
+
import org.joda.time.DateTime;
import org.junit.Test;
import org.onap.dcae.inventory.daos.DCAEServiceComponentsDAO;
@@ -27,11 +32,6 @@ import org.onap.dcae.inventory.daos.DCAEServiceTransactionDAO;
import org.onap.dcae.inventory.daos.DCAEServicesComponentsMapsDAO;
import org.onap.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.
*/
@@ -55,29 +55,29 @@ public class DCAEServiceTransactionDAOTests {
DCAEServiceTransactionDAO.DCAEServiceTransactionContext context
= new DCAEServiceTransactionDAO.DCAEServiceTransactionContext(serviceId, modifiedTime);
- DCAEServicesDAO servicesDAO = mock(DCAEServicesDAO.class);
- DCAEServicesComponentsMapsDAO componentsMapsDAO = mock(DCAEServicesComponentsMapsDAO.class);
- DCAEServiceComponentsDAO componentsDAO = mock(DCAEServiceComponentsDAO.class);
+ DCAEServicesDAO servicesDao = mock(DCAEServicesDAO.class);
+ DCAEServicesComponentsMapsDAO componentsMapsDao = mock(DCAEServicesComponentsMapsDAO.class);
+ DCAEServiceComponentsDAO componentsDao = mock(DCAEServiceComponentsDAO.class);
- DCAEServiceTransactionDAO transactionDAO = new DCAEServiceTransactionDAO() {
+ DCAEServiceTransactionDAO transactionDao = new DCAEServiceTransactionDAO() {
public DCAEServicesDAO getServicesDAO() {
- return servicesDAO;
+ return servicesDao;
}
public DCAEServicesComponentsMapsDAO getServicesComponentsMappingDAO() {
- return componentsMapsDAO;
+ return componentsMapsDao;
}
public DCAEServiceComponentsDAO getComponentsDAO() {
- return componentsDAO;
+ return componentsDao;
}
};
try {
- transactionDAO.insert(context);
+ transactionDao.insert(context);
assertTrue(true);
- } catch(Exception e) {
+ } catch (Exception e) {
fail("Unexpected error");
}
diff --git a/src/test/java/org/onap/dcae/inventory/dbthings/mappers/DCAEServiceComponentObjectMapperTests.java b/src/test/java/org/onap/dcae/inventory/dbthings/mappers/DCAEServiceComponentObjectMapperTests.java
index bb511e2..65ad2b0 100644
--- a/src/test/java/org/onap/dcae/inventory/dbthings/mappers/DCAEServiceComponentObjectMapperTests.java
+++ b/src/test/java/org/onap/dcae/inventory/dbthings/mappers/DCAEServiceComponentObjectMapperTests.java
@@ -20,14 +20,14 @@
package org.onap.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 java.sql.ResultSet;
+
+import org.junit.Test;
+
/**
* Created by mhwang on 10/2/17.
*/
@@ -40,7 +40,7 @@ public class DCAEServiceComponentObjectMapperTests {
try {
assertNotNull(mapper.map(0, resultSet, null));
- } catch(Exception e) {
+ } catch (Exception e) {
fail("Unexpected exception");
}
}
diff --git a/src/test/java/org/onap/dcae/inventory/dbthings/mappers/DCAEServiceObjectMapperTests.java b/src/test/java/org/onap/dcae/inventory/dbthings/mappers/DCAEServiceObjectMapperTests.java
index ab150bb..a0dec3d 100644
--- a/src/test/java/org/onap/dcae/inventory/dbthings/mappers/DCAEServiceObjectMapperTests.java
+++ b/src/test/java/org/onap/dcae/inventory/dbthings/mappers/DCAEServiceObjectMapperTests.java
@@ -20,15 +20,15 @@
package org.onap.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;
+import java.sql.ResultSet;
+
+import org.junit.Test;
+
/**
* Created by mhwang on 10/2/17.
*/
@@ -42,7 +42,7 @@ public class DCAEServiceObjectMapperTests {
try {
when(resultSet.getString("status")).thenReturn("RUNNING");
assertNotNull(mapper.map(0, resultSet, null));
- } catch(Exception e) {
+ } catch (Exception e) {
fail("Unexpected exception");
}
}
diff --git a/src/test/java/org/onap/dcae/inventory/dbthings/mappers/DCAEServiceTypeObjectMapperTests.java b/src/test/java/org/onap/dcae/inventory/dbthings/mappers/DCAEServiceTypeObjectMapperTests.java
index c1caa29..bdac01d 100644
--- a/src/test/java/org/onap/dcae/inventory/dbthings/mappers/DCAEServiceTypeObjectMapperTests.java
+++ b/src/test/java/org/onap/dcae/inventory/dbthings/mappers/DCAEServiceTypeObjectMapperTests.java
@@ -20,19 +20,19 @@
package org.onap.dcae.inventory.dbthings.mappers;
-import junit.framework.TestCase;
-import org.junit.Test;
+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;
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;
+import org.junit.Test;
+
+import junit.framework.TestCase;
/**
* Created by mhwang on 10/2/17.
@@ -102,7 +102,7 @@ public class DCAEServiceTypeObjectMapperTests {
}
});
TestCase.assertNotNull(mapper.map(0, resultSet, null));
- } catch(Exception e) {
+ } catch (Exception e) {
fail("Unexpected exception");
}
}
diff --git a/src/test/java/org/onap/dcae/inventory/dbthings/models/DCAEServiceComponentObjectTests.java b/src/test/java/org/onap/dcae/inventory/dbthings/models/DCAEServiceComponentObjectTests.java
index cb81131..1d80059 100644
--- a/src/test/java/org/onap/dcae/inventory/dbthings/models/DCAEServiceComponentObjectTests.java
+++ b/src/test/java/org/onap/dcae/inventory/dbthings/models/DCAEServiceComponentObjectTests.java
@@ -20,13 +20,14 @@
package org.onap.dcae.inventory.dbthings.models;
-import io.swagger.model.DCAEServiceComponentRequest;
-import org.junit.Test;
-
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
+import org.junit.Test;
+
+import io.swagger.model.DCAEServiceComponentRequest;
+
/**
* Created by mhwang on 9/27/17.
*/
diff --git a/src/test/java/org/onap/dcae/inventory/dbthings/models/DCAEServiceObjectTests.java b/src/test/java/org/onap/dcae/inventory/dbthings/models/DCAEServiceObjectTests.java
index 7a39883..5d3c272 100644
--- a/src/test/java/org/onap/dcae/inventory/dbthings/models/DCAEServiceObjectTests.java
+++ b/src/test/java/org/onap/dcae/inventory/dbthings/models/DCAEServiceObjectTests.java
@@ -20,12 +20,13 @@
package org.onap.dcae.inventory.dbthings.models;
-import io.swagger.model.DCAEServiceRequest;
-import org.junit.Test;
-
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import org.junit.Test;
+
+import io.swagger.model.DCAEServiceRequest;
+
/**
* Created by mhwang on 9/27/17.
*/
diff --git a/src/test/java/org/onap/dcae/inventory/exceptions/mappers/DBIExceptionMapperTests.java b/src/test/java/org/onap/dcae/inventory/exceptions/mappers/DBIExceptionMapperTests.java
index b0d5ba4..21feaba 100644
--- a/src/test/java/org/onap/dcae/inventory/exceptions/mappers/DBIExceptionMapperTests.java
+++ b/src/test/java/org/onap/dcae/inventory/exceptions/mappers/DBIExceptionMapperTests.java
@@ -20,12 +20,15 @@
package org.onap.dcae.inventory.exceptions.mappers;
-import org.onap.dcae.inventory.daos.InventoryDAOManager;
-import org.onap.dcae.inventory.exceptions.mappers.DBIExceptionMapper;
-import io.swagger.api.ApiResponseMessage;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import javax.ws.rs.core.Response;
+
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
+import org.onap.dcae.inventory.daos.InventoryDAOManager;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
@@ -33,10 +36,7 @@ import org.skife.jdbi.v2.exceptions.UnableToCreateStatementException;
import org.skife.jdbi.v2.exceptions.UnableToExecuteStatementException;
import org.skife.jdbi.v2.exceptions.UnableToObtainConnectionException;
-import javax.ws.rs.core.Response;
-
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
+import io.swagger.api.ApiResponseMessage;
/**
* Created by mhwang on 3/8/17.
@@ -49,14 +49,15 @@ public class DBIExceptionMapperTests {
public void testReinitializeSuccess() {
// PowerMockito does bytecode magic to mock static methods and use final classes
PowerMockito.mockStatic(InventoryDAOManager.class);
- InventoryDAOManager mockDAOManager = mock(InventoryDAOManager.class);
- when(InventoryDAOManager.getInstance()).thenReturn(mockDAOManager);
+ InventoryDAOManager mockDaoManager = mock(InventoryDAOManager.class);
+ when(InventoryDAOManager.getInstance()).thenReturn(mockDaoManager);
RuntimeException fakeException = new RuntimeException("Spoofing database failure");
// Test UnableToObtainConnectionExceptionMapper
- DBIExceptionMapper.UnableToObtainConnectionExceptionMapper mapperOne = new DBIExceptionMapper.UnableToObtainConnectionExceptionMapper();
+ DBIExceptionMapper.UnableToObtainConnectionExceptionMapper mapperOne =
+ new DBIExceptionMapper.UnableToObtainConnectionExceptionMapper();
Response responseOne = mapperOne.toResponse(new UnableToObtainConnectionException(fakeException));
assert responseOne.getStatus() == 502;
String messageOne = ((ApiResponseMessage) responseOne.getEntity()).getMessage();
@@ -64,7 +65,8 @@ public class DBIExceptionMapperTests {
// Test UnableToCreateStatementExceptionMapper
- DBIExceptionMapper.UnableToCreateStatementExceptionMapper mapperTwo = new DBIExceptionMapper.UnableToCreateStatementExceptionMapper();
+ DBIExceptionMapper.UnableToCreateStatementExceptionMapper mapperTwo =
+ new DBIExceptionMapper.UnableToCreateStatementExceptionMapper();
Response responseTwo = mapperTwo.toResponse(new UnableToCreateStatementException(fakeException));
assert responseTwo.getStatus() == 502;
String messageTwo = ((ApiResponseMessage) responseTwo.getEntity()).getMessage();
@@ -72,7 +74,8 @@ public class DBIExceptionMapperTests {
// Test UnableToExecuteStatementExceptionMapper
- DBIExceptionMapper.UnableToExecuteStatementExceptionMapper mapperThree = new DBIExceptionMapper.UnableToExecuteStatementExceptionMapper();
+ DBIExceptionMapper.UnableToExecuteStatementExceptionMapper mapperThree =
+ new DBIExceptionMapper.UnableToExecuteStatementExceptionMapper();
Response responseThree = mapperThree.toResponse(new UnableToExecuteStatementException(fakeException));
assert responseThree.getStatus() == 502;
String messageThree = ((ApiResponseMessage) responseThree.getEntity()).getMessage();
@@ -83,15 +86,16 @@ public class DBIExceptionMapperTests {
public void testReinitializeFailed() {
// PowerMockito does bytecode magic to mock static methods and use final classes
PowerMockito.mockStatic(InventoryDAOManager.class);
- InventoryDAOManager mockDAOManager = mock(InventoryDAOManager.class);
- when(InventoryDAOManager.getInstance()).thenReturn(mockDAOManager);
- Mockito.doThrow(new RuntimeException("Spoof initialization failure")).when(mockDAOManager).initialize();
+ InventoryDAOManager mockDaoManager = mock(InventoryDAOManager.class);
+ when(InventoryDAOManager.getInstance()).thenReturn(mockDaoManager);
+ Mockito.doThrow(new RuntimeException("Spoof initialization failure")).when(mockDaoManager).initialize();
RuntimeException fakeException = new RuntimeException("Spoofing database failure");
// Test UnableToObtainConnectionExceptionMapper
- DBIExceptionMapper.UnableToObtainConnectionExceptionMapper mapperOne = new DBIExceptionMapper.UnableToObtainConnectionExceptionMapper();
+ DBIExceptionMapper.UnableToObtainConnectionExceptionMapper mapperOne =
+ new DBIExceptionMapper.UnableToObtainConnectionExceptionMapper();
Response responseOne = mapperOne.toResponse(new UnableToObtainConnectionException(fakeException));
assert responseOne.getStatus() == 502;
String messageOne = ((ApiResponseMessage) responseOne.getEntity()).getMessage();
@@ -99,7 +103,8 @@ public class DBIExceptionMapperTests {
// Test UnableToCreateStatementExceptionMapper
- DBIExceptionMapper.UnableToCreateStatementExceptionMapper mapperTwo = new DBIExceptionMapper.UnableToCreateStatementExceptionMapper();
+ DBIExceptionMapper.UnableToCreateStatementExceptionMapper mapperTwo =
+ new DBIExceptionMapper.UnableToCreateStatementExceptionMapper();
Response responseTwo = mapperTwo.toResponse(new UnableToCreateStatementException(fakeException));
assert responseTwo.getStatus() == 502;
String messageTwo = ((ApiResponseMessage) responseTwo.getEntity()).getMessage();
@@ -107,7 +112,8 @@ public class DBIExceptionMapperTests {
// Test UnableToExecuteStatementExceptionMapper
- DBIExceptionMapper.UnableToExecuteStatementExceptionMapper mapperThree = new DBIExceptionMapper.UnableToExecuteStatementExceptionMapper();
+ DBIExceptionMapper.UnableToExecuteStatementExceptionMapper mapperThree =
+ new DBIExceptionMapper.UnableToExecuteStatementExceptionMapper();
Response responseThree = mapperThree.toResponse(new UnableToExecuteStatementException(fakeException));
assert responseThree.getStatus() == 502;
String messageThree = ((ApiResponseMessage) responseThree.getEntity()).getMessage();
diff --git a/src/test/java/org/onap/dcae/inventory/providers/NotFoundExceptionMapperTests.java b/src/test/java/org/onap/dcae/inventory/providers/NotFoundExceptionMapperTests.java
index 8e2b767..87defdf 100644
--- a/src/test/java/org/onap/dcae/inventory/providers/NotFoundExceptionMapperTests.java
+++ b/src/test/java/org/onap/dcae/inventory/providers/NotFoundExceptionMapperTests.java
@@ -20,12 +20,13 @@
package org.onap.dcae.inventory.providers;
-import io.swagger.api.NotFoundException;
-import org.junit.Test;
+import static org.junit.Assert.assertEquals;
import javax.ws.rs.core.Response;
-import static org.junit.Assert.assertEquals;
+import org.junit.Test;
+
+import io.swagger.api.NotFoundException;
/**
* Created by mhwang on 10/2/17.