@Test public void testCreateForDomain() throws IOException { OkHttpClient mockClient = mock(OkHttpClient.class); FederationServer.setHttpClient(mockClient); Call mockCall = mock(Call.class); when(mockClient.newCall((Request) any())).thenReturn(mockCall); Response mockResponseSuccess = new Response.Builder() .code(200) .message("OK") .protocol(Protocol.HTTP_1_1) .body(ResponseBody.create(MediaType.parse("application/json"), stellarToml)) .request(new Request.Builder() .url("http: .get() .build()) .build(); when(mockCall.execute()).thenReturn(mockResponseSuccess); FederationServer server = FederationServer.createForDomain("stellar.org"); assertEquals(server.getServerUri().toString(), "https: assertEquals(server.getDomain(), "stellar.org"); ArgumentCaptor<Request> argument = ArgumentCaptor.forClass(Request.class); verify(mockClient).newCall(argument.capture()); assertEquals(URI.create("https: }
public static FederationServer createForDomain(String domain) { URI stellarTomlUri; try { StringBuilder uriBuilder = new StringBuilder(); uriBuilder.append("https: uriBuilder.append(domain); uriBuilder.append("/.well-known/stellar.toml"); stellarTomlUri = new URI(uriBuilder.toString()); } catch (URISyntaxException e) { throw new RuntimeException(e); } Toml stellarToml = null; try { Request request = new Request.Builder().get() .url(stellarTomlUri.toString()) .build(); Response response = httpClient.newCall(request) .execute(); if (response.code() >= 300) { throw new StellarTomlNotFoundInvalidException(); } ResponseBody body = response.body(); if (body == null) { throw new StellarTomlNotFoundInvalidException(); } stellarToml = new Toml().read(body.string()); } catch (IOException e) { throw new ConnectionErrorException(); } String federationServer = stellarToml.getString("FEDERATION_SERVER"); if (federationServer == null) { throw new NoFederationServerException(); } return new FederationServer(federationServer, domain); }
FederationServer { public static FederationServer createForDomain(String domain) { URI stellarTomlUri; try { StringBuilder uriBuilder = new StringBuilder(); uriBuilder.append("https: uriBuilder.append(domain); uriBuilder.append("/.well-known/stellar.toml"); stellarTomlUri = new URI(uriBuilder.toString()); } catch (URISyntaxException e) { throw new RuntimeException(e); } Toml stellarToml = null; try { Request request = new Request.Builder().get() .url(stellarTomlUri.toString()) .build(); Response response = httpClient.newCall(request) .execute(); if (response.code() >= 300) { throw new StellarTomlNotFoundInvalidException(); } ResponseBody body = response.body(); if (body == null) { throw new StellarTomlNotFoundInvalidException(); } stellarToml = new Toml().read(body.string()); } catch (IOException e) { throw new ConnectionErrorException(); } String federationServer = stellarToml.getString("FEDERATION_SERVER"); if (federationServer == null) { throw new NoFederationServerException(); } return new FederationServer(federationServer, domain); } }
FederationServer { public static FederationServer createForDomain(String domain) { URI stellarTomlUri; try { StringBuilder uriBuilder = new StringBuilder(); uriBuilder.append("https: uriBuilder.append(domain); uriBuilder.append("/.well-known/stellar.toml"); stellarTomlUri = new URI(uriBuilder.toString()); } catch (URISyntaxException e) { throw new RuntimeException(e); } Toml stellarToml = null; try { Request request = new Request.Builder().get() .url(stellarTomlUri.toString()) .build(); Response response = httpClient.newCall(request) .execute(); if (response.code() >= 300) { throw new StellarTomlNotFoundInvalidException(); } ResponseBody body = response.body(); if (body == null) { throw new StellarTomlNotFoundInvalidException(); } stellarToml = new Toml().read(body.string()); } catch (IOException e) { throw new ConnectionErrorException(); } String federationServer = stellarToml.getString("FEDERATION_SERVER"); if (federationServer == null) { throw new NoFederationServerException(); } return new FederationServer(federationServer, domain); } FederationServer(URL serverUri, String domain);  FederationServer(String serverUri, String domain); }
FederationServer { public static FederationServer createForDomain(String domain) { URI stellarTomlUri; try { StringBuilder uriBuilder = new StringBuilder(); uriBuilder.append("https: uriBuilder.append(domain); uriBuilder.append("/.well-known/stellar.toml"); stellarTomlUri = new URI(uriBuilder.toString()); } catch (URISyntaxException e) { throw new RuntimeException(e); } Toml stellarToml = null; try { Request request = new Request.Builder().get() .url(stellarTomlUri.toString()) .build(); Response response = httpClient.newCall(request) .execute(); if (response.code() >= 300) { throw new StellarTomlNotFoundInvalidException(); } ResponseBody body = response.body(); if (body == null) { throw new StellarTomlNotFoundInvalidException(); } stellarToml = new Toml().read(body.string()); } catch (IOException e) { throw new ConnectionErrorException(); } String federationServer = stellarToml.getString("FEDERATION_SERVER"); if (federationServer == null) { throw new NoFederationServerException(); } return new FederationServer(federationServer, domain); } FederationServer(URL serverUri, String domain);  FederationServer(String serverUri, String domain); static FederationServer createForDomain(String domain); FederationResponse resolveAddress(String address); URL getServerUri(); String getDomain(); }
FederationServer { public static FederationServer createForDomain(String domain) { URI stellarTomlUri; try { StringBuilder uriBuilder = new StringBuilder(); uriBuilder.append("https: uriBuilder.append(domain); uriBuilder.append("/.well-known/stellar.toml"); stellarTomlUri = new URI(uriBuilder.toString()); } catch (URISyntaxException e) { throw new RuntimeException(e); } Toml stellarToml = null; try { Request request = new Request.Builder().get() .url(stellarTomlUri.toString()) .build(); Response response = httpClient.newCall(request) .execute(); if (response.code() >= 300) { throw new StellarTomlNotFoundInvalidException(); } ResponseBody body = response.body(); if (body == null) { throw new StellarTomlNotFoundInvalidException(); } stellarToml = new Toml().read(body.string()); } catch (IOException e) { throw new ConnectionErrorException(); } String federationServer = stellarToml.getString("FEDERATION_SERVER"); if (federationServer == null) { throw new NoFederationServerException(); } return new FederationServer(federationServer, domain); } FederationServer(URL serverUri, String domain);  FederationServer(String serverUri, String domain); static FederationServer createForDomain(String domain); FederationResponse resolveAddress(String address); URL getServerUri(); String getDomain();  }