use of org.motechproject.mds.exception.rest.RestNotSupportedException in project motech by motech.
the class MdsRestControllerTest method shouldReturn404WhenEntityNotFound.
// ERRORS
@Test
public void shouldReturn404WhenEntityNotFound() throws Exception {
when(restFacadeRetriever.getRestFacade(ENTITY_NAME, MODULE_NAME, NAMESPACE)).thenThrow(new RestNotSupportedException(ENTITY_NAME, MODULE_NAME, NAMESPACE));
String url = buildUrl(ENTITY_NAME, MODULE_NAME, NAMESPACE);
mockMvc.perform(get(url)).andExpect(status().isNotFound());
mockMvc.perform(put(url)).andExpect(status().isNotFound());
mockMvc.perform(post(url)).andExpect(status().isNotFound());
mockMvc.perform(delete(url + "/6")).andExpect(status().isNotFound());
}
use of org.motechproject.mds.exception.rest.RestNotSupportedException in project motech by motech.
the class MdsRestFacadeRetriever method getRestFacade.
public MdsRestFacade getRestFacade(String entityName, String moduleName, String namespace) {
String restId = ClassName.restId(entityName, moduleName, namespace);
MdsRestFacade restFacade = null;
try {
String filter = String.format("(org.eclipse.gemini.blueprint.bean.name=%s)", restId);
Collection<ServiceReference<MdsRestFacade>> refs = bundleContext.getServiceReferences(MdsRestFacade.class, filter);
if (refs != null && refs.size() > 1 && LOGGER.isWarnEnabled()) {
LOGGER.warn("More then one Rest Facade matching for entityName={}, module={}, namespace={}. " + "Using first one available.", entityName, moduleName, namespace);
}
if (refs != null && refs.size() > 0) {
ServiceReference<MdsRestFacade> ref = refs.iterator().next();
restFacade = bundleContext.getService(ref);
}
} catch (InvalidSyntaxException e) {
throw new IllegalArgumentException("Invalid Syntax for Rest Facade retrieval", e);
}
if (restFacade == null) {
throw new RestNotSupportedException(entityName, moduleName, namespace);
}
return restFacade;
}
Aggregations