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.config.definition;
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.Map;
24  
25  import org.junit.Test;
26  
27  import de.smartics.properties.api.config.domain.key.ApplicationId;
28  import de.smartics.properties.api.config.domain.key.ConfigurationKey;
29  import de.smartics.properties.api.config.domain.key.EnvironmentId;
30  import de.smartics.properties.spi.config.definition.DefinitionKeyHelper;
31  import de.smartics.properties.spi.config.definition.PropertiesDefinitionContext;
32  import de.smartics.testdoc.annotations.Uut;
33  
34  /**
35   * Tests {@link DefinitionKeyHelper} with registered files.
36   */
37  @Uut(type = DefinitionKeyHelper.class)
38  public class DefinitionKeyHelperRegisteredFilesTest
39  { // NOPMD
40    // ********************************* Fields *********************************
41  
42    // --- constants ------------------------------------------------------------
43  
44    private static final ConfigurationKey DEFAULT_KEY = new ConfigurationKey(
45        new EnvironmentId("xxx-env", "xxx-node"), new ApplicationId("xxx-group",
46            "xxx-artifact", "23.42"));
47  
48    private static final String DEFAULT_GROUP = "de.smartics.test.one";
49  
50    // ... environments .........................................................
51  
52    private static final EnvironmentId ENV_PRODUCTION = new EnvironmentId(
53        "production", "node");
54  
55    // ... applications .........................................................
56  
57    private static final ApplicationId APP_ANY_IN_GROUP = new ApplicationId(
58        DEFAULT_GROUP, null, null);
59  
60    // --- members --------------------------------------------------------------
61  
62    // ****************************** Inner Classes *****************************
63  
64    // ********************************* Methods ********************************
65  
66    // --- prepare --------------------------------------------------------------
67  
68    // --- helper ---------------------------------------------------------------
69  
70    // --- tests ----------------------------------------------------------------
71  
72    @Test
73    public void identifiesRegisteredFiles()
74    {
75      final String path =
76          ENV_PRODUCTION.toString() + '/' + APP_ANY_IN_GROUP.toPath();
77      final Map<String, ConfigurationKey> files =
78          new HashMap<String, ConfigurationKey>();
79      files.put(path, DEFAULT_KEY);
80  
81      final PropertiesDefinitionContext context =
82          new PropertiesDefinitionContext(null, null, null, files);
83  
84      final DefinitionKeyHelper uut = new DefinitionKeyHelper(context);
85      final ConfigurationKey key = uut.parse(path);
86  
87      assertThat(key, is(equalTo(DEFAULT_KEY)));
88    }
89  }