ConsulRawClient(HttpTransport httpTransport, String agentHost, int agentPort, String path) { this.httpTransport = httpTransport; // check that agentHost has scheme or not String agentHostLowercase = agentHost.toLowerCase(); if (!agentHostLowercase.startsWith("https://") && !agentHostLowercase.startsWith("http://")) { // no scheme in host, use default 'http' agentHost = "http://" + agentHost; } this.agentAddress = Utils.assembleAgentAddress(agentHost, agentPort, path); }
ConsulRawClient(HttpTransport httpTransport, String agentHost, int agentPort, String path) { this.httpTransport = httpTransport; // check that agentHost has scheme or not String agentHostLowercase = agentHost.toLowerCase(); if (!agentHostLowercase.startsWith("https://") && !agentHostLowercase.startsWith("http://")) { // no scheme in host, use default 'http' agentHost = "http://" + agentHost; } this.agentAddress = Utils.assembleAgentAddress(agentHost, agentPort, path); }
@Test public void testAssembleAgentAddressWithoutPath() { // Given String expectedHost = "https://host"; int expectedPort = 8888; // When String actualAddress = Utils.assembleAgentAddress(expectedHost, expectedPort, null); // Then assertEquals( String.format("%s:%d", expectedHost, expectedPort), actualAddress ); } }
@Test public void testAssembleAgentAddressWithPath() { // Given String expectedHost = "http://host"; int expectedPort = 8888; String expectedPath = "path"; // When String actualAddress = Utils.assembleAgentAddress(expectedHost, expectedPort, expectedPath); // Then assertEquals( String.format("%s:%d/%s", expectedHost, expectedPort, expectedPath), actualAddress ); }
@Test public void testAssembleAgentAddressWithEmptyPath() { // Given String expectedHost = "http://host"; int expectedPort = 8888; String expectedPath = " "; // When String actualAddress = Utils.assembleAgentAddress(expectedHost, expectedPort, expectedPath); // Then assertEquals( String.format("%s:%d", expectedHost, expectedPort), actualAddress ); }