mirror of
https://github.com/apache/struts.git
synced 2026-08-31 19:35:40 +00:00
WW-5411 Delete deprecated methods from cache factories and OgnlUtil constructor
This commit is contained in:
@@ -28,20 +28,24 @@ import com.opensymphony.xwork2.config.entities.InterceptorMapping;
|
||||
import com.opensymphony.xwork2.config.entities.ResultConfig;
|
||||
import com.opensymphony.xwork2.mock.MockActionProxy;
|
||||
import com.opensymphony.xwork2.mock.MockInterceptor;
|
||||
import com.opensymphony.xwork2.ognl.DefaultOgnlBeanInfoCacheFactory;
|
||||
import com.opensymphony.xwork2.ognl.DefaultOgnlExpressionCacheFactory;
|
||||
import com.opensymphony.xwork2.ognl.OgnlUtil;
|
||||
import com.opensymphony.xwork2.util.XWorkTestCaseHelper;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import junit.framework.TestCase;
|
||||
import org.apache.struts2.ServletActionContext;
|
||||
import org.apache.struts2.ognl.StrutsOgnlGuard;
|
||||
import org.apache.struts2.result.HttpHeaderResult;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.opensymphony.xwork2.ognl.OgnlCacheFactory.CacheType.BASIC;
|
||||
import static jakarta.servlet.http.HttpServletResponse.SC_NOT_MODIFIED;
|
||||
|
||||
public class RestActionInvocationTest extends TestCase {
|
||||
@@ -53,7 +57,7 @@ public class RestActionInvocationTest extends TestCase {
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
|
||||
restActionInvocation = new RestActionInvocationTester();
|
||||
request = new MockHttpServletRequest();
|
||||
response = new MockHttpServletResponse();
|
||||
@@ -61,7 +65,7 @@ public class RestActionInvocationTest extends TestCase {
|
||||
ServletActionContext.setResponse(response);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test the correct action results: null, String, HttpHeaders, Result
|
||||
* @throws Exception
|
||||
@@ -71,12 +75,12 @@ public class RestActionInvocationTest extends TestCase {
|
||||
Object methodResult = "index";
|
||||
ActionConfig actionConfig = restActionInvocation.getProxy().getConfig();
|
||||
assertEquals("index", restActionInvocation.saveResult(actionConfig, methodResult));
|
||||
|
||||
|
||||
setUp();
|
||||
methodResult = new DefaultHttpHeaders("show");
|
||||
assertEquals("show", restActionInvocation.saveResult(actionConfig, methodResult));
|
||||
assertEquals(methodResult, restActionInvocation.httpHeaders);
|
||||
|
||||
|
||||
setUp();
|
||||
methodResult = new HttpHeaderResult(HttpServletResponse.SC_ACCEPTED);
|
||||
assertEquals(null, restActionInvocation.saveResult(actionConfig, methodResult));
|
||||
@@ -89,18 +93,18 @@ public class RestActionInvocationTest extends TestCase {
|
||||
|
||||
// ko
|
||||
assertFalse(true);
|
||||
|
||||
|
||||
} catch (ConfigurationException c) {
|
||||
// ok, object not allowed
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test the target selection: exception, error messages, model and null
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testSelectTarget() throws Exception {
|
||||
|
||||
|
||||
// Exception
|
||||
Exception e = new Exception();
|
||||
restActionInvocation.getStack().set("exception", e);
|
||||
@@ -118,7 +122,7 @@ public class RestActionInvocationTest extends TestCase {
|
||||
errors.put("actionErrors", list);
|
||||
restActionInvocation.selectTarget();
|
||||
assertEquals(errors, restActionInvocation.target);
|
||||
|
||||
|
||||
// Model with get and no content in post, put, delete
|
||||
setUp();
|
||||
RestAction restAction = (RestAction)restActionInvocation.getAction();
|
||||
@@ -168,18 +172,18 @@ public class RestActionInvocationTest extends TestCase {
|
||||
};
|
||||
model.add("Item");
|
||||
restAction.model = model;
|
||||
|
||||
|
||||
restActionInvocation.processResult();
|
||||
assertEquals(SC_NOT_MODIFIED, response.getStatus());
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test the default error result.
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testDefaultErrorResult() throws Exception {
|
||||
|
||||
|
||||
// Exception
|
||||
Exception e = new Exception();
|
||||
restActionInvocation.getStack().set("exception", e);
|
||||
@@ -189,24 +193,24 @@ public class RestActionInvocationTest extends TestCase {
|
||||
List<String> model = new ArrayList<String>();
|
||||
model.add("Item");
|
||||
restAction.model = model;
|
||||
|
||||
|
||||
restActionInvocation.setDefaultErrorResultName("default-error");
|
||||
ResultConfig resultConfig = new ResultConfig.Builder("default-error",
|
||||
ResultConfig resultConfig = new ResultConfig.Builder("default-error",
|
||||
"org.apache.struts2.result.HttpHeaderResult")
|
||||
.addParam("status", "123").build();
|
||||
ActionConfig actionConfig = new ActionConfig.Builder("org.apache.rest",
|
||||
ActionConfig actionConfig = new ActionConfig.Builder("org.apache.rest",
|
||||
"RestAction", "org.apache.rest.RestAction")
|
||||
.addResultConfig(resultConfig)
|
||||
.build();
|
||||
((MockActionProxy)restActionInvocation.getProxy()).setConfig(actionConfig);
|
||||
|
||||
|
||||
restActionInvocation.processResult();
|
||||
assertEquals(123, response.getStatus());
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void testNoResult() throws Exception {
|
||||
|
||||
|
||||
RestAction restAction = (RestAction)restActionInvocation.getAction();
|
||||
List<String> model = new ArrayList<String>();
|
||||
model.add("Item");
|
||||
@@ -219,35 +223,39 @@ public class RestActionInvocationTest extends TestCase {
|
||||
|
||||
// ko
|
||||
assertFalse(true);
|
||||
|
||||
|
||||
} catch (ConfigurationException c) {
|
||||
// ok, no result
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test the global execution
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testInvoke() throws Exception {
|
||||
|
||||
|
||||
// Default index method return 'success'
|
||||
((MockActionProxy)restActionInvocation.getProxy()).setMethod("index");
|
||||
|
||||
// Define result 'success'
|
||||
ResultConfig resultConfig = new ResultConfig.Builder("success",
|
||||
ResultConfig resultConfig = new ResultConfig.Builder("success",
|
||||
"org.apache.struts2.result.HttpHeaderResult")
|
||||
.addParam("status", "123").build();
|
||||
ActionConfig actionConfig = new ActionConfig.Builder("org.apache.rest",
|
||||
ActionConfig actionConfig = new ActionConfig.Builder("org.apache.rest",
|
||||
"RestAction", "org.apache.rest.RestAction")
|
||||
.addResultConfig(resultConfig)
|
||||
.build();
|
||||
((MockActionProxy)restActionInvocation.getProxy()).setConfig(actionConfig);
|
||||
|
||||
request.setMethod("GET");
|
||||
|
||||
restActionInvocation.setOgnlUtil(new OgnlUtil());
|
||||
|
||||
restActionInvocation.setOgnlUtil(new OgnlUtil(
|
||||
new DefaultOgnlExpressionCacheFactory<>(String.valueOf(10_000), BASIC.toString()),
|
||||
new DefaultOgnlBeanInfoCacheFactory<>(String.valueOf(10_000), BASIC.toString()),
|
||||
new StrutsOgnlGuard()
|
||||
));
|
||||
restActionInvocation.invoke();
|
||||
|
||||
assertEquals(123, response.getStatus());
|
||||
@@ -264,7 +272,7 @@ public class RestActionInvocationTest extends TestCase {
|
||||
interceptorMappings.add(new InterceptorMapping("interceptor", mockInterceptor));
|
||||
interceptors = interceptorMappings.iterator();
|
||||
MockActionProxy actionProxy = new MockActionProxy();
|
||||
ActionConfig actionConfig = new ActionConfig.Builder("org.apache.rest",
|
||||
ActionConfig actionConfig = new ActionConfig.Builder("org.apache.rest",
|
||||
"RestAction", "org.apache.rest.RestAction").build();
|
||||
actionProxy.setConfig(actionConfig);
|
||||
proxy = actionProxy;
|
||||
@@ -280,18 +288,18 @@ public class RestActionInvocationTest extends TestCase {
|
||||
container = ActionContext.getContext().getContainer();
|
||||
stack = ActionContext.getContext().getValueStack();
|
||||
objectFactory = container.getInstance(ObjectFactory.class);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
class RestAction extends RestActionSupport implements ModelDriven<List<String>> {
|
||||
|
||||
List<String> model;
|
||||
|
||||
|
||||
public List<String> getModel() {
|
||||
return model;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user