Project

General

Profile

« Previous | Next » 

Revision 6307

add the d1_common formats if they do not exist on the server

View differences:

test/edu/ucsb/nceas/metacat/dataone/CNodeServiceTest.java
26 26
package edu.ucsb.nceas.metacat.dataone;
27 27

  
28 28
import java.io.ByteArrayInputStream;
29
import java.io.ByteArrayOutputStream;
29 30
import java.io.InputStream;
31
import java.io.InputStreamReader;
32
import java.io.Reader;
30 33
import java.util.Date;
31 34

  
32 35
import junit.framework.Test;
......
39 42
import org.dataone.service.exceptions.NotFound;
40 43
import org.dataone.service.exceptions.NotImplemented;
41 44
import org.dataone.service.exceptions.ServiceFailure;
45
import org.dataone.service.impl.ObjectFormatServiceImpl;
42 46
import org.dataone.service.types.AccessPolicy;
43 47
import org.dataone.service.types.AccessRule;
44 48
import org.dataone.service.types.Checksum;
......
57 61
import org.dataone.service.types.Session;
58 62
import org.dataone.service.types.Subject;
59 63
import org.dataone.service.types.SystemMetadata;
64
import org.dataone.service.types.util.ServiceTypeUtil;
60 65

  
61 66
import edu.ucsb.nceas.MCTestCase;
67
import edu.ucsb.nceas.metacat.client.Metacat;
68
import edu.ucsb.nceas.metacat.client.MetacatFactory;
62 69

  
63 70
/**
64 71
 * A JUnit test for testing the dataone CNCore implementation
......
404 411
        
405 412
        return sm;
406 413
	}
414
	
415
	/**
416
	 * For fresh Metacat installations without the Object Format List
417
	 * we insert the default version from d1_common.jar
418
	 */
419
	private void setUpFormats() {
420
		try {
421
			Metacat m = MetacatFactory.createMetacatConnection(metacatUrl);
422
			m.login(username, password);
423
			// check if it exists already
424
			InputStream is = null;
425
			try {
426
				is = m.read(ObjectFormatService.OBJECT_FORMAT_DOCID);
427
			} catch (Exception e) {
428
				// probably missing the doc
429
			}
430
			if (is == null) {
431
				ObjectFormatList formats = ObjectFormatServiceImpl.getInstance().listFormats();
432
				ByteArrayOutputStream out = new ByteArrayOutputStream();
433
				ServiceTypeUtil.serializeServiceType(ObjectFormatList.class, formats, out);
434
				Reader xmlDocument = new InputStreamReader(new ByteArrayInputStream(out.toByteArray()));
435
				m.insert(ObjectFormatService.OBJECT_FORMAT_DOCID + ".1", xmlDocument, null);
436
			}
437
			m.logout();
438
		} catch (Exception e) {
439
			// any number of things could go wrong
440
			e.printStackTrace();
441
		}
442
	}
407 443

  
408 444
	/**
409 445
	 * test to list the object formats registered in metacat
......
412 448
		
413 449
    printTestHeader("testListFormats");
414 450
    
451
    // make sure we are set up
452
    setUpFormats();
453
    
415 454
    // there should be at least 59 formats in the list
416 455
  	int formatsCount = 59;
417 456
  	ObjectFormatList objectFormatList;
......
446 485
  	
447 486
    printTestHeader("testGetFormat");
448 487

  
488
    // make sure we are set up
489
    setUpFormats();
490
    
449 491
    String knownFormat = "text/plain";
450 492
    ObjectFormatIdentifier fmtid = new ObjectFormatIdentifier();
451 493
    fmtid.setValue(knownFormat);

Also available in: Unified diff