Search in sources :

Example 51 with JDBCConnection

use of com.yahoo.athenz.zms.store.jdbc.JDBCConnection in project athenz by yahoo.

the class JDBCConnectionTest method testVerifyDomainAccountUniquenessEmptyAccount.

@Test
public void testVerifyDomainAccountUniquenessEmptyAccount() throws Exception {
    // we are going to set the code to return exception so that we can
    // verify that we're returning before making any sql calls
    Mockito.when(mockResultSet.next()).thenReturn(false);
    Mockito.when(mockPrepStmt.executeQuery()).thenThrow(new SQLException("failed operation", "state", 1001));
    JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
    jdbcConn.verifyDomainAccountUniqueness("iaas.athenz", null, "unitTest");
    jdbcConn.verifyDomainAccountUniqueness("iaas.athenz", "", "unitTest");
    jdbcConn.close();
}
Also used : SQLException(java.sql.SQLException) JDBCConnection(com.yahoo.athenz.zms.store.jdbc.JDBCConnection) Test(org.testng.annotations.Test)

Example 52 with JDBCConnection

use of com.yahoo.athenz.zms.store.jdbc.JDBCConnection in project athenz by yahoo.

the class JDBCConnectionTest method testCountRoleMembersException.

@Test
public void testCountRoleMembersException() throws Exception {
    JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
    // return domain id
    Mockito.when(mockResultSet.getInt(1)).thenReturn(5).thenReturn(7);
    Mockito.when(mockResultSet.next()).thenReturn(// this one is for domain id
    true).thenReturn(// this one is for role id
    true);
    Mockito.when(mockPrepStmt.executeQuery()).thenReturn(mockResultSet).thenReturn(mockResultSet).thenThrow(new SQLException("failed operation", "state", 1001));
    try {
        jdbcConn.countRoleMembers("my-domain", "role1");
        fail();
    } catch (Exception ex) {
        assertTrue(true);
    }
    jdbcConn.close();
}
Also used : SQLException(java.sql.SQLException) JDBCConnection(com.yahoo.athenz.zms.store.jdbc.JDBCConnection) ResourceException(com.yahoo.athenz.zms.ResourceException) SQLException(java.sql.SQLException) Test(org.testng.annotations.Test)

Example 53 with JDBCConnection

use of com.yahoo.athenz.zms.store.jdbc.JDBCConnection in project athenz by yahoo.

the class JDBCConnectionTest method testUpdateServiceIdentityAllFields.

@Test
public void testUpdateServiceIdentityAllFields() throws Exception {
    JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
    ServiceIdentity service = new ServiceIdentity().setName("my-domain.service1").setDescription("test service").setExecutable("/usr/bin64/test.sh").setGroup("users").setUser("root").setProviderEndpoint("http://server.athenzcompany.com");
    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);
    boolean requestSuccess = jdbcConn.updateServiceIdentity("my-domain", service);
    assertTrue(requestSuccess);
    // get domain id
    Mockito.verify(mockPrepStmt, times(1)).setString(1, "my-domain");
    // get service id
    Mockito.verify(mockPrepStmt, times(1)).setInt(1, 5);
    Mockito.verify(mockPrepStmt, times(1)).setString(2, "service1");
    // update service
    Mockito.verify(mockPrepStmt, times(1)).setString(1, "test service");
    Mockito.verify(mockPrepStmt, times(1)).setString(2, "http://server.athenzcompany.com");
    Mockito.verify(mockPrepStmt, times(1)).setString(3, "/usr/bin64/test.sh");
    Mockito.verify(mockPrepStmt, times(1)).setString(4, "root");
    Mockito.verify(mockPrepStmt, times(1)).setString(5, "users");
    Mockito.verify(mockPrepStmt, times(1)).setInt(6, 4);
    jdbcConn.close();
}
Also used : ServiceIdentity(com.yahoo.athenz.zms.ServiceIdentity) JDBCConnection(com.yahoo.athenz.zms.store.jdbc.JDBCConnection) Test(org.testng.annotations.Test)

Example 54 with JDBCConnection

use of com.yahoo.athenz.zms.store.jdbc.JDBCConnection in project athenz by yahoo.

the class JDBCConnectionTest method testDeleteEntityInvalidDomain.

@Test
public void testDeleteEntityInvalidDomain() throws Exception {
    JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
    Mockito.when(mockResultSet.next()).thenReturn(false);
    try {
        jdbcConn.deleteEntity("my-domain", "entity1");
        fail();
    } catch (Exception ex) {
        assertTrue(true);
    }
    jdbcConn.close();
}
Also used : JDBCConnection(com.yahoo.athenz.zms.store.jdbc.JDBCConnection) ResourceException(com.yahoo.athenz.zms.ResourceException) SQLException(java.sql.SQLException) Test(org.testng.annotations.Test)

Example 55 with JDBCConnection

use of com.yahoo.athenz.zms.store.jdbc.JDBCConnection in project athenz by yahoo.

the class JDBCConnectionTest method testCountAssertionsInvalidPolicy.

@Test
public void testCountAssertionsInvalidPolicy() throws Exception {
    JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
    // this one is for domain id
    Mockito.when(mockResultSet.next()).thenReturn(true).thenReturn(// this one is for policy id
    false);
    Mockito.when(mockResultSet.getInt(1)).thenReturn(5);
    try {
        jdbcConn.countAssertions("my-domain", "policy1");
        fail();
    } catch (Exception ex) {
        assertTrue(true);
    }
    jdbcConn.close();
}
Also used : JDBCConnection(com.yahoo.athenz.zms.store.jdbc.JDBCConnection) ResourceException(com.yahoo.athenz.zms.ResourceException) SQLException(java.sql.SQLException) 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