1 /*
2 * Copyright 2012 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.at.classpath;
17
18 import java.util.Properties;
19
20 import org.junit.Assert;
21 import org.junit.Before;
22 import org.junit.Test;
23
24 import de.smartics.properties.at.classpath.ApplicationProperties;
25 import de.smartics.properties.impl.config.classpath.ClasspathConfigurationProperties;
26 import de.smartics.properties.impl.config.classpath.ClasspathConfigurationPropertiesFactory;
27 import de.smartics.testdoc.annotations.Uut;
28 import de.smartics.util.test.io.FileTestUtils;
29
30 /**
31 * The simplest possible usage of smartics properties declares an interface and
32 * has a property file with the name of the interface in the same package and
33 * accesses the properties.
34 */
35 public class UsecaseClasspathTest
36 {
37
38 // ********************************* Fields *********************************
39
40 // --- constants - -----------------------------------------------------------
41
42 // --- members --------------------------------------------------------------
43
44 @Uut
45 private ApplicationProperties properties;
46
47 // ****************************** Inner Classes *****************************
48
49 // ********************************* Methods ********************************
50
51 // --- prepare --------------------------------------------------------------
52
53 @Before
54 public void setUp()
55 {
56 final ClasspathConfigurationPropertiesFactory factory =
57 new ClasspathConfigurationPropertiesFactory();
58 final ClasspathConfigurationProperties configuration =
59 factory.createManagement();
60
61 configuration.addClassPathProperties(ApplicationProperties.class);
62 configuration.validate();
63
64 this.properties = configuration.getProperties(ApplicationProperties.class);
65 }
66
67 // --- helper ---------------------------------------------------------------
68
69 // --- tests ----------------------------------------------------------------
70
71 @Test
72 public void returnsTheValuesFromThePropertiesFileFoundInTheClasspath()
73 throws Exception
74 {
75 final Properties props =
76 FileTestUtils
77 .getPropertiesFromRelativePropertiesFileForClass(ApplicationProperties.class);
78 Assert.assertEquals(props.getProperty("app.domain"), properties.domain());
79 }
80
81 }