1 package org.apache.turbine.pipeline;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import static org.junit.Assert.assertEquals;
23 import static org.junit.Assert.assertTrue;
24
25 import java.io.StringReader;
26 import java.io.StringWriter;
27
28 import javax.xml.bind.JAXBContext;
29 import javax.xml.bind.Marshaller;
30 import javax.xml.bind.Unmarshaller;
31
32 import org.junit.Before;
33 import org.junit.Test;
34
35
36
37
38
39
40
41 public class PipelineCreationTest
42 {
43 private Pipeline pipeline;
44
45 @Before
46 public void setUp()
47 {
48 pipeline = new TurbinePipeline();
49 pipeline.addValve(new SimpleValve());
50 pipeline.addValve(new DetermineActionValve());
51 }
52
53 @Test
54 public void testSavingPipeline() throws Exception
55 {
56 JAXBContext context = JAXBContext.newInstance(TurbinePipeline.class);
57 Marshaller marshaller = context.createMarshaller();
58 StringWriter writer = new StringWriter();
59 marshaller.marshal(pipeline, writer);
60 assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
61 + "<pipeline><valves>"
62 + "<valve>org.apache.turbine.pipeline.SimpleValve</valve>"
63 + "<valve>org.apache.turbine.pipeline.DetermineActionValve</valve>"
64 + "</valves></pipeline>", writer.toString());
65 }
66
67 @Test
68 public void testReadingPipeline() throws Exception
69 {
70 String xml = "<pipeline name=\"default\"><valves>"
71 + "<valve>org.apache.turbine.pipeline.SimpleValve</valve>"
72 + "<valve>org.apache.turbine.pipeline.DetermineActionValve</valve>"
73 + "</valves></pipeline>";
74 JAXBContext context = JAXBContext.newInstance(TurbinePipeline.class);
75 Unmarshaller unmarshaller = context.createUnmarshaller();
76 StringReader reader = new StringReader(xml);
77 Pipeline pipeline = (Pipeline) unmarshaller.unmarshal(reader);
78 assertEquals(2, pipeline.getValves().length);
79 assertTrue(pipeline.getValves()[0] instanceof SimpleValve);
80 assertTrue(pipeline.getValves()[1] instanceof DetermineActionValve);
81 }
82
83 }