working on write config test 69/10669/1
authorHeongseok Heo <hyeongseok.heo@samsung.com>
Fri, 4 Oct 2013 11:09:34 +0000 (20:09 +0900)
committerHeongseok Heo <hyeongseok.heo@samsung.com>
Fri, 4 Oct 2013 11:09:34 +0000 (20:09 +0900)
org.tizen.ncli.ide/.classpath
org.tizen.ncli.ide/src/org/tizen/ncli/ide/core/config/NCLIConfigLoader.java
org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/AbstractCLI.java
org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/ConfigCLICommand.java
org.tizen.ncli.ide/test/resources/org/tizen/ncli/ide/test/resources/tizen-cli-config-global [new file with mode: 0644]
org.tizen.ncli.ide/test/resources/org/tizen/ncli/ide/test/resources/tizen-cli-config-local [new file with mode: 0644]
org.tizen.ncli.ide/test/src/org/tizen/ncli/ide/test/CommonCLISubCommandTest.java
org.tizen.ncli.ide/test/src/org/tizen/ncli/ide/test/ConfigCommandTest.java

index 088f649..45c269c 100644 (file)
@@ -5,6 +5,7 @@
        <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>\r
        <classpathentry kind="src" path="src"/>\r
        <classpathentry kind="src" path="test/src"/>\r
+       <classpathentry kind="src" path="test/resources"/>\r
        <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>\r
        <classpathentry kind="output" path="bin"/>\r
 </classpath>\r
index c40645e..591fd83 100644 (file)
@@ -89,8 +89,10 @@ public class NCLIConfigLoader implements Loader {
             \r
         }catch (FileNotFoundException e) {\r
             //FIXME something to do\r
+            e.printStackTrace();\r
         }catch(IOException io){\r
             //FIXME something to do\r
+            io.printStackTrace();\r
         }finally {\r
             IOUtil.tryClose(inStream);\r
         }\r
index 401cb45..68f26ac 100644 (file)
@@ -35,7 +35,7 @@ import org.slf4j.LoggerFactory;
 \r
 /**\r
  * Implemented common function of CLI options\r
- * @author Harry Hyeongseok Heo{@leteral <hyeongseok.heo@samsung.com>} (S-core)\r
+ * @author Harry Hyeongseok Heo{@literal <hyeongseok.heo@samsung.com>} (S-core)\r
  */\r
 public abstract class AbstractCLI {\r
        protected Logger log = LoggerFactory.getLogger(getClass());\r
index ebd45ad..cb1bdd3 100644 (file)
@@ -34,6 +34,7 @@ import java.util.Map;
 import java.util.Properties;\r
 import java.util.Set;\r
 \r
+import org.tizen.common.util.Assert;\r
 import org.tizen.common.util.IOUtil;\r
 import org.tizen.ncli.ide.config.CLIConfig;\r
 import org.tizen.ncli.ide.core.config.NCLIConfigLoader;\r
diff --git a/org.tizen.ncli.ide/test/resources/org/tizen/ncli/ide/test/resources/tizen-cli-config-global b/org.tizen.ncli.ide/test/resources/org/tizen/ncli/ide/test/resources/tizen-cli-config-global
new file mode 100644 (file)
index 0000000..e625c2f
--- /dev/null
@@ -0,0 +1,3 @@
+global.key1=This is global value1\r
+global.key2=This is global value2\r
+global.key1.subkey1=This is global subkey value1\r
diff --git a/org.tizen.ncli.ide/test/resources/org/tizen/ncli/ide/test/resources/tizen-cli-config-local b/org.tizen.ncli.ide/test/resources/org/tizen/ncli/ide/test/resources/tizen-cli-config-local
new file mode 100644 (file)
index 0000000..f9f1762
--- /dev/null
@@ -0,0 +1,3 @@
+global.key1=This is local value1\r
+local.key2=This is global value2\r
+local.key1.subkey1=This is local subkey value1\r
index 5cd40f6..0d5ada4 100644 (file)
@@ -24,6 +24,7 @@
  */\r
 package org.tizen.ncli.ide.test;\r
 \r
+import java.io.File;\r
 import java.io.IOException;\r
 import java.io.InputStream;\r
 import java.util.Properties;\r
@@ -41,6 +42,7 @@ public class CommonCLISubCommandTest {
     protected static Logger log = LoggerFactory.getLogger(CommonCLISubCommandTest.class);\r
     protected static Properties testGlobalProp = new Properties();\r
     protected static Properties testLocalProp = new Properties();\r
+    protected static File testLocalConf = null;\r
 \r
     @BeforeClass\r
     public static void prepare_once() {\r
@@ -69,6 +71,7 @@ public class CommonCLISubCommandTest {
        protected static InputStream loadTestLocalConfig() {\r
                final ClassLoader classLoader = CommonCLISubCommandTest.class.getClassLoader();\r
        final String testFilePath = CommonCLISubCommandTest.class.getPackage().getName().replace(".", "/")+"/tizen-cli-config-local";\r
+       testLocalConf = new File(classLoader.getResource(testFilePath).getFile());\r
        InputStream configStream = null;\r
        configStream = classLoader.getResourceAsStream(testFilePath);\r
                return configStream;\r
index 74d1839..27a6449 100644 (file)
@@ -5,7 +5,9 @@ package org.tizen.ncli.ide.test;
 \r
 import static org.junit.Assert.*;\r
 import static org.powermock.api.mockito.PowerMockito.doAnswer;\r
+import static org.powermock.api.mockito.PowerMockito.mockStatic;\r
 import static org.powermock.api.mockito.PowerMockito.spy;\r
+import static org.powermock.api.mockito.PowerMockito.when;\r
 \r
 import java.io.InputStream;\r
 import java.util.Collection;\r
@@ -24,7 +26,9 @@ import org.powermock.modules.junit4.PowerMockRunner;
 import org.tizen.common.config.Preference;\r
 import org.tizen.common.config.provider.EnvironmentProvider;\r
 import org.tizen.common.config.provider.SystemPropertiesProvider;\r
+import org.tizen.ncli.ide.CLIConstant;\r
 import org.tizen.ncli.ide.config.CLIConfig;\r
+import org.tizen.ncli.ide.core.config.NCLIConfigLoader;\r
 import org.tizen.ncli.ide.core.config.TizenCLIConfigProvider;\r
 import org.tizen.ncli.ide.subcommands.ConfigCLICommand;\r
 \r
@@ -80,12 +84,20 @@ public class ConfigCommandTest extends CommonCLISubCommandTest{
         \r
     }\r
     \r
+    @PrepareForTest(NCLIConfigLoader.class )\r
     @Test\r
     public void test_setLocalConfig() throws Exception {\r
-        final TizenCLIConfigProvider globalProvider = new TizenCLIConfigProvider(testGlobalProp);\r
-         final TizenCLIConfigProvider localProvider = new TizenCLIConfigProvider(testLocalProp);\r
-\r
-        ConfigCLICommand configCmd = spy(new ConfigCLICommand());\r
+         \r
+       mockStatic(NCLIConfigLoader.class);\r
+       \r
+       when(NCLIConfigLoader.getLocalConfigFile()).thenReturn(testLocalConf);\r
+       when(NCLIConfigLoader.loadLocalConf()).thenReturn(testLocalProp);\r
+\r
+       final TizenCLIConfigProvider globalProvider = new TizenCLIConfigProvider(testGlobalProp);\r
+       final TizenCLIConfigProvider localProvider = new TizenCLIConfigProvider(NCLIConfigLoader.loadLocalConf());\r
+       \r
+       \r
+       ConfigCLICommand configCmd = spy(new ConfigCLICommand());\r
 \r
         doAnswer(new Answer<Object>() {\r
 \r
@@ -94,7 +106,7 @@ public class ConfigCommandTest extends CommonCLISubCommandTest{
                 Preference.register("OS", new EnvironmentProvider());\r
                 Preference.register("JVM", new SystemPropertiesProvider());\r
                 Preference.register("TIZEN.CLI.GLOBAL", globalProvider);\r
-                Preference.register("TIZEN.CLI.LOCAL", localProvider);\r
+                Preference.register(CLIConstant.TIZEN_CLI_LOCAL_KEY, localProvider);\r
                 return "run command called";\r
             }\r
 \r