Search in sources :

Example 1 with RestNotSupportedException

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());
}
Also used : RestNotSupportedException(org.motechproject.mds.exception.rest.RestNotSupportedException) Test(org.junit.Test)

Example 2 with RestNotSupportedException

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;
}
Also used : MdsRestFacade(org.motechproject.mds.rest.MdsRestFacade) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) RestNotSupportedException(org.motechproject.mds.exception.rest.RestNotSupportedException) ServiceReference(org.osgi.framework.ServiceReference)

Aggregations

RestNotSupportedException (org.motechproject.mds.exception.rest.RestNotSupportedException)2 Test (org.junit.Test)1 MdsRestFacade (org.motechproject.mds.rest.MdsRestFacade)1 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)1 ServiceReference (org.osgi.framework.ServiceReference)1