@Test
public void testRegistryStoredQuery() throws Throwable {

	// Arrange
	when(xdsbRegistry.extractFormatCode(adhocQuery)).thenReturn(formatCode)
			.thenReturn(formatCode);
	when(xdsbRegistry.extractDocumentEntryStatus(adhocQuery)).thenReturn(
			docEntryStatus);
	when(xdsbRegistry.extractPatientId(adhocQuery)).thenReturn(
			patientUniqueId).thenReturn(patientUniqueId);
	when(xdsbRegistry.getPatientUniqueId(anyString(), anyString()))
			.thenReturn(patientUniqueId);
	when(xdsbRegistry.extractResponseOptionReturnType(adhocQuery))
			.thenReturn(responseOptionType);
	when(
			xdsbRegistry.registryStoredQuery(eq(adhocQuery),
					eq(intermediarySubjectNPI), anyString())).thenReturn(
			adhocQueryResponse);
	when(contextHandler.enforcePolicy(isA(XacmlRequest.class))).thenReturn(
			xacmlResponse);
	when(context.getUserPrincipal()).thenReturn(samlTokenPrincipal);
	when(
			samlTokenParser.parse(samlTokenPrincipal.getToken(),
					"urn:oasis:names:tc:xacml:1.0:resource:resource-id"))
			.thenReturn(
					"d3bb3930-7241-11e3-b4f7-00155d3a2124^^^&2.16.840.1.113883.10.20.1^^HITSP");
	when(
			samlTokenParser.parse(samlTokenPrincipal.getToken(),
					"urn:oasis:names:tc:xacml:1.0:subject-category:intermediary-subject"))
			.thenReturn(intermediarySubjectNPI);
	when(
			samlTokenParser.parse(samlTokenPrincipal.getToken(),
					"urn:oasis:names:tc:xspa:1.0:subject:purposeofuse"))
			.thenReturn("TREATMENT");
	when(
			samlTokenParser.parse(samlTokenPrincipal.getToken(),
					"urn:oasis:names:tc:xacml:1.0:subject-category:recipient-subject"))
			.thenReturn(recepientSubjectNPI);
	// Act
	final AdhocQueryResponse response = pep.registryStoredQuery(adhocQuery);
	// Assert
	assertEquals(adhocQueryResponse, response);
}