Search in sources :

Example 36 with JDBCConnection

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

the class JDBCConnectionTest method testPrepareDomainScanStatementPrefixModifiedZero.

@Test
public void testPrepareDomainScanStatementPrefixModifiedZero() throws Exception {
    JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
    jdbcConn.prepareDomainScanStatement("prefix", 0);
    Mockito.verify(mockPrepStmt, times(1)).setString(1, "prefix");
    Mockito.verify(mockPrepStmt, times(1)).setString(2, "prefiy");
    jdbcConn.close();
}
Also used : JDBCConnection(com.yahoo.athenz.zms.store.jdbc.JDBCConnection) Test(org.testng.annotations.Test)

Example 37 with JDBCConnection

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

the class JDBCConnectionTest method testUpdatePolicyModTimestampException.

@Test
public void testUpdatePolicyModTimestampException() throws Exception {
    JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
    Mockito.when(mockPrepStmt.executeUpdate()).thenThrow(new SQLException("failed operation", "state", 1001));
    try {
        jdbcConn.updatePolicyModTimestamp("my-domain", "policy1");
        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 38 with JDBCConnection

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

the class JDBCConnectionTest method testUpdateEntity.

@Test
public void testUpdateEntity() throws Exception {
    JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
    Entity entity = new Entity().setName("entity1").setValue(JSON.fromString("{\"value\":1}", Struct.class));
    Mockito.doReturn(1).when(mockPrepStmt).executeUpdate();
    Mockito.when(mockResultSet.next()).thenReturn(true);
    // return domain id
    Mockito.doReturn(5).when(mockResultSet).getInt(1);
    boolean requestSuccess = jdbcConn.updateEntity("my-domain", entity);
    assertTrue(requestSuccess);
    Mockito.verify(mockPrepStmt, times(1)).setString(1, "my-domain");
    Mockito.verify(mockPrepStmt, times(1)).setString(1, "{\"value\":1}");
    Mockito.verify(mockPrepStmt, times(1)).setInt(2, 5);
    Mockito.verify(mockPrepStmt, times(1)).setString(3, "entity1");
    jdbcConn.close();
}
Also used : Entity(com.yahoo.athenz.zms.Entity) JDBCConnection(com.yahoo.athenz.zms.store.jdbc.JDBCConnection) Struct(com.yahoo.rdl.Struct) Test(org.testng.annotations.Test)

Example 39 with JDBCConnection

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

the class JDBCConnectionTest method testCountAssertions.

@Test
public void testCountAssertions() throws Exception {
    JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
    Mockito.when(mockResultSet.getInt(1)).thenReturn(5).thenReturn(7).thenReturn(// return domain/policy id/count
    1);
    Mockito.when(mockResultSet.next()).thenReturn(true);
    assertEquals(jdbcConn.countAssertions("my-domain", "policy1"), 1);
    jdbcConn.close();
}
Also used : JDBCConnection(com.yahoo.athenz.zms.store.jdbc.JDBCConnection) Test(org.testng.annotations.Test)

Example 40 with JDBCConnection

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

the class JDBCConnectionTest method testVerifyDomainAccountUniquenessPassNoMatch.

@Test
public void testVerifyDomainAccountUniquenessPassNoMatch() throws Exception {
    Mockito.when(mockResultSet.next()).thenReturn(false);
    JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
    jdbcConn.verifyDomainAccountUniqueness("iaas.athenz", "12345", "unitTest");
    jdbcConn.close();
}
Also used : 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