[
http://issues.appfuse.org/browse/APF-1146?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12655 ]
tibi commented on APF-1146:
----------------------------
and here is the
package org.appfuse.webapp.util;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
/**
* Test the requestUtil
*
* @author <a href="mailto:
[hidden email]">Tibor Strausz</a>
*/
public class RequestUtilTest {
final MockHttpServletRequest request = new MockHttpServletRequest("GET", "/scripts/dojo/test.html");
final MockHttpServletResponse response = new MockHttpServletResponse();
@Test
public void setCookie() {
// just for coverage
Logger.getLogger(RequestUtil.class).setLevel(Level.WARN);
RequestUtil.setCookie(response, "name", "value", "path");
Logger.getLogger(RequestUtil.class).setLevel(Level.DEBUG);
RequestUtil.setCookie(response, "name", "value", "path");
request.setCookies(response.getCookies());
Assert.assertNotNull(RequestUtil.getCookie(request, "name"));
Assert.assertEquals("path", response.getCookie("name").getPath());
}
@Test
public void getCookie() {
final String cookieName = "name";
Assert.assertNull(RequestUtil.getCookie(request, cookieName));
RequestUtil.setCookie(response, cookieName, "value", "path");
request.setCookies(response.getCookies());
Assert.assertNotNull(RequestUtil.getCookie(request, cookieName));
Assert.assertNull(RequestUtil.getCookie(request, "wrongName"));
RequestUtil.setCookie(response, "empty", "", "path");
request.setCookies(response.getCookies());
Assert.assertNull(RequestUtil.getCookie(request, "empty"));
}
@Test
public void deleteCookie() {
final String cookieName = "name";
RequestUtil.setCookie(response, cookieName, "value", "path");
request.setCookies(response.getCookies());
RequestUtil.deleteCookie(response, RequestUtil.getCookie(request, cookieName), "path");
Assert.assertEquals(0, RequestUtil.getCookie(request, cookieName).getMaxAge());
// don't fail on null input
RequestUtil.deleteCookie(response, null, null);
}
@Test
public void getAppURL() {
String url = RequestUtil.getAppURL(request);
Assert.assertNotNull(url);
Assert.assertEquals("
http://localhost", url);
request.setServerPort(12);
url = RequestUtil.getAppURL(request);
Assert.assertNotNull(url);
Assert.assertEquals("
http://localhost:12", url);
request.setServerPort(-12);
url = RequestUtil.getAppURL(request);
Assert.assertNotNull(url);
Assert.assertEquals("
http://localhost", url);
request.setScheme("foo");
request.setServerPort(-12);
url = RequestUtil.getAppURL(request);
Assert.assertNotNull(url);
Assert.assertEquals("foo://localhost", url);
}
}
> to improve code coverage add the following patches
> --------------------------------------------------
>
> Key: APF-1146
> URL:
http://issues.appfuse.org/browse/APF-1146> Project: AppFuse
> Issue Type: Improvement
> Components: Service Layer
> Affects Versions: 2.0.2
> Reporter: tibi
> Assignee: Matt Raible
> Fix For: 2.1
>
> Attachments: patchActionDateConverter.txt, patchApplicationContext-test.txt, patchConvertUtil.txt, patchDateConverter.txt, patchDateUtil.txt, patchMailEngineTest.txt, patchUserActionTest.txt, patchUserActionTest.txt
>
>
> i'm working on code coverage and will add some patches to improve. everyone is welcome to do so :D
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.appfuse.org/secure/Administrators.jspa-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail:
[hidden email]
For additional commands, e-mail:
[hidden email]