@Test public void testFailTokenAuthInvalidateAppResource() throws Exception { String path = "/cache/invalidate"; RestHandler operation = registry.getRestHandler(path, "POST"); params.put(InvalidationHandler.KEYS_PARAM, new String[]{"http://www.example.org/gadget.xml"}); try { operation.execute(params, null, token, converter).get(); fail("Expected error"); } catch (ExecutionException ee) { assertTrue(ee.getCause() instanceof ProtocolException); } }
@Test public void testHandleSimpleGetInvalidateViewer() throws Exception { String path = "/cache/invalidate"; RestHandler operation = registry.getRestHandler(path, "GET"); invalidationService.invalidateUserResources( eq(ImmutableSet.of("userX")), eq(token)); expectLastCall(); replay(); operation.execute(params, null, token, converter).get(); verify(); reset(); }
@Before public void setUp() throws Exception { token = new FakeGadgetToken(); token.setAppId("appId"); token.setViewerId("userX"); converter = mock(BeanJsonConverter.class); invalidationService = mock(InvalidationService.class); handler = new InvalidationHandler(invalidationService); registry = new DefaultHandlerRegistry(null, converter, new HandlerExecutionListener.NoOpHandler()); registry.addHandlers(Sets.<Object>newHashSet(handler)); params = Maps.newHashMap(); }
@Before public void setUp() throws Exception { token = new FakeGadgetToken(); token.setAppId("appId"); token.setViewerId("userX"); converter = mock(BeanJsonConverter.class); invalidationService = mock(InvalidationService.class); handler = new InvalidationHandler(invalidationService); registry = new DefaultHandlerRegistry(null, converter, new HandlerExecutionListener.NoOpHandler()); registry.addHandlers(Sets.<Object>newHashSet(handler)); params = Maps.newHashMap(); }
@Test public void testHandleSimpleGetInvalidateViewer() throws Exception { String path = "/cache/invalidate"; RestHandler operation = registry.getRestHandler(path, "GET"); invalidationService.invalidateUserResources( eq(ImmutableSet.of("userX")), eq(token)); expectLastCall(); replay(); operation.execute(params, null, token, converter).get(); verify(); reset(); }
@Test public void testFailTokenAuthInvalidateAppResource() throws Exception { String path = "/cache/invalidate"; RestHandler operation = registry.getRestHandler(path, "POST"); params.put(InvalidationHandler.KEYS_PARAM, new String[]{"http://www.example.org/gadget.xml"}); try { operation.execute(params, null, token, converter).get(); fail("Expected error"); } catch (ExecutionException ee) { assertTrue(ee.getCause() instanceof ProtocolException); } }
@Before public void setUp() throws Exception { token = new FakeGadgetToken(); token.setAppId("appId"); token.setViewerId("userX"); converter = mock(BeanJsonConverter.class); invalidationService = mock(InvalidationService.class); handler = new InvalidationHandler(invalidationService); registry = new DefaultHandlerRegistry(null, converter, new HandlerExecutionListener.NoOpHandler()); registry.addHandlers(Sets.<Object>newHashSet(handler)); params = Maps.newHashMap(); }
@Test public void testHandleSimpleGetInvalidateViewer() throws Exception { String path = "/cache/invalidate"; RestHandler operation = registry.getRestHandler(path, "GET"); invalidationService.invalidateUserResources( eq(ImmutableSet.of("userX")), eq(token)); expectLastCall(); replay(); operation.execute(params, null, token, converter).get(); verify(); reset(); }
@Test public void testFailTokenAuthInvalidateAppResource() throws Exception { String path = "/cache/invalidate"; RestHandler operation = registry.getRestHandler(path, "POST"); params.put(InvalidationHandler.KEYS_PARAM, new String[]{"http://www.example.org/gadget.xml"}); try { operation.execute(params, null, token, converter).get(); fail("Expected error"); } catch (ExecutionException ee) { assertTrue(ee.getCause() instanceof ProtocolException); } }
@Test public void testAllowConsumerAuthInvalidateAppResource() throws Exception { String path = "/cache/invalidate"; RestHandler operation = registry.getRestHandler(path, "POST"); params.put(InvalidationHandler.KEYS_PARAM, new String[]{"http://www.example.org/gadget.xml"}); token.setAuthenticationMode(AuthenticationMode.OAUTH_CONSUMER_REQUEST.name()); invalidationService.invalidateApplicationResources( eq(ImmutableSet.of(Uri.parse("http://www.example.org/gadget.xml"))), eq(token)); expectLastCall(); replay(); operation.execute(params, null, token, converter).get(); verify(); reset(); }
@Test public void testFailInvalidateNoApp() throws Exception { String path = "/cache/invalidate"; RestHandler operation = registry.getRestHandler(path, "POST"); params.put(InvalidationHandler.KEYS_PARAM, new String[]{"http://www.example.org/gadget.xml"}); try { token.setAppId(""); token.setAppUrl(""); operation.execute(params, null, token, converter).get(); fail("Expected error"); } catch (ExecutionException ee) { assertTrue(ee.getCause() instanceof ProtocolException); } } }
@Test public void testAllowConsumerAuthInvalidateAppResource() throws Exception { String path = "/cache/invalidate"; RestHandler operation = registry.getRestHandler(path, "POST"); params.put(InvalidationHandler.KEYS_PARAM, new String[]{"http://www.example.org/gadget.xml"}); token.setAuthenticationMode(AuthenticationMode.OAUTH_CONSUMER_REQUEST.name()); invalidationService.invalidateApplicationResources( eq(ImmutableSet.of(Uri.parse("http://www.example.org/gadget.xml"))), eq(token)); expectLastCall(); replay(); operation.execute(params, null, token, converter).get(); verify(); reset(); }
@Test public void testFailInvalidateNoApp() throws Exception { String path = "/cache/invalidate"; RestHandler operation = registry.getRestHandler(path, "POST"); params.put(InvalidationHandler.KEYS_PARAM, new String[]{"http://www.example.org/gadget.xml"}); try { token.setAppId(""); token.setAppUrl(""); operation.execute(params, null, token, converter).get(); fail("Expected error"); } catch (ExecutionException ee) { assertTrue(ee.getCause() instanceof ProtocolException); } } }
@Test public void testAllowConsumerAuthInvalidateAppResource() throws Exception { String path = "/cache/invalidate"; RestHandler operation = registry.getRestHandler(path, "POST"); params.put(InvalidationHandler.KEYS_PARAM, new String[]{"http://www.example.org/gadget.xml"}); token.setAuthenticationMode(AuthenticationMode.OAUTH_CONSUMER_REQUEST.name()); invalidationService.invalidateApplicationResources( eq(ImmutableSet.of(Uri.parse("http://www.example.org/gadget.xml"))), eq(token)); expectLastCall(); replay(); operation.execute(params, null, token, converter).get(); verify(); reset(); }
@Test public void testFailInvalidateNoApp() throws Exception { String path = "/cache/invalidate"; RestHandler operation = registry.getRestHandler(path, "POST"); params.put(InvalidationHandler.KEYS_PARAM, new String[]{"http://www.example.org/gadget.xml"}); try { token.setAppId(""); token.setAppUrl(""); operation.execute(params, null, token, converter).get(); fail("Expected error"); } catch (ExecutionException ee) { assertTrue(ee.getCause() instanceof ProtocolException); } } }