View Javadoc

1   package org.apache.torque.generator.configuration.outlet;
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.util.ArrayList;
25  import java.util.List;
26  
27  import org.apache.torque.generator.configuration.ConfigurationException;
28  import org.apache.torque.generator.configuration.mergepoint.MergepointMapping;
29  import org.apache.torque.generator.control.action.ApplyAction;
30  import org.apache.torque.generator.java.JavaOutlet;
31  import org.apache.torque.generator.outlet.Outlet;
32  import org.apache.torque.generator.outlet.java.PackageToPathOutlet;
33  import org.apache.torque.generator.qname.QualifiedName;
34  import org.junit.Test;
35  
36  public class OutletConfigurationTest
37  {
38      /**
39       * Tests that getOutlets returns the correct result.
40       *
41       * @throws ConfigurationException if an error occurs.
42       */
43      @Test
44      public void testGetOutlets() throws ConfigurationException
45      {
46          List<Outlet> outlets = new ArrayList<Outlet>();
47          outlets.add(new JavaOutlet(
48                  new QualifiedName("test.outlet.0")));
49          outlets.add(new PackageToPathOutlet(
50                  new QualifiedName("test.outlet.1")));
51          List<MergepointMapping> mergepointMappings
52                  = new ArrayList<MergepointMapping>();
53  
54          OutletConfiguration outletConfiguration
55                  = new OutletConfiguration(outlets, mergepointMappings);
56          outletConfiguration.resolveMergepointMappings();
57  
58          assertEquals(2, outletConfiguration.getOutlets().size());
59          assertEquals(
60                  outlets.get(0),
61                  outletConfiguration.getOutlets().get(
62                          new QualifiedName("test.outlet.0")));
63          assertEquals(
64                  outlets.get(1),
65                  outletConfiguration.getOutlets().get(
66                          new QualifiedName("test.outlet.1")));
67      }
68  
69      /**
70       * Tests that one cannot add a outlet with the same name twice
71       *
72       * @throws ConfigurationException if OutletConfiguration cannot be
73       *         created,
74       */
75      @Test(expected = ConfigurationException.class)
76      public void testConstructorWithSameOutletName()
77              throws ConfigurationException
78      {
79          List<Outlet> outlets = new ArrayList<Outlet>();
80          outlets.add(new JavaOutlet(
81                  new QualifiedName("sameName")));
82          outlets.add(new PackageToPathOutlet(
83                  new QualifiedName("sameName")));
84          List<MergepointMapping> mergepointMappings
85                  = new ArrayList<MergepointMapping>();
86  
87          new OutletConfiguration(outlets, mergepointMappings);
88      }
89  
90      /**
91       * Checks that resolveMergepointMappings adds the mergepoint
92       * to the correct outlet.
93       */
94      @Test
95      public void testResolveMergepointMappings() throws ConfigurationException
96      {
97          List<Outlet> outlets = new ArrayList<Outlet>();
98          outlets.add(new JavaOutlet(
99                  new QualifiedName("test.outlet")));
100         outlets.add(new PackageToPathOutlet(
101                 new QualifiedName("test.outlet.2")));
102         List<MergepointMapping> mergepointMappings
103                 = new ArrayList<MergepointMapping>();
104         mergepointMappings.add(
105                 new MergepointMapping("test.outlet.testMergepoint"));
106         mergepointMappings.get(0).addAction(
107                 new ApplyAction(".", "test.outlet.2", false));
108 
109         OutletConfiguration outletConfiguration
110                 = new OutletConfiguration(outlets, mergepointMappings);
111         outletConfiguration.resolveMergepointMappings();
112 
113         Outlet outlet = outletConfiguration.getOutlet(
114                 new QualifiedName("test.outlet"));
115         assertEquals(1, outlet.getMergepointMappings().size());
116         assertEquals(
117                 1,
118                 outlet.getMergepointMapping("testMergepoint")
119                     .getActions().size());
120     }
121 
122     /**
123      * Checks that resolveMergepointMappings throws an error if the
124      * outlet name cannot be resolved.
125      */
126     @Test(expected = ConfigurationException.class)
127     public void testResolveMergepointMappingsNotExistingOutlet()
128             throws ConfigurationException
129     {
130         List<Outlet> outlets = new ArrayList<Outlet>();
131         outlets.add(new JavaOutlet(
132                 new QualifiedName("test.outlet")));
133         List<MergepointMapping> mergepointMappings
134                 = new ArrayList<MergepointMapping>();
135         mergepointMappings.add(
136                 new MergepointMapping("not.existing.outlet.testMergepoint"));
137 
138         OutletConfiguration outletConfiguration
139                 = new OutletConfiguration(outlets, mergepointMappings);
140         outletConfiguration.resolveMergepointMappings();
141     }
142 
143     /**
144      * Checks that resolveMergepointMappings throws an error if a
145      * mergepoint does not contain a namespace.
146      */
147     @Test(expected = ConfigurationException.class)
148     public void testResolveMergepointMappingsNoNamespace()
149             throws ConfigurationException
150     {
151         List<Outlet> outlets = new ArrayList<Outlet>();
152         outlets.add(new JavaOutlet(
153                 new QualifiedName("test.outlet")));
154         List<MergepointMapping> mergepointMappings
155                 = new ArrayList<MergepointMapping>();
156         mergepointMappings.add(
157                 new MergepointMapping("testMergepoint"));
158 
159         OutletConfiguration outletConfiguration
160                 = new OutletConfiguration(outlets, mergepointMappings);
161         outletConfiguration.resolveMergepointMappings();
162     }
163 }