@Test(expected = InvalidArgumentsException.class) public void testGetAggregatorListInvalidArguments() throws InvalidArgumentsException { Mockito.when(response.getStatus()).thenReturn(400); Mockito.when(response.readEntity(Result.class)).thenReturn(new Result("Invalid argument!")); aa.getAggregatorList(0, 1); }
public List<Aggregator> getAggregatorList(int offset, int number) throws InvalidArgumentsException { WebTarget target = client.target(restUrl + "/" + AggregatorOptionListContainer.AGGREGATORS) .queryParam(AggregatorOptionListContainer.OFFSET, offset) .queryParam(AggregatorOptionListContainer.NUMBER, number); Response response = target.request(MediaType.APPLICATION_JSON).get(); if (response.getStatus() == 400) { Result errorMessage = response.readEntity(Result.class); LOGGER.warn("getAggregatorList(..) failure! : " + errorMessage.getResult()); throw new InvalidArgumentsException(errorMessage.getResult()); } List<Aggregator> subList = response.readEntity(new GenericType<List<Aggregator>>() {}); LOGGER.info("getAggregatorList(..) success!"); return subList; }
AggregatorsAccessor { public List<Aggregator> getAggregatorList(int offset, int number) throws InvalidArgumentsException { WebTarget target = client.target(restUrl + "/" + AggregatorOptionListContainer.AGGREGATORS) .queryParam(AggregatorOptionListContainer.OFFSET, offset) .queryParam(AggregatorOptionListContainer.NUMBER, number); Response response = target.request(MediaType.APPLICATION_JSON).get(); if (response.getStatus() == 400) { Result errorMessage = response.readEntity(Result.class); LOGGER.warn("getAggregatorList(..) failure! : " + errorMessage.getResult()); throw new InvalidArgumentsException(errorMessage.getResult()); } List<Aggregator> subList = response.readEntity(new GenericType<List<Aggregator>>() {}); LOGGER.info("getAggregatorList(..) success!"); return subList; } }
AggregatorsAccessor { public List<Aggregator> getAggregatorList(int offset, int number) throws InvalidArgumentsException { WebTarget target = client.target(restUrl + "/" + AggregatorOptionListContainer.AGGREGATORS) .queryParam(AggregatorOptionListContainer.OFFSET, offset) .queryParam(AggregatorOptionListContainer.NUMBER, number); Response response = target.request(MediaType.APPLICATION_JSON).get(); if (response.getStatus() == 400) { Result errorMessage = response.readEntity(Result.class); LOGGER.warn("getAggregatorList(..) failure! : " + errorMessage.getResult()); throw new InvalidArgumentsException(errorMessage.getResult()); } List<Aggregator> subList = response.readEntity(new GenericType<List<Aggregator>>() {}); LOGGER.info("getAggregatorList(..) success!"); return subList; } AggregatorsAccessor(URL restUrl, String username, String password);   AggregatorsAccessor(URL restUrl, String username, String password, Client client); }
AggregatorsAccessor { public List<Aggregator> getAggregatorList(int offset, int number) throws InvalidArgumentsException { WebTarget target = client.target(restUrl + "/" + AggregatorOptionListContainer.AGGREGATORS) .queryParam(AggregatorOptionListContainer.OFFSET, offset) .queryParam(AggregatorOptionListContainer.NUMBER, number); Response response = target.request(MediaType.APPLICATION_JSON).get(); if (response.getStatus() == 400) { Result errorMessage = response.readEntity(Result.class); LOGGER.warn("getAggregatorList(..) failure! : " + errorMessage.getResult()); throw new InvalidArgumentsException(errorMessage.getResult()); } List<Aggregator> subList = response.readEntity(new GenericType<List<Aggregator>>() {}); LOGGER.info("getAggregatorList(..) success!"); return subList; } AggregatorsAccessor(URL restUrl, String username, String password);   AggregatorsAccessor(URL restUrl, String username, String password, Client client); Aggregator getAggregator(String aggregatorId); void deleteAggregator(String aggregatorId); List<Aggregator> getAggregatorList(int offset, int number); void createAggregator(String id, String name, String nameCode, String homepage); void updateAggregator(String id, String newId, String name, String nameCode,
      String homepage); URL getRestUrl(); void setRestUrl(URL restUrl); }
AggregatorsAccessor { public List<Aggregator> getAggregatorList(int offset, int number) throws InvalidArgumentsException { WebTarget target = client.target(restUrl + "/" + AggregatorOptionListContainer.AGGREGATORS) .queryParam(AggregatorOptionListContainer.OFFSET, offset) .queryParam(AggregatorOptionListContainer.NUMBER, number); Response response = target.request(MediaType.APPLICATION_JSON).get(); if (response.getStatus() == 400) { Result errorMessage = response.readEntity(Result.class); LOGGER.warn("getAggregatorList(..) failure! : " + errorMessage.getResult()); throw new InvalidArgumentsException(errorMessage.getResult()); } List<Aggregator> subList = response.readEntity(new GenericType<List<Aggregator>>() {}); LOGGER.info("getAggregatorList(..) success!"); return subList; } AggregatorsAccessor(URL restUrl, String username, String password);   AggregatorsAccessor(URL restUrl, String username, String password, Client client); Aggregator getAggregator(String aggregatorId); void deleteAggregator(String aggregatorId); List<Aggregator> getAggregatorList(int offset, int number); void createAggregator(String id, String name, String nameCode, String homepage); void updateAggregator(String id, String newId, String name, String nameCode,
      String homepage); URL getRestUrl(); void setRestUrl(URL restUrl);  }