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