use of org.hl7.fhir.r4.model.Endpoint in project dpc-app by CMSgov.
the class EndpointResourceTest method testUpdateEndpoint.
@Test
void testUpdateEndpoint() {
Organization organization = OrganizationHelpers.createOrganization(ctx, client, "1211111111", false);
String endpointId = FHIRExtractors.getEntityUUID(organization.getEndpointFirstRep().getReference()).toString();
Endpoint endpoint = client.read().resource(Endpoint.class).withId(endpointId).execute();
endpoint.setName("New Endpoint Name");
MethodOutcome outcome = client.update().resource(endpoint).withId(endpoint.getId()).execute();
Endpoint updatedEndpoint = (Endpoint) outcome.getResource();
assertTrue(updatedEndpoint.equalsDeep(endpoint));
}
use of org.hl7.fhir.r4.model.Endpoint in project dpc-app by CMSgov.
the class EndpointResource method searchEndpoints.
@FHIR
@GET
@Timed
@ExceptionMetered
@UnitOfWork
@Override
public List<Endpoint> searchEndpoints(@NotNull @QueryParam("organization") String organizationID, @QueryParam("_id") String resourceId) {
final UUID orgUUID = FHIRExtractors.getEntityUUID(organizationID);
UUID endpointUUID = null;
if (resourceId != null) {
endpointUUID = FHIRExtractors.getEntityUUID(resourceId);
}
final List<EndpointEntity> endpointList = this.endpointDAO.endpointSearch(orgUUID, endpointUUID);
return endpointList.stream().map(e -> converter.toFHIR(Endpoint.class, e)).collect(Collectors.toList());
}
use of org.hl7.fhir.r4.model.Endpoint in project dpc-app by CMSgov.
the class OrganizationResourceTest method testMissingOrganization.
@Test
void testMissingOrganization() throws IOException {
// Generate a golden macaroon
final String goldenMacaroon = APIAuthHelpers.createGoldenMacaroon();
final IGenericClient client = APIAuthHelpers.buildAdminClient(ctx, getBaseURL(), goldenMacaroon, false);
final Endpoint endpoint = OrganizationFactory.createFakeEndpoint();
final Bundle bundle = new Bundle();
bundle.addEntry().setResource(endpoint);
final Parameters parameters = new Parameters();
parameters.addParameter().setName("resource").setResource(bundle);
final IOperationUntypedWithInput<Organization> operation = client.operation().onType(Organization.class).named("submit").withParameters(parameters).returnResourceType(Organization.class).encodedJson();
assertThrows(InvalidRequestException.class, operation::execute, "Should be unprocessable");
}
use of org.hl7.fhir.r4.model.Endpoint in project dpc-app by CMSgov.
the class OrganizationResourceTest method testUpdateOrganization.
@Test
void testUpdateOrganization() throws IOException, URISyntaxException, GeneralSecurityException {
final String orgID = UUID.randomUUID().toString();
final IParser parser = ctx.newJsonParser();
final IGenericClient attrClient = APITestHelpers.buildAttributionClient(ctx);
final String macaroon = FHIRHelpers.registerOrganization(attrClient, parser, orgID, "1111121111", getAdminURL());
final Pair<UUID, PrivateKey> uuidPrivateKeyPair = APIAuthHelpers.generateAndUploadKey("org-update-key", orgID, GOLDEN_MACAROON, getBaseURL());
final IGenericClient client = APIAuthHelpers.buildAuthenticatedClient(ctx, getBaseURL(), macaroon, uuidPrivateKeyPair.getLeft(), uuidPrivateKeyPair.getRight());
Organization organization = client.read().resource(Organization.class).withId(orgID).encodedJson().execute();
assertNotNull(organization);
organization.setName("New Org Name");
organization.setContact(Lists.emptyList());
MethodOutcome outcome = client.update().resource(organization).execute();
Organization result = (Organization) outcome.getResource();
assertEquals("1111121111", result.getIdentifierFirstRep().getValue());
assertEquals(organization.getName(), result.getName(), "Name should be updated");
assertTrue(organization.getContact().isEmpty(), "Contact list should be updated");
assertEquals(1, result.getEndpoint().size(), "Endpoint list should be unchanged");
// Try to update when authenticated as different organization
final String org2ID = UUID.randomUUID().toString();
final String org2Macaroon = FHIRHelpers.registerOrganization(attrClient, parser, org2ID, "4321234211", getAdminURL());
final Pair<UUID, PrivateKey> org2UUIDPrivateKeyPair = APIAuthHelpers.generateAndUploadKey("org2-update-key", org2ID, GOLDEN_MACAROON, getBaseURL());
final IGenericClient org2Client = APIAuthHelpers.buildAuthenticatedClient(ctx, getBaseURL(), org2Macaroon, org2UUIDPrivateKeyPair.getLeft(), org2UUIDPrivateKeyPair.getRight());
IUpdateTyped update = org2Client.update().resource(organization);
assertThrows(AuthenticationException.class, update::execute);
}
use of org.hl7.fhir.r4.model.Endpoint in project dpc-app by CMSgov.
the class EndpointResourceTest method testGetEndpoints.
@Test
void testGetEndpoints() {
Bundle result = client.search().forResource(Endpoint.class).returnBundle(Bundle.class).execute();
assertTrue(result.getTotal() > 0);
for (Bundle.BundleEntryComponent component : result.getEntry()) {
Resource resource = component.getResource();
assertEquals(DPCResourceType.Endpoint.getPath(), resource.getResourceType().getPath());
Endpoint endpoint = (Endpoint) resource;
assertEquals(APITestHelpers.ORGANIZATION_ID, FHIRExtractors.getEntityUUID(endpoint.getManagingOrganization().getReference()).toString());
}
}
Aggregations