View Javadoc

1   package org.apache.torque.generator.source.properties;
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.configuration.ConfigurationException;
27  import org.apache.torque.generator.configuration.UnitConfiguration;
28  import org.apache.torque.generator.configuration.source.EntityReferences;
29  import org.apache.torque.generator.control.ControllerState;
30  import org.apache.torque.generator.source.SourceElement;
31  import org.apache.torque.generator.source.SourceException;
32  import org.apache.torque.generator.source.stream.FileSource;
33  import org.apache.torque.generator.source.stream.PropertiesSourceFormat;
34  import org.junit.Test;
35  
36  public class PropertiesParserTest
37  {
38      private ControllerState controllerState = new ControllerState();
39  
40      public PropertiesParserTest()
41      {
42          UnitConfiguration unitConfiguration = new UnitConfiguration();
43          unitConfiguration.setEntityReferences(new EntityReferences());
44          controllerState.setUnitConfiguration(unitConfiguration);
45      }
46  
47      @Test
48      public void testParsePropertiesFile()
49              throws ConfigurationException, SourceException
50      {
51          File propertiesFile
52              = new File("src/test/resources/org/apache/torque/generator/source/properties/propertiesParserTest.properties");
53          FileSource fileSource
54                  = new FileSource(
55                          new PropertiesSourceFormat(),
56                          propertiesFile,
57                          controllerState);
58  
59          SourceElement rootElement = fileSource.getRootElement();
60          assertEquals("properties", rootElement.getName());
61          assertEquals(0, rootElement.getAttributeNames().size());
62  
63          assertEquals(2, rootElement.getChildren().size());
64          {
65              SourceElement child0 = rootElement.getChildren().get(0);
66              assertEquals("entry", child0.getName());
67              assertEquals(2, child0.getAttributeNames().size());
68              assertEquals("propertyName1", child0.getAttribute("key"));
69              assertEquals("propertyValue1", child0.getAttribute((String) null));
70          }
71          {
72              SourceElement child1 = rootElement.getChildren().get(1);
73              assertEquals("entry", child1.getName());
74              assertEquals(2, child1.getAttributeNames().size());
75              assertEquals("propertyName2", child1.getAttribute("key"));
76              assertEquals("propertyValue2", child1.getAttribute((String) null));
77          }
78      }
79  
80      @Test(expected = NullPointerException.class)
81      public void testPathNull() throws ConfigurationException
82      {
83          new FileSource(
84                  new PropertiesSourceFormat(),
85                  null,
86                  controllerState);
87      }
88  }