diff --git a/src/test/java/com/github/wovnio/wovnjava/HeadersTest.java b/src/test/java/com/github/wovnio/wovnjava/HeadersTest.java index fb5186dc..bae1a03c 100644 --- a/src/test/java/com/github/wovnio/wovnjava/HeadersTest.java +++ b/src/test/java/com/github/wovnio/wovnjava/HeadersTest.java @@ -11,169 +11,64 @@ public class HeadersTest extends TestCase { private static FilterConfig mockConfigPath() { - FilterConfig mock = EasyMock.createMock(FilterConfig.class); - EasyMock.expect(mock.getInitParameter("userToken")).andReturn("2Wle3"); - EasyMock.expect(mock.getInitParameter("projectToken")).andReturn("2Wle3"); - EasyMock.expect(mock.getInitParameter("sitePrefixPath")).andReturn(""); - EasyMock.expect(mock.getInitParameter("secretKey")).andReturn("secret"); - EasyMock.expect(mock.getInitParameter("urlPattern")).andReturn(""); - EasyMock.expect(mock.getInitParameter("urlPatternReg")).andReturn(""); - EasyMock.expect(mock.getInitParameter("query")).andReturn(""); - EasyMock.expect(mock.getInitParameter("apiUrl")).andReturn(""); - EasyMock.expect(mock.getInitParameter("defaultLang")).andReturn(""); - EasyMock.expect(mock.getInitParameter("supportedLangs")).andReturn(""); - EasyMock.expect(mock.getInitParameter("testMode")).andReturn(""); - EasyMock.expect(mock.getInitParameter("testUrl")).andReturn(""); - EasyMock.expect(mock.getInitParameter("useProxy")).andReturn(""); - EasyMock.expect(mock.getInitParameter("debugMode")).andReturn(""); - EasyMock.expect(mock.getInitParameter("originalUrlHeader")).andReturn(""); - EasyMock.expect(mock.getInitParameter("originalQueryStringHeader")).andReturn(""); - EasyMock.expect(mock.getInitParameter("strictHtmlCheck")).andReturn(""); - EasyMock.expect(mock.getInitParameter("deleteInvalidClosingTag")).andReturn(""); - EasyMock.expect(mock.getInitParameter("deleteInvalidUTF8")).andReturn(""); - EasyMock.expect(mock.getInitParameter("connectTimeout")).andReturn(""); - EasyMock.expect(mock.getInitParameter("readTimeout")).andReturn(""); - EasyMock.replay(mock); - - return mock; + HashMap parameters = new HashMap() {{ + put("userToken", "2Wle3"); + put("projectToken", "2Wle3"); + put("secretKey", "secret"); + }}; + return TestUtil.makeConfig(parameters); } private static FilterConfig mockConfigSubdomain() { - FilterConfig mock = EasyMock.createMock(FilterConfig.class); - EasyMock.expect(mock.getInitParameter("userToken")).andReturn("2Wle3"); - EasyMock.expect(mock.getInitParameter("projectToken")).andReturn("2Wle3"); - EasyMock.expect(mock.getInitParameter("sitePrefixPath")).andReturn(""); - EasyMock.expect(mock.getInitParameter("secretKey")).andReturn("secret"); - EasyMock.expect(mock.getInitParameter("urlPattern")).andReturn("subdomain"); - EasyMock.expect(mock.getInitParameter("urlPatternReg")).andReturn(""); - EasyMock.expect(mock.getInitParameter("query")).andReturn(""); - EasyMock.expect(mock.getInitParameter("apiUrl")).andReturn(""); - EasyMock.expect(mock.getInitParameter("defaultLang")).andReturn(""); - EasyMock.expect(mock.getInitParameter("supportedLangs")).andReturn(""); - EasyMock.expect(mock.getInitParameter("testMode")).andReturn(""); - EasyMock.expect(mock.getInitParameter("testUrl")).andReturn(""); - EasyMock.expect(mock.getInitParameter("useProxy")).andReturn(""); - EasyMock.expect(mock.getInitParameter("debugMode")).andReturn(""); - EasyMock.expect(mock.getInitParameter("originalUrlHeader")).andReturn(""); - EasyMock.expect(mock.getInitParameter("originalQueryStringHeader")).andReturn(""); - EasyMock.expect(mock.getInitParameter("strictHtmlCheck")).andReturn(""); - EasyMock.expect(mock.getInitParameter("deleteInvalidClosingTag")).andReturn(""); - EasyMock.expect(mock.getInitParameter("deleteInvalidUTF8")).andReturn(""); - EasyMock.expect(mock.getInitParameter("connectTimeout")).andReturn(""); - EasyMock.expect(mock.getInitParameter("readTimeout")).andReturn(""); - EasyMock.replay(mock); - - return mock; + HashMap parameters = new HashMap() {{ + put("userToken", "2Wle3"); + put("projectToken", "2Wle3"); + put("secretKey", "secret"); + put("urlPattern", "subdomain"); + }}; + return TestUtil.makeConfig(parameters); } private static FilterConfig mockConfigQuery() { - FilterConfig mock = EasyMock.createMock(FilterConfig.class); - EasyMock.expect(mock.getInitParameter("userToken")).andReturn("2Wle3"); - EasyMock.expect(mock.getInitParameter("projectToken")).andReturn("2Wle3"); - EasyMock.expect(mock.getInitParameter("sitePrefixPath")).andReturn(""); - EasyMock.expect(mock.getInitParameter("secretKey")).andReturn("secret"); - EasyMock.expect(mock.getInitParameter("urlPattern")).andReturn("query"); - EasyMock.expect(mock.getInitParameter("urlPatternReg")).andReturn(""); - EasyMock.expect(mock.getInitParameter("query")).andReturn(""); - EasyMock.expect(mock.getInitParameter("apiUrl")).andReturn(""); - EasyMock.expect(mock.getInitParameter("defaultLang")).andReturn(""); - EasyMock.expect(mock.getInitParameter("supportedLangs")).andReturn(""); - EasyMock.expect(mock.getInitParameter("testMode")).andReturn(""); - EasyMock.expect(mock.getInitParameter("testUrl")).andReturn(""); - EasyMock.expect(mock.getInitParameter("useProxy")).andReturn(""); - EasyMock.expect(mock.getInitParameter("debugMode")).andReturn(""); - EasyMock.expect(mock.getInitParameter("originalUrlHeader")).andReturn(""); - EasyMock.expect(mock.getInitParameter("originalQueryStringHeader")).andReturn(""); - EasyMock.expect(mock.getInitParameter("strictHtmlCheck")).andReturn(""); - EasyMock.expect(mock.getInitParameter("deleteInvalidClosingTag")).andReturn(""); - EasyMock.expect(mock.getInitParameter("deleteInvalidUTF8")).andReturn(""); - EasyMock.expect(mock.getInitParameter("connectTimeout")).andReturn(""); - EasyMock.expect(mock.getInitParameter("readTimeout")).andReturn(""); - EasyMock.replay(mock); - - return mock; + HashMap parameters = new HashMap() {{ + put("userToken", "2Wle3"); + put("projectToken", "2Wle3"); + put("secretKey", "secret"); + put("urlPattern", "query"); + }}; + return TestUtil.makeConfig(parameters); } private static FilterConfig mockConfigQueryParameter() { - FilterConfig mock = EasyMock.createMock(FilterConfig.class); - EasyMock.expect(mock.getInitParameter("userToken")).andReturn("2Wle3"); - EasyMock.expect(mock.getInitParameter("projectToken")).andReturn("2Wle3"); - EasyMock.expect(mock.getInitParameter("sitePrefixPath")).andReturn(""); - EasyMock.expect(mock.getInitParameter("secretKey")).andReturn("secret"); - EasyMock.expect(mock.getInitParameter("urlPattern")).andReturn("query"); - EasyMock.expect(mock.getInitParameter("urlPatternReg")).andReturn(""); - EasyMock.expect(mock.getInitParameter("query")).andReturn("abc"); - EasyMock.expect(mock.getInitParameter("apiUrl")).andReturn(""); - EasyMock.expect(mock.getInitParameter("defaultLang")).andReturn(""); - EasyMock.expect(mock.getInitParameter("supportedLangs")).andReturn(""); - EasyMock.expect(mock.getInitParameter("testMode")).andReturn(""); - EasyMock.expect(mock.getInitParameter("testUrl")).andReturn(""); - EasyMock.expect(mock.getInitParameter("useProxy")).andReturn(""); - EasyMock.expect(mock.getInitParameter("debugMode")).andReturn(""); - EasyMock.expect(mock.getInitParameter("originalUrlHeader")).andReturn(""); - EasyMock.expect(mock.getInitParameter("originalQueryStringHeader")).andReturn(""); - EasyMock.expect(mock.getInitParameter("strictHtmlCheck")).andReturn(""); - EasyMock.expect(mock.getInitParameter("deleteInvalidClosingTag")).andReturn(""); - EasyMock.expect(mock.getInitParameter("deleteInvalidUTF8")).andReturn(""); - EasyMock.expect(mock.getInitParameter("connectTimeout")).andReturn(""); - EasyMock.expect(mock.getInitParameter("readTimeout")).andReturn(""); - EasyMock.replay(mock); - - return mock; + HashMap parameters = new HashMap() {{ + put("userToken", "2Wle3"); + put("projectToken", "2Wle3"); + put("secretKey", "secret"); + put("urlPattern", "query"); + put("query", "abc"); + }}; + return TestUtil.makeConfig(parameters); } private static FilterConfig mockConfigQueryParameterAAA() { - FilterConfig mock = EasyMock.createMock(FilterConfig.class); - EasyMock.expect(mock.getInitParameter("userToken")).andReturn("2Wle3"); - EasyMock.expect(mock.getInitParameter("projectToken")).andReturn("2Wle3"); - EasyMock.expect(mock.getInitParameter("sitePrefixPath")).andReturn(""); - EasyMock.expect(mock.getInitParameter("secretKey")).andReturn("secret"); - EasyMock.expect(mock.getInitParameter("urlPattern")).andReturn("query"); - EasyMock.expect(mock.getInitParameter("urlPatternReg")).andReturn(""); - EasyMock.expect(mock.getInitParameter("query")).andReturn("AAA"); - EasyMock.expect(mock.getInitParameter("apiUrl")).andReturn(""); - EasyMock.expect(mock.getInitParameter("defaultLang")).andReturn(""); - EasyMock.expect(mock.getInitParameter("supportedLangs")).andReturn(""); - EasyMock.expect(mock.getInitParameter("testMode")).andReturn(""); - EasyMock.expect(mock.getInitParameter("testUrl")).andReturn(""); - EasyMock.expect(mock.getInitParameter("useProxy")).andReturn(""); - EasyMock.expect(mock.getInitParameter("debugMode")).andReturn(""); - EasyMock.expect(mock.getInitParameter("originalUrlHeader")).andReturn(""); - EasyMock.expect(mock.getInitParameter("originalQueryStringHeader")).andReturn(""); - EasyMock.expect(mock.getInitParameter("strictHtmlCheck")).andReturn(""); - EasyMock.expect(mock.getInitParameter("deleteInvalidClosingTag")).andReturn(""); - EasyMock.expect(mock.getInitParameter("deleteInvalidUTF8")).andReturn(""); - EasyMock.expect(mock.getInitParameter("connectTimeout")).andReturn(""); - EasyMock.expect(mock.getInitParameter("readTimeout")).andReturn(""); - EasyMock.replay(mock); - - return mock; + HashMap parameters = new HashMap() {{ + put("userToken", "2Wle3"); + put("projectToken", "2Wle3"); + put("secretKey", "secret"); + put("urlPattern", "query"); + put("query", "AAA"); + }}; + return TestUtil.makeConfig(parameters); } private static FilterConfig mockConfigOriginalHeaders() { - FilterConfig mock = EasyMock.createMock(FilterConfig.class); - EasyMock.expect(mock.getInitParameter("userToken")).andReturn("2Wle3"); - EasyMock.expect(mock.getInitParameter("projectToken")).andReturn("2Wle3"); - EasyMock.expect(mock.getInitParameter("sitePrefixPath")).andReturn(""); - EasyMock.expect(mock.getInitParameter("secretKey")).andReturn("secret"); - EasyMock.expect(mock.getInitParameter("urlPattern")).andReturn(""); - EasyMock.expect(mock.getInitParameter("urlPatternReg")).andReturn(""); - EasyMock.expect(mock.getInitParameter("query")).andReturn("baz"); - EasyMock.expect(mock.getInitParameter("apiUrl")).andReturn(""); - EasyMock.expect(mock.getInitParameter("defaultLang")).andReturn(""); - EasyMock.expect(mock.getInitParameter("supportedLangs")).andReturn(""); - EasyMock.expect(mock.getInitParameter("testMode")).andReturn(""); - EasyMock.expect(mock.getInitParameter("testUrl")).andReturn(""); - EasyMock.expect(mock.getInitParameter("useProxy")).andReturn(""); - EasyMock.expect(mock.getInitParameter("debugMode")).andReturn(""); - EasyMock.expect(mock.getInitParameter("originalUrlHeader")).andReturn("REDIRECT_URL"); - EasyMock.expect(mock.getInitParameter("originalQueryStringHeader")).andReturn("REDIRECT_QUERY_STRING"); - EasyMock.expect(mock.getInitParameter("strictHtmlCheck")).andReturn(""); - EasyMock.expect(mock.getInitParameter("deleteInvalidClosingTag")).andReturn(""); - EasyMock.expect(mock.getInitParameter("deleteInvalidUTF8")).andReturn(""); - EasyMock.expect(mock.getInitParameter("connectTimeout")).andReturn(""); - EasyMock.expect(mock.getInitParameter("readTimeout")).andReturn(""); - EasyMock.replay(mock); - - return mock; + HashMap parameters = new HashMap() {{ + put("userToken", "2Wle3"); + put("projectToken", "2Wle3"); + put("secretKey", "secret"); + put("query", "baz"); + put("originalUrlHeader", "REDIRECT_URL"); + put("originalQueryStringHeader", "REDIRECT_QUERY_STRING"); + }}; + return TestUtil.makeConfig(parameters); } private static HttpServletRequest mockRequestPath() { @@ -258,24 +153,6 @@ private static HttpServletRequest mockRequestOriginalHeaders() { } - private static FilterConfig mockSpecificConfig(HashMap option) { - FilterConfig mock = EasyMock.createMock(FilterConfig.class); - String[] keys = {"userToken", "projectToken", "sitePrefixPath", "secretKey", "urlPattern", "urlPatternReg", "query", "apiUrl", "defaultLang", "supportedLangs", "testMode", "testUrl", "useProxy", "debugMode", "originalUrlHeader", "originalQueryStringHeader", "strictHtmlCheck", "deleteInvalidClosingTag", "deleteInvalidUTF8", "connectTimeout", "readTimeout"}; - for (int i=0; i option) { - FilterConfig mock = mockSpecificConfig(option); - return new Settings(mock); - } - public void testHeaders() { HttpServletRequest mockRequest = mockRequestPath(); FilterConfig mockConfig = mockConfigPath(); @@ -432,7 +309,7 @@ public void testSitePrefixPath() { private Headers makeHeader(String requestPath, String sitePrefix) { HttpServletRequest mockRequest = mockRequestPath(requestPath); HashMap option = new HashMap(){ { put("sitePrefixPath", "/global/"); } }; - Settings s = makeSettings(option); + Settings s = TestUtil.makeSettings(option); return new Headers(mockRequest, s); } diff --git a/src/test/java/com/github/wovnio/wovnjava/SettingsTest.java b/src/test/java/com/github/wovnio/wovnjava/SettingsTest.java index c6249ed9..d84a9ad8 100644 --- a/src/test/java/com/github/wovnio/wovnjava/SettingsTest.java +++ b/src/test/java/com/github/wovnio/wovnjava/SettingsTest.java @@ -12,113 +12,51 @@ public class SettingsTest extends TestCase { private static FilterConfig mockEmptyConfig() { - FilterConfig mock = EasyMock.createMock(FilterConfig.class); - EasyMock.expect(mock.getInitParameter("userToken")).andReturn(""); - EasyMock.expect(mock.getInitParameter("projectToken")).andReturn(""); - EasyMock.expect(mock.getInitParameter("sitePrefixPath")).andReturn(""); - EasyMock.expect(mock.getInitParameter("secretKey")).andReturn(""); - EasyMock.expect(mock.getInitParameter("urlPattern")).andReturn(""); - EasyMock.expect(mock.getInitParameter("urlPatternReg")).andReturn(""); - EasyMock.expect(mock.getInitParameter("query")).andReturn(""); - EasyMock.expect(mock.getInitParameter("apiUrl")).andReturn(""); - EasyMock.expect(mock.getInitParameter("defaultLang")).andReturn(""); - EasyMock.expect(mock.getInitParameter("supportedLangs")).andReturn(""); - EasyMock.expect(mock.getInitParameter("useProxy")).andReturn(""); - EasyMock.expect(mock.getInitParameter("originalUrlHeader")).andReturn(""); - EasyMock.expect(mock.getInitParameter("originalQueryStringHeader")).andReturn(""); - EasyMock.expect(mock.getInitParameter("strictHtmlCheck")).andReturn(""); - EasyMock.expect(mock.getInitParameter("connectTimeout")).andReturn(""); - EasyMock.expect(mock.getInitParameter("readTimeout")).andReturn(""); - EasyMock.replay(mock); - - return mock; + return TestUtil.makeConfig(); } private static FilterConfig mockValidConfig() { - FilterConfig mock = EasyMock.createMock(FilterConfig.class); - EasyMock.expect(mock.getInitParameter("userToken")).andReturn("2Wle3"); - EasyMock.expect(mock.getInitParameter("projectToken")).andReturn("2Wle3"); - EasyMock.expect(mock.getInitParameter("sitePrefixPath")).andReturn(""); - EasyMock.expect(mock.getInitParameter("secretKey")).andReturn("secret"); - EasyMock.expect(mock.getInitParameter("urlPattern")).andReturn("query"); - EasyMock.expect(mock.getInitParameter("urlPatternReg")).andReturn("aaa"); - EasyMock.expect(mock.getInitParameter("query")).andReturn("foo,bar"); - EasyMock.expect(mock.getInitParameter("apiUrl")).andReturn("https://example.com/v0/values"); - EasyMock.expect(mock.getInitParameter("defaultLang")).andReturn("ja"); - EasyMock.expect(mock.getInitParameter("supportedLangs")).andReturn("en,ja"); - EasyMock.expect(mock.getInitParameter("useProxy")).andReturn(""); - EasyMock.expect(mock.getInitParameter("originalUrlHeader")).andReturn("REDIRECT_URL"); - EasyMock.expect(mock.getInitParameter("originalQueryStringHeader")).andReturn("REDIRECT_QUERY_STRING"); - EasyMock.expect(mock.getInitParameter("strictHtmlCheck")).andReturn(""); - EasyMock.expect(mock.getInitParameter("connectTimeout")).andReturn(""); - EasyMock.expect(mock.getInitParameter("readTimeout")).andReturn(""); - EasyMock.replay(mock); - - return mock; + HashMap parameters = new HashMap() {{ + put("userToken", "2Wle3"); + put("projectToken", "2Wle3"); + put("secretKey", "secret"); + put("urlPattern", "query"); + put("urlPatternReg", "aaa"); + put("query", "foo,bar"); + put("apiUrl", "https://example.com/v0/values"); + put("defaultLang", "ja"); + put("supportedLangs", "en,ja"); + put("originalUrlHeader", "REDIRECT_URL"); + put("originalQueryStringHeader", "REDIRECT_QUERY_STRING"); + }}; + return TestUtil.makeConfig(parameters); } private static FilterConfig mockValidConfigMultipleToken() { - FilterConfig mock = EasyMock.createMock(FilterConfig.class); - EasyMock.expect(mock.getInitParameter("userToken")).andReturn("2Wle3"); - EasyMock.expect(mock.getInitParameter("projectToken")).andReturn("3elW2"); - EasyMock.expect(mock.getInitParameter("sitePrefixPath")).andReturn(""); - EasyMock.expect(mock.getInitParameter("secretKey")).andReturn("secret"); - EasyMock.expect(mock.getInitParameter("urlPattern")).andReturn("query"); - EasyMock.expect(mock.getInitParameter("urlPatternReg")).andReturn("aaa"); - EasyMock.expect(mock.getInitParameter("query")).andReturn("foo,bar"); - EasyMock.expect(mock.getInitParameter("apiUrl")).andReturn("https://example.com/v0/values"); - EasyMock.expect(mock.getInitParameter("defaultLang")).andReturn("ja"); - EasyMock.expect(mock.getInitParameter("supportedLangs")).andReturn("en,ja"); - EasyMock.expect(mock.getInitParameter("useProxy")).andReturn(""); - EasyMock.expect(mock.getInitParameter("originalUrlHeader")).andReturn("REDIRECT_URL"); - EasyMock.expect(mock.getInitParameter("originalQueryStringHeader")).andReturn("REDIRECT_QUERY_STRING"); - EasyMock.expect(mock.getInitParameter("strictHtmlCheck")).andReturn(""); - EasyMock.expect(mock.getInitParameter("connectTimeout")).andReturn(""); - EasyMock.expect(mock.getInitParameter("readTimeout")).andReturn(""); - EasyMock.replay(mock); - - return mock; + HashMap parameters = new HashMap() {{ + put("userToken", "2Wle3"); + put("projectToken", "3elW2"); + put("secretKey", "secret"); + put("urlPattern", "query"); + put("urlPatternReg", "aaa"); + put("query", "foo,bar"); + put("apiUrl", "https://example.com/v0/values"); + put("defaultLang", "ja"); + put("supportedLangs", "en,ja"); + put("originalUrlHeader", "REDIRECT_URL"); + put("originalQueryStringHeader", "REDIRECT_QUERY_STRING"); + }}; + return TestUtil.makeConfig(parameters); } private static FilterConfig mockQueryConfig() { - FilterConfig mock = EasyMock.createMock(FilterConfig.class); - EasyMock.expect(mock.getInitParameter("userToken")).andReturn("2Wle3"); - EasyMock.expect(mock.getInitParameter("projectToken")).andReturn("2Wle3"); - EasyMock.expect(mock.getInitParameter("sitePrefixPath")).andReturn(""); - EasyMock.expect(mock.getInitParameter("secretKey")).andReturn("secret"); - EasyMock.expect(mock.getInitParameter("urlPattern")).andReturn("query"); - EasyMock.expect(mock.getInitParameter("urlPatternReg")).andReturn(""); - EasyMock.expect(mock.getInitParameter("query")).andReturn(""); - EasyMock.expect(mock.getInitParameter("apiUrl")).andReturn(""); - EasyMock.expect(mock.getInitParameter("defaultLang")).andReturn(""); - EasyMock.expect(mock.getInitParameter("supportedLangs")).andReturn(""); - EasyMock.expect(mock.getInitParameter("useProxy")).andReturn(""); - EasyMock.expect(mock.getInitParameter("originalUrlHeader")).andReturn(""); - EasyMock.expect(mock.getInitParameter("originalQueryStringHeader")).andReturn(""); - EasyMock.expect(mock.getInitParameter("strictHtmlCheck")).andReturn(""); - EasyMock.expect(mock.getInitParameter("connectTimeout")).andReturn(""); - EasyMock.expect(mock.getInitParameter("readTimeout")).andReturn(""); - EasyMock.replay(mock); - - return mock; - } - - private static FilterConfig mockSpecificConfig(HashMap option) { - FilterConfig mock = EasyMock.createMock(FilterConfig.class); - String[] keys = {"userToken", "projectToken", "sitePrefixPath", "secretKey", "urlPattern", "urlPatternReg", "query", "apiUrl", "defaultLang", "supportedLangs", "useProxy", "originalUrlHeader", "originalQueryStringHeader", "connectTimeout", "readTimeout", "strictHtmlCheck"}; - for (int i=0; i option) { - FilterConfig mock = mockSpecificConfig(option); - return new Settings(mock); + HashMap parameters = new HashMap() {{ + put("userToken", "2Wle3"); + put("projectToken", "2Wle3"); + put("secretKey", "secret"); + put("urlPattern", "query"); + }}; + return TestUtil.makeConfig(parameters); } // urlPattern is "path". @@ -252,8 +190,7 @@ public void testSettingsWithValidConfigMultipleToken() { } public void testSettingsWithoutSitePrefix() { - HashMap option = new HashMap(); - Settings s = newSettings(option); + Settings s = TestUtil.makeSettings(); assertFalse(s.hasSitePrefixPath); assertEquals("/", s.sitePrefixPathWithSlash); assertEquals("", s.sitePrefixPathWithoutSlash); @@ -262,7 +199,7 @@ public void testSettingsWithoutSitePrefix() { public void testSettingsWithSitePrefix() { HashMap option = new HashMap(); option.put("sitePrefixPath", "/global/"); - Settings s = newSettings(option); + Settings s = TestUtil.makeSettings(option); assertTrue(s.hasSitePrefixPath); assertEquals("/global/", s.sitePrefixPathWithSlash); assertEquals("/global", s.sitePrefixPathWithoutSlash); diff --git a/src/test/java/com/github/wovnio/wovnjava/TestUtil.java b/src/test/java/com/github/wovnio/wovnjava/TestUtil.java index a19c5c23..6af238c9 100644 --- a/src/test/java/com/github/wovnio/wovnjava/TestUtil.java +++ b/src/test/java/com/github/wovnio/wovnjava/TestUtil.java @@ -73,33 +73,6 @@ public static ServletResponse mockResponse(String contentType, String encoding) return mock; } - public static FilterConfig mockFilterConfig() { - FilterConfig mock = EasyMock.createMock(FilterConfig.class); - EasyMock.expect(mock.getInitParameter("userToken")).andReturn("2Wle3"); - EasyMock.expect(mock.getInitParameter("projectToken")).andReturn("2Wle3"); - EasyMock.expect(mock.getInitParameter("sitePrefixPath")).andReturn(""); - EasyMock.expect(mock.getInitParameter("secretKey")).andReturn("secret"); - EasyMock.expect(mock.getInitParameter("urlPattern")).andReturn(""); - EasyMock.expect(mock.getInitParameter("urlPatternReg")).andReturn(""); - EasyMock.expect(mock.getInitParameter("query")).andReturn(""); - EasyMock.expect(mock.getInitParameter("apiUrl")).andReturn(""); - EasyMock.expect(mock.getInitParameter("defaultLang")).andReturn(""); - EasyMock.expect(mock.getInitParameter("supportedLangs")).andReturn(""); - EasyMock.expect(mock.getInitParameter("testMode")).andReturn(""); - EasyMock.expect(mock.getInitParameter("testUrl")).andReturn(""); - EasyMock.expect(mock.getInitParameter("useProxy")).andReturn(""); - EasyMock.expect(mock.getInitParameter("debugMode")).andReturn(""); - EasyMock.expect(mock.getInitParameter("originalUrlHeader")).andReturn(""); - EasyMock.expect(mock.getInitParameter("originalQueryStringHeader")).andReturn(""); - EasyMock.expect(mock.getInitParameter("strictHtmlCheck")).andReturn(""); - EasyMock.expect(mock.getInitParameter("deleteInvalidClosingTag")).andReturn(""); - EasyMock.expect(mock.getInitParameter("deleteInvalidUTF8")).andReturn(""); - EasyMock.expect(mock.getInitParameter("connectTimeout")).andReturn(""); - EasyMock.expect(mock.getInitParameter("readTimeout")).andReturn(""); - EasyMock.replay(mock); - return mock; - } - public static FilterChainMock doServletFilter(String contentType, String path) throws ServletException, IOException { return doServletFilter(contentType, path, path, emptyOption); } diff --git a/src/test/java/com/github/wovnio/wovnjava/WovnHttpServletRequestTest.java b/src/test/java/com/github/wovnio/wovnjava/WovnHttpServletRequestTest.java index 080bf1b2..6877a6bf 100644 --- a/src/test/java/com/github/wovnio/wovnjava/WovnHttpServletRequestTest.java +++ b/src/test/java/com/github/wovnio/wovnjava/WovnHttpServletRequestTest.java @@ -2,6 +2,7 @@ import junit.framework.TestCase; +import java.util.HashMap; import org.easymock.EasyMock; import javax.servlet.FilterConfig; @@ -52,84 +53,32 @@ private static HttpServletRequest mockRequestQuery() { } private static FilterConfig mockConfigPath() { - FilterConfig mock = EasyMock.createMock(FilterConfig.class); - EasyMock.expect(mock.getInitParameter("userToken")).andReturn("2Wle3"); - EasyMock.expect(mock.getInitParameter("projectToken")).andReturn("2Wle3"); - EasyMock.expect(mock.getInitParameter("sitePrefixPath")).andReturn(""); - EasyMock.expect(mock.getInitParameter("secretKey")).andReturn("secret"); - EasyMock.expect(mock.getInitParameter("urlPattern")).andReturn(""); - EasyMock.expect(mock.getInitParameter("urlPatternReg")).andReturn(""); - EasyMock.expect(mock.getInitParameter("query")).andReturn(""); - EasyMock.expect(mock.getInitParameter("apiUrl")).andReturn(""); - EasyMock.expect(mock.getInitParameter("defaultLang")).andReturn(""); - EasyMock.expect(mock.getInitParameter("supportedLangs")).andReturn(""); - EasyMock.expect(mock.getInitParameter("testMode")).andReturn(""); - EasyMock.expect(mock.getInitParameter("testUrl")).andReturn(""); - EasyMock.expect(mock.getInitParameter("useProxy")).andReturn(""); - EasyMock.expect(mock.getInitParameter("debugMode")).andReturn(""); - EasyMock.expect(mock.getInitParameter("originalUrlHeader")).andReturn(""); - EasyMock.expect(mock.getInitParameter("originalQueryStringHeader")).andReturn(""); - EasyMock.expect(mock.getInitParameter("strictHtmlCheck")).andReturn(""); - EasyMock.expect(mock.getInitParameter("deleteInvalidClosingTag")).andReturn(""); - EasyMock.expect(mock.getInitParameter("deleteInvalidUTF8")).andReturn(""); - EasyMock.expect(mock.getInitParameter("connectTimeout")).andReturn(""); - EasyMock.expect(mock.getInitParameter("readTimeout")).andReturn(""); - EasyMock.replay(mock); - return mock; + HashMap parameters = new HashMap() {{ + put("userToken", "2Wle3"); + put("projectToken", "2Wle3"); + put("secretKey", "secret"); + }}; + return TestUtil.makeConfig(parameters); } private static FilterConfig mockConfigSubDomain() { - FilterConfig mock = EasyMock.createMock(FilterConfig.class); - EasyMock.expect(mock.getInitParameter("userToken")).andReturn("2Wle3"); - EasyMock.expect(mock.getInitParameter("projectToken")).andReturn("2Wle3"); - EasyMock.expect(mock.getInitParameter("sitePrefixPath")).andReturn(""); - EasyMock.expect(mock.getInitParameter("secretKey")).andReturn("secret"); - EasyMock.expect(mock.getInitParameter("urlPattern")).andReturn("subdomain"); - EasyMock.expect(mock.getInitParameter("urlPatternReg")).andReturn(""); - EasyMock.expect(mock.getInitParameter("query")).andReturn(""); - EasyMock.expect(mock.getInitParameter("apiUrl")).andReturn(""); - EasyMock.expect(mock.getInitParameter("defaultLang")).andReturn(""); - EasyMock.expect(mock.getInitParameter("supportedLangs")).andReturn(""); - EasyMock.expect(mock.getInitParameter("testMode")).andReturn(""); - EasyMock.expect(mock.getInitParameter("testUrl")).andReturn(""); - EasyMock.expect(mock.getInitParameter("useProxy")).andReturn(""); - EasyMock.expect(mock.getInitParameter("debugMode")).andReturn(""); - EasyMock.expect(mock.getInitParameter("originalUrlHeader")).andReturn(""); - EasyMock.expect(mock.getInitParameter("originalQueryStringHeader")).andReturn(""); - EasyMock.expect(mock.getInitParameter("strictHtmlCheck")).andReturn(""); - EasyMock.expect(mock.getInitParameter("deleteInvalidClosingTag")).andReturn(""); - EasyMock.expect(mock.getInitParameter("deleteInvalidUTF8")).andReturn(""); - EasyMock.expect(mock.getInitParameter("connectTimeout")).andReturn(""); - EasyMock.expect(mock.getInitParameter("readTimeout")).andReturn(""); - EasyMock.replay(mock); - return mock; + HashMap parameters = new HashMap() {{ + put("userToken", "2Wle3"); + put("projectToken", "2Wle3"); + put("secretKey", "secret"); + put("urlPattern", "subdomain"); + }}; + return TestUtil.makeConfig(parameters); } private static FilterConfig mockConfigQuery() { - FilterConfig mock = EasyMock.createMock(FilterConfig.class); - EasyMock.expect(mock.getInitParameter("userToken")).andReturn("2Wle3"); - EasyMock.expect(mock.getInitParameter("projectToken")).andReturn("2Wle3"); - EasyMock.expect(mock.getInitParameter("sitePrefixPath")).andReturn(""); - EasyMock.expect(mock.getInitParameter("secretKey")).andReturn("secret"); - EasyMock.expect(mock.getInitParameter("urlPattern")).andReturn("query"); - EasyMock.expect(mock.getInitParameter("urlPatternReg")).andReturn(""); - EasyMock.expect(mock.getInitParameter("query")).andReturn(""); - EasyMock.expect(mock.getInitParameter("apiUrl")).andReturn(""); - EasyMock.expect(mock.getInitParameter("defaultLang")).andReturn(""); - EasyMock.expect(mock.getInitParameter("supportedLangs")).andReturn(""); - EasyMock.expect(mock.getInitParameter("testMode")).andReturn(""); - EasyMock.expect(mock.getInitParameter("testUrl")).andReturn(""); - EasyMock.expect(mock.getInitParameter("useProxy")).andReturn(""); - EasyMock.expect(mock.getInitParameter("debugMode")).andReturn(""); - EasyMock.expect(mock.getInitParameter("originalUrlHeader")).andReturn(""); - EasyMock.expect(mock.getInitParameter("originalQueryStringHeader")).andReturn(""); - EasyMock.expect(mock.getInitParameter("strictHtmlCheck")).andReturn(""); - EasyMock.expect(mock.getInitParameter("deleteInvalidClosingTag")).andReturn(""); - EasyMock.expect(mock.getInitParameter("deleteInvalidUTF8")).andReturn(""); - EasyMock.expect(mock.getInitParameter("connectTimeout")).andReturn(""); - EasyMock.expect(mock.getInitParameter("readTimeout")).andReturn(""); - EasyMock.replay(mock); - return mock; + HashMap parameters = new HashMap() {{ + put("userToken", "2Wle3"); + put("projectToken", "2Wle3"); + put("secretKey", "secret"); + put("urlPattern", "query"); + }}; + return TestUtil.makeConfig(parameters); } public void testWovnHttpServletRequest() {