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.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   * Tests {@link DeclarationConfigParser}.
39   */
40  public class DeclarationConfigParserTest
41  {
42    // ********************************* Fields *********************************
43  
44    // --- constants ------------------------------------------------------------
45  
46    // --- members --------------------------------------------------------------
47  
48    @Uut
49    private DeclarationConfigParser uut;
50  
51    // ****************************** Inner Classes *****************************
52  
53    // ********************************* Methods ********************************
54  
55    // --- prepare --------------------------------------------------------------
56  
57    @Before
58    public void setUp()
59    {
60      uut = new DeclarationConfigParser();
61    }
62  
63    // --- helper ---------------------------------------------------------------
64  
65    // --- tests ----------------------------------------------------------------
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 }