cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1244332 - /cxf/branches/2.5.x-fixes/rt/core/src/test/java/org/apache/cxf/interceptor/LoggingOutInterceptorTest.java
Date Wed, 15 Feb 2012 03:48:34 GMT
Author: dkulp
Date: Wed Feb 15 03:48:33 2012
New Revision: 1244332

URL: http://svn.apache.org/viewvc?rev=1244332&view=rev
Log:
Merged revisions 1242831 via  git cherry-pick from
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1242831 | asoldano | 2012-02-10 10:58:09 -0500 (Fri, 10 Feb 2012) | 2 lines

  [CXF-4030] Add option for setting in-memory threshold for dealing with messages caching
in logging interceptors

........

Modified:
    cxf/branches/2.5.x-fixes/rt/core/src/test/java/org/apache/cxf/interceptor/LoggingOutInterceptorTest.java

Modified: cxf/branches/2.5.x-fixes/rt/core/src/test/java/org/apache/cxf/interceptor/LoggingOutInterceptorTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/core/src/test/java/org/apache/cxf/interceptor/LoggingOutInterceptorTest.java?rev=1244332&r1=1244331&r2=1244332&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/core/src/test/java/org/apache/cxf/interceptor/LoggingOutInterceptorTest.java
(original)
+++ cxf/branches/2.5.x-fixes/rt/core/src/test/java/org/apache/cxf/interceptor/LoggingOutInterceptorTest.java
Wed Feb 15 03:48:33 2012
@@ -20,29 +20,48 @@
 package org.apache.cxf.interceptor;
 
 import java.io.ByteArrayOutputStream;
+import java.io.OutputStream;
 import java.io.PrintWriter;
 import java.util.logging.Logger;
 
 import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.io.CachedOutputStream;
 import org.apache.cxf.message.ExchangeImpl;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.message.MessageImpl;
-
+import org.apache.cxf.service.model.EndpointInfo;
+import org.easymock.EasyMock;
+import org.easymock.IMocksControl;
+import org.junit.After;
 import org.junit.Assert;
+import org.junit.Before;
 import org.junit.Test;
 
 public class LoggingOutInterceptorTest extends Assert {
-    
+
+    protected IMocksControl control;
+
+    @Before
+    public void setUp() throws Exception {
+        control = EasyMock.createNiceControl();
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        control.verify();
+    }
+
     @Test
-    public void testFormatting() throws Exception { 
+    public void testFormatting() throws Exception {
+        control.replay();
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         PrintWriter pw = new PrintWriter(baos);
         
         LoggingOutInterceptor p = new LoggingOutInterceptor(pw);
         //p.setPrettyLogging(true);
         CachedOutputStream cos = new CachedOutputStream();
-        String s = "<today><is><the><twenty> <second> <of>
<january> <two> <thousand> <and> <nine></nine> " 
+        String s = "<today><is><the><twenty> <second> <of>
<january> <two> <thousand> <and> <nine></nine> "
             + "</and></thousand></two></january></of></second></twenty></the></is></today>";
         cos.write(s.getBytes());
         Message message = new MessageImpl();
@@ -57,4 +76,40 @@ public class LoggingOutInterceptorTest e
         assertTrue(str.contains("<today>"));
 
     }
+
+    @Test
+    public void testCachedOutputStreamThreshold() throws Exception {
+        byte[] mex = "<test><threshold/></test>".getBytes();
+
+        LoggingOutInterceptor p = new LoggingOutInterceptor();
+        p.setInMemThreshold(mex.length);
+
+        CachedOutputStream cos = handleAndGetCachedOutputStream(p);
+        cos.write(mex);
+        assertNull(cos.getTempFile());
+        cos.write("a".getBytes());
+        assertNotNull(cos.getTempFile());
+    }
+
+    private CachedOutputStream handleAndGetCachedOutputStream(LoggingOutInterceptor interceptor)
{
+        interceptor.setPrintWriter(new PrintWriter(new ByteArrayOutputStream()));
+
+        Endpoint endpoint = control.createMock(Endpoint.class);
+        EndpointInfo endpointInfo = control.createMock(EndpointInfo.class);
+        EasyMock.expect(endpoint.getEndpointInfo()).andReturn(endpointInfo).anyTimes();
+        control.replay();
+
+        Message message = new MessageImpl();
+        ExchangeImpl exchange = new ExchangeImpl();
+        message.setExchange(exchange);
+        exchange.put(Endpoint.class, endpoint);
+
+        message.put(Message.CONTENT_TYPE, "application/xml");
+        message.setContent(OutputStream.class, new ByteArrayOutputStream());
+        interceptor.handleMessage(message);
+        OutputStream os = message.getContent(OutputStream.class);
+        assertTrue(os instanceof CachedOutputStream);
+        return (CachedOutputStream)os;
+    }
+
 }



Mime
View raw message