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();
}
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();
}
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();
}
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();
}
Aggregations