OSDN Git Service

update Land-F URI
[jindolf/JinCore.git] / src / test / java / jp / sourceforge / jindolf / corelib / LandDefTest.java
1 /*
2  * License : The MIT License
3  * Copyright(c) 2009 olyutorskii
4  */
5
6 package jp.sourceforge.jindolf.corelib;
7
8 import java.io.IOException;
9 import java.nio.charset.Charset;
10 import java.util.ArrayList;
11 import java.util.Collection;
12 import java.util.GregorianCalendar;
13 import java.util.List;
14 import java.util.Locale;
15 import java.util.TimeZone;
16 import javax.xml.parsers.DocumentBuilder;
17 import javax.xml.parsers.DocumentBuilderFactory;
18 import javax.xml.parsers.ParserConfigurationException;
19 import org.junit.After;
20 import org.junit.AfterClass;
21 import org.junit.Before;
22 import org.junit.BeforeClass;
23 import org.junit.Test;
24 import org.xml.sax.SAXException;
25
26 import static org.junit.Assert.*;
27
28 /**
29  */
30 public class LandDefTest {
31
32     private DocumentBuilder builder;
33
34     public LandDefTest() {
35     }
36
37     @BeforeClass
38     public static void setUpClass() throws Exception{
39     }
40
41     @AfterClass
42     public static void tearDownClass() throws Exception{
43     }
44
45     @Before
46     public void setUp() {
47         DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
48         try{
49             this.builder = factory.newDocumentBuilder();
50         }catch(ParserConfigurationException e){
51             fail();
52         }
53         return;
54     }
55
56     @After
57     public void tearDown() {
58     }
59
60     /**
61      * Test of parseIntList method, of class LandDef.
62      */
63     @Test
64     public void testParseIntList(){
65         System.out.println("parseIntList");
66         CharSequence seq;
67         Collection<Integer> coll;
68         List<Integer> result;
69
70         seq = "1,2,3";
71         coll = LandDef.parseIntList(seq);
72         result = new ArrayList<>(coll);
73         assertEquals(3, result.size());
74         assertEquals(Integer.valueOf(1), result.get(0));
75         assertEquals(Integer.valueOf(2), result.get(1));
76         assertEquals(Integer.valueOf(3), result.get(2));
77
78         seq = "\u0020\t1\u0020,2,\u00203\t\u0020";
79         coll = LandDef.parseIntList(seq);
80         result = new ArrayList<>(coll);
81         assertEquals(3, result.size());
82         assertEquals(Integer.valueOf(1), result.get(0));
83         assertEquals(Integer.valueOf(2), result.get(1));
84         assertEquals(Integer.valueOf(3), result.get(2));
85
86         seq = "1-3";
87         coll = LandDef.parseIntList(seq);
88         result = new ArrayList<>(coll);
89         assertEquals(3, result.size());
90         assertEquals(Integer.valueOf(1), result.get(0));
91         assertEquals(Integer.valueOf(2), result.get(1));
92         assertEquals(Integer.valueOf(3), result.get(2));
93
94         seq = "1\u0020\t-\t\u00203";
95         coll = LandDef.parseIntList(seq);
96         result = new ArrayList<>(coll);
97         assertEquals(3, result.size());
98         assertEquals(Integer.valueOf(1), result.get(0));
99         assertEquals(Integer.valueOf(2), result.get(1));
100         assertEquals(Integer.valueOf(3), result.get(2));
101
102         seq = "3,2,1";
103         coll = LandDef.parseIntList(seq);
104         result = new ArrayList<>(coll);
105         assertEquals(3, result.size());
106         assertEquals(Integer.valueOf(1), result.get(0));
107         assertEquals(Integer.valueOf(2), result.get(1));
108         assertEquals(Integer.valueOf(3), result.get(2));
109
110         seq = "3-1";
111         coll = LandDef.parseIntList(seq);
112         result = new ArrayList<>(coll);
113         assertEquals(3, result.size());
114         assertEquals(Integer.valueOf(1), result.get(0));
115         assertEquals(Integer.valueOf(2), result.get(1));
116         assertEquals(Integer.valueOf(3), result.get(2));
117
118         seq = "1,2,3,11-13";
119         coll = LandDef.parseIntList(seq);
120         result = new ArrayList<>(coll);
121         assertEquals(6, result.size());
122         assertEquals(Integer.valueOf(1), result.get(0));
123         assertEquals(Integer.valueOf(2), result.get(1));
124         assertEquals(Integer.valueOf(3), result.get(2));
125         assertEquals(Integer.valueOf(11), result.get(3));
126         assertEquals(Integer.valueOf(12), result.get(4));
127         assertEquals(Integer.valueOf(13), result.get(5));
128
129         seq = "1,2,11-13,3";
130         coll = LandDef.parseIntList(seq);
131         result = new ArrayList<>(coll);
132         assertEquals(6, result.size());
133         assertEquals(Integer.valueOf(1), result.get(0));
134         assertEquals(Integer.valueOf(2), result.get(1));
135         assertEquals(Integer.valueOf(3), result.get(2));
136         assertEquals(Integer.valueOf(11), result.get(3));
137         assertEquals(Integer.valueOf(12), result.get(4));
138         assertEquals(Integer.valueOf(13), result.get(5));
139
140         seq = "1,1";
141         coll = LandDef.parseIntList(seq);
142         result = new ArrayList<>(coll);
143         assertEquals(1, result.size());
144         assertEquals(Integer.valueOf(1), result.get(0));
145
146         seq = "1,2,1";
147         coll = LandDef.parseIntList(seq);
148         result = new ArrayList<>(coll);
149         assertEquals(2, result.size());
150         assertEquals(Integer.valueOf(1), result.get(0));
151         assertEquals(Integer.valueOf(2), result.get(1));
152
153         seq = "1-3,2-4";
154         coll = LandDef.parseIntList(seq);
155         result = new ArrayList<>(coll);
156         assertEquals(4, result.size());
157         assertEquals(Integer.valueOf(1), result.get(0));
158         assertEquals(Integer.valueOf(2), result.get(1));
159         assertEquals(Integer.valueOf(3), result.get(2));
160         assertEquals(Integer.valueOf(4), result.get(3));
161
162         seq = "";
163         coll = LandDef.parseIntList(seq);
164         result = new ArrayList<>(coll);
165         assertEquals(0, result.size());
166
167         seq = "x";
168         try{
169             LandDef.parseIntList(seq);
170             fail();
171         }catch(IllegalArgumentException e){
172         }
173
174         seq = "1,x,3";
175         try{
176             LandDef.parseIntList(seq);
177             fail();
178         }catch(IllegalArgumentException e){
179         }
180
181         seq = "-";
182         try{
183             LandDef.parseIntList(seq);
184             fail();
185         }catch(IllegalArgumentException e){
186         }
187
188         seq = "1-2-3";
189         try{
190             LandDef.parseIntList(seq);
191             fail();
192         }catch(IllegalArgumentException e){
193         }
194
195         seq = "1-x";
196         try{
197             LandDef.parseIntList(seq);
198             fail();
199         }catch(IllegalArgumentException e){
200         }
201
202         seq = "x-3";
203         try{
204             LandDef.parseIntList(seq);
205             fail();
206         }catch(IllegalArgumentException e){
207         }
208
209         seq = "1-";
210         try{
211             LandDef.parseIntList(seq);
212             fail();
213         }catch(IllegalArgumentException e){
214         }
215
216         seq = "-3";
217         try{
218             LandDef.parseIntList(seq);
219             fail();
220         }catch(IllegalArgumentException e){
221         }
222
223         return;
224     }
225
226     /**
227      * Test of buildLandDefList method, of class LandDef.
228      */
229     @Test
230     public void testBuildLandDefList(){
231         System.out.println("buildLandDefList");
232
233         List<LandDef> result;
234         try{
235             result = LandDef.buildLandDefList(this.builder);
236         }catch(SAXException e){
237             fail();
238             return;
239         }catch(IOException e){
240             fail();
241             return;
242         }
243
244         assertEquals(9, result.size());
245
246         assertEquals("wolf", result.get(0).getLandId());
247         assertEquals("wolff", result.get(7).getLandId());
248         assertEquals("wolfg", result.get(8).getLandId());
249
250         return;
251     }
252
253     private List<LandDef> loadList(){
254         List<LandDef> result;
255         try{
256             result = LandDef.buildLandDefList(this.builder);
257         }catch(SAXException e){
258             fail();
259             return null;
260         }catch(IOException e){
261             fail();
262             return null;
263         }
264         return result;
265     }
266
267     private LandDef selectLand(String id){
268         for(LandDef land : loadList()){
269             if(land.getLandId().equals(id)) return land;
270         }
271         return null;
272     }
273
274     /**
275      * Test of getLandName method, of class LandDef.
276      */
277     @Test
278     public void testGetLandName(){
279         System.out.println("getLandName");
280
281         assertEquals("人狼BBS:古国", selectLand("wolf").getLandName());
282         assertEquals("人狼BBS:F国", selectLand("wolff").getLandName());
283         assertEquals("人狼BBS:G国", selectLand("wolfg").getLandName());
284
285         return;
286     }
287
288     /**
289      * Test of getLandId method, of class LandDef.
290      */
291     @Test
292     public void testGetLandId(){
293         System.out.println("getLandId");
294
295         assertEquals("wolf", selectLand("wolf").getLandId());
296         assertEquals("wolf0", selectLand("wolf0").getLandId());
297         assertEquals("wolff", selectLand("wolff").getLandId());
298         assertEquals("wolfg", selectLand("wolfg").getLandId());
299
300         return;
301     }
302
303     /**
304      * Test of getFormalName method, of class LandDef.
305      */
306     @Test
307     public void testGetFormalName(){
308         System.out.println("getFormalName");
309
310         assertEquals("旧人狼BBS 2", selectLand("wolf").getFormalName());
311         assertEquals("人狼BBS:F", selectLand("wolff").getFormalName());
312         assertEquals("人狼BBS:G", selectLand("wolfg").getFormalName());
313
314         return;
315     }
316
317     /**
318      * Test of getLandPrefix method, of class LandDef.
319      */
320     @Test
321     public void testGetLandPrefix(){
322         System.out.println("getLandPrefix");
323
324         assertEquals("", selectLand("wolf").getLandPrefix());
325         assertEquals("", selectLand("wolf0").getLandPrefix());
326         assertEquals("F", selectLand("wolff").getLandPrefix());
327         assertEquals("G", selectLand("wolfg").getLandPrefix());
328
329         return;
330     }
331
332     /**
333      * Test of getLandState method, of class LandDef.
334      */
335     @Test
336     public void testGetLandState(){
337         System.out.println("getLandState");
338
339         assertEquals(LandState.HISTORICAL, selectLand("wolf0").getLandState());
340         assertEquals(LandState.HISTORICAL, selectLand("wolff").getLandState());
341         assertEquals(LandState.ACTIVE,     selectLand("wolfg").getLandState());
342
343         return;
344     }
345
346     /**
347      * Test of getMinMembers method, of class LandDef.
348      */
349     @Test
350     public void testGetMinMembers(){
351         System.out.println("getMinMembers");
352
353         assertEquals(8, selectLand("wolf0").getMinMembers());
354         assertEquals(11, selectLand("wolff").getMinMembers());
355         assertEquals(10, selectLand("wolfg").getMinMembers());
356
357         return;
358     }
359
360     /**
361      * Test of getMaxMembers method, of class LandDef.
362      */
363     @Test
364     public void testGetMaxMembers(){
365         System.out.println("getMaxMembers");
366
367         assertEquals(16, selectLand("wolf0").getMaxMembers());
368         assertEquals(16, selectLand("wolff").getMaxMembers());
369         assertEquals(16, selectLand("wolfg").getMaxMembers());
370
371         return;
372     }
373
374     /**
375      * Test of getWebURI method, of class LandDef.
376      */
377     @Test
378     public void testGetWebURI(){
379         System.out.println("getWebURI");
380
381         assertEquals("http://ninjinix.x0.com/wolf/",
382                      selectLand("wolf").getWebURI().toString());
383         assertEquals("http://ninjinix.x0.com/wolff/",
384                      selectLand("wolff").getWebURI().toString());
385         assertEquals("http://www.wolfg.x0.com/",
386                      selectLand("wolfg").getWebURI().toString());
387
388         return;
389     }
390
391     /**
392      * Test of getCgiURI method, of class LandDef.
393      */
394     @Test
395     public void testGetCgiURI(){
396         System.out.println("getCgiURI");
397
398         assertEquals("http://ninjinix.x0.com/wolf/index.rb",
399                      selectLand("wolf").getCgiURI().toString());
400         assertEquals("http://ninjinix.x0.com/wolff/index.rb",
401                      selectLand("wolff").getCgiURI().toString());
402         assertEquals("http://www.wolfg.x0.com/index.rb",
403                      selectLand("wolfg").getCgiURI().toString());
404
405         return;
406     }
407
408     /**
409      * Test of getTombFaceIconURI method, of class LandDef.
410      */
411     @Test
412     public void testGetTombFaceIconURI(){
413         System.out.println("getTombFaceIconURI");
414
415         assertEquals("plugin_wolf/img/face99.jpg",
416                      selectLand("wolf").getTombFaceIconURI().toString());
417         assertEquals("../img/face99.jpg",
418                      selectLand("wolf0").getTombFaceIconURI().toString());
419         assertEquals("plugin_wolf/img/face99.jpg",
420                      selectLand("wolff").getTombFaceIconURI().toString());
421         assertEquals("plugin_wolf/img/face99.jpg",
422                      selectLand("wolfg").getTombFaceIconURI().toString());
423
424         return;
425     }
426
427     /**
428      * Test of getTombBodyIconURI method, of class LandDef.
429      */
430     @Test
431     public void testGetTombBodyIconURI(){
432         System.out.println("getTombBodyIconURI");
433
434         assertEquals("plugin_wolf/img/body99.jpg",
435                      selectLand("wolf").getTombBodyIconURI().toString());
436         assertEquals("../img/body99.jpg",
437                      selectLand("wolf0").getTombBodyIconURI().toString());
438         assertEquals("plugin_wolf/img/body99.jpg",
439                      selectLand("wolff").getTombBodyIconURI().toString());
440         assertEquals("plugin_wolf/img/body99.jpg",
441                      selectLand("wolfg").getTombBodyIconURI().toString());
442
443         return;
444     }
445
446     /**
447      * Test of getFaceURITemplate method, of class LandDef.
448      */
449     @Test
450     public void testGetFaceURITemplate(){
451         System.out.println("getFaceURITemplate");
452
453         assertEquals("./plugin_wolf/img/face{0,number,#00}.jpg",
454                      selectLand("wolf").getFaceURITemplate());
455         assertEquals("../img/face{0,number,#00}.jpg",
456                      selectLand("wolf0").getFaceURITemplate());
457         assertEquals("./plugin_wolf/img/face{0,number,#00}.jpg",
458                      selectLand("wolff").getFaceURITemplate());
459         assertEquals("./plugin_wolf/img/face{0,number,#00}.jpg",
460                      selectLand("wolfg").getFaceURITemplate());
461
462         return;
463     }
464
465     /**
466      * Test of getBodyURITemplate method, of class LandDef.
467      */
468     @Test
469     public void testGetBodyURITemplate(){
470         System.out.println("getBodyURITemplate");
471
472         assertEquals("./plugin_wolf/img/body{0,number,#00}.jpg",
473                      selectLand("wolf").getBodyURITemplate());
474         assertEquals("../img/body{0,number,#00}.jpg",
475                      selectLand("wolf0").getBodyURITemplate());
476         assertEquals("./plugin_wolf/img/body{0,number,#00}.jpg",
477                      selectLand("wolff").getBodyURITemplate());
478         assertEquals("./plugin_wolf/img/body{0,number,#00}.jpg",
479                      selectLand("wolfg").getBodyURITemplate());
480
481         return;
482     }
483
484     /**
485      * Test of getLocale method, of class LandDef.
486      */
487     @Test
488     public void testGetLocale(){
489         System.out.println("getLocale");
490
491         assertEquals(Locale.JAPAN, selectLand("wolf").getLocale());
492         assertEquals(Locale.JAPAN, selectLand("wolff").getLocale());
493         assertEquals(Locale.JAPAN, selectLand("wolfg").getLocale());
494
495         return;
496     }
497
498     /**
499      * Test of getEncoding method, of class LandDef.
500      */
501     @Test
502     public void testGetEncoding(){
503         System.out.println("getEncoding");
504
505         Charset sj = Charset.forName("Shift_JIS");
506
507         assertEquals(sj, selectLand("wolf").getEncoding());
508         assertEquals(sj, selectLand("wolff").getEncoding());
509
510         Charset utf8 = Charset.forName("UTF-8");
511
512         assertEquals(utf8, selectLand("wolfg").getEncoding());
513
514         return;
515     }
516
517     /**
518      * Test of getTimeZone method, of class LandDef.
519      */
520     @Test
521     public void testGetTimeZone(){
522         System.out.println("getTimeZone");
523
524         TimeZone tz = TimeZone.getTimeZone("GMT+09");
525
526         assertTrue(tz.hasSameRules(selectLand("wolf0").getTimeZone()));
527         assertTrue(tz.hasSameRules(selectLand("wolff").getTimeZone()));
528         assertTrue(tz.hasSameRules(selectLand("wolfg").getTimeZone()));
529
530         return;
531     }
532
533     /**
534      * Test of getStartDateTime method, of class LandDef.
535      */
536     @Test
537     public void testGetStartDateTime(){
538         System.out.println("getStartDateTime");
539
540         TimeZone tz = TimeZone.getTimeZone("GMT+09");
541
542         GregorianCalendar cal = new GregorianCalendar();
543         cal.clear();
544         cal.setTimeZone(tz);
545
546         cal.set(2004, 8-1, 15, 23, 31, 36);
547         assertEquals(cal.getTimeInMillis(),
548                      selectLand("wolf").getStartDateTime());
549
550         cal.set(2005, 9-1, 12, 20, 21, 3);
551         assertEquals(cal.getTimeInMillis(),
552                      selectLand("wolff").getStartDateTime());
553
554         cal.set(2010, 3-1,  7, 13, 53, 27);
555         assertEquals(cal.getTimeInMillis(),
556                      selectLand("wolfg").getStartDateTime());
557
558         return;
559     }
560
561     /**
562      * Test of getEndDateTime method, of class LandDef.
563      */
564     @Test
565     public void testGetEndDateTime(){
566         System.out.println("getEndDateTime");
567
568         TimeZone tz = TimeZone.getTimeZone("GMT+09");
569
570         GregorianCalendar cal = new GregorianCalendar();
571         cal.clear();
572         cal.setTimeZone(tz);
573
574         cal.set(2004, 9-1, 30, 13, 58, 31);
575         assertEquals(cal.getTimeInMillis(),
576                      selectLand("wolf").getEndDateTime());
577
578         assertTrue(0 > selectLand("wolfg").getEndDateTime());
579
580         return;
581     }
582
583     /**
584      * Test of getDescription method, of class LandDef.
585      */
586     @Test
587     public void testGetDescription(){
588         System.out.println("getDescription");
589
590         assertNotNull(selectLand("wolf0").getDescription());
591         assertNotNull(selectLand("wolff").getDescription());
592         assertNotNull(selectLand("wolfg").getDescription());
593
594         return;
595     }
596
597     /**
598      * Test of getContactInfo method, of class LandDef.
599      */
600     @Test
601     public void testGetContactInfo(){
602         System.out.println("getContactInfo");
603
604         assertNotNull(selectLand("wolf0").getContactInfo());
605         assertNotNull(selectLand("wolff").getContactInfo());
606         assertNotNull(selectLand("wolfg").getContactInfo());
607
608         return;
609     }
610
611     /**
612      * Test of isValidVillageId method, of class LandDef.
613      */
614     @Test
615     public void testIsValidVillageId(){
616         System.out.println("isValidVillageId");
617
618         assertTrue(selectLand("wolfa").isValidVillageId(339));
619         assertFalse(selectLand("wolfa").isValidVillageId(340));
620         assertTrue(selectLand("wolfa").isValidVillageId(343));
621         assertTrue(selectLand("wolfa").isValidVillageId(366));
622         assertFalse(selectLand("wolfa").isValidVillageId(367));
623
624         assertFalse(selectLand("wolfb").isValidVillageId(149));
625
626         assertFalse(selectLand("wolfc").isValidVillageId(451));
627
628         return;
629     }
630
631     /**
632      * Test of buildLocale method, of class LandDef.
633      */
634     @Test
635     public void testBuildLocale(){
636         System.out.println("buildLocale");
637         assertEquals(Locale.JAPAN, LandDef.buildLocale("ja-JP"));
638         assertEquals(Locale.JAPANESE, LandDef.buildLocale("ja"));
639         return;
640     }
641
642 }