use of com.yahoo.athenz.zms.store.jdbc.JDBCConnection in project athenz by yahoo.
the class JDBCConnectionTest method testDeletePrincipalFailure.
@Test
public void testDeletePrincipalFailure() throws Exception {
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
// both delete requests as failure
Mockito.when(mockPrepStmt.executeUpdate()).thenReturn(0);
Mockito.when(mockResultSet.next()).thenReturn(true);
boolean requestSuccess = jdbcConn.deletePrincipal("user.jake", true);
assertTrue(requestSuccess);
Mockito.verify(mockPrepStmt, times(1)).setString(1, "user.jake");
Mockito.verify(mockPrepStmt, times(1)).setString(1, "user.jake.%");
jdbcConn.close();
}
use of com.yahoo.athenz.zms.store.jdbc.JDBCConnection in project athenz by yahoo.
the class JDBCConnectionTest method testInsertDomain.
@Test
public void testInsertDomain() 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.doReturn(1).when(mockPrepStmt).executeUpdate();
boolean requestSuccess = jdbcConn.insertDomain(domain);
assertTrue(requestSuccess);
Mockito.verify(mockPrepStmt, times(1)).setString(1, "my-domain");
Mockito.verify(mockPrepStmt, times(1)).setString(2, "my domain");
Mockito.verify(mockPrepStmt, times(1)).setString(3, "cloud_services");
Mockito.verify(mockPrepStmt, times(1)).setString(4, "e5e97240-e94e-11e4-8163-6d083f3f473f");
Mockito.verify(mockPrepStmt, times(1)).setBoolean(5, true);
Mockito.verify(mockPrepStmt, times(1)).setBoolean(6, false);
Mockito.verify(mockPrepStmt, times(1)).setString(7, "");
Mockito.verify(mockPrepStmt, times(1)).setInt(8, 0);
jdbcConn.close();
}
use of com.yahoo.athenz.zms.store.jdbc.JDBCConnection in project athenz by yahoo.
the class JDBCConnectionTest method testUpdateDomain.
@Test
public void testUpdateDomain() 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").setAccount("123456789").setYpmId(Integer.valueOf(1011)).setApplicationId("application_id");
Mockito.doReturn(1).when(mockPrepStmt).executeUpdate();
boolean requestSuccess = jdbcConn.updateDomain(domain);
assertTrue(requestSuccess);
Mockito.verify(mockPrepStmt, times(1)).setString(1, "my domain");
Mockito.verify(mockPrepStmt, times(1)).setString(2, "cloud_services");
Mockito.verify(mockPrepStmt, times(1)).setString(3, "e5e97240-e94e-11e4-8163-6d083f3f473f");
Mockito.verify(mockPrepStmt, times(1)).setBoolean(4, true);
Mockito.verify(mockPrepStmt, times(1)).setBoolean(5, false);
Mockito.verify(mockPrepStmt, times(1)).setString(6, "123456789");
Mockito.verify(mockPrepStmt, times(1)).setInt(7, 1011);
Mockito.verify(mockPrepStmt, times(1)).setString(8, "application_id");
Mockito.verify(mockPrepStmt, times(1)).setString(9, "my-domain");
jdbcConn.close();
}
use of com.yahoo.athenz.zms.store.jdbc.JDBCConnection in project athenz by yahoo.
the class JDBCConnectionTest method testGetAssertion.
@Test
public void testGetAssertion() throws Exception {
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
Mockito.when(mockResultSet.next()).thenReturn(true);
Mockito.when(mockResultSet.getString(ZMSConsts.DB_COLUMN_ROLE)).thenReturn("role1");
Mockito.when(mockResultSet.getString(ZMSConsts.DB_COLUMN_RESOURCE)).thenReturn("my-domain:*");
Mockito.when(mockResultSet.getString(ZMSConsts.DB_COLUMN_ACTION)).thenReturn("*");
Mockito.when(mockResultSet.getString(ZMSConsts.DB_COLUMN_EFFECT)).thenReturn("ALLOW");
Assertion assertion = jdbcConn.getAssertion("my-domain", "policy1", Long.valueOf(101));
assertEquals("my-domain:role.role1", assertion.getRole());
assertEquals("my-domain:*", assertion.getResource());
assertEquals("*", assertion.getAction());
assertEquals("ALLOW", assertion.getEffect().toString());
Mockito.verify(mockPrepStmt, times(1)).setInt(1, 101);
Mockito.verify(mockPrepStmt, times(1)).setString(2, "my-domain");
Mockito.verify(mockPrepStmt, times(1)).setString(3, "policy1");
jdbcConn.close();
}
use of com.yahoo.athenz.zms.store.jdbc.JDBCConnection in project athenz by yahoo.
the class JDBCConnectionTest method testGetAssertionException.
@Test
public void testGetAssertionException() throws Exception {
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
Mockito.when(mockPrepStmt.executeQuery()).thenThrow(new SQLException("failed operation", "state", 1001));
try {
jdbcConn.getAssertion("my-domain", "policy1", Long.valueOf(101));
fail();
} catch (Exception ex) {
assertTrue(true);
}
jdbcConn.close();
}
Aggregations