OSDN Git Service

コンフィグのロードとセーブ
[coroid/inqubus.git] / frontend / test / yukihane / inqubus / ConfigTest.java
1 package yukihane.inqubus;
2
3 import yukihane.inqubus.Config;
4 import java.io.File;
5 import static org.junit.Assert.*;
6
7 import java.nio.file.FileSystem;
8 import java.nio.file.FileSystems;
9 import org.apache.commons.configuration.ConfigurationException;
10 import org.junit.After;
11 import org.junit.Before;
12 import org.junit.Test;
13
14 /**
15  *
16  * @author yuki
17  */
18 public class ConfigTest {
19
20     private final Config p = Config.INSTANCE;
21
22     @Before
23     public void setUp() {
24         Config.INSTANCE.clear();
25     }
26
27     @After
28     public void tearDown() {
29         Config.INSTANCE.clear();
30     }
31
32     @Test
33     public void testLoadFail() {
34         FileSystem fs = FileSystems.getDefault();
35         System.out.println(fs.getPath(".").toAbsolutePath());
36         Config p = Config.INSTANCE;
37         try {
38             p.load("test/testdata/error.xml");
39             fail("ファイルが存在しないので読み込みに失敗するはず");
40         } catch (ConfigurationException ex) {
41         }
42         try {
43             p.load("test/testdata/inqubus_test.xml");
44             fail("ファイルが空なので読み込みに失敗するはず");
45         } catch (ConfigurationException ex) {
46         }
47     }
48
49 //    @Test
50 //    public void test2() throws ConfigurationException, IllegalArgumentException, IllegalAccessException {
51 //        Properties p = Properties.INSTANCE;
52 //        p.load("test/testdata/inqubus_test.ok");
53 //        p.setDbLocation("d_loc");
54 //        p.save();
55 //        Field[] fields = p.getClass().getDeclaredFields();
56 //        for(Field f: fields){
57 //            f.setAccessible(true);
58 //            System.out.println(f.get(p));
59 //        }
60 //    }
61     @Test
62     public void testGetSetNetworkAccount() {
63     }
64
65     /**
66      * コンフィグ取得・設定テストケース.
67      * デフォルト値の取得、設定とその設定値の取得のテストです.
68      */
69     @Test
70     public void testGetSetNetworkProxy() throws ConfigurationException {
71
72         /*
73          * ネットワーク - アカウント
74          */
75         assertEquals("", p.getId());
76         p.setId("id");
77         assertEquals("id", p.getId());
78
79         assertEquals("", p.getPassword());
80         p.setPassword("password");
81         assertEquals("password", p.getPassword());
82
83
84         /*
85          * ネットワーク - プロキシ
86          */
87         assertEquals(false, p.getProxyUse());
88         p.setProxyUse(true);
89         assertEquals(true, p.getProxyUse());
90
91         assertEquals("localhost", p.getProxyHost());
92         p.setProxyHost("proxyhost");
93         assertEquals("proxyhost", p.getProxyHost());
94
95         assertEquals("8080", p.getProxyPort());
96         p.setProxyPort("80");
97         assertEquals("80", p.getProxyPort());
98
99
100         /*
101          * ファイル - 動画
102          */
103         assertEquals("in/video", p.getVideoDir());
104         p.setVideoDir("v");
105         assertEquals("v", p.getVideoDir());
106
107         assertEquals("[{id}]{title}", p.getVideoFileNamePattern());
108         p.setVideoFileNamePattern("videotitle");
109         assertEquals("videotitle", p.getVideoFileNamePattern());
110
111         assertEquals(false, p.getVideoUseLocal());
112         p.setVideoUseLocal(true);
113         assertEquals(true, p.getVideoUseLocal());
114
115         /*
116          * ファイル - コメント
117          */
118         assertEquals("in/comment", p.getCommentDir());
119         p.setCommentDir("c");
120         assertEquals("c", p.getCommentDir());
121
122         assertEquals("[{id}]{title}", p.getCommentFileNamePattern());
123         p.setVideoFileNamePattern("comtitle");
124         assertEquals("comtitle", p.getVideoFileNamePattern());
125
126         assertEquals(false, p.getCommentUseLocal());
127         p.setCommentUseLocal(true);
128         assertEquals(true, p.getCommentUseLocal());
129
130
131         /*
132          * ファイル - 変換動画
133          */
134         assertEquals("out", p.getOutputDir());
135         p.setOutputDir("_out_");
136         assertEquals("_out_", p.getOutputDir());
137
138 //        p.save(new File("test/testdata/save.xml"));
139     }
140 }