View Javadoc

1   package org.apache.torque.generator.outlet.java;
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  
24  import java.io.File;
25  
26  import org.apache.torque.generator.GeneratorException;
27  import org.apache.torque.generator.control.ControllerState;
28  import org.apache.torque.generator.outlet.OutletResult;
29  import org.apache.torque.generator.qname.QualifiedName;
30  import org.junit.Before;
31  import org.junit.Test;
32  
33  /**
34   * Component Tests for the ModifySourcenameOutlet.
35   */
36  public class ModifySourcenameOutletTest
37  {
38      /** System under test. */
39      private ModifySourcenameOutlet outlet;
40  
41      /** A mock controller state. */
42      private ControllerState controllerState;
43  
44      @Before
45      public void setUp()
46      {
47          this.outlet = new ModifySourcenameOutlet(new QualifiedName(
48                  "org.apache.torque.generator.modifySourcenameOutlet"));
49          controllerState = new ControllerState();
50          controllerState.setSourceFile(
51                  new File("src/test/some-test-file-name.someTestExtension"));
52      }
53  
54      @Test
55      public void testDefault() throws GeneratorException
56      {
57          OutletResult result = outlet.execute(controllerState);
58          assertEquals(
59                  "some-test-file-name.someTestExtension",
60                  result.getStringResult());
61      }
62  
63      @Test
64      public void testAll() throws GeneratorException
65      {
66          outlet.setDiscardFrom("Ext");
67          outlet.setDiscardTo("me-");
68          outlet.setPrefix("prefix-");
69          outlet.setSuffix("-suffix");
70          OutletResult result = outlet.execute(controllerState);
71          assertEquals(
72                  "prefix-test-file-name.someTest-suffix",
73                  result.getStringResult());
74      }
75  
76      @Test
77      public void testDiscardFrom() throws GeneratorException
78      {
79          outlet.setDiscardFrom("-");
80          OutletResult result = outlet.execute(controllerState);
81          assertEquals("some", result.getStringResult());
82      }
83  
84      @Test
85      public void testDiscardTo() throws GeneratorException
86      {
87          outlet.setDiscardTo("-");
88          OutletResult result = outlet.execute(controllerState);
89          assertEquals("name.someTestExtension", result.getStringResult());
90      }
91  
92      @Test
93      public void testOverlappingFromAndTo() throws GeneratorException
94      {
95          outlet.setDiscardFrom("-");
96          outlet.setDiscardTo("-");
97          OutletResult result = outlet.execute(controllerState);
98          assertEquals("", result.getStringResult());
99      }
100 
101     @Test
102     public void testSourceFilenameNull() throws GeneratorException
103     {
104         controllerState.setSourceFile(null);
105         OutletResult result = outlet.execute(controllerState);
106         assertEquals("", result.getStringResult());
107     }
108 }