Search in sources :

Example 6 with Entity

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

the class JDBCConnectionTest method testInsertEntity.

@Test
public void testInsertEntity() throws Exception {
    JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
    Entity entity = new Entity().setName("entity1").setValue(JSON.fromString("{\"value\":1}", Struct.class));
    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.insertEntity("my-domain", entity);
    assertTrue(requestSuccess);
    Mockito.verify(mockPrepStmt, times(1)).setString(1, "my-domain");
    Mockito.verify(mockPrepStmt, times(1)).setInt(1, 5);
    Mockito.verify(mockPrepStmt, times(1)).setString(2, "entity1");
    jdbcConn.close();
}
Also used : Entity(com.yahoo.athenz.zms.Entity) JDBCConnection(com.yahoo.athenz.zms.store.jdbc.JDBCConnection) Struct(com.yahoo.rdl.Struct) Test(org.testng.annotations.Test)

Example 7 with Entity

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

the class JDBCConnectionTest method testGetEntity.

@Test
public void testGetEntity() throws Exception {
    Mockito.when(mockResultSet.next()).thenReturn(true);
    Mockito.doReturn("{\"value\":1}").when(mockResultSet).getString(ZMSConsts.DB_COLUMN_VALUE);
    // domain id
    Mockito.when(mockResultSet.getInt(1)).thenReturn(5);
    JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
    Entity entity = jdbcConn.getEntity("my-domain", "entity1");
    assertNotNull(entity);
    assertEquals("entity1", entity.getName());
    assertEquals("{\"value\":1}", JSON.string(entity.getValue()));
    Mockito.verify(mockPrepStmt, times(1)).setInt(1, 5);
    Mockito.verify(mockPrepStmt, times(1)).setString(2, "entity1");
    jdbcConn.close();
}
Also used : Entity(com.yahoo.athenz.zms.Entity) JDBCConnection(com.yahoo.athenz.zms.store.jdbc.JDBCConnection) Test(org.testng.annotations.Test)

Example 8 with Entity

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

the class JDBCConnectionTest method testInsertEntityInvalidDomain.

@Test
public void testInsertEntityInvalidDomain() throws Exception {
    JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
    Entity entity = new Entity().setName("entity1").setValue(JSON.fromString("{\"value\":1}", Struct.class));
    Mockito.when(mockResultSet.next()).thenReturn(false);
    try {
        jdbcConn.insertEntity("my-domain", entity);
        fail();
    } catch (Exception ex) {
        assertTrue(true);
    }
    jdbcConn.close();
}
Also used : Entity(com.yahoo.athenz.zms.Entity) JDBCConnection(com.yahoo.athenz.zms.store.jdbc.JDBCConnection) ResourceException(com.yahoo.athenz.zms.ResourceException) SQLException(java.sql.SQLException) Struct(com.yahoo.rdl.Struct) Test(org.testng.annotations.Test)

Example 9 with Entity

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

the class JDBCConnectionTest method testUpdateEntityInvalidDomain.

@Test
public void testUpdateEntityInvalidDomain() throws Exception {
    JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
    Entity entity = new Entity().setName("entity1").setValue(JSON.fromString("{\"value\":1}", Struct.class));
    Mockito.when(mockResultSet.next()).thenReturn(false);
    try {
        jdbcConn.updateEntity("my-domain", entity);
        fail();
    } catch (Exception ex) {
        assertTrue(true);
    }
    jdbcConn.close();
}
Also used : Entity(com.yahoo.athenz.zms.Entity) JDBCConnection(com.yahoo.athenz.zms.store.jdbc.JDBCConnection) ResourceException(com.yahoo.athenz.zms.ResourceException) SQLException(java.sql.SQLException) Struct(com.yahoo.rdl.Struct) Test(org.testng.annotations.Test)

Aggregations

Entity (com.yahoo.athenz.zms.Entity)9 JDBCConnection (com.yahoo.athenz.zms.store.jdbc.JDBCConnection)8 Test (org.testng.annotations.Test)8 Struct (com.yahoo.rdl.Struct)7 SQLException (java.sql.SQLException)5 ResourceException (com.yahoo.athenz.zms.ResourceException)4 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1