@Test public void testGet() throws Exception { assertEquals("foo", ImmediateFuture.newInstance("foo").get()); }
@Operation(httpMethods = {"POST", "PUT"}) public Future<?> create(RequestItem req) { if (mock != null) { return mock.create(req); } return ImmediateFuture.newInstance(CREATE_RESPONSE); }
@Test public void testGetWithTimeout() throws Exception { assertEquals("foo", ImmediateFuture.newInstance("foo").get(1L, TimeUnit.MILLISECONDS)); }
@Test public void testIsDone() { assertTrue(ImmediateFuture.newInstance("foo").isDone()); }
@Test public void testGetWithTimeout() throws Exception { assertEquals("foo", ImmediateFuture.newInstance("foo").get(1L, TimeUnit.MILLISECONDS)); }
@Test public void testCancel() { Future<String> stringFuture = ImmediateFuture.newInstance("foo"); assertFalse(stringFuture.cancel(true)); assertFalse(stringFuture.cancel(false)); assertFalse(stringFuture.isCancelled()); }
@Operation(httpMethods = {"POST", "PUT"}) public Future<?> create(RequestItem req) { if (mock != null) { return mock.create(req); } return ImmediateFuture.newInstance(CREATE_RESPONSE); }
@Test public void testCancel() { Future<String> stringFuture = ImmediateFuture.newInstance("foo"); assertFalse(stringFuture.cancel(true)); assertFalse(stringFuture.cancel(false)); assertFalse(stringFuture.isCancelled()); }
@Test public void testPostMessage() throws Exception { MessageImpl message = new MessageImpl("A message body", "A title", Message.Type.PRIVATE_MESSAGE); message.setRecipients(recipients); EasyMock.expect(converter.convertToObject(null, Message.class)).andReturn(message); EasyMock.expect(messageService.createMessage(sender, "messageHandlerTest", "@outbox", message, token)).andReturn(ImmediateFuture.newInstance((Void) null)); EasyMock.replay(messageService, converter); RestHandler operation = registry.getRestHandler("/messages/" + sender.getUserId() + "/@outbox", "POST"); Map<String,String[]> params = ImmutableMap.of(RequestItem.APP_ID, new String[]{"messageHandlerTest"}); operation.execute(params,null, token, converter).get(); EasyMock.verify(converter, messageService); } }
@Test public void testGetFirstOfMany() throws Exception { List<String> words = Lists.newArrayList(firstWord, "goodbye", "blah"); Future<RestfulCollection<String>> collection = ImmediateFuture.newInstance( new RestfulCollection<String>(words)); Future<String> futureWord = FutureUtil.getFirstFromCollection(collection); assertEquals(firstWord, futureWord.get()); }
@Test public void testGetFirstOfNone() throws Exception { List<String> words = Lists.newArrayList(new String[]{}); Future<RestfulCollection<String>> collection = ImmediateFuture.newInstance( new RestfulCollection<String>(words)); Future<String> futureWord = FutureUtil.getFirstFromCollection(collection); assertNull(futureWord.get()); } }
@Test public void testGetFirstOfMany() throws Exception { List<String> words = Lists.newArrayList(firstWord, "goodbye", "blah"); Future<RestfulCollection<String>> collection = ImmediateFuture.newInstance( new RestfulCollection<String>(words)); Future<String> futureWord = FutureUtil.getFirstFromCollection(collection); assertEquals(firstWord, futureWord.get()); }
@Test public void testGetFirstOfSingle() throws Exception { List<String> words = Lists.newArrayList(firstWord); Future<RestfulCollection<String>> collection = ImmediateFuture.newInstance( new RestfulCollection<String>(words)); Future<String> futureWord = FutureUtil.getFirstFromCollection(collection); assertEquals(firstWord, futureWord.get()); }
@Test public void testGetFirstOfSingle() throws Exception { List<String> words = Lists.newArrayList(firstWord); Future<RestfulCollection<String>> collection = ImmediateFuture.newInstance( new RestfulCollection<String>(words)); Future<String> futureWord = FutureUtil.getFirstFromCollection(collection); assertEquals(firstWord, futureWord.get()); }
@Test public void testGetFirstOfNone() throws Exception { List<String> words = Lists.newArrayList(new String[]{}); Future<RestfulCollection<String>> collection = ImmediateFuture.newInstance( new RestfulCollection<String>(words)); Future<String> futureWord = FutureUtil.getFirstFromCollection(collection); assertNull(futureWord.get()); } }
@Test public void testHandleGetSelf() throws Exception { String path = "/people/john.doe/@self"; RestHandler operation = registry.getRestHandler(path, "GET"); Person data = new PersonImpl(); expect(personService.getPerson(eq(JOHN_DOE.iterator().next()), eq(DEFAULT_FIELDS), eq(token))).andReturn(ImmediateFuture.newInstance(data)); replay(); assertEquals(data, operation.execute(Maps.<String, String[]>newHashMap(), null, token, converter).get()); verify(); }
private Future<?> setupBodyRequest(String method) throws ProtocolException { String jsonActivity = "{title: hi mom!, etc etc}"; String path = "/activities/john.doe/@self/@app"; RestHandler operation = registry.getRestHandler(path, method); Activity activity = new ActivityImpl(); org.easymock.EasyMock.expect(converter.convertToObject(eq(jsonActivity), eq(Activity.class))) .andReturn(activity); org.easymock.EasyMock.expect(activityService.createActivity(eq(JOHN_DOE.iterator().next()), eq(new GroupId(GroupId.Type.self, null)), eq("appId"), eq(ImmutableSet.<String>of()), eq(activity), eq(token))).andReturn(ImmediateFuture.newInstance((Void) null)); replay(); return operation.execute(Maps.<String, String[]>newHashMap(), new StringReader(jsonActivity), token, converter); }
@Test public void testHandleDelete() throws Exception { String path = "/activities/john.doe/@self/@app/1"; RestHandler operation = registry.getRestHandler(path, "DELETE"); org.easymock.EasyMock.expect(activityService.deleteActivities(eq(JOHN_DOE.iterator().next()), eq(new GroupId(GroupId.Type.self, null)), eq("appId"), eq(ImmutableSet.of("1")), eq(token))).andReturn(ImmediateFuture.newInstance((Void) null)); replay(); assertNull(operation.execute(Maps.<String, String[]>newHashMap(), null, token, converter).get()); verify(); reset(); }
private void assertHandleGetForGroup(GroupId.Type group) throws Exception { String path = "/appdata/john.doe/@" + group.toString() + "/appId"; RestHandler operation = registry.getRestHandler(path, "GET"); DataCollection data = new DataCollection(null); org.easymock.EasyMock.expect(appDataService.getPersonData(eq(JOHN_DOE), eq(new GroupId(group, null)), eq("appId"), eq(ImmutableSet.<String>of()), eq(token))) .andReturn(ImmediateFuture.newInstance(data)); replay(); assertEquals(data, operation.execute(Maps.<String, String[]>newHashMap(), null, token, converter).get()); verify(); }
private void assertHandleGetForGroup(GroupId.Type group) throws Exception { String path = "/activities/john.doe/@" + group.toString(); RestHandler operation = registry.getRestHandler(path, "GET"); List<Activity> activityList = ImmutableList.of(); RestfulCollection<Activity> data = new RestfulCollection<Activity>(activityList); org.easymock.EasyMock.expect(activityService.getActivities(eq(JOHN_DOE), eq(new GroupId(group, null)), (String)isNull(), eq(ImmutableSet.<String>of()), org.easymock.EasyMock.isA(CollectionOptions.class), eq(token))). andReturn(ImmediateFuture.newInstance(data)); replay(); assertEquals(data, operation.execute(Maps.<String, String[]>newHashMap(), null, token, converter).get()); verify(); reset(); }