summaryrefslogtreecommitdiffstats
path: root/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/system/DbUtilsTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/system/DbUtilsTest.java')
-rw-r--r--ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/system/DbUtilsTest.java627
1 files changed, 414 insertions, 213 deletions
diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/system/DbUtilsTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/system/DbUtilsTest.java
index 664e27c7..10e1d9e1 100644
--- a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/system/DbUtilsTest.java
+++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/system/DbUtilsTest.java
@@ -36,10 +36,14 @@
* ECOMP is a trademark and service mark of AT&T Intellectual Property.
*/
package org.onap.portalsdk.analytics.system;
-import static org.junit.Assert.*;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
import java.sql.CallableStatement;
import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
@@ -55,298 +59,495 @@ import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.onap.portalsdk.analytics.error.RaptorException;
import org.onap.portalsdk.analytics.error.ReportSQLException;
+import org.onap.portalsdk.analytics.model.runtime.ReportRuntime;
+import org.onap.portalsdk.analytics.xmlobj.DataColumnType;
import org.onap.portalsdk.core.web.support.AppUtils;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
@RunWith(PowerMockRunner.class)
-@PrepareForTest({AppUtils.class, Globals.class})
+@PrepareForTest({ AppUtils.class, Globals.class, Runtime.class, ConnectionUtils.class })
public class DbUtilsTest {
@Mock
DataSource dataSource;
-
+
@InjectMocks
DbUtils dbUtils = new DbUtils();
-
+
@Mock
Connection connection;
@Mock
CallableStatement stmt;
-
+
@Mock
Statement statement;
-
+
+ @Mock
+ ResultSet rs;
+
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
}
-
+
@SuppressWarnings("static-access")
@Test
- public void getConnectionTest() throws Exception
- {
+ public void getConnectionTest() throws Exception {
PowerMockito.mockStatic(AppUtils.class);
Mockito.when(AppUtils.getDatasource()).thenReturn(dataSource);
Mockito.when(dataSource.getConnection()).thenReturn(connection);
dbUtils.getConnection();
}
-
+
@SuppressWarnings({ "static-access", "unchecked" })
@Test
- public void getConnectionExceptionTest() throws Exception
- {
+ public void getConnectionExceptionTest() throws Exception {
PowerMockito.mockStatic(AppUtils.class);
Mockito.when(AppUtils.getDatasource()).thenThrow(SQLException.class);
Mockito.when(dataSource.getConnection()).thenReturn(connection);
assertNull(dbUtils.getConnection());
}
+
+ @SuppressWarnings("static-access")
+ @Test
+ public void clearConnectionTest() throws Exception
+ {
+ PowerMockito.mockStatic(Globals.class);
+ IDbUtils iDbUtils= PowerMockito.mock(IDbUtils.class);
+ Mockito.when(Globals.getDbUtils()).thenReturn(iDbUtils);
+ Mockito.doNothing().when(iDbUtils).clearConnection(connection);
+ Globals.getDbUtils().clearConnection(connection);
+ Mockito.when(connection.isClosed()).thenReturn(false);
+ dbUtils.clearConnection(connection);
+ }
- @SuppressWarnings("static-access")
- @Test
- public void clearConnectionTest() throws Exception
- {
- PowerMockito.mockStatic(Globals.class);
- IDbUtils iDbUtils= PowerMockito.mock(IDbUtils.class);
- Mockito.when(Globals.getDbUtils()).thenReturn(iDbUtils);
- Mockito.doNothing().when(iDbUtils).clearConnection(connection);
- Globals.getDbUtils().clearConnection(connection);
- Mockito.when(connection.isClosed()).thenReturn(false);
- dbUtils.clearConnection(connection);
- }
+ @SuppressWarnings("static-access")
+ @Test
+ public void clearConnection1Test() throws Exception
+ {
+ dbUtils.clearConnection(null);
+ }
- @SuppressWarnings("static-access")
- @Test
- public void clearConnection1Test() throws Exception
- {
- dbUtils.clearConnection(null);
- }
+ @SuppressWarnings({ "static-access", "unchecked" })
+ @Test(expected = Exception.class)
+ public void clearConnectionExceptionTest() throws Exception
+ {
+ PowerMockito.mockStatic(Globals.class);
+ IDbUtils iDbUtils= PowerMockito.mock(IDbUtils.class);
+ Mockito.when(Globals.getDbUtils()).thenThrow(Exception.class);
+ Mockito.doNothing().when(iDbUtils).clearConnection(connection);
+ Globals.getDbUtils().clearConnection(connection);
+ Mockito.when(connection.isClosed()).thenReturn(false);
+ dbUtils.clearConnection(connection);
+ }
- @SuppressWarnings({ "static-access", "unchecked" })
- @Test(expected = Exception.class)
- public void clearConnectionExceptionTest() throws Exception
- {
- PowerMockito.mockStatic(Globals.class);
- IDbUtils iDbUtils= PowerMockito.mock(IDbUtils.class);
- Mockito.when(Globals.getDbUtils()).thenThrow(Exception.class);
- Mockito.doNothing().when(iDbUtils).clearConnection(connection);
- Globals.getDbUtils().clearConnection(connection);
- Mockito.when(connection.isClosed()).thenReturn(false);
- dbUtils.clearConnection(connection);
- }
+ @SuppressWarnings({ "static-access", "unchecked" })
+ @Test(expected = SQLException.class)
+ public void clearConnectionException2Test() throws Exception
+ {
+ PowerMockito.mockStatic(Globals.class);
+ IDbUtils iDbUtils= PowerMockito.mock(IDbUtils.class);
+ Mockito.when(Globals.getDbUtils()).thenThrow(SQLException.class);
+ Mockito.doNothing().when(iDbUtils).clearConnection(connection);
+ Globals.getDbUtils().clearConnection(connection);
+ Mockito.when(connection.isClosed()).thenReturn(false);
+ dbUtils.clearConnection(connection);
+ }
+ @SuppressWarnings("static-access")
+ @Test
+ public void startTransactionTest() throws Exception
+ {
+ PowerMockito.mockStatic(AppUtils.class);
+ Mockito.when(AppUtils.getDatasource()).thenReturn(dataSource);
+ Mockito.when(dataSource.getConnection()).thenReturn(connection);
+ Mockito.doNothing().when(connection).setAutoCommit(false);
+ dbUtils.startTransaction();
+ }
- @SuppressWarnings({ "static-access", "unchecked" })
- @Test(expected = SQLException.class)
- public void clearConnectionException2Test() throws Exception
- {
- PowerMockito.mockStatic(Globals.class);
- IDbUtils iDbUtils= PowerMockito.mock(IDbUtils.class);
- Mockito.when(Globals.getDbUtils()).thenThrow(SQLException.class);
- Mockito.doNothing().when(iDbUtils).clearConnection(connection);
- Globals.getDbUtils().clearConnection(connection);
- Mockito.when(connection.isClosed()).thenReturn(false);
- dbUtils.clearConnection(connection);
- }
- @SuppressWarnings("static-access")
- @Test
- public void startTransactionTest() throws Exception
- {
- PowerMockito.mockStatic(AppUtils.class);
- Mockito.when(AppUtils.getDatasource()).thenReturn(dataSource);
- Mockito.when(dataSource.getConnection()).thenReturn(connection);
- Mockito.doNothing().when(connection).setAutoCommit(false);
- dbUtils.startTransaction();
- }
+ @SuppressWarnings("static-access")
+ @Test(expected = ReportSQLException.class)
+ public void startTransactionExceptionTest() throws Exception
+ {
+ Mockito.doNothing().when(connection).setAutoCommit(false);
+ PowerMockito.mockStatic(AppUtils.class);
+ Mockito.when(AppUtils.getDatasource()).thenThrow(SQLException.class);
+ Mockito.when(dataSource.getConnection()).thenReturn(null);
+ assertNull(dbUtils.startTransaction());
+ }
- @SuppressWarnings("static-access")
- @Test(expected = ReportSQLException.class)
- public void startTransactionExceptionTest() throws Exception
- {
- Mockito.doNothing().when(connection).setAutoCommit(false);
- PowerMockito.mockStatic(AppUtils.class);
- Mockito.when(AppUtils.getDatasource()).thenThrow(SQLException.class);
- Mockito.when(dataSource.getConnection()).thenReturn(null);
- assertNull(dbUtils.startTransaction());
- }
+ @SuppressWarnings({ "static-access", "unchecked" })
+ @Test(expected = ReportSQLException.class)
+ public void startTransactionException1Test() throws Exception
+ {
+ Mockito.doNothing().when(connection).setAutoCommit(false);
+ PowerMockito.mockStatic(AppUtils.class);
+ Mockito.when(AppUtils.getDatasource()).thenThrow(Exception.class);
+ Mockito.when(dataSource.getConnection()).thenReturn(null);
+ assertNull(dbUtils.startTransaction());
+ }
- @SuppressWarnings({ "static-access", "unchecked" })
- @Test(expected = ReportSQLException.class)
- public void startTransactionException1Test() throws Exception
- {
- Mockito.doNothing().when(connection).setAutoCommit(false);
- PowerMockito.mockStatic(AppUtils.class);
- Mockito.when(AppUtils.getDatasource()).thenThrow(Exception.class);
- Mockito.when(dataSource.getConnection()).thenReturn(null);
- assertNull(dbUtils.startTransaction());
- }
+ @SuppressWarnings("static-access")
+ @Test
+ public void commitTransactionTest() throws Exception
+ {
+ Mockito.doNothing().when(connection).commit();
+ dbUtils.commitTransaction(connection);
+ }
- @SuppressWarnings("static-access")
- @Test
- public void commitTransactionTest() throws Exception
- {
- Mockito.doNothing().when(connection).commit();
- dbUtils.commitTransaction(connection);
- }
+ @SuppressWarnings("static-access")
+ @Test(expected = RaptorException.class)
+ public void commitTransactionExceptionTest() throws Exception {
+ Mockito.doThrow(SQLException.class).when(connection).commit();
+ dbUtils.commitTransaction(connection);
+ }
- @SuppressWarnings("static-access")
- @Test(expected = RaptorException.class)
- public void commitTransactionExceptionTest() throws Exception {
- Mockito.doThrow(SQLException.class).when(connection).commit();
- dbUtils.commitTransaction(connection);
- }
-
- @SuppressWarnings("static-access")
- @Test(expected = Exception.class)
- public void commitTransactionException2Test() throws Exception {
- Mockito.doThrow(Exception.class).when(connection).commit();
- dbUtils.commitTransaction(connection);
- }
+ @SuppressWarnings("static-access")
+ @Test(expected = Exception.class)
+ public void commitTransactionException2Test() throws Exception {
+ Mockito.doThrow(Exception.class).when(connection).commit();
+ dbUtils.commitTransaction(connection);
+ }
-// @SuppressWarnings("static-access")
-// @Test
-// public void rollbackTransactionTest() throws Exception
-// {
-// Mockito.doNothing().when(connection).rollback();
-// dbUtils.rollbackTransaction(connection);
-// }
+ // @SuppressWarnings("static-access")
+ // @Test
+ // public void rollbackTransactionTest() throws Exception
+ // {
+ // Mockito.doNothing().when(connection).rollback();
+ // dbUtils.rollbackTransaction(connection);
+ // }
- @SuppressWarnings("static-access")
- @Test(expected = RaptorException.class)
- public void rollbackTransactionExceptionTest() throws Exception {
- Mockito.doThrow(SQLException.class).when(connection).rollback();
- dbUtils.rollbackTransaction(connection);
- }
-
- @SuppressWarnings("static-access")
- @Test(expected = Exception.class)
- public void rollbackTransactionException2Test() throws Exception {
- Mockito.doThrow(Exception.class).when(connection).rollback();
- dbUtils.rollbackTransaction(connection);
- }
+ @SuppressWarnings("static-access")
+ @Test(expected = RaptorException.class)
+ public void rollbackTransactionExceptionTest() throws Exception {
+ Mockito.doThrow(SQLException.class).when(connection).rollback();
+ dbUtils.rollbackTransaction(connection);
+ }
- @SuppressWarnings("static-access")
- @Test
- public void executeCallTest() throws Exception
- {
- Mockito.when(connection.isClosed()).thenReturn(true);
- PowerMockito.mockStatic(AppUtils.class);
- Mockito.when(AppUtils.getDatasource()).thenReturn(dataSource);
- Mockito.when(dataSource.getConnection()).thenReturn(connection);
- Mockito.when(connection.prepareCall(Matchers.anyString())).thenReturn(stmt);
- Mockito.when(stmt.getString(1)).thenReturn("test");
- dbUtils.executeCall(connection ,"test", false);
- }
+ @SuppressWarnings("static-access")
+ @Test(expected = Exception.class)
+ public void rollbackTransactionException2Test() throws Exception {
+ Mockito.doThrow(Exception.class).when(connection).rollback();
+ dbUtils.rollbackTransaction(connection);
+ }
- @SuppressWarnings("static-access")
- @Test
- public void executeCall1Test() throws Exception
- {
- Mockito.when(connection.isClosed()).thenReturn(true);
- PowerMockito.mockStatic(AppUtils.class);
- Mockito.when(AppUtils.getDatasource()).thenReturn(dataSource);
- Mockito.when(dataSource.getConnection()).thenReturn(connection);
- Mockito.when(connection.prepareCall(Matchers.anyString())).thenReturn(stmt);
- Mockito.when(stmt.getString(1)).thenReturn("test");
- dbUtils.executeCall(connection ,"test", true);
- }
+ @SuppressWarnings("static-access")
+ @Test
+ public void executeCallTest() throws Exception
+ {
+ Mockito.when(connection.isClosed()).thenReturn(true);
+ PowerMockito.mockStatic(AppUtils.class);
+ Mockito.when(AppUtils.getDatasource()).thenReturn(dataSource);
+ Mockito.when(dataSource.getConnection()).thenReturn(connection);
+ Mockito.when(connection.prepareCall(Matchers.anyString())).thenReturn(stmt);
+ Mockito.when(stmt.getString(1)).thenReturn("test");
+ dbUtils.executeCall(connection ,"test", false);
+ }
+
+ @SuppressWarnings("static-access")
+ @Test
+ public void executeCall1Test() throws Exception
+ {
+ Mockito.when(connection.isClosed()).thenReturn(true);
+ PowerMockito.mockStatic(AppUtils.class);
+ Mockito.when(AppUtils.getDatasource()).thenReturn(dataSource);
+ Mockito.when(dataSource.getConnection()).thenReturn(connection);
+ Mockito.when(connection.prepareCall(Matchers.anyString())).thenReturn(stmt);
+ Mockito.when(stmt.getString(1)).thenReturn("test");
+ dbUtils.executeCall(connection ,"test", true);
+ }
+
+
+ @SuppressWarnings({ "static-access", "unchecked" })
+ @Test(expected = RaptorException.class)
+ public void executeCall2Test() throws Exception
+ {
+ Mockito.when(connection.isClosed()).thenReturn(true);
+ PowerMockito.mockStatic(AppUtils.class);
+ Mockito.when(AppUtils.getDatasource()).thenReturn(dataSource);
+ Mockito.when(dataSource.getConnection()).thenReturn(connection);
+ Mockito.when(connection.prepareCall(Matchers.anyString())).thenThrow(SQLException.class);
+ Mockito.when(stmt.getString(1)).thenReturn("test");
+ dbUtils.executeCall(connection ,"test", true);
+ }
+
+ @SuppressWarnings("static-access")
+ @Test
+ public void executeCall3Test() throws Exception
+ {
+ PowerMockito.mockStatic(AppUtils.class);
+ Mockito.when(AppUtils.getDatasource()).thenReturn(dataSource);
+ Mockito.when(dataSource.getConnection()).thenReturn(connection);
+ Mockito.when(connection.isClosed()).thenReturn(true);
+ Mockito.when(connection.prepareCall(Matchers.anyString())).thenReturn(stmt);
+ Mockito.when(stmt.getString(1)).thenReturn("test");
+ dbUtils.executeCall("test", true);
+ }
+ @SuppressWarnings("static-access")
+ @Test
+ public void executeUpdateTest() throws Exception
+ {
+ Mockito.when(connection.createStatement()).thenReturn(statement);
+ Mockito.when(statement.executeUpdate(Matchers.anyString())).thenReturn(1);
+ assertEquals(dbUtils.executeUpdate(connection, "test"),1);
+ }
+
+ @SuppressWarnings({ "static-access", "unchecked" })
+ @Test(expected = RaptorException.class )
+ public void executeUpdate1Test() throws Exception
+ {
+ Mockito.when(connection.createStatement()).thenReturn(statement);
+ Mockito.when(statement.executeUpdate(Matchers.anyString())).thenThrow(SQLException.class);
+ dbUtils.executeUpdate(connection, "test");
+ }
+ @SuppressWarnings("static-access")
+ @Test
+ public void executeUpdate2Test() throws Exception
+ {
+ PowerMockito.mockStatic(AppUtils.class);
+ PowerMockito.mockStatic(Globals.class);
+ Mockito.when(AppUtils.getDatasource()).thenReturn(dataSource);
+ Mockito.when(dataSource.getConnection()).thenReturn(connection);
+ Mockito.when(connection.isClosed()).thenReturn(true);
+ Mockito.when(connection.prepareCall(Matchers.anyString())).thenReturn(stmt);
+ Mockito.when(connection.createStatement()).thenReturn(statement);
+ Mockito.when(statement.executeUpdate(Matchers.anyString())).thenReturn(1);
+ Mockito.when(stmt.getString(1)).thenReturn("test");
+ Mockito.when(Globals.getDBType()).thenReturn("oracle");
+ Mockito.doNothing().when(connection).commit();
+ dbUtils.executeUpdate("test");
+ }
+ @SuppressWarnings("static-access")
+ @Test
+ public void executeUpdate3Test() throws Exception
+ {
+ PowerMockito.mockStatic(AppUtils.class);
+ PowerMockito.mockStatic(Globals.class);
+ Mockito.when(AppUtils.getDatasource()).thenReturn(dataSource);
+ Mockito.when(dataSource.getConnection()).thenReturn(connection);
+ Mockito.when(connection.isClosed()).thenReturn(true);
+ Mockito.when(connection.prepareCall(Matchers.anyString())).thenReturn(stmt);
+ Mockito.when(connection.createStatement()).thenReturn(statement);
+ Mockito.when(statement.executeUpdate(Matchers.anyString())).thenReturn(1);
+ Mockito.when(stmt.getString(1)).thenReturn("test");
+ Mockito.when(Globals.getDBType()).thenReturn("oracle1");
+ Mockito.doNothing().when(connection).commit();
+ dbUtils.executeUpdate("test");
+ }
+
+
+ @SuppressWarnings("static-access")
+ @Test(expected = RaptorException.class)
+ public void executeUpdate4Test() throws Exception
+ {
+ PowerMockito.mockStatic(AppUtils.class);
+ PowerMockito.mockStatic(Globals.class);
+ Mockito.when(AppUtils.getDatasource()).thenReturn(dataSource);
+ Mockito.when(dataSource.getConnection()).thenReturn(connection);
+ Mockito.when(connection.isClosed()).thenReturn(true);
+ Mockito.when(connection.prepareCall(Matchers.anyString())).thenReturn(stmt);
+ Mockito.when(connection.createStatement()).thenReturn(statement);
+ Mockito.when(statement.executeUpdate(Matchers.anyString())).thenReturn(1);
+ Mockito.when(stmt.getString(1)).thenReturn("test");
+ Mockito.when(Globals.getDBType()).thenReturn("oracle");
+ Mockito.doThrow(SQLException.class).when(connection).commit();
+ dbUtils.executeUpdate("test");
+ }
- @SuppressWarnings({ "static-access", "unchecked" })
- @Test(expected = RaptorException.class)
- public void executeCall2Test() throws Exception
- {
- Mockito.when(connection.isClosed()).thenReturn(true);
- PowerMockito.mockStatic(AppUtils.class);
- Mockito.when(AppUtils.getDatasource()).thenReturn(dataSource);
- Mockito.when(dataSource.getConnection()).thenReturn(connection);
- Mockito.when(connection.prepareCall(Matchers.anyString())).thenThrow(SQLException.class);
- Mockito.when(stmt.getString(1)).thenReturn("test");
- dbUtils.executeCall(connection ,"test", true);
- }
+ @SuppressWarnings("static-access")
+ @Test
+ public void executeQueryTest() throws Exception
+ {
+ PowerMockito.mockStatic(AppUtils.class);
+ Mockito.when(AppUtils.getDatasource()).thenReturn(dataSource);
+ Mockito.when(dataSource.getConnection()).thenReturn(connection);
+ Mockito.when(connection.isClosed()).thenReturn(true);
+ Mockito.when(connection.createStatement()).thenReturn(statement);
+ Mockito.when(statement.executeQuery("test")).thenReturn(rs);
+ PowerMockito.mockStatic(Runtime.class);
+ Mockito.when(Runtime.getRuntime()).thenReturn(null);
+ ResultSetMetaData rsmd = PowerMockito.mock(ResultSetMetaData.class);
+ Mockito.when(rs.getMetaData()).thenReturn(rsmd);
+ Mockito.when(rsmd.getColumnCount()).thenReturn(1);
+ Mockito.when(rsmd.getColumnLabel(0)).thenReturn("test");
+ Mockito.when(rsmd.getColumnTypeName(0)).thenReturn("test");
+ dbUtils.executeQuery(connection, "test");
+ }
+
+ @SuppressWarnings("static-access")
+ @Test(expected = ReportSQLException.class)
+ public void executeQuery1Test() throws Exception
+ {
+ PowerMockito.mockStatic(AppUtils.class);
+ Mockito.when(AppUtils.getDatasource()).thenReturn(dataSource);
+ Mockito.when(dataSource.getConnection()).thenReturn(connection);
+ Mockito.when(connection.isClosed()).thenReturn(true);
+ Mockito.when(connection.createStatement()).thenThrow(SQLException.class);
+ Mockito.when(statement.executeQuery("test")).thenReturn(rs);
+ PowerMockito.mockStatic(Runtime.class);
+ Mockito.when(Runtime.getRuntime()).thenReturn(null);
+ ResultSetMetaData rsmd = PowerMockito.mock(ResultSetMetaData.class);
+ Mockito.when(rs.getMetaData()).thenReturn(rsmd);
+ Mockito.when(rsmd.getColumnCount()).thenReturn(1);
+ Mockito.when(rsmd.getColumnLabel(0)).thenReturn("test");
+ Mockito.when(rsmd.getColumnTypeName(0)).thenReturn("test");
+ dbUtils.executeQuery(connection, "test");
+ }
+
+ @SuppressWarnings("static-access")
+ @Test(expected = ReportSQLException.class)
+ public void executeQuery2Test() throws Exception
+ {
+ PowerMockito.mockStatic(AppUtils.class);
+ Mockito.when(AppUtils.getDatasource()).thenReturn(dataSource);
+ Mockito.when(dataSource.getConnection()).thenReturn(connection);
+ Mockito.when(connection.isClosed()).thenReturn(false);
+ Mockito.when(connection.createStatement()).thenThrow(SQLException.class);
+ Mockito.when(statement.executeQuery("test")).thenReturn(rs);
+ PowerMockito.mockStatic(Runtime.class);
+ Mockito.when(Runtime.getRuntime()).thenReturn(null);
+ ResultSetMetaData rsmd = PowerMockito.mock(ResultSetMetaData.class);
+ Mockito.when(rs.getMetaData()).thenReturn(rsmd);
+ Mockito.when(rsmd.getColumnCount()).thenReturn(1);
+ Mockito.when(rsmd.getColumnLabel(0)).thenReturn("test");
+ Mockito.when(rsmd.getColumnTypeName(0)).thenReturn("test");
+ dbUtils.executeQuery(connection, "test");
+ }
+
+ @SuppressWarnings("static-access")
+ @Test(expected = ReportSQLException.class)
+ public void executeQuery3Test() throws Exception
+ {
+ PowerMockito.mockStatic(AppUtils.class);
+ Mockito.when(AppUtils.getDatasource()).thenReturn(dataSource);
+ Mockito.when(dataSource.getConnection()).thenReturn(connection);
+ Mockito.when(connection.isClosed()).thenReturn(false);
+ Mockito.when(connection.createStatement()).thenThrow(SQLException.class);
+ Mockito.when(statement.executeQuery("test")).thenReturn(rs);
+ PowerMockito.mockStatic(Runtime.class);
+ Mockito.when(Runtime.getRuntime()).thenReturn(null);
+ ResultSetMetaData rsmd = PowerMockito.mock(ResultSetMetaData.class);
+ Mockito.when(rs.getMetaData()).thenReturn(rsmd);
+ Mockito.when(rsmd.getColumnCount()).thenReturn(1);
+ Mockito.when(rsmd.getColumnLabel(0)).thenReturn("test");
+ Mockito.when(rsmd.getColumnTypeName(0)).thenReturn("test");
+ dbUtils.executeQuery(connection, "test", 1);
+ }
+
+
@SuppressWarnings("static-access")
@Test
- public void executeCall3Test() throws Exception
- {
+ public void executeQuery4Test() throws Exception {
PowerMockito.mockStatic(AppUtils.class);
Mockito.when(AppUtils.getDatasource()).thenReturn(dataSource);
Mockito.when(dataSource.getConnection()).thenReturn(connection);
Mockito.when(connection.isClosed()).thenReturn(true);
- Mockito.when(connection.prepareCall(Matchers.anyString())).thenReturn(stmt);
- Mockito.when(stmt.getString(1)).thenReturn("test");
- dbUtils.executeCall("test", true);
- }
- @SuppressWarnings("static-access")
- @Test
- public void executeUpdateTest() throws Exception
- {
Mockito.when(connection.createStatement()).thenReturn(statement);
- Mockito.when(statement.executeUpdate(Matchers.anyString())).thenReturn(1);
- assertEquals(dbUtils.executeUpdate(connection, "test"),1);
- }
-
- @SuppressWarnings({ "static-access", "unchecked" })
- @Test(expected = RaptorException.class )
- public void executeUpdate1Test() throws Exception
- {
- Mockito.when(connection.createStatement()).thenReturn(statement);
- Mockito.when(statement.executeUpdate(Matchers.anyString())).thenThrow(SQLException.class);
- dbUtils.executeUpdate(connection, "test");
+ Mockito.when(statement.executeQuery("test")).thenReturn(rs);
+ PowerMockito.mockStatic(Runtime.class);
+ Mockito.when(Runtime.getRuntime()).thenReturn(null);
+ ResultSetMetaData rsmd = PowerMockito.mock(ResultSetMetaData.class);
+ Mockito.when(rs.getMetaData()).thenReturn(rsmd);
+ Mockito.when(rsmd.getColumnCount()).thenReturn(1);
+ Mockito.when(rsmd.getColumnLabel(0)).thenReturn("test");
+ Mockito.when(rsmd.getColumnTypeName(0)).thenReturn("test");
+ dbUtils.executeQuery("test", 1);
}
+
@SuppressWarnings("static-access")
@Test
- public void executeUpdate2Test() throws Exception
- {
+ public void executeQuery5Test() throws Exception {
PowerMockito.mockStatic(AppUtils.class);
- PowerMockito.mockStatic(Globals.class);
Mockito.when(AppUtils.getDatasource()).thenReturn(dataSource);
Mockito.when(dataSource.getConnection()).thenReturn(connection);
Mockito.when(connection.isClosed()).thenReturn(true);
- Mockito.when(connection.prepareCall(Matchers.anyString())).thenReturn(stmt);
Mockito.when(connection.createStatement()).thenReturn(statement);
- Mockito.when(statement.executeUpdate(Matchers.anyString())).thenReturn(1);
- Mockito.when(stmt.getString(1)).thenReturn("test");
- Mockito.when(Globals.getDBType()).thenReturn("oracle");
- Mockito.doNothing().when(connection).commit();
- dbUtils.executeUpdate("test");
+ Mockito.when(statement.executeQuery("test")).thenReturn(rs);
+ PowerMockito.mockStatic(Runtime.class);
+ Mockito.when(Runtime.getRuntime()).thenReturn(null);
+ ResultSetMetaData rsmd = PowerMockito.mock(ResultSetMetaData.class);
+ Mockito.when(rs.getMetaData()).thenReturn(rsmd);
+ Mockito.when(rsmd.getColumnCount()).thenReturn(1);
+ Mockito.when(rsmd.getColumnLabel(0)).thenReturn("test");
+ Mockito.when(rsmd.getColumnTypeName(0)).thenReturn("test");
+ ReportRuntime rr = PowerMockito.mock(ReportRuntime.class);
+ Mockito.when(rr.getDBInfo()).thenReturn("test");
+ PowerMockito.mockStatic(ConnectionUtils.class);
+ Mockito.when(ConnectionUtils.getConnection(Matchers.anyString())).thenReturn(connection);
+ Mockito.when(rr.getWholeSQL()).thenReturn("test");
+ DataColumnType dc = PowerMockito.mock(DataColumnType.class);
+ Mockito.when(rr.getColumnWhichNeedEnhancedPagination()).thenReturn(dc);
+ Mockito.when(dc.getColId()).thenReturn("test");
+ Mockito.when(dc.getColFormat()).thenReturn("test");
+ dbUtils.executeQuery(rr, 1);
}
-
+
@SuppressWarnings("static-access")
@Test
- public void executeUpdate3Test() throws Exception
- {
+ public void executeQuery6Test() throws Exception {
PowerMockito.mockStatic(AppUtils.class);
- PowerMockito.mockStatic(Globals.class);
Mockito.when(AppUtils.getDatasource()).thenReturn(dataSource);
Mockito.when(dataSource.getConnection()).thenReturn(connection);
Mockito.when(connection.isClosed()).thenReturn(true);
- Mockito.when(connection.prepareCall(Matchers.anyString())).thenReturn(stmt);
Mockito.when(connection.createStatement()).thenReturn(statement);
- Mockito.when(statement.executeUpdate(Matchers.anyString())).thenReturn(1);
- Mockito.when(stmt.getString(1)).thenReturn("test");
- Mockito.when(Globals.getDBType()).thenReturn("oracle1");
- Mockito.doNothing().when(connection).commit();
- dbUtils.executeUpdate("test");
+ Mockito.when(statement.executeQuery("test")).thenReturn(rs);
+ PowerMockito.mockStatic(Runtime.class);
+ Mockito.when(Runtime.getRuntime()).thenReturn(null);
+ ResultSetMetaData rsmd = PowerMockito.mock(ResultSetMetaData.class);
+ Mockito.when(rs.getMetaData()).thenReturn(rsmd);
+ Mockito.when(rsmd.getColumnCount()).thenReturn(1);
+ Mockito.when(rsmd.getColumnLabel(0)).thenReturn("test");
+ Mockito.when(rsmd.getColumnTypeName(0)).thenReturn("test");
+ ReportRuntime rr = PowerMockito.mock(ReportRuntime.class);
+ Mockito.when(rr.getDBInfo()).thenReturn("test");
+ PowerMockito.mockStatic(ConnectionUtils.class);
+ Mockito.when(ConnectionUtils.getConnection(Matchers.anyString())).thenReturn(connection);
+ Mockito.when(rr.getWholeSQL()).thenReturn("test");
+ DataColumnType dc = PowerMockito.mock(DataColumnType.class);
+ Mockito.when(rr.getColumnWhichNeedEnhancedPagination()).thenReturn(dc);
+ Mockito.when(dc.getColId()).thenReturn("test");
+ Mockito.when(dc.getColFormat()).thenReturn("test");
+ dbUtils.executeQuery(rr, 2);
}
-
-
+
@SuppressWarnings("static-access")
- @Test(expected = RaptorException.class)
- public void executeUpdate4Test() throws Exception
- {
+ @Test
+ public void executeQuery7Test() throws Exception {
PowerMockito.mockStatic(AppUtils.class);
- PowerMockito.mockStatic(Globals.class);
Mockito.when(AppUtils.getDatasource()).thenReturn(dataSource);
Mockito.when(dataSource.getConnection()).thenReturn(connection);
Mockito.when(connection.isClosed()).thenReturn(true);
- Mockito.when(connection.prepareCall(Matchers.anyString())).thenReturn(stmt);
Mockito.when(connection.createStatement()).thenReturn(statement);
- Mockito.when(statement.executeUpdate(Matchers.anyString())).thenReturn(1);
- Mockito.when(stmt.getString(1)).thenReturn("test");
- Mockito.when(Globals.getDBType()).thenReturn("oracle");
- Mockito.doThrow(SQLException.class).when(connection).commit();
- dbUtils.executeUpdate("test");
+ Mockito.when(statement.executeQuery("test")).thenReturn(rs);
+ PowerMockito.mockStatic(Runtime.class);
+ Mockito.when(Runtime.getRuntime()).thenReturn(null);
+ ResultSetMetaData rsmd = PowerMockito.mock(ResultSetMetaData.class);
+ Mockito.when(rs.getMetaData()).thenReturn(rsmd);
+ Mockito.when(rsmd.getColumnCount()).thenReturn(1);
+ Mockito.when(rsmd.getColumnLabel(0)).thenReturn("test");
+ Mockito.when(rsmd.getColumnTypeName(0)).thenReturn("test");
+ ReportRuntime rr = PowerMockito.mock(ReportRuntime.class);
+ Mockito.when(rr.getDBInfo()).thenReturn("test");
+ PowerMockito.mockStatic(ConnectionUtils.class);
+ Mockito.when(ConnectionUtils.getConnection(Matchers.anyString())).thenReturn(connection);
+ Mockito.when(rr.getWholeSQL()).thenReturn("test");
+ DataColumnType dc = PowerMockito.mock(DataColumnType.class);
+ Mockito.when(rr.getColumnWhichNeedEnhancedPagination()).thenReturn(dc);
+ Mockito.when(dc.getColId()).thenReturn("test");
+ Mockito.when(dc.getColFormat()).thenReturn("test");
+ dbUtils.executeQuery(rr, 3);
+ }
+
+ @Test
+ public void nvlTest() {
+ assertEquals(dbUtils.nvl(null), "");
+ assertEquals(dbUtils.nvl("test"), "test");
+ assertEquals(dbUtils.nvls("test"), "test");
+ assertEquals(dbUtils.nvls(null), "");
+ assertEquals(dbUtils.nvl("test", "test1"), "test");
+ assertEquals(dbUtils.nvl(null, "test1"), "test1");
}
-
}