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 org.apache.torque.generator.control.ControllerState;
25  import org.apache.torque.generator.outlet.OutletResult;
26  import org.apache.torque.generator.qname.QualifiedName;
27  import org.apache.torque.generator.source.SourceElement;
28  import org.junit.Test;
29  
30  /**
31   * Component tests for the XmlOutlet.
32   */
33  public class XmlOutletTest
34  {
35      /**
36       * A basic test for the XML Outlet, where no id attributes are created.
37       *
38       * @throws Exception if an error occurs.
39       */
40      @Test
41      public void testXmlOutlet() throws Exception
42      {
43          SourceElement rootElement = new SourceElement("root");
44          rootElement.getChildren().add(new SourceElement("child"));
45          ControllerState controllerState = new ControllerState();
46          controllerState.setRootElement(rootElement);
47          XmlOutlet xmlOutlet = new XmlOutlet(new QualifiedName("test"));
48          OutletResult result = xmlOutlet.execute(controllerState);
49          assertEquals(
50                  "<root>\n  <child/>\n</root>\n",
51                  result.getStringResult());
52      }
53  
54      /**
55       * A basic test for the XML Outlet, where id attributes are created.
56       *
57       * @throws Exception if an error occurs.
58       */
59      @Test
60      public void testXmlOutletCreateIdAttributes() throws Exception
61      {
62          SourceElement rootElement = new SourceElement("root");
63          rootElement.getChildren().add(new SourceElement("child"));
64          ControllerState controllerState = new ControllerState();
65          controllerState.setRootElement(rootElement);
66          XmlOutlet xmlOutlet = new XmlOutlet(new QualifiedName("test"));
67          xmlOutlet.setCreateIdAttributes(true);
68          OutletResult result = xmlOutlet.execute(controllerState);
69          assertEquals(
70                  "<root id=\"1\">\n  <child id=\"2\"/>\n</root>\n",
71                  result.getStringResult());
72      }
73  }