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.Ignore;
28 import org.junit.Test;
29
30 import de.smartics.properties.api.config.domain.Property;
31 import de.smartics.properties.api.config.domain.PropertyCollection;
32 import de.smartics.properties.api.config.domain.PropertyLocation;
33 import de.smartics.properties.impl.config.ds.mysql.MySqlDataSourceProxy;
34 import de.smartics.properties.spi.config.ds.PropertiesStore;
35 import de.smartics.testdoc.annotations.Uut;
36
37
38
39
40 @Ignore("Requires a running MySQL instance at jdbc:mysql://localhost:3306/properties.")
41 public class PropertiesStoreGetCollectionTest
42 {
43
44
45
46
47 private static final String CONFIG_NAME = "test";
48
49
50
51 @Uut(method = "getCollection(String)")
52 private PropertiesStore uut;
53
54 private Property expectedProperty;
55
56
57
58
59
60
61
62 @Before
63 public void setUp()
64 {
65 final MySqlDataSourceProxy dataSourceProxy = MySqlDataSourceProxy.create();
66
67 expectedProperty =
68 new Property(new PropertyLocation(dataSourceProxy.getDataSourceId()
69 + "@config>test"), "test.key",
70 "test-value");
71 final Map<String, String> properties = new HashMap<String, String>();
72 properties.put(expectedProperty.getName(), expectedProperty.getValue());
73 final Map<String, Map<String, String>> initialProperties =
74 new HashMap<String, Map<String, String>>();
75 initialProperties.put(CONFIG_NAME, properties);
76
77 final PropertiesStore.Builder builder = new PropertiesStore.Builder();
78 builder.setDataSourceProxy(dataSourceProxy);
79 builder.setInitialProperties(initialProperties);
80 uut = builder.build();
81
82 uut.createConfigTable();
83 }
84
85
86
87
88
89 @Test
90 public void test()
91 {
92 final PropertyCollection collection = uut.getCollection(CONFIG_NAME);
93 try
94 {
95 final Iterator<Property> i = collection.iterator();
96
97 assertThat(i.hasNext(), is(true));
98 final Property property = i.next();
99 assertThat(property, is(equalTo(expectedProperty)));
100 }
101 finally
102 {
103 collection.close();
104 }
105 }
106 }