PathContext unit tests
[appc.git] / appc-common / src / test / java / org / onap / appc / util / PathContextTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2017 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  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  * ============LICENSE_END=========================================================
23  */
24 package org.onap.appc.util;
25
26 import static org.junit.Assert.*;
27
28 import java.util.Map;
29 import org.junit.Before;
30 import org.junit.Test;
31
32 public class PathContextTest {
33
34     private PathContext pathContext;
35
36     @Before
37     public void setup() {
38         pathContext = new PathContext();
39     }
40
41     @Test(expected = IllegalArgumentException.class)
42     public void should_throw_exception_when_pushed_null_token() {
43         pathContext.pushToken(null);
44     }
45
46     @Test(expected = IllegalStateException.class)
47     public void should_throw_exception_when_popped_token_from_empty_path() {
48         pathContext.popToken();
49     }
50
51     @Test
52     public void should_delimit_tokens_with_dot() {
53         pathContext.pushToken("test");
54         pathContext.pushToken("token");
55
56         assertEquals("test.token", pathContext.getPath());
57     }
58
59     @Test
60     public void should_pop_tokens() {
61         pathContext.pushToken("test");
62         pathContext.pushToken("token");
63         pathContext.pushToken("token2");
64
65         pathContext.popToken();
66
67         assertEquals("test.token", pathContext.getPath());
68     }
69
70     @Test(expected = IllegalArgumentException.class)
71     public void should_throw_exception_when_pushed_null_modifier() {
72         pathContext.pushModifier(null);
73     }
74
75     @Test(expected = IllegalStateException.class)
76     public void should_throw_exception_when_popped_modifier_from_empty_path() {
77         pathContext.popModifier();
78     }
79
80     @Test
81     public void should_not_delimit_modifiers() {
82         pathContext.pushModifier("test");
83         pathContext.pushModifier("modifier");
84
85         assertEquals("testmodifier", pathContext.getPath());
86     }
87
88     @Test
89     public void should_pop_modifiers() {
90         pathContext.pushModifier("test");
91         pathContext.pushModifier("modifier");
92         pathContext.pushModifier("modifier2");
93
94         pathContext.popModifier();
95
96         assertEquals("testmodifier", pathContext.getPath());
97     }
98
99     @Test
100     public void should_pop_modifiers_and_tokens() {
101         pathContext.pushModifier("test");
102         pathContext.pushModifier("modifier");
103         pathContext.pushToken("token");
104
105         //TODO popToken() and popModifier() actually work the same.
106         //TODO Is there sense to keep same method under different names then?
107
108         pathContext.popToken();
109         assertEquals("testmodifier", pathContext.getPath());
110
111         pathContext.popModifier();
112         assertEquals("test", pathContext.getPath());
113     }
114
115     @Test
116     public void should_add_entries(){
117         pathContext.entry("name", "value");
118
119         Map<String, String> entries = pathContext.entries();
120         assertEquals("value", entries.get("name"));
121     }
122
123 }