~donal-k-fellows/taverna-server/2.5-branch

« back to all changes in this revision

Viewing changes to server-execution-delegate/src/test/java/SerializationTest.java

  • Committer: donal.k.fellows@man.ac.uk
  • Date: 2012-10-25 14:42:46 UTC
  • Revision ID: git-v1:b6c60a63b847e4c0d03ca5664c8570451588bdd8
Starting to code the workflow report serialization plugin

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import static org.junit.Assert.assertEquals;
 
2
import static org.junit.Assert.assertFalse;
 
3
import static org.junit.Assert.assertTrue;
 
4
 
 
5
import java.io.IOException;
 
6
import java.io.StringWriter;
 
7
 
 
8
import javax.xml.bind.JAXBContext;
 
9
import javax.xml.bind.JAXBException;
 
10
import javax.xml.bind.SchemaOutputResolver;
 
11
import javax.xml.transform.Result;
 
12
import javax.xml.transform.stream.StreamResult;
 
13
 
 
14
import org.junit.Before;
 
15
import org.junit.Test;
 
16
import org.taverna.server.execution_delegate.RemoteExecution.WorkflowReportDocument;
 
17
 
 
18
public class SerializationTest {
 
19
        private static final boolean PRINT = true;
 
20
        SchemaOutputResolver sink;
 
21
        StringWriter schema;
 
22
 
 
23
        String schema() {
 
24
                return schema.toString();
 
25
        }
 
26
 
 
27
        @Before
 
28
        public void init() {
 
29
                schema = new StringWriter();
 
30
                sink = new SchemaOutputResolver() {
 
31
                        @Override
 
32
                        public Result createOutput(String namespaceUri,
 
33
                                        String suggestedFileName) throws IOException {
 
34
                                StreamResult sr = new StreamResult(schema);
 
35
                                sr.setSystemId("/dev/null");
 
36
                                return sr;
 
37
                        }
 
38
                };
 
39
                assertEquals("", schema());
 
40
        }
 
41
 
 
42
        @Test
 
43
        public void testSchemaGeneration() throws JAXBException, IOException {
 
44
                JAXBContext.newInstance(WorkflowReportDocument.class).generateSchema(
 
45
                                sink);
 
46
                assertFalse("generated schema must be non-empty", schema().isEmpty());
 
47
                assertTrue(
 
48
                                "generated schema must define workflowReport element",
 
49
                                schema().contains(
 
50
                                                "<xs:element name=\"workflowReport\" type=\"WorkflowReport\"/>\n"));
 
51
                if (PRINT)
 
52
                        System.out.print(schema());
 
53
        }
 
54
}