Update appc-common to Karaf 4
[appc.git] / appc-core / appc-common-bundle / src / test / java / org / onap / appc / util / PathContextTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Copyright (C) 2018 Nokia Solutions and Networks
8  * =============================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * 
21  * ============LICENSE_END=========================================================
22  */
23 package org.onap.appc.util;
24
25 import static org.junit.Assert.*;
26
27 import java.util.Map;
28 import org.junit.Before;
29 import org.junit.Test;
30
31 public class PathContextTest {
32
33     private PathContext pathContext;
34
35     @Before
36     public void setup() {
37         pathContext = new PathContext();
38     }
39
40     @Test(expected = IllegalArgumentException.class)
41     public void should_throw_exception_when_pushed_null_token() {
42         pathContext.pushToken(null);
43     }
44
45     @Test(expected = IllegalStateException.class)
46     public void should_throw_exception_when_popped_token_from_empty_path() {
47         pathContext.popToken();
48     }
49
50     @Test
51     public void should_delimit_tokens_with_dot() {
52         pathContext.pushToken("test");
53         pathContext.pushToken("token");
54
55         assertEquals("test.token", pathContext.getPath());
56     }
57
58     @Test
59     public void should_pop_tokens() {
60         pathContext.pushToken("test");
61         pathContext.pushToken("token");
62         pathContext.pushToken("token2");
63
64         pathContext.popToken();
65
66         assertEquals("test.token", pathContext.getPath());
67     }
68
69     @Test(expected = IllegalArgumentException.class)
70     public void should_throw_exception_when_pushed_null_modifier() {
71         pathContext.pushModifier(null);
72     }
73
74     @Test(expected = IllegalStateException.class)
75     public void should_throw_exception_when_popped_modifier_from_empty_path() {
76         pathContext.popModifier();
77     }
78
79     @Test
80     public void should_not_delimit_modifiers() {
81         pathContext.pushModifier("test");
82         pathContext.pushModifier("modifier");
83
84         assertEquals("testmodifier", pathContext.getPath());
85     }
86
87     @Test
88     public void should_pop_modifiers() {
89         pathContext.pushModifier("test");
90         pathContext.pushModifier("modifier");
91         pathContext.pushModifier("modifier2");
92
93         pathContext.popModifier();
94
95         assertEquals("testmodifier", pathContext.getPath());
96     }
97
98     @Test
99     public void should_pop_modifiers_and_tokens() {
100         pathContext.pushModifier("test");
101         pathContext.pushModifier("modifier");
102         pathContext.pushToken("token");
103
104         //TODO popToken() and popModifier() actually work the same.
105         //TODO Is there sense to keep same method under different names then?
106
107         pathContext.popToken();
108         assertEquals("testmodifier", pathContext.getPath());
109
110         pathContext.popModifier();
111         assertEquals("test", pathContext.getPath());
112     }
113
114     @Test
115     public void should_add_entries(){
116         pathContext.entry("name", "value");
117
118         Map<String, String> entries = pathContext.entries();
119         assertEquals("value", entries.get("name"));
120     }
121
122 }