@Test public void testCreateTokenBadResponse() throws BaseException { final Response mockedResponse = new Response(500, "", "fjkdlsfd"); new Expectations() {{ serviceBase.sendRequest((Request) any); result = mockedResponse; }}; RequestContext requestContext = new RequestContext(); requestContext.setBaseUrl("fakeBaseUrl"); TokenService tokenService = new TokenService(requestContext); try { Token token = new Token(); Token tokenGenerated = tokenService.createToken(token); Assert.assertNull(tokenGenerated); } catch (BaseException e) { Assert.fail("Unexpected BaseException thrown " + e.getMessage()); } }
public Token createToken(Token token) throws BaseException { logger.debug("Enter TokenService::createToken"); String apiUrl = requestContext.getBaseUrl() + "tokens"; logger.info("apiUrl - " + apiUrl); TypeReference<Token> typeReference = new TypeReference<Token>() { }; Request request = new Request.RequestBuilder(MethodType.POST, apiUrl).ignoreAuthHeader(true) .requestObject(token).typeReference(typeReference).context(requestContext).build(); Response response = sendRequest(request); Token tokenResponse = (Token) response.getResponseObject(); prepareResponse(request, response, tokenResponse); return tokenResponse; }
TokenService extends ServiceBase { public Token createToken(Token token) throws BaseException { logger.debug("Enter TokenService::createToken"); String apiUrl = requestContext.getBaseUrl() + "tokens"; logger.info("apiUrl - " + apiUrl); TypeReference<Token> typeReference = new TypeReference<Token>() { }; Request request = new Request.RequestBuilder(MethodType.POST, apiUrl).ignoreAuthHeader(true) .requestObject(token).typeReference(typeReference).context(requestContext).build(); Response response = sendRequest(request); Token tokenResponse = (Token) response.getResponseObject(); prepareResponse(request, response, tokenResponse); return tokenResponse; } }
TokenService extends ServiceBase { public Token createToken(Token token) throws BaseException { logger.debug("Enter TokenService::createToken"); String apiUrl = requestContext.getBaseUrl() + "tokens"; logger.info("apiUrl - " + apiUrl); TypeReference<Token> typeReference = new TypeReference<Token>() { }; Request request = new Request.RequestBuilder(MethodType.POST, apiUrl).ignoreAuthHeader(true) .requestObject(token).typeReference(typeReference).context(requestContext).build(); Response response = sendRequest(request); Token tokenResponse = (Token) response.getResponseObject(); prepareResponse(request, response, tokenResponse); return tokenResponse; } TokenService(RequestContext requestContext); protected  TokenService(); }
TokenService extends ServiceBase { public Token createToken(Token token) throws BaseException { logger.debug("Enter TokenService::createToken"); String apiUrl = requestContext.getBaseUrl() + "tokens"; logger.info("apiUrl - " + apiUrl); TypeReference<Token> typeReference = new TypeReference<Token>() { }; Request request = new Request.RequestBuilder(MethodType.POST, apiUrl).ignoreAuthHeader(true) .requestObject(token).typeReference(typeReference).context(requestContext).build(); Response response = sendRequest(request); Token tokenResponse = (Token) response.getResponseObject(); prepareResponse(request, response, tokenResponse); return tokenResponse; } TokenService(RequestContext requestContext); protected  TokenService(); RequestContext getRequestContext(); void setRequestContext(RequestContext requestContext); Token createToken(Token token); }
TokenService extends ServiceBase { public Token createToken(Token token) throws BaseException { logger.debug("Enter TokenService::createToken"); String apiUrl = requestContext.getBaseUrl() + "tokens"; logger.info("apiUrl - " + apiUrl); TypeReference<Token> typeReference = new TypeReference<Token>() { }; Request request = new Request.RequestBuilder(MethodType.POST, apiUrl).ignoreAuthHeader(true) .requestObject(token).typeReference(typeReference).context(requestContext).build(); Response response = sendRequest(request); Token tokenResponse = (Token) response.getResponseObject(); prepareResponse(request, response, tokenResponse); return tokenResponse; } TokenService(RequestContext requestContext); protected  TokenService(); RequestContext getRequestContext(); void setRequestContext(RequestContext requestContext); Token createToken(Token token);  }