1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package test.de.smartics.properties.impl.config.ds;
17
18 import static org.hamcrest.MatcherAssert.assertThat;
19 import static org.hamcrest.Matchers.equalTo;
20 import static org.hamcrest.Matchers.is;
21
22 import java.util.HashMap;
23 import java.util.Iterator;
24 import java.util.Map;
25
26 import org.junit.Before;
27 import org.junit.Test;
28
29 import de.smartics.properties.api.config.domain.Property;
30 import de.smartics.properties.api.config.domain.PropertyCollection;
31 import de.smartics.properties.api.config.domain.PropertyLocation;
32 import de.smartics.properties.impl.config.ds.hsql.HSqlDataSourceProxy;
33 import de.smartics.properties.spi.config.ds.PropertiesStore;
34 import de.smartics.testdoc.annotations.Uut;
35
36
37
38
39 public class PropertiesStoreGetCollectionTest
40 {
41
42
43
44
45 private static final String CONFIG_NAME = "test";
46
47
48
49 @Uut(method = "getCollection(String)")
50 private PropertiesStore uut;
51
52 private Property expectedProperty;
53
54
55
56
57
58
59
60 @Before
61 public void setUp()
62 {
63 final HSqlDataSourceProxy dataSourceProxy = HSqlDataSourceProxy.create();
64
65 expectedProperty =
66 new Property(new PropertyLocation(dataSourceProxy.getDataSourceId()
67 + "@config>test"), "test.key",
68 "test-value");
69 final Map<String, String> properties = new HashMap<String, String>();
70 properties.put(expectedProperty.getName(), expectedProperty.getValue());
71 final Map<String, Map<String, String>> initialProperties =
72 new HashMap<String, Map<String, String>>();
73 initialProperties.put(CONFIG_NAME, properties);
74
75 final PropertiesStore.Builder builder = new PropertiesStore.Builder();
76 builder.setCreateTableSqlStatementTemplate(dataSourceProxy
77 .getCreateTableSqlTemplate());
78 builder.setInsertOrUpdateSqlStatementTemplate(dataSourceProxy
79 .getInsertOrUpdateSqlTemplate());
80 builder.setDataSourceProxy(dataSourceProxy);
81 builder.setInitialProperties(initialProperties);
82 uut = builder.build();
83 uut.createConfigTable();
84 }
85
86
87
88
89
90 @Test
91 public void test()
92 {
93 final PropertyCollection collection = uut.getCollection(CONFIG_NAME);
94 try
95 {
96 final Iterator<Property> i = collection.iterator();
97
98 assertThat(i.hasNext(), is(true));
99 final Property property = i.next();
100 assertThat(property, is(equalTo(expectedProperty)));
101 }
102 finally
103 {
104 collection.close();
105 }
106 }
107 }