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.Ignore;
27 import org.junit.Test;
28
29 import de.smartics.properties.api.config.domain.Property;
30 import de.smartics.properties.api.config.domain.PropertyLocation;
31 import de.smartics.properties.impl.config.ds.mysql.MySqlDataSourceProxy;
32 import de.smartics.properties.spi.config.ds.PropertiesStore;
33 import de.smartics.testdoc.annotations.Uut;
34
35
36
37
38 @Ignore("Requires a running MySQL instance at jdbc:mysql://localhost:3306/properties.")
39 public class PropertiesStoreSetPropertyTest
40 {
41
42
43
44
45 private static final String CONFIG_NAME = "test";
46
47 private static final String PROPERTY_KEY = "test.key";
48
49
50
51 @Uut(method = "setProperty(String, String, String)")
52 private PropertiesStore uut;
53
54
55
56
57
58
59
60 @Before
61 public void setUp()
62 {
63 final MySqlDataSourceProxy dataSourceProxy = MySqlDataSourceProxy.create();
64
65 final Property expectedProperty =
66 new Property(new PropertyLocation(dataSourceProxy.getDataSourceId()
67 + "@config>test"), PROPERTY_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 allowsToUpdateAnExistingProperty()
92 {
93 final String newValue = "new-test-value";
94 uut.setProperty(CONFIG_NAME, PROPERTY_KEY, newValue);
95
96 final Property propertyRead = uut.getProperty(CONFIG_NAME, PROPERTY_KEY);
97 final String valueRead = propertyRead.getValue();
98
99 assertThat(valueRead, is(equalTo(newValue)));
100 }
101
102 @Test
103 public void allowsToInsertANewProperty()
104 {
105 final String newKey = "test.key.new";
106 final String newValue = "new-test-value";
107 uut.setProperty(CONFIG_NAME, newKey, newValue);
108
109 final Property propertyRead = uut.getProperty(CONFIG_NAME, newKey);
110 final String valueRead = propertyRead.getValue();
111
112 assertThat(valueRead, is(equalTo(newValue)));
113 }
114 }