### Question:
SSOUtils { public static Optional<String> constructApplicationServerURL(Request request) { if (request == null) { return Optional.empty(); } String sslConnectorScheme = "https"; StringBuilder appServerURL = new StringBuilder(sslConnectorScheme + ": String requestHost = request.getHost().getName(); Optional<Connector> sslConnector = Arrays.stream(((Engine) request.getHost().getParent()).getService().findConnectors()) .filter(connector -> connector.getScheme().equals(sslConnectorScheme)) .findFirst(); if (sslConnector.isPresent()) { return Optional.of(appServerURL.append(requestHost).append(":") .append(sslConnector.get().getPort()).toString()); } else { return Optional.empty(); } } private  SSOUtils(); static String createID(); static Optional<String> constructApplicationServerURL(Request request); static Map<String, String[]> getSplitQueryParameters(String queryParameterString); @SuppressWarnings("unchecked") static Map<String, Object> generateRelayState(Request request); static Optional<String> generateIssuerID(String contextPath, String hostAppBase); static Optional<String> generateConsumerURL(String contextPath, String acsBase, String acsPostfix); static Optional generateKeyStore(); static void sendCharacterData(HttpServletResponse response, String htmlPayload); static void doBootstrap(); static RequestAbstractType setSignature(RequestAbstractType request, String signatureAlgorithm,
                                                   X509Credential credential); static String encodeRequestMessage(RequestAbstractType requestMessage, String binding); static String marshall(XMLObject xmlObject); static Optional<XMLObject> unmarshall(String xmlString); static Assertion decryptAssertion(SSOX509Credential ssoAgentX509Credential,
                                             EncryptedAssertion encryptedAssertion); static Map<String, List<String>> getAssertionStatements(Assertion assertion); static void addDeflateSignatureToHTTPQueryString(StringBuilder httpQueryString, X509Credential credential);  }### Answer:
@Test(description = "Tests the construction of Application Server URL for a sample request") public void testConstructionOfApplicationServerURL() { Request request = new Request(); Connector connector = new Connector(); connector.setProtocol(TestConstants.SSL_PROTOCOL); connector.setPort(TestConstants.SSL_PORT); connector.setScheme(TestConstants.SSL_PROTOCOL); Engine engine = new StandardEngine(); Service service = new StandardService(); engine.setService(service); engine.getService().addConnector(connector); Host host = new StandardHost(); host.setName(TestConstants.DEFAULT_TOMCAT_HOST); request.getMappingData().host = host; host.setParent(engine); Optional<String> actual = SSOUtils.constructApplicationServerURL(request); if (actual.isPresent()) { Assert.assertEquals(actual.get(), TestConstants.DEFAULT_APPLICATION_SERVER_URL); } else { Assert.fail(); } }
@Test(description = "Tests the construction of Application Server URL for an invalid 'null' request") public void testConstructionOfApplicationServerURLFromInvalidRequest() { Optional<String> actual = SSOUtils.constructApplicationServerURL(null); Assert.assertTrue(!actual.isPresent()); }
@Test(description = "Tests the construction of Application Server URL for no SSL/TLS Connector") public void testConstructionOfApplicationServerURLWithNoConnector() { Request request = new Request(); Engine engine = new StandardEngine(); Service service = new StandardService(); engine.setService(service); Host host = new StandardHost(); host.setName(TestConstants.DEFAULT_TOMCAT_HOST); request.getMappingData().host = host; host.setParent(engine); Optional<String> actual = SSOUtils.constructApplicationServerURL(request); Assert.assertTrue(!actual.isPresent()); }