source: VirtualCollectionRegistry/tags/VirtualCollectionRegistry-0.4.0-alpha2/VirtualCollectionRegistry/src/test/java/eu/clarin/cmdi/virtualcollectionregistry/service/impl/VirtualCollectionValidatorImplTest.java @ 5557

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

tag for VCR alpha 2

File size: 3.0 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.VirtualCollectionRegistryException;
20import eu.clarin.cmdi.virtualcollectionregistry.VirtualCollectionRegistryUsageException;
21import eu.clarin.cmdi.virtualcollectionregistry.model.Resource;
22import eu.clarin.cmdi.virtualcollectionregistry.model.VirtualCollection;
23import eu.clarin.cmdi.virtualcollectionregistry.service.VirtualCollectionValidator;
24import static org.junit.Assert.fail;
25import org.junit.Before;
26import org.junit.Test;
27
28/**
29 *
30 * @author twagoo
31 */
32public class VirtualCollectionValidatorImplTest {
33
34    private VirtualCollectionValidator instance;
35    private VirtualCollection vc;
36
37    @Before
38    public void setUp() {
39        vc = new VirtualCollection();
40        instance = new VirtualCollectionValidatorImpl();
41    }
42
43    @Test(expected = VirtualCollectionRegistryUsageException.class)
44    public void testValidateExtensionalEmptyResources() throws Exception {
45        vc.setName("Name");
46        vc.setType(VirtualCollection.Type.EXTENSIONAL);
47        instance.validate(vc);
48    }
49
50    @Test
51    public void testValidateExtensionalLegalResources() throws Exception {
52        vc.setName("Name");
53        vc.setType(VirtualCollection.Type.EXTENSIONAL);
54        vc.getResources().add(new Resource(Resource.Type.METADATA, "http://clarin.eu"));
55        vc.getResources().add(new Resource(Resource.Type.METADATA, "hdl:1234/5678"));
56        vc.getResources().add(new Resource(Resource.Type.METADATA, "doi:10.1000/182"));
57        try {
58            instance.validate(vc);
59        } catch (VirtualCollectionRegistryException ex) {
60            fail("Validation of valid collection failed: " + ex.getMessage());
61        }
62    }
63
64    @Test(expected = VirtualCollectionRegistryUsageException.class)
65    public void testValidateExtensionalIllegalResources() throws Exception {
66        vc.setName("Name");
67        vc.setType(VirtualCollection.Type.EXTENSIONAL);
68        vc.getResources().add(new Resource(Resource.Type.METADATA, "http://clarin.eu"));
69        vc.getResources().add(new Resource(Resource.Type.METADATA, "hdl:1234/5678"));
70        vc.getResources().add(new Resource(Resource.Type.METADATA, "doi:10.1000/182"));
71        vc.getResources().add(new Resource(Resource.Type.METADATA, "some://illegal/url"));
72        instance.validate(vc);
73    }
74
75}
Note: See TracBrowser for help on using the repository browser.