2 * ============LICENSE_START=======================================================
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
15 * http://www.apache.org/licenses/LICENSE-2.0
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.
23 * ============LICENSE_END=========================================================
25 package org.onap.appc.util;
28 import static org.junit.Assert.assertEquals;
30 import org.junit.Before;
31 import org.junit.Test;
33 public class PathContextTest {
35 private PathContext pathContext;
39 pathContext = new PathContext();
42 @Test(expected = IllegalArgumentException.class)
43 public void should_throw_exception_when_pushed_null_token() {
44 pathContext.pushToken(null);
47 @Test(expected = IllegalStateException.class)
48 public void should_throw_exception_when_popped_token_from_empty_path() {
49 pathContext.popToken();
53 public void should_delimit_tokens_with_dot() {
54 pathContext.pushToken("test");
55 pathContext.pushToken("token");
57 assertEquals("test.token", pathContext.getPath());
61 public void should_pop_tokens() {
62 pathContext.pushToken("test");
63 pathContext.pushToken("token");
64 pathContext.pushToken("token2");
66 pathContext.popToken();
68 assertEquals("test.token", pathContext.getPath());
71 @Test(expected = IllegalArgumentException.class)
72 public void should_throw_exception_when_pushed_null_modifier() {
73 pathContext.pushModifier(null);
76 @Test(expected = IllegalStateException.class)
77 public void should_throw_exception_when_popped_modifier_from_empty_path() {
78 pathContext.popModifier();
82 public void should_not_delimit_modifiers() {
83 pathContext.pushModifier("test");
84 pathContext.pushModifier("modifier");
86 assertEquals("testmodifier", pathContext.getPath());
90 public void should_pop_modifiers() {
91 pathContext.pushModifier("test");
92 pathContext.pushModifier("modifier");
93 pathContext.pushModifier("modifier2");
95 pathContext.popModifier();
97 assertEquals("testmodifier", pathContext.getPath());
101 public void should_pop_modifiers_and_tokens() {
102 pathContext.pushModifier("test");
103 pathContext.pushModifier("modifier");
104 pathContext.pushToken("token");
106 //TODO popToken() and popModifier() actually work the same.
107 //TODO Is there sense to keep same method under different names then?
109 pathContext.popToken();
110 assertEquals("testmodifier", pathContext.getPath());
112 pathContext.popModifier();
113 assertEquals("test", pathContext.getPath());
117 public void should_add_entries(){
118 pathContext.entry("name", "value");
120 Map<String, String> entries = pathContext.entries();
121 assertEquals("value", entries.get("name"));