From 781b1a6df324419c846c84ea983c18fc8362bfd3 Mon Sep 17 00:00:00 2001 From: Patrick Brady Date: Wed, 13 Dec 2017 11:19:06 -0800 Subject: Third part of onap rename This part of the commit changes the folder structure on all other folders of appc. Change-Id: I8acfa11cdfcdcd36be0e137245d1dd7324f1abd3 Signed-off-by: Patrick Brady Issue-ID: APPC-13 --- .../rankingframework/TestRankingFramework.java | 228 +++++++++++++++++++++ .../rankingframework/TestRankingFramework.java | 228 --------------------- 2 files changed, 228 insertions(+), 228 deletions(-) create mode 100644 appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/test/java/org/onap/appc/rankingframework/TestRankingFramework.java delete mode 100644 appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/test/java/org/openecomp/appc/rankingframework/TestRankingFramework.java (limited to 'appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/test/java') diff --git a/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/test/java/org/onap/appc/rankingframework/TestRankingFramework.java b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/test/java/org/onap/appc/rankingframework/TestRankingFramework.java new file mode 100644 index 000000000..99376923f --- /dev/null +++ b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/test/java/org/onap/appc/rankingframework/TestRankingFramework.java @@ -0,0 +1,228 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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.rankingframework; + +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.Assert; +import org.junit.Test; +import org.onap.appc.rankingframework.AbstractRankedAttributesResolverFactory; +import org.onap.appc.rankingframework.ConfigurationEntry; +import org.onap.appc.rankingframework.ConfigurationSet; +import org.onap.appc.rankingframework.RankedAttributesContext; +import org.onap.appc.rankingframework.RankedAttributesResolver; + +public class TestRankingFramework { + + private static final String COUNTRY = "COUNTRY"; + private static final String STATE = "STATE"; + private static final String CITY = "CITY"; + + private static final List NAMES = Arrays.asList(COUNTRY, STATE, CITY); + + private static final String PACIFIC = "Pacific"; + private static final String ATLANTIC = "Atlantic"; + private static final String ARCTIC = "Arctic"; + private static final String NA = "N/A"; + + private static ConfigurationEntry entry(String [] attributes, String result) { + if (attributes == null || attributes.length != NAMES.size()) { + throw new IllegalArgumentException(); + } + + Map map = new HashMap<>(attributes.length); + for (int i = 0; i < attributes.length; i++) { + map.put(NAMES.get(i), attributes[i]); + } + + return new ConfigurationEntryImpl(map, result); + } + + private static ConfigurationSet config(ConfigurationEntry ... entries) { + return new ConfigurationSetImpl(Arrays.asList(entries), NAMES); + } + + private static RankedAttributesContext context(String ... attributes) { + if (attributes == null || attributes.length != NAMES.size()) { + throw new IllegalArgumentException(); + } + + Map map = new HashMap<>(attributes.length); + for (int i = 0; i < attributes.length; i++) { + map.put(NAMES.get(i), attributes[i]); + } + + return new Context(map); + } + + private static class ConfigurationSetImpl implements ConfigurationSet { + + private final Collection> entries; + private final Collection names; + + ConfigurationSetImpl(Collection> entries, Collection names) { + this.entries = entries; + this.names = names; + } + + @Override + public Iterable> getEntries() { + return entries; + } + + @Override + public Collection getRankedAttributeNames() { + return names; + } + } + + private static class ConfigurationEntryImpl implements ConfigurationEntry { + + private final Map attributes; + private final String result; + + ConfigurationEntryImpl(Map attributes, String result) { + this.attributes = attributes; + this.result = result; + } + + @Override + public Object getAttributeValue(String name) { + return attributes.get(name); + } + + @Override + public String getResult() { + return result; + } + } + + private static class Context implements RankedAttributesContext { + + private final Map map; + + Context(Map map) { + this.map = map; + } + + @Override + public Object getAttributeValue(String name) { + return map.get(name); + } + } + + private static ConfigurationSet testData() { + @SuppressWarnings("unchecked") + ConfigurationSet config = config( + entry(new String [] {"US", "CA", "SFO"}, PACIFIC), + entry(new String [] {"US", "CA", "LA"}, PACIFIC), + entry(new String [] {"US", "FL", "MIAMI"}, ATLANTIC), + entry(new String [] {"US", "AK", "Barrow"}, ARCTIC), + entry(new String [] {"US", "AK", "*"}, PACIFIC), + entry(new String [] {"US", "*", "Houston"}, ATLANTIC), + entry(new String [] {"US", "*", "*"}, NA) + ); + + return config; + } + + private static RankedAttributesResolver resolver(ConfigurationSet config) { + return AbstractRankedAttributesResolverFactory.getInstance().create(config); + } + + @Test + public void testExactMatch() { + + ConfigurationSet config = testData(); + + RankedAttributesResolver resolver = resolver(config) ; + + RankedAttributesContext context = context("US", "CA", "SFO"); + + String result = resolver.resolve(context); + + Assert.assertEquals(PACIFIC, result); + } + + @Test + public void testDefaultMatchPartial() { + + ConfigurationSet config = testData(); + + RankedAttributesResolver resolver = resolver(config) ; + + RankedAttributesContext context = context("US", "AK", "Anchorage"); + + String result = resolver.resolve(context); + + Assert.assertEquals(PACIFIC, result); + } + + @Test + public void testDefaultMatchFull() { + + ConfigurationSet config = testData(); + + RankedAttributesResolver resolver = resolver(config) ; + + RankedAttributesContext context = context("US", "IL", "Chicago"); + + String result = resolver.resolve(context); + + Assert.assertEquals(NA, result); + } + + @Test + public void testDefaultMatchInTheMiddle() { + + ConfigurationSet config = testData(); + + RankedAttributesResolver resolver = resolver(config) ; + + RankedAttributesContext context = context("US", "TX", "Houston"); + + String result = resolver.resolve(context); + + Assert.assertEquals(ATLANTIC, result); + } + + @Test + public void testBacktrace() { + + ConfigurationSet config = testData(); + + RankedAttributesResolver resolver = resolver(config) ; + + RankedAttributesContext context = context("US", "CA", "SJC"); + + String result = resolver.resolve(context); + + Assert.assertEquals(NA, result); + } +} diff --git a/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/test/java/org/openecomp/appc/rankingframework/TestRankingFramework.java b/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/test/java/org/openecomp/appc/rankingframework/TestRankingFramework.java deleted file mode 100644 index 99376923f..000000000 --- a/appc-dispatcher/appc-dispatcher-common/ranking-framework-lib/src/test/java/org/openecomp/appc/rankingframework/TestRankingFramework.java +++ /dev/null @@ -1,228 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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.rankingframework; - -import java.util.Arrays; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.junit.Assert; -import org.junit.Test; -import org.onap.appc.rankingframework.AbstractRankedAttributesResolverFactory; -import org.onap.appc.rankingframework.ConfigurationEntry; -import org.onap.appc.rankingframework.ConfigurationSet; -import org.onap.appc.rankingframework.RankedAttributesContext; -import org.onap.appc.rankingframework.RankedAttributesResolver; - -public class TestRankingFramework { - - private static final String COUNTRY = "COUNTRY"; - private static final String STATE = "STATE"; - private static final String CITY = "CITY"; - - private static final List NAMES = Arrays.asList(COUNTRY, STATE, CITY); - - private static final String PACIFIC = "Pacific"; - private static final String ATLANTIC = "Atlantic"; - private static final String ARCTIC = "Arctic"; - private static final String NA = "N/A"; - - private static ConfigurationEntry entry(String [] attributes, String result) { - if (attributes == null || attributes.length != NAMES.size()) { - throw new IllegalArgumentException(); - } - - Map map = new HashMap<>(attributes.length); - for (int i = 0; i < attributes.length; i++) { - map.put(NAMES.get(i), attributes[i]); - } - - return new ConfigurationEntryImpl(map, result); - } - - private static ConfigurationSet config(ConfigurationEntry ... entries) { - return new ConfigurationSetImpl(Arrays.asList(entries), NAMES); - } - - private static RankedAttributesContext context(String ... attributes) { - if (attributes == null || attributes.length != NAMES.size()) { - throw new IllegalArgumentException(); - } - - Map map = new HashMap<>(attributes.length); - for (int i = 0; i < attributes.length; i++) { - map.put(NAMES.get(i), attributes[i]); - } - - return new Context(map); - } - - private static class ConfigurationSetImpl implements ConfigurationSet { - - private final Collection> entries; - private final Collection names; - - ConfigurationSetImpl(Collection> entries, Collection names) { - this.entries = entries; - this.names = names; - } - - @Override - public Iterable> getEntries() { - return entries; - } - - @Override - public Collection getRankedAttributeNames() { - return names; - } - } - - private static class ConfigurationEntryImpl implements ConfigurationEntry { - - private final Map attributes; - private final String result; - - ConfigurationEntryImpl(Map attributes, String result) { - this.attributes = attributes; - this.result = result; - } - - @Override - public Object getAttributeValue(String name) { - return attributes.get(name); - } - - @Override - public String getResult() { - return result; - } - } - - private static class Context implements RankedAttributesContext { - - private final Map map; - - Context(Map map) { - this.map = map; - } - - @Override - public Object getAttributeValue(String name) { - return map.get(name); - } - } - - private static ConfigurationSet testData() { - @SuppressWarnings("unchecked") - ConfigurationSet config = config( - entry(new String [] {"US", "CA", "SFO"}, PACIFIC), - entry(new String [] {"US", "CA", "LA"}, PACIFIC), - entry(new String [] {"US", "FL", "MIAMI"}, ATLANTIC), - entry(new String [] {"US", "AK", "Barrow"}, ARCTIC), - entry(new String [] {"US", "AK", "*"}, PACIFIC), - entry(new String [] {"US", "*", "Houston"}, ATLANTIC), - entry(new String [] {"US", "*", "*"}, NA) - ); - - return config; - } - - private static RankedAttributesResolver resolver(ConfigurationSet config) { - return AbstractRankedAttributesResolverFactory.getInstance().create(config); - } - - @Test - public void testExactMatch() { - - ConfigurationSet config = testData(); - - RankedAttributesResolver resolver = resolver(config) ; - - RankedAttributesContext context = context("US", "CA", "SFO"); - - String result = resolver.resolve(context); - - Assert.assertEquals(PACIFIC, result); - } - - @Test - public void testDefaultMatchPartial() { - - ConfigurationSet config = testData(); - - RankedAttributesResolver resolver = resolver(config) ; - - RankedAttributesContext context = context("US", "AK", "Anchorage"); - - String result = resolver.resolve(context); - - Assert.assertEquals(PACIFIC, result); - } - - @Test - public void testDefaultMatchFull() { - - ConfigurationSet config = testData(); - - RankedAttributesResolver resolver = resolver(config) ; - - RankedAttributesContext context = context("US", "IL", "Chicago"); - - String result = resolver.resolve(context); - - Assert.assertEquals(NA, result); - } - - @Test - public void testDefaultMatchInTheMiddle() { - - ConfigurationSet config = testData(); - - RankedAttributesResolver resolver = resolver(config) ; - - RankedAttributesContext context = context("US", "TX", "Houston"); - - String result = resolver.resolve(context); - - Assert.assertEquals(ATLANTIC, result); - } - - @Test - public void testBacktrace() { - - ConfigurationSet config = testData(); - - RankedAttributesResolver resolver = resolver(config) ; - - RankedAttributesContext context = context("US", "CA", "SJC"); - - String result = resolver.resolve(context); - - Assert.assertEquals(NA, result); - } -} -- cgit 1.2.3-korg