Search in sources :

Example 1 with AbstractContentTypeHandler

use of org.apache.struts2.rest.handler.AbstractContentTypeHandler in project struts by apache.

the class ContentTypeHandlerManagerTest method testHandleResultOK.

public void testHandleResultOK() throws IOException {
    String obj = "mystring";
    ContentTypeHandler handler = new AbstractContentTypeHandler() {

        public void toObject(ActionInvocation invocation, Reader in, Object target) {
        }

        public String fromObject(ActionInvocation invocation, Object obj, String resultCode, Writer stream) throws IOException {
            stream.write(obj.toString());
            return resultCode;
        }

        public String getContentType() {
            return "foo";
        }

        public String getExtension() {
            return "foo";
        }
    };
    mgr.handlersByExtension.put("xml", handler);
    mgr.setDefaultExtension("xml");
    ActionConfig actionConfig = new ActionConfig.Builder("", "", "").build();
    MockActionProxy proxy = new MockActionProxy();
    proxy.setConfig(actionConfig);
    invocation.setProxy(proxy);
    mgr.handleResult(invocation, new DefaultHttpHeaders().withStatus(SC_OK), obj);
    assertEquals(obj.getBytes().length, mockResponse.getContentLength());
}
Also used : AbstractContentTypeHandler(org.apache.struts2.rest.handler.AbstractContentTypeHandler) ContentTypeHandler(org.apache.struts2.rest.handler.ContentTypeHandler) ActionConfig(com.opensymphony.xwork2.config.entities.ActionConfig) AbstractContentTypeHandler(org.apache.struts2.rest.handler.AbstractContentTypeHandler) ActionInvocation(com.opensymphony.xwork2.ActionInvocation) MockActionInvocation(com.opensymphony.xwork2.mock.MockActionInvocation) Reader(java.io.Reader) Writer(java.io.Writer) MockActionProxy(com.opensymphony.xwork2.mock.MockActionProxy)

Aggregations

ActionInvocation (com.opensymphony.xwork2.ActionInvocation)1 ActionConfig (com.opensymphony.xwork2.config.entities.ActionConfig)1 MockActionInvocation (com.opensymphony.xwork2.mock.MockActionInvocation)1 MockActionProxy (com.opensymphony.xwork2.mock.MockActionProxy)1 Reader (java.io.Reader)1 Writer (java.io.Writer)1 AbstractContentTypeHandler (org.apache.struts2.rest.handler.AbstractContentTypeHandler)1 ContentTypeHandler (org.apache.struts2.rest.handler.ContentTypeHandler)1