1 | /* |
---|
2 | * Copyright (C) 2014 CLARIN |
---|
3 | * |
---|
4 | * This program is free software: you can redistribute it and/or modify |
---|
5 | * it under the terms of the GNU General Public License as published by |
---|
6 | * the Free Software Foundation, either version 3 of the License, or |
---|
7 | * (at your option) any later version. |
---|
8 | * |
---|
9 | * This program is distributed in the hope that it will be useful, |
---|
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
12 | * GNU General Public License for more details. |
---|
13 | * |
---|
14 | * You should have received a copy of the GNU General Public License |
---|
15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
16 | */ |
---|
17 | package eu.clarin.cmdi.virtualcollectionregistry.service.impl; |
---|
18 | |
---|
19 | import eu.clarin.cmdi.virtualcollectionregistry.VirtualCollectionRegistryUsageException; |
---|
20 | import eu.clarin.cmdi.virtualcollectionregistry.model.Creator; |
---|
21 | import eu.clarin.cmdi.virtualcollectionregistry.model.GeneratedBy; |
---|
22 | import eu.clarin.cmdi.virtualcollectionregistry.model.Resource; |
---|
23 | import eu.clarin.cmdi.virtualcollectionregistry.model.VirtualCollection; |
---|
24 | import eu.clarin.cmdi.virtualcollectionregistry.service.VirtualCollectionValidator; |
---|
25 | import org.junit.Before; |
---|
26 | import org.junit.Test; |
---|
27 | import static org.junit.Assert.*; |
---|
28 | |
---|
29 | /** |
---|
30 | * |
---|
31 | * @author twagoo |
---|
32 | */ |
---|
33 | public class VirtualCollectionPrePublicationValidatorTest { |
---|
34 | |
---|
35 | private VirtualCollection vc; |
---|
36 | private VirtualCollectionValidator instance; |
---|
37 | |
---|
38 | @Before |
---|
39 | public void setUp() { |
---|
40 | // start with a extensional collection that is valid (enough) |
---|
41 | vc = new VirtualCollection(); |
---|
42 | vc.setType(VirtualCollection.Type.EXTENSIONAL); |
---|
43 | vc.setName("Name"); |
---|
44 | vc.setDescription("Description"); |
---|
45 | vc.setPurpose(VirtualCollection.Purpose.SAMPLE); |
---|
46 | vc.setReproducibility(VirtualCollection.Reproducibility.INTENDED); |
---|
47 | vc.getCreators().add(new Creator("creator")); |
---|
48 | instance = new VirtualCollectionPrePublicationValidator(); |
---|
49 | } |
---|
50 | |
---|
51 | @Test |
---|
52 | public void testValidateResources() { |
---|
53 | // this is a valid resource set |
---|
54 | vc.getResources().add(new Resource(Resource.Type.METADATA, "hdl:1234/5678")); |
---|
55 | vc.getResources().add(new Resource(Resource.Type.METADATA, "doi:1.2.3/456")); |
---|
56 | vc.getResources().add(new Resource(Resource.Type.METADATA, "http://hdl.handle.net/1234/5678")); |
---|
57 | vc.getResources().add(new Resource(Resource.Type.METADATA, "http://dx.doi.org/1.2.3/456")); |
---|
58 | try { |
---|
59 | instance.validate(vc); |
---|
60 | } catch (VirtualCollectionRegistryUsageException ex) { |
---|
61 | fail("Validation should not fail"); |
---|
62 | } |
---|
63 | } |
---|
64 | |
---|
65 | @Test(expected = VirtualCollectionRegistryUsageException.class) |
---|
66 | public void testValidateResourcesNonPid() throws Exception { |
---|
67 | // Non-PIDs should not be allowed as references |
---|
68 | vc.getResources().add(new Resource(Resource.Type.METADATA, "hdl:1234/5678")); |
---|
69 | vc.getResources().add(new Resource(Resource.Type.METADATA, "doi:1.2.3/456")); |
---|
70 | vc.getResources().add(new Resource(Resource.Type.METADATA, "http://clarin.eu")); |
---|
71 | instance.validate(vc); |
---|
72 | } |
---|
73 | |
---|
74 | @Test(expected = VirtualCollectionRegistryUsageException.class) |
---|
75 | public void testValidateQueryUriNonPid() throws Exception { |
---|
76 | // Non-PIDs should not be allowed as query URI |
---|
77 | vc.setType(VirtualCollection.Type.INTENSIONAL); |
---|
78 | final GeneratedBy generatedBy = new GeneratedBy(); |
---|
79 | generatedBy.setURI("http://catalog.clarin.eu/vlo"); |
---|
80 | vc.setGeneratedBy(generatedBy); |
---|
81 | instance.validate(vc); |
---|
82 | } |
---|
83 | |
---|
84 | @Test(expected = VirtualCollectionRegistryUsageException.class) |
---|
85 | public void testValidateNoDescription() throws Exception { |
---|
86 | // Description should not be allowed to be null |
---|
87 | vc.setDescription(null); |
---|
88 | instance.validate(vc); |
---|
89 | } |
---|
90 | |
---|
91 | @Test(expected = VirtualCollectionRegistryUsageException.class) |
---|
92 | public void testValidateNoCreators() throws Exception { |
---|
93 | // Description should not be allowed to be null |
---|
94 | vc.getCreators().clear(); |
---|
95 | instance.validate(vc); |
---|
96 | } |
---|
97 | |
---|
98 | @Test(expected = VirtualCollectionRegistryUsageException.class) |
---|
99 | public void testValidatePurposeFutureUse() throws Exception { |
---|
100 | // Description should not be allowed to be null |
---|
101 | vc.setPurpose(VirtualCollection.Purpose.FUTURE_USE); |
---|
102 | instance.validate(vc); |
---|
103 | } |
---|
104 | |
---|
105 | @Test(expected = VirtualCollectionRegistryUsageException.class) |
---|
106 | public void testValidateNoPurpose() throws Exception { |
---|
107 | // Description should not be allowed to be null |
---|
108 | vc.setPurpose(null); |
---|
109 | instance.validate(vc); |
---|
110 | } |
---|
111 | |
---|
112 | @Test(expected = VirtualCollectionRegistryUsageException.class) |
---|
113 | public void testValidateNoReproducibility() throws Exception { |
---|
114 | // Description should not be allowed to be null |
---|
115 | vc.setReproducibility(null); |
---|
116 | instance.validate(vc); |
---|
117 | } |
---|
118 | } |
---|