001: /**
002: * Copyright (c) 2007, Aberystwyth University
003: *
004: * All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions
008: * are met:
009: *
010: * - Redistributions of source code must retain the above
011: * copyright notice, this list of conditions and the
012: * following disclaimer.
013: *
014: * - Redistributions in binary form must reproduce the above copyright
015: * notice, this list of conditions and the following disclaimer in
016: * the documentation and/or other materials provided with the
017: * distribution.
018: *
019: * - Neither the name of the Centre for Advanced Software and
020: * Intelligent Systems (CASIS) nor the names of its
021: * contributors may be used to endorse or promote products derived
022: * from this software without specific prior written permission.
023: *
024: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
025: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
026: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
027: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
028: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
029: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
030: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
031: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
032: * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
033: * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
034: * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
035: * SUCH DAMAGE.
036: */package org.purl.sword.test;
037:
038: /**
039: * Author : $Author: nst $
040: * Date : $Date: 2007/09/21 15:18:57 $
041: * Revision : $Revision: 1.3 $
042: * Name : $Name: $
043: */
044:
045: import org.purl.sword.base.*;
046:
047: import org.w3.atom.*;
048:
049: /**
050: * Simple test class for the ServiceDocument and DepositResponse
051: * classes in the SWORD common classes.
052: *
053: * @author Neil Taylor
054: */
055: public class SwordTest {
056: /**
057: * Start the test of the ServiceDocument followed by the
058: * DepositResponse.
059: *
060: * @param args
061: */
062: public static void main(String[] args) {
063: SwordTest test = new SwordTest();
064: test.serviceDocumentTest();
065:
066: test.depositResponseTest();
067: }
068:
069: /**
070: * Create a test ServiceDocument class. Marshall and Unmarshall the
071: * data to ensure that it is preserved when transformed to and
072: * from an XML string.
073: */
074: public void serviceDocumentTest() {
075: // create a new service document
076: Service service = new Service(ServiceLevel.ZERO);
077: service.setVerbose(true);
078: service.setNoOp(false);
079:
080: // add some workspace/collections
081: Workspace workspace = new Workspace();
082: workspace.setTitle("This is a test");
083:
084: Collection collection = new Collection();
085: collection.setTitle("The first collection");
086: collection.setLocation("http://www.somewhere.com/here");
087:
088: workspace.addCollection(collection);
089:
090: service.addWorkspace(workspace);
091:
092: workspace = new Workspace();
093: workspace.setTitle("This is a second test");
094:
095: collection = new Collection();
096: collection.setTitle("The second collection");
097: collection
098: .setLocation("http://www.somewhere.com/here/something");
099: collection.addAccepts("application/zip");
100: collection.addAccepts("application/xml");
101: collection.setAbstract("An abstract goes in here");
102: collection.setCollectionPolicy("A collection policy");
103: collection.setMediation(true);
104: collection.setFormatNamespace("a namespace in here");
105: collection.setTreatment("treatment in here too");
106:
107: workspace.addCollection(collection);
108:
109: service.addWorkspace(workspace);
110:
111: // create the service document, marshall, unmarshall and marshall again.
112: ServiceDocument document = new ServiceDocument(service);
113:
114: // display the XML document that has been constructed
115: String doc = document.marshall();
116: System.out.println(doc);
117:
118: try {
119: ServiceDocument unmarshalledDocument = new ServiceDocument();
120: unmarshalledDocument.unmarshall(doc);
121:
122: System.out.println(unmarshalledDocument.marshall());
123: } catch (Exception e) {
124: e.printStackTrace();
125: }
126:
127: }
128:
129: /**
130: * Create a test DepositResponse class. Marshall and Unmarshall the
131: * data to ensure that it is preserved when transformed to and
132: * from an XML string.
133: */
134: public void depositResponseTest() {
135: try {
136:
137: DepositResponse response = new DepositResponse(
138: HttpHeaders.ACCEPTED);
139: SWORDEntry entry = new SWORDEntry();
140: entry.setId("atom:com.intrallect.atomTest3p0:60");
141: Title title = new Title();
142: title.setContent("Burning Stubble");
143: title.setType(ContentType.TEXT);
144: entry.setTitle(title);
145:
146: // add authors
147: Author author = new Author();
148: author.setName("Sword Tester");
149: author.setEmail("sword@ukoln.ac.uk");
150: author
151: .setUri("http://www.ukoln.ac.uk/repositories/digirep/index/SWORD");
152: entry.addAuthors(author);
153:
154: author = new Author();
155: author.setName("CASIS Tester");
156: author.setEmail("nst@aber.ac.uk");
157: author.setUri("http://www.aber.ac.uk/casis/");
158: entry.addAuthors(author);
159:
160: // add links
161: Link link = new Link();
162: link.setRel("edit-media");
163: link
164: .setHref("http://bagel.intrallect.com:5555/intralibrary3p0/IntraLibrary-Deposit/edit-media/learning_object_id60");
165: link.setHreflang("en");
166: link.setTitle("Edit Media Title");
167: link.setType("edit media type");
168: link.setContent("some content in here");
169:
170: entry.addLink(link);
171:
172: link = new Link();
173: link.setRel("edit");
174: link
175: .setHref("http://bagel.intrallect.com:5555/intralibrary3p0/IntraLibrary-Deposit/edit/learning_object_id60");
176: link.setHreflang("en");
177: link.setTitle("Edit Title");
178: link.setType("edit type");
179: link.setContent("some content in here");
180:
181: entry.addLink(link);
182:
183: entry.addCategory("test category");
184: entry.addCategory("second test category");
185:
186: Contributor contributor = new Contributor();
187: contributor.setName("Neil Taylor");
188: contributor.setEmail("nst@aber.ac.uk");
189: contributor.setUri("http://www.aber.ac.uk/casis/");
190:
191: entry.addContributor(contributor);
192:
193: Rights rights = new Rights();
194: rights.setType(ContentType.TEXT);
195: rights.setContent("Rights declaration.");
196: entry.setRights(rights);
197:
198: Content content = new Content();
199: content
200: .setSource("http://bagel.intrallect.com:5555/intralibrary3p0/IntraLibrary?command=open-preview&learning_object_key=i189n4207t");
201: content.setType("application/zip");
202: entry.setContent(content);
203:
204: Generator generator = new Generator();
205: generator.setContent("Test Generator ID");
206: generator.setUri("http://www.somewhere.com/");
207: generator.setVersion("1.1");
208:
209: Source source = new Source();
210: source.setGenerator(generator);
211: entry.setSource(source);
212:
213: entry.setPublished("2007-08-02T10:13:14Z");
214: entry.setUpdated("2007-08-02T10:22:17Z");
215:
216: entry.setFormatNamespace("Test format namespace");
217: entry.setTreatment("Treatment description");
218: entry.setNoOp(true);
219: entry.setVerboseDescription("A Verbose Description.");
220:
221: response.setEntry(entry);
222:
223: String test = response.marshall();
224: System.out.println(test);
225: System.out.println("=================");
226:
227: DepositResponse unmarshalledDocument = new DepositResponse(
228: HttpHeaders.CREATED);
229: unmarshalledDocument.unmarshall(test);
230: System.out.println(unmarshalledDocument.marshall());
231: } catch (Exception e) {
232: e.printStackTrace();
233: }
234: }
235:
236: }
|