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 de.smartics.properties.impl.config.domain.key.rtaware;
17  
18  import static org.hamcrest.MatcherAssert.assertThat;
19  import static org.hamcrest.Matchers.is;
20  
21  import java.util.List;
22  
23  import org.junit.Before;
24  import org.junit.Test;
25  
26  import de.smartics.properties.api.config.domain.key.ConfigurationKey;
27  import de.smartics.testdoc.annotations.Uut;
28  
29  public class TenantUserKeyListBuilderTest
30  {
31  
32    @Uut
33    private TenantUserKeyListBuilder uut;
34  
35    private TenantUserConfigurationKeyFactory keyFactory;
36  
37    private ConfigurationKey<?> key;
38  
39    @Before
40    public void setUp() throws Exception
41    {
42      this.uut = new TenantUserKeyListBuilder();
43      this.keyFactory = new TenantUserConfigurationKeyFactory();
44      this.key =
45          keyFactory
46              .createKeyFromString("user/tenant/environment:node/groupId:artifactid:version");
47    }
48  
49    /**
50     * Key: user/tenant/environment:node/groupId:artifactid:version will be
51     * converted to:
52     * <ul>
53     * <li>user/tenant/environment:node/groupId:artifactid:version
54     * <li>user//:/::
55     * <li>/tenant/:/::
56     * <li>//environment:node/groupId:artifactid:
57     * <li>//environment:node/groupId::
58     * <li>//environment:node/::
59     * <li>//environment:/groupId:artifactid:version
60     * <li>//environment:/groupId:artifactid:
61     * <li>//environment:/groupId::
62     * <li>//environment:/::
63     * <li>//:/groupId:artifactid:version
64     * <li>//:/groupId:artifactid:
65     * <li>//:/groupId::
66     * <li>//:/::
67     * </ul>
68     */
69    @Test
70    public void returnsStrictlyDefindedKeys()
71    {
72      final List<ConfigurationKey<?>> keyList = uut.createKeyList(key);
73      final String expected =
74          "[user/tenant/environment:node/groupId:artifactid:version,"
75              + " user//:/::, /tenant/:/::, //environment:node/groupId:artifactid:,"
76              + " //environment:node/groupId::, //environment:node/::,"
77              + " //environment:/groupId:artifactid:version,"
78              + " //environment:/groupId:artifactid:, //environment:/groupId::,"
79              + " //environment:/::, //:/groupId:artifactid:version,"
80              + " //:/groupId:artifactid:, //:/groupId::, //:/::]";
81      assertThat(keyList.toString(), is(expected));
82  
83    }
84  
85  }