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 * 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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * ============LICENSE_END=========================================================
23 package org.onap.appc.util;
25 import static org.junit.Assert.*;
28 import org.junit.Before;
29 import org.junit.Test;
31 public class PathContextTest {
33 private PathContext pathContext;
37 pathContext = new PathContext();
40 @Test(expected = IllegalArgumentException.class)
41 public void should_throw_exception_when_pushed_null_token() {
42 pathContext.pushToken(null);
45 @Test(expected = IllegalStateException.class)
46 public void should_throw_exception_when_popped_token_from_empty_path() {
47 pathContext.popToken();
51 public void should_delimit_tokens_with_dot() {
52 pathContext.pushToken("test");
53 pathContext.pushToken("token");
55 assertEquals("test.token", pathContext.getPath());
59 public void should_pop_tokens() {
60 pathContext.pushToken("test");
61 pathContext.pushToken("token");
62 pathContext.pushToken("token2");
64 pathContext.popToken();
66 assertEquals("test.token", pathContext.getPath());
69 @Test(expected = IllegalArgumentException.class)
70 public void should_throw_exception_when_pushed_null_modifier() {
71 pathContext.pushModifier(null);
74 @Test(expected = IllegalStateException.class)
75 public void should_throw_exception_when_popped_modifier_from_empty_path() {
76 pathContext.popModifier();
80 public void should_not_delimit_modifiers() {
81 pathContext.pushModifier("test");
82 pathContext.pushModifier("modifier");
84 assertEquals("testmodifier", pathContext.getPath());
88 public void should_pop_modifiers() {
89 pathContext.pushModifier("test");
90 pathContext.pushModifier("modifier");
91 pathContext.pushModifier("modifier2");
93 pathContext.popModifier();
95 assertEquals("testmodifier", pathContext.getPath());
99 public void should_pop_modifiers_and_tokens() {
100 pathContext.pushModifier("test");
101 pathContext.pushModifier("modifier");
102 pathContext.pushToken("token");
104 //TODO popToken() and popModifier() actually work the same.
105 //TODO Is there sense to keep same method under different names then?
107 pathContext.popToken();
108 assertEquals("testmodifier", pathContext.getPath());
110 pathContext.popModifier();
111 assertEquals("test", pathContext.getPath());
115 public void should_add_entries(){
116 pathContext.entry("name", "value");
118 Map<String, String> entries = pathContext.entries();
119 assertEquals("value", entries.get("name"));