use of com.yahoo.athenz.zms.Domain in project athenz by yahoo.
the class JDBCConnectionTest method testGetDomainNotFound.
@Test
public void testGetDomainNotFound() throws Exception {
Mockito.when(mockResultSet.next()).thenReturn(false);
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
Domain domain = jdbcConn.getDomain("my-domain");
assertNull(domain);
jdbcConn.close();
}
use of com.yahoo.athenz.zms.Domain in project athenz by yahoo.
the class JDBCConnectionTest method testInsertDomain.
@Test
public void testInsertDomain() throws Exception {
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
Domain domain = new Domain().setName("my-domain").setEnabled(true).setAuditEnabled(false).setDescription("my domain").setId(UUID.fromString("e5e97240-e94e-11e4-8163-6d083f3f473f")).setOrg("cloud_services");
Mockito.doReturn(1).when(mockPrepStmt).executeUpdate();
boolean requestSuccess = jdbcConn.insertDomain(domain);
assertTrue(requestSuccess);
Mockito.verify(mockPrepStmt, times(1)).setString(1, "my-domain");
Mockito.verify(mockPrepStmt, times(1)).setString(2, "my domain");
Mockito.verify(mockPrepStmt, times(1)).setString(3, "cloud_services");
Mockito.verify(mockPrepStmt, times(1)).setString(4, "e5e97240-e94e-11e4-8163-6d083f3f473f");
Mockito.verify(mockPrepStmt, times(1)).setBoolean(5, true);
Mockito.verify(mockPrepStmt, times(1)).setBoolean(6, false);
Mockito.verify(mockPrepStmt, times(1)).setString(7, "");
Mockito.verify(mockPrepStmt, times(1)).setInt(8, 0);
jdbcConn.close();
}
use of com.yahoo.athenz.zms.Domain in project athenz by yahoo.
the class JDBCConnectionTest method testUpdateDomain.
@Test
public void testUpdateDomain() throws Exception {
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
Domain domain = new Domain().setName("my-domain").setEnabled(true).setAuditEnabled(false).setDescription("my domain").setId(UUID.fromString("e5e97240-e94e-11e4-8163-6d083f3f473f")).setOrg("cloud_services").setAccount("123456789").setYpmId(Integer.valueOf(1011)).setApplicationId("application_id");
Mockito.doReturn(1).when(mockPrepStmt).executeUpdate();
boolean requestSuccess = jdbcConn.updateDomain(domain);
assertTrue(requestSuccess);
Mockito.verify(mockPrepStmt, times(1)).setString(1, "my domain");
Mockito.verify(mockPrepStmt, times(1)).setString(2, "cloud_services");
Mockito.verify(mockPrepStmt, times(1)).setString(3, "e5e97240-e94e-11e4-8163-6d083f3f473f");
Mockito.verify(mockPrepStmt, times(1)).setBoolean(4, true);
Mockito.verify(mockPrepStmt, times(1)).setBoolean(5, false);
Mockito.verify(mockPrepStmt, times(1)).setString(6, "123456789");
Mockito.verify(mockPrepStmt, times(1)).setInt(7, 1011);
Mockito.verify(mockPrepStmt, times(1)).setString(8, "application_id");
Mockito.verify(mockPrepStmt, times(1)).setString(9, "my-domain");
jdbcConn.close();
}
use of com.yahoo.athenz.zms.Domain in project athenz by yahoo.
the class JDBCConnection method getAthenzDomain.
@Override
public AthenzDomain getAthenzDomain(String domainName) {
final String caller = "getAthenzDomain";
int domainId = 0;
AthenzDomain athenzDomain = new AthenzDomain(domainName);
try (PreparedStatement ps = con.prepareStatement(SQL_GET_DOMAIN)) {
ps.setString(1, domainName);
try (ResultSet rs = executeQuery(ps, caller)) {
if (rs.next()) {
Domain domain = saveDomainSettings(domainName, rs, caller);
athenzDomain.setDomain(domain);
domainId = rs.getInt(ZMSConsts.DB_COLUMN_DOMAIN_ID);
}
}
} catch (SQLException ex) {
throw sqlError(ex, caller);
}
if (domainId == 0) {
throw notFoundError(caller, ZMSConsts.OBJECT_DOMAIN, domainName);
}
getAthenzDomainRoles(domainName, domainId, athenzDomain, caller);
getAthenzDomainPolicies(domainName, domainId, athenzDomain, caller);
getAthenzDomainServices(domainName, domainId, athenzDomain, caller);
return athenzDomain;
}
use of com.yahoo.athenz.zms.Domain in project athenz by yahoo.
the class JDBCConnectionTest method testGetDomain.
@Test
public void testGetDomain() throws Exception {
Mockito.when(mockResultSet.next()).thenReturn(true);
Mockito.doReturn("my-domain").when(mockResultSet).getString(ZMSConsts.DB_COLUMN_NAME);
Mockito.doReturn(new java.sql.Timestamp(1454358916)).when(mockResultSet).getTimestamp(ZMSConsts.DB_COLUMN_MODIFIED);
Mockito.doReturn(true).when(mockResultSet).getBoolean(ZMSConsts.DB_COLUMN_ENABLED);
Mockito.doReturn(false).when(mockResultSet).getBoolean(ZMSConsts.DB_COLUMN_AUDIT_ENABLED);
Mockito.doReturn("").when(mockResultSet).getString(ZMSConsts.DB_COLUMN_DESCRIPTION);
Mockito.doReturn("").when(mockResultSet).getString(ZMSConsts.DB_COLUMN_ORG);
Mockito.doReturn("").when(mockResultSet).getString(ZMSConsts.DB_COLUMN_UUID);
Mockito.doReturn("12345").when(mockResultSet).getString(ZMSConsts.DB_COLUMN_ACCOUNT);
Mockito.doReturn(1001).when(mockResultSet).getInt(ZMSConsts.DB_COLUMN_PRODUCT_ID);
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
Domain domain = jdbcConn.getDomain("my-domain");
assertNotNull(domain);
assertEquals("my-domain", domain.getName());
assertTrue(domain.getEnabled());
assertFalse(domain.getAuditEnabled());
assertNull(domain.getDescription());
assertNull(domain.getOrg());
assertNull(domain.getId());
jdbcConn.close();
}
Aggregations