use of org.motechproject.mds.exception.rest.RestLookupNotFoundException in project motech by motech.
the class MdsRestFacadeImpl method executeLookup.
@Override
@Transactional
public Object executeLookup(String lookupName, Map<String, String> lookupMap, QueryParams queryParams, boolean includeBlob) {
if (lookupExecutors.containsKey(lookupName)) {
LookupExecutor executor = lookupExecutors.get(lookupName);
Object result = executor.execute(lookupMap, queryParams);
if (result instanceof Collection) {
if (includeBlob) {
for (T value : ((Collection<T>) result)) {
getBlobs(value);
}
}
return new RestResponse(entityName, entityClass.getName(), moduleName, namespace, executor.executeCount(lookupMap), queryParams, RestProjection.createProjectionCollection((Collection) result, restFields, blobFields));
} else {
if (result == null) {
throw new RestNoLookupResultException("No result for lookup:" + lookupName);
}
if (includeBlob) {
getBlobs((T) result);
}
return new RestResponse(entityName, entityClass.getName(), moduleName, namespace, 1l, new QueryParams(1, 1), RestProjection.createProjection(result, restFields, blobFields));
}
} else if (forbiddenLookupMethodNames.contains(lookupName)) {
throw new RestLookupExecutionForbiddenException(lookupName);
} else {
throw new RestLookupNotFoundException(lookupName);
}
}
use of org.motechproject.mds.exception.rest.RestLookupNotFoundException in project motech by motech.
the class MdsRestControllerTest method shouldReturn404ForNotExistingLookups.
// lookup errors
@Test
public void shouldReturn404ForNotExistingLookups() throws Exception {
when(restFacadeRetriever.getRestFacade(ENTITY_NAME, MODULE_NAME, NAMESPACE)).thenReturn(restFacade);
when(restFacade.executeLookup(eq(LOOKUP_NAME), any(Map.class), any(QueryParams.class), anyBoolean())).thenThrow(new RestLookupNotFoundException(LOOKUP_NAME));
mockMvc.perform(get(buildUrl(ENTITY_NAME, MODULE_NAME, NAMESPACE) + "?lookup=" + LOOKUP_NAME)).andExpect(status().isNotFound());
verify(restFacade).executeLookup(eq(LOOKUP_NAME), any(Map.class), any(QueryParams.class), anyBoolean());
}
Aggregations