Search in sources :

Example 1 with Study

use of org.sagebionetworks.repo.model.Study in project Synapse-Repository-Services by Sage-Bionetworks.

the class StackStatusInterceptorTest method testPostWithReadWrite.

@Test
public void testPostWithReadWrite() throws Exception {
    // We should be able to get when the status is read-write
    assertEquals(StatusEnum.READ_WRITE, stackStatusDao.getCurrentStatus());
    Study child = new Study();
    child.setParentId(sampleProject.getId());
    Study fetched = ServletTestHelper.createEntity(dispatchServlet, child, userName);
    assertNotNull(fetched);
}
Also used : Study(org.sagebionetworks.repo.model.Study) Test(org.junit.Test)

Example 2 with Study

use of org.sagebionetworks.repo.model.Study in project Synapse-Repository-Services by Sage-Bionetworks.

the class DefaultControllerAutowiredAllTypesTest method createEntitesOfEachType.

/**
 * This is a test helper method that will create at least on of each type of entity.
 * @return
 * @throws IOException
 * @throws ServletException
 * @throws InvalidModelException
 * @throws IllegalAccessException
 * @throws InstantiationException
 * @throws UnauthorizedException
 * @throws NotFoundException
 * @throws DatastoreException
 */
private List<Entity> createEntitesOfEachType(int countPerType) throws ServletException, IOException, InstantiationException, IllegalAccessException, InvalidModelException, DatastoreException, NotFoundException, UnauthorizedException {
    // For now put each object in a project so their parent id is not null;
    // Create a project
    Project project = new Project();
    project.setName("createAtLeastOneOfEachType");
    project = ServletTestHelper.createEntity(dispatchServlet, project, userName);
    assertNotNull(project);
    toDelete.add(project.getId());
    // Create a dataset
    Study datasetParent = (Study) ObjectTypeFactory.createObjectForTest("datasetParent", EntityType.dataset, project.getId());
    datasetParent = ServletTestHelper.createEntity(dispatchServlet, datasetParent, userName);
    // Create a layer parent
    Data layerParent = (Data) ObjectTypeFactory.createObjectForTest("layerParent", EntityType.layer, datasetParent.getId());
    layerParent = ServletTestHelper.createEntity(dispatchServlet, layerParent, userName);
    // Now get the path of the layer
    List<EntityHeader> path = entityController.getEntityPath(userName, layerParent.getId());
    // This is the list of entities that will be created.
    List<Entity> newChildren = new ArrayList<Entity>();
    // Create one of each type
    EntityType[] types = EntityType.values();
    for (int i = 0; i < countPerType; i++) {
        int index = i;
        Study dataset = null;
        for (EntityType type : types) {
            String name = type.name() + index;
            // use the correct parent type.
            String parentId = findCompatableParentId(path, type);
            Entity object = ObjectTypeFactory.createObjectForTest(name, type, parentId);
            Entity clone = ServletTestHelper.createEntity(dispatchServlet, object, userName);
            assertNotNull(clone);
            assertNotNull(clone.getId());
            assertNotNull(clone.getEtag());
            // Mark entities for deletion after the current test completes
            toDelete.add(clone.getId());
            // Stash these for later use
            if (EntityType.dataset == type) {
                dataset = (Study) clone;
            }
            // Check the base urls
            UrlHelpers.validateAllUrls(clone);
            // Add this to the list of entities created
            newChildren.add(clone);
            index++;
        }
    }
    return newChildren;
}
Also used : EntityType(org.sagebionetworks.repo.model.EntityType) Project(org.sagebionetworks.repo.model.Project) Study(org.sagebionetworks.repo.model.Study) Entity(org.sagebionetworks.repo.model.Entity) EntityHeader(org.sagebionetworks.repo.model.EntityHeader) ArrayList(java.util.ArrayList) Data(org.sagebionetworks.repo.model.Data)

Example 3 with Study

use of org.sagebionetworks.repo.model.Study in project Synapse-Repository-Services by Sage-Bionetworks.

the class EntityServiceImplAutowiredTest method createForTest.

private Study createForTest(int i) {
    Study ds = new Study();
    ds.setName("someName" + i);
    ds.setDescription("someDesc" + i);
    ds.setCreatedBy("magic" + i);
    ds.setCreatedOn(new Date(1001));
    ds.setAnnotations("someAnnoUrl" + 1);
    ds.setUri("someUri" + i);
    return ds;
}
Also used : Study(org.sagebionetworks.repo.model.Study) Date(java.util.Date)

Example 4 with Study

use of org.sagebionetworks.repo.model.Study in project Synapse-Repository-Services by Sage-Bionetworks.

the class EntityServiceImplAutowiredTest method testQuery.

@Test
public void testQuery() throws DatastoreException, NotFoundException, UnauthorizedException {
    // Basic query
    PaginatedResults<Study> paginated = entityController.getEntities(userName, new PaginatedParameters(1, 100, null, true), mockRequest, Study.class);
    assertNotNull(paginated);
    assertNotNull(paginated.getPaging());
    List<Study> results = paginated.getResults();
    assertNotNull(results);
    assertEquals(totalEntities, results.size());
    // Check the urls for each object
    for (Study ds : results) {
        UrlHelpers.validateAllUrls(ds);
    }
    // Sorted
    paginated = entityController.getEntities(userName, new PaginatedParameters(1, 3, "name", true), mockRequest, Study.class);
    results = paginated.getResults();
    assertNotNull(results);
    assertEquals(3, results.size());
    assertNotNull(results.get(2));
    assertEquals("someName2", results.get(2).getName());
}
Also used : Study(org.sagebionetworks.repo.model.Study) Test(org.junit.Test)

Example 5 with Study

use of org.sagebionetworks.repo.model.Study in project Synapse-Repository-Services by Sage-Bionetworks.

the class EntityServiceImplAutowiredTest method before.

@Before
public void before() throws DatastoreException, InvalidModelException, NotFoundException, UnauthorizedException {
    assertNotNull(entityController);
    assertNotNull(testUserProvider);
    // Map test objects to their urls
    // Make sure we have a valid user.
    userInfo = testUserProvider.getTestAdminUserInfo();
    UserInfo.validateUserInfo(userInfo);
    userName = userInfo.getUser().getUserId();
    mockRequest = Mockito.mock(HttpServletRequest.class);
    when(mockRequest.getServletPath()).thenReturn("/repo/v1");
    toDelete = new ArrayList<String>();
    // Create a project to hold the datasets
    Project project = new Project();
    project.setName("projectRoot");
    project = entityController.createEntity(userName, project, mockRequest);
    assertNotNull(project);
    // Create some datasetst.
    for (int i = 0; i < totalEntities; i++) {
        Study ds = createForTest(i);
        ds.setParentId(project.getId());
        ds = entityController.createEntity(userName, ds, mockRequest);
        for (int layer = 0; layer < layers; layer++) {
            Data inLayer = createLayerForTest(i * 10 + layer);
            inLayer.setParentId(ds.getId());
            inLayer.setMd5("b960413cf33e1333b2b709319c29870d");
            List<LocationData> locationDatas = new ArrayList<LocationData>();
            inLayer.setLocations(locationDatas);
            for (int loc = 0; loc < locations; loc++) {
                LocationData loca = createLayerLocatoinsForTest(i * 10 + layer * 10 + loc);
                locationDatas.add(loca);
            }
            inLayer = entityController.createEntity(userName, inLayer, mockRequest);
        }
        toDelete.add(ds.getId());
    }
    toDelete.add(project.getId());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Project(org.sagebionetworks.repo.model.Project) Study(org.sagebionetworks.repo.model.Study) LocationData(org.sagebionetworks.repo.model.LocationData) ArrayList(java.util.ArrayList) LocationData(org.sagebionetworks.repo.model.LocationData) Data(org.sagebionetworks.repo.model.Data) Before(org.junit.Before)

Aggregations

Study (org.sagebionetworks.repo.model.Study)53 Test (org.junit.Test)38 Project (org.sagebionetworks.repo.model.Project)18 Annotations (org.sagebionetworks.repo.model.Annotations)12 AccessControlList (org.sagebionetworks.repo.model.AccessControlList)10 LocationData (org.sagebionetworks.repo.model.LocationData)9 Date (java.util.Date)8 Data (org.sagebionetworks.repo.model.Data)7 EntityBundle (org.sagebionetworks.repo.model.EntityBundle)7 ArrayList (java.util.ArrayList)6 Before (org.junit.Before)6 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 StringEntity (org.apache.http.entity.StringEntity)5 EntityHeader (org.sagebionetworks.repo.model.EntityHeader)5 ResourceAccess (org.sagebionetworks.repo.model.ResourceAccess)5 ACCESS_TYPE (org.sagebionetworks.repo.model.ACCESS_TYPE)4 HashSet (java.util.HashSet)3 LinkedList (java.util.LinkedList)3 Matchers.anyString (org.mockito.Matchers.anyString)3 Synapse (org.sagebionetworks.client.Synapse)3