@Test public void shouldIndicateWhenNoTokenCanBeRead() throws CoreTokenException { CTSPersistentStore store = mock(CTSPersistentStore.class); given(store.read(anyString())).willReturn(null); CoreTokenResource resource = new CoreTokenResource(mock(JSONSerialisation.class), store); ResultHandler<Resource> handler = mock(ResultHandler.class); resource.readInstance(null, "badger", mock(ReadRequest.class), handler); ArgumentCaptor<ResourceException> captor = ArgumentCaptor.forClass(ResourceException.class); verify(handler).handleError(captor.capture()); ResourceException exception = captor.getValue(); assertEquals(exception.getCode(), ResourceException.NOT_FOUND); }
public void readInstance(ServerContext serverContext, String tokenId, ReadRequest readRequest, ResultHandler<Resource> handler) { try { Token token = store.read(tokenId); if (token == null) { handler.handleError(generateNotFoundException(tokenId)); return; } String json = serialisation.serialise(token); Resource response = new Resource(null, null, new JsonValue(json)); handler.handleResult(response); } catch (CoreTokenException e) { handler.handleError(generateException(e)); } }
CoreTokenResource implements CollectionResourceProvider { public void readInstance(ServerContext serverContext, String tokenId, ReadRequest readRequest, ResultHandler<Resource> handler) { try { Token token = store.read(tokenId); if (token == null) { handler.handleError(generateNotFoundException(tokenId)); return; } String json = serialisation.serialise(token); Resource response = new Resource(null, null, new JsonValue(json)); handler.handleResult(response); } catch (CoreTokenException e) { handler.handleError(generateException(e)); } } }
CoreTokenResource implements CollectionResourceProvider { public void readInstance(ServerContext serverContext, String tokenId, ReadRequest readRequest, ResultHandler<Resource> handler) { try { Token token = store.read(tokenId); if (token == null) { handler.handleError(generateNotFoundException(tokenId)); return; } String json = serialisation.serialise(token); Resource response = new Resource(null, null, new JsonValue(json)); handler.handleResult(response); } catch (CoreTokenException e) { handler.handleError(generateException(e)); } } CoreTokenResource(JSONSerialisation serialisation, CTSPersistentStore store); }
CoreTokenResource implements CollectionResourceProvider { public void readInstance(ServerContext serverContext, String tokenId, ReadRequest readRequest, ResultHandler<Resource> handler) { try { Token token = store.read(tokenId); if (token == null) { handler.handleError(generateNotFoundException(tokenId)); return; } String json = serialisation.serialise(token); Resource response = new Resource(null, null, new JsonValue(json)); handler.handleResult(response); } catch (CoreTokenException e) { handler.handleError(generateException(e)); } } CoreTokenResource(JSONSerialisation serialisation, CTSPersistentStore store); void createInstance(ServerContext serverContext, CreateRequest createRequest, ResultHandler<Resource> handler); void deleteInstance(ServerContext serverContext, String tokenId, DeleteRequest deleteRequest, ResultHandler<Resource> handler); void readInstance(ServerContext serverContext, String tokenId, ReadRequest readRequest, ResultHandler<Resource> handler); void updateInstance(ServerContext serverContext, String tokenId, UpdateRequest updateRequest, ResultHandler<Resource> handler); void queryCollection(ServerContext serverContext, QueryRequest queryRequest, QueryResultHandler queryResultHandler); void patchInstance(ServerContext serverContext, String s, PatchRequest patchRequest, ResultHandler<Resource> handler); void actionInstance(ServerContext serverContext, String s, ActionRequest actionRequest, ResultHandler<JsonValue> jsonValueResultHandler); void actionCollection(ServerContext serverContext, ActionRequest actionRequest, ResultHandler<JsonValue> jsonValueResultHandler); }
CoreTokenResource implements CollectionResourceProvider { public void readInstance(ServerContext serverContext, String tokenId, ReadRequest readRequest, ResultHandler<Resource> handler) { try { Token token = store.read(tokenId); if (token == null) { handler.handleError(generateNotFoundException(tokenId)); return; } String json = serialisation.serialise(token); Resource response = new Resource(null, null, new JsonValue(json)); handler.handleResult(response); } catch (CoreTokenException e) { handler.handleError(generateException(e)); } } CoreTokenResource(JSONSerialisation serialisation, CTSPersistentStore store); void createInstance(ServerContext serverContext, CreateRequest createRequest, ResultHandler<Resource> handler); void deleteInstance(ServerContext serverContext, String tokenId, DeleteRequest deleteRequest, ResultHandler<Resource> handler); void readInstance(ServerContext serverContext, String tokenId, ReadRequest readRequest, ResultHandler<Resource> handler); void updateInstance(ServerContext serverContext, String tokenId, UpdateRequest updateRequest, ResultHandler<Resource> handler); void queryCollection(ServerContext serverContext, QueryRequest queryRequest, QueryResultHandler queryResultHandler); void patchInstance(ServerContext serverContext, String s, PatchRequest patchRequest, ResultHandler<Resource> handler); void actionInstance(ServerContext serverContext, String s, ActionRequest actionRequest, ResultHandler<JsonValue> jsonValueResultHandler); void actionCollection(ServerContext serverContext, ActionRequest actionRequest, ResultHandler<JsonValue> jsonValueResultHandler);  }