use of com.yahoo.rdl.Struct in project athenz by yahoo.
the class ZMSFileChangeLogStoreTest method testGetLocalDomainListDelete.
@Test
public void testGetLocalDomainListDelete() {
ZMSFileChangeLogStore fstore = new ZMSFileChangeLogStore(FSTORE_PATH, null, null);
ZMSFileChangeLogStoreCommon cstore = new ZMSFileChangeLogStoreCommon(FSTORE_PATH);
Struct data = new Struct();
data.put("key", "val1");
cstore.put("test1", JSON.bytes(data));
data = new Struct();
data.put("key", "val1");
cstore.put("test2", JSON.bytes(data));
data = new Struct();
data.put("key", "val1");
cstore.put("test3", JSON.bytes(data));
cstore.delete("test2");
List<String> ls = fstore.getLocalDomainList();
assertEquals(ls.size(), 2);
assertTrue(ls.contains("test1"));
assertTrue(ls.contains("test3"));
}
use of com.yahoo.rdl.Struct in project athenz by yahoo.
the class ZMSFileChangeLogStoreTest method testGetLocalDomainListHidden.
@Test
public void testGetLocalDomainListHidden() {
ZMSFileChangeLogStore fstore = new ZMSFileChangeLogStore(FSTORE_PATH, null, null);
ZMSFileChangeLogStoreCommon cstore = new ZMSFileChangeLogStoreCommon(FSTORE_PATH);
Struct data = new Struct();
data.put("key", "val1");
cstore.put("test1", JSON.bytes(data));
data = new Struct();
data.put("key", "val1");
cstore.put(".test2", JSON.bytes(data));
data = new Struct();
data.put("key", "val1");
cstore.put(".test3", JSON.bytes(data));
List<String> ls = fstore.getLocalDomainList();
assertEquals(ls.size(), 1);
assertTrue(ls.contains("test1"));
}
use of com.yahoo.rdl.Struct in project athenz by yahoo.
the class ZMSFileChangeLogStoreTest method testGetLocalDomainListSingle.
@Test
public void testGetLocalDomainListSingle() throws IOException {
File rootDir = new File(FSTORE_PATH);
// noinspection ResultOfMethodCallIgnored
rootDir.mkdirs();
Struct lastModStruct = new Struct();
lastModStruct.put("lastModTime", 1001);
File file = new File(FSTORE_PATH, ".lastModTime");
Path path = Paths.get(file.toURI());
Files.write(path, JSON.bytes(lastModStruct));
ZMSFileChangeLogStore fstore = new ZMSFileChangeLogStore(FSTORE_PATH, null, null);
ZMSFileChangeLogStoreCommon cstore = new ZMSFileChangeLogStoreCommon(FSTORE_PATH);
Struct data = new Struct();
data.put("key", "val1");
cstore.put("test1", JSON.bytes(data));
List<String> ls = fstore.getLocalDomainList();
assertEquals(ls.size(), 1);
assertTrue(ls.contains("test1"));
}
use of com.yahoo.rdl.Struct in project athenz by yahoo.
the class AuthzHelperTest method testConvertEntityToAuthzDetailsEntity.
@Test
public void testConvertEntityToAuthzDetailsEntity() throws JsonProcessingException {
Entity entity = new Entity();
entity.setName("athenz:entity.zts.authorization_details_set1");
final String jsonData = "{\"type\":\"message_access\",\"roles\":[{\"name\":\"msg-readers\"," + "\"optional\":true},{\"name\":\"msg-writers\",\"optional\":false},{\"name\":" + "\"msg-editors\"}],\"fields\":[{\"name\":\"location\",\"optional\":true}," + "{\"name\":\"identifier\",\"optional\":false},{\"name\":\"resource\"}]}";
entity.setValue(new Struct().with("data", jsonData));
AuthzDetailsEntity authzEntity = AuthzHelper.convertEntityToAuthzDetailsEntity(entity);
assertNotNull(authzEntity);
assertEquals(authzEntity.getType(), "message_access");
List<AuthzDetailsField> roles = authzEntity.getRoles();
assertNotNull(roles);
assertEquals(roles.size(), 3);
assertEquals(roles.get(0).getName(), "msg-readers");
assertTrue(roles.get(0).isOptional());
assertEquals(roles.get(1).getName(), "msg-writers");
assertFalse(roles.get(1).isOptional());
assertEquals(roles.get(2).getName(), "msg-editors");
assertFalse(roles.get(2).isOptional());
List<AuthzDetailsField> fields = authzEntity.getFields();
assertNotNull(fields);
assertEquals(fields.size(), 3);
assertEquals(fields.get(0).getName(), "location");
assertTrue(fields.get(0).isOptional());
assertEquals(fields.get(1).getName(), "identifier");
assertFalse(fields.get(1).isOptional());
assertEquals(fields.get(2).getName(), "resource");
assertFalse(fields.get(2).isOptional());
}
use of com.yahoo.rdl.Struct in project athenz by yahoo.
the class AuthzHelperTest method testConvertEntityToAuthzDetailsEntityInvalidDetails.
@Test
public void testConvertEntityToAuthzDetailsEntityInvalidDetails() {
Entity entity = new Entity();
entity.setName("athenz:entity.zts.authorization_details_set1");
try {
AuthzHelper.convertEntityToAuthzDetailsEntity(entity);
fail();
} catch (Exception ex) {
assertTrue(ex.getMessage().contains("Entity has no value"));
}
// without data field is also invalid
entity.setValue(new Struct().with("key", "value"));
try {
AuthzHelper.convertEntityToAuthzDetailsEntity(entity);
fail();
} catch (Exception ex) {
assertTrue(ex.getMessage().contains("Entity has no data field"));
}
final String jsonData = "{\"type\":\"message_access\",\"policies\":[{\"name\":\"msg-readers\"," + "\"optional\":true},{\"name\":\"msg-writers\",\"optional\":false},{\"name\":" + "\"msg-editors\"}],\"fields\":[{\"name\":\"location\",\"optional\":true}," + "{\"name\":\"identifier\",\"optional\":false},{\"name\":\"resource\"}]}";
entity.setValue(new Struct().with("data", jsonData));
try {
AuthzHelper.convertEntityToAuthzDetailsEntity(entity);
fail();
} catch (Exception ignored) {
}
}
Aggregations