Search in sources :

Example 71 with JDBCConnection

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();
}
Also used : JDBCConnection(com.yahoo.athenz.zms.store.jdbc.JDBCConnection) Test(org.testng.annotations.Test)

Example 72 with JDBCConnection

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();
}
Also used : JDBCConnection(com.yahoo.athenz.zms.store.jdbc.JDBCConnection) Test(org.testng.annotations.Test)

Example 73 with JDBCConnection

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();
}
Also used : JDBCConnection(com.yahoo.athenz.zms.store.jdbc.JDBCConnection) Test(org.testng.annotations.Test)

Example 74 with JDBCConnection

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();
}
Also used : ResourceException(com.yahoo.athenz.zms.ResourceException) JDBCConnection(com.yahoo.athenz.zms.store.jdbc.JDBCConnection) RoleMember(com.yahoo.athenz.zms.RoleMember) Test(org.testng.annotations.Test)

Example 75 with JDBCConnection

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();
}
Also used : ServiceIdentity(com.yahoo.athenz.zms.ServiceIdentity) ResourceException(com.yahoo.athenz.zms.ResourceException) JDBCConnection(com.yahoo.athenz.zms.store.jdbc.JDBCConnection) Test(org.testng.annotations.Test)

Aggregations

JDBCConnection (com.yahoo.athenz.zms.store.jdbc.JDBCConnection)307 Test (org.testng.annotations.Test)307 ResourceException (com.yahoo.athenz.zms.ResourceException)131 SQLException (java.sql.SQLException)125 Assertion (com.yahoo.athenz.zms.Assertion)16 PrincipalRole (com.yahoo.athenz.zms.PrincipalRole)15 Role (com.yahoo.athenz.zms.Role)14 PublicKeyEntry (com.yahoo.athenz.zms.PublicKeyEntry)11 ServiceIdentity (com.yahoo.athenz.zms.ServiceIdentity)11 AthenzDomain (com.yahoo.athenz.zms.store.AthenzDomain)11 Domain (com.yahoo.athenz.zms.Domain)10 Entity (com.yahoo.athenz.zms.Entity)8 Quota (com.yahoo.athenz.zms.Quota)8 Policy (com.yahoo.athenz.zms.Policy)7 ResourceAccessList (com.yahoo.athenz.zms.ResourceAccessList)7 ArrayList (java.util.ArrayList)7 RoleMember (com.yahoo.athenz.zms.RoleMember)6 Struct (com.yahoo.rdl.Struct)6 Timestamp (com.yahoo.rdl.Timestamp)6 DomainModifiedList (com.yahoo.athenz.zms.DomainModifiedList)5