Project

General

Profile

« Previous | Next » 

Revision 8622

test for inserting dryad instance doc. https://projects.ecoinformatics.org/ecoinfo/issues/6419

View differences:

test/edu/ucsb/nceas/metacattest/DryadTest.java
25 25

  
26 26
package edu.ucsb.nceas.metacattest;
27 27

  
28
import java.io.IOException;
29 28
import java.io.InputStream;
30 29
import java.io.StringReader;
30
import java.math.BigInteger;
31 31

  
32 32
import org.apache.commons.io.IOUtils;
33
import org.dataone.service.types.v1.Identifier;
34
import org.dataone.service.types.v1.ObjectFormatIdentifier;
35
import org.dataone.service.types.v1.Session;
36
import org.dataone.service.types.v1.SystemMetadata;
33 37

  
34 38
import junit.framework.Test;
35 39
import junit.framework.TestSuite;
36
import edu.ucsb.nceas.MCTestCase;
37
import edu.ucsb.nceas.metacat.client.InsufficientKarmaException;
38
import edu.ucsb.nceas.metacat.client.MetacatException;
39 40
import edu.ucsb.nceas.metacat.client.MetacatFactory;
40 41
import edu.ucsb.nceas.metacat.client.MetacatInaccessibleException;
42
import edu.ucsb.nceas.metacat.dataone.D1NodeServiceTest;
43
import edu.ucsb.nceas.metacat.dataone.MNodeService;
41 44

  
42 45
/**
43
 * A JUnit test for testing Metacat when Non Ascii Characters are inserted
46
 * A JUnit test for testing Dryad documents
44 47
 */
45 48
public class DryadTest
46
    extends MCTestCase {
49
    extends D1NodeServiceTest {
47 50
    
48 51
    private static final String DRYAD_TEST_DOC = "test/dryad-metadata-profile-sample.xml";
49 52

  
......
83 86
        TestSuite suite = new TestSuite();
84 87
        suite.addTest(new DryadTest("initialize"));
85 88
        // Test basic functions
86
        suite.addTest(new DryadTest("insertDoc"));
89
        //suite.addTest(new DryadTest("insertDoc"));
90
        suite.addTest(new DryadTest("d1InsertDoc"));
91

  
87 92
        return suite;
88 93
    }
89 94

  
......
96 101
    }
97 102
    
98 103
    /**
99
     * Test insert of Dryad document
100
     * @throws InsufficientKarmaException
101
     * @throws MetacatException
102
     * @throws IOException
103
     * @throws MetacatInaccessibleException
104
     * Test insert of Dryad document via Metacat
105
     * Note: formatId will be generic
104 106
     */
105 107
    public void insertDoc() {
106 108
		try {
......
119 121
		}
120 122
    	
121 123
    }
124
    
125
    /**
126
     * Insert test doc using D1 API
127
     */
128
    public void d1InsertDoc() {
129
		try {
130
	    	String docid = this.generateDocumentId();
131
	    	docid += ".1";
132
			String documentContents = this.getTestDocFromFile(DRYAD_TEST_DOC);
133
			Session session = getTestSession();
134
			Identifier pid = new Identifier();
135
			pid.setValue(docid);
136
			SystemMetadata sysmeta = this.createSystemMetadata(pid, session.getSubject(), IOUtils.toInputStream(documentContents, "UTF-8"));
137
			ObjectFormatIdentifier formatId = new ObjectFormatIdentifier();
138
			formatId.setValue("http://datadryad.org/profile/v3.1");
139
			sysmeta.setFormatId(formatId);
140
			sysmeta.setSize(BigInteger.valueOf(IOUtils.toByteArray(documentContents).length));
141
			MNodeService.getInstance(request).create(session, pid, IOUtils.toInputStream(documentContents, "UTF-8"), sysmeta);
142
			InputStream results = MNodeService.getInstance(request).get(session, pid);
143
			String resultString = IOUtils.toString(results);
144
			assertEquals(documentContents, resultString);
145
			m.logout();
146
		} catch (Exception e) {
147
			e.printStackTrace();
148
			fail(e.getMessage());
149
		}
150
    	
151
    }
122 152

  
123 153
    
124 154
}

Also available in: Unified diff