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.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   * Tests {@link PropertiesStore#getCollection(String)}.
39   */
40  @Ignore("Requires a running MySQL instance at jdbc:mysql://localhost:3306/properties.")
41  public class PropertiesStoreGetCollectionTest
42  {
43    // ********************************* Fields *********************************
44  
45    // --- constants ------------------------------------------------------------
46  
47    private static final String CONFIG_NAME = "test";
48  
49    // --- members --------------------------------------------------------------
50  
51    @Uut(method = "getCollection(String)")
52    private PropertiesStore uut;
53  
54    private Property expectedProperty;
55  
56    // ****************************** Inner Classes *****************************
57  
58    // ********************************* Methods ********************************
59  
60    // --- prepare --------------------------------------------------------------
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    // --- helper ---------------------------------------------------------------
86  
87    // --- tests ----------------------------------------------------------------
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 }