use of org.sagebionetworks.schema.adapter.org.json.JSONObjectAdapterImpl in project Synapse-Repository-Services by Sage-Bionetworks.
the class ObjectTypeSerializerTest method testPLFM_834Paginated.
@Test
public void testPLFM_834Paginated() throws HttpMessageNotWritableException, IOException, JSONObjectAdapterException {
// Make sure we can write an entity to json
List<EntityHeader> results = new ArrayList<EntityHeader>();
EntityHeader h1 = new EntityHeader();
h1.setId("123");
h1.setName("Joe");
h1.setType("type");
results.add(h1);
PaginatedResults<EntityHeader> paged = new PaginatedResults<EntityHeader>("/repo/v1/somePath", results, 101, 50, 1, "sortOn", true);
final ByteArrayOutputStream out = new ByteArrayOutputStream();
HttpOutputMessage message = new HttpOutputMessage() {
@Override
public HttpHeaders getHeaders() {
return new HttpHeaders();
}
@Override
public OutputStream getBody() throws IOException {
return out;
}
};
// Write this to the stream
objectTypeSerializer.write(paged, mediaType, message);
String outString = new String(out.toByteArray(), Charset.forName("UTF-8"));
System.out.println(outString);
assertFalse("The resulting JSON should not contain the schema", outString.indexOf("jsonschema") > -1);
// Make sure we can create a new entity with the path.
JSONObjectAdapter adapter = new JSONObjectAdapterImpl(outString);
PaginatedResults<EntityHeader> clone = new PaginatedResults<EntityHeader>(EntityHeader.class);
clone.initializeFromJSONObject(adapter);
assertEquals(paged, clone);
}
use of org.sagebionetworks.schema.adapter.org.json.JSONObjectAdapterImpl in project Synapse-Repository-Services by Sage-Bionetworks.
the class StorageUsageControllerTest method testGrandTotals.
@Test
public void testGrandTotals() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
request.setMethod("GET");
request.addHeader("Accept", "application/json");
request.setRequestURI(UrlHelpers.STORAGE_SUMMARY);
request.setParameter(AuthorizationConstants.USER_ID_PARAM, "0");
MockHttpServletResponse response = new MockHttpServletResponse();
HttpServlet servlet = DispatchServletSingleton.getInstance();
servlet.service(request, response);
Assert.assertEquals(200, response.getStatus());
String jsonStr = response.getContentAsString();
JSONObjectAdapter adapter = new JSONObjectAdapterImpl(jsonStr);
StorageUsageSummaryList sus = new StorageUsageSummaryList();
sus.initializeFromJSONObject(adapter);
Assert.assertNotNull(sus);
Assert.assertEquals(0L, sus.getTotalSize().longValue());
Assert.assertEquals(0, sus.getSummaryList().size());
}
use of org.sagebionetworks.schema.adapter.org.json.JSONObjectAdapterImpl in project Synapse-Repository-Services by Sage-Bionetworks.
the class AnnotationJSONTest method testBackwardsCompatibility.
@Test
public void testBackwardsCompatibility() throws JsonGenerationException, JsonMappingException, IOException, JSONObjectAdapterException {
ObjectMapper objectMapper = new ObjectMapper();
Annotations annos = new Annotations();
annos.setId("123");
annos.setEtag("456");
annos.setCreationDate(new Date(System.currentTimeMillis()));
annos.setUri("http://localhost:8080/");
annos.addAnnotation("binary", "This will be binary".getBytes("UTF-8"));
annos.addAnnotation("date", new Date(System.currentTimeMillis()));
annos.addAnnotation("double", new Double(123.5));
annos.addAnnotation("long", new Long(345));
annos.addAnnotation("string", "String value");
annos.getStringAnnotations().put("nullList", null);
annos.getStringAnnotations().put("empty", new ArrayList<String>());
List<String> withNull = new ArrayList<String>();
withNull.add(null);
annos.getStringAnnotations().put("nullValueInList", withNull);
StringWriter writer = new StringWriter();
objectMapper.writeValue(writer, annos);
String objectMapperJson = writer.toString();
System.out.println(objectMapperJson);
// Make sure we are generating the same JSON as before
JSONObjectAdapter adapter = new JSONObjectAdapterImpl();
annos.writeToJSONObject(adapter);
// The strings should be the same
String fromAdapterJson = adapter.toJSONString();
System.out.println(fromAdapterJson);
// Make sure one can load the other
Annotations cloneOne = objectMapper.readValue(fromAdapterJson, Annotations.class);
assertEquals(annos, cloneOne);
// Now go the other way
Annotations cloneTwo = EntityFactory.createEntityFromJSONString(objectMapperJson, Annotations.class);
assertEquals(annos, cloneTwo);
}
use of org.sagebionetworks.schema.adapter.org.json.JSONObjectAdapterImpl in project Synapse-Repository-Services by Sage-Bionetworks.
the class JSONEntityHttpMessageConverter method readEntity.
/**
* Read an entity from the reader.
* @param reader
* @return
* @throws IOException
* @throws JSONObjectAdapterException
*/
public static Entity readEntity(Reader reader) throws IOException, JSONObjectAdapterException {
// First read in the string
String jsonString = readToString(reader);
// Read it into an adapter
JSONObjectAdapter adapter = new JSONObjectAdapterImpl(jsonString);
return createEntityFromeAdapter(adapter);
}
use of org.sagebionetworks.schema.adapter.org.json.JSONObjectAdapterImpl in project Synapse-Repository-Services by Sage-Bionetworks.
the class GenotypeDataTest method testRoundTripLayer.
@Test
public void testRoundTripLayer() throws JSONObjectAdapterException {
GenotypeData l1 = new GenotypeData();
JSONObjectAdapter adapter1 = new JSONObjectAdapterImpl();
JSONObjectAdapter adapter2 = new JSONObjectAdapterImpl();
Date d = new Date();
l1.setAccessControlList("/acl");
l1.setAnnotations("/annotations");
l1.setCreatedBy("createdBy");
l1.setCreatedOn(d);
l1.setDescription("description");
l1.setEtag("1");
l1.setId("1");
l1.setModifiedBy("modifiedBy");
l1.setModifiedOn(d);
l1.setName("name");
l1.setParentId("0");
l1.setUri("uri");
l1.setVersionComment("versionComment");
l1.setVersionLabel("versionLabel");
l1.setVersionNumber(1L);
l1.setVersionUrl("/versions/1");
l1.setVersions("/versions");
l1.setContentType("text");
l1.setMd5("01234567890123456789012345678901");
List<LocationData> ll = new ArrayList<LocationData>();
LocationData l = new LocationData();
l.setPath("path");
l.setType(LocationTypeNames.sage);
ll.add(l);
l1.setLocations(ll);
l1.setNumSamples(1000L);
l1.setNumSamples(100L);
l1.setDisease("disease");
l1.setSpecies("species");
l1.setS3Token("S3token");
l1.setPlatform("platform");
adapter1 = l1.writeToJSONObject(adapter1);
String s = adapter1.toJSONString();
adapter2 = new JSONObjectAdapterImpl(s);
GenotypeData l2 = new GenotypeData(adapter2);
assertEquals(l1, l2);
}
Aggregations