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());
}
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");
}
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());
}
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");
}
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);
}
Aggregations