use of org.forgerock.json.resource.QueryRequest in project OpenAM by OpenRock.
the class PrivilegePolicyStoreTest method shouldHandleAndQueries.
@Test
public void shouldHandleAndQueries() throws Exception {
// Given
String value1 = "value1";
String value2 = "value2";
QueryRequest request = mockQueryRequest(QueryFilter.and(QueryFilter.equalTo(new JsonPointer(STRING_ATTRIBUTE), value1), QueryFilter.equalTo(new JsonPointer(STRING_ATTRIBUTE), value2)));
// When
testStore.query(request);
// Then
verify(mockManager).search(asSet(new SearchFilter(STRING_SEARCH_ATTRIBUTE, value1), new SearchFilter(STRING_SEARCH_ATTRIBUTE, value2)));
}
use of org.forgerock.json.resource.QueryRequest in project OpenAM by OpenRock.
the class PrivilegePolicyStoreTest method shouldSendAllMatchingPoliciesToQueryHandler.
@Test
public void shouldSendAllMatchingPoliciesToQueryHandler() throws Exception {
// Given
QueryRequest request = mockQueryRequest(QueryFilter.alwaysTrue());
List<Privilege> policies = Arrays.<Privilege>asList(new StubPrivilege("one"), new StubPrivilege("two"), new StubPrivilege("three"));
given(mockManager.search(anySetOf(SearchFilter.class))).willReturn(policies);
// When
List<Privilege> result = testStore.query(request);
// Then
assertThat(result).isEqualTo(policies);
}
use of org.forgerock.json.resource.QueryRequest in project OpenAM by OpenRock.
the class PrivilegePolicyStoreTest method shouldTranslateAlwaysTrueQueryFilterToEmptySearchFilters.
@Test
public void shouldTranslateAlwaysTrueQueryFilterToEmptySearchFilters() throws Exception {
// Given
QueryRequest request = mockQueryRequest(QueryFilter.alwaysTrue());
// When
testStore.query(request);
// Then
verify(mockManager).search(Collections.<SearchFilter>emptySet());
}
use of org.forgerock.json.resource.QueryRequest in project OpenAM by OpenRock.
the class PolicyResourceWithCopyMoveSupport method copyOrMovePoliciesByApplication.
private ActionResponse copyOrMovePoliciesByApplication(Context context, ActionRequest request, PolicyAction copyOrMoveAction) throws ResourceException {
JsonValue payload = request.getContent();
JsonValue from = payload.get("from");
JsonValue to = payload.get("to");
if (from.isNull()) {
throw new BadRequestException("from definition is missing");
}
if (!from.isDefined("application")) {
throw new BadRequestException("from application definition is missing");
}
String sourceApplication = from.get("application").asString();
if (to.isNull()) {
throw new BadRequestException("to definition is missing");
}
String sourceRealm = RealmContext.getRealm(context);
String destinationRealm = to.get("realm").defaultTo(sourceRealm).asString();
String destinationApplication = to.get("application").defaultTo(sourceApplication).asString();
JsonValue resourceTypeMapping = payload.get("resourceTypeMapping").defaultTo(Collections.emptyMap());
String namePostfix = to.get("namePostfix").defaultTo("").asString();
QueryRequest queryRequest = Requests.newQueryRequest("policies");
queryRequest.setQueryFilter(QueryFilter.equalTo(new JsonPointer("applicationName"), sourceApplication));
final List<JsonValue> policies = new ArrayList<>();
router.handleQuery(context, queryRequest, new QueryResourceHandler() {
@Override
public boolean handleResource(ResourceResponse resourceResponse) {
policies.add(resourceResponse.getContent());
return true;
}
}).getOrThrowUninterruptibly();
JsonValue actionResponseContent = json(array());
for (JsonValue policy : policies) {
ActionResponse response = copyOrMoveGivenPolicy(context, policy, destinationRealm, destinationApplication, namePostfix, resourceTypeMapping, copyOrMoveAction);
actionResponseContent.add(response.getJsonContent().asMap());
}
return Responses.newActionResponse(actionResponseContent);
}
use of org.forgerock.json.resource.QueryRequest in project OpenAM by OpenRock.
the class ApplicationsResourceTest method shouldHandleStringEquality.
@Test
public void shouldHandleStringEquality() throws Exception {
// Given
String value = "testValue";
QueryRequest request = mockQueryRequest(equalTo(new JsonPointer(STRING_ATTRIBUTE), value));
Subject subject = new Subject();
// When
applicationsResource.query(request, subject, "/abc");
// Then
SearchFilter searchFilter = new SearchFilter(new SearchAttribute(STRING_ATTRIBUTE, "ou"), value);
verify(applicationManagerWrapper).search(eq(subject), eq("/abc"), eq(asSet(searchFilter)));
}
Aggregations