FederationServer { public FederationResponse resolveAddress(String address) { String[] tokens = address.split("\\*"); if (tokens.length != 2) { throw new MalformedAddressException(); } URL uri = HttpUrl.parse(serverUri.toString()).newBuilder() .addQueryParameter("type", "name") .addQueryParameter("q", address) .build().url(); TypeToken type = new TypeToken<FederationResponse>() { }; ResponseHandler<FederationResponse> responseHandler = new ResponseHandler<FederationResponse>(httpClient, type); Request request = new Request.Builder() .url(uri.toString()) .get() .build(); try { Response response = httpClient.newCall(request) .execute(); return responseHandler.handleResponse(response); } catch (HttpResponseException e) { if (e.getStatusCode() == 404) { throw new NotFoundException(); } else { throw new ServerErrorException(); } } catch (IOException e) { throw new ConnectionErrorException(); } } FederationServer(URL serverUri, String domain);  FederationServer(String serverUri, String domain); static FederationServer createForDomain(String domain); FederationResponse resolveAddress(String address); URL getServerUri(); String getDomain();  }
@Test public void testNameFederationSuccess() throws IOException { mockWebServer.enqueue( new MockResponse() .setResponseCode(200) .setBody(successResponse) ); FederationResponse response = server.resolveAddress("bob*stellar.org"); assertEquals(response.getStellarAddress(), "bob*stellar.org"); assertEquals(response.getAccountId(), "GCW667JUHCOP5Y7KY6KGDHNPHFM4CS3FCBQ7QWDUALXTX3PGXLSOEALY"); assertNull(response.getMemoType()); assertNull(response.getMemo()); }
@Test public void testNameFederationSuccessWithMemo() throws IOException { mockWebServer.enqueue( new MockResponse() .setResponseCode(200) .setBody(successResponseWithMemo) ); FederationResponse response = server.resolveAddress("bob*stellar.org"); assertEquals(response.getStellarAddress(), "bob*stellar.org"); assertEquals(response.getAccountId(), "GCW667JUHCOP5Y7KY6KGDHNPHFM4CS3FCBQ7QWDUALXTX3PGXLSOEALY"); assertEquals(response.getMemoType(), "text"); assertEquals(response.getMemo(), "test"); }
@Test public void testNameFederationNotFound() throws IOException { mockWebServer.enqueue( new MockResponse() .setResponseCode(404) .setBody(notFoundResponse) ); try { FederationResponse response = server.resolveAddress("bob*stellar.org"); fail("Expected exception"); } catch (NotFoundException e) { } }