diff options
author | 2018-03-22 11:02:57 -0400 | |
---|---|---|
committer | 2018-03-26 10:56:24 -0400 | |
commit | e65fc2fc02594a7c8640a6330b2373db1efb923e (patch) | |
tree | 4433e083f96dcb1ad26c6f73d437195d6d8f7a75 /src/test/java/org/onap/dcae/inventory/exception/mappers/DBIExceptionMapperTests.java | |
parent | 7f61b70d33879712c5dad64c04a5d54b2b065138 (diff) |
Add unit tests to reach 50% coverage
Ripped out the dcae controller code which is no longer
needed.
Change-Id: I43906edb80bcd5e25445ec2a7175c6748b0ab2ae
Signed-off-by: Michael Hwang <mhwang@research.att.com>
Issue-ID: DCAEGEN2-257
Diffstat (limited to 'src/test/java/org/onap/dcae/inventory/exception/mappers/DBIExceptionMapperTests.java')
-rw-r--r-- | src/test/java/org/onap/dcae/inventory/exception/mappers/DBIExceptionMapperTests.java | 117 |
1 files changed, 0 insertions, 117 deletions
diff --git a/src/test/java/org/onap/dcae/inventory/exception/mappers/DBIExceptionMapperTests.java b/src/test/java/org/onap/dcae/inventory/exception/mappers/DBIExceptionMapperTests.java deleted file mode 100644 index 7c04295..0000000 --- a/src/test/java/org/onap/dcae/inventory/exception/mappers/DBIExceptionMapperTests.java +++ /dev/null @@ -1,117 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * dcae-inventory - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.dcae.inventory.exception.mappers; - -import org.onap.dcae.inventory.daos.InventoryDAOManager; -import org.onap.dcae.inventory.exceptions.mappers.DBIExceptionMapper; -import io.swagger.api.ApiResponseMessage; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mockito; -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.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; - -/** - * Created by mhwang on 3/8/17. - */ -@PrepareForTest({InventoryDAOManager.class}) -@RunWith(PowerMockRunner.class) -public class DBIExceptionMapperTests { - - @Test - 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); - - RuntimeException fakeException = new RuntimeException("Spoofing database failure"); - - // Test UnableToObtainConnectionExceptionMapper - - DBIExceptionMapper.UnableToObtainConnectionExceptionMapper mapperOne = new DBIExceptionMapper.UnableToObtainConnectionExceptionMapper(); - Response responseOne = mapperOne.toResponse(new UnableToObtainConnectionException(fakeException)); - assert responseOne.getStatus() == 502; - String messageOne = ((ApiResponseMessage) responseOne.getEntity()).getMessage(); - assert messageOne.contains("successfully reset"); - - // Test UnableToCreateStatementExceptionMapper - - DBIExceptionMapper.UnableToCreateStatementExceptionMapper mapperTwo = new DBIExceptionMapper.UnableToCreateStatementExceptionMapper(); - Response responseTwo = mapperTwo.toResponse(new UnableToCreateStatementException(fakeException)); - assert responseTwo.getStatus() == 502; - String messageTwo = ((ApiResponseMessage) responseTwo.getEntity()).getMessage(); - assert messageTwo.contains("successfully reset"); - - // Test UnableToExecuteStatementExceptionMapper - - DBIExceptionMapper.UnableToExecuteStatementExceptionMapper mapperThree = new DBIExceptionMapper.UnableToExecuteStatementExceptionMapper(); - Response responseThree = mapperThree.toResponse(new UnableToExecuteStatementException(fakeException)); - assert responseThree.getStatus() == 502; - String messageThree = ((ApiResponseMessage) responseThree.getEntity()).getMessage(); - assert messageThree.contains("successfully reset"); - } - - @Test - 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(); - - RuntimeException fakeException = new RuntimeException("Spoofing database failure"); - - // Test UnableToObtainConnectionExceptionMapper - - DBIExceptionMapper.UnableToObtainConnectionExceptionMapper mapperOne = new DBIExceptionMapper.UnableToObtainConnectionExceptionMapper(); - Response responseOne = mapperOne.toResponse(new UnableToObtainConnectionException(fakeException)); - assert responseOne.getStatus() == 502; - String messageOne = ((ApiResponseMessage) responseOne.getEntity()).getMessage(); - assert !messageOne.contains("successfully reset"); - - // Test UnableToCreateStatementExceptionMapper - - DBIExceptionMapper.UnableToCreateStatementExceptionMapper mapperTwo = new DBIExceptionMapper.UnableToCreateStatementExceptionMapper(); - Response responseTwo = mapperTwo.toResponse(new UnableToCreateStatementException(fakeException)); - assert responseTwo.getStatus() == 502; - String messageTwo = ((ApiResponseMessage) responseTwo.getEntity()).getMessage(); - assert !messageTwo.contains("successfully reset"); - - // Test UnableToExecuteStatementExceptionMapper - - DBIExceptionMapper.UnableToExecuteStatementExceptionMapper mapperThree = new DBIExceptionMapper.UnableToExecuteStatementExceptionMapper(); - Response responseThree = mapperThree.toResponse(new UnableToExecuteStatementException(fakeException)); - assert responseThree.getStatus() == 502; - String messageThree = ((ApiResponseMessage) responseThree.getEntity()).getMessage(); - assert !messageThree.contains("successfully reset"); - } - -} |