Search in sources :

Example 1 with Dataset

use of org.gbif.api.model.registry.Dataset in project registry by gbif.

the class IptResourceIT method testUpdateIptDatasetWithNoPrimaryContact.

/**
 * The test sends an update Dataset (POST) request to update a Dataset, however, it is missing a
 * mandatory HTTP Parameter for the primary contact email. The test must check that the server
 * responds with a 400 BAD_REQUEST Response.
 */
@Test
public void testUpdateIptDatasetWithNoPrimaryContact() throws Exception {
    // persist new organization (Dataset publishing 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);
    // populate params for ws
    MultiValueMap<String, String> data = buildIptDatasetParameters(installationKey);
    assertEquals(12, data.size());
    // remove mandatory key/value before sending
    data.remove(PRIMARY_CONTACT_EMAIL_PARAM);
    assertEquals(11, data.size());
    // construct request uri
    String uri = "/registry/ipt/resource/" + datasetKey;
    // send POST request with credentials, 400 expected
    requestTestFixture.postRequestUrlEncoded(data, organizationKey, organization.getPassword(), uri).andExpect(status().isBadRequest());
}
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) Test(org.junit.jupiter.api.Test) BaseItTest(org.gbif.registry.ws.it.BaseItTest)

Example 2 with Dataset

use of org.gbif.api.model.registry.Dataset in project registry by gbif.

the class IptResourceIT method testRegisterIptEventDataset.

/**
 * NOTE: This test is the same as testRegisterIptDataset() except that it registers a dataset of
 * type SAMPLING_EVENT
 */
@Test
public void testRegisterIptEventDataset() throws Exception {
    // persist new organization (Dataset publishing 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);
    // populate params for ws
    MultiValueMap<String, String> data = buildIptDatasetParameters(installationKey);
    // replace service type and url params in order to reflect that this is a dataset of type
    // SAMPLING_EVENT
    data.remove(SERVICE_TYPES_PARAM);
    data.remove(SERVICE_URLS_PARAM);
    data.add(SERVICE_TYPES_PARAM, DATASET_EVENT_SERVICE_TYPES);
    data.add(SERVICE_URLS_PARAM, DATASET_SERVICE_URLS);
    // organisationKey param included on register, not on update
    data.add(ORGANIZATION_KEY_PARAM, organizationKey.toString());
    // construct request uri
    String uri = "/registry/ipt/resource";
    // send POST request with credentials and check response code
    ResultActions actions = requestTestFixture.postRequestUrlEncoded(data, organizationKey, organization.getPassword(), uri).andExpect(status().isCreated());
    // parse newly registered IPT key (UUID)
    IptEntityResponse iptEntityResponse = requestTestFixture.extractXmlResponse(actions, IptEntityResponse.class);
    assertNotNull(iptEntityResponse.getKey(), "Registered Dataset key should be in response");
    // some information that should have been updated
    Dataset dataset = validatePersistedIptDataset(UUID.fromString(iptEntityResponse.getKey()), organizationKey, installationKey, DatasetType.SAMPLING_EVENT);
    // information that is only persisted on creation, not on updates
    assertEquals(TestConstants.DATASET_NAME, dataset.getTitle());
    assertEquals(TestConstants.DATASET_DESCRIPTION, dataset.getDescription());
    // some additional information to check
    assertNotNull(dataset.getCreatedBy());
    assertNotNull(dataset.getModifiedBy());
}
Also used : Installation(org.gbif.api.model.registry.Installation) Organization(org.gbif.api.model.registry.Organization) Dataset(org.gbif.api.model.registry.Dataset) ResultActions(org.springframework.test.web.servlet.ResultActions) UUID(java.util.UUID) IptEntityResponse(org.gbif.registry.domain.ws.IptEntityResponse) Test(org.junit.jupiter.api.Test) BaseItTest(org.gbif.registry.ws.it.BaseItTest)

Example 3 with Dataset

use of org.gbif.api.model.registry.Dataset 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 4 with Dataset

use of org.gbif.api.model.registry.Dataset in project registry by gbif.

the class IptResourceIT method validatePersistedIptDataset.

/**
 * Retrieve persisted IPT dataset, and make a series of assertions to ensure it has been properly
 * persisted.
 *
 * @param datasetKey      installation key (UUID)
 * @param organizationKey installation publishing organization key
 * @return validated installation
 */
private Dataset validatePersistedIptDataset(UUID datasetKey, UUID organizationKey, UUID installationKey, DatasetType datasetType) {
    // retrieve installation anew
    Dataset dataset = datasetService.get(datasetKey);
    assertNotNull(dataset, "Dataset should be present");
    assertEquals(organizationKey, dataset.getPublishingOrganizationKey());
    assertEquals(installationKey, dataset.getInstallationKey());
    assertEquals(datasetType, dataset.getType());
    assertNotNull(dataset.getCreated());
    assertNotNull(dataset.getModified());
    // check dataset's primary contact was properly persisted
    Contact contact = dataset.getContacts().get(0);
    assertNotNull(contact, "Dataset primary contact should be present");
    assertNotNull(contact.getKey());
    assertTrue(contact.isPrimary());
    assertEquals(TestConstants.DATASET_PRIMARY_CONTACT_NAME, contact.getFirstName());
    assertEquals(TestConstants.DATASET_PRIMARY_CONTACT_EMAIL, contact.getEmail());
    assertEquals(TestConstants.DATASET_PRIMARY_CONTACT_PHONE, contact.getPhone());
    assertEquals(TestConstants.DATASET_PRIMARY_CONTACT_ADDRESS, contact.getAddress());
    assertEquals(ContactType.ADMINISTRATIVE_POINT_OF_CONTACT, contact.getType());
    assertNotNull(contact.getCreated());
    assertNotNull(contact.getCreatedBy());
    assertNotNull(contact.getModified());
    assertNotNull(contact.getModifiedBy());
    // check dataset's EML & DWC_ARCHIVE endpoints were properly persisted
    Endpoint endpoint = dataset.getEndpoints().get(0);
    assertNotNull(endpoint, "Dataset ARCHIVE endpoint should be present");
    assertNotNull(endpoint.getKey());
    assertEquals(DATASET_OCCURRENCE_SERVICE_URL, endpoint.getUrl());
    assertTrue(endpoint.getType().equals(EndpointType.DWC_ARCHIVE) || endpoint.getType().equals(EndpointType.EML));
    assertNotNull(endpoint.getCreated());
    assertNotNull(endpoint.getCreatedBy());
    assertNotNull(endpoint.getModified());
    assertNotNull(endpoint.getModifiedBy());
    endpoint = dataset.getEndpoints().get(1);
    assertNotNull(endpoint, "Dataset EML endpoint should be present");
    assertNotNull(endpoint.getKey());
    assertEquals(DATASET_EML_SERVICE_URL, endpoint.getUrl());
    assertTrue(endpoint.getType().equals(EndpointType.DWC_ARCHIVE) || endpoint.getType().equals(EndpointType.EML));
    assertNotNull(endpoint.getCreated());
    assertNotNull(endpoint.getCreatedBy());
    assertNotNull(endpoint.getModified());
    assertNotNull(endpoint.getModifiedBy());
    return dataset;
}
Also used : Endpoint(org.gbif.api.model.registry.Endpoint) Dataset(org.gbif.api.model.registry.Dataset) Contact(org.gbif.api.model.registry.Contact)

Example 5 with Dataset

use of org.gbif.api.model.registry.Dataset 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)

Aggregations

Dataset (org.gbif.api.model.registry.Dataset)222 Test (org.junit.jupiter.api.Test)103 Organization (org.gbif.api.model.registry.Organization)66 UUID (java.util.UUID)62 Installation (org.gbif.api.model.registry.Installation)53 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)34 EnumSource (org.junit.jupiter.params.provider.EnumSource)30 Contact (org.gbif.api.model.registry.Contact)27 Endpoint (org.gbif.api.model.registry.Endpoint)27 PagingRequest (org.gbif.api.model.common.paging.PagingRequest)26 SyncResult (org.gbif.registry.metasync.api.SyncResult)25 DOI (org.gbif.api.model.common.DOI)22 DatasetService (org.gbif.api.service.registry.DatasetService)20 BaseItTest (org.gbif.registry.ws.it.BaseItTest)20 IOException (java.io.IOException)15 List (java.util.List)15 StringWriter (java.io.StringWriter)14 Date (java.util.Date)14 Collection (org.gbif.api.model.collections.Collection)13 HttpGet (org.apache.http.client.methods.HttpGet)12