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.Map;
24
25 import org.junit.Before;
26 import org.junit.Test;
27
28 import de.smartics.properties.api.config.domain.Property;
29 import de.smartics.properties.api.config.domain.PropertyLocation;
30 import de.smartics.properties.impl.config.ds.hsql.HSqlDataSourceProxy;
31 import de.smartics.properties.spi.config.ds.PropertiesStore;
32 import de.smartics.testdoc.annotations.Uut;
33
34
35
36
37 public class PropertiesStoreSetPropertyTest
38 {
39
40
41
42
43 private static final String CONFIG_NAME = "test";
44
45 private static final String PROPERTY_KEY = "test.key";
46
47
48
49 @Uut(method = "setProperty(String, String, String)")
50 private PropertiesStore uut;
51
52
53
54
55
56
57
58 @Before
59 public void setUp()
60 {
61 final HSqlDataSourceProxy dataSourceProxy = HSqlDataSourceProxy.create();
62
63 final Property expectedProperty =
64 new Property(new PropertyLocation(dataSourceProxy.getDataSourceId()
65 + "@config>test"), PROPERTY_KEY,
66 "test-value");
67 final Map<String, String> properties = new HashMap<String, String>();
68 properties.put(expectedProperty.getName(), expectedProperty.getValue());
69 final Map<String, Map<String, String>> initialProperties =
70 new HashMap<String, Map<String, String>>();
71 initialProperties.put(CONFIG_NAME, properties);
72
73 final PropertiesStore.Builder builder = new PropertiesStore.Builder();
74 builder.setCreateTableSqlStatementTemplate(dataSourceProxy
75 .getCreateTableSqlTemplate());
76 builder.setInsertOrUpdateSqlStatementTemplate(dataSourceProxy
77 .getInsertOrUpdateSqlTemplate());
78 builder.setDataSourceProxy(dataSourceProxy);
79 builder.setInitialProperties(initialProperties);
80 uut = builder.build();
81 uut.createConfigTable();
82 }
83
84
85
86
87
88 @Test
89 public void allowsToUpdateAnExistingProperty()
90 {
91 final String newValue = "new-test-value";
92 uut.setProperty(CONFIG_NAME, PROPERTY_KEY, newValue);
93
94 final Property propertyRead = uut.getProperty(CONFIG_NAME, PROPERTY_KEY);
95 final String valueRead = propertyRead.getValue();
96
97 assertThat(valueRead, is(equalTo(newValue)));
98 }
99
100 @Test
101 public void allowsToInsertANewProperty()
102 {
103 final String newKey = "test.key.new";
104 final String newValue = "new-test-value";
105 uut.setProperty(CONFIG_NAME, newKey, newValue);
106
107 final Property propertyRead = uut.getProperty(CONFIG_NAME, newKey);
108 final String valueRead = propertyRead.getValue();
109
110 assertThat(valueRead, is(equalTo(newValue)));
111 }
112 }