2 * ============LICENSE_START=======================================================
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
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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
24 package org.onap.appc.util;
26 import static org.junit.Assert.*;
29 import org.junit.Before;
30 import org.junit.Test;
32 public class PathContextTest {
34 private PathContext pathContext;
38 pathContext = new PathContext();
41 @Test(expected = IllegalArgumentException.class)
42 public void should_throw_exception_when_pushed_null_token() {
43 pathContext.pushToken(null);
46 @Test(expected = IllegalStateException.class)
47 public void should_throw_exception_when_popped_token_from_empty_path() {
48 pathContext.popToken();
52 public void should_delimit_tokens_with_dot() {
53 pathContext.pushToken("test");
54 pathContext.pushToken("token");
56 assertEquals("test.token", pathContext.getPath());
60 public void should_pop_tokens() {
61 pathContext.pushToken("test");
62 pathContext.pushToken("token");
63 pathContext.pushToken("token2");
65 pathContext.popToken();
67 assertEquals("test.token", pathContext.getPath());
70 @Test(expected = IllegalArgumentException.class)
71 public void should_throw_exception_when_pushed_null_modifier() {
72 pathContext.pushModifier(null);
75 @Test(expected = IllegalStateException.class)
76 public void should_throw_exception_when_popped_modifier_from_empty_path() {
77 pathContext.popModifier();
81 public void should_not_delimit_modifiers() {
82 pathContext.pushModifier("test");
83 pathContext.pushModifier("modifier");
85 assertEquals("testmodifier", pathContext.getPath());
89 public void should_pop_modifiers() {
90 pathContext.pushModifier("test");
91 pathContext.pushModifier("modifier");
92 pathContext.pushModifier("modifier2");
94 pathContext.popModifier();
96 assertEquals("testmodifier", pathContext.getPath());
100 public void should_pop_modifiers_and_tokens() {
101 pathContext.pushModifier("test");
102 pathContext.pushModifier("modifier");
103 pathContext.pushToken("token");
105 //TODO popToken() and popModifier() actually work the same.
106 //TODO Is there sense to keep same method under different names then?
108 pathContext.popToken();
109 assertEquals("testmodifier", pathContext.getPath());
111 pathContext.popModifier();
112 assertEquals("test", pathContext.getPath());
116 public void should_add_entries(){
117 pathContext.entry("name", "value");
119 Map<String, String> entries = pathContext.entries();
120 assertEquals("value", entries.get("name"));