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