@Test public void shouldUseDeserialisedTokenToCreate() throws CoreTokenException { Token token = mock(Token.class); CTSPersistentStore store = mock(CTSPersistentStore.class); JSONSerialisation serialisation = mock(JSONSerialisation.class); given(serialisation.deserialise(anyString(), Matchers.<Class<Object>>any())).willReturn(token); CoreTokenResource resource = new CoreTokenResource(serialisation, store); CreateRequest request = mock(CreateRequest.class); given(request.getContent()).willReturn(new JsonValue("")); resource.createInstance(null, request, mock(ResultHandler.class)); verify(store).create(token); }
public void createInstance(ServerContext serverContext, CreateRequest createRequest, ResultHandler<Resource> handler) { String json = createRequest.getContent().toString(); Token token = serialisation.deserialise(json, Token.class); try { store.create(token); Map<String, String> result = new HashMap<String, String>(); result.put(TOKEN_ID, token.getTokenId()); Resource resource = new Resource(token.getTokenId(), "0", new JsonValue(result)); handler.handleResult(resource); } catch (CoreTokenException e) { handler.handleError(generateException(e)); } }
CoreTokenResource implements CollectionResourceProvider { public void createInstance(ServerContext serverContext, CreateRequest createRequest, ResultHandler<Resource> handler) { String json = createRequest.getContent().toString(); Token token = serialisation.deserialise(json, Token.class); try { store.create(token); Map<String, String> result = new HashMap<String, String>(); result.put(TOKEN_ID, token.getTokenId()); Resource resource = new Resource(token.getTokenId(), "0", new JsonValue(result)); handler.handleResult(resource); } catch (CoreTokenException e) { handler.handleError(generateException(e)); } } }
CoreTokenResource implements CollectionResourceProvider { public void createInstance(ServerContext serverContext, CreateRequest createRequest, ResultHandler<Resource> handler) { String json = createRequest.getContent().toString(); Token token = serialisation.deserialise(json, Token.class); try { store.create(token); Map<String, String> result = new HashMap<String, String>(); result.put(TOKEN_ID, token.getTokenId()); Resource resource = new Resource(token.getTokenId(), "0", new JsonValue(result)); handler.handleResult(resource); } catch (CoreTokenException e) { handler.handleError(generateException(e)); } } CoreTokenResource(JSONSerialisation serialisation, CTSPersistentStore store); }
CoreTokenResource implements CollectionResourceProvider { public void createInstance(ServerContext serverContext, CreateRequest createRequest, ResultHandler<Resource> handler) { String json = createRequest.getContent().toString(); Token token = serialisation.deserialise(json, Token.class); try { store.create(token); Map<String, String> result = new HashMap<String, String>(); result.put(TOKEN_ID, token.getTokenId()); Resource resource = new Resource(token.getTokenId(), "0", new JsonValue(result)); handler.handleResult(resource); } 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 createInstance(ServerContext serverContext, CreateRequest createRequest, ResultHandler<Resource> handler) { String json = createRequest.getContent().toString(); Token token = serialisation.deserialise(json, Token.class); try { store.create(token); Map<String, String> result = new HashMap<String, String>(); result.put(TOKEN_ID, token.getTokenId()); Resource resource = new Resource(token.getTokenId(), "0", new JsonValue(result)); handler.handleResult(resource); } 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);  }