Revision 6563
Added by Chris Jones about 13 years ago
test/edu/ucsb/nceas/metacat/dataone/MetadataTypeRegisterTest.java | ||
---|---|---|
1 |
/* '$RCSfile$' |
|
2 |
* Copyright: 2010 Regents of the University of California and the |
|
3 |
* National Center for Ecological Analysis and Synthesis |
|
4 |
* Purpose: To test the Access Controls in metacat by JUnit |
|
5 |
* |
|
6 |
* '$Author: berkley $' |
|
7 |
* '$Date: 2010-05-03 14:26:08 -0700 (Fri, 14 Aug 2009) $' |
|
8 |
* '$Revision: 5027 $' |
|
9 |
* |
|
10 |
* This program is free software; you can redistribute it and/or modify |
|
11 |
* it under the terms of the GNU General Public License as published by |
|
12 |
* the Free Software Foundation; either version 2 of the License, or |
|
13 |
* (at your option) any later version. |
|
14 |
* |
|
15 |
* This program is distributed in the hope that it will be useful, |
|
16 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
17 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
18 |
* GNU General Public License for more details. |
|
19 |
* |
|
20 |
* You should have received a copy of the GNU General Public License |
|
21 |
* along with this program; if not, write to the Free Software |
|
22 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
23 |
*/ |
|
24 |
|
|
25 |
package edu.ucsb.nceas.metacat.dataone; |
|
26 |
|
|
27 |
import junit.framework.Test; |
|
28 |
import junit.framework.TestSuite; |
|
29 |
|
|
30 |
import org.dataone.client.ObjectFormatCache; |
|
31 |
import org.dataone.service.exceptions.NotFound; |
|
32 |
import org.dataone.service.types.v1.ObjectFormat; |
|
33 |
|
|
34 |
import edu.ucsb.nceas.MCTestCase; |
|
35 |
|
|
36 |
/** |
|
37 |
* A JUnit test for testing the dataone MetadataTypeRegister class |
|
38 |
*/ |
|
39 |
public class MetadataTypeRegisterTest extends MCTestCase |
|
40 |
{ |
|
41 |
private int createCount = 0; |
|
42 |
|
|
43 |
/** |
|
44 |
* consstructor for the test |
|
45 |
*/ |
|
46 |
public MetadataTypeRegisterTest(String name) |
|
47 |
{ |
|
48 |
super(name); |
|
49 |
} |
|
50 |
|
|
51 |
/** |
|
52 |
* Establish a testing framework by initializing appropriate objects |
|
53 |
*/ |
|
54 |
public void setUp() throws Exception |
|
55 |
{ |
|
56 |
super.setUp(); |
|
57 |
} |
|
58 |
|
|
59 |
/** |
|
60 |
* Release any objects after tests are complete |
|
61 |
*/ |
|
62 |
public void tearDown() |
|
63 |
{ |
|
64 |
System.out.println(createCount + " docs created in this test session."); |
|
65 |
} |
|
66 |
|
|
67 |
/** |
|
68 |
* Create a suite of tests to be run together |
|
69 |
*/ |
|
70 |
public static Test suite() |
|
71 |
{ |
|
72 |
TestSuite suite = new TestSuite(); |
|
73 |
suite.addTest(new MetadataTypeRegisterTest("testIsMetadataType")); |
|
74 |
return suite; |
|
75 |
} |
|
76 |
|
|
77 |
/** |
|
78 |
* MetadataTypeRegister.isMetadataType() |
|
79 |
*/ |
|
80 |
public void testIsMetadataType() |
|
81 |
{ |
|
82 |
ObjectFormat of = null; |
|
83 |
try { |
|
84 |
of = ObjectFormatCache.getInstance().getFormat("XXXX"); |
|
85 |
|
|
86 |
} catch (NotFound e) { |
|
87 |
assertFalse(MetadataTypeRegister.isMetadataType(of)); |
|
88 |
|
|
89 |
} |
|
90 |
|
|
91 |
try { |
|
92 |
|
|
93 |
of = ObjectFormatCache.getInstance().getFormat("eml://ecoinformatics.org/eml-2.0.0"); |
|
94 |
assertTrue(MetadataTypeRegister.isMetadataType(of)); |
|
95 |
|
|
96 |
of = ObjectFormatCache.getInstance().getFormat("http://www.unidata.ucar.edu/namespaces/netcdf/ncml-2.2"); |
|
97 |
assertTrue(MetadataTypeRegister.isMetadataType(of)); |
|
98 |
|
|
99 |
of = ObjectFormatCache.getInstance().getFormat("CF-1.3"); |
|
100 |
assertTrue(MetadataTypeRegister.isMetadataType(of)); |
|
101 |
|
|
102 |
of = ObjectFormatCache.getInstance().getFormat("http://www.loc.gov/METS/"); |
|
103 |
assertTrue(MetadataTypeRegister.isMetadataType(of)); |
|
104 |
|
|
105 |
of = ObjectFormatCache.getInstance().getFormat("eml://ecoinformatics.org/eml-3.0.0"); |
|
106 |
assertFalse(MetadataTypeRegister.isMetadataType(of)); |
|
107 |
|
|
108 |
} catch (NotFound e) { |
|
109 |
e.printStackTrace(); |
|
110 |
|
|
111 |
} |
|
112 |
|
|
113 |
} |
|
114 |
} |
src/edu/ucsb/nceas/metacat/dataone/MetadataTypeRegister.java | ||
---|---|---|
1 |
/** |
|
2 |
* '$RCSfile$' |
|
3 |
* Copyright: 2000 Regents of the University of California and the |
|
4 |
* National Center for Ecological Analysis and Synthesis |
|
5 |
* |
|
6 |
* '$Author: $' |
|
7 |
* '$Date: 2009-06-13 15:28:13 +0300 $' |
|
8 |
* |
|
9 |
* This program is free software; you can redistribute it and/or modify |
|
10 |
* it under the terms of the GNU General Public License as published by |
|
11 |
* the Free Software Foundation; either version 2 of the License, or |
|
12 |
* (at your option) any later version. |
|
13 |
* |
|
14 |
* This program is distributed in the hope that it will be useful, |
|
15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17 |
* GNU General Public License for more details. |
|
18 |
* |
|
19 |
* You should have received a copy of the GNU General Public License |
|
20 |
* along with this program; if not, write to the Free Software |
|
21 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
22 |
*/ |
|
23 |
package edu.ucsb.nceas.metacat.dataone; |
|
24 |
|
|
25 |
import java.io.*; |
|
26 |
import java.util.*; |
|
27 |
|
|
28 |
import edu.ucsb.nceas.metacat.properties.*; |
|
29 |
|
|
30 |
import org.apache.log4j.Logger; |
|
31 |
import org.dataone.service.types.v1.*; |
|
32 |
|
|
33 |
import edu.ucsb.nceas.metacat.properties.PropertyService; |
|
34 |
import edu.ucsb.nceas.utilities.PropertyNotFoundException; |
|
35 |
|
|
36 |
/** |
|
37 |
* @author berkley |
|
38 |
* A class to determine data types for metadata documents |
|
39 |
*/ |
|
40 |
public class MetadataTypeRegister |
|
41 |
{ |
|
42 |
private static Logger log = null; |
|
43 |
|
|
44 |
public static boolean isMetadataType(ObjectFormat format) |
|
45 |
{ |
|
46 |
log = Logger.getLogger(MetadataTypeRegister.class); |
|
47 |
if(format == null) |
|
48 |
{ |
|
49 |
return false; |
|
50 |
} |
|
51 |
|
|
52 |
try |
|
53 |
{ |
|
54 |
Map<String, String> types = PropertyService.getPropertiesByGroup("dataone"); |
|
55 |
//System.out.println("types: " + types.toString()); |
|
56 |
Iterator<String> vals = types.values().iterator(); |
|
57 |
//System.out.println("MetadataTypeRegister: looking through dataone types for type " + format.toString()); |
|
58 |
while(vals.hasNext()) |
|
59 |
{ |
|
60 |
String val = vals.next(); |
|
61 |
String ofVal = format.getFormatId().getValue(); |
|
62 |
//System.out.println("val: " + val); |
|
63 |
if(val.trim().equals(ofVal.trim())) |
|
64 |
{ |
|
65 |
//System.out.println("returning true"); |
|
66 |
log.info("type " + val + " IS a dataone metadata type"); |
|
67 |
return true; |
|
68 |
} |
|
69 |
} |
|
70 |
} |
|
71 |
catch(PropertyNotFoundException pnfe) |
|
72 |
{ |
|
73 |
log.error("Could not find the property 'dataone': " + pnfe.getMessage()); |
|
74 |
} |
|
75 |
|
|
76 |
if(format != null) |
|
77 |
{ |
|
78 |
log.info("type " + format.toString() + " is NOT a dataone metadata type"); |
|
79 |
} |
|
80 |
else |
|
81 |
{ |
|
82 |
log.info("A null format is not a dataone metadata type"); |
|
83 |
} |
|
84 |
|
|
85 |
return false; |
|
86 |
} |
|
87 |
} |
Also available in: Unified diff
MetadataTypeRegister is now replaced by ObjectFormatService. Removing it and it's test.