@Test public void getByName_shouldReturnServer_whenClientReturnsNotUniqueResult() throws Exception { when(responseMock.readEntity(ServerList.class)).thenReturn(new ServerList(asList( Server.builder().name("server").build(), Server.builder().name("server1").build() ))); Optional<Server> serverOptional = testee.getByName("server"); assertThat(serverOptional).isNotEmpty(); }
@Override public Optional<Server> getByName(String serverName) { String serverNameEncoded = UriComponent.encode(serverName, QUERY_PARAM_SPACE_ENCODED); Invocation.Builder builder = client .target(SERVERS_URL) .queryParam("filter[name]", serverNameEncoded) .request(APPLICATION_JSON_TYPE); return getPageable(builder, ServerList.class) .filter(application -> application.getName().equals(serverName)) .getSingle(); }
DefaultServersApi extends ApiBase implements ServersApi { @Override public Optional<Server> getByName(String serverName) { String serverNameEncoded = UriComponent.encode(serverName, QUERY_PARAM_SPACE_ENCODED); Invocation.Builder builder = client .target(SERVERS_URL) .queryParam("filter[name]", serverNameEncoded) .request(APPLICATION_JSON_TYPE); return getPageable(builder, ServerList.class) .filter(application -> application.getName().equals(serverName)) .getSingle(); } }
DefaultServersApi extends ApiBase implements ServersApi { @Override public Optional<Server> getByName(String serverName) { String serverNameEncoded = UriComponent.encode(serverName, QUERY_PARAM_SPACE_ENCODED); Invocation.Builder builder = client .target(SERVERS_URL) .queryParam("filter[name]", serverNameEncoded) .request(APPLICATION_JSON_TYPE); return getPageable(builder, ServerList.class) .filter(application -> application.getName().equals(serverName)) .getSingle(); } DefaultServersApi(NewRelicClient client); }
DefaultServersApi extends ApiBase implements ServersApi { @Override public Optional<Server> getByName(String serverName) { String serverNameEncoded = UriComponent.encode(serverName, QUERY_PARAM_SPACE_ENCODED); Invocation.Builder builder = client .target(SERVERS_URL) .queryParam("filter[name]", serverNameEncoded) .request(APPLICATION_JSON_TYPE); return getPageable(builder, ServerList.class) .filter(application -> application.getName().equals(serverName)) .getSingle(); } DefaultServersApi(NewRelicClient client); @Override Optional<Server> getByName(String serverName); @Override Server getById(int serverId); }
DefaultServersApi extends ApiBase implements ServersApi { @Override public Optional<Server> getByName(String serverName) { String serverNameEncoded = UriComponent.encode(serverName, QUERY_PARAM_SPACE_ENCODED); Invocation.Builder builder = client .target(SERVERS_URL) .queryParam("filter[name]", serverNameEncoded) .request(APPLICATION_JSON_TYPE); return getPageable(builder, ServerList.class) .filter(application -> application.getName().equals(serverName)) .getSingle(); } DefaultServersApi(NewRelicClient client); @Override Optional<Server> getByName(String serverName); @Override Server getById(int serverId);  }