struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From musa...@apache.org
Subject svn commit: r817318 - in /struts/struts2/trunk/plugins/jfreechart: pom.xml src/main/java/org/apache/struts2/dispatcher/ChartResult.java src/test/java/org/apache/struts2/dispatcher/ChartResultTest.java
Date Mon, 21 Sep 2009 16:55:10 GMT
Author: musachy
Date: Mon Sep 21 16:55:09 2009
New Revision: 817318

URL: http://svn.apache.org/viewvc?rev=817318&view=rev
Log:
WW-3210 JFreeChart plugin not setting correct mime type

Modified:
    struts/struts2/trunk/plugins/jfreechart/pom.xml
    struts/struts2/trunk/plugins/jfreechart/src/main/java/org/apache/struts2/dispatcher/ChartResult.java
    struts/struts2/trunk/plugins/jfreechart/src/test/java/org/apache/struts2/dispatcher/ChartResultTest.java

Modified: struts/struts2/trunk/plugins/jfreechart/pom.xml
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/jfreechart/pom.xml?rev=817318&r1=817317&r2=817318&view=diff
==============================================================================
--- struts/struts2/trunk/plugins/jfreechart/pom.xml (original)
+++ struts/struts2/trunk/plugins/jfreechart/pom.xml Mon Sep 21 16:55:09 2009
@@ -65,12 +65,6 @@
             </exclusions>
         </dependency>
         <dependency>
-            <groupId>mockobjects</groupId>
-            <artifactId>mockobjects-core</artifactId>
-            <version>0.09</version>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
             <groupId>org.apache.struts</groupId>
             <artifactId>struts2-core</artifactId>
             <scope>compile</scope>
@@ -88,14 +82,18 @@
             <version>2.4</version>
             <scope>provided</scope>
         </dependency>
-
         <dependency>
             <groupId>javax.servlet</groupId>
             <artifactId>jsp-api</artifactId>
             <version>2.0</version>
             <scope>provided</scope>
         </dependency>
-
+ 		<dependency>
+            <groupId>org.easymock</groupId>
+            <artifactId>easymock</artifactId>
+            <version>2.3</version>
+            <scope>test</scope>
+        </dependency>
 
     </dependencies>
 </project>

Modified: struts/struts2/trunk/plugins/jfreechart/src/main/java/org/apache/struts2/dispatcher/ChartResult.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/jfreechart/src/main/java/org/apache/struts2/dispatcher/ChartResult.java?rev=817318&r1=817317&r2=817318&view=diff
==============================================================================
--- struts/struts2/trunk/plugins/jfreechart/src/main/java/org/apache/struts2/dispatcher/ChartResult.java
(original)
+++ struts/struts2/trunk/plugins/jfreechart/src/main/java/org/apache/struts2/dispatcher/ChartResult.java
Mon Sep 21 16:55:09 2009
@@ -30,6 +30,8 @@
 
 import java.io.OutputStream;
 
+import javax.servlet.http.HttpServletResponse;
+
 /**
  * <!-- START SNIPPET: description -->
  * <p/>
@@ -192,13 +194,18 @@
             throw new NullPointerException("No width parameter was given.");
 
         // get a reference to the servlet output stream to write our chart image to
-        OutputStream os = ServletActionContext.getResponse().getOutputStream();
+        HttpServletResponse response = ServletActionContext.getResponse();
+        OutputStream os = response.getOutputStream();
         try {
             // check the type to see what kind of output we have to produce
-            if ("png".equalsIgnoreCase(type))
+            if ("png".equalsIgnoreCase(type)) {
+                response.setContentType("image/png");
                 ChartUtilities.writeChartAsPNG(os, chart, getIntValueFromString(width), getIntValueFromString(height));
-            else if ("jpg".equalsIgnoreCase(type) || "jpeg".equalsIgnoreCase(type))
+            }
+            else if ("jpg".equalsIgnoreCase(type) || "jpeg".equalsIgnoreCase(type)) {
+                response.setContentType("image/jpg");
                 ChartUtilities.writeChartAsJPEG(os, chart, getIntValueFromString(width),
getIntValueFromString(height));
+            }
             else
                 throw new IllegalArgumentException(type + " is not a supported render type
(only JPG and PNG are).");
         } finally {

Modified: struts/struts2/trunk/plugins/jfreechart/src/test/java/org/apache/struts2/dispatcher/ChartResultTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/jfreechart/src/test/java/org/apache/struts2/dispatcher/ChartResultTest.java?rev=817318&r1=817317&r2=817318&view=diff
==============================================================================
--- struts/struts2/trunk/plugins/jfreechart/src/test/java/org/apache/struts2/dispatcher/ChartResultTest.java
(original)
+++ struts/struts2/trunk/plugins/jfreechart/src/test/java/org/apache/struts2/dispatcher/ChartResultTest.java
Mon Sep 21 16:55:09 2009
@@ -21,9 +21,10 @@
 
 package org.apache.struts2.dispatcher;
 
-import com.mockobjects.dynamic.Mock;
 import org.apache.struts2.ServletActionContext;
 import org.apache.struts2.StrutsTestCase;
+import org.easymock.EasyMock;
+
 import com.opensymphony.xwork2.ActionContext;
 import com.opensymphony.xwork2.ActionInvocation;
 import com.opensymphony.xwork2.ActionProxy;
@@ -43,30 +44,67 @@
 
     private ActionInvocation actionInvocation;
     private JFreeChart mockChart;
-    private Mock responseMock;
-    private Mock mockActionProxy;
     private MockServletOutputStream os;
     private ValueStack stack;
+    private ActionProxy mockActionProxy;
+    private HttpServletResponse responseMock;
 
 
     public void testChart() throws Exception {
-        responseMock.expectAndReturn("getOutputStream", os);
+        EasyMock.expect(responseMock.getOutputStream()).andReturn(os);
+        EasyMock.replay(responseMock, mockActionProxy, actionInvocation);
+        
+        ChartResult result = new ChartResult();
+
+        result.setChart(mockChart);
+
+        result.setHeight("10");
+        result.setWidth("10");
+        result.execute(actionInvocation);
+
+        EasyMock.verify(responseMock);
+        assertTrue(os.isWritten());
+    }
+    
+    public void testContentTypePng() throws Exception {
+        EasyMock.expect(responseMock.getOutputStream()).andReturn(os);
+        responseMock.setContentType("image/png");
+        EasyMock.replay(responseMock, mockActionProxy, actionInvocation);
+        ChartResult result = new ChartResult();
+
+        result.setChart(mockChart);
+
+        result.setHeight("10");
+        result.setWidth("10");
+        result.setType("png");
+        result.execute(actionInvocation);
 
+        EasyMock.verify(responseMock);
+        assertTrue(os.isWritten());
+    }
+    
+    public void testContentTypeJpg() throws Exception {
+        EasyMock.expect(responseMock.getOutputStream()).andReturn(os);
+        responseMock.setContentType("image/jpg");
+        EasyMock.replay(responseMock, mockActionProxy, actionInvocation);
         ChartResult result = new ChartResult();
 
         result.setChart(mockChart);
 
         result.setHeight("10");
         result.setWidth("10");
+        result.setType("jpg");
         result.execute(actionInvocation);
 
-        responseMock.verify();
+        EasyMock.verify(responseMock);
         assertTrue(os.isWritten());
     }
 
+
     public void testChartNotSet() {
         ChartResult result = new ChartResult();
-
+        EasyMock.replay(responseMock, mockActionProxy, actionInvocation);
+        
         // expect exception if chart not set.
         result.setChart(null);
 
@@ -76,13 +114,14 @@
         } catch (Exception e) {
         }
 
-        responseMock.verify();
+        EasyMock.verify(responseMock);
         assertFalse(os.isWritten());
     }
 
 
     public void testChartWithOGNLProperties() throws Exception {
-        responseMock.expectAndReturn("getOutputStream", os);
+        EasyMock.expect(responseMock.getOutputStream()).andReturn(os);
+        EasyMock.replay(responseMock, mockActionProxy, actionInvocation);
 
 
         ChartResult result = new ChartResult();
@@ -98,7 +137,7 @@
 
         result.execute(actionInvocation);
 
-        responseMock.verify();
+        EasyMock.verify(responseMock);
         assertEquals(result.getHeight(), stack.findValue("myHeight").toString());
         assertEquals(result.getWidth(), stack.findValue("myWidth").toString());
         assertEquals("250", result.getHeight().toString());
@@ -120,20 +159,18 @@
         ActionContext.getContext().setValueStack(stack);
 
 
-        mockActionProxy = new Mock(ActionProxy.class);
-        mockActionProxy.expectAndReturn("getNamespace", "/html");
+        mockActionProxy = EasyMock.createNiceMock(ActionProxy.class);
+        EasyMock.expect(mockActionProxy.getNamespace()).andReturn("/html");
 
-        Mock mockActionInvocation = new Mock(ActionInvocation.class);
+        actionInvocation = EasyMock.createMock(ActionInvocation.class);
 
-        mockActionInvocation.matchAndReturn("getStack", stack);
-//        mockActionInvocation.expectAndReturn("getProxy", mockActionProxy.proxy());
+        EasyMock.expect(actionInvocation.getStack()).andReturn(stack).anyTimes();
         
-        actionInvocation = (ActionInvocation) mockActionInvocation.proxy();
         
         os = new MockServletOutputStream();
-        responseMock = new Mock(HttpServletResponse.class);
+        responseMock = EasyMock.createNiceMock(HttpServletResponse.class);
 
-        ServletActionContext.setResponse((HttpServletResponse) responseMock.proxy());
+        ServletActionContext.setResponse((HttpServletResponse) responseMock);
     }
 
     protected void tearDown() throws Exception {



Mime
View raw message