@Test public void shouldUpdateUsingTokenInUpdateRequest() throws CoreTokenException { JSONSerialisation serialisation = new JSONSerialisation(); CTSPersistentStore store = mock(CTSPersistentStore.class); ResultHandler<Resource> handler = mock(ResultHandler.class); UpdateRequest updateRequest = mock(UpdateRequest.class); CoreTokenResource resource = new CoreTokenResource(serialisation, store); Token token = new Token("badger", TokenType.OAUTH); String tokenJson = serialisation.serialise(token); given(updateRequest.getNewContent()).willReturn(new JsonValue(tokenJson)); resource.updateInstance(null, "badger", updateRequest, handler); verify(store).update(any(Token.class)); }
public void updateInstance(ServerContext serverContext, String tokenId, UpdateRequest updateRequest, ResultHandler<Resource> handler) { JsonValue value = updateRequest.getNewContent(); String jsonText = value.getObject().toString(); Token newToken = serialisation.deserialise(jsonText, Token.class); try { store.update(newToken); Resource resource = new Resource(newToken.getTokenId(), "0", new JsonValue("Token Updated")); handler.handleResult(resource); } catch (CoreTokenException e) { generateException(e); } }
CoreTokenResource implements CollectionResourceProvider { public void updateInstance(ServerContext serverContext, String tokenId, UpdateRequest updateRequest, ResultHandler<Resource> handler) { JsonValue value = updateRequest.getNewContent(); String jsonText = value.getObject().toString(); Token newToken = serialisation.deserialise(jsonText, Token.class); try { store.update(newToken); Resource resource = new Resource(newToken.getTokenId(), "0", new JsonValue("Token Updated")); handler.handleResult(resource); } catch (CoreTokenException e) { generateException(e); } } }
CoreTokenResource implements CollectionResourceProvider { public void updateInstance(ServerContext serverContext, String tokenId, UpdateRequest updateRequest, ResultHandler<Resource> handler) { JsonValue value = updateRequest.getNewContent(); String jsonText = value.getObject().toString(); Token newToken = serialisation.deserialise(jsonText, Token.class); try { store.update(newToken); Resource resource = new Resource(newToken.getTokenId(), "0", new JsonValue("Token Updated")); handler.handleResult(resource); } catch (CoreTokenException e) { generateException(e); } } CoreTokenResource(JSONSerialisation serialisation, CTSPersistentStore store); }
CoreTokenResource implements CollectionResourceProvider { public void updateInstance(ServerContext serverContext, String tokenId, UpdateRequest updateRequest, ResultHandler<Resource> handler) { JsonValue value = updateRequest.getNewContent(); String jsonText = value.getObject().toString(); Token newToken = serialisation.deserialise(jsonText, Token.class); try { store.update(newToken); Resource resource = new Resource(newToken.getTokenId(), "0", new JsonValue("Token Updated")); handler.handleResult(resource); } catch (CoreTokenException e) { 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 updateInstance(ServerContext serverContext, String tokenId, UpdateRequest updateRequest, ResultHandler<Resource> handler) { JsonValue value = updateRequest.getNewContent(); String jsonText = value.getObject().toString(); Token newToken = serialisation.deserialise(jsonText, Token.class); try { store.update(newToken); Resource resource = new Resource(newToken.getTokenId(), "0", new JsonValue("Token Updated")); handler.handleResult(resource); } catch (CoreTokenException e) { 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);  }