Project

General

Profile

« Previous | Next » 

Revision 6784

EML replication test with insert, update and set access
http://bugzilla.ecoinformatics.org/show_bug.cgi?id=5520

View differences:

test/edu/ucsb/nceas/metacat/replication/ReplicationTest.java
26 26
package edu.ucsb.nceas.metacat.replication;
27 27

  
28 28
import java.io.InputStream;
29
import java.io.StringReader;
29 30
import java.net.URL;
30 31

  
31 32
import org.apache.commons.io.IOUtils;
......
182 183
		}
183 184
    }
184 185
    
186
    public void testReplicateEML_AtoB() {
187
    	try {
188
    		// the id
189
    		String baseDocid = DocumentUtil.generateDocumentId("replicationTest", 0);
190
    		String docid = baseDocid + "." + 1;
191
    		
192
    		// the test data, no public access
193
    		String emlContent = null;
194
			emlContent = getTestEmlDoc(
195
    				"Test replication", //title, 
196
    				EML2_1_0, //emlVersion, 
197
    				null, //inlineData1, 
198
    				null, //inlineData2, 
199
    				null, //onlineUrl1, 
200
    				null, //onlineUrl2, 
201
    				null, //docAccessBlock , 
202
    				null, //inlineAccessBlock1, 
203
    				null, //inlineAccessBlock2, 
204
    				null, //onlineAccessBlock1, 
205
    				null //onlineAccessBlock2
206
    				);
207
    				
208
    		StringReader xmlReader = new StringReader(emlContent);
209
    		
210
			// insert data locally
211
    		m.login(username, password);
212
    		m.insert(docid, xmlReader, null);
213
    		
214
    		// wait for replication (forced)
215
    		Thread.sleep(forceReplicationSleep);
216
    		
217
    		// check the target for the same data
218
    		targetMetacat.login(username, password);
219
    		InputStream is = targetMetacat.read(docid);
220
    		String replicatedObject = IOUtils.toString(is, MetaCatServlet.DEFAULT_ENCODING);
221
    		
222
    		assertEquals(emlContent, replicatedObject);
223
    		
224
    		// update the object
225
    		docid = baseDocid + "." + 2;
226
    		//emlContent = getTestEmlDoc("Test replication2", EML2_1_0);
227
    		emlContent = getTestEmlDoc(
228
    				"Test replication", //title, 
229
    				EML2_1_0, //emlVersion, 
230
    				null, //inlineData1, 
231
    				null, //inlineData2, 
232
    				null, //onlineUrl1, 
233
    				null, //onlineUrl2, 
234
    				null, //docAccessBlock , 
235
    				null, //inlineAccessBlock1, 
236
    				null, //inlineAccessBlock2, 
237
    				null, //onlineAccessBlock1, 
238
    				null //onlineAccessBlock2
239
    				);
240
    		xmlReader = new StringReader(emlContent);
241
    		m.update(docid, xmlReader, null);
242

  
243
    		// wait for replication (forced)
244
    		Thread.sleep(forceReplicationSleep);
245
    		
246
    		// check the target for the updated data
247
    		is = targetMetacat.read(docid);
248
    		replicatedObject = IOUtils.toString(is, MetaCatServlet.DEFAULT_ENCODING);
249
    		
250
    		assertEquals(emlContent, replicatedObject);
251
    		
252
    		// update the access control rules
253
    		m.setAccess(
254
    				docid, 
255
    				AccessControlInterface.PUBLIC, 
256
    				AccessControlInterface.READSTRING, 
257
    				AccessControlInterface.ALLOW, 
258
    				AccessControlInterface.ALLOWFIRST);
259
    		
260
    		// wait for replication (forced)
261
    		Thread.sleep(forceReplicationSleep);
262
    		
263
    		// check the target for the same data, logout to act as public
264
    		targetMetacat.logout();
265
    		is = targetMetacat.read(docid);
266
    		replicatedObject = IOUtils.toString(is, MetaCatServlet.DEFAULT_ENCODING);
267
    		
268
    		assertEquals(emlContent, replicatedObject);
269
			
270
    	} catch (Exception e) {
271
    		e.printStackTrace();
272
			fail(e.getMessage());
273
		}
274
    }
275
    
185 276
    public void testReplicateData_BtoA() {
186 277
    	try {
187 278
    		// the id

Also available in: Unified diff