1 package org.apache.torque.generator.source.properties;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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 }