Revision 9292
Added by Jing Tao over 9 years ago
test/edu/ucsb/nceas/metacat/dataone/D1NodeVersionCheckerTest.java | ||
---|---|---|
1 |
/** |
|
2 |
* '$RCSfile$' |
|
3 |
* Copyright: 2010 Regents of the University of California and the |
|
4 |
* National Center for Ecological Analysis and Synthesis |
|
5 |
* Purpose: To test the Access Controls in metacat by JUnit |
|
6 |
* |
|
7 |
* '$Author:$' |
|
8 |
* '$Date:$' |
|
9 |
* '$Revision:$' |
|
10 |
* |
|
11 |
* This program is free software; you can redistribute it and/or modify |
|
12 |
* it under the terms of the GNU General Public License as published by |
|
13 |
* the Free Software Foundation; either version 2 of the License, or |
|
14 |
* (at your option) any later version. |
|
15 |
* |
|
16 |
* This program is distributed in the hope that it will be useful, |
|
17 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
19 |
* GNU General Public License for more details. |
|
20 |
* |
|
21 |
* You should have received a copy of the GNU General Public License |
|
22 |
* along with this program; if not, write to the Free Software |
|
23 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
24 |
*/ |
|
25 |
|
|
26 |
package edu.ucsb.nceas.metacat.dataone; |
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
import edu.ucsb.nceas.MCTestCase; |
|
31 |
import edu.ucsb.nceas.metacat.dataone.CNodeService; |
|
32 |
import edu.ucsb.nceas.metacat.dataone.D1NodeVersionChecker; |
|
33 |
import edu.ucsb.nceas.metacat.dataone.MNodeService; |
|
34 |
import edu.ucsb.nceas.metacat.properties.SkinPropertyService; |
|
35 |
import edu.ucsb.nceas.metacat.service.ServiceService; |
|
36 |
import edu.ucsb.nceas.utilities.IOUtil; |
|
37 |
import gov.loc.repository.bagit.Bag; |
|
38 |
import gov.loc.repository.bagit.BagFactory; |
|
39 |
import gov.loc.repository.bagit.BagFile; |
|
40 |
import gov.loc.repository.bagit.Manifest; |
|
41 |
|
|
42 |
import java.io.ByteArrayInputStream; |
|
43 |
import java.io.ByteArrayOutputStream; |
|
44 |
import java.io.File; |
|
45 |
import java.io.FileOutputStream; |
|
46 |
import java.io.IOException; |
|
47 |
import java.io.InputStream; |
|
48 |
import java.io.UnsupportedEncodingException; |
|
49 |
import java.math.BigInteger; |
|
50 |
import java.net.URL; |
|
51 |
import java.text.SimpleDateFormat; |
|
52 |
import java.util.ArrayList; |
|
53 |
import java.util.Calendar; |
|
54 |
import java.util.Date; |
|
55 |
import java.util.HashMap; |
|
56 |
import java.util.Iterator; |
|
57 |
import java.util.List; |
|
58 |
import java.util.Map; |
|
59 |
import java.util.Vector; |
|
60 |
|
|
61 |
import junit.framework.Test; |
|
62 |
import junit.framework.TestSuite; |
|
63 |
|
|
64 |
import org.apache.commons.io.FileUtils; |
|
65 |
import org.apache.commons.io.IOUtils; |
|
66 |
import org.dataone.client.v2.CNode; |
|
67 |
import org.dataone.client.v2.formats.ObjectFormatCache; |
|
68 |
import org.dataone.client.v2.itk.D1Client; |
|
69 |
import org.dataone.configuration.Settings; |
|
70 |
import org.dataone.ore.ResourceMapFactory; |
|
71 |
import org.dataone.service.util.Constants; |
|
72 |
import org.dataone.service.util.TypeMarshaller; |
|
73 |
import org.dataone.service.exceptions.IdentifierNotUnique; |
|
74 |
import org.dataone.service.exceptions.InsufficientResources; |
|
75 |
import org.dataone.service.exceptions.InvalidRequest; |
|
76 |
import org.dataone.service.exceptions.InvalidSystemMetadata; |
|
77 |
import org.dataone.service.exceptions.InvalidToken; |
|
78 |
import org.dataone.service.exceptions.NotAuthorized; |
|
79 |
import org.dataone.service.exceptions.NotFound; |
|
80 |
import org.dataone.service.exceptions.NotImplemented; |
|
81 |
import org.dataone.service.exceptions.ServiceFailure; |
|
82 |
import org.dataone.service.exceptions.SynchronizationFailed; |
|
83 |
import org.dataone.service.exceptions.UnsupportedType; |
|
84 |
import org.dataone.service.types.v1.AccessPolicy; |
|
85 |
import org.dataone.service.types.v1.AccessRule; |
|
86 |
import org.dataone.service.types.v1.Checksum; |
|
87 |
import org.dataone.service.types.v1.DescribeResponse; |
|
88 |
import org.dataone.service.types.v1.Event; |
|
89 |
import org.dataone.service.types.v1.ObjectFormatIdentifier; |
|
90 |
import org.dataone.service.types.v1.Identifier; |
|
91 |
import org.dataone.service.types.v2.Log; |
|
92 |
import org.dataone.service.types.v2.Node; |
|
93 |
import org.dataone.service.types.v2.OptionList; |
|
94 |
import org.dataone.service.types.v1.NodeReference; |
|
95 |
import org.dataone.service.types.v1.ObjectFormatIdentifier; |
|
96 |
import org.dataone.service.types.v1.ObjectList; |
|
97 |
import org.dataone.service.types.v1.Permission; |
|
98 |
import org.dataone.service.types.v1.Person; |
|
99 |
import org.dataone.service.types.v1.Session; |
|
100 |
import org.dataone.service.types.v1.Subject; |
|
101 |
import org.dataone.service.types.v1.SubjectInfo; |
|
102 |
import org.dataone.service.types.v1.util.ChecksumUtil; |
|
103 |
import org.dataone.service.types.v2.SystemMetadata; |
|
104 |
import org.dspace.foresite.ResourceMap; |
|
105 |
import org.jibx.runtime.JiBXException; |
|
106 |
import org.junit.After; |
|
107 |
import org.junit.Before; |
|
108 |
|
|
109 |
|
|
110 |
/** |
|
111 |
* A JUnit test to exercise the Metacat Member Node service implementation. |
|
112 |
* This also tests a few of the D1NodeService superclass methods |
|
113 |
* |
|
114 |
* @author cjones |
|
115 |
* |
|
116 |
*/ |
|
117 |
public class D1NodeVersionCheckerTest extends MCTestCase { |
|
118 |
|
|
119 |
private static String unmatchingEncodingFilePath = "test/incorrect-encoding-declaration.xml"; |
|
120 |
/** |
|
121 |
* Set up the test fixtures |
|
122 |
* |
|
123 |
* @throws Exception |
|
124 |
*/ |
|
125 |
@Before |
|
126 |
public void setUp() throws Exception { |
|
127 |
super.setUp(); |
|
128 |
// set up the configuration for d1client |
|
129 |
|
|
130 |
} |
|
131 |
|
|
132 |
/** |
|
133 |
* Remove the test fixtures |
|
134 |
*/ |
|
135 |
@After |
|
136 |
public void tearDown() { |
|
137 |
} |
|
138 |
|
|
139 |
/** |
|
140 |
* Build the test suite |
|
141 |
* @return |
|
142 |
*/ |
|
143 |
public static Test suite() { |
|
144 |
|
|
145 |
TestSuite suite = new TestSuite(); |
|
146 |
suite.addTest(new D1NodeVersionCheckerTest("initialize")); |
|
147 |
// MNStorage tests |
|
148 |
suite.addTest(new D1NodeVersionCheckerTest("testGetVersion")); |
|
149 |
return suite; |
|
150 |
|
|
151 |
} |
|
152 |
|
|
153 |
/** |
|
154 |
* Constructor for the tests |
|
155 |
* |
|
156 |
* @param name - the name of the test |
|
157 |
*/ |
|
158 |
public D1NodeVersionCheckerTest(String name) { |
|
159 |
super(name); |
|
160 |
|
|
161 |
} |
|
162 |
|
|
163 |
/** |
|
164 |
* Initial blank test |
|
165 |
*/ |
|
166 |
public void initialize() { |
|
167 |
assertTrue(1 == 1); |
|
168 |
|
|
169 |
} |
|
170 |
|
|
171 |
/** |
|
172 |
* Test getting a known object |
|
173 |
*/ |
|
174 |
public void testGetVersion() throws Exception { |
|
175 |
Settings.getConfiguration().setProperty("D1Client.CN_URL", "https://cn-dev.test.dataone.org/cn"); |
|
176 |
NodeReference node = new NodeReference(); |
|
177 |
node.setValue("urn:node:mnDemo6"); |
|
178 |
D1NodeVersionChecker checker = new D1NodeVersionChecker(node); |
|
179 |
assertTrue(checker.getVersion("MNReplication").equals("v1")); |
|
180 |
node.setValue("urn:node:cnDevUCSB1"); |
|
181 |
checker = new D1NodeVersionChecker(node); |
|
182 |
assertTrue(checker.getVersion("MNReplication") == null); |
|
183 |
assertTrue(checker.getVersion("CNRegister").equals("v1")); |
|
184 |
|
|
185 |
} |
|
186 |
|
|
187 |
|
|
188 |
|
|
189 |
} |
Also available in: Unified diff
A test class is used to test the D1NodeVersionChecker class.