@Override public boolean apply(Integer input) { checkNotNull(input, "action id cannot be null"); Action current = api.actionApi().get(input); switch (current.status()) { case COMPLETED: return true; case IN_PROGRESS: return false; case ERRORED: default: throw new IllegalStateException("Resource is in invalid status: " + current.status().name()); } }
@Override protected IterableWithMarker<Action> fetchPageUsingOptions(ListOptions options, Optional<Object> arg0) { return api.actionApi().list(options); } }
@Override protected IterableWithMarker<Action> fetchPageUsingOptions(ListOptions options, Optional<Object> arg0) { return api.actionApi().list(options); } }
@Override public boolean apply(Integer input) { checkNotNull(input, "action id cannot be null"); Action current = api.actionApi().get(input); switch (current.status()) { case COMPLETED: return true; case IN_PROGRESS: return false; case ERRORED: default: throw new IllegalStateException("Resource is in invalid status: " + current.status().name()); } }
@Override protected IterableWithMarker<Action> fetchPageUsingOptions(ListOptions options, Optional<Object> arg0) { return api.actionApi().list(options); } }
@Override public boolean apply(Integer input) { checkNotNull(input, "action id cannot be null"); Action current = api.actionApi().get(input); switch (current.status()) { case COMPLETED: return true; case IN_PROGRESS: return false; case ERRORED: default: throw new IllegalStateException("Resource is in invalid status: " + current.status().name()); } }
public void testListActions() { final AtomicInteger found = new AtomicInteger(0); // DigitalOcean return 25 records per page by default. Inspect at most 2 pages assertTrue(api().list().concat().limit(50).allMatch(new Predicate<Action>() { @Override public boolean apply(Action input) { found.incrementAndGet(); return !isNullOrEmpty(input.type()); } }), "All actions must have the 'type' field populated"); assertTrue(found.get() > 0, "Expected some actions to be returned"); }
public void testActionStatusOk() { ActionApi actionApi = EasyMock.createMock(ActionApi.class); DigitalOcean2Api api = EasyMock.createMock(DigitalOcean2Api.class); expect(actionApi.get(1)).andReturn(action(Action.Status.COMPLETED)); expect(actionApi.get(2)).andReturn(action(Action.Status.IN_PROGRESS)); expect(api.actionApi()).andReturn(actionApi).times(2); replay(actionApi, api); ActionDonePredicate predicate = new ActionDonePredicate(api); assertTrue(predicate.apply(1)); assertFalse(predicate.apply(2)); }
public void testListActionsOnePage() { final AtomicInteger found = new AtomicInteger(0); assertTrue(api().list(page(1).perPage(5)).allMatch(new Predicate<Action>() { @Override public boolean apply(Action input) { found.incrementAndGet(); return !isNullOrEmpty(input.type()); } }), "All actions must have the 'type' field populated"); assertTrue(found.get() > 0, "Expected some actions to be returned"); }
public void testActionStatusError() { ActionApi actionApi = EasyMock.createMock(ActionApi.class); DigitalOcean2Api api = EasyMock.createMock(DigitalOcean2Api.class); expect(actionApi.get(anyInt())).andReturn(action(Action.Status.ERRORED)); expect(api.actionApi()).andReturn(actionApi); replay(actionApi, api); ActionDonePredicate predicate = new ActionDonePredicate(api); try { predicate.apply(1); fail("Method should have thrown an IllegalStateException"); } catch (IllegalStateException ex) { assertEquals(ex.getMessage(), "Resource is in invalid status: ERRORED"); } }
public void testListActionsReturns404() throws InterruptedException { server.enqueue(response404()); Iterable<Action> actions = api.actionApi().list().concat(); assertTrue(isEmpty(actions)); assertEquals(server.getRequestCount(), 1); assertSent(server, "GET", "/actions"); }
public void testGetActionReturns404() throws InterruptedException { server.enqueue(response404()); Action action = api.actionApi().get(1); assertNull(action); assertEquals(server.getRequestCount(), 1); assertSent(server, "GET", "/actions/1"); }
public void testListActionsWithOptions() throws InterruptedException { server.enqueue(jsonResponse("/actions-first.json")); Iterable<Action> actions = api.actionApi().list(page(1).perPage(5)); assertEquals(size(actions), 5); assertEquals(server.getRequestCount(), 1); assertSent(server, "GET", "/actions?page=1&per_page=5"); }
public void testGetAction() throws InterruptedException { server.enqueue(jsonResponse("/action.json")); Action action = api.actionApi().get(1); assertEquals(action, actionFromResource("/action.json")); assertEquals(server.getRequestCount(), 1); assertSent(server, "GET", "/actions/1"); }
public void testListActionsWithOptionsReturns404() throws InterruptedException { server.enqueue(response404()); Iterable<Action> actions = api.actionApi().list(page(1).perPage(5)); assertTrue(isEmpty(actions)); assertEquals(server.getRequestCount(), 1); assertSent(server, "GET", "/actions?page=1&per_page=5"); }
public void testListActions() throws InterruptedException { server.enqueue(jsonResponse("/actions-first.json")); server.enqueue(jsonResponse("/actions-last.json")); Iterable<Action> actions = api.actionApi().list().concat(); assertEquals(size(actions), 8); // Force the PagedIterable to advance assertEquals(server.getRequestCount(), 2); assertSent(server, "GET", "/actions"); assertSent(server, "GET", "/actions?page=2&per_page=5"); }