    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 junit.framework.TestCase;
    26
    27  import com.thoughtworks.xstream.XStream;
    28  import com.thoughtworks.xstream.io.xml.DomDriver;
    29
    30  /**
    31   * Tests TurbinePipeline.
    32   *
    33   * @author <a href="mailto:dlr@finemaltcoding.com">Daniel Rall</a>
    34   * @version $Id: PipelineCreationTest.java 615328 2008-01-25 20:25:05Z tv $
    35   */
    36  public class PipelineCreationTest extends TestCase
    37  {
    38      private Pipeline pipeline;
    39      /**
    40       * Constructor
    41       */
    42      public PipelineCreationTest(String testName)
    43      {
    44          super(testName);
    45      }
    46
    47      public void setUp(){
    48          pipeline = new TurbinePipeline();
    49          pipeline.addValve(new SimpleValve());
    50          pipeline.addValve(new DetermineActionValve());
    51      }
    52
    53
    54      public void testSavingPipelineWXstream() throws Exception
    55      {
    56          XStream xstream = new XStream(new DomDriver()); // does not require XPP3 library
    57
    58          String xml = xstream.toXML(pipeline);
    59          //System.out.println(xml);
    60          //Pipeline pipeline = (Pipeline)xstream.fromXML(xml);
    61
    62      }
    63
    64      public void testReadingPipelineWXstream() throws Exception{
    65          String xml="<org.apache.turbine.pipeline.TurbinePipeline>  <valves>    <org.apache.turbine.pipeline.SimpleValve/>    <org.apache.turbine.pipeline.DetermineActionValve/>  </valves></org.apache.turbine.pipeline.TurbinePipeline>";
    66          XStream xstream = new XStream(new DomDriver()); // does not require XPP3 library
    67          Object o = xstream.fromXML(xml);
    68          Pipeline pipeline = (Pipeline)o;
    69          assertEquals(pipeline.getValves().length,2);
    70          assertTrue(pipeline.getValves()[0] instanceof SimpleValve);
    71          assertTrue(pipeline.getValves()[1] instanceof DetermineActionValve);
    72      }
    73
    74  }