You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jmeter-dev@jakarta.apache.org by se...@apache.org on 2005/11/20 19:38:28 UTC

svn commit: r345770 - /jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/services/TestFileServer.java

Author: sebb
Date: Sun Nov 20 10:38:24 2005
New Revision: 345770

URL: http://svn.apache.org/viewcvs?rev=345770&view=rev
Log:
Add tests for FileServer

Added:
    jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/services/TestFileServer.java   (with props)

Added: jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/services/TestFileServer.java
URL: http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/services/TestFileServer.java?rev=345770&view=auto
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/services/TestFileServer.java (added)
+++ jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/services/TestFileServer.java Sun Nov 20 10:38:24 2005
@@ -0,0 +1,101 @@
+/*
+ * Copyright 2005 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 to test FileServer methods 
+ */
+     
+package org.apache.jmeter.services;
+
+import java.io.IOException;
+
+import org.apache.jmeter.junit.JMeterTestCase;
+import org.apache.jmeter.util.JMeterUtils;
+
+public class TestFileServer extends JMeterTestCase {
+
+    private static final FileServer FS = FileServer.getFileServer();
+    
+    public TestFileServer() {
+        super();
+    }
+
+    public TestFileServer(String arg0) {
+        super(arg0);
+    }
+
+    public void tearDown() throws IOException{
+        FS.closeFiles();
+        FS.resetBase();
+    }
+    
+    public void testopen() throws Exception {
+        try {
+            FS.readLine("test");
+            fail("Expected IOException");
+        } catch (IOException ignored){
+        }
+        try {
+            FS.write("test","");
+            fail("Expected IOException");
+        } catch (IOException ignored){
+        }
+        assertFalse("Should not have any files open",FS.filesOpen());
+        FS.closeFile("xxx"); // Unrecognised files are ignored
+        assertFalse("Should not have any files open",FS.filesOpen());
+        String infile="testfiles/test.csv";
+        FS.reserveFile(infile); // Does not open file
+        assertFalse("Should not have any files open",FS.filesOpen());
+        assertEquals("a1,b1,c1,d1",FS.readLine(infile));
+        assertTrue("Should have some files open",FS.filesOpen());
+        assertNotNull(FS.readLine(infile));
+        assertNotNull(FS.readLine(infile));
+        assertNotNull(FS.readLine(infile));
+        assertEquals("a1,b1,c1,d1",FS.readLine(infile));// Re-read 1st line
+        assertNotNull(FS.readLine(infile));
+        try {
+            FS.write(infile,"");// should not be able to write to it ...
+            fail("Expected IOException");
+        } catch (IOException ignored){
+        }
+        FS.closeFile(infile); // does not remove the entry
+        assertFalse("Should not have any files open",FS.filesOpen());
+        assertEquals("a1,b1,c1,d1",FS.readLine(infile));// Re-read 1st line
+        assertTrue("Should have some files open",FS.filesOpen());
+        FS.closeFiles(); // removes all entries
+        assertFalse("Should not have any files open",FS.filesOpen());
+        try {
+            FS.readLine(infile);
+            fail("Expected IOException");
+        } catch (IOException ignored){
+        }
+        String base=FS.getBaseDir();
+        infile=base+"/testfiles/test.csv";
+        FS.reserveFile(infile); // Does not open file
+        assertFalse("Should not have any files open",FS.filesOpen());
+        assertEquals("a1,b1,c1,d1",FS.readLine(infile));
+        try {
+            FS.setBasedir("x");
+            fail("Expected IOException");
+        } catch (IOException ignored){
+        }
+        FS.closeFile(infile);
+        FS.setBasedir("y");
+        FS.closeFiles();
+        FS.setBasedir(JMeterUtils.getProperty("user.dir"));
+    }
+}

Propchange: jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/services/TestFileServer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/services/TestFileServer.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision



---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org