diff options
author | Pamela Dragosh <pdragosh@research.att.com> | 2018-06-20 17:26:17 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2018-06-20 17:26:17 +0000 |
commit | b5a47dcb16af9e90e46d08d0b5faedb3302bca8b (patch) | |
tree | 33236fe4bd7b1b7398d760be467eafdad090cb98 /feature-pooling-dmaap/src/test | |
parent | cea49f658fe6eb93c6d9d8fd1049f2fcb77b1ac4 (diff) | |
parent | 35d4e5606dbbe055f29afb5e837c000863d5a15f (diff) |
Merge "Remove references to SpecPropertyConfiguration"
Diffstat (limited to 'feature-pooling-dmaap/src/test')
4 files changed, 40 insertions, 242 deletions
diff --git a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/FeatureTest.java b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/FeatureTest.java index d453e746..8683103c 100644 --- a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/FeatureTest.java +++ b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/FeatureTest.java @@ -26,7 +26,7 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import static org.onap.policy.common.utils.properties.SpecPropertyConfiguration.specialize; +import static org.onap.policy.drools.pooling.PoolingProperties.PREFIX; import java.io.IOException; import java.util.Arrays; import java.util.Deque; @@ -994,6 +994,18 @@ public class FeatureTest { public PolicyController getController(DroolsController droolsController) { return context.getController(droolsController); } + + /** + * Embeds a specializer within a property name, after the prefix. + * + * @param propnm property name into which it should be embedded + * @param spec specializer to be embedded + * @return the property name, with the specializer embedded within it + */ + private String specialize(String propnm, String spec) { + String suffix = propnm.substring(PREFIX.length()); + return PREFIX + spec + "." + suffix; + } } /** diff --git a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/FeatureTest2.java b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/FeatureTest2.java index 6884bec8..298af064 100644 --- a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/FeatureTest2.java +++ b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/FeatureTest2.java @@ -26,7 +26,7 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import static org.onap.policy.common.utils.properties.SpecPropertyConfiguration.specialize; +import static org.onap.policy.drools.pooling.PoolingProperties.PREFIX; import java.io.IOException; import java.util.Deque; import java.util.IdentityHashMap; @@ -674,6 +674,18 @@ public class FeatureTest2 { public PolicyController getController(DroolsController droolsController) { return context.getController(droolsController); } + + /** + * Embeds a specializer within a property name, after the prefix. + * + * @param propnm property name into which it should be embedded + * @param spec specializer to be embedded + * @return the property name, with the specializer embedded within it + */ + private String specialize(String propnm, String spec) { + String suffix = propnm.substring(PREFIX.length()); + return PREFIX + spec + "." + suffix; + } } /** diff --git a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/PoolingPropertiesTest.java b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/PoolingPropertiesTest.java index 459c770a..eac8bfb1 100644 --- a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/PoolingPropertiesTest.java +++ b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/PoolingPropertiesTest.java @@ -21,9 +21,6 @@ package org.onap.policy.drools.pooling; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.onap.policy.common.utils.properties.SpecPropertyConfiguration.generalize; -import static org.onap.policy.common.utils.properties.SpecPropertyConfiguration.specialize; import static org.onap.policy.drools.pooling.PoolingProperties.ACTIVE_HEARTBEAT_MS; import static org.onap.policy.drools.pooling.PoolingProperties.FEATURE_ENABLED; import static org.onap.policy.drools.pooling.PoolingProperties.IDENTIFICATION_MS; @@ -32,6 +29,7 @@ import static org.onap.policy.drools.pooling.PoolingProperties.OFFLINE_AGE_MS; import static org.onap.policy.drools.pooling.PoolingProperties.OFFLINE_LIMIT; import static org.onap.policy.drools.pooling.PoolingProperties.OFFLINE_PUB_WAIT_MS; import static org.onap.policy.drools.pooling.PoolingProperties.POOLING_TOPIC; +import static org.onap.policy.drools.pooling.PoolingProperties.PREFIX; import static org.onap.policy.drools.pooling.PoolingProperties.REACTIVATE_MS; import static org.onap.policy.drools.pooling.PoolingProperties.START_HEARTBEAT_MS; import java.util.Properties; @@ -82,12 +80,6 @@ public class PoolingPropertiesTest { assertEquals(STD_POOLING_TOPIC, pooling.getPoolingTopic()); } - @Test(expected = IllegalArgumentException.class) - public void testGetPoolingTopic_Generalize() { - // shouldn't be able to generalize the topic - generalize(POOLING_TOPIC); - } - @Test public void testGetOfflineLimit() throws PropertyException { doTest(OFFLINE_LIMIT, STD_OFFLINE_LIMIT, 1000, xxx -> pooling.getOfflineLimit()); @@ -147,16 +139,10 @@ public class PoolingPropertiesTest { assertEquals("special " + propnm, specValue, func.apply(null)); /* - * Ensure the property supports generalization - this will throw an exception if - * it does not. - */ - assertFalse(propnm.equals(generalize(propnm))); - - /* * Without the property - should use the default value. */ plain.remove(specialize(propnm, CONTROLLER)); - plain.remove(generalize(propnm)); + plain.remove(propnm); pooling = new PoolingProperties(CONTROLLER, plain); assertEquals("default " + propnm, dfltValue, func.apply(null)); } @@ -183,4 +169,16 @@ public class PoolingPropertiesTest { return props; } + + /** + * Embeds a specializer within a property name, after the prefix. + * + * @param propnm property name into which it should be embedded + * @param spec specializer to be embedded + * @return the property name, with the specializer embedded within it + */ + private String specialize(String propnm, String spec) { + String suffix = propnm.substring(PREFIX.length()); + return PREFIX + spec + "." + suffix; + } } diff --git a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/SpecPropertiesTest.java b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/SpecPropertiesTest.java deleted file mode 100644 index d09650db..00000000 --- a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/SpecPropertiesTest.java +++ /dev/null @@ -1,224 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * ONAP - * ================================================================================ - * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.drools.pooling; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import java.util.Properties; -import org.junit.Before; -import org.junit.Test; - -public class SpecPropertiesTest { - - /** - * Property prefix of interest. - */ - private static final String MY_PREFIX = "my.prefix"; - - /** - * Specialization, which follows the prefix. - */ - private static final String MY_SPEC = "my.spec"; - - /** - * Generalized prefix (i.e., without the spec). - */ - private static final String PREFIX_GEN = MY_PREFIX + "."; - - /** - * Specialized prefix (i.e., with the spec). - */ - private static final String PREFIX_SPEC = PREFIX_GEN + MY_SPEC + "."; - - /** - * Suffix to add to property names to generate names of properties that are not - * populated. - */ - private static final String SUFFIX = ".suffix"; - - /** - * Property name without a prefix. - */ - private static final String PROP_NO_PREFIX = "other"; - - /** - * Generalized property name (i.e., without the spec). - */ - private static final String PROP_GEN = PREFIX_GEN + "generalized"; - - // property names that include the spec - private static final String PROP_SPEC = PREFIX_SPEC + "specialized"; - private static final String PROP_UNKNOWN = PREFIX_SPEC + "unknown"; - - // property values - private static final String VAL_NO_PREFIX = "no-prefix"; - private static final String VAL_GEN = "gen"; - private static final String VAL_SPEC = "spec"; - - private static final String VAL_DEFAULT = "default value"; - - private Properties supportingProps; - private SpecProperties props; - - @Before - public void setUp() { - supportingProps = new Properties(); - - supportingProps.setProperty(PROP_NO_PREFIX, VAL_NO_PREFIX); - supportingProps.setProperty(PROP_GEN, VAL_GEN); - supportingProps.setProperty(PROP_SPEC, VAL_SPEC); - - props = new SpecProperties(MY_PREFIX, MY_SPEC); - - props.putAll(supportingProps); - } - - @Test - public void testSpecPropertiesStringString() { - - // no supporting properties - props = new SpecProperties(MY_PREFIX, MY_SPEC); - - assertEquals(PREFIX_GEN, props.getPrefix()); - assertEquals(PREFIX_SPEC, props.getSpecPrefix()); - - // everything is null - assertNull(props.getProperty(gen(PROP_NO_PREFIX))); - assertNull(props.getProperty(gen(PROP_GEN))); - assertNull(props.getProperty(gen(PROP_SPEC))); - assertNull(props.getProperty(gen(PROP_UNKNOWN))); - } - - @Test - public void testSpecPropertiesStringStringProperties() { - - // use supportingProps as default properties - props = new SpecProperties(MY_PREFIX, MY_SPEC, supportingProps); - - assertEquals(PREFIX_GEN, props.getPrefix()); - assertEquals(PREFIX_SPEC, props.getSpecPrefix()); - - assertEquals(VAL_NO_PREFIX, props.getProperty(gen(PROP_NO_PREFIX))); - assertEquals(VAL_GEN, props.getProperty(gen(PROP_GEN))); - assertEquals(VAL_SPEC, props.getProperty(gen(PROP_SPEC))); - assertNull(props.getProperty(gen(PROP_UNKNOWN))); - } - - @Test - public void testSpecPropertiesStringStringProperties_EmptyPrefix() { - supportingProps = new Properties(); - - supportingProps.setProperty(PROP_NO_PREFIX, VAL_NO_PREFIX); - supportingProps.setProperty("a.value", VAL_GEN); - supportingProps.setProperty("b.value", VAL_GEN); - supportingProps.setProperty(MY_SPEC + ".b.value", VAL_SPEC); - - // no supporting properties - props = new SpecProperties("", MY_SPEC, supportingProps); - - assertEquals(VAL_NO_PREFIX, props.getProperty(gen(PROP_NO_PREFIX))); - assertEquals(VAL_GEN, props.getProperty(gen("a.value"))); - assertEquals(VAL_SPEC, props.getProperty(MY_SPEC + ".b.value")); - assertNull(props.getProperty(gen(PROP_UNKNOWN))); - } - - @Test - public void testWithTrailingDot() { - // neither has trailing dot - assertEquals(PREFIX_GEN, props.getPrefix()); - assertEquals(PREFIX_SPEC, props.getSpecPrefix()); - - // both have trailing dot - props = new SpecProperties(PREFIX_GEN, MY_SPEC + "."); - assertEquals(PREFIX_GEN, props.getPrefix()); - assertEquals(PREFIX_SPEC, props.getSpecPrefix()); - - // first is empty - props = new SpecProperties("", MY_SPEC); - assertEquals("", props.getPrefix()); - assertEquals(MY_SPEC + ".", props.getSpecPrefix()); - - // second is empty - props = new SpecProperties(PREFIX_GEN, ""); - assertEquals(PREFIX_GEN, props.getPrefix()); - assertEquals(PREFIX_GEN, props.getSpecPrefix()); - } - - @Test - public void testGetPropertyString() { - // the key does contain the prefix - assertEquals(VAL_NO_PREFIX, props.getProperty(gen(PROP_NO_PREFIX))); - assertNull(props.getProperty(gen(PROP_NO_PREFIX + SUFFIX))); - - // specialized value exists - assertEquals(VAL_GEN, props.getProperty(gen(PROP_GEN))); - assertNull(props.getProperty(gen(PROP_GEN + SUFFIX))); - - // generalized value exists - assertEquals(VAL_SPEC, props.getProperty(gen(PROP_SPEC))); - assertNull(props.getProperty(gen(PROP_SPEC + SUFFIX))); - - // not found - assertNull(props.getProperty(gen(PROP_UNKNOWN))); - assertNull(props.getProperty(gen(PROP_UNKNOWN + SUFFIX))); - } - - @Test - public void testGetPropertyStringString() { - // the key does contain the prefix - assertEquals(VAL_NO_PREFIX, props.getProperty(gen(PROP_NO_PREFIX), VAL_DEFAULT)); - assertEquals(VAL_DEFAULT, props.getProperty(gen(PROP_NO_PREFIX + SUFFIX), VAL_DEFAULT)); - - // specialized value exists - assertEquals(VAL_GEN, props.getProperty(gen(PROP_GEN), VAL_DEFAULT)); - assertEquals(VAL_DEFAULT, props.getProperty(gen(PROP_GEN + SUFFIX), VAL_DEFAULT)); - - // generalized value exists - assertEquals(VAL_SPEC, props.getProperty(gen(PROP_SPEC), VAL_DEFAULT)); - assertEquals(VAL_DEFAULT, props.getProperty(gen(PROP_SPEC + SUFFIX), VAL_DEFAULT)); - - // not found - assertEquals(VAL_DEFAULT, props.getProperty(gen(PROP_UNKNOWN), VAL_DEFAULT)); - assertEquals(VAL_DEFAULT, props.getProperty(gen(PROP_UNKNOWN + SUFFIX), VAL_DEFAULT)); - - // can return null - assertNull(props.getProperty(gen(PROP_UNKNOWN), null)); - } - - @Test(expected = UnsupportedOperationException.class) - public void testHashCode() { - props.hashCode(); - } - - @Test(expected = UnsupportedOperationException.class) - public void testEquals() { - props.equals(props); - } - - private String gen(String propnm) { - if (propnm.startsWith(PREFIX_SPEC)) { - return PREFIX_GEN + propnm.substring(PREFIX_SPEC.length()); - } - - return propnm; - } - -} |