Skip to content

Commit

Permalink
Merge pull request #180 from yasserzamani/WW-4846-tests
Browse files Browse the repository at this point in the history
WW-4846 Adds unit tests
  • Loading branch information
lukaszlenart authored Nov 5, 2017
2 parents a443937 + fb0a612 commit d5c7196
Showing 1 changed file with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@

import javax.servlet.http.HttpServletResponse;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.apache.struts2.StrutsStatics;
import org.apache.struts2.StrutsTestCase;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.mock.web.MockServletContext;
Expand Down Expand Up @@ -153,6 +156,38 @@ public void testExcludeNullPropeties() throws Exception {
assertEquals(normalizedExpected, normalizedActual);
}

public void testNotTraverseOrIncludeProxyInfo() throws Exception {
JSONResult result = new JSONResult();
JSONUtil jsonUtil = new JSONUtil();
JSONWriter writer = new DefaultJSONWriter();
jsonUtil.setWriter(writer);
result.setJsonUtil(jsonUtil);
Object proxiedAction = new ProxyFactory(new TestAction2()).getProxy();
stack.push(proxiedAction);

this.invocation.setAction(proxiedAction);
try {
result.execute(this.invocation);
} catch (Exception ignored) {
}

String out = response.getContentAsString();

String normalizedActual = TestUtils.normalize(out, true);
String normalizedExpected = "{\"name\":\"name\"}";
assertNotSame(normalizedExpected, normalizedActual);
response.setCommitted(false);
response.reset();

writer.setExcludeProxyProperties(true);
result.execute(this.invocation);

out = response.getContentAsString();

normalizedActual = TestUtils.normalize(out, true);
assertEquals(normalizedExpected, normalizedActual);
}

public void testWrapPrefix() throws Exception {
JSONResult result = new JSONResult();
result.setWrapPrefix("_prefix_");
Expand Down

0 comments on commit d5c7196

Please sign in to comment.