1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package test.de.smartics.properties.spi.core.context;
17
18 import static org.hamcrest.MatcherAssert.assertThat;
19 import static org.hamcrest.Matchers.equalTo;
20 import static org.hamcrest.Matchers.is;
21 import static org.mockito.Mockito.mock;
22 import static org.mockito.Mockito.when;
23
24 import java.util.Locale;
25
26 import org.junit.Before;
27 import org.junit.Test;
28
29 import de.smartics.properties.api.core.domain.DocumentName;
30 import de.smartics.properties.api.core.domain.PropertiesContext;
31 import de.smartics.properties.api.core.domain.PropertyDescriptor;
32 import de.smartics.properties.api.core.domain.PropertyKey;
33 import de.smartics.properties.api.core.domain.PropertyType;
34 import de.smartics.properties.spi.core.context.DeclarationConfigParser;
35 import de.smartics.testdoc.annotations.Uut;
36
37
38
39
40 public class DeclarationConfigParserTest
41 {
42
43
44
45
46
47
48 @Uut
49 private DeclarationConfigParser uut;
50
51
52
53
54
55
56
57 @Before
58 public void setUp()
59 {
60 uut = new DeclarationConfigParser();
61 }
62
63
64
65
66
67 @Test
68 public void parsesConfigurationFromClassPath()
69 {
70 final PropertiesContext context =
71 uut.parse(DeclarationConfigParserTest.class);
72 assertThat(context.getHomePageUrl(),
73 is(equalTo("http://www.smartics.de/myproject")));
74 assertThat(context.getPropertiesReportUrl(),
75 is(equalTo("http://www.smartics.de/myproject/property")));
76 }
77
78 @Test
79 public void createsAPathToAnExistingXmlDocument()
80 {
81 final String propertyId =
82 "de.smartics.properties.test.values.UserStoryProperties.businessPriority";
83
84 final PropertyDescriptor descriptor = mock(PropertyDescriptor.class);
85 when(descriptor.getType()).thenReturn(new PropertyType(String.class));
86 when(descriptor.getKey()).thenReturn(new PropertyKey(propertyId));
87 when(descriptor.getDocumentName()).thenReturn(new DocumentName(propertyId));
88
89 final PropertiesContext.Builder builder = new PropertiesContext.Builder();
90 final PropertiesContext context = builder.build();
91
92 final String path = context.createMetaInfPath(descriptor, Locale.GERMANY);
93 assertThat(path, is(equalTo("META-INF/smartics-properties/property-report/"
94 + propertyId + "_de.xml")));
95 }
96
97 @Test
98 public void createsAPathToAnExistingDefaultXmlDocument()
99 {
100 final String propertyId =
101 "de.smartics.properties.test.values.UserStoryProperties.just-a-file";
102
103 final PropertyDescriptor descriptor = mock(PropertyDescriptor.class);
104 when(descriptor.getType()).thenReturn(new PropertyType(String.class));
105 when(descriptor.getKey()).thenReturn(new PropertyKey(propertyId));
106 when(descriptor.getDocumentName()).thenReturn(new DocumentName(propertyId));
107
108 final PropertiesContext.Builder builder = new PropertiesContext.Builder();
109 final PropertiesContext context = builder.build();
110
111 final String path = context.createMetaInfPath(descriptor, Locale.GERMANY);
112 assertThat(path, is(equalTo("META-INF/smartics-properties/property-report/"
113 + propertyId + ".xml")));
114 }
115
116 }