geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gdam...@apache.org
Subject cvs commit: incubator-geronimo/sandbox/webdav/src/test/org/apache/geronimo/datastore/impl/remote RemoteUseCaseTest.java
Date Sun, 29 Feb 2004 13:14:11 GMT
gdamour     2004/02/29 05:14:11

  Added:       sandbox/webdav/src/test/org/apache/geronimo/datastore/impl/local
                        LocalUseCaseTest.java AbstractUseCaseTest.java
                        LocalGFileDAOTest.java
               sandbox/webdav/src/test/org/apache/geronimo/datastore
                        Util.java
               sandbox/webdav/src/test/org/apache/geronimo/datastore/impl
                        DirtyMarkerImplTest.java
               sandbox/webdav/src/test/org/apache/geronimo/datastore/impl/remote
                        RemoteUseCaseTest.java
  Log:
  Local and remote use-case of a GFileManager.
  
  Revision  Changes    Path
  1.1                  incubator-geronimo/sandbox/webdav/src/test/org/apache/geronimo/datastore/impl/local/LocalUseCaseTest.java
  
  Index: LocalUseCaseTest.java
  ===================================================================
  /**
   *
   * Copyright 2004 The Apache Software Foundation
   *
   *  Licensed 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.
   */
  
  package org.apache.geronimo.datastore.impl.local;
  
  import java.io.File;
  
  import org.apache.geronimo.datastore.Util;
  import org.apache.geronimo.datastore.impl.LockManager;
  import org.apache.geronimo.datastore.impl.local.LocalGFileManager;
  
  /**
   * This is a simple use-case.
   *
   * @version $Revision: 1.1 $ $Date: 2004/02/29 13:14:11 $
   */
  public class LocalUseCaseTest extends AbstractUseCaseTest {
  
      protected void setUp() throws Exception {
          LockManager lockManager = new LockManager();
          File root = new File(System.getProperty("java.io.tmpdir"),
                  "GFileManager");
          Util.recursiveDelete(root);
          root.mkdir();
          
          fileManager = new LocalGFileManager("test", root, lockManager);
      }
      
  }
  
  
  
  1.1                  incubator-geronimo/sandbox/webdav/src/test/org/apache/geronimo/datastore/impl/local/AbstractUseCaseTest.java
  
  Index: AbstractUseCaseTest.java
  ===================================================================
  /**
   *
   * Copyright 2004 The Apache Software Foundation
   *
   *  Licensed 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.
   */
  
  package org.apache.geronimo.datastore.impl.local;
  
  import java.io.ByteArrayInputStream;
  import java.io.InputStream;
  import java.util.Map;
  
  import org.apache.geronimo.datastore.GFile;
  import org.apache.geronimo.datastore.GFileManager;
  
  import junit.framework.TestCase;
  
  /**
   *
   * @version $Revision: 1.1 $ $Date: 2004/02/29 13:14:11 $
   */
  public class AbstractUseCaseTest
      extends TestCase
  {
      
      protected GFileManager fileManager;
      
      public void testUseCase() throws Exception {
  
          byte[] content = "Dummy content".getBytes();
          
          fileManager.start();
          GFile file = fileManager.factoryGFile("test");
          fileManager.persistNew(file);
          file.addProperty("name1", "value1");
          file.addProperty("name2", "value2");
          file.addProperty("name3", "value3");
          file.setContent(new ByteArrayInputStream(content));
          fileManager.end();
          
          fileManager.start();
          InputStream in = file.getInputStream();
          int read;
          int nbRead = 0;
          while ( -1 < (read = in.read()) ) {
              assertEquals("Wrong content", content[nbRead], read);
              nbRead++;
          }
          Map properties = file.getProperties();
          assertEquals("Properties issue", 3, properties.size());
          assertEquals("Properties issue", "value1", properties.get("name1"));
          assertEquals("Properties issue", "value2", properties.get("name2"));
          assertEquals("Properties issue", "value3", properties.get("name3"));
          file.addProperty("name4", "value4");
          file.removeProperty("name3");
          fileManager.persistUpdate(file);
          fileManager.end();
          
          fileManager.start();
          properties = file.getProperties();
          assertEquals("Properties issue", 3, properties.size());
          assertEquals("Properties issue", "value1", properties.get("name1"));
          assertEquals("Properties issue", "value2", properties.get("name2"));
          assertEquals("Properties issue", "value4", properties.get("name4"));
          fileManager.persistDelete(file);
          fileManager.end();
      }
      
  }
  
  
  
  1.1                  incubator-geronimo/sandbox/webdav/src/test/org/apache/geronimo/datastore/impl/local/LocalGFileDAOTest.java
  
  Index: LocalGFileDAOTest.java
  ===================================================================
  /**
   *
   * Copyright 2004 The Apache Software Foundation
   *
   *  Licensed 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.
   */
  
  package org.apache.geronimo.datastore.impl.local;
  
  import java.io.ByteArrayInputStream;
  import java.io.File;
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.Map;
  
  import org.apache.geronimo.datastore.Util;
  import org.apache.geronimo.datastore.impl.GFileDAO;
  import org.apache.geronimo.datastore.impl.GFileTO;
  import org.apache.geronimo.datastore.impl.LockManager;
  import org.apache.geronimo.datastore.impl.local.LocalGFileDAO;
  
  import junit.framework.TestCase;
  
  /**
   *
   * @version $Revision: 1.1 $ $Date: 2004/02/29 13:14:11 $
   */
  public class LocalGFileDAOTest extends TestCase
  {
  
      private File root;
      
      protected void setUp() throws Exception {
          root = new File(System.getProperty("java.io.tmpdir"), "GFileManager");
          Util.recursiveDelete(root);
          root.mkdir();
          LocalGFileManager fileManager =
              new LocalGFileManager("test", root, new LockManager());
      }
      
      public void testCRUD() throws Exception {
          String path = "TestFile";
          Map props = new HashMap();
          props.put("name1", "value1");
          props.put("name2", "value2");
          byte[] content = "Dummy content".getBytes();
          ByteArrayInputStream in = new ByteArrayInputStream(content);
          GFileTO fileTO = new GFileTO(path, props, in);
          GFileDAO fileDAO = new LocalGFileDAO(root);
  
          // Create.
          fileDAO.create(fileTO);
          
          // Read.
          fileTO = fileDAO.read(path);
          assertEquals("Wrong path", path, fileTO.getPath());
          props = fileTO.getProperties();
          assertEquals("Wrong # of properties", 2, props.size());
          for (Iterator iter = props.entrySet().iterator(); iter.hasNext();) {
              Map.Entry property = (Map.Entry) iter.next();
              String name = (String) property.getKey();
              if ( name.equals("name1") ) {
                  assertEquals("Wrong value", "value1", property.getValue());
              } else if ( name.equals("name2") ) {
                  assertEquals("Wrong value", "value2", property.getValue());
              } else {
                  assertTrue("Wrong property name {" + name + "}", false);
              }
          }
          
          // Update
          props.put("name3", "value3");
          fileDAO.update(fileTO);
          fileTO = fileDAO.read(path);
          props = fileTO.getProperties();
          assertEquals("Wrong # of properties", 3, props.size());
          
          // Delete
          fileDAO.delete(path);
          fileTO = fileDAO.read(path);
          assertFalse("Should not exist.", fileTO.exists());
      }
      
  }
  
  
  
  1.1                  incubator-geronimo/sandbox/webdav/src/test/org/apache/geronimo/datastore/Util.java
  
  Index: Util.java
  ===================================================================
  /**
   *
   * Copyright 2004 The Apache Software Foundation
   *
   *  Licensed 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.
   */
  
  package org.apache.geronimo.datastore;
  
  import java.io.File;
  import java.io.IOException;
  
  /**
   *
   * @version $Revision: 1.1 $ $Date: 2004/02/29 13:14:11 $
   */
  public class Util {
      
      public static void recursiveDelete(File aRoot) throws IOException {
          if ( !aRoot.isDirectory() ) {
              return;
          }
          File[] files = aRoot.listFiles();
          for (int i = 0; i < files.length; i++) {
              File file = files[i];
              if (file.isDirectory()) {
                  recursiveDelete(file);
              } else {
                  file.delete();
              }
          }
          aRoot.delete();
      }
      
  }
  
  
  
  1.1                  incubator-geronimo/sandbox/webdav/src/test/org/apache/geronimo/datastore/impl/DirtyMarkerImplTest.java
  
  Index: DirtyMarkerImplTest.java
  ===================================================================
  /**
   *
   * Copyright 2004 The Apache Software Foundation
   *
   *  Licensed 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.
   */
  
  package org.apache.geronimo.datastore.impl;
  
  import junit.framework.TestCase;
  
  /**
   *
   * @version $Revision: 1.1 $ $Date: 2004/02/29 13:14:11 $
   */
  public class DirtyMarkerImplTest extends TestCase {
  
      public void testNew() {
          DirtyMarkerImpl dirtyMarker = new DirtyMarkerImpl();
          dirtyMarker.setIsNew(true);
  
          Exception ex = null;
          try {
              dirtyMarker.setIsDelete(true);
          } catch (IllegalArgumentException e) {
              ex = e;
          }
          assertNotNull("Transition should ne impossible", ex);
          
          try {
              dirtyMarker.setIsDirty(true);
          } catch (IllegalArgumentException e) {
              ex = e;
          }
          assertNotNull("Transition should ne impossible", ex);
      }
  
      public void testDirty() {
          DirtyMarkerImpl dirtyMarker = new DirtyMarkerImpl();
          dirtyMarker.setIsDirty(true);
  
          Exception ex = null;
          try {
              dirtyMarker.setIsNew(true);
          } catch (IllegalArgumentException e) {
              ex = e;
          }
          assertNotNull("Transition should ne impossible", ex);
          
          try {
              dirtyMarker.setIsDelete(true);
          } catch (IllegalArgumentException e) {
              ex = e;
          }
          assertNotNull("Transition should ne impossible", ex);
      }
      
      public void testDelete() {
          DirtyMarkerImpl dirtyMarker = new DirtyMarkerImpl();
          dirtyMarker.setIsDelete(true);
  
          Exception ex = null;
          try {
              dirtyMarker.setIsNew(true);
          } catch (IllegalArgumentException e) {
              ex = e;
          }
          assertNotNull("Transition should ne impossible", ex);
          
          try {
              dirtyMarker.setIsDirty(true);
          } catch (IllegalArgumentException e) {
              ex = e;
          }
          assertNotNull("Transition should ne impossible", ex);
      }
      
  }
  
  
  
  1.1                  incubator-geronimo/sandbox/webdav/src/test/org/apache/geronimo/datastore/impl/remote/RemoteUseCaseTest.java
  
  Index: RemoteUseCaseTest.java
  ===================================================================
  /**
   *
   * Copyright 2004 The Apache Software Foundation
   *
   *  Licensed 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.
   */
  
  package org.apache.geronimo.datastore.impl.remote;
  
  import java.io.File;
  import java.net.InetAddress;
  import java.util.Collections;
  
  
  import org.apache.geronimo.datastore.GFileManager;
  import org.apache.geronimo.datastore.Util;
  import org.apache.geronimo.datastore.impl.LockManager;
  import org.apache.geronimo.datastore.impl.local.AbstractUseCaseTest;
  import org.apache.geronimo.datastore.impl.local.LocalGFileManager;
  import org.apache.geronimo.datastore.impl.remote.datastore.GFileManagerClient;
  import org.apache.geronimo.datastore.impl.remote.datastore.GFileManagerProxy;
  import org.apache.geronimo.datastore.impl.remote.messaging.ServantNode;
  import org.apache.geronimo.datastore.impl.remote.messaging.ServerNode;
  
  /**
   * This is a remote use-case.
   *
   * @version $Revision: 1.1 $ $Date: 2004/02/29 13:14:11 $
   */
  public class RemoteUseCaseTest extends AbstractUseCaseTest {
  
      protected void setUp() throws Exception {
          LockManager lockManager = new LockManager();
          File root = new File(System.getProperty("java.io.tmpdir"),
                  "GFileManager");
          Util.recursiveDelete(root);
          root.mkdir();
          
          GFileManager delegate;
          delegate = new LocalGFileManager("test", root, lockManager);
          InetAddress address = InetAddress.getLocalHost();
          int port = 8080;
          GFileManagerProxy proxy = new GFileManagerProxy(delegate);
          ServerNode server = new ServerNode("MasterNode",
                  Collections.singleton(proxy), address, port, 2);
          server.doStart();
          proxy.doStart();
  
          fileManager = new GFileManagerClient("test");
          ServantNode servant = new ServantNode(
                  "ChildNode", Collections.singleton(fileManager), address, port, 10);
          servant.doStart();
          ((GFileManagerClient) fileManager).doStart();
      }
      
  }
  
  
  

Mime
View raw message