Revision 9276
Added by Jing Tao over 9 years ago
test/edu/ucsb/nceas/metacat/dataone/MNodeServiceTest.java | ||
---|---|---|
174 | 174 |
suite.addTest(new MNodeServiceTest("testGetSID")); |
175 | 175 |
suite.addTest(new MNodeServiceTest("testListViews")); |
176 | 176 |
suite.addTest(new MNodeServiceTest("testUpdateSystemMetadata")); |
177 |
suite.addTest(new MNodeServiceTest("testUpdateObsoletesAndObsoletedBy")); |
|
177 | 178 |
|
178 | 179 |
return suite; |
179 | 180 |
|
... | ... | |
2108 | 2109 |
} |
2109 | 2110 |
} |
2110 | 2111 |
|
2112 |
public void testUpdateObsoletesAndObsoletedBy() throws Exception { |
|
2113 |
String str1 = "object1"; |
|
2114 |
String str2 = "object2"; |
|
2115 |
String str3 = "object3"; |
|
2116 |
|
|
2117 |
//insert two documents |
|
2118 |
Session session = getTestSession(); |
|
2119 |
Identifier guid1 = new Identifier(); |
|
2120 |
guid1.setValue(generateDocumentId()); |
|
2121 |
InputStream object1 = new ByteArrayInputStream(str1.getBytes("UTF-8")); |
|
2122 |
SystemMetadata sysmeta1 = createSystemMetadata(guid1, session.getSubject(), object1); |
|
2123 |
MNodeService.getInstance(request).create(session, guid1, object1, sysmeta1); |
|
2124 |
//Test the generating object succeeded. |
|
2125 |
SystemMetadata metadata = MNodeService.getInstance(request).getSystemMetadata(session, guid1); |
|
2126 |
assertTrue(metadata.getIdentifier().equals(guid1)); |
|
2127 |
assertTrue(metadata.getSize().equals(sysmeta1.getSize())); |
|
2128 |
|
|
2129 |
Identifier guid2 = new Identifier(); |
|
2130 |
guid2.setValue(generateDocumentId()); |
|
2131 |
InputStream object2 = new ByteArrayInputStream(str1.getBytes("UTF-8")); |
|
2132 |
SystemMetadata sysmeta2 = createSystemMetadata(guid2, session.getSubject(), object2); |
|
2133 |
MNodeService.getInstance(request).create(session, guid2, object2, sysmeta2); |
|
2134 |
//Test the generating object succeeded. |
|
2135 |
metadata = MNodeService.getInstance(request).getSystemMetadata(session, guid2); |
|
2136 |
assertTrue(metadata.getIdentifier().equals(guid2)); |
|
2137 |
assertTrue(metadata.getSize().equals(sysmeta2.getSize())); |
|
2138 |
|
|
2139 |
|
|
2140 |
|
|
2141 |
//update the system metadata without touching the obsoletes and obsoletdBy |
|
2142 |
AccessPolicy accessPolicy = new AccessPolicy(); |
|
2143 |
AccessRule allow = new AccessRule(); |
|
2144 |
allow.addPermission(Permission.WRITE); |
|
2145 |
Subject subject = new Subject(); |
|
2146 |
subject.setValue("user_foo"); |
|
2147 |
allow.addSubject(subject); |
|
2148 |
accessPolicy.addAllow(allow); |
|
2149 |
sysmeta1.setAccessPolicy(accessPolicy); |
|
2150 |
MNodeService.getInstance(request).updateSystemMetadata(session, guid1, sysmeta1); |
|
2151 |
metadata = MNodeService.getInstance(request).getSystemMetadata(session, guid1); |
|
2152 |
assertTrue(metadata.getIdentifier().equals(guid1)); |
|
2153 |
assertTrue(metadata.getObsoletedBy() == null); |
|
2154 |
assertTrue(metadata.getObsoletes() == null); |
|
2155 |
Session newSession = new Session(); |
|
2156 |
newSession.setSubject(subject); |
|
2157 |
boolean isAuthorized = MNodeService.getInstance(request).isAuthorized(newSession, guid1, Permission.WRITE); |
|
2158 |
assertTrue(isAuthorized); |
|
2159 |
|
|
2160 |
sysmeta2.setAccessPolicy(accessPolicy); |
|
2161 |
MNodeService.getInstance(request).updateSystemMetadata(session, guid2, sysmeta2); |
|
2162 |
metadata = MNodeService.getInstance(request).getSystemMetadata(session, guid2); |
|
2163 |
assertTrue(metadata.getIdentifier().equals(guid2)); |
|
2164 |
assertTrue(metadata.getObsoletes() == null); |
|
2165 |
assertTrue(metadata.getObsoletedBy() == null); |
|
2166 |
assertTrue(metadata.getChecksum().getValue().equals(sysmeta2.getChecksum().getValue())); |
|
2167 |
isAuthorized = MNodeService.getInstance(request).isAuthorized(newSession, guid2, Permission.WRITE); |
|
2168 |
assertTrue(isAuthorized); |
|
2169 |
|
|
2170 |
|
|
2171 |
|
|
2172 |
//update obsolets and obsoletedBy sucessfully |
|
2173 |
sysmeta1.setObsoletedBy(guid2); |
|
2174 |
MNodeService.getInstance(request).updateSystemMetadata(session, guid1, sysmeta1); |
|
2175 |
metadata = MNodeService.getInstance(request).getSystemMetadata(session, guid1); |
|
2176 |
assertTrue(metadata.getIdentifier().equals(guid1)); |
|
2177 |
assertTrue(metadata.getObsoletedBy().equals(guid2)); |
|
2178 |
assertTrue(metadata.getObsoletes() == null); |
|
2179 |
assertTrue(metadata.getChecksum().getValue().equals(sysmeta1.getChecksum().getValue())); |
|
2180 |
|
|
2181 |
sysmeta2.setObsoletes(guid1); |
|
2182 |
MNodeService.getInstance(request).updateSystemMetadata(session, guid2, sysmeta2); |
|
2183 |
metadata = MNodeService.getInstance(request).getSystemMetadata(session, guid2); |
|
2184 |
assertTrue(metadata.getIdentifier().equals(guid2)); |
|
2185 |
assertTrue(metadata.getObsoletes().equals(guid1)); |
|
2186 |
assertTrue(metadata.getObsoletedBy() == null); |
|
2187 |
assertTrue(metadata.getChecksum().getValue().equals(sysmeta2.getChecksum().getValue())); |
|
2188 |
|
|
2189 |
|
|
2190 |
|
|
2191 |
|
|
2192 |
//update obsolets and obsoletedBy sucessfully |
|
2193 |
sysmeta1.setObsoletedBy(guid2); |
|
2194 |
MNodeService.getInstance(request).updateSystemMetadata(session, guid1, sysmeta1); |
|
2195 |
metadata = MNodeService.getInstance(request).getSystemMetadata(session, guid1); |
|
2196 |
assertTrue(metadata.getIdentifier().equals(guid1)); |
|
2197 |
assertTrue(metadata.getObsoletedBy().equals(guid2)); |
|
2198 |
assertTrue(metadata.getObsoletes() == null); |
|
2199 |
assertTrue(metadata.getChecksum().getValue().equals(sysmeta1.getChecksum().getValue())); |
|
2200 |
|
|
2201 |
sysmeta2.setObsoletes(guid1); |
|
2202 |
MNodeService.getInstance(request).updateSystemMetadata(session, guid2, sysmeta2); |
|
2203 |
metadata = MNodeService.getInstance(request).getSystemMetadata(session, guid2); |
|
2204 |
assertTrue(metadata.getIdentifier().equals(guid2)); |
|
2205 |
assertTrue(metadata.getObsoletes().equals(guid1)); |
|
2206 |
assertTrue(metadata.getObsoletedBy() == null); |
|
2207 |
assertTrue(metadata.getChecksum().getValue().equals(sysmeta2.getChecksum().getValue())); |
|
2208 |
|
|
2209 |
|
|
2210 |
|
|
2211 |
|
|
2212 |
|
|
2213 |
//resetting the obsoletes and obsoletedBy fails |
|
2214 |
Identifier newId = new Identifier(); |
|
2215 |
newId.setValue("newValue"); |
|
2216 |
sysmeta1.setObsoletedBy(newId); |
|
2217 |
try { |
|
2218 |
MNodeService.getInstance(request).updateSystemMetadata(session, guid1, sysmeta1); |
|
2219 |
fail("We shouldn't get there"); |
|
2220 |
} catch (Exception e) { |
|
2221 |
e.printStackTrace(); |
|
2222 |
assertTrue(e instanceof InvalidRequest); |
|
2223 |
} |
|
2224 |
|
|
2225 |
sysmeta2.setObsoletes(newId); |
|
2226 |
try { |
|
2227 |
MNodeService.getInstance(request).updateSystemMetadata(session, guid2, sysmeta2); |
|
2228 |
fail("We shouldn't get there"); |
|
2229 |
} catch (Exception e) { |
|
2230 |
assertTrue(e instanceof InvalidRequest); |
|
2231 |
} |
|
2232 |
} |
|
2233 |
|
|
2111 | 2234 |
} |
Also available in: Unified diff
Add a test method to test the update of the obsoletes and obsoletedBy fields.