View Javadoc

1   /*
2    * Copyright 2012-2013 smartics, Kronseder & Reiner GmbH
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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   * Tests {@link PropertiesStore#getCollection(String)}.
38   */
39  public class PropertiesStoreGetCollectionTest
40  {
41    // ********************************* Fields *********************************
42  
43    // --- constants ------------------------------------------------------------
44  
45    private static final String CONFIG_NAME = "test";
46  
47    // --- members --------------------------------------------------------------
48  
49    @Uut(method = "getCollection(String)")
50    private PropertiesStore uut;
51  
52    private Property expectedProperty;
53  
54    // ****************************** Inner Classes *****************************
55  
56    // ********************************* Methods ********************************
57  
58    // --- prepare --------------------------------------------------------------
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    // --- helper ---------------------------------------------------------------
87  
88    // --- tests ----------------------------------------------------------------
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 }