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.
public void testNoServletConfig() {
try {
(new Bootstrap()).init(null);
- } catch(ServletException e) {
+ } catch (ServletException e) {
fail("This might be a valid failure. Should investigate.");
}
}
* ============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.
}
@Override
- public String getPath(boolean b) {
+ public String getPath(boolean bunused) {
return null;
}
}
@Override
- public List<PathSegment> getPathSegments(boolean b) {
+ public List<PathSegment> getPathSegments(boolean bunused) {
return null;
}
}
@Override
- public MultivaluedMap<String, String> getPathParameters(boolean b) {
+ public MultivaluedMap<String, String> getPathParameters(boolean bunused) {
return null;
}
}
@Override
- public MultivaluedMap<String, String> getQueryParameters(boolean b) {
+ public MultivaluedMap<String, String> getQueryParameters(boolean bunused) {
return null;
}
}
@Override
- public List<String> getMatchedURIs(boolean b) {
+ public List<String> getMatchedURIs(boolean bunused) {
return null;
}
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.
*/
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.
*/
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.
*/
* ============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;
/**
@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())
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);
@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())
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);
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;
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.
@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" );
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");
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);
* ============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;
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.
@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
// 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");
}
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");
}
}
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);
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);
@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);
}
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);
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");
}
}
@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);
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");
}
}
* ============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;
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.
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
}
/*
- 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();
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");
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");
}
}
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.
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;
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;
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");
}
try {
assertEquals(client.isExists("some-component-id"), false);
- } catch(Exception e) {
+ } catch (Exception e) {
fail("Unexpected exception");
}
}
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");
}
}
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" );
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");
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.");
}
}
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);
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;
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.
*/
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");
}
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.
*/
try {
assertNotNull(mapper.map(0, resultSet, null));
- } catch(Exception e) {
+ } catch (Exception e) {
fail("Unexpected exception");
}
}
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.
*/
try {
when(resultSet.getString("status")).thenReturn("RUNNING");
assertNotNull(mapper.map(0, resultSet, null));
- } catch(Exception e) {
+ } catch (Exception e) {
fail("Unexpected exception");
}
}
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.
}
});
TestCase.assertNotNull(mapper.map(0, resultSet, null));
- } catch(Exception e) {
+ } catch (Exception e) {
fail("Unexpected exception");
}
}
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.
*/
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.
*/
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;
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.
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();
// 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();
// 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();
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();
// 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();
// 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();
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.