Search in sources :

Example 1 with NodeService

use of org.gbif.api.service.registry.NodeService 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 NodeService

use of org.gbif.api.service.registry.NodeService 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 NodeService

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

the class NodeIT method testCountries.

@ParameterizedTest
@EnumSource(ServiceType.class)
public void testCountries(ServiceType serviceType) {
    NodeService service = (NodeService) getService(serviceType);
    initVotingCountryNodes(serviceType);
    List<Country> countries = service.listNodeCountries();
    assertEquals(TEST_COUNTRIES.size(), countries.size());
    for (Country c : countries) {
        assertTrue(TEST_COUNTRIES.containsKey(c), "Unexpected node country" + c);
    }
}
Also used : NodeService(org.gbif.api.service.registry.NodeService) Country(org.gbif.api.vocabulary.Country) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with NodeService

use of org.gbif.api.service.registry.NodeService 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 5 with NodeService

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

the class NodeIT method testAddContact.

/**
 * Node contacts are IMS managed and the service throws exceptions
 */
@ParameterizedTest
@EnumSource(ServiceType.class)
public void testAddContact(ServiceType serviceType) {
    NodeService service = ((NodeService) getService(serviceType));
    Node n = create(newEntity(serviceType), serviceType, 1);
    assertThrows(UnsupportedOperationException.class, () -> service.addContact(n.getKey(), new Contact()));
}
Also used : NodeService(org.gbif.api.service.registry.NodeService) Node(org.gbif.api.model.registry.Node) Contact(org.gbif.api.model.registry.Contact) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

NodeService (org.gbif.api.service.registry.NodeService)21 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)16 EnumSource (org.junit.jupiter.params.provider.EnumSource)16 Node (org.gbif.api.model.registry.Node)12 OrganizationService (org.gbif.api.service.registry.OrganizationService)11 Organization (org.gbif.api.model.registry.Organization)10 UUID (java.util.UUID)8 PagingRequest (org.gbif.api.model.common.paging.PagingRequest)6 Installation (org.gbif.api.model.registry.Installation)5 InstallationService (org.gbif.api.service.registry.InstallationService)4 Country (org.gbif.api.vocabulary.Country)3 Dataset (org.gbif.api.model.registry.Dataset)2 OrganizationClient (org.gbif.registry.ws.client.OrganizationClient)2 Contact (org.gbif.api.model.registry.Contact)1 Identifier (org.gbif.api.model.registry.Identifier)1 DatasetService (org.gbif.api.service.registry.DatasetService)1 OrganizationResource (org.gbif.registry.ws.resources.OrganizationResource)1 AccessDeniedException (org.springframework.security.access.AccessDeniedException)1