Author: jdumay
Date: Tue Jun 24 18:59:41 2008
New Revision: 671395
URL: http://svn.apache.org/viewvc?rev=671395&view=rev
Log:
Adding tests
Added:
archiva/sandbox/new-repository-api/src/test/java/org/apache/archiva/repository/filesystem/
archiva/sandbox/new-repository-api/src/test/java/org/apache/archiva/repository/filesystem/FileSystemRepositoryBackendTest.java
Added:
archiva/sandbox/new-repository-api/src/test/java/org/apache/archiva/repository/filesystem/FileSystemRepositoryBackendTest.java
URL:
http://svn.apache.org/viewvc/archiva/sandbox/new-repository-api/src/test/java/org/apache/archiva/repository/filesystem/FileSystemRepositoryBackendTest.java?rev=671395&view=auto
==============================================================================
---
archiva/sandbox/new-repository-api/src/test/java/org/apache/archiva/repository/filesystem/FileSystemRepositoryBackendTest.java
(added)
+++
archiva/sandbox/new-repository-api/src/test/java/org/apache/archiva/repository/filesystem/FileSystemRepositoryBackendTest.java
Tue Jun 24 18:59:41 2008
@@ -0,0 +1,93 @@
+package org.apache.archiva.repository.filesystem;
+
+import java.io.File;
+import java.io.InputStream;
+import java.util.List;
+import junit.framework.TestCase;
+
+/*
+ * 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 org.apache.archiva.repository.ResourceContext;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
+
+/**
+ * @author <a href="mailto:[EMAIL PROTECTED]">James William Dumay</a>
+ */
+public class FileSystemRepositoryBackendTest extends TestCase
+{
+ private FileSystemRepositoryBackend backend;
+
+ private File rootDir;
+
+ protected void setUp()
+ throws Exception
+ {
+ super.setUp();
+ rootDir = new File("target/fsbackend");
+ backend = new FileSystemRepositoryBackend(rootDir.getCanonicalPath());
+ new File(rootDir, "testing").mkdir();
+ }
+
+ protected void tearDown()
+ throws Exception
+ {
+ super.tearDown();
+ FileUtils.deleteDirectory(rootDir);
+ }
+
+ public void testWrite()
+ throws Exception
+ {
+ InputStream is = IOUtils.toInputStream("Hello World!");
+ backend.writeStream(new MockResourceContext("writetest.txt"), is);
+ assertEquals("Hello World!", FileUtils.readFileToString(new
File(rootDir, "testing/writetest.txt")));
+ }
+
+ public void testRead()
+ throws Exception
+ {
+ File file = new File(rootDir, "testing/test.txt");
+ FileUtils.writeStringToFile(file, "Help im trapped in a lisp factory");
+ InputStream is = backend.getStream(new
MockResourceContext("test.txt"));
+ List lines = IOUtils.readLines(is);
+ assertEquals(1, lines.size());
+ assertEquals("Help im trapped in a lisp factory", lines.get(0));
+ }
+
+ public class MockResourceContext implements ResourceContext
+ {
+ private final String logicalPath;
+
+ public MockResourceContext(String logicalPath)
+ {
+ this.logicalPath = logicalPath;
+ }
+
+ public String getLogicalPath()
+ {
+ return logicalPath;
+ }
+
+ public String getRepositoryId()
+ {
+ return "testing";
+ }
+ }
+}