diff options
author | Jakub Dudycz <jakub.dudycz@nokia.com> | 2018-03-13 11:51:24 +0100 |
---|---|---|
committer | Takamune Cho <tc012c@att.com> | 2018-03-13 19:08:05 +0000 |
commit | bc73640c5d910e376fd06d0a3fcbf18d8f92fd90 (patch) | |
tree | 447256499c3e707ce5ff3829710679f4e144aeab /appc-common/src/test/java/org/onap | |
parent | 11e583e4e37bd274390643d494d2a8670e118c36 (diff) |
PathContext unit tests
Improved code coverage
Change-Id: I8b7d1fe8a033bd1c4df34bdd74efc011dc130a46
Issue-ID: APPC-724
Signed-off-by: Jakub Dudycz <jakub.dudycz@nokia.com>
Diffstat (limited to 'appc-common/src/test/java/org/onap')
-rw-r--r-- | appc-common/src/test/java/org/onap/appc/util/PathContextTest.java | 123 |
1 files changed, 123 insertions, 0 deletions
diff --git a/appc-common/src/test/java/org/onap/appc/util/PathContextTest.java b/appc-common/src/test/java/org/onap/appc/util/PathContextTest.java new file mode 100644 index 000000000..e075381a0 --- /dev/null +++ b/appc-common/src/test/java/org/onap/appc/util/PathContextTest.java @@ -0,0 +1,123 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2018 Nokia Solutions and Networks + * ============================================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ +package org.onap.appc.util; + +import static org.junit.Assert.*; + +import java.util.Map; +import org.junit.Before; +import org.junit.Test; + +public class PathContextTest { + + private PathContext pathContext; + + @Before + public void setup() { + pathContext = new PathContext(); + } + + @Test(expected = IllegalArgumentException.class) + public void should_throw_exception_when_pushed_null_token() { + pathContext.pushToken(null); + } + + @Test(expected = IllegalStateException.class) + public void should_throw_exception_when_popped_token_from_empty_path() { + pathContext.popToken(); + } + + @Test + public void should_delimit_tokens_with_dot() { + pathContext.pushToken("test"); + pathContext.pushToken("token"); + + assertEquals("test.token", pathContext.getPath()); + } + + @Test + public void should_pop_tokens() { + pathContext.pushToken("test"); + pathContext.pushToken("token"); + pathContext.pushToken("token2"); + + pathContext.popToken(); + + assertEquals("test.token", pathContext.getPath()); + } + + @Test(expected = IllegalArgumentException.class) + public void should_throw_exception_when_pushed_null_modifier() { + pathContext.pushModifier(null); + } + + @Test(expected = IllegalStateException.class) + public void should_throw_exception_when_popped_modifier_from_empty_path() { + pathContext.popModifier(); + } + + @Test + public void should_not_delimit_modifiers() { + pathContext.pushModifier("test"); + pathContext.pushModifier("modifier"); + + assertEquals("testmodifier", pathContext.getPath()); + } + + @Test + public void should_pop_modifiers() { + pathContext.pushModifier("test"); + pathContext.pushModifier("modifier"); + pathContext.pushModifier("modifier2"); + + pathContext.popModifier(); + + assertEquals("testmodifier", pathContext.getPath()); + } + + @Test + public void should_pop_modifiers_and_tokens() { + pathContext.pushModifier("test"); + pathContext.pushModifier("modifier"); + pathContext.pushToken("token"); + + //TODO popToken() and popModifier() actually work the same. + //TODO Is there sense to keep same method under different names then? + + pathContext.popToken(); + assertEquals("testmodifier", pathContext.getPath()); + + pathContext.popModifier(); + assertEquals("test", pathContext.getPath()); + } + + @Test + public void should_add_entries(){ + pathContext.entry("name", "value"); + + Map<String, String> entries = pathContext.entries(); + assertEquals("value", entries.get("name")); + } + +} |