use of com.yahoo.athenz.zms.Quota in project athenz by yahoo.
the class FileConnection method getQuota.
@Override
public Quota getQuota(String domainName) {
File f = new File(quotaDir, domainName);
if (!f.exists()) {
return null;
}
Quota quota = null;
try {
Path path = Paths.get(f.toURI());
quota = JSON.fromBytes(Files.readAllBytes(path), Quota.class);
} catch (IOException e) {
}
return quota;
}
use of com.yahoo.athenz.zms.Quota in project athenz by yahoo.
the class JDBCConnectionTest method testUpdateQuotaException.
@Test
public void testUpdateQuotaException() 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(mockPrepStmt.executeUpdate()).thenThrow(new SQLException("failed operation", "state", 1001));
Mockito.when(mockResultSet.next()).thenReturn(true);
// return domain id
Mockito.doReturn(5).when(mockResultSet).getInt(1);
try {
jdbcConn.updateQuota("athenz", quota);
fail();
} catch (Exception ex) {
assertTrue(true);
}
jdbcConn.close();
}
use of com.yahoo.athenz.zms.Quota in project athenz by yahoo.
the class JDBCConnectionTest method testInsertQuotaException.
@Test
public void testInsertQuotaException() 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(mockPrepStmt.executeUpdate()).thenThrow(new SQLException("failed operation", "state", 1001));
Mockito.when(mockResultSet.next()).thenReturn(true);
// return domain id
Mockito.doReturn(5).when(mockResultSet).getInt(1);
try {
jdbcConn.insertQuota("athenz", quota);
fail();
} catch (Exception ex) {
assertTrue(true);
}
jdbcConn.close();
}
use of com.yahoo.athenz.zms.Quota in project athenz by yahoo.
the class JDBCConnectionTest method testInsertQuota.
@Test
public void testInsertQuota() 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.doReturn(1).when(mockPrepStmt).executeUpdate();
Mockito.when(mockResultSet.next()).thenReturn(true);
// return domain id
Mockito.doReturn(5).when(mockResultSet).getInt(1);
boolean requestSuccess = jdbcConn.insertQuota("athenz", quota);
assertTrue(requestSuccess);
Mockito.verify(mockPrepStmt, times(1)).setString(1, "athenz");
Mockito.verify(mockPrepStmt, times(1)).setInt(1, 5);
Mockito.verify(mockPrepStmt, times(1)).setInt(2, 14);
Mockito.verify(mockPrepStmt, times(1)).setInt(3, 15);
Mockito.verify(mockPrepStmt, times(1)).setInt(4, 12);
Mockito.verify(mockPrepStmt, times(1)).setInt(5, 10);
Mockito.verify(mockPrepStmt, times(1)).setInt(6, 16);
Mockito.verify(mockPrepStmt, times(1)).setInt(7, 17);
Mockito.verify(mockPrepStmt, times(1)).setInt(8, 13);
Mockito.verify(mockPrepStmt, times(1)).setInt(9, 11);
Mockito.verify(mockPrepStmt, times(1)).setInt(10, 18);
jdbcConn.close();
}
use of com.yahoo.athenz.zms.Quota 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();
}
Aggregations