use of com.yahoo.athenz.zms.store.jdbc.JDBCConnection in project athenz by yahoo.
the class JDBCConnectionTest method testPrepareScanByRoleStatementOnlyRoleMemberNull.
@Test
public void testPrepareScanByRoleStatementOnlyRoleMemberNull() throws Exception {
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
jdbcConn.prepareScanByRoleStatement("user.member", null);
Mockito.verify(mockPrepStmt, times(1)).setString(Matchers.eq(1), Matchers.eq("user.member"));
Mockito.verify(mockPrepStmt, times(0)).setString(Matchers.eq(2), Mockito.isA(String.class));
jdbcConn.close();
}
use of com.yahoo.athenz.zms.store.jdbc.JDBCConnection in project athenz by yahoo.
the class JDBCConnectionTest method testCommit.
@Test
public void testCommit() throws Exception {
JDBCConnection jdbcConn = new JDBCConnection(mockConn, false);
assertFalse(jdbcConn.transactionCompleted);
Mockito.verify(mockConn, times(1)).setAutoCommit(false);
jdbcConn.commitChanges();
assertTrue(jdbcConn.transactionCompleted);
Mockito.verify(mockConn, times(1)).commit();
Mockito.verify(mockConn, times(1)).setAutoCommit(true);
jdbcConn.close();
}
use of com.yahoo.athenz.zms.store.jdbc.JDBCConnection in project athenz by yahoo.
the class JDBCConnectionTest method testInsertDomainTemplateNewTemplate.
@Test
public void testInsertDomainTemplateNewTemplate() 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);
Mockito.doReturn(1).when(mockPrepStmt).executeUpdate();
boolean requestSuccess = jdbcConn.insertDomainTemplate("my-domain", "platforms", null);
// this is combined for all operations above
Mockito.verify(mockPrepStmt, times(1)).setString(1, "my-domain");
Mockito.verify(mockPrepStmt, times(1)).setInt(1, 5);
Mockito.verify(mockPrepStmt, times(1)).setString(2, "platforms");
assertTrue(requestSuccess);
jdbcConn.close();
}
use of com.yahoo.athenz.zms.store.jdbc.JDBCConnection in project athenz by yahoo.
the class JDBCConnectionTest method testInsertRoleMemberNewPrincipalFailure.
@Test
public void testInsertRoleMemberNewPrincipalFailure() throws Exception {
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
Mockito.when(mockResultSet.getInt(1)).thenReturn(// domain id
5).thenReturn(// role id
7).thenReturn(// principal domain id
8).thenReturn(// principal id
9);
Mockito.when(mockResultSet.next()).thenReturn(// this one is for domain id
true).thenReturn(// this one is for role id
true).thenReturn(// this one is for valid principal domain
true).thenReturn(// principal does not exist
false);
// principal add returns 0
Mockito.doReturn(0).when(mockPrepStmt).executeUpdate();
try {
jdbcConn.insertRoleMember("my-domain", "role1", new RoleMember().setMemberName("user.user1"), "user.admin", "audit-ref");
fail();
} catch (ResourceException ex) {
assertEquals(ex.getCode(), 500);
}
jdbcConn.close();
}
use of com.yahoo.athenz.zms.store.jdbc.JDBCConnection in project athenz by yahoo.
the class JDBCConnectionTest method testUpdateServiceIdentityInvalidName.
@Test
public void testUpdateServiceIdentityInvalidName() throws Exception {
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
ServiceIdentity service = new ServiceIdentity().setName("service1");
Mockito.doReturn(1).when(mockPrepStmt).executeUpdate();
Mockito.when(mockResultSet.next()).thenReturn(true);
// return domain id
Mockito.when(mockResultSet.getInt(1)).thenReturn(5).thenReturn(// service id
4);
try {
jdbcConn.updateServiceIdentity("my-domain", service);
fail();
} catch (ResourceException ex) {
assertEquals(400, ex.getCode());
}
jdbcConn.close();
}
Aggregations