maven-wagon-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r662218 - in /maven/wagon/trunk/wagon-provider-api: ./ src/test/java/org/apache/maven/wagon/ src/test/java/org/apache/maven/wagon/events/
Date Sun, 01 Jun 2008 14:18:33 GMT
Author: brett
Date: Sun Jun  1 07:18:33 2008
New Revision: 662218

URL: http://svn.apache.org/viewvc?rev=662218&view=rev
Log:
use easymock instead of mocks in some cases

Added:
    maven/wagon/trunk/wagon-provider-api/src/test/java/org/apache/maven/wagon/AbstractWagonTest.java
Modified:
    maven/wagon/trunk/wagon-provider-api/pom.xml
    maven/wagon/trunk/wagon-provider-api/src/test/java/org/apache/maven/wagon/events/SessionEventSupportTest.java
    maven/wagon/trunk/wagon-provider-api/src/test/java/org/apache/maven/wagon/events/SessionEventTest.java
    maven/wagon/trunk/wagon-provider-api/src/test/java/org/apache/maven/wagon/events/TransferEventSupportTest.java
    maven/wagon/trunk/wagon-provider-api/src/test/java/org/apache/maven/wagon/events/TransferEventTest.java

Modified: maven/wagon/trunk/wagon-provider-api/pom.xml
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-provider-api/pom.xml?rev=662218&r1=662217&r2=662218&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-provider-api/pom.xml (original)
+++ maven/wagon/trunk/wagon-provider-api/pom.xml Sun Jun  1 07:18:33 2008
@@ -36,5 +36,11 @@
       <groupId>org.codehaus.plexus</groupId>
       <artifactId>plexus-utils</artifactId>
     </dependency>
+    <dependency>
+      <groupId>easymock</groupId>
+      <artifactId>easymock</artifactId>
+      <version>1.2_Java1.3</version>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 </project>

Added: maven/wagon/trunk/wagon-provider-api/src/test/java/org/apache/maven/wagon/AbstractWagonTest.java
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-provider-api/src/test/java/org/apache/maven/wagon/AbstractWagonTest.java?rev=662218&view=auto
==============================================================================
--- maven/wagon/trunk/wagon-provider-api/src/test/java/org/apache/maven/wagon/AbstractWagonTest.java
(added)
+++ maven/wagon/trunk/wagon-provider-api/src/test/java/org/apache/maven/wagon/AbstractWagonTest.java
Sun Jun  1 07:18:33 2008
@@ -0,0 +1,266 @@
+package org.apache.maven.wagon;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.File;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import junit.framework.TestCase;
+
+import org.apache.maven.wagon.authentication.AuthenticationException;
+import org.apache.maven.wagon.authorization.AuthorizationException;
+import org.apache.maven.wagon.events.SessionListener;
+import org.apache.maven.wagon.events.TransferListener;
+import org.apache.maven.wagon.repository.Repository;
+import org.codehaus.plexus.util.IOUtil;
+import org.easymock.MockControl;
+
+/**
+ * @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
+ * @version $Id$
+ */
+public class AbstractWagonTest
+    extends TestCase
+{
+    private String basedir;
+
+    private WagonMock wagon = null;
+
+    private File destination;
+
+    private File source;
+
+    private String artifact;
+
+    private SessionListener sessionListener = null;
+
+    private TransferListener transferListener = null;
+
+    private MockControl transferListenerControl;
+
+    private MockControl sessionListenerControl;
+
+    protected void setUp()
+        throws Exception
+    {
+        super.setUp();
+
+        basedir = System.getProperty( "basedir" );
+
+        destination = new File( basedir, "target/folder/subfolder" );
+
+        source = new File( basedir, "pom.xml" );
+
+        wagon = new WagonMock();
+
+        sessionListenerControl = MockControl.createControl( SessionListener.class ); 
+        sessionListener = (SessionListener) sessionListenerControl.getMock();
+
+        wagon.addSessionListener( sessionListener );
+
+        transferListenerControl = MockControl.createControl( TransferListener.class ); 
+        transferListener = (TransferListener) transferListenerControl.getMock();
+
+        wagon.addTransferListener( transferListener );
+
+    }
+
+    public void testSessionListenerRegistration()
+    {
+        assertTrue( wagon.hasSessionListener( sessionListener ) );
+
+        wagon.removeSessionListener( sessionListener );
+
+        assertFalse( wagon.hasSessionListener( sessionListener ) );
+    }
+
+    public void testTransferListenerRegistration()
+    {
+        assertTrue( wagon.hasTransferListener( transferListener ) );
+
+        wagon.removeTransferListener( transferListener );
+
+        assertFalse( wagon.hasTransferListener( transferListener ) );
+    }
+
+    public void testSessionOpenEvents()
+        throws Exception
+    {
+        Repository repository = new Repository();
+
+        sessionListenerControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER );
+        sessionListener.sessionOpening( null );
+        sessionListener.sessionOpened( null );
+        sessionListenerControl.replay();
+        
+        wagon.connect( repository );
+        
+        sessionListenerControl.verify();
+
+        assertEquals( repository, wagon.getRepository() );
+    }
+
+    public void testSessionCloseEvents()
+        throws Exception
+    {
+        sessionListenerControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER );
+        sessionListener.sessionDisconnecting( null );
+        sessionListener.sessionDisconnected( null );
+        sessionListenerControl.replay();
+        
+        wagon.disconnect();
+        
+        sessionListenerControl.verify();
+    }
+
+    public void testGetTransferEvents()
+        throws Exception
+    {
+        transferListener.debug( "fetch debug message" );
+        transferListenerControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER );
+        transferListener.transferInitiated( null );
+        transferListener.transferStarted( null );
+        transferListener.debug( null );
+        transferListenerControl.setVoidCallable( MockControl.ZERO_OR_MORE );
+        transferListener.transferProgress( null, null, 0 );
+        transferListenerControl.setVoidCallable( 5 );
+        transferListener.transferCompleted( null );
+        transferListenerControl.replay();
+        
+        wagon.fireTransferDebug( "fetch debug message" );
+
+        Repository repository = new Repository();
+        wagon.connect( repository );
+
+        wagon.get( artifact, destination );
+        
+        transferListenerControl.verify();
+    }
+
+    public void testGetError()
+        throws Exception
+    {
+        transferListenerControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER );
+        transferListener.transferInitiated( null );
+        transferListener.transferStarted( null );        
+        transferListener.debug( null );
+        transferListenerControl.setVoidCallable( MockControl.ZERO_OR_MORE );
+        transferListener.transferError( null );
+        transferListenerControl.replay();
+        
+        try
+        {
+            Repository repository = new Repository();
+
+            WagonMock wagon = new WagonMock( true );
+
+            wagon.addTransferListener( transferListener );
+
+            wagon.connect( repository );
+
+            wagon.get( artifact, destination );
+
+            fail( "Transfer error was expected during deploy" );
+        }
+        catch ( TransferFailedException expected )
+        {
+            assertTrue( true );
+        }
+
+        transferListenerControl.verify();
+    }
+
+    public void testPutTransferEvents()
+        throws ConnectionException, AuthenticationException, ResourceDoesNotExistException,
TransferFailedException,
+        AuthorizationException
+    {
+        transferListener.debug( "deploy debug message" );
+        transferListenerControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER );
+        transferListener.transferInitiated( null );
+        transferListener.transferStarted( null );
+        transferListener.transferProgress( null, null, 0 );
+        transferListener.transferCompleted( null );
+        transferListenerControl.replay();
+        
+        wagon.fireTransferDebug( "deploy debug message" );
+
+        Repository repository = new Repository();
+
+        wagon.connect( repository );
+
+        wagon.put( source, artifact );
+
+        transferListenerControl.verify();
+    }
+
+    /*
+    public void testPutError()
+    {
+        MockInputStream mockInputStream = new MockInputStream();
+
+        //forced io error!
+        mockInputStream.setForcedError( true );
+
+        StreamSource result = new StreamSource( mockInputStream );
+
+        PutRequest command = new PutRequest( result, "my favourite resource" );
+
+        try
+        {
+            wagon.transfer( command );
+
+            fail( "Transfer error was expected during fetch" );
+        }
+        catch ( Exception e )
+        {
+        }
+
+        assertTrue( transferListener.isTransferStartedCalled() );
+
+        assertTrue( transferListener.isTransferErrorCalled() );
+
+        assertFalse( transferListener.isTransferCompletedCalled() );
+    }
+    */
+
+    public void testStreamShutdown()
+    {
+        IOUtil.close( (InputStream) null );
+
+        IOUtil.close( (OutputStream) null );
+
+        InputStreamMock inputStream = new InputStreamMock();
+
+        assertFalse( inputStream.isClosed() );
+
+        IOUtil.close( inputStream );
+
+        assertTrue( inputStream.isClosed() );
+
+        OutputStreamMock outputStream = new OutputStreamMock();
+
+        assertFalse( outputStream.isClosed() );
+
+        IOUtil.close( outputStream );
+
+        assertTrue( outputStream.isClosed() );
+    }
+}

Modified: maven/wagon/trunk/wagon-provider-api/src/test/java/org/apache/maven/wagon/events/SessionEventSupportTest.java
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-provider-api/src/test/java/org/apache/maven/wagon/events/SessionEventSupportTest.java?rev=662218&r1=662217&r2=662218&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-provider-api/src/test/java/org/apache/maven/wagon/events/SessionEventSupportTest.java
(original)
+++ maven/wagon/trunk/wagon-provider-api/src/test/java/org/apache/maven/wagon/events/SessionEventSupportTest.java
Sun Jun  1 07:18:33 2008
@@ -20,8 +20,9 @@
  */
 
 import junit.framework.TestCase;
-import org.apache.maven.wagon.WagonMock;
+
 import org.apache.maven.wagon.Wagon;
+import org.easymock.MockControl;
 
 /**
  * @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
@@ -33,6 +34,9 @@
 
     private SessionEventSupport eventSupport;
 
+    private MockControl wagonMockControl;
+    
+    private Wagon wagon;
 
     /**
      * @see junit.framework.TestCase#setUp()
@@ -43,6 +47,11 @@
         super.setUp();
 
         eventSupport = new SessionEventSupport();
+        
+        // TODO: actually test it gets called?
+        wagonMockControl = MockControl.createControl( Wagon.class );
+        
+        wagon = (Wagon) wagonMockControl.getMock();
     }
 
     public void testSessionListenerRegistration()
@@ -85,8 +94,6 @@
 
         eventSupport.addSessionListener( mock2 );
 
-        final Wagon wagon = new WagonMock();
-
         final SessionEvent event = new SessionEvent( wagon, 1 );
 
         eventSupport.fireSessionDisconnected( event );
@@ -111,8 +118,6 @@
 
         eventSupport.addSessionListener( mock2 );
 
-        final Wagon wagon = new WagonMock();
-
         final SessionEvent event = new SessionEvent( wagon, 1 );
 
         eventSupport.fireSessionDisconnecting( event );
@@ -136,8 +141,6 @@
 
         eventSupport.addSessionListener( mock2 );
 
-        final Wagon wagon = new WagonMock();
-
         final SessionEvent event = new SessionEvent( wagon, 1 );
 
         eventSupport.fireSessionLoggedIn( event );
@@ -162,8 +165,6 @@
 
         eventSupport.addSessionListener( mock2 );
 
-        final Wagon wagon = new WagonMock();
-
         final SessionEvent event = new SessionEvent( wagon, 1 );
 
         eventSupport.fireSessionLoggedOff( event );
@@ -188,8 +189,6 @@
 
         eventSupport.addSessionListener( mock2 );
 
-        final Wagon wagon = new WagonMock();
-
         final SessionEvent event = new SessionEvent( wagon, 1 );
 
         eventSupport.fireSessionOpened( event );
@@ -215,8 +214,6 @@
 
         eventSupport.addSessionListener( mock2 );
 
-        final Wagon wagon = new WagonMock();
-
         final SessionEvent event = new SessionEvent( wagon, 1 );
 
         eventSupport.fireSessionOpening( event );
@@ -241,8 +238,6 @@
 
         eventSupport.addSessionListener( mock2 );
 
-        final Wagon wagon = new WagonMock();
-
         final SessionEvent event = new SessionEvent( wagon, 1 );
 
         eventSupport.fireSessionConnectionRefused( event );
@@ -277,5 +272,5 @@
         assertEquals( "mm", mock2.getDebugMessage() );
 
     }
-
+    
 }

Modified: maven/wagon/trunk/wagon-provider-api/src/test/java/org/apache/maven/wagon/events/SessionEventTest.java
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-provider-api/src/test/java/org/apache/maven/wagon/events/SessionEventTest.java?rev=662218&r1=662217&r2=662218&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-provider-api/src/test/java/org/apache/maven/wagon/events/SessionEventTest.java
(original)
+++ maven/wagon/trunk/wagon-provider-api/src/test/java/org/apache/maven/wagon/events/SessionEventTest.java
Sun Jun  1 07:18:33 2008
@@ -21,10 +21,10 @@
 
 import junit.framework.TestCase;
 import org.apache.maven.wagon.ConnectionException;
-import org.apache.maven.wagon.WagonMock;
 import org.apache.maven.wagon.Wagon;
 import org.apache.maven.wagon.authentication.AuthenticationException;
 import org.apache.maven.wagon.repository.Repository;
+import org.easymock.MockControl;
 
 /**
  * @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
@@ -33,26 +33,6 @@
 public class SessionEventTest
     extends TestCase
 {
-
-    /*
-	 * @see TestCase#setUp()
-	 */
-    protected void setUp()
-        throws Exception
-    {
-        super.setUp();
-    }
-
-    /**
-     * Constructor for SESSIONEventTest.
-     *
-     * @param arg0
-     */
-    public SessionEventTest( final String arg0 )
-    {
-        super( arg0 );
-    }
-
     /*
 	 * Class to test for void SESSIONEvent(Wagon, Repository, String, int,
 	 * int)
@@ -61,7 +41,7 @@
         throws ConnectionException, AuthenticationException
     {
 
-        final Wagon wagon = new WagonMock();
+        final Wagon wagon = (Wagon) MockControl.createControl( Wagon.class ).getMock();
         final Repository repo = new Repository();
 
         wagon.connect( repo );
@@ -72,14 +52,12 @@
         SessionEvent event = new SessionEvent( wagon, SessionEvent.SESSION_CLOSED );
 
         assertEquals( wagon, event.getWagon() );
-        assertEquals( repo, event.getWagon().getRepository() );
 
         assertEquals( SessionEvent.SESSION_CLOSED, event.getEventType() );
 
         event = new SessionEvent( wagon, exception );
 
         assertEquals( wagon, event.getWagon() );
-        assertEquals( repo, event.getWagon().getRepository() );
         assertEquals( SessionEvent.SESSION_ERROR_OCCURRED, event.getEventType() );
         assertEquals( exception, event.getException() );
 

Modified: maven/wagon/trunk/wagon-provider-api/src/test/java/org/apache/maven/wagon/events/TransferEventSupportTest.java
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-provider-api/src/test/java/org/apache/maven/wagon/events/TransferEventSupportTest.java?rev=662218&r1=662217&r2=662218&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-provider-api/src/test/java/org/apache/maven/wagon/events/TransferEventSupportTest.java
(original)
+++ maven/wagon/trunk/wagon-provider-api/src/test/java/org/apache/maven/wagon/events/TransferEventSupportTest.java
Sun Jun  1 07:18:33 2008
@@ -20,8 +20,8 @@
  */
 
 import junit.framework.TestCase;
-import org.apache.maven.wagon.WagonMock;
 import org.apache.maven.wagon.Wagon;
+import org.easymock.MockControl;
 
 /**
  * @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
@@ -31,19 +31,26 @@
 public class TransferEventSupportTest
     extends TestCase
 {
-
     private TransferEventSupport eventSupport;
 
+    private MockControl wagonMockControl;
+    
+    private Wagon wagon;
+
     /**
      * @see junit.framework.TestCase#setUp()
      */
     protected void setUp()
         throws Exception
     {
-
         super.setUp();
+        
         eventSupport = new TransferEventSupport();
-
+        
+        // TODO: actually test it gets called?
+        wagonMockControl = MockControl.createControl( Wagon.class );
+        
+        wagon = (Wagon) wagonMockControl.getMock();
     }
 
     public void testTransferListenerRegistration()
@@ -78,7 +85,6 @@
         final TransferListenerMock mock2 = new TransferListenerMock();
         eventSupport.addTransferListener( mock2 );
 
-        final Wagon wagon = new WagonMock();
         final TransferEvent event = getEvent( wagon );
 
         eventSupport.fireTransferStarted( event );
@@ -100,8 +106,6 @@
 
         eventSupport.addTransferListener( mock2 );
 
-        final Wagon wagon = new WagonMock();
-
         final TransferEvent event = getEvent( wagon );
 
         // TODO: should be testing the buffer
@@ -126,8 +130,6 @@
 
         eventSupport.addTransferListener( mock2 );
 
-        final Wagon wagon = new WagonMock();
-
         final TransferEvent event = getEvent( wagon );
 
         eventSupport.fireTransferCompleted( event );
@@ -152,8 +154,6 @@
 
         eventSupport.addTransferListener( mock2 );
 
-        final Wagon wagon = new WagonMock();
-
         final TransferEvent event = getEvent( wagon );
 
         eventSupport.fireTransferError( event );

Modified: maven/wagon/trunk/wagon-provider-api/src/test/java/org/apache/maven/wagon/events/TransferEventTest.java
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-provider-api/src/test/java/org/apache/maven/wagon/events/TransferEventTest.java?rev=662218&r1=662217&r2=662218&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-provider-api/src/test/java/org/apache/maven/wagon/events/TransferEventTest.java
(original)
+++ maven/wagon/trunk/wagon-provider-api/src/test/java/org/apache/maven/wagon/events/TransferEventTest.java
Sun Jun  1 07:18:33 2008
@@ -21,11 +21,11 @@
 
 import junit.framework.TestCase;
 import org.apache.maven.wagon.ConnectionException;
-import org.apache.maven.wagon.WagonMock;
 import org.apache.maven.wagon.Wagon;
 import org.apache.maven.wagon.authentication.AuthenticationException;
 import org.apache.maven.wagon.repository.Repository;
 import org.apache.maven.wagon.resource.Resource;
+import org.easymock.MockControl;
 
 /**
  * @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
@@ -34,22 +34,6 @@
 public class TransferEventTest
     extends TestCase
 {
-
-    public TransferEventTest( final String name )
-    {
-        super( name );
-    }
-
-    /*
-     * @see TestCase#setUp()
-     */
-    protected void setUp()
-        throws Exception
-    {
-        super.setUp();
-    }
-
-
     /*
      * Class to test for void TransferEvent(Wagon, Repository, String, int,
      * int)
@@ -57,8 +41,7 @@
     public void testTransferEventProperties()
         throws ConnectionException, AuthenticationException
     {
-
-        final Wagon wagon = new WagonMock();
+        final Wagon wagon = (Wagon) MockControl.createControl( Wagon.class ).getMock();
 
         final Repository repo = new Repository();
 
@@ -77,8 +60,6 @@
 
         assertEquals( wagon, event.getWagon() );
 
-        assertEquals( repo, event.getWagon().getRepository() );
-
         assertEquals( "mm", event.getResource().getName() );
 
         assertEquals( TransferEvent.TRANSFER_COMPLETED, event.getEventType() );
@@ -93,8 +74,6 @@
 
         assertEquals( wagon, event.getWagon() );
 
-        assertEquals( repo, event.getWagon().getRepository() );
-
         assertEquals( "mm", event.getResource().getName() );
 
         assertEquals( TransferEvent.TRANSFER_ERROR, event.getEventType() );



---------------------------------------------------------------------
To unsubscribe, e-mail: wagon-commits-unsubscribe@maven.apache.org
For additional commands, e-mail: wagon-commits-help@maven.apache.org


Mime
View raw message