Search in sources :

Example 1 with PagingRequest

use of org.gbif.api.model.common.paging.PagingRequest in project registry by gbif.

the class IptResourceIT method testDeleteIptDataset.

/**
 * The test begins by persisting a new Organization, Installation associated
 * to the Organization, and Dataset associated to the Organization.
 * <p>
 * Then, it sends an update Dataset (POST) request to update the same Dataset.
 * This populates the primary contact and endpoints.
 * <p>
 * Then, it sends a delete Dataset (POST) request to delete the Dataset.
 * <p>
 * Next, the test validates that the Dataset was deleted correctly.
 */
@Test
public void testDeleteIptDataset() throws Exception {
    // persist new organization (IPT hosting organization)
    Organization organization = testDataFactory.newPersistedOrganization();
    UUID organizationKey = organization.getKey();
    assertNotNull(organizationKey);
    // persist new installation of type IPT
    Installation installation = testDataFactory.newPersistedInstallation(organizationKey);
    UUID installationKey = installation.getKey();
    assertNotNull(installationKey);
    // persist new Dataset associated to installation
    Dataset dataset = testDataFactory.newPersistedDataset(organizationKey, installationKey);
    UUID datasetKey = dataset.getKey();
    assertNotNull(datasetKey);
    // construct update request uri
    String uri = "/registry/ipt/resource/" + datasetKey;
    // before sending the delete POST request, count the number of datasets, contacts and endpoints
    assertEquals(1, datasetService.list(new PagingRequest(0, 10)).getResults().size());
    // send delete POST request (using same URL), 200 expected
    requestTestFixture.deleteRequestUrlEncoded(organizationKey, organization.getPassword(), uri).andExpect(status().isOk());
    // check that the dataset was deleted
    assertEquals(0, datasetService.list(new PagingRequest(0, 10)).getResults().size());
}
Also used : Installation(org.gbif.api.model.registry.Installation) Organization(org.gbif.api.model.registry.Organization) Dataset(org.gbif.api.model.registry.Dataset) UUID(java.util.UUID) PagingRequest(org.gbif.api.model.common.paging.PagingRequest) Test(org.junit.jupiter.api.Test) BaseItTest(org.gbif.registry.ws.it.BaseItTest)

Example 2 with PagingRequest

use of org.gbif.api.model.common.paging.PagingRequest in project registry by gbif.

the class LegacyDatasetResourceIT method testUpdateLegacyDatasetWithNoContactNoEndpointNoInstallationKey.

/**
 * The test begins by persisting a new Organization, Installation associated to the Organization,
 * and Dataset associated to the Organization. A primary contact and endpoint is then added to the
 * Dataset. </br> Then, it sends an update Dataset (POST) request to update the same Dataset. The
 * request does not have the primary contact, endpoint, or installation key form parameters. Since
 * the organization only has 1 installation anyways, it will be inferred that the dataset belongs
 * to this one. </br> Upon receiving an HTTP Response, the test parses its XML content in order to
 * extract the registered Dataset UUID for example. It also ensures that the primary contact and
 * endpoints still exist.
 */
@Test
public void testUpdateLegacyDatasetWithNoContactNoEndpointNoInstallationKey() throws Exception {
    // persist new organization (IPT hosting organization)
    Organization organization = testDataFactory.newPersistedOrganization();
    UUID organizationKey = organization.getKey();
    assertNotNull(organizationKey);
    // persist new installation of type IPT
    Installation installation = testDataFactory.newPersistedInstallation(organizationKey);
    UUID installationKey = installation.getKey();
    assertNotNull(installationKey);
    // persist new Dataset associated to installation, assigned CC-BY-NC 4.0
    Dataset dataset = testDataFactory.newPersistedDataset(organizationKey, installationKey);
    assertEquals(License.CC_BY_NC_4_0, dataset.getLicense());
    UUID datasetKey = dataset.getKey();
    assertNotNull(datasetKey);
    // add primary contact to Dataset
    Contact c = testDataFactory.newContact();
    c.setType(ContactType.TECHNICAL_POINT_OF_CONTACT);
    datasetService.addContact(datasetKey, c);
    // add endpoint to Dataset
    Endpoint e = testDataFactory.newEndpoint();
    datasetService.addEndpoint(datasetKey, e);
    // validate it
    validateExistingDataset(dataset, organizationKey, installationKey);
    // before sending the update POST request, count the number of datasets, contacts and endpoints
    assertEquals(1, datasetService.list(new PagingRequest(0, 10)).getResults().size());
    assertEquals(1, datasetService.listEndpoints(datasetKey).size());
    assertEquals(1, datasetService.listContacts(datasetKey).size());
    // some information never going to change
    Date created = dataset.getCreated();
    assertNotNull(created);
    String createdBy = dataset.getCreatedBy();
    assertNotNull(createdBy);
    // populate params for ws
    MultiValueMap<String, String> data = new LinkedMultiValueMap<>();
    // main
    data.add(NAME_PARAM, TestConstants.DATASET_NAME);
    data.add(NAME_LANGUAGE_PARAM, TestConstants.DATASET_NAME_LANGUAGE);
    data.add(DESCRIPTION_PARAM, TestConstants.DATASET_DESCRIPTION);
    data.add(DOI_PARAM, TestConstants.DOI);
    data.add(DESCRIPTION_LANGUAGE_PARAM, TestConstants.DATASET_DESCRIPTION_LANGUAGE);
    data.add(HOMEPAGE_URL_PARAM, TestConstants.DATASET_HOMEPAGE_URL);
    data.add(LOGO_URL_PARAM, TestConstants.DATASET_LOGO_URL);
    // add additional ipt and organisation parameters
    data.add(ORGANIZATION_KEY_PARAM, organizationKey.toString());
    // construct request uri
    String uri = "/registry/resource/" + datasetKey;
    // send POST request with credentials
    ResultActions actions = requestTestFixture.postRequestUrlEncoded(data, organizationKey, organization.getPassword(), uri).andExpect(status().is2xxSuccessful());
    // parse updated registered Dataset key (UUID)
    LegacyDatasetResponse response = requestTestFixture.extractXmlResponse(actions, LegacyDatasetResponse.class);
    assertNotNull(response.getKey(), "Updated Dataset key should be in response");
    assertEquals(datasetKey.toString(), response.getKey());
    assertNotNull(response.getOrganisationKey(), "Updated Dataset organizationKey should be in response");
    assertEquals(organizationKey.toString(), response.getOrganisationKey());
    // make some additional assertions that the update was successful
    // retrieve installation anew
    dataset = datasetService.get(datasetKey);
    assertNotNull(dataset, "Dataset should be present");
    assertEquals(organizationKey, dataset.getPublishingOrganizationKey());
    assertEquals(installationKey, dataset.getInstallationKey());
    assertEquals(DatasetType.OCCURRENCE, dataset.getType());
    assertEquals(TestConstants.DATASET_NAME, dataset.getTitle());
    assertEquals(TestConstants.DATASET_NAME_LANGUAGE, dataset.getLanguage().getIso2LetterCode());
    assertEquals(TestConstants.DATASET_DESCRIPTION, dataset.getDescription());
    assertNotNull(dataset.getHomepage());
    assertEquals(TestConstants.DATASET_HOMEPAGE_URL, dataset.getHomepage().toString());
    assertNotNull(dataset.getLogoUrl());
    assertEquals(TestConstants.DATASET_LOGO_URL, dataset.getLogoUrl().toString());
    assertNotNull(dataset.getCreated());
    assertEquals(created.toString(), dataset.getCreated().toString());
    assertEquals(createdBy, dataset.getCreatedBy());
    assertNotNull(dataset.getModified());
}
Also used : Installation(org.gbif.api.model.registry.Installation) Organization(org.gbif.api.model.registry.Organization) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) Dataset(org.gbif.api.model.registry.Dataset) PagingRequest(org.gbif.api.model.common.paging.PagingRequest) Date(java.util.Date) Contact(org.gbif.api.model.registry.Contact) LegacyDatasetResponse(org.gbif.registry.domain.ws.LegacyDatasetResponse) Endpoint(org.gbif.api.model.registry.Endpoint) ResultActions(org.springframework.test.web.servlet.ResultActions) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test) BaseItTest(org.gbif.registry.ws.it.BaseItTest)

Example 3 with PagingRequest

use of org.gbif.api.model.common.paging.PagingRequest in project registry by gbif.

the class AuditLogMapperIT method createAndListTest.

@Test
public void createAndListTest() {
    assertTrue(auditLogMapper.list(AuditLogListParams.builder().build(), new PagingRequest()).isEmpty());
    AuditLog dto = new AuditLog();
    dto.setCollectionEntityKey(UUID.randomUUID());
    dto.setCollectionEntityType(CollectionEntityType.COLLECTION);
    dto.setSubEntityType("Identifier");
    dto.setSubEntityKey("23543");
    dto.setOperation("update");
    dto.setCreatedBy("test");
    auditLogMapper.create(dto);
    dto = new AuditLog();
    dto.setCollectionEntityKey(UUID.randomUUID());
    dto.setCollectionEntityType(CollectionEntityType.INSTITUTION);
    dto.setSubEntityType("Machine Tag");
    dto.setSubEntityKey("1111");
    dto.setOperation("create");
    dto.setCreatedBy("test2");
    auditLogMapper.create(dto);
    assertEquals(2, auditLogMapper.list(AuditLogListParams.builder().build(), new PagingRequest()).size());
    assertEquals(1, auditLogMapper.list(AuditLogListParams.builder().collectionEntityType(CollectionEntityType.INSTITUTION).build(), new PagingRequest()).size());
    assertEquals(1, auditLogMapper.list(AuditLogListParams.builder().operation("create").build(), new PagingRequest()).size());
    assertEquals(1, auditLogMapper.list(AuditLogListParams.builder().createdBy("test").build(), new PagingRequest()).size());
    assertEquals(0, auditLogMapper.list(AuditLogListParams.builder().collectionEntityKey(dto.getCollectionEntityKey()).createdBy("test").build(), new PagingRequest()).size());
    assertEquals(2, auditLogMapper.list(AuditLogListParams.builder().dateTo(new Date()).build(), new PagingRequest()).size());
    assertEquals(0, auditLogMapper.list(AuditLogListParams.builder().dateFrom(new Date()).build(), new PagingRequest()).size());
}
Also used : PagingRequest(org.gbif.api.model.common.paging.PagingRequest) AuditLog(org.gbif.registry.domain.collections.AuditLog) Date(java.util.Date) BaseItTest(org.gbif.registry.ws.it.BaseItTest) Test(org.junit.jupiter.api.Test)

Example 4 with PagingRequest

use of org.gbif.api.model.common.paging.PagingRequest in project registry by gbif.

the class DerivedDatasetMapperIT method testAddDatasetCitations.

@Test
public void testAddDatasetCitations() {
    // create datasets
    Dataset dataset1 = testDataFactory.newPersistedDataset(new DOI("10.21373/dataset1"));
    Dataset dataset2 = testDataFactory.newPersistedDataset(new DOI("10.21373/dataset2"));
    Dataset dataset3 = testDataFactory.newPersistedDataset(new DOI("10.21373/dataset3"));
    // create citations
    DerivedDataset derivedDataset1 = prepareDerivedDataset();
    derivedDataset1.setDoi(new DOI("10.21373/dd.doi1"));
    derivedDataset1.setOriginalDownloadDOI(new DOI("10.21373/dl.doi1"));
    mapper.create(derivedDataset1);
    DerivedDataset derivedDataset2 = prepareDerivedDataset();
    derivedDataset2.setDoi(new DOI("10.21373/dd.doi2"));
    derivedDataset2.setOriginalDownloadDOI(new DOI("10.21373/dl.doi2"));
    mapper.create(derivedDataset2);
    // create citation datasets
    List<DerivedDatasetUsage> citationDatasets1 = new ArrayList<>();
    citationDatasets1.add(new DerivedDatasetUsage(dataset1.getKey(), dataset1.getDoi(), null, 1L, dataset1.getTitle()));
    citationDatasets1.add(new DerivedDatasetUsage(dataset2.getKey(), dataset2.getDoi(), null, 2L, dataset2.getTitle()));
    citationDatasets1.add(new DerivedDatasetUsage(dataset3.getKey(), null, null, 3L, dataset3.getTitle()));
    List<DerivedDatasetUsage> citationDatasets2 = new ArrayList<>();
    citationDatasets2.add(new DerivedDatasetUsage(dataset3.getKey(), dataset3.getDoi(), null, 3L, dataset3.getTitle()));
    mapper.addUsagesToDerivedDataset(derivedDataset1.getDoi(), citationDatasets1);
    mapper.addUsagesToDerivedDataset(derivedDataset2.getDoi(), citationDatasets2);
    // test methods
    List<DerivedDatasetUsage> usages = mapper.listDerivedDatasetUsages(derivedDataset2.getDoi(), new PagingRequest());
    assertNotNull(usages);
    assertEquals(1, usages.size());
    assertNotNull(usages.get(0).getCitation());
    usages = mapper.listDerivedDatasetUsages(derivedDataset1.getDoi(), new PagingRequest());
    assertNotNull(usages);
    assertEquals(3, usages.size());
    assertNotNull(usages.get(0).getCitation());
}
Also used : DerivedDataset(org.gbif.registry.domain.ws.DerivedDataset) Dataset(org.gbif.api.model.registry.Dataset) ArrayList(java.util.ArrayList) DerivedDataset(org.gbif.registry.domain.ws.DerivedDataset) DerivedDatasetUsage(org.gbif.registry.domain.ws.DerivedDatasetUsage) PagingRequest(org.gbif.api.model.common.paging.PagingRequest) DOI(org.gbif.api.model.common.DOI) BaseItTest(org.gbif.registry.ws.it.BaseItTest) Test(org.junit.jupiter.api.Test)

Example 5 with PagingRequest

use of org.gbif.api.model.common.paging.PagingRequest in project registry by gbif.

the class CollectionServiceIT method listWithoutParametersTest.

@Test
public void listWithoutParametersTest() {
    collectionService.create(testData.newEntity());
    collectionService.create(testData.newEntity());
    Collection collection3 = testData.newEntity();
    UUID key3 = collectionService.create(collection3);
    PagingResponse<CollectionView> response = collectionService.list(CollectionSearchRequest.builder().page(DEFAULT_PAGE).build());
    assertEquals(3, response.getResults().size());
    collectionService.delete(key3);
    response = collectionService.list(CollectionSearchRequest.builder().page(DEFAULT_PAGE).build());
    assertEquals(2, response.getResults().size());
    response = collectionService.list(CollectionSearchRequest.builder().page(new PagingRequest(0L, 1)).build());
    assertEquals(1, response.getResults().size());
    response = collectionService.list(CollectionSearchRequest.builder().page(new PagingRequest(0L, 0)).build());
    assertEquals(0, response.getResults().size());
}
Also used : CollectionView(org.gbif.api.model.collections.view.CollectionView) Collection(org.gbif.api.model.collections.Collection) UUID(java.util.UUID) PagingRequest(org.gbif.api.model.common.paging.PagingRequest) Test(org.junit.jupiter.api.Test)

Aggregations

PagingRequest (org.gbif.api.model.common.paging.PagingRequest)81 UUID (java.util.UUID)32 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)32 EnumSource (org.junit.jupiter.params.provider.EnumSource)29 Test (org.junit.jupiter.api.Test)26 Dataset (org.gbif.api.model.registry.Dataset)25 Organization (org.gbif.api.model.registry.Organization)15 Installation (org.gbif.api.model.registry.Installation)14 Pageable (org.gbif.api.model.common.paging.Pageable)10 PagingResponse (org.gbif.api.model.common.paging.PagingResponse)9 OrganizationService (org.gbif.api.service.registry.OrganizationService)9 AuditLog (org.gbif.registry.domain.collections.AuditLog)9 BaseItTest (org.gbif.registry.ws.it.BaseItTest)9 Date (java.util.Date)6 Institution (org.gbif.api.model.collections.Institution)6 DatasetService (org.gbif.api.service.registry.DatasetService)6 NodeService (org.gbif.api.service.registry.NodeService)6 OccurrenceDownloadService (org.gbif.api.service.registry.OccurrenceDownloadService)6 Person (org.gbif.api.model.collections.Person)5 Endpoint (org.gbif.api.model.registry.Endpoint)5