Search in sources :

Example 21 with ResourceException

use of com.yahoo.athenz.zms.ResourceException in project athenz by yahoo.

the class JDBCConnectionTest method testInsertQuotaInvalidDomain.

@Test
public void testInsertQuotaInvalidDomain() throws Exception {
    JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
    Quota quota = new Quota().setName("athenz").setAssertion(10).setEntity(11).setPolicy(12).setPublicKey(13).setRole(14).setRoleMember(15).setService(16).setServiceHost(17).setSubdomain(18);
    Mockito.when(mockResultSet.next()).thenReturn(false);
    try {
        jdbcConn.insertQuota("athenz", quota);
        fail();
    } catch (ResourceException ex) {
        assertEquals(404, ex.getCode());
    }
    jdbcConn.close();
}
Also used : Quota(com.yahoo.athenz.zms.Quota) ResourceException(com.yahoo.athenz.zms.ResourceException) JDBCConnection(com.yahoo.athenz.zms.store.jdbc.JDBCConnection) Test(org.testng.annotations.Test)

Example 22 with ResourceException

use of com.yahoo.athenz.zms.ResourceException in project athenz by yahoo.

the class JDBCConnectionTest method testInsertServiceIdentityInvalidName.

@Test
public void testInsertServiceIdentityInvalidName() 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.insertServiceIdentity("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)

Example 23 with ResourceException

use of com.yahoo.athenz.zms.ResourceException in project athenz by yahoo.

the class JDBCConnectionTest method testVerifyDomainAccountUniquenessFail.

@Test
public void testVerifyDomainAccountUniquenessFail() throws Exception {
    Mockito.when(mockResultSet.next()).thenReturn(true).thenReturn(false);
    Mockito.doReturn("iaas.athenz.ci").when(mockResultSet).getString(1);
    JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
    try {
        jdbcConn.verifyDomainAccountUniqueness("iaas.athenz", "12345", "unitTest");
        fail();
    } catch (ResourceException ex) {
        assertEquals(400, ex.getCode());
        assertTrue(ex.getMessage().contains("iaas.athenz.ci"));
    }
    jdbcConn.close();
}
Also used : ResourceException(com.yahoo.athenz.zms.ResourceException) JDBCConnection(com.yahoo.athenz.zms.store.jdbc.JDBCConnection) Test(org.testng.annotations.Test)

Aggregations

ResourceException (com.yahoo.athenz.zms.ResourceException)23 Test (org.testng.annotations.Test)22 JDBCConnection (com.yahoo.athenz.zms.store.jdbc.JDBCConnection)19 SQLException (java.sql.SQLException)8 Policy (com.yahoo.athenz.zms.Policy)2 Quota (com.yahoo.athenz.zms.Quota)2 ServiceIdentity (com.yahoo.athenz.zms.ServiceIdentity)2 ResourceError (com.yahoo.athenz.zms.ResourceError)1 RoleMember (com.yahoo.athenz.zms.RoleMember)1