You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by fm...@apache.org on 2007/08/06 10:01:50 UTC

svn commit: r563058 - in /felix/sandbox/fmeschbe/configdamin_bundled_config/src/test/java/org/apache/felix/cm/impl: ./ ConfigurationFileInputStreamTest.java

Author: fmeschbe
Date: Mon Aug  6 01:01:49 2007
New Revision: 563058

URL: http://svn.apache.org/viewvc?view=rev&rev=563058
Log:
#add test case to sandbox

Added:
    felix/sandbox/fmeschbe/configdamin_bundled_config/src/test/java/org/apache/felix/cm/impl/
    felix/sandbox/fmeschbe/configdamin_bundled_config/src/test/java/org/apache/felix/cm/impl/ConfigurationFileInputStreamTest.java

Added: felix/sandbox/fmeschbe/configdamin_bundled_config/src/test/java/org/apache/felix/cm/impl/ConfigurationFileInputStreamTest.java
URL: http://svn.apache.org/viewvc/felix/sandbox/fmeschbe/configdamin_bundled_config/src/test/java/org/apache/felix/cm/impl/ConfigurationFileInputStreamTest.java?view=auto&rev=563058
==============================================================================
--- felix/sandbox/fmeschbe/configdamin_bundled_config/src/test/java/org/apache/felix/cm/impl/ConfigurationFileInputStreamTest.java (added)
+++ felix/sandbox/fmeschbe/configdamin_bundled_config/src/test/java/org/apache/felix/cm/impl/ConfigurationFileInputStreamTest.java Mon Aug  6 01:01:49 2007
@@ -0,0 +1,231 @@
+/*
+ * $Url: $
+ * $Id: $
+ *
+ * Copyright 1997-2005 Day Management AG
+ * Barfuesserplatz 6, 4001 Basel, Switzerland
+ * All Rights Reserved.
+ *
+ * This software is the confidential and proprietary information of
+ * Day Management AG, ("Confidential Information"). You shall not
+ * disclose such Confidential Information and shall use it only in
+ * accordance with the terms of the license agreement you entered into
+ * with Day.
+ */
+package org.apache.felix.cm.impl;
+
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+
+import junit.framework.TestCase;
+
+
+/**
+ * The <code>ConfigurationFileInputStreamTest</code> TODO
+ */
+public class ConfigurationFileInputStreamTest extends TestCase
+{
+
+    private final String path = getClass().getName().replace( '.', '/' );
+    private final String ext = ".ini";
+
+
+    public void test0() throws IOException
+    {
+        ConfigurationFileInputStream ini = new ConfigurationFileInputStream( getFile( 0 ) );
+
+        String entry = ini.getNextEntry();
+        assertNotNull( entry );
+        assertEquals( "Section1", entry );
+
+        BufferedReader br = new BufferedReader( new InputStreamReader( ini ) );
+        assertLine( br, "Entry" );
+        ini.close();
+    }
+
+
+    public void test1() throws IOException
+    {
+        ConfigurationFileInputStream ini = new ConfigurationFileInputStream( getFile( 1 ) );
+
+        String entry = ini.getNextEntry();
+        assertNotNull( entry );
+        assertEquals( "Section1", entry );
+
+        BufferedReader br = new BufferedReader( new InputStreamReader( ini ) );
+
+        assertLine( br, "Entry" );
+
+        ini.close();
+    }
+
+
+    public void test2() throws IOException
+    {
+        ConfigurationFileInputStream ini = new ConfigurationFileInputStream( getFile( 2 ) );
+
+        String entry = ini.getNextEntry();
+        assertNotNull( entry );
+        assertEquals( "Section1", entry );
+
+        BufferedReader br = new BufferedReader( new InputStreamReader( ini ) );
+
+        assertLine( br, "Entry" );
+        assertLine( br, "" );
+        assertLine( br, "" );
+        assertLine( br, "Another Entry" );
+        assertLine( br, "" );
+        assertLine( br, "Entry 3 \\" );
+        assertLine( br, "# comment not read as a comment" );
+
+        ini.close();
+    }
+
+
+    public void test3() throws IOException
+    {
+        ConfigurationFileInputStream ini = new ConfigurationFileInputStream( getFile( 3 ) );
+
+        String entry = ini.getNextEntry();
+        assertNotNull( entry );
+        assertEquals( "Section1", entry );
+
+        BufferedReader br = new BufferedReader( new InputStreamReader( ini ) );
+        assertLine( br, "Entry" );
+
+        // make sure, there is nothing anymore after the Entry
+        assertNull( br.readLine() );
+
+        // expect Section2
+        entry = ini.getNextEntry();
+        assertNotNull( entry );
+        assertEquals( "Section2", entry );
+
+        br = new BufferedReader( new InputStreamReader( ini ) );
+        assertLine( br, "Section2Entry" );
+
+        ini.close();
+    }
+
+
+    public void test3Skip() throws IOException
+    {
+        ConfigurationFileInputStream ini = new ConfigurationFileInputStream( getFile( 3 ) );
+
+        String entry = ini.getNextEntry();
+        assertNotNull( entry );
+        assertEquals( "Section1", entry );
+
+        // skipt to Section2
+        entry = ini.getNextEntry();
+        assertNotNull( entry );
+        assertEquals( "Section2", entry );
+
+        BufferedReader br = new BufferedReader( new InputStreamReader( ini ) );
+        assertLine( br, "Section2Entry" );
+
+        ini.close();
+    }
+
+
+    public void test3_CRLF() throws IOException
+    {
+        ConfigurationFileInputStream ini = new ConfigurationFileInputStream( getFile( "3_CRLF" ) );
+
+        String entry = ini.getNextEntry();
+        assertNotNull( entry );
+        assertEquals( "Section1", entry );
+
+        BufferedReader br = new BufferedReader( new InputStreamReader( ini ) );
+        assertLine( br, "Entry" );
+
+        // make sure, there is nothing anymore after the Entry
+        assertNull( br.readLine() );
+
+        // expect Section2
+        entry = ini.getNextEntry();
+        assertNotNull( entry );
+        assertEquals( "Section2", entry );
+
+        br = new BufferedReader( new InputStreamReader( ini ) );
+        assertLine( br, "Section2Entry" );
+
+        ini.close();
+    }
+
+
+    public void test3_LFCR() throws IOException
+    {
+        ConfigurationFileInputStream ini = new ConfigurationFileInputStream( getFile( "3_LFCR" ) );
+
+        String entry = ini.getNextEntry();
+        assertNotNull( entry );
+        assertEquals( "Section1", entry );
+
+        BufferedReader br = new BufferedReader( new InputStreamReader( ini ) );
+        assertLine( br, "Entry" );
+
+        // make sure, there is nothing anymore after the Entry
+        assertNull( br.readLine() );
+
+        // expect Section2
+        entry = ini.getNextEntry();
+        assertNotNull( entry );
+        assertEquals( "Section2", entry );
+
+        br = new BufferedReader( new InputStreamReader( ini ) );
+        assertLine( br, "Section2Entry" );
+
+        ini.close();
+    }
+
+
+    public void test3_CR() throws IOException
+    {
+        ConfigurationFileInputStream ini = new ConfigurationFileInputStream( getFile( "3_CR" ) );
+
+        String entry = ini.getNextEntry();
+        assertNotNull( entry );
+        assertEquals( "Section1", entry );
+
+        BufferedReader br = new BufferedReader( new InputStreamReader( ini ) );
+        assertLine( br, "Entry" );
+
+        // make sure, there is nothing anymore after the Entry
+        assertNull( br.readLine() );
+
+        // expect Section2
+        entry = ini.getNextEntry();
+        assertNotNull( entry );
+        assertEquals( "Section2", entry );
+
+        br = new BufferedReader( new InputStreamReader( ini ) );
+        assertLine( br, "Section2Entry" );
+
+        ini.close();
+    }
+
+
+    private InputStream getFile( int idx )
+    {
+        return getFile( String.valueOf( idx ) );
+    }
+
+
+    private InputStream getFile( String idx )
+    {
+        String name = path + idx + ext;
+        return getClass().getClassLoader().getResourceAsStream( name );
+    }
+
+
+    private void assertLine( BufferedReader br, String expected ) throws IOException
+    {
+        String line = br.readLine();
+        assertNotNull( line );
+        assertEquals( expected, line );
+    }
+}