geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject cvs commit: incubator-geronimo/modules/core/src/test/org/apache/geronimo/test/protocol/mockproto Handler.java MockInputStream.java MockURLConnection.java
Date Sat, 30 Aug 2003 12:32:32 GMT
jdillon     2003/08/30 05:32:32

  Modified:    modules/core/src/test/org/apache/geronimo/deployment/repository
                        DownloadTest.java
  Added:       modules/core/src/test/org/apache/geronimo/test/protocol/mockproto
                        Handler.java MockInputStream.java
                        MockURLConnection.java
  Log:
   o Applied modified patch GERONIMO-38 (patch2)
  
  Revision  Changes    Path
  1.2       +65 -44    incubator-geronimo/modules/core/src/test/org/apache/geronimo/deployment/repository/DownloadTest.java
  
  Index: DownloadTest.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/core/src/test/org/apache/geronimo/deployment/repository/DownloadTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DownloadTest.java	12 Aug 2003 04:16:47 -0000	1.1
  +++ DownloadTest.java	30 Aug 2003 12:32:32 -0000	1.2
  @@ -62,20 +62,77 @@
   
   import junit.framework.TestCase;
   
  +import org.apache.geronimo.common.net.protocol.Protocols;
  +
  +import org.apache.geronimo.test.protocol.mockproto.Handler;
  +import org.apache.geronimo.test.protocol.mockproto.MockURLConnection;
  +
   /**
    * 
    * 
    * @version $Revision$ $Date$
    */
  -public class DownloadTest extends TestCase {
  +public class DownloadTest
  +    extends TestCase
  +{
       private File localRoot;
       private File fakeRemoteRoot;
       private ComponentRepository repo;
       private ComponentDescription desc;
       private ComponentDescription desc2;
       private ComponentDescription desc3;
  +    private MockURLConnection urlConnection;
       private File testArchive;
  +    
  +    protected void setUp() throws Exception {
  +        Protocols.appendHandlerPackage("org.apache.geronimo.test.protocol");
  +        
  +        File temp = new File(System.getProperty("java.io.tmpdir"));
  +        localRoot = new File(temp, "localRepo");
  +
  +        desc = new ComponentDescription("product", "1.1.1", "myproduct/product-1.1.1.txt");
  +        fakeRemoteRoot = new File(temp, "remoteRepo");
  +        testArchive = new File(fakeRemoteRoot, desc.getLocation());
  +        testArchive.getParentFile().mkdirs();
  +        testArchive.createNewFile();
  +        FileOutputStream fos = new FileOutputStream(testArchive);
  +        PrintWriter writer = new PrintWriter(fos);
  +        writer.println("Hello World");
  +        writer.flush();
  +        writer.close();
  +
  +        String location = "commons-logging/jars/commons-logging-1.0.1.jar";
  +        desc2 = new ComponentDescription("commons-logging", "1.0.1", location);
  +        desc3 = new ComponentDescription("nosuchfile", "noversion", "nolocation");
  +
  +        repo = new ComponentRepository(localRoot);
  +        repo.addRemoteRoot(fakeRemoteRoot.toURL());
  +
  +        String urlspec = "mockproto://www.ibiblio.org/maven/";
  +        urlConnection =  Handler.registerURL(urlspec + location, "This is test file content");
  +        repo.addRemoteRoot(new URL(urlspec));
  +    }
  +
  +    protected void tearDown() throws Exception {
  +        Protocols.setHandlerPackages(Protocols.getSystemHandlerPackages());
  +        
  +        recursiveDelete(localRoot);
  +        recursiveDelete(fakeRemoteRoot);
  +    }
   
  +    private void recursiveDelete(File root) throws Exception {
  +        File[] files = root.listFiles();
  +        for (int i = 0; i < files.length; i++) {
  +            File file = files[i];
  +            if (file.isDirectory()) {
  +                recursiveDelete(file);
  +            } else {
  +                file.delete();
  +            }
  +        }
  +        root.delete();
  +    }
  +    
       public void testLocalCopy() throws Exception {
           assertTrue(repo.ensureLocal(desc));
   
  @@ -106,12 +163,18 @@
   
           repo.removeLocal(desc2);
           assertFalse(localFile.exists());
  +
  +        assertTrue("Was expecting clean up of resources",
  +                urlConnection.getState() == MockURLConnection.STATE_CLOSED);
       }
   
       public void testNotFound() throws Exception {
           assertFalse(repo.ensureLocal(desc3));
           File localFile = new File(localRoot, desc3.getLocation());
           assertFalse(localFile.exists());
  +        assertTrue("Was expecting clean up",
  +                ( urlConnection.getState() == MockURLConnection.STATE_CLOSED 
  +                 || urlConnection.getState() == MockURLConnection.STATE_INIT));
       }
   
       private void sleep(long naptime) {
  @@ -120,47 +183,5 @@
           } catch (InterruptedException e) {
               // ignore
           }
  -    }
  -    protected void setUp() throws Exception {
  -        super.setUp();
  -        File temp = new File(System.getProperty("java.io.tmpdir"));
  -        localRoot = new File(temp, "localRepo");
  -
  -        desc = new ComponentDescription("product", "1.1.1", "myproduct/product-1.1.1.txt");
  -        fakeRemoteRoot = new File(temp, "remoteRepo");
  -        testArchive = new File(fakeRemoteRoot, desc.getLocation());
  -        testArchive.getParentFile().mkdirs();
  -        testArchive.createNewFile();
  -        FileOutputStream fos = new FileOutputStream(testArchive);
  -        PrintWriter writer = new PrintWriter(fos);
  -        writer.println("Hello World");
  -        writer.flush();
  -        writer.close();
  -
  -        desc2 = new ComponentDescription("commons-logging", "1.0.1", "commons-logging/jars/commons-logging-1.0.1.jar");
  -        desc3 = new ComponentDescription("nosuchfile", "noversion", "nolocation");
  -
  -        repo = new ComponentRepository(localRoot);
  -        repo.addRemoteRoot(fakeRemoteRoot.toURL());
  -        repo.addRemoteRoot(new URL("http://www.ibiblio.org/maven/"));
  -    }
  -
  -    protected void tearDown() throws Exception {
  -        super.tearDown();
  -        recursiveDelete(localRoot);
  -        recursiveDelete(fakeRemoteRoot);
  -    }
  -
  -    private void recursiveDelete(File root) throws Exception {
  -        File[] files = root.listFiles();
  -        for (int i = 0; i < files.length; i++) {
  -            File file = files[i];
  -            if (file.isDirectory()) {
  -                recursiveDelete(file);
  -            } else {
  -                file.delete();
  -            }
  -        }
  -        root.delete();
       }
   }
  
  
  
  1.1                  incubator-geronimo/modules/core/src/test/org/apache/geronimo/test/protocol/mockproto/Handler.java
  
  Index: Handler.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  
  package org.apache.geronimo.test.protocol.mockproto;
  
  import java.net.URLConnection;
  import java.net.URL;
  import java.net.MalformedURLException;
  import java.net.URLStreamHandler;
  
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.StringBufferInputStream;
  
  import java.util.HashMap;
  import java.util.Map;
  
  /**
   * URL handler foe the 'mockproto' protocol.
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/30 12:32:32 $
   */
  public class Handler
      extends URLStreamHandler
  {
      static Map urlMap = new HashMap();
  
      protected URLConnection openConnection(URL u) throws IOException {
          if (urlMap.containsKey(u)) {
              return (URLConnection) urlMap.get(u);
          } else {
              throw new IOException("Don't have the url in my map");
          }
      }
      
      public static MockURLConnection registerURL(String urlspec, String contents)
          throws MalformedURLException
      {
          URL url = new URL(urlspec);
          MockURLConnection c = new MockURLConnection(url, contents);
          urlMap.put(url, c);
          
          return c;
      }
  }
  
  
  
  
  1.1                  incubator-geronimo/modules/core/src/test/org/apache/geronimo/test/protocol/mockproto/MockInputStream.java
  
  Index: MockInputStream.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  
  package org.apache.geronimo.test.protocol.mockproto;
  
  import java.io.StringBufferInputStream;
  import java.io.IOException;
  
  /**
   * A mock input stream for mockproto urls.
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/30 12:32:32 $
   */
  public final class MockInputStream
      extends StringBufferInputStream
  {
      private MockURLConnection conn;
  
      public MockInputStream(MockURLConnection conn, String s) {
          super(s);
          this.conn = conn;
      }
  
      public void close() throws IOException {
          conn.close();
      }
  }
  
  
  1.1                  incubator-geronimo/modules/core/src/test/org/apache/geronimo/test/protocol/mockproto/MockURLConnection.java
  
  Index: MockURLConnection.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  
  package org.apache.geronimo.test.protocol.mockproto;
  
  import java.net.URLConnection;
  import java.net.URL;
  import java.io.IOException;
  import java.io.InputStream;
  
  /**
   * URL connection for the 'mockproto' protocol.
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/30 12:32:32 $
   */
  public final class MockURLConnection
      extends URLConnection
  {
      private String urlContents;
      private int state;
  
      public static int STATE_INIT = 0;
      public static int STATE_OPENED = 1;
      public static int STATE_CLOSED = 2;
  
      public MockURLConnection(URL url, String urlContents) {
          super(url);
          this.urlContents = urlContents;
          this.state = STATE_INIT;
      }
  
      public void connect() throws IOException {
          this.state = STATE_OPENED;
      }
  
      public InputStream getInputStream() {
          return new MockInputStream(this, urlContents);
      }
  
      public void close() throws IOException {
          if (this.state != STATE_CLOSED) {
              this.state = STATE_CLOSED;
          }
          else {
              throw new IOException("Closing an already closed connection");
          }
      }
  
      public int getState() {
          return this.state;
      }
  }
  
  
  

Mime
View raw message