Search in sources :

Example 1 with NetworkService

use of org.gbif.api.service.registry.NetworkService in project registry by gbif.

the class NetworkIT method testConstituentsHandlingErrors.

@ParameterizedTest
@EnumSource(ServiceType.class)
public void testConstituentsHandlingErrors(ServiceType serviceType) {
    NetworkService service = (NetworkService) getService(serviceType);
    Network network = testDataFactory.newPersistedNetwork();
    Organization organization = testDataFactory.newPersistedOrganization();
    Installation installation = testDataFactory.newPersistedInstallation();
    Dataset dataset = testDataFactory.newPersistedDataset(organization.getKey(), installation.getKey());
    // Simple add
    service.addConstituent(network.getKey(), dataset.getKey());
    // Exception class depends on the service type
    Class<? extends Throwable> expectedException = serviceType == ServiceType.RESOURCE ? WebApplicationException.class : IllegalArgumentException.class;
    // Adding to a non-existing network
    assertThrows(expectedException, () -> service.addConstituent(UUID.randomUUID(), dataset.getKey()));
    // Adding a non-existing dataset
    assertThrows(expectedException, () -> service.addConstituent(network.getKey(), UUID.randomUUID()));
    // Removing from a non-existing network
    assertThrows(expectedException, () -> service.removeConstituent(UUID.randomUUID(), dataset.getKey()));
    // Removing a non-existing dataset
    assertThrows(expectedException, () -> service.removeConstituent(network.getKey(), UUID.randomUUID()));
    // Simple remove
    service.removeConstituent(network.getKey(), dataset.getKey());
}
Also used : Installation(org.gbif.api.model.registry.Installation) Organization(org.gbif.api.model.registry.Organization) Dataset(org.gbif.api.model.registry.Dataset) Network(org.gbif.api.model.registry.Network) NetworkService(org.gbif.api.service.registry.NetworkService) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with NetworkService

use of org.gbif.api.service.registry.NetworkService in project registry by gbif.

the class NetworkIT method testListPublishingOrganizations.

@ParameterizedTest
@EnumSource(ServiceType.class)
public void testListPublishingOrganizations(ServiceType serviceType) {
    NetworkService service = (NetworkService) getService(serviceType);
    // prepare two networks
    Network network1 = testDataFactory.newPersistedNetwork();
    Network network2 = testDataFactory.newPersistedNetwork();
    // prepare organizations & installations
    Organization org1 = testDataFactory.newPersistedOrganization();
    Organization org2 = testDataFactory.newPersistedOrganization();
    Organization org3 = testDataFactory.newPersistedOrganization();
    Installation installation1 = testDataFactory.newPersistedInstallation(org1.getKey());
    Installation installation2 = testDataFactory.newPersistedInstallation(org2.getKey());
    Installation installation3 = testDataFactory.newPersistedInstallation(org3.getKey());
    // prepare 4 datasets: 3 for the first network and 1 for the second one
    Dataset dataset1 = testDataFactory.newPersistedDataset(org1.getKey(), installation1.getKey());
    Dataset dataset2 = testDataFactory.newPersistedDataset(org1.getKey(), installation1.getKey());
    Dataset dataset3 = testDataFactory.newPersistedDataset(org2.getKey(), installation2.getKey());
    Dataset dataset4 = testDataFactory.newPersistedDataset(org3.getKey(), installation3.getKey());
    // add constituents
    service.addConstituent(network1.getKey(), dataset1.getKey());
    service.addConstituent(network1.getKey(), dataset2.getKey());
    service.addConstituent(network1.getKey(), dataset3.getKey());
    service.addConstituent(network2.getKey(), dataset4.getKey());
    // list publishing organizations for networks
    PagingResponse<Organization> network1PublishingOrgs = service.publishingOrganizations(network1.getKey(), new PagingRequest());
    PagingResponse<Organization> network2PublishingOrgs = service.publishingOrganizations(network2.getKey(), new PagingRequest());
    PagingResponse<Organization> notExistingNetworkPublishingOrgs = service.publishingOrganizations(UUID.randomUUID(), new PagingRequest());
    assertEquals(2, network1PublishingOrgs.getCount());
    assertEquals(1, network2PublishingOrgs.getCount());
    assertEquals(0, notExistingNetworkPublishingOrgs.getCount());
    // remove constituent
    service.removeConstituent(network1.getKey(), dataset3.getKey());
    // check again
    network1PublishingOrgs = service.publishingOrganizations(network1.getKey(), new PagingRequest());
    assertEquals(1, network1PublishingOrgs.getCount());
    // delete datasets
    datasetResource.delete(dataset1.getKey());
    datasetResource.delete(dataset2.getKey());
    // check again
    network1PublishingOrgs = service.publishingOrganizations(network1.getKey(), new PagingRequest());
    assertEquals(0, network1PublishingOrgs.getCount());
}
Also used : Installation(org.gbif.api.model.registry.Installation) Organization(org.gbif.api.model.registry.Organization) Dataset(org.gbif.api.model.registry.Dataset) Network(org.gbif.api.model.registry.Network) NetworkService(org.gbif.api.service.registry.NetworkService) PagingRequest(org.gbif.api.model.common.paging.PagingRequest) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Dataset (org.gbif.api.model.registry.Dataset)2 Installation (org.gbif.api.model.registry.Installation)2 Network (org.gbif.api.model.registry.Network)2 Organization (org.gbif.api.model.registry.Organization)2 NetworkService (org.gbif.api.service.registry.NetworkService)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 EnumSource (org.junit.jupiter.params.provider.EnumSource)2 PagingRequest (org.gbif.api.model.common.paging.PagingRequest)1