use of org.sagebionetworks.schema.adapter.org.json.JSONObjectAdapterImpl in project Synapse-Repository-Services by Sage-Bionetworks.
the class AccessApprovalUtilsTest method testRoundtripWithNulls.
@Test
public void testRoundtripWithNulls() throws Exception {
AccessApproval dto = createDTO();
dto.setId(null);
DBOAccessApproval dbo = new DBOAccessApproval();
String jsonString = (String) AccessApproval.class.getField(JSONEntity.EFFECTIVE_SCHEMA).get(null);
ObjectSchema schema = new ObjectSchema(new JSONObjectAdapterImpl(jsonString));
AccessApprovalUtils.copyDtoToDbo(dto, dbo);
AccessApproval dto2 = AccessApprovalUtils.copyDboToDto(dbo);
assertEquals(dto, dto2);
}
use of org.sagebionetworks.schema.adapter.org.json.JSONObjectAdapterImpl in project Synapse-Repository-Services by Sage-Bionetworks.
the class SchemaSerializationUtilsTest method testAnnotationsRoundtrip.
@Test
public void testAnnotationsRoundtrip() throws Exception {
UserProfile dto = new UserProfile();
dto.setOwnerId("101");
dto.setFirstName("foo");
dto.setLastName("bar");
dto.setRStudioUrl("http://rstudio.com");
dto.setDisplayName("foo bar");
dto.setEtag("0");
String jsonString = (String) UserProfile.class.getField(JSONEntity.EFFECTIVE_SCHEMA).get(null);
ObjectSchema schema = new ObjectSchema(new JSONObjectAdapterImpl(jsonString));
byte[] na = SchemaSerializationUtils.mapDtoFieldsToAnnotations(dto, schema);
UserProfile dto2 = new UserProfile();
SchemaSerializationUtils.mapAnnotationsToDtoFields(na, dto2, schema);
assertEquals(dto, dto2);
}
use of org.sagebionetworks.schema.adapter.org.json.JSONObjectAdapterImpl in project Synapse-Repository-Services by Sage-Bionetworks.
the class DBOUserGroupDAOImplTest method testGetMigrationObjectData.
@Test
public void testGetMigrationObjectData() throws Exception {
boolean foundPublic = false;
UserGroup ug = userGroupDAO.findGroup("PUBLIC", false);
assertNotNull(ug);
boolean foundUser = false;
UserGroup oner = new UserGroup();
oner.setName("oner");
oner.setIsIndividual(true);
String onerId = userGroupDAO.create(oner);
groupsToDelete.add(onerId);
UserProfile up = new UserProfile();
up.setOwnerId(onerId);
up.setEtag("some tag");
String jsonString = (String) UserProfile.class.getField(JSONEntity.EFFECTIVE_SCHEMA).get(null);
ObjectSchema schema = new ObjectSchema(new JSONObjectAdapterImpl(jsonString));
// this will be deleted via cascade when the user-group is deleted
String upId = userProfileDAO.create(up, schema);
QueryResults<MigratableObjectData> migrationData = userGroupDAO.getMigrationObjectData(0, 10000, true);
assert (migrationData.getTotalNumberOfResults() > 1);
assertEquals(migrationData.getTotalNumberOfResults(), migrationData.getResults().size());
for (MigratableObjectData od : migrationData.getResults()) {
MigratableObjectDescriptor obj = od.getId();
assertNotNull(obj.getId());
assertEquals(MigratableObjectType.PRINCIPAL, obj.getType());
assertNotNull(od.getEtag());
// Groups are not dependent on any other migratable object
assertTrue(od.getDependencies().isEmpty());
if (obj.getId().equals(ug.getId())) {
foundPublic = true;
// multiuser groups have no real etags
assertEquals(DBOUserGroupDAOImpl.DEFAULT_ETAG, od.getEtag());
}
if (obj.getId().equals(onerId)) {
foundUser = true;
}
}
assertTrue(foundPublic);
assertTrue(foundUser);
// make sure pagination works
migrationData = userGroupDAO.getMigrationObjectData(0, 1, true);
assertEquals(1, migrationData.getResults().size());
}
use of org.sagebionetworks.schema.adapter.org.json.JSONObjectAdapterImpl in project Synapse-Repository-Services by Sage-Bionetworks.
the class EntityObjectMapper method writeValue.
/**
* Write the passed entity to the writer
* @param w
* @param entity
* @throws JSONObjectAdapterException
* @throws IOException
*/
public void writeValue(Writer w, JSONEntity entity) {
JSONObjectAdapter adapter;
try {
adapter = entity.writeToJSONObject(new JSONObjectAdapterImpl());
w.write(adapter.toJSONString());
} catch (JSONObjectAdapterException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of org.sagebionetworks.schema.adapter.org.json.JSONObjectAdapterImpl in project Synapse-Repository-Services by Sage-Bionetworks.
the class JSONEntityHttpMessageConverterTest method testCreateEntityFromeAdapterBadJSON.
/**
* This test was added for PLFM-1280.
* @throws JSONObjectAdapterException
*/
@Test(expected = JSONObjectAdapterException.class)
public void testCreateEntityFromeAdapterBadJSON() throws JSONObjectAdapterException {
// Test a vaild entity type with a field that does not exist on that type.
JSONObjectAdapter adapter = new JSONObjectAdapterImpl();
adapter.put("entityType", ExampleEntity.class.getName());
adapter.put("notAField", "shoudld not exist");
JSONEntityHttpMessageConverter.createEntityFromeAdapter(adapter);
}
Aggregations