public FeatureRegistry get(String repository) throws GadgetException { if (repository == null) { return registry; } throw new GadgetException(Code.INVALID_PARAMETER, "Repository is not supported", HttpResponse.SC_BAD_REQUEST); } }
public HttpResponse fetch(HttpRequest request) throws GadgetException { fetchCount++; this.request = request; if (response == null) { throw new GadgetException(GadgetException.Code.FAILED_TO_RETRIEVE_CONTENT); } return response; } }
public HttpResponse fetch(HttpRequest request) throws GadgetException { fetchCount++; this.request = request; if (response == null) { throw new GadgetException(GadgetException.Code.FAILED_TO_RETRIEVE_CONTENT); } return response; } }
/** * @param request * @return A valid token for the given input. */ private SecurityToken extractAndValidateToken(HttpServletRequest request) throws GadgetException { SecurityToken token = AuthInfoUtil.getSecurityTokenFromRequest(request); if (token == null) { // TODO: Determine appropriate external error code for this. throw new GadgetException(GadgetException.Code.INVALID_SECURITY_TOKEN); } return token; }
/** * @param request * @return A valid token for the given input. */ private SecurityToken extractAndValidateToken(HttpServletRequest request) throws GadgetException { SecurityToken token = new AuthInfo(request).getSecurityToken(); if (token == null) { // TODO: Determine appropriate external error code for this. throw new GadgetException(GadgetException.Code.INVALID_SECURITY_TOKEN); } return token; }
/** * @param request * @return A valid token for the given input. */ private SecurityToken extractAndValidateToken(HttpServletRequest request) throws GadgetException { SecurityToken token = new AuthInfo(request).getSecurityToken(); if (token == null) { // TODO: Determine appropriate external error code for this. throw new GadgetException(GadgetException.Code.INVALID_SECURITY_TOKEN); } return token; }
public GadgetSpec getGadgetSpec(final GadgetContext context) throws GadgetException { final Uri contextUri = context.getUrl(); if (contextUri != null && contextUri.toString().equals(MockUtils.GADGET_URI1)) { return new GadgetSpec(context.getUrl(), DummyGadgetSpecFactory.xml); } throw new GadgetException(GadgetException.Code.OAUTH_STORAGE_ERROR); }
@Test public void handlesRuntimeWrappedGadgetExceptionGracefully() { htmlRenderer.runtimeException = new RuntimeException( new GadgetException(GadgetException.Code.FAILED_TO_RETRIEVE_CONTENT, "oh no!")); RenderingResults results = renderer.render(makeContext("html")); assertEquals(RenderingResults.Status.ERROR, results.getStatus()); assertEquals("oh no!", results.getErrorMessage()); }
public GadgetSpec getGadgetSpec(final GadgetContext context) throws GadgetException { final Uri contextUri = context.getUrl(); if (contextUri != null && contextUri.toString().equals(MockUtils.GADGET_URI1)) { return new GadgetSpec(context.getUrl(), DummyGadgetSpecFactory.xml); } throw new GadgetException(GadgetException.Code.OAUTH_STORAGE_ERROR); }
@Test(expected = ProcessingException.class) public void handlesGadgetExceptionGracefully() throws Exception { gadgetSpecFactory.exception = new GadgetException(GadgetException.Code.INVALID_PATH); processor.process(makeContext("url")); }
@Test public void handlesRuntimeWrappedGadgetExceptionGracefully() { htmlRenderer.runtimeException = new RuntimeException( new GadgetException(GadgetException.Code.FAILED_TO_RETRIEVE_CONTENT, "oh no!")); RenderingResults results = renderer.render(makeContext("html")); assertEquals(RenderingResults.Status.ERROR, results.getStatus()); assertEquals("oh no!", results.getErrorMessage()); }
@Test public void testDoPostException() throws Exception { setupRequest(BASIC_SYNTAX_URL); expect(request.getInputStream()).andReturn(postContentStream); expect(request.getMethod()).andReturn(POST_METHOD); expect(proxyHandler.fetch(proxyUri, POST_CONTENT)).andThrow( new GadgetException(GadgetException.Code.FAILED_TO_RETRIEVE_CONTENT, ERROR_MESSAGE)); replay(); servlet.doPost(request, recorder); verify(); assertEquals(HttpServletResponse.SC_BAD_REQUEST, recorder.getHttpStatusCode()); assertContains(ERROR_MESSAGE, recorder.getResponseAsString()); }
@Test(expected = GadgetException.class) public void throwingPipelineRethrows() throws Exception { HttpRequest request = createIgnoreCacheRequest(); expect(pipeline.execute(request)).andThrow( new GadgetException(GadgetException.Code.FAILED_TO_RETRIEVE_CONTENT)); replay(pipeline); specFactory.getGadgetSpec(createContext(SPEC_URL, true)); }
@Test(expected = GadgetException.class) public void throwingPipelineRethrows() throws Exception { HttpRequest request = createIgnoreCacheRequest(); expect(pipeline.execute(request)).andThrow( new GadgetException(GadgetException.Code.FAILED_TO_RETRIEVE_CONTENT)); replay(pipeline); specFactory.getGadgetSpec(createContext(SPEC_URL, true)); }
@Test public void testJsServletGivesErrorWhenUriManagerThrowsException() throws Exception { setUp(0); expect(jsUriManagerMock.processExternJsUri(isA(Uri.class))).andThrow(new GadgetException(null)); replay(); servlet.doGet(request, recorder); assertEquals(HttpServletResponse.SC_BAD_REQUEST, recorder.getHttpStatusCode()); verify(); }
@Test public void testDoGetException() throws Exception { setupGet(); expect(pipeline.execute(internalRequest)).andThrow( new GadgetException(GadgetException.Code.FAILED_TO_RETRIEVE_CONTENT, ERROR_MESSAGE)); replay(); servlet.doGet(request, recorder); assertEquals(HttpServletResponse.SC_BAD_REQUEST, recorder.getHttpStatusCode()); assertContains(ERROR_MESSAGE, recorder.getResponseAsString()); }
@Test public void testDoGetException() throws Exception { setupGet(); expect(pipeline.execute(internalRequest)).andThrow( new GadgetException(GadgetException.Code.FAILED_TO_RETRIEVE_CONTENT, ERROR_MESSAGE)); replay(); servlet.doGet(request, recorder); assertEquals(HttpServletResponse.SC_BAD_REQUEST, recorder.getHttpStatusCode()); assertContains(ERROR_MESSAGE, recorder.getResponseAsString()); }
@Test public void testDoPostException() throws Exception { setupPost(); expect(pipeline.execute(internalRequest)).andThrow( new GadgetException(GadgetException.Code.FAILED_TO_RETRIEVE_CONTENT, ERROR_MESSAGE)); replay(); servlet.doPost(request, recorder); assertEquals(HttpServletResponse.SC_BAD_REQUEST, recorder.getHttpStatusCode()); assertContains(ERROR_MESSAGE, recorder.getResponseAsString()); } }
@Test public void testDoGetException() throws Exception { setupGet(); expect(pipeline.execute(internalRequest)).andThrow( new GadgetException(GadgetException.Code.FAILED_TO_RETRIEVE_CONTENT, ERROR_MESSAGE)); replay(); servlet.doGet(request, recorder); assertEquals(HttpServletResponse.SC_BAD_REQUEST, recorder.getHttpStatusCode()); assertContains(ERROR_MESSAGE, recorder.getResponseAsString()); }
@Test public void testDoGetException() throws Exception { setupRequest(BASIC_SYNTAX_URL); expect(proxyHandler.fetch(proxyUri)).andThrow( new GadgetException(GadgetException.Code.FAILED_TO_RETRIEVE_CONTENT, ERROR_MESSAGE)); replay(); servlet.doGet(request, recorder); verify(); assertEquals(HttpServletResponse.SC_BAD_REQUEST, recorder.getHttpStatusCode()); assertContains(ERROR_MESSAGE, recorder.getResponseAsString()); }