source: vlo/branches/vlo-3.3-oeaw/vlo-commons/src/test/java/eu/clarin/cmdi/vlo/config/DefaultVloConfigFactoryTest.java @ 6412

Last change on this file since 6412 was 6412, checked in by davor.ostojic@oeaw.ac.at, 9 years ago

merged with trunk
#746

File size: 22.6 KB
Line 
1package eu.clarin.cmdi.vlo.config;
2
3import java.io.File;
4import java.util.Arrays;
5import java.util.List;
6import java.util.Properties;
7import java.util.Set;
8import static org.hamcrest.CoreMatchers.hasItems;
9import static org.junit.Assert.*;
10import org.junit.Before;
11import org.junit.Test;
12
13/**
14 *
15 * @author keeloo
16 */
17public class DefaultVloConfigFactoryTest {
18
19    public DefaultVloConfigFactoryTest() {
20    }
21
22    private VloConfig config;
23    private Properties testProps;
24
25    @Before
26    public void setUp() throws Exception {
27        config = new DefaultVloConfigFactory().newConfig();
28        testProps = new Properties();
29        testProps.load(getClass().getResourceAsStream("/vloconfig.properties"));
30    }
31
32    /**
33     * Test the getDataRoots method.<br><br>
34     *
35     * Use the values defined in the packaged {@literal VloConfig.xml}
36     * configuration file.
37     */
38    @Test
39    public void testGetDataRoots() {
40        final List<DataRoot> rootsReturned = config.getDataRoots();
41
42        assertNotNull(rootsReturned);
43        assertTrue("One or more data roots should be defined", rootsReturned.size() > 0);
44        assertNotNull(rootsReturned.get(0).getOriginName());
45        assertTrue("Origin name cannot be empty", rootsReturned.get(0).getOriginName().length() > 0);
46        assertNotNull(rootsReturned.get(0).getPrefix());
47        assertTrue("Prefix cannot be empty", rootsReturned.get(0).getPrefix().length() > 0);
48        assertNotNull(rootsReturned.get(0).getRootFile());
49        assertTrue("Root file cannot be empty", rootsReturned.get(0).getRootFile().getName().length() > 0);
50        assertNotNull(rootsReturned.get(0).getToStrip());
51    }
52
53    /**
54     * Test the set setDataRoots method
55     */
56    @Test
57    public void testSetDataRoots() {
58
59        List<DataRoot> dataRoots = Arrays.asList(
60                new DataRoot("MPI IMDI Archive",
61                        new File("/lat/apache/htdocs/oai-harvester/mpi-self-harvest/harvested/results/cmdi/"),
62                        "http://catalog.clarin.eu/",
63                        "/lat/apache/htdocs/", false),
64                new DataRoot("CMDI Providers",
65                        new File("/lat/apache/htdocs/oai-harvester/cmdi-providers/harvested/results/cmdi/"),
66                        "http://catalog.clarin.eu/",
67                        "/lat/apache/htdocs/", false),
68                new DataRoot("OLAC Metadata Providers",
69                        new File("/lat/apache/htdocs/oai-harvester/olac-and-dc-providers/harvested/results/cmdi/"),
70                        "http://catalog.clarin.eu/",
71                        "/lat/apache/htdocs/", false));
72
73        System.out.println("setDataRoots");
74
75        config.setDataRoots(dataRoots);
76
77        List rootsReturned = config.getDataRoots();
78
79        assertEquals(dataRoots, rootsReturned);
80    }
81
82    /**
83     * Test the getPagesInApplicationCache method
84     */
85    @Test
86    public void testGetPagesInApplicationCache() {
87
88        System.out.println("getPagesInApplicationCache");
89
90        int expResult = 40; // as defined in vloconfig.xml
91        int result = config.getPagesInApplicationCache();
92
93        assertEquals(expResult, result);
94    }
95
96    /**
97     * Test the setPagesInApplicationCache method
98     */
99    @Test
100    public void testSetPagesInApplicationCache() {
101
102        System.out.println("setPagesInApplicationCache");
103
104        int param = 999;
105
106        config.setPagesInApplicationCache(param);
107
108        int result = config.getPagesInApplicationCache();
109
110        assertEquals(param, result);
111    }
112
113    /**
114     * Test the getSessionCacheSize method
115     */
116    @Test
117    public void testGetSessionCacheSize() {
118
119        System.out.println("getPagesInApplicationCache");
120
121        int expResult = 10000; // as defined in vloconfig.xml
122        int result = config.getSessionCacheSize();
123
124        assertEquals(expResult, result);
125    }
126
127    /**
128     * Test the setSessionCacheSize method
129     */
130    @Test
131    public void testSetSessionCacheSize() {
132
133        System.out.println("setPagesInApplicationCache");
134
135        int param = 9999;
136
137        config.setSessionCacheSize(param);
138
139        int result = config.getSessionCacheSize();
140
141        assertEquals(param, result);
142    }
143
144    /**
145     * Test the getMaxDocsInList method
146     */
147    @Test
148    public void testGetMaxDocsInList() {
149
150        System.out.println("getMaxDocsInList");
151
152        int expResult = 128;
153        int result = config.getMaxDocsInList();
154
155        assertEquals(expResult, result);
156    }
157
158    /**
159     * Test the setMaxDocsInList method
160     */
161    @Test
162    public void testSetMaxDocsInList() {
163
164        System.out.println("setMaxDocsInList");
165
166        int param = 1000;
167
168        config.setMaxDocsInList(param);
169
170        int result = config.getMaxDocsInList();
171
172        assertEquals(param, result);
173    }
174
175    /**
176     * Test the getMaxDocsInSolrQueue method
177     */
178    @Test
179    public void testGetMaxDocsInSolrQueue() {
180
181        System.out.println("getMaxDocsInSolrQueue");
182
183        int expResult = 128;
184        int result = config.getMaxDocsInList();
185
186        assertEquals(expResult, result);
187    }
188
189    /**
190     * Test the setMaxDocsInSolrQueue method
191     */
192    @Test
193    public void testSetMaxDocsInSolrQueue() {
194
195        System.out.println("setMaxDocsInSolrQueue");
196
197        int param = 1000;
198
199        config.setMaxDocsInList(param);
200
201        int result = config.getMaxDocsInList();
202
203        assertEquals(param, result);
204    }
205
206    /**
207     * Test the getMaxFileSize method
208     */
209    @Test
210    public void testGetMaxFileSize() {
211
212        System.out.println("getMaxFileSize");
213
214        int expResult = 10000000;
215        int result = config.getMaxFileSize();
216
217        assertEquals(expResult, result);
218    }
219
220    /**
221     * Test the setMaxFileSize method
222     */
223    @Test
224    public void testSetMaxFileSize() {
225
226        System.out.println("setMaxFileSize");
227
228        int param = 10000000;
229
230        config.setMaxFileSize(param);
231
232        int result = config.getMaxFileSize();
233
234        assertEquals(param, result);
235    }
236
237    /**
238     * Test the getHandleResolver method
239     */
240    @Test
241    public void testGetUseHandleResolver() {
242
243        System.out.println("getUseHandleResolver");
244
245        boolean expResult = false;
246        boolean result = config.getUseHandleResolver();
247
248        assertEquals(expResult, result);
249    }
250
251    /**
252     * Test the setUseHandleResolver method
253     */
254    @Test
255    public void testSetUseHandleResolver() {
256
257        System.out.println("setUseHandleResolver");
258
259        boolean param = true;
260
261        config.setUseHandleResolver(param);
262
263        boolean result = config.getUseHandleResolver();
264
265        assertEquals(param, result);
266    }
267
268    /**
269     * Test the deleteAllFirst method
270     */
271    @Test
272    public void testDeleteAllFirst() {
273
274        System.out.println("deleteAllFirst");
275
276        boolean expResult = Boolean.valueOf(testProps.getProperty("deleteAllFirst"));
277        boolean result = config.getDeleteAllFirst();
278
279        assertEquals(expResult, result);
280    }
281
282    /**
283     * Test the deleteAllFirst method
284     */
285    @Test
286    public void testSetDeleteAllFirst() {
287
288        System.out.println("setDeleteAllFirst");
289
290        boolean param = true;
291
292        config.setDeleteAllFirst(param);
293
294        boolean result = config.getDeleteAllFirst();
295
296        assertEquals(param, result);
297    }
298
299    /**
300     * Test the printMapping method
301     */
302    @Test
303    public void testPrintMapping() {
304
305        System.out.println("printMapping");
306
307        boolean expResult = false;
308        boolean result = config.printMapping();
309
310        assertEquals(expResult, result);
311    }
312
313    /**
314     * Test the setPrintMapping method
315     */
316    @Test
317    public void testSetPrintMapping() {
318        System.out.println("setPrintMapping");
319
320        boolean param = false;
321
322        config.setPrintMapping(param);
323
324        boolean result = config.printMapping();
325
326        assertEquals(param, result);
327    }
328
329    /**
330     * Test the getHomeUrl method
331     */
332    @Test
333    public void testGetVloHomeLink() {
334
335        System.out.println("getVloHomeLink");
336
337        String expResult = testProps.getProperty("homeUrl");
338        String result = config.getHomeUrl();
339
340        assertEquals(expResult, result);
341    }
342
343    /**
344     * Test the setHomeUrl method
345     */
346    @Test
347    public void testSetVloHomeLink() {
348
349        System.out.println("setVloHomeLink");
350
351        String param = "http://www.clarin.eu/vlo";
352
353        config.setHomeUrl(param);
354
355        String result = config.getHomeUrl();
356
357        assertEquals(param, result);
358    }
359
360    /**
361     * Test the getHelpUrl method
362     */
363    @Test
364    public void testGetHelpUrl() {
365
366        System.out.println("getHelpUrl");
367
368        String expResult = testProps.getProperty("helpUrl");
369        String result = config.getHelpUrl();
370
371        assertEquals(expResult, result);
372    }
373
374    /**
375     * Test the setHelpUrl method
376     */
377    @Test
378    public void testSetHelpUrl() {
379
380        System.out.println("setHelpUrl");
381
382        String param = "http://www.clarin.eu/vlo";
383
384        config.setHelpUrl(param);
385
386        String result = config.getHelpUrl();
387
388        assertEquals(param, result);
389    }
390
391    /**
392     * Test the getSolrUrl method
393     */
394    @Test
395    public void testGetSolrUrl() {
396
397        System.out.println("getSolrUrl");
398
399        String expResult = testProps.getProperty("solrUrl");
400        String result = config.getSolrUrl();
401
402        assertEquals(expResult, result);
403    }
404
405    /**
406     * Test the setHomeUrl method
407     */
408    @Test
409    public void testSetSolrUrl() {
410
411        System.out.println("setSolrUrl");
412
413        String param = "http://localhost:8084/vlo_solr/";
414
415        config.setSolrUrl(param);
416
417        String result = config.getSolrUrl();
418
419        assertEquals(param, result);
420    }
421
422    /**
423     * Test the getGetComponentRegistryProfileSchema method
424     */
425    @Test
426    public void testGetComponentRegistryProfileSchema() {
427
428        System.out.println("getComponentRegistryProfileSchema");
429
430        String expResult = "http://catalog.clarin.eu/ds/ComponentRegistry/rest/registry/profiles/someId/xsd";
431        String result = config.getComponentRegistryProfileSchema("someId");
432
433        assertEquals(expResult, result);
434    }
435
436    /**
437     * Test the getComponentRegistryRESTURL method
438     */
439    @Test
440    public void testGetComponentRegistryRESTURL() {
441
442        System.out.println("getComponentRegistryRESTURL");
443
444        String expResult = "http://catalog.clarin.eu/ds/ComponentRegistry/rest/registry/profiles/";
445        String result = config.getComponentRegistryRESTURL();
446
447        assertEquals(expResult, result);
448    }
449
450    /**
451     * Test the setComponentRegistryRESTURL method
452     */
453    @Test
454    public void testComponentRegistryRESTURL() {
455
456        System.out.println("setComponentRegistryRESTURL");
457
458        String param = "http://catalog.clarin.eu/ds/ComponentRegistry/rest/registry/profiles/";
459
460        config.setComponentRegistryRESTURL(param);
461
462        String result = config.getComponentRegistryRESTURL();
463
464        assertEquals(param, result);
465    }
466
467    /**
468     * Test the getHandleServerUrl method
469     */
470    @Test
471    public void testGetHandleServerUrl() {
472
473        System.out.println("getHandleServerUrl");
474
475        String expResult = "http://hdl.handle.net/";
476        String result = config.getHandleServerUrl();
477
478        assertEquals(expResult, result);
479    }
480
481    /**
482     * Test the setHandleServerUrl method
483     */
484    @Test
485    public void testSetHandleServerUrl() {
486
487        System.out.println("setHandleServerUrl");
488
489        String param = "http://hdl.handle.net/";
490
491        config.setHandleServerUrl(param);
492
493        String result = config.getHandleServerUrl();
494
495        assertEquals(param, result);
496    }
497
498    /**
499     * Test the getLanguageLinkTemplate method
500     */
501    @Test
502    public void testGetLanguageLinkPrefix() {
503
504        System.out.println("getLanguageLinkPrefix");
505
506        String expResult = "https://infra.clarin.eu/content/language_info/data/{}.html";
507        String result = config.getLanguageLinkTemplate();
508
509        assertEquals(expResult, result);
510    }
511
512    /**
513     * Test the setLanguageLinkPrefix method
514     */
515    @Test
516    public void testSetLanguageLinkPrefix() {
517
518        System.out.println("setLanguageLinkPrefix");
519
520        String param = "https://infra.clarin.eu/content/language_info/data/{}.html";
521
522        config.setLanguageLinkTemplate(param);
523
524        String result = config.getLanguageLinkTemplate();
525
526        assertEquals(param, result);
527    }
528
529    /**
530     * Test the getFeedbackFromUrl method
531     */
532    @Test
533    public void testGetFeedbackFromUrl() {
534
535        System.out.println("getFeedBackFromUrl");
536
537        String expResult = "http://www.clarin.eu/node/3759?url=";
538        String result = config.getFeedbackFromUrl();
539
540        assertEquals(expResult, result);
541    }
542
543    /**
544     * Test the setFeedbackFromUrl method
545     */
546    @Test
547    public void testSetFeedbackFromUrl() {
548
549        System.out.println("setFeedbackFromUrl");
550
551        String param = "http://www.clarin.eu/node/3759?url=";
552
553        config.setFeedbackFromUrl(param);
554
555        String result = config.getFeedbackFromUrl();
556
557        assertEquals(param, result);
558    }
559
560    /**
561     * Test the getFederatedContentSearchUrl method
562     */
563    @Test
564    public void testGetFederatedContentSearchUrl() {
565
566        System.out.println("getFederatedContentSearchUrl");
567
568        String expResult = "http://weblicht.sfs.uni-tuebingen.de/Aggregator/";
569        String result = config.getFederatedContentSearchUrl();
570
571        assertEquals(expResult, result);
572    }
573
574    /**
575     * Test the setFederatedContentSearchUrl method
576     */
577    @Test
578    public void testSetFederatedContentSearchUrl() {
579
580        System.out.println("setFederatedContentSearchUrl");
581
582        String param = "http://weblicht.sfs.uni-tuebingen.de/Aggregator/";
583
584        config.setFederatedContentSearchUrl(param);
585
586        String result = config.getFederatedContentSearchUrl();
587
588        assertEquals(param, result);
589    }
590
591    /**
592     * Test the getNationalProjectMapping method
593     */
594    @Test
595    public void testGetNationalProjectMapping() {
596
597        System.out.println("getNationalProjectMapping");
598
599        String expResult = "/nationalProjectsMapping.xml";
600        String result = config.getNationalProjectMapping();
601
602        assertEquals(expResult, result);
603    }
604
605    /**
606     * Test the setNationalProjectMapping method
607     */
608    @Test
609    public void testSetNationalProjectMapping() {
610
611        System.out.println("setFNationalProjectMapping");
612
613        String param = "nationalProjectsMapping.xml";
614
615        config.setNationalProjectMapping(param);
616
617        String result = config.getNationalProjectMapping();
618
619        assertEquals(param, result);
620    }
621
622    /**
623     * Test of getFacetFields method
624     */
625    @Test
626    public void testGetFacetFields() {
627
628        System.out.println("getFacetFields");
629
630        List<String> expResult = Arrays.asList(
631                "languageCode",
632                "collection",
633                "resourceClass",
634                "continent",
635                "country",
636                "modality",
637                "genre",
638                "subject",
639                "format",
640                "organisation",
641                "availability",
642                "nationalProject",
643                "keywords",
644                "dataProvider");
645
646        List<String> result = config.getFacetFields();
647
648        assertEquals(expResult, result);
649    }
650
651    @Test
652    public void testGetAllFacetsField() {
653        final String[] expItems = new String[]{
654            "languageCode",
655            "collection",
656            "resourceClass",
657            "modality",
658            "continent",
659            "genre",
660            "country",
661            "subject",
662            "organisation",
663            "format",
664            "dataProvider",
665            "nationalProject",
666            "keywords",
667            "collection"};
668        List<String> result = config.getAllFacetFields();
669
670        //order is not important in this case
671        assertThat(result, hasItems(expItems));
672    }
673
674    /**
675     * Test of setFacetFields method, of class VloConfig
676     */
677    @Test
678    public void testSetFacetFields() {
679
680        System.out.println("setFacetFields");
681
682        List<String> expResult = Arrays.asList(
683                "language",
684                "resourceClass",
685                "modality",
686                "continent",
687                "genre",
688                "country",
689                "dataProvider",
690                "nationalProject",
691                "keywords");
692
693        config.setFacetFields(expResult);
694
695        List<String> result = config.getFacetFields();
696
697        assertEquals(expResult, result);
698    }
699
700    /**
701     * Test the getCountryComponentUrl method.
702     */
703    @Test
704    public void testCountryComponentUrl() {
705
706        System.out.println("getCountryComponentUrl");
707
708        String expResult = "http://catalog.clarin.eu/ds/ComponentRegistry/rest/registry/components/clarin.eu:cr1:c_1271859438104/xml";
709        String result = config.getCountryComponentUrl();
710
711        assertEquals(expResult, result);
712    }
713
714    /**
715     * Test the setCountryComponentUrl method.
716     */
717    @Test
718    public void testSetCountryComponentUrl() {
719
720        System.out.println("setCountryComponentUrl");
721
722        String param = "http://catalog.clarin.eu/ds/ComponentRegistry/rest/registry/components/clarin.eu:cr1:c_1271859438104/xml";
723
724        config.setCountryComponentUrl(param);
725
726        String result = config.getCountryComponentUrl();
727
728        assertEquals(param, result);
729    }
730
731    /**
732     * Test the getLanguage2LetterCodeComponentUrl method.
733     */
734    @Test
735    public void testGetLanguage2LetterCodeComponentUrl() {
736
737        System.out.println("getLanguage2LetterCodeComponentUrl");
738
739        String expResult = "http://catalog.clarin.eu/ds/ComponentRegistry/rest/registry/components/clarin.eu:cr1:c_1271859438109/xml";
740        String result = config.getLanguage2LetterCodeComponentUrl();
741
742        assertEquals(expResult, result);
743    }
744
745    /**
746     * Test the setLanguage2LetterCodeComponentUrl method.
747     */
748    @Test
749    public void testSetLanguage2LetterCodeComponentUrl() {
750
751        System.out.println("setLanguage2LetterCodeComponentUrl");
752
753        String param = "http://catalog.clarin.eu/ds/ComponentRegistry/rest/registry/components/clarin.eu:cr1:c_1271859438109/xml";
754
755        config.setLanguage2LetterCodeComponentUrl(param);
756
757        String result = config.getLanguage2LetterCodeComponentUrl();
758
759        assertEquals(param, result);
760    }
761
762    /**
763     * Test the getLanguage3LetterCodeComponentUrl.
764     */
765    @Test
766    public void testGetLanguage3LetterCodeComponentUrl() {
767
768        System.out.println("getLanguage3LetterCodeComponentUrl");
769
770        String expResult = "http://catalog.clarin.eu/ds/ComponentRegistry/rest/registry/components/clarin.eu:cr1:c_1271859438110/xml";
771        String result = config.getLanguage3LetterCodeComponentUrl();
772
773        assertEquals(expResult, result);
774    }
775
776    /**
777     * Test the setLanguage3LetterCodeComponentUrl.
778     */
779    @Test
780    public void testSetLanguage3LetterCodeComponentUrl() {
781
782        System.out.println("setLanguage3LetterCodeComponentUrl");
783
784        String param = "http://catalog.clarin.eu/ds/ComponentRegistry/rest/registry/components/clarin.eu:cr1:c_1271859438110/xml";
785
786        config.setLanguage3LetterCodeComponentUrl(param);
787
788        String result = config.getLanguage3LetterCodeComponentUrl();
789
790        assertEquals(param, result);
791    }
792
793    /**
794     * Test the getSilToISO639CodesUrl method.
795     */
796    @Test
797    public void testGetSilToISO639CodesUrl() {
798
799        System.out.println("getSilToISO639CodesUrl");
800
801        String expResult = "http://www.clarin.eu/cmd/xslt/sil_to_iso6393.xml";
802        String result = config.getSilToISO639CodesUrl();
803
804        assertEquals(expResult, result);
805    }
806
807    /**
808     * Test the setSilToISO639CodesUrl method.
809     */
810    @Test
811    public void testSetSilToISO639CodesUrl() {
812
813        System.out.println("setSilToISO639CodesUrl");
814
815        String param = "http://www.clarin.eu/cmd/xslt/sil_to_iso6393.xml";
816
817        config.setSilToISO639CodesUrl(param);
818
819        String result = config.getSilToISO639CodesUrl();
820
821        assertEquals(param, result);
822    }
823
824    /**
825     * Test the getReverseProxyPrefix method
826     */
827    @Test
828    public void testReverseProxyPrefix() {
829
830        System.out.println("getReverseProxyPrefix");
831
832        String expResult = "";
833        String result = config.getReverseProxyPrefix();
834
835        assertEquals(expResult, result);
836    }
837
838    /**
839     * Test the setReverseProxyPrefix method
840     */
841    @Test
842    public void testSetReverseProxyPrefix() {
843
844        System.out.println("setReverseProxyPrefix");
845
846        String param = "vlodev/";
847
848        config.setReverseProxyPrefix(param);
849
850        String result = config.getReverseProxyPrefix();
851
852        assertEquals(param, result);
853    }
854
855    /**
856     * Test the getCqlEndpointFilter method
857     */
858    @Test
859    public void testGetCqlEndpointFilter() {
860
861        System.out.println("getCqlEndpointFilter");
862
863        String expResult = "http://cqlservlet.mpi.nl/";
864        String result = config.getCqlEndpointFilter();
865
866        assertEquals(expResult, result);
867    }
868
869    /**
870     * Test the setCqlEndpointFilter method
871     */
872    @Test
873    public void testSetCqlEndpointFilter() {
874
875        System.out.println("setCqlEndpointFilter");
876
877        String param = "http://cqlservlet.mpi.nl/";
878
879        config.setCqlEndpointFilter(param);
880
881        String result = config.getCqlEndpointFilter();
882
883        assertEquals(param, result);
884    }
885
886    /**
887     * Test the getCqlEndpointAlternative method
888     */
889    @Test
890    public void testGetCqlEndpointAlternative() {
891
892        System.out.println("getCqlEndpointAlternative");
893
894        String expResult = "http://cqlservlet.mpi.nl/";
895        String result = config.getCqlEndpointAlternative();
896
897        assertEquals(expResult, result);
898    }
899
900    /**
901     * Test the setCqlEndpointAlternative method
902     */
903    @Test
904    public void testSetCqlEndpointAlternative() {
905
906        System.out.println("setCqlEndpointAlternative");
907
908        String param = "http://cqlservlet.mpi.nl/";
909
910        config.setCqlEndpointAlternative(param);
911
912        String result = config.getCqlEndpointAlternative();
913
914        assertEquals(param, result);
915    }
916
917    @Test
918    public void testGetCollectionFacet() {
919        final String result = config.getCollectionFacet();
920        assertNull(result);
921    }
922
923    @Test
924    public void testGetIgnoredFields() {
925        Set<String> result = config.getIgnoredFields();
926        assertEquals(2, result.size());
927    }
928
929    @Test
930    public void testGetTechnicalFields() {
931        Set<String> result = config.getTechnicalFields();
932        assertEquals(12, result.size());
933    }
934
935    @Test
936    public void testGetSimpleSearchFacetFields() {
937        List<String> result = config.getSimpleSearchFacetFields();
938        assertEquals(5, result.size());
939    }
940}
Note: See TracBrowser for help on using the repository browser.