View Javadoc

1   package org.apache.turbine.pipeline;
2   
3   
4   /*
5    * Licensed to the Apache Software Foundation (ASF) under one
6    * or more contributor license agreements.  See the NOTICE file
7    * distributed with this work for additional information
8    * regarding copyright ownership.  The ASF licenses this file
9    * to you under the Apache License, Version 2.0 (the
10   * "License"); you may not use this file except in compliance
11   * with the License.  You may obtain a copy of the License at
12   *
13   *   http://www.apache.org/licenses/LICENSE-2.0
14   *
15   * Unless required by applicable law or agreed to in writing,
16   * software distributed under the License is distributed on an
17   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18   * KIND, either express or implied.  See the License for the
19   * specific language governing permissions and limitations
20   * under the License.
21   */
22  
23  
24  
25  import static org.junit.Assert.assertEquals;
26  import static org.junit.Assert.assertTrue;
27  
28  import org.junit.Test;
29  
30  import com.thoughtworks.xstream.XStream;
31  import com.thoughtworks.xstream.io.xml.DomDriver;
32  
33  /**
34   * Tests TurbinePipeline.
35   *
36   * @author <a href="mailto:dlr@finemaltcoding.com">Daniel Rall</a>
37   * @version $Id: PipelineCreationTest.java 1606111 2014-06-27 14:46:47Z gk $
38   */
39  public class PipelineCreationTest
40  {
41      private Pipeline pipeline;
42  
43      public void setUp(){
44          pipeline = new TurbinePipeline();
45          pipeline.addValve(new SimpleValve());
46          pipeline.addValve(new DetermineActionValve());
47      }
48  
49      @Test public void testSavingPipelineWXstream() throws Exception
50      {
51          XStream xstream = new XStream(new DomDriver()); // does not require XPP3 library
52  
53          /* String xml = */ xstream.toXML(pipeline);
54          //System.out.println(xml);
55          //Pipeline pipeline = (Pipeline)xstream.fromXML(xml);
56      }
57  
58      @Test public void testReadingPipelineWXstream() throws Exception{
59          String xml="<org.apache.turbine.pipeline.TurbinePipeline>  <valves>    <org.apache.turbine.pipeline.SimpleValve/>    <org.apache.turbine.pipeline.DetermineActionValve/>  </valves></org.apache.turbine.pipeline.TurbinePipeline>";
60          XStream xstream = new XStream(new DomDriver()); // does not require XPP3 library
61          Object o = xstream.fromXML(xml);
62          Pipeline pipeline = (Pipeline)o;
63          assertEquals(pipeline.getValves().length,2);
64          assertTrue(pipeline.getValves()[0] instanceof SimpleValve);
65          assertTrue(pipeline.getValves()[1] instanceof DetermineActionValve);
66      }
67  
68  }