View Javadoc

    1   package org.apache.turbine.pipeline;
    2
    3   /*
    4    * Licensed to the Apache Software Foundation (ASF) under one
    5    * or more contributor license agreements.  See the NOTICE file
    6    * distributed with this work for additional information
    7    * regarding copyright ownership.  The ASF licenses this file
    8    * to you under the Apache License, Version 2.0 (the
    9    * "License"); you may not use this file except in compliance
    10   * with the License.  You may obtain a copy of the License at
    11   *
    12   *   http://www.apache.org/licenses/LICENSE-2.0
    13   *
    14   * Unless required by applicable law or agreed to in writing,
    15   * software distributed under the License is distributed on an
    16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    17   * KIND, either express or implied.  See the License for the
    18   * specific language governing permissions and limitations
    19   * under the License.
    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   * Tests TurbinePipeline.
    37   *
    38   * @author <a href="mailto:dlr@finemaltcoding.com">Daniel Rall</a>
    39   * @version $Id: PipelineCreationTest.java 1725002 2016-01-16 16:31:45Z tv $
    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  }