Project

General

Profile

« Previous | Next » 

Revision 8625

add test for invalid dryad content -- should be rejected because it is not schema valid.

View differences:

test/dryad-metadata-profile-invalid.xml
1
<DryadDataPackage xmlns="http://purl.org/dryad/schema/terms/v3.1" xmlns:dwc="http://rs.tdwg.org/dwc/terms/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:bibo="http://purl.org/dryad/schema/dryad-bibo/v3.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://purl.org/dryad/schema/terms/v3.1 http://datadryad.org/profile/v3.1/dryad.xsd">
2
  <bad>Should not be valid</bad>
3
  <dcterms:type>package</dcterms:type>
4
  <dcterms:creator>Zmasek, Christian M.</dcterms:creator>
5
  <dcterms:creator>Zhang, Qing</dcterms:creator>
6
  <dcterms:creator>Ye, Yuzhen</dcterms:creator>
7
  <dcterms:creator>Godzik, Adam</dcterms:creator>
8
  <dcterms:dateSubmitted>2007-12-06T20:55:28Z</dcterms:dateSubmitted>
9
  <dcterms:available>2007-12-06T20:55:28Z</dcterms:available>
10
  <dcterms:title>Data from: Surprising complexity of the ancestral apoptosis network</dcterms:title>
11
  <dcterms:identifier>http://dx.doi.org/10.5061/dryad.12</dcterms:identifier>
12
  <dcterms:references>http://dx.doi.org/10.1186/gb-2007-8-10-r226</dcterms:references>
13
  <dcterms:hasPart>http://dx.doi.org/10.5061/dryad.12/1</dcterms:hasPart>
14
  <dcterms:hasPart>http://dx.doi.org/10.5061/dryad.12/2</dcterms:hasPart>
15
  <dcterms:hasPart>http://dx.doi.org/10.5061/dryad.12/3</dcterms:hasPart>
16
  <dcterms:hasPart>http://dx.doi.org/10.5061/dryad.12/4</dcterms:hasPart>
17
  <dcterms:hasPart>http://dx.doi.org/10.5061/dryad.12/5</dcterms:hasPart>
18
  <dcterms:hasPart>http://dx.doi.org/10.5061/dryad.12/6</dcterms:hasPart>
19
</DryadDataPackage>
0 20

  
test/edu/ucsb/nceas/metacattest/DryadTest.java
32 32
import junit.framework.TestSuite;
33 33

  
34 34
import org.apache.commons.io.IOUtils;
35
import org.dataone.service.exceptions.ServiceFailure;
35 36
import org.dataone.service.types.v1.Identifier;
36 37
import org.dataone.service.types.v1.ObjectFormatIdentifier;
37 38
import org.dataone.service.types.v1.Session;
......
47 48
    extends D1NodeServiceTest {
48 49
    
49 50
    private static final String DRYAD_TEST_DOC = "test/dryad-metadata-profile-sample.xml";
51
    
52
    private static final String DRYAD_TEST_DOC_INVALID = "test/dryad-metadata-profile-invalid.xml";
50 53

  
51 54
    /**
52 55
     * Constructor to build the test
......
65 68
        suite.addTest(new DryadTest("initialize"));
66 69
        // Test basic functions
67 70
        suite.addTest(new DryadTest("d1InsertDoc"));
71
        suite.addTest(new DryadTest("d1InsertInvalidDoc"));
68 72

  
69 73
        return suite;
70 74
    }
......
103 107
    	
104 108
    }
105 109
    
110
    /**
111
     * Insert test doc using D1 API
112
     */
113
    public void d1InsertInvalidDoc() {
114
		try {
115
	    	String docid = this.generateDocumentId();
116
			String documentContents = this.getTestDocFromFile(DRYAD_TEST_DOC_INVALID);
117
			Session session = getTestSession();
118
			Identifier pid = new Identifier();
119
			pid.setValue(docid);
120
			SystemMetadata sysmeta = this.createSystemMetadata(pid, session.getSubject(), IOUtils.toInputStream(documentContents, "UTF-8"));
121
			ObjectFormatIdentifier formatId = new ObjectFormatIdentifier();
122
			formatId.setValue("http://datadryad.org/profile/v3.1");
123
			sysmeta.setFormatId(formatId);
124
			sysmeta.setSize(BigInteger.valueOf(IOUtils.toByteArray(documentContents).length));
125
			try {
126
				MNodeService.getInstance(request).create(session, pid, IOUtils.toInputStream(documentContents, "UTF-8"), sysmeta);
127
			} catch (Exception expectedException) {
128

  
129
				// expected exception
130
				assertTrue(expectedException instanceof ServiceFailure);
131
				return;
132
			}
133
			fail("Should not allow inserting invalid Dryad content");
134
		} catch (Exception e) {
135
			e.printStackTrace();
136
			fail(e.getMessage());
137
		}
138
    	
139
    }
140
    
106 141
}

Also available in: Unified diff