Search in sources :

Example 51 with JSONObjectAdapterImpl

use of org.sagebionetworks.schema.adapter.org.json.JSONObjectAdapterImpl in project Synapse-Repository-Services by Sage-Bionetworks.

the class ProjectTest method testRoundTripProject.

@Test
public void testRoundTripProject() throws JSONObjectAdapterException {
    Project p1 = new Project();
    JSONObjectAdapter adapter1 = new JSONObjectAdapterImpl();
    JSONObjectAdapter adapter2 = new JSONObjectAdapterImpl();
    Date d = new Date();
    p1.setAccessControlList("/acl");
    p1.setAnnotations("/annotations");
    p1.setCreatedBy("createdBy");
    p1.setCreatedOn(d);
    p1.setDescription("description");
    p1.setEtag("etag");
    p1.setId("1");
    p1.setModifiedBy("modifiedBy");
    p1.setModifiedOn(d);
    p1.setName("name");
    p1.setParentId("0");
    p1.setUri("uri");
    adapter1 = p1.writeToJSONObject(adapter1);
    String s = adapter1.toJSONString();
    adapter2 = new JSONObjectAdapterImpl(s);
    Project p2 = new Project(adapter2);
    assertEquals(p1, p2);
}
Also used : JSONObjectAdapter(org.sagebionetworks.schema.adapter.JSONObjectAdapter) JSONObjectAdapterImpl(org.sagebionetworks.schema.adapter.org.json.JSONObjectAdapterImpl) Date(java.util.Date) Test(org.junit.Test)

Example 52 with JSONObjectAdapterImpl

use of org.sagebionetworks.schema.adapter.org.json.JSONObjectAdapterImpl in project Synapse-Repository-Services by Sage-Bionetworks.

the class PaginatedResultsTest method testRoundJSONRoundTrip.

@Test
public void testRoundJSONRoundTrip() throws JSONObjectAdapterException {
    // Create a list of projects
    List<Project> list = new ArrayList<Project>();
    for (int i = 0; i < 4; i++) {
        Project project = new Project();
        project.setParentId("1" + i);
        project.setId("" + i);
        project.setName("Project" + i);
        list.add(project);
    }
    PaginatedResults<Project> pr = new PaginatedResults<Project>("http//localhost:8080/rep/v1/projects", list, 101, 4, 14, "name", true);
    // now write it to JSON
    JSONObjectAdapter adapter = new JSONObjectAdapterImpl();
    pr.writeToJSONObject(adapter);
    // Now to go json string
    String json = adapter.toJSONString();
    System.out.println(json);
    // Now create a clone from the JSON
    adapter = new JSONObjectAdapterImpl(json);
    PaginatedResults<Project> clone = new PaginatedResults<Project>(Project.class);
    clone.initializeFromJSONObject(adapter);
    assertEquals(pr, clone);
}
Also used : JSONObjectAdapter(org.sagebionetworks.schema.adapter.JSONObjectAdapter) ArrayList(java.util.ArrayList) JSONObjectAdapterImpl(org.sagebionetworks.schema.adapter.org.json.JSONObjectAdapterImpl) Test(org.junit.Test)

Example 53 with JSONObjectAdapterImpl

use of org.sagebionetworks.schema.adapter.org.json.JSONObjectAdapterImpl in project Synapse-Repository-Services by Sage-Bionetworks.

the class AnalysisTest method testRoundTripAnalysis.

@Test
public void testRoundTripAnalysis() throws JSONObjectAdapterException {
    Analysis a1 = new Analysis();
    JSONObjectAdapter adapter1 = new JSONObjectAdapterImpl();
    JSONObjectAdapter adapter2 = new JSONObjectAdapterImpl();
    Date d = new Date();
    a1.setAccessControlList("/acl");
    a1.setAnnotations("/annotations");
    a1.setCreatedBy("createdBy");
    a1.setCreatedOn(d);
    a1.setDescription("description");
    a1.setEtag("1");
    a1.setId("1");
    a1.setModifiedBy("modifiedBy");
    a1.setModifiedOn(d);
    a1.setName("name");
    a1.setParentId("0");
    a1.setUri("uri");
    a1.setSteps("/steps");
    a1.setStatus("status");
    adapter1 = a1.writeToJSONObject(adapter1);
    String s = adapter1.toJSONString();
    adapter2 = new JSONObjectAdapterImpl(s);
    Analysis a2 = new Analysis(adapter2);
    assertEquals(a1, a2);
    return;
}
Also used : JSONObjectAdapter(org.sagebionetworks.schema.adapter.JSONObjectAdapter) JSONObjectAdapterImpl(org.sagebionetworks.schema.adapter.org.json.JSONObjectAdapterImpl) Date(java.util.Date) Test(org.junit.Test)

Example 54 with JSONObjectAdapterImpl

use of org.sagebionetworks.schema.adapter.org.json.JSONObjectAdapterImpl in project Synapse-Repository-Services by Sage-Bionetworks.

the class ExpressionDataTest method testRoundTripLayer.

@Test
public void testRoundTripLayer() throws JSONObjectAdapterException {
    ExpressionData l1 = new ExpressionData();
    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");
    l1.setTissueType("tissue");
    adapter1 = l1.writeToJSONObject(adapter1);
    String s = adapter1.toJSONString();
    adapter2 = new JSONObjectAdapterImpl(s);
    ExpressionData l2 = new ExpressionData(adapter2);
    assertEquals(l1, l2);
}
Also used : JSONObjectAdapter(org.sagebionetworks.schema.adapter.JSONObjectAdapter) ArrayList(java.util.ArrayList) JSONObjectAdapterImpl(org.sagebionetworks.schema.adapter.org.json.JSONObjectAdapterImpl) Date(java.util.Date) Test(org.junit.Test)

Example 55 with JSONObjectAdapterImpl

use of org.sagebionetworks.schema.adapter.org.json.JSONObjectAdapterImpl in project Synapse-Repository-Services by Sage-Bionetworks.

the class LayerTest method testRoundTripLayer.

@Test
public void testRoundTripLayer() throws JSONObjectAdapterException {
    Data l1 = new Data();
    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.setPlatform("platform");
    l1.setTissueType("tissueType");
    l1.setType(LayerTypeNames.E);
    adapter1 = l1.writeToJSONObject(adapter1);
    String s = adapter1.toJSONString();
    adapter2 = new JSONObjectAdapterImpl(s);
    Data l2 = new Data(adapter2);
    assertEquals(l1, l2);
    return;
}
Also used : JSONObjectAdapter(org.sagebionetworks.schema.adapter.JSONObjectAdapter) ArrayList(java.util.ArrayList) JSONObjectAdapterImpl(org.sagebionetworks.schema.adapter.org.json.JSONObjectAdapterImpl) Date(java.util.Date) Test(org.junit.Test)

Aggregations

JSONObjectAdapterImpl (org.sagebionetworks.schema.adapter.org.json.JSONObjectAdapterImpl)62 JSONObjectAdapter (org.sagebionetworks.schema.adapter.JSONObjectAdapter)49 Test (org.junit.Test)30 JSONObjectAdapterException (org.sagebionetworks.schema.adapter.JSONObjectAdapterException)24 JSONObject (org.json.JSONObject)19 ArrayList (java.util.ArrayList)15 Date (java.util.Date)12 ObjectSchema (org.sagebionetworks.schema.ObjectSchema)11 PaginatedResults (org.sagebionetworks.repo.model.PaginatedResults)10 SynapseException (org.sagebionetworks.client.exceptions.SynapseException)9 VariableContentPaginatedResults (org.sagebionetworks.repo.model.VariableContentPaginatedResults)7 EntityHeader (org.sagebionetworks.repo.model.EntityHeader)6 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)6 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)6 StringEntity (org.apache.http.entity.StringEntity)5 EntityBundle (org.sagebionetworks.repo.model.EntityBundle)5 UserProfile (org.sagebionetworks.repo.model.UserProfile)5 AccessRequirement (org.sagebionetworks.repo.model.AccessRequirement)4 Annotations (org.sagebionetworks.repo.model.Annotations)4 HttpServlet (javax.servlet.http.HttpServlet)3