polygene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From paulmer...@apache.org
Subject [30/35] zest-java git commit: fileconfig: add coverage
Date Sat, 19 Nov 2016 22:50:31 GMT
fileconfig: add coverage


Project: http://git-wip-us.apache.org/repos/asf/zest-java/repo
Commit: http://git-wip-us.apache.org/repos/asf/zest-java/commit/a16b9567
Tree: http://git-wip-us.apache.org/repos/asf/zest-java/tree/a16b9567
Diff: http://git-wip-us.apache.org/repos/asf/zest-java/diff/a16b9567

Branch: refs/heads/develop
Commit: a16b956733000a93be427f6402caa0981df50ebb
Parents: cb2c52f
Author: Paul Merlin <paulmerlin@apache.org>
Authored: Sat Nov 19 19:57:42 2016 +0100
Committer: Paul Merlin <paulmerlin@apache.org>
Committed: Sat Nov 19 19:57:42 2016 +0100

----------------------------------------------------------------------
 .../fileconfig/FileConfigurationTest.java       | 71 +++++++++++++++++---
 1 file changed, 61 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zest-java/blob/a16b9567/libraries/fileconfig/src/test/java/org/apache/zest/library/fileconfig/FileConfigurationTest.java
----------------------------------------------------------------------
diff --git a/libraries/fileconfig/src/test/java/org/apache/zest/library/fileconfig/FileConfigurationTest.java
b/libraries/fileconfig/src/test/java/org/apache/zest/library/fileconfig/FileConfigurationTest.java
index 850bd83..c3ae515 100644
--- a/libraries/fileconfig/src/test/java/org/apache/zest/library/fileconfig/FileConfigurationTest.java
+++ b/libraries/fileconfig/src/test/java/org/apache/zest/library/fileconfig/FileConfigurationTest.java
@@ -21,16 +21,22 @@ package org.apache.zest.library.fileconfig;
 
 import java.io.File;
 import java.io.IOException;
+import org.junit.Rule;
 import org.junit.Test;
 import org.apache.zest.api.activation.ActivationException;
 import org.apache.zest.bootstrap.AssemblyException;
 import org.apache.zest.bootstrap.ModuleAssembly;
 import org.apache.zest.bootstrap.SingletonAssembler;
+import org.junit.rules.TemporaryFolder;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
 
 public class FileConfigurationTest
 {
+    @Rule
+    public final TemporaryFolder tmpDir = new TemporaryFolder();
+
     @Test
     public void testFileConfiguration()
         throws ActivationException, AssemblyException
@@ -48,16 +54,24 @@ public class FileConfigurationTest
         };
 
         FileConfiguration config = assembler.module().findService( FileConfiguration.class
).get();
-
-        File confDir = config.configurationDirectory();
-        System.out.println( confDir );
+        assertNotNull( config.configurationDirectory() );
+        assertNotNull( config.dataDirectory() );
+        assertNotNull( config.temporaryDirectory() );
+        assertNotNull( config.cacheDirectory() );
+        assertNotNull( config.logDirectory() );
+        System.out.println( "FileConfiguration defaults:\n"
+                            + "\tconfiguration: " + config.configurationDirectory().getAbsolutePath()
+ "\n"
+                            + "\tdata:          " + config.configurationDirectory().getAbsolutePath()
+ "\n"
+                            + "\ttemporary:     " + config.configurationDirectory().getAbsolutePath()
+ "\n"
+                            + "\tcache:         " + config.configurationDirectory().getAbsolutePath()
+ "\n"
+                            + "\tlog:           " + config.configurationDirectory().getAbsolutePath()
);
     }
 
     @Test
     public void testFileConfigurationOverride()
         throws IOException, ActivationException, AssemblyException
     {
-        File testFile = File.createTempFile( FileConfigurationTest.class.getName(), "tmp"
);
+        File testFile = tmpDir.getRoot();
         final File confDir = testFile;
         final File dataDir = testFile;
         final File tempDir = testFile;
@@ -70,12 +84,12 @@ public class FileConfigurationTest
                 throws AssemblyException
             {
                 // START SNIPPET: override
-                FileConfigurationOverride override = new FileConfigurationOverride().
-                    withConfiguration( confDir ).
-                    withData( dataDir ).
-                    withTemporary( tempDir ).
-                    withCache( cacheDir ).
-                    withLog( logDir );
+                FileConfigurationOverride override = new FileConfigurationOverride()
+                    .withConfiguration( confDir )
+                    .withData( dataDir )
+                    .withTemporary( tempDir )
+                    .withCache( cacheDir )
+                    .withLog( logDir );
                 new FileConfigurationAssembler().withOverride( override ).assemble( module
);
                 // END SNIPPET: override
             }
@@ -84,5 +98,42 @@ public class FileConfigurationTest
         FileConfiguration config = assembler.module().findService( FileConfiguration.class
).get();
 
         assertEquals( testFile.getAbsolutePath(), config.configurationDirectory().getAbsolutePath()
);
+        assertEquals( testFile.getAbsolutePath(), config.dataDirectory().getAbsolutePath()
);
+        assertEquals( testFile.getAbsolutePath(), config.temporaryDirectory().getAbsolutePath()
);
+        assertEquals( testFile.getAbsolutePath(), config.cacheDirectory().getAbsolutePath()
);
+        assertEquals( testFile.getAbsolutePath(), config.logDirectory().getAbsolutePath()
);
+    }
+
+    @Test
+    public void testFileConfigurationOverrideConvention()
+        throws IOException, ActivationException, AssemblyException
+    {
+        File rootDir = tmpDir.getRoot();
+        SingletonAssembler assembler = new SingletonAssembler()
+        {
+            @Override
+            public void assemble( ModuleAssembly module )
+                throws AssemblyException
+            {
+                // START SNIPPET: override-convention
+                new FileConfigurationAssembler()
+                    .withOverride( new FileConfigurationOverride().withConventionalRoot(
rootDir ) )
+                    .assemble( module );
+                // END SNIPPET: override-convention
+            }
+        };
+
+        FileConfiguration config = assembler.module().findService( FileConfiguration.class
).get();
+
+        assertEquals( new File( rootDir, FileConfigurationOverride.CONVENTIONAL_CONFIGURATION
).getAbsolutePath(),
+                      config.configurationDirectory().getAbsolutePath() );
+        assertEquals( new File( rootDir, FileConfigurationOverride.CONVENTIONAL_DATA ).getAbsolutePath(),
+                      config.dataDirectory().getAbsolutePath() );
+        assertEquals( new File( rootDir, FileConfigurationOverride.CONVENTIONAL_TEMPORARY
).getAbsolutePath(),
+                      config.temporaryDirectory().getAbsolutePath() );
+        assertEquals( new File( rootDir, FileConfigurationOverride.CONVENTIONAL_CACHE ).getAbsolutePath(),
+                      config.cacheDirectory().getAbsolutePath() );
+        assertEquals( new File( rootDir, FileConfigurationOverride.CONVENTIONAL_LOG ).getAbsolutePath(),
+                      config.logDirectory().getAbsolutePath() );
     }
 }


Mime
View raw message