public void testRedirectUrlWithParam() { final String loginUrl = "http://localhost:8080/login?myName=foo"; final String fullyConstructedUrl = CommonUtils.constructRedirectUrl(loginUrl, "foo", "foo", false, false); int count = 0; final char[] chars = fullyConstructedUrl.toCharArray(); for (int i = 0; i < chars.length; i++) { if (chars[i] == '?') { count++; } } assertEquals(1, count); }
public void testIsBlank() { assertFalse(CommonUtils.isBlank("test")); assertFalse(CommonUtils.isBlank(" test")); assertTrue(CommonUtils.isBlank("")); assertTrue(CommonUtils.isBlank(null)); assertTrue(CommonUtils.isBlank(" ")); }
public void testConstructUrlNonStandardPortAndNoScheme() { constructUrlNonStandardPortAndNoPortInConfigTest("www.myserver.com"); }
public void testUrlEncode() { assertEquals("this+is+a+very+special+parameter+with+%3D%25%2F", CommonUtils.urlEncode("this is a very special parameter with =%/")); }
public void testIsNotBlank() { assertTrue(CommonUtils.isNotBlank("test")); assertTrue(CommonUtils.isNotBlank(" test")); assertFalse(CommonUtils.isNotBlank("")); assertFalse(CommonUtils.isNotBlank(null)); assertFalse(CommonUtils.isNotBlank(" ")); }
public void testConstructUrlNonStandardPortAndScheme() { constructUrlNonStandardPortAndNoPortInConfigTest("https://www.myserver.com"); }
public void testAssertNotNull() { final String CONST_MESSAGE = "test"; CommonUtils.assertNotNull(new Object(), CONST_MESSAGE); try { CommonUtils.assertNotNull(null, CONST_MESSAGE); } catch (IllegalArgumentException e) { assertEquals(CONST_MESSAGE, e.getMessage()); } }
public void testIsEmpty() { assertFalse(CommonUtils.isEmpty("test")); assertFalse(CommonUtils.isEmpty(" test")); assertTrue(CommonUtils.isEmpty("")); assertTrue(CommonUtils.isEmpty(null)); assertFalse(CommonUtils.isEmpty(" ")); }
public void testGetResponseFromServer() throws Exception { final String RESPONSE = "test1\r\ntest2"; server.content = RESPONSE.getBytes(server.encoding); final String responsedContent = CommonUtils.getResponseFromServer(new URL("http://localhost:8092"), new HttpsURLConnectionFactory(), null); assertEquals(RESPONSE, responsedContent); }
public void testIsNotEmpty() { assertTrue(CommonUtils.isNotEmpty("test")); assertTrue(CommonUtils.isNotEmpty(" test")); assertFalse(CommonUtils.isNotEmpty("")); assertFalse(CommonUtils.isNotEmpty(null)); assertTrue(CommonUtils.isNotEmpty(" ")); }
public void testAssertNotEmpty() { final String CONST_MESSAGE = "test"; final Collection<Object> c = new ArrayList<Object>(); c.add(new Object()); CommonUtils.assertNotEmpty(c, CONST_MESSAGE); try { CommonUtils.assertNotEmpty(new ArrayList<Object>(), CONST_MESSAGE); } catch (IllegalArgumentException e) { assertEquals(CONST_MESSAGE, e.getMessage()); } try { CommonUtils.assertNotEmpty(null, CONST_MESSAGE); } catch (IllegalArgumentException e) { assertEquals(CONST_MESSAGE, e.getMessage()); } }
public void testAssertTrue() { final String CONST_MESSAGE = "test"; CommonUtils.assertTrue(true, CONST_MESSAGE); try { CommonUtils.assertTrue(false, CONST_MESSAGE); } catch (IllegalArgumentException e) { assertEquals(CONST_MESSAGE, e.getMessage()); } }
public void testConstructServiceUrlWithTrailingSlash() { final String CONST_MY_URL = "https://www.myserver.com/hello/hithere/"; final MockHttpServletRequest request = new MockHttpServletRequest("GET", "/hello/hithere/"); request.setScheme("https"); request.setSecure(true); final MockHttpServletResponse response = new MockHttpServletResponse(); final String constructedUrl = CommonUtils.constructServiceUrl(request, response, null, "www.myserver.com", "service", "ticket", false); assertEquals(CONST_MY_URL, constructedUrl); }
public void testConstructURlWithMultipleHostsAndPorts() { final String CONST_MY_URL = "https://www.myserver.com/hello/hithere/"; final MockHttpServletRequest request = new MockHttpServletRequest("GET", "/hello/hithere/"); request.addHeader("Host", "www.myserver.com"); request.setScheme("https"); request.setSecure(true); final MockHttpServletResponse response = new MockHttpServletResponse(); final String constructedUrl = CommonUtils.constructServiceUrl(request, response, null, "http://www.amazon.com https://www.bestbuy.com https://www.myserver.com", "service", "ticket", false); assertEquals(CONST_MY_URL, constructedUrl); }
public void testConstructUrlWithMultipleHostsNoPortsOrProtocol() { final String CONST_MY_URL = "https://www.myserver.com/hello/hithere/"; final MockHttpServletRequest request = new MockHttpServletRequest("GET", "/hello/hithere/"); request.addHeader("Host", "www.myserver.com"); request.setScheme("https"); request.setSecure(true); final MockHttpServletResponse response = new MockHttpServletResponse(); final String constructedUrl = CommonUtils.constructServiceUrl(request, response, null, "www.amazon.com www.bestbuy.com www.myserver.com", "service", "ticket", false); assertEquals(CONST_MY_URL, constructedUrl); }
public void testConstructServiceUrlWithServerNameContainingPath() { final MockHttpServletRequest request = new MockHttpServletRequest("GET", "/hello/hithere/"); request.setScheme("https"); request.setSecure(true); final MockHttpServletResponse response = new MockHttpServletResponse(); final String constructedUrl = CommonUtils.constructServiceUrl(request, response, null, "www.my.server.com/app", Protocol.CAS3.getServiceParameterName(), Protocol.CAS3.getArtifactParameterName(), false); assertEquals("https://www.my.server.com/app/hello/hithere/", constructedUrl); }
public void testConstructServiceUrlWithNoServiceParametersPassed() { final String CONST_MY_URL = "https://www.myserver.com/hello/hithere/"; final MockHttpServletRequest request = new MockHttpServletRequest("GET", "/hello/hithere/"); request.setScheme("https"); request.setSecure(true); request.setQueryString("TARGET=Test1&service=Test2&custom=custom"); final MockHttpServletResponse response = new MockHttpServletResponse(); final String constructedUrl = CommonUtils.constructServiceUrl(request, response, null, "www.myserver.com", Protocol.SAML11.getArtifactParameterName(), true); assertEquals("https://www.myserver.com/hello/hithere/?custom=custom", constructedUrl); }
public void testConstructServiceUrlWithServerNameContainingPathAndSchema() { final MockHttpServletRequest request = new MockHttpServletRequest("GET", "/hello/hithere/"); request.setScheme("https"); request.setSecure(true); final MockHttpServletResponse response = new MockHttpServletResponse(); final String constructedUrl = CommonUtils.constructServiceUrl(request, response, null, "https://www.my.server.com/app", Protocol.CAS3.getServiceParameterName(), Protocol.CAS3.getArtifactParameterName(), false); assertEquals("https://www.my.server.com/app/hello/hithere/", constructedUrl); }
private void constructUrlNonStandardPortAndNoPortInConfigTest(final String serverNameList) { final String CONST_MY_URL = "https://www.myserver.com:555/hello/hithere/"; final MockHttpServletRequest request = new MockHttpServletRequest("GET", "/hello/hithere/"); request.addHeader("Host", "www.myserver.com"); request.setScheme("https"); request.setSecure(true); request.setServerPort(555); final MockHttpServletResponse response = new MockHttpServletResponse(); final String constructedUrl = CommonUtils.constructServiceUrl(request, response, null, serverNameList, "service", "ticket", false); assertEquals(CONST_MY_URL, constructedUrl); }
public void testUrlEncodeWithQueryParameters() { final MockHttpServletRequest request = new MockHttpServletRequest("GET", "/idp/authN/ExtCas"); request.setQueryString("conversation=e1s1&ticket=ST-1234-123456789-a&entityId=https://test.edu/sp?alias=1234-1234-1234-1234&something=else"); request.addHeader("Host", "www.myserver.com"); request.setScheme("https"); request.setSecure(true); final MockHttpServletResponse response = new MockHttpServletResponse(); final String constructedUrl = CommonUtils.constructServiceUrl(request, response, null, "https://my.server.com", "service", "ticket", false); assertEquals("https://my.server.com/idp/authN/ExtCas?conversation=e1s1&entityId=https://test.edu/sp?alias=1234-1234-1234-1234&something=else", constructedUrl); } }