use of com.yahoo.athenz.zms.store.jdbc.JDBCConnection in project athenz by yahoo.
the class JDBCConnectionTest method testGetDomain.
@Test
public void testGetDomain() throws Exception {
Mockito.when(mockResultSet.next()).thenReturn(true);
Mockito.doReturn("my-domain").when(mockResultSet).getString(ZMSConsts.DB_COLUMN_NAME);
Mockito.doReturn(new java.sql.Timestamp(1454358916)).when(mockResultSet).getTimestamp(ZMSConsts.DB_COLUMN_MODIFIED);
Mockito.doReturn(true).when(mockResultSet).getBoolean(ZMSConsts.DB_COLUMN_ENABLED);
Mockito.doReturn(false).when(mockResultSet).getBoolean(ZMSConsts.DB_COLUMN_AUDIT_ENABLED);
Mockito.doReturn("").when(mockResultSet).getString(ZMSConsts.DB_COLUMN_DESCRIPTION);
Mockito.doReturn("").when(mockResultSet).getString(ZMSConsts.DB_COLUMN_ORG);
Mockito.doReturn("").when(mockResultSet).getString(ZMSConsts.DB_COLUMN_UUID);
Mockito.doReturn("12345").when(mockResultSet).getString(ZMSConsts.DB_COLUMN_ACCOUNT);
Mockito.doReturn(1001).when(mockResultSet).getInt(ZMSConsts.DB_COLUMN_PRODUCT_ID);
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
Domain domain = jdbcConn.getDomain("my-domain");
assertNotNull(domain);
assertEquals("my-domain", domain.getName());
assertTrue(domain.getEnabled());
assertFalse(domain.getAuditEnabled());
assertNull(domain.getDescription());
assertNull(domain.getOrg());
assertNull(domain.getId());
jdbcConn.close();
}
use of com.yahoo.athenz.zms.store.jdbc.JDBCConnection in project athenz by yahoo.
the class JDBCConnectionTest method testDeletePublicKeyEntryException.
@Test
public void testDeletePublicKeyEntryException() throws Exception {
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
Mockito.when(mockResultSet.getInt(1)).thenReturn(// domain id
5).thenReturn(// service id
7);
Mockito.when(mockResultSet.next()).thenReturn(// this one is for domain id
true).thenReturn(// this one is for service id
true);
Mockito.when(mockPrepStmt.executeUpdate()).thenThrow(new SQLException("failed operation", "state", 1001));
try {
jdbcConn.deletePublicKeyEntry("my-domain", "service1", "zms1");
fail();
} catch (Exception ex) {
assertTrue(true);
}
jdbcConn.close();
}
use of com.yahoo.athenz.zms.store.jdbc.JDBCConnection in project athenz by yahoo.
the class JDBCConnectionTest method testDeleteAssertionInvalidPolicy.
@Test
public void testDeleteAssertionInvalidPolicy() throws Exception {
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
Mockito.when(mockResultSet.getInt(1)).thenReturn(// domain id
5);
Mockito.when(mockResultSet.next()).thenReturn(// this one is for domain id
true).thenReturn(// this one is for policy id
false);
try {
jdbcConn.deleteAssertion("my-domain", "policy1", (long) 101);
fail();
} catch (Exception ex) {
assertTrue(true);
}
jdbcConn.close();
}
use of com.yahoo.athenz.zms.store.jdbc.JDBCConnection in project athenz by yahoo.
the class JDBCConnectionTest method testInsertDomainException.
@Test
public void testInsertDomainException() throws Exception {
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
Domain domain = new Domain().setName("my-domain").setEnabled(true).setAuditEnabled(false).setDescription("my domain").setId(UUID.fromString("e5e97240-e94e-11e4-8163-6d083f3f473f")).setOrg("cloud_services");
Mockito.when(mockPrepStmt.executeUpdate()).thenThrow(new SQLException("failed operation", "state", 1001));
try {
jdbcConn.insertDomain(domain);
fail();
} catch (Exception ex) {
assertTrue(true);
}
jdbcConn.close();
}
use of com.yahoo.athenz.zms.store.jdbc.JDBCConnection in project athenz by yahoo.
the class JDBCConnectionTest method testUpdatePolicyModTimestampSuccess.
@Test
public void testUpdatePolicyModTimestampSuccess() throws Exception {
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
Mockito.doReturn(1).when(mockPrepStmt).executeUpdate();
Mockito.when(mockResultSet.next()).thenReturn(true);
Mockito.when(mockResultSet.getInt(1)).thenReturn(// domain id
5).thenReturn(// policy id
7);
boolean requestSuccess = jdbcConn.updatePolicyModTimestamp("my-domain", "policy1");
assertTrue(requestSuccess);
// get domain id
Mockito.verify(mockPrepStmt, times(1)).setString(1, "my-domain");
// get policy id
Mockito.verify(mockPrepStmt, times(1)).setInt(1, 5);
Mockito.verify(mockPrepStmt, times(1)).setString(2, "policy1");
// update policy time-stamp
Mockito.verify(mockPrepStmt, times(1)).setInt(1, 7);
jdbcConn.close();
}
Aggregations