source: VirtualCollectionRegistry/trunk/VirtualCollectionRegistry/src/test/java/eu/clarin/cmdi/virtualcollectionregistry/service/impl/VirtualCollectionPrePublicationValidatorTest.java @ 5545

Last change on this file since 5545 was 5545, checked in by Twan Goosen, 10 years ago

Completed the pre-publication validator. Created tests. Tweaked the confirmation dialogue in case of warnings.
Fixes #607

File size: 4.6 KB
Line 
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 */
17package eu.clarin.cmdi.virtualcollectionregistry.service.impl;
18
19import eu.clarin.cmdi.virtualcollectionregistry.VirtualCollectionRegistryUsageException;
20import eu.clarin.cmdi.virtualcollectionregistry.model.Creator;
21import eu.clarin.cmdi.virtualcollectionregistry.model.GeneratedBy;
22import eu.clarin.cmdi.virtualcollectionregistry.model.Resource;
23import eu.clarin.cmdi.virtualcollectionregistry.model.VirtualCollection;
24import eu.clarin.cmdi.virtualcollectionregistry.service.VirtualCollectionValidator;
25import org.junit.Before;
26import org.junit.Test;
27import static org.junit.Assert.*;
28
29/**
30 *
31 * @author twagoo
32 */
33public 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        try {
57            instance.validate(vc);
58        } catch (VirtualCollectionRegistryUsageException ex) {
59            fail("Validation should not fail");
60        }
61    }
62   
63    @Test(expected = VirtualCollectionRegistryUsageException.class)
64    public void testValidateResourcesNonPid() throws Exception {
65        // Non-PIDs should not be allowed as references
66        vc.getResources().add(new Resource(Resource.Type.METADATA, "hdl:1234/5678"));
67        vc.getResources().add(new Resource(Resource.Type.METADATA, "doi:1.2.3/456"));
68        vc.getResources().add(new Resource(Resource.Type.METADATA, "http://clarin.eu"));
69        instance.validate(vc);
70    }
71   
72    @Test(expected = VirtualCollectionRegistryUsageException.class)
73    public void testValidateQueryUriNonPid() throws Exception {
74        // Non-PIDs should not be allowed as query URI
75        vc.setType(VirtualCollection.Type.INTENSIONAL);
76        final GeneratedBy generatedBy = new GeneratedBy();
77        generatedBy.setURI("http://catalog.clarin.eu/vlo");
78        vc.setGeneratedBy(generatedBy);
79        instance.validate(vc);
80    }
81   
82    @Test(expected = VirtualCollectionRegistryUsageException.class)
83    public void testValidateNoDescription() throws Exception {
84        // Description should not be allowed to be null
85        vc.setDescription(null);
86        instance.validate(vc);
87    }
88   
89    @Test(expected = VirtualCollectionRegistryUsageException.class)
90    public void testValidateNoCreators() throws Exception {
91        // Description should not be allowed to be null
92        vc.getCreators().clear();
93        instance.validate(vc);
94    }
95   
96    @Test(expected = VirtualCollectionRegistryUsageException.class)
97    public void testValidatePurposeFutureUse() throws Exception {
98        // Description should not be allowed to be null
99        vc.setPurpose(VirtualCollection.Purpose.FUTURE_USE);
100        instance.validate(vc);
101    }
102   
103    @Test(expected = VirtualCollectionRegistryUsageException.class)
104    public void testValidateNoPurpose() throws Exception {
105        // Description should not be allowed to be null
106        vc.setPurpose(null);
107        instance.validate(vc);
108    }
109   
110    @Test(expected = VirtualCollectionRegistryUsageException.class)
111    public void testValidateNoReproducibility() throws Exception {
112        // Description should not be allowed to be null
113        vc.setReproducibility(null);
114        instance.validate(vc);
115    }
116}
Note: See TracBrowser for help on using the repository browser.