Search in sources :

Example 1 with OrganizationService

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

the class OrganizationCreationIT method testEndorsements.

/**
 * It is not in the scope of this test to test the email bits.
 */
@ParameterizedTest
@EnumSource(ServiceType.class)
public void testEndorsements(ServiceType serviceType) {
    OrganizationService service = getService(serviceType, organizationResource, organizationClient);
    NodeService nodeService = getService(serviceType, nodeResource, nodeClient);
    Organization organization = prepareOrganization(prepareNode(nodeService, testDataFactory), service, testDataFactory);
    assertEquals(0L, nodeService.endorsedOrganizations(organization.getEndorsingNodeKey(), new PagingRequest()).getCount());
    assertEquals(1L, nodeService.pendingEndorsements(new PagingRequest()).getCount());
    assertEquals(1L, nodeService.pendingEndorsements(organization.getEndorsingNodeKey(), new PagingRequest()).getCount());
    assertEquals(1L, nodeService.pendingEndorsements(new PagingRequest()).getCount(), "Paging is not returning the correct count");
    Integer challengeCodeKey = challengeCodeSupportMapper.getChallengeCodeKey(organization.getKey());
    UUID challengeCode = challengeCodeMapper.getChallengeCode(challengeCodeKey);
    assertTrue(service.confirmEndorsement(organization.getKey(), challengeCode), "endorsement should be confirmed");
    // We should have no more pending endorsement for this node
    assertEquals(0L, nodeService.pendingEndorsements(organization.getEndorsingNodeKey(), new PagingRequest()).getCount());
    // We should also have a contact
    assertEquals(1, service.get(organization.getKey()).getContacts().size());
    // and a comment
    assertEquals(1, service.get(organization.getKey()).getComments().size());
}
Also used : OrganizationService(org.gbif.api.service.registry.OrganizationService) Organization(org.gbif.api.model.registry.Organization) NodeService(org.gbif.api.service.registry.NodeService) UUID(java.util.UUID) PagingRequest(org.gbif.api.model.common.paging.PagingRequest) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with OrganizationService

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

the class OrganizationCreationIT method testEndorsementsByUpdateMethodByAdmin.

@ParameterizedTest
@EnumSource(ServiceType.class)
public void testEndorsementsByUpdateMethodByAdmin(ServiceType serviceType) {
    OrganizationService service = getService(serviceType, organizationResource, organizationClient);
    NodeService nodeService = getService(serviceType, nodeResource, nodeClient);
    Organization organization = prepareOrganization(prepareNode(nodeService, testDataFactory), service, testDataFactory);
    assertEquals(0L, nodeService.endorsedOrganizations(organization.getEndorsingNodeKey(), new PagingRequest()).getCount());
    UUID organizationKey = organization.getKey();
    boolean endorsement = service.confirmEndorsement(organizationKey, UUID.randomUUID());
    assertFalse(endorsement, "endorsement should NOT be confirmed using appkey and no confirmation code");
    // reset principal - use ADMIN role
    setupPrincipal(TEST_ADMIN, REGISTRY_ADMIN);
    OrganizationService adminService = getService(serviceType, organizationResource, adminOrganizationClient);
    assertThrows(AccessDeniedException.class, () -> adminService.confirmEndorsement(organizationKey, UUID.randomUUID()), "endorsement should NOT be confirmed without confirmation code");
    // get the latest version (to get fields like modified)
    organization = service.get(organizationKey);
    organization.setEndorsementApproved(true);
    adminService.update(organization);
    assertEquals(0L, nodeService.endorsedOrganizations(organization.getEndorsingNodeKey(), new PagingRequest()).getCount(), "Organization can't be endorsed by update method");
}
Also used : OrganizationService(org.gbif.api.service.registry.OrganizationService) Organization(org.gbif.api.model.registry.Organization) NodeService(org.gbif.api.service.registry.NodeService) UUID(java.util.UUID) PagingRequest(org.gbif.api.model.common.paging.PagingRequest) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with OrganizationService

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

the class NodeIT method testDatasets.

@ParameterizedTest
@EnumSource(ServiceType.class)
public void testDatasets(ServiceType serviceType) {
    NodeService service = (NodeService) getService(serviceType);
    OrganizationService organizationService = getService(serviceType, organizationResource, organizationClient);
    InstallationService installationService = getService(serviceType, installationResource, installationClient);
    DatasetService datasetService = getService(serviceType, datasetResource, datasetClient);
    // endorsing node for the organization
    Node node = create(newEntity(serviceType), serviceType, 1);
    // publishing organization (required field)
    Organization o = testDataFactory.newOrganization(node.getKey());
    o.setEndorsingNodeKey(node.getKey());
    UUID organizationKey = organizationService.create(o);
    // endorse organization
    if (serviceType == ServiceType.RESOURCE) {
        organizationService.confirmEndorsement(organizationKey);
    } else {
        ((OrganizationClient) organizationClient).confirmEndorsementEndpoint(organizationKey);
    }
    // hosting technical installation (required field)
    Installation i = testDataFactory.newInstallation(organizationKey);
    UUID installationKey = installationService.create(i);
    // 2 datasets
    Dataset d1 = testDataFactory.newDataset(organizationKey, installationKey);
    datasetService.create(d1);
    Dataset d2 = testDataFactory.newDataset(organizationKey, installationKey);
    UUID d2Key = datasetService.create(d2);
    // test node service
    PagingResponse<Dataset> resp = service.endorsedDatasets(node.getKey(), new PagingRequest());
    assertEquals(2, resp.getResults().size());
    assertEquals(2L, resp.getCount(), "Paging is not returning the correct count");
    // the last created dataset should be the first in the list
    assertEquals(d2Key, resp.getResults().get(0).getKey());
}
Also used : OrganizationService(org.gbif.api.service.registry.OrganizationService) Installation(org.gbif.api.model.registry.Installation) Organization(org.gbif.api.model.registry.Organization) OrganizationClient(org.gbif.registry.ws.client.OrganizationClient) Dataset(org.gbif.api.model.registry.Dataset) NodeService(org.gbif.api.service.registry.NodeService) Node(org.gbif.api.model.registry.Node) InstallationService(org.gbif.api.service.registry.InstallationService) DatasetService(org.gbif.api.service.registry.DatasetService) UUID(java.util.UUID) PagingRequest(org.gbif.api.model.common.paging.PagingRequest) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with OrganizationService

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

the class OrganizationIT method testSuggest.

@ParameterizedTest
@EnumSource(ServiceType.class)
public void testSuggest(ServiceType serviceType) {
    OrganizationService service = (OrganizationService) getService(serviceType);
    Node node = testDataFactory.newNode();
    UUID nodeKey = nodeResource.create(node);
    Organization o1 = testDataFactory.newOrganization(nodeKey);
    o1.setTitle("Tim");
    service.create(o1);
    Organization o2 = testDataFactory.newOrganization(nodeKey);
    o2.setTitle("The Tim");
    service.create(o2);
    assertEquals(1, service.suggest("The").size(), "Should find only The Tim");
    assertEquals(2, service.suggest("Tim").size(), "Should find both organizations");
}
Also used : OrganizationService(org.gbif.api.service.registry.OrganizationService) Organization(org.gbif.api.model.registry.Organization) Node(org.gbif.api.model.registry.Node) UUID(java.util.UUID) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with OrganizationService

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

the class OrganizationIT method testByCountry.

@ParameterizedTest
@EnumSource(ServiceType.class)
public void testByCountry(ServiceType serviceType) {
    OrganizationService service = (OrganizationService) getService(serviceType);
    NodeService nodeService = getService(serviceType, nodeResource, nodeClient);
    Node node = testDataFactory.newNode();
    nodeService.create(node);
    node = nodeService.list(new PagingRequest()).getResults().get(0);
    createOrgs(node.getKey(), serviceType, Country.ANGOLA, Country.ANGOLA, Country.DENMARK, Country.FRANCE, Country.FRANCE, Country.UNKNOWN);
    assertResultsOfSize(service.listByCountry(Country.ANGOLA, new PagingRequest()), 2);
    assertEquals(Long.valueOf(2), service.listByCountry(Country.ANGOLA, new PagingRequest()).getCount(), "Paging is not returning the correct count");
    assertResultsOfSize(service.listByCountry(Country.FRANCE, new PagingRequest()), 2);
    assertResultsOfSize(service.listByCountry(Country.GERMANY, new PagingRequest()), 0);
}
Also used : OrganizationService(org.gbif.api.service.registry.OrganizationService) NodeService(org.gbif.api.service.registry.NodeService) Node(org.gbif.api.model.registry.Node) PagingRequest(org.gbif.api.model.common.paging.PagingRequest) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

OrganizationService (org.gbif.api.service.registry.OrganizationService)18 Organization (org.gbif.api.model.registry.Organization)15 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)13 EnumSource (org.junit.jupiter.params.provider.EnumSource)13 NodeService (org.gbif.api.service.registry.NodeService)12 UUID (java.util.UUID)9 PagingRequest (org.gbif.api.model.common.paging.PagingRequest)9 Installation (org.gbif.api.model.registry.Installation)8 Dataset (org.gbif.api.model.registry.Dataset)7 InstallationService (org.gbif.api.service.registry.InstallationService)7 Node (org.gbif.api.model.registry.Node)5 DatasetService (org.gbif.api.service.registry.DatasetService)4 OrganizationClient (org.gbif.registry.ws.client.OrganizationClient)3 Country (org.gbif.api.vocabulary.Country)2 Charsets (com.google.common.base.Charsets)1 CharStreams (com.google.common.io.CharStreams)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 URI (java.net.URI)1