OSDN Git Service

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