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.envapp;
17  
18  import static org.hamcrest.MatcherAssert.assertThat;
19  import static org.hamcrest.Matchers.is;
20  import static org.hamcrest.Matchers.notNullValue;
21  
22  import org.junit.Before;
23  import org.junit.Test;
24  
25  import de.smartics.properties.api.config.domain.key.ConfigurationKey;
26  import de.smartics.testdoc.annotations.Uut;
27  
28  /**
29   * user/tenant/environment:node/groupId:artifactid:version
30   */
31  public class EnvAppConfigurationKeyFactoryCreateKeyFromStringTest
32  {
33  
34    @Uut(method = "createKeyFromString(String)")
35    private EnvAppConfigurationKeyFactory uut;
36  
37    @Before
38    public void setUp()
39    {
40      uut = new EnvAppConfigurationKeyFactory();
41    }
42  
43    @Test(expected = IllegalArgumentException.class)
44    public void rejectsNullKeyString()
45    {
46      uut.createKeyFromString(null);
47    }
48  
49    @Test(expected = IllegalArgumentException.class)
50    public void rejectsEmptyKeyString()
51    {
52      uut.createKeyFromString("");
53    }
54  
55    @Test(expected = IllegalArgumentException.class)
56    public void rejectsTooShortKeyString()
57    {
58      uut.createKeyFromString("environment");
59    }
60  
61    @Test
62    public void returnsValidKeyForShortestPossibleDefaultKey()
63    {
64      final ConfigurationKey<?> key = uut.createKeyFromString("/");
65      assertThat(key, notNullValue());
66      assertThat(key.toString(), is(":/::"));
67    }
68  
69    @Test
70    public void returnsValidKeyForFullKey()
71    {
72      final ConfigurationKey<?> key =
73          uut.createKeyFromString("environment:node/groupid:artifactid:version");
74      assertThat(key, notNullValue());
75      assertThat(key.toString(),
76          is("environment:node/groupid:artifactid:version"));
77    }
78  }