Search in sources :

Example 6 with Domain

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

the class JDBCConnectionTest method testInsertDomainException.

@Test
public void testInsertDomainException() 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.when(mockPrepStmt.executeUpdate()).thenThrow(new SQLException("failed operation", "state", 1001));
    try {
        jdbcConn.insertDomain(domain);
        fail();
    } catch (Exception ex) {
        assertTrue(true);
    }
    jdbcConn.close();
}
Also used : SQLException(java.sql.SQLException) AthenzDomain(com.yahoo.athenz.zms.store.AthenzDomain) Domain(com.yahoo.athenz.zms.Domain) JDBCConnection(com.yahoo.athenz.zms.store.jdbc.JDBCConnection) ResourceException(com.yahoo.athenz.zms.ResourceException) SQLException(java.sql.SQLException) Test(org.testng.annotations.Test)

Example 7 with Domain

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

the class JDBCConnectionTest method testUpdateDomainNullFields.

@Test
public void testUpdateDomainNullFields() throws Exception {
    JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
    Domain domain = new Domain().setName("my-domain").setEnabled(true).setAuditEnabled(false);
    Mockito.doReturn(1).when(mockPrepStmt).executeUpdate();
    boolean requestSuccess = jdbcConn.updateDomain(domain);
    assertTrue(requestSuccess);
    Mockito.verify(mockPrepStmt, times(1)).setString(1, "");
    Mockito.verify(mockPrepStmt, times(1)).setString(2, "");
    Mockito.verify(mockPrepStmt, times(1)).setString(3, "");
    Mockito.verify(mockPrepStmt, times(1)).setBoolean(4, true);
    Mockito.verify(mockPrepStmt, times(1)).setBoolean(5, false);
    Mockito.verify(mockPrepStmt, times(1)).setString(6, "");
    Mockito.verify(mockPrepStmt, times(1)).setInt(7, 0);
    Mockito.verify(mockPrepStmt, times(1)).setString(8, "");
    Mockito.verify(mockPrepStmt, times(1)).setString(9, "my-domain");
    jdbcConn.close();
}
Also used : AthenzDomain(com.yahoo.athenz.zms.store.AthenzDomain) Domain(com.yahoo.athenz.zms.Domain) JDBCConnection(com.yahoo.athenz.zms.store.jdbc.JDBCConnection) Test(org.testng.annotations.Test)

Example 8 with Domain

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

the class JDBCConnectionTest method testInsertDomainWithAccountInfo.

@Test
public void testInsertDomainWithAccountInfo() 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));
    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, "123456789");
    Mockito.verify(mockPrepStmt, times(1)).setInt(8, 1011);
    jdbcConn.close();
}
Also used : AthenzDomain(com.yahoo.athenz.zms.store.AthenzDomain) Domain(com.yahoo.athenz.zms.Domain) JDBCConnection(com.yahoo.athenz.zms.store.jdbc.JDBCConnection) Test(org.testng.annotations.Test)

Example 9 with Domain

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

the class JDBCConnectionTest method testGetDomainAllFields.

@Test
public void testGetDomainAllFields() 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(true).when(mockResultSet).getBoolean(ZMSConsts.DB_COLUMN_AUDIT_ENABLED);
    Mockito.doReturn("my own domain").when(mockResultSet).getString(ZMSConsts.DB_COLUMN_DESCRIPTION);
    Mockito.doReturn("cloud_services").when(mockResultSet).getString(ZMSConsts.DB_COLUMN_ORG);
    Mockito.doReturn("e5e97240-e94e-11e4-8163-6d083f3f473f").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());
    assertTrue(domain.getAuditEnabled());
    assertEquals("my own domain", domain.getDescription());
    assertEquals("cloud_services", domain.getOrg());
    assertEquals(UUID.fromString("e5e97240-e94e-11e4-8163-6d083f3f473f"), domain.getId());
    jdbcConn.close();
}
Also used : AthenzDomain(com.yahoo.athenz.zms.store.AthenzDomain) Domain(com.yahoo.athenz.zms.Domain) JDBCConnection(com.yahoo.athenz.zms.store.jdbc.JDBCConnection) Test(org.testng.annotations.Test)

Example 10 with Domain

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

the class DataCacheTest method testSingleHostSingleService.

@Test
public void testSingleHostSingleService() {
    Domain domain = new Domain();
    domain.setName("testDomain");
    ServiceIdentity service = new ServiceIdentity();
    service.setName("testDomain.storage");
    List<String> hosts = new ArrayList<>();
    hosts.add("host1");
    service.setHosts(hosts);
    DataCache cache = new DataCache();
    cache.processServiceIdentity(service);
    Map<String, Set<String>> hostMap = cache.getHostMap();
    assertEquals(hostMap.size(), 1);
    assertTrue(hostMap.containsKey("host1"));
    Set<String> set = hostMap.get("host1");
    assertEquals(set.size(), 1);
    assertTrue(set.contains("testDomain.storage"));
}
Also used : Set(java.util.Set) ServiceIdentity(com.yahoo.athenz.zms.ServiceIdentity) ArrayList(java.util.ArrayList) Domain(com.yahoo.athenz.zms.Domain) DataCache(com.yahoo.athenz.zts.cache.DataCache) Test(org.testng.annotations.Test)

Aggregations

Domain (com.yahoo.athenz.zms.Domain)24 Test (org.testng.annotations.Test)23 DataCache (com.yahoo.athenz.zts.cache.DataCache)12 ArrayList (java.util.ArrayList)12 AthenzDomain (com.yahoo.athenz.zms.store.AthenzDomain)11 JDBCConnection (com.yahoo.athenz.zms.store.jdbc.JDBCConnection)10 Policy (com.yahoo.athenz.zms.Policy)6 Role (com.yahoo.athenz.zms.Role)6 ServiceIdentity (com.yahoo.athenz.zms.ServiceIdentity)6 HashMap (java.util.HashMap)6 Assertion (com.yahoo.athenz.zms.Assertion)5 RoleMember (com.yahoo.athenz.zms.RoleMember)5 Set (java.util.Set)5 SQLException (java.sql.SQLException)3 ResourceException (com.yahoo.athenz.zms.ResourceException)2 File (java.io.File)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1