Project

General

Profile

1
/**
2
 *  '$RCSfile$'
3
 *  Copyright: 2004 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: leinfelder $'
8
 *     '$Date: 2014-02-20 12:42:36 -0800 (Thu, 20 Feb 2014) $'
9
 * '$Revision: 8624 $'
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.metacattest;
27

    
28
import java.io.InputStream;
29
import java.math.BigInteger;
30

    
31
import junit.framework.Test;
32
import junit.framework.TestSuite;
33

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

    
40
import edu.ucsb.nceas.metacat.dataone.D1NodeServiceTest;
41
import edu.ucsb.nceas.metacat.dataone.MNodeService;
42

    
43
/**
44
 * A JUnit test for testing Dryad documents
45
 */
46
public class DryadTest
47
    extends D1NodeServiceTest {
48
    
49
    private static final String DRYAD_TEST_DOC = "test/dryad-metadata-profile-sample.xml";
50

    
51
    /**
52
     * Constructor to build the test
53
     *
54
     * @param name the name of the test method
55
     */
56
    public DryadTest(String name) {
57
        super(name);
58
    }
59

    
60
    /**
61
     * Create a suite of tests to be run together
62
     */
63
    public static Test suite() {
64
        TestSuite suite = new TestSuite();
65
        suite.addTest(new DryadTest("initialize"));
66
        // Test basic functions
67
        suite.addTest(new DryadTest("d1InsertDoc"));
68

    
69
        return suite;
70
    }
71

    
72
    /**
73
     * Run an initial test that always passes to check that the test
74
     * harness is working.
75
     */
76
    public void initialize() {
77
        assertTrue(1 == 1);
78
    }
79
    
80
    /**
81
     * Insert test doc using D1 API
82
     */
83
    public void d1InsertDoc() {
84
		try {
85
	    	String docid = this.generateDocumentId();
86
			String documentContents = this.getTestDocFromFile(DRYAD_TEST_DOC);
87
			Session session = getTestSession();
88
			Identifier pid = new Identifier();
89
			pid.setValue(docid);
90
			SystemMetadata sysmeta = this.createSystemMetadata(pid, session.getSubject(), IOUtils.toInputStream(documentContents, "UTF-8"));
91
			ObjectFormatIdentifier formatId = new ObjectFormatIdentifier();
92
			formatId.setValue("http://datadryad.org/profile/v3.1");
93
			sysmeta.setFormatId(formatId);
94
			sysmeta.setSize(BigInteger.valueOf(IOUtils.toByteArray(documentContents).length));
95
			MNodeService.getInstance(request).create(session, pid, IOUtils.toInputStream(documentContents, "UTF-8"), sysmeta);
96
			InputStream results = MNodeService.getInstance(request).get(session, pid);
97
			String resultString = IOUtils.toString(results);
98
			assertEquals(documentContents, resultString);
99
		} catch (Exception e) {
100
			e.printStackTrace();
101
			fail(e.getMessage());
102
		}
103
    	
104
    }
105
    
106
}
(5-5/25)