use of com.yahoo.athenz.zms.ResourceException 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();
}
use of com.yahoo.athenz.zms.ResourceException in project athenz by yahoo.
the class ResourceExceptionTest method testGetData.
@Test
public void testGetData() {
ResourceException exc = new ResourceException(400, "Invalid domain name");
assertEquals(exc.getData(), "Invalid domain name");
}
use of com.yahoo.athenz.zms.ResourceException in project athenz by yahoo.
the class ResourceExceptionTest method testGetDataCast.
@Test
public void testGetDataCast() {
ResourceException exc = new ResourceException(400, new Integer(5000));
assertEquals(exc.getData(Integer.class), new Integer(5000));
}
use of com.yahoo.athenz.zms.ResourceException in project athenz by yahoo.
the class JDBCConnectionTest method testDeletePrincipalDomainException.
@Test
public void testDeletePrincipalDomainException() throws Exception {
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
Mockito.when(mockPrepStmt.executeUpdate()).thenThrow(new SQLException("failed operation", "state", 1001));
try {
jdbcConn.deletePrincipal("user.jake", true);
fail();
} catch (ResourceException ex) {
assertEquals(ex.getCode(), ResourceException.INTERNAL_SERVER_ERROR);
}
jdbcConn.close();
}
use of com.yahoo.athenz.zms.ResourceException in project athenz by yahoo.
the class JDBCConnectionTest method testCommitException.
@Test
public void testCommitException() throws Exception {
JDBCConnection jdbcConn = new JDBCConnection(mockConn, false);
assertFalse(jdbcConn.transactionCompleted);
Mockito.verify(mockConn, times(1)).setAutoCommit(false);
Mockito.doThrow(new SQLException("failed operation", "state", 1001)).when(mockConn).commit();
try {
jdbcConn.commitChanges();
fail();
} catch (ResourceException ex) {
assertTrue(jdbcConn.transactionCompleted);
Mockito.verify(mockConn, times(1)).commit();
}
jdbcConn.close();
}
Aggregations