From bc73640c5d910e376fd06d0a3fcbf18d8f92fd90 Mon Sep 17 00:00:00 2001 From: Jakub Dudycz Date: Tue, 13 Mar 2018 11:51:24 +0100 Subject: PathContext unit tests Improved code coverage Change-Id: I8b7d1fe8a033bd1c4df34bdd74efc011dc130a46 Issue-ID: APPC-724 Signed-off-by: Jakub Dudycz --- .../java/org/onap/appc/util/PathContextTest.java | 123 +++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 appc-common/src/test/java/org/onap/appc/util/PathContextTest.java (limited to 'appc-common') 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 entries = pathContext.entries(); + assertEquals("value", entries.get("name")); + } + +} -- cgit 1.2.3-korg