diff options
author | liamfallon <liam.fallon@est.tech> | 2022-02-10 12:06:25 +0000 |
---|---|---|
committer | liamfallon <liam.fallon@est.tech> | 2022-02-10 13:48:15 +0000 |
commit | 8534756d13531ffec9c2d7b2ffe0a53ee1d3aaef (patch) | |
tree | a35f6b3f7766d47900ee6691111acff1418bb747 /model/utilities/src/test/java | |
parent | 2f2c5465cd23c8c3300a5c3d185806bb3e7d73c1 (diff) |
Collapse apex-pdp maven model submodules
This review collapses all the code in six podel submodules into a single
model module. There are no code changes, just files moved around.
This change reduces the complexity of the code structure and speeds up
the build.
Issue-ID: POLICY-1820
Change-Id: Ifb644e8ec85ae6d0987378f4616fbc8a8858a9a8
Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'model/utilities/src/test/java')
7 files changed, 0 insertions, 543 deletions
diff --git a/model/utilities/src/test/java/org/onap/policy/apex/model/utilities/CollectionUtilitiesTest.java b/model/utilities/src/test/java/org/onap/policy/apex/model/utilities/CollectionUtilitiesTest.java deleted file mode 100644 index 2512133e7..000000000 --- a/model/utilities/src/test/java/org/onap/policy/apex/model/utilities/CollectionUtilitiesTest.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. 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. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.utilities; - -import static org.junit.Assert.assertEquals; - -import java.util.ArrayList; -import java.util.List; -import org.junit.Test; - -public class CollectionUtilitiesTest { - - @Test - public void testNullLists() { - int result = 0; - - result = CollectionUtils.compareLists(null, null); - assertEquals(0, result); - - List<String> leftList = new ArrayList<String>(); - - result = CollectionUtils.compareLists(leftList, null); - assertEquals(-1, result); - - List<String> rightList = new ArrayList<String>(); - - result = CollectionUtils.compareLists(null, rightList); - assertEquals(1, result); - - result = CollectionUtils.compareLists(leftList, rightList); - assertEquals(0, result); - - leftList.add("AAA"); - result = CollectionUtils.compareLists(leftList, rightList); - assertEquals(-1, result); - - rightList.add("AAA"); - result = CollectionUtils.compareLists(leftList, rightList); - assertEquals(0, result); - - rightList.add("BBB"); - result = CollectionUtils.compareLists(leftList, rightList); - assertEquals(1, result); - - leftList.add("BBB"); - result = CollectionUtils.compareLists(leftList, rightList); - assertEquals(0, result); - - leftList.add("CCA"); - rightList.add("CCB"); - result = CollectionUtils.compareLists(leftList, rightList); - assertEquals(-1, result); - - leftList.remove(leftList.size() - 1); - rightList.remove(rightList.size() - 1); - result = CollectionUtils.compareLists(leftList, rightList); - assertEquals(0, result); - - leftList.add("CCB"); - rightList.add("CCA"); - result = CollectionUtils.compareLists(leftList, rightList); - assertEquals(1, result); - - leftList.remove(leftList.size() - 1); - rightList.remove(rightList.size() - 1); - result = CollectionUtils.compareLists(leftList, rightList); - assertEquals(0, result); - } -} diff --git a/model/utilities/src/test/java/org/onap/policy/apex/model/utilities/DirectoryUtilsTest.java b/model/utilities/src/test/java/org/onap/policy/apex/model/utilities/DirectoryUtilsTest.java deleted file mode 100644 index 69c2d4763..000000000 --- a/model/utilities/src/test/java/org/onap/policy/apex/model/utilities/DirectoryUtilsTest.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020 Nordix Foundation. - * ================================================================================ - * 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. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.utilities; - -import static org.junit.Assert.assertNotNull; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.util.Arrays; -import org.junit.Test; -import org.onap.policy.common.utils.resources.TextFileUtils; - -public class DirectoryUtilsTest { - - @Test - public void test() throws IOException { - DirectoryUtils.emptyDirectory(new File("/i/dont/exist")); - - File tempDir = Files.createTempDirectory("test").toFile(); - assertNotNull(tempDir); - - Files.createTempDirectory(tempDir.toPath(), "testsubprefix"); - - TextFileUtils.putStringAsTextFile("Temp File 0 contents", tempDir.getAbsolutePath() + "/tempFile0.tmp"); - TextFileUtils.putStringAsTextFile("Temp File 1 contents", tempDir.getAbsolutePath() + "/tempFile1.tmp"); - - DirectoryUtils.emptyDirectory(tempDir); - - DirectoryUtils.getLocalTempDirectory(null); - - byte[] byteArray = new byte[] {0, 0, 0}; - DirectoryUtils.getLocalTempDirectory(Arrays.toString(byteArray)); - } - -} diff --git a/model/utilities/src/test/java/org/onap/policy/apex/model/utilities/KeyComparerTest.java b/model/utilities/src/test/java/org/onap/policy/apex/model/utilities/KeyComparerTest.java deleted file mode 100644 index 20780b271..000000000 --- a/model/utilities/src/test/java/org/onap/policy/apex/model/utilities/KeyComparerTest.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020 Nordix Foundation. - * ================================================================================ - * 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. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.utilities; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; - -import org.junit.Test; -import org.onap.policy.apex.model.utilities.comparison.KeyComparer; -import org.onap.policy.apex.model.utilities.comparison.KeyDifference; - -/** - * Test key comparisons. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class KeyComparerTest { - - @Test - public void test() { - KeyDifference<String> keyDifference = new KeyComparer<String>().compareKeys("Hello", "Goodbye"); - - assertFalse(keyDifference.isEqual()); - assertEquals("Hello", keyDifference.getLeftKey().toString()); - assertEquals("Goodbye", keyDifference.getRightKey().toString()); - - assertEquals("left key Hello and right key Goodbye differ\n", keyDifference.asString(true)); - assertEquals("left key Hello and right key Goodbye differ\n", keyDifference.asString(false)); - - KeyDifference<String> keyDifference2 = new KeyComparer<String>().compareKeys("Here", "Here"); - assertEquals("", keyDifference2.asString(true)); - assertEquals("left key Here equals right key Here\n", keyDifference2.asString(false)); - } -} diff --git a/model/utilities/src/test/java/org/onap/policy/apex/model/utilities/KeyedMapComparerTest.java b/model/utilities/src/test/java/org/onap/policy/apex/model/utilities/KeyedMapComparerTest.java deleted file mode 100644 index b4e88e20d..000000000 --- a/model/utilities/src/test/java/org/onap/policy/apex/model/utilities/KeyedMapComparerTest.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020 Nordix Foundation. - * ================================================================================ - * 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. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.utilities; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import java.util.TreeMap; -import org.junit.Test; -import org.onap.policy.apex.model.utilities.comparison.KeyedMapComparer; -import org.onap.policy.apex.model.utilities.comparison.KeyedMapDifference; - -/** - * Test key map comparisons. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class KeyedMapComparerTest { - - @Test - public void test() { - TreeMap<String, String> leftMap = new TreeMap<String, String>(); - leftMap.put("B", "BBBBB"); - leftMap.put("C", "CCCCC"); - leftMap.put("E", "EEEEE"); - leftMap.put("G", "GGGGG"); - - TreeMap<String, String> rightMap = new TreeMap<String, String>(); - rightMap.put("A", "AAAAA"); - rightMap.put("B", "B"); - rightMap.put("D", "DDDDD"); - rightMap.put("E", "EEEEE"); - rightMap.put("F", "FFFFF"); - rightMap.put("G", "G"); - - KeyedMapDifference<String, String> kmComparedSame = - new KeyedMapComparer<String, String>().compareMaps(leftMap, leftMap); - KeyedMapDifference<String, String> kmComparedDiff = - new KeyedMapComparer<String, String>().compareMaps(leftMap, rightMap); - - assertEquals(leftMap, kmComparedSame.getIdenticalValues()); - assertEquals(1, kmComparedDiff.getLeftOnly().size()); - assertEquals(3, kmComparedDiff.getRightOnly().size()); - assertEquals(2, kmComparedDiff.getDifferentValues().size()); - assertEquals(1, kmComparedDiff.getIdenticalValues().size()); - - assertNotNull(kmComparedSame.asString(true, true)); - assertNotNull(kmComparedSame.asString(true, false)); - assertNotNull(kmComparedSame.asString(false, false)); - assertNotNull(kmComparedSame.asString(false, true)); - - assertNotNull(kmComparedDiff.asString(true, true)); - assertNotNull(kmComparedDiff.asString(true, false)); - assertNotNull(kmComparedDiff.asString(false, false)); - assertNotNull(kmComparedDiff.asString(false, true)); - } -} diff --git a/model/utilities/src/test/java/org/onap/policy/apex/model/utilities/TextFileUtilsTest.java b/model/utilities/src/test/java/org/onap/policy/apex/model/utilities/TextFileUtilsTest.java deleted file mode 100644 index 1d6f29fe5..000000000 --- a/model/utilities/src/test/java/org/onap/policy/apex/model/utilities/TextFileUtilsTest.java +++ /dev/null @@ -1,56 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020 Nordix Foundation. - * ================================================================================ - * 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. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.utilities; - -import static org.junit.Assert.assertEquals; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import org.junit.Test; -import org.onap.policy.common.utils.resources.TextFileUtils; - -/** - * Test text file utilities. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class TextFileUtilsTest { - - private static final String FILE_CONTENT = "This is the contents of a text file"; - - @Test - public void test() throws IOException { - final File tempTextFile = File.createTempFile("Test", "txt"); - - TextFileUtils.putStringAsTextFile(FILE_CONTENT, tempTextFile.getAbsolutePath()); - - final String textFileString0 = TextFileUtils.getTextFileAsString(tempTextFile.getAbsolutePath()); - assertEquals(FILE_CONTENT, textFileString0); - - final FileInputStream fis = new FileInputStream(tempTextFile); - final String textFileString1 = TextFileUtils.getStreamAsString(fis); - assertEquals(textFileString0, textFileString1); - - } - -} diff --git a/model/utilities/src/test/java/org/onap/policy/apex/model/utilities/TreeMapUtilsTest.java b/model/utilities/src/test/java/org/onap/policy/apex/model/utilities/TreeMapUtilsTest.java deleted file mode 100644 index c3a36b7b9..000000000 --- a/model/utilities/src/test/java/org/onap/policy/apex/model/utilities/TreeMapUtilsTest.java +++ /dev/null @@ -1,157 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2021 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. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.utilities; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertEquals; - -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.TreeMap; -import org.junit.Test; - -/** - * Test the tree map utilities. - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class TreeMapUtilsTest { - - private static final int KEY1 = 10; - private static final int KEY2 = 20; - private static final int KEY3 = 30; - private static final String VALUE1 = "a-one"; - private static final String VALUE2 = "b-two"; - private static final String VALUE3 = "c-three"; - private static final String VALUE4 = "d-four"; - - @Test - public void testFindMatchingEntries() { - TreeMap<String, String> testTreeMap = new TreeMap<String, String>(); - testTreeMap.put("G", "G"); - testTreeMap.put("H", "H"); - testTreeMap.put("JA", "JA"); - testTreeMap.put("JAM", "JAM"); - testTreeMap.put("JOE", "JOE"); - testTreeMap.put("JOSH", "JOSH"); - testTreeMap.put("K", "K"); - - List<Entry<String, String>> foundKeyList = TreeMapUtils.findMatchingEntries(testTreeMap, "F"); - assertEquals(0, foundKeyList.size()); - - foundKeyList = TreeMapUtils.findMatchingEntries(testTreeMap, "G"); - assertEquals("G", foundKeyList.get(0).getKey()); - - foundKeyList = TreeMapUtils.findMatchingEntries(testTreeMap, "H"); - assertEquals("H", foundKeyList.get(0).getKey()); - - foundKeyList = TreeMapUtils.findMatchingEntries(testTreeMap, "I"); - assertEquals(0, foundKeyList.size()); - - foundKeyList = TreeMapUtils.findMatchingEntries(testTreeMap, "J"); - assertEquals("JA", foundKeyList.get(0).getKey()); - - foundKeyList = TreeMapUtils.findMatchingEntries(testTreeMap, "JA"); - assertEquals("JA", foundKeyList.get(0).getKey()); - - foundKeyList = TreeMapUtils.findMatchingEntries(testTreeMap, "JB"); - assertEquals(0, foundKeyList.size()); - - foundKeyList = TreeMapUtils.findMatchingEntries(testTreeMap, "JO"); - assertEquals("JOE", foundKeyList.get(0).getKey()); - - foundKeyList = TreeMapUtils.findMatchingEntries(testTreeMap, "JOE"); - assertEquals("JOE", foundKeyList.get(0).getKey()); - - foundKeyList = TreeMapUtils.findMatchingEntries(testTreeMap, "JOS"); - assertEquals("JOSH", foundKeyList.get(0).getKey()); - - foundKeyList = TreeMapUtils.findMatchingEntries(testTreeMap, "JOSH"); - assertEquals("JOSH", foundKeyList.get(0).getKey()); - - foundKeyList = TreeMapUtils.findMatchingEntries(testTreeMap, "K"); - assertEquals("K", foundKeyList.get(0).getKey()); - - foundKeyList = TreeMapUtils.findMatchingEntries(testTreeMap, "L"); - assertEquals(0, foundKeyList.size()); - } - - @Test - public void testCompareMaps() { - Map<Integer, String> map1 = Map.of(); - Map<Integer, String> map2 = Map.of(); - - // note: using TreeMap so we can control the ordering of the entries - - // compare with self - assertThat(TreeMapUtils.compareMaps(map1, map1)).isZero(); - - // two empty maps - assertThat(TreeMapUtils.compareMaps(map1, map2)).isZero(); - - // same content - map1 = new TreeMap<>(Map.of(KEY1, VALUE1, KEY2, VALUE2, KEY3, VALUE3)); - map2 = new TreeMap<>(Map.of(KEY1, VALUE1, KEY2, VALUE2, KEY3, VALUE3)); - assertThat(TreeMapUtils.compareMaps(map1, map1)).isZero(); - assertThat(TreeMapUtils.compareMaps(map1, map2)).isZero(); - - // one is shorter than the other - map1 = new TreeMap<>(Map.of(KEY1, VALUE1, KEY2, VALUE2, KEY3, VALUE3)); - map2 = new TreeMap<>(Map.of(KEY1, VALUE1)); - assertThat(TreeMapUtils.compareMaps(map1, map2)).isPositive(); - assertThat(TreeMapUtils.compareMaps(map2, map1)).isNegative(); - - map2 = new TreeMap<>(Map.of(KEY1, VALUE1, KEY2, VALUE2)); - assertThat(TreeMapUtils.compareMaps(map1, map2)).isPositive(); - assertThat(TreeMapUtils.compareMaps(map2, map1)).isNegative(); - - // first key is different - map1 = new TreeMap<>(Map.of(KEY3, VALUE1, KEY2, VALUE2)); - map2 = new TreeMap<>(Map.of(KEY1, VALUE1, KEY2, VALUE2)); - assertThat(TreeMapUtils.compareMaps(map1, map2)).isPositive(); - assertThat(TreeMapUtils.compareMaps(map2, map1)).isNegative(); - - // second key is different - map1 = new TreeMap<>(Map.of(KEY1, VALUE1, KEY3, VALUE2)); - map2 = new TreeMap<>(Map.of(KEY1, VALUE1, KEY2, VALUE2)); - assertThat(TreeMapUtils.compareMaps(map1, map2)).isPositive(); - assertThat(TreeMapUtils.compareMaps(map2, map1)).isNegative(); - - // first value is different - map1 = new TreeMap<>(Map.of(KEY1, VALUE4, KEY2, VALUE2, KEY3, VALUE3)); - map2 = new TreeMap<>(Map.of(KEY1, VALUE1, KEY2, VALUE2, KEY3, VALUE3)); - assertThat(TreeMapUtils.compareMaps(map1, map2)).isPositive(); - assertThat(TreeMapUtils.compareMaps(map2, map1)).isNegative(); - - // second value is different - map1 = new TreeMap<>(Map.of(KEY1, VALUE1, KEY2, VALUE4, KEY3, VALUE3)); - map2 = new TreeMap<>(Map.of(KEY1, VALUE1, KEY2, VALUE2, KEY3, VALUE3)); - assertThat(TreeMapUtils.compareMaps(map1, map2)).isPositive(); - assertThat(TreeMapUtils.compareMaps(map2, map1)).isNegative(); - - // third value is different - map1 = new TreeMap<>(Map.of(KEY1, VALUE1, KEY2, VALUE2, KEY3, VALUE4)); - map2 = new TreeMap<>(Map.of(KEY1, VALUE1, KEY2, VALUE2, KEY3, VALUE3)); - assertThat(TreeMapUtils.compareMaps(map1, map2)).isPositive(); - assertThat(TreeMapUtils.compareMaps(map2, map1)).isNegative(); - } -} diff --git a/model/utilities/src/test/java/org/onap/policy/apex/model/utilities/json/JsonHandlerTest.java b/model/utilities/src/test/java/org/onap/policy/apex/model/utilities/json/JsonHandlerTest.java deleted file mode 100644 index ae5d53ec3..000000000 --- a/model/utilities/src/test/java/org/onap/policy/apex/model/utilities/json/JsonHandlerTest.java +++ /dev/null @@ -1,59 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. 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. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.utilities.json; - -import static org.junit.Assert.assertEquals; - -import com.google.gson.GsonBuilder; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.nio.charset.StandardCharsets; -import org.junit.Test; - -public class JsonHandlerTest { - - private static final String VALUE = "value"; - - @Test - public void testAssertions() throws IOException { - final OverTheMoonObject jsonObject = new OverTheMoonObject(VALUE); - final String jsonString = new GsonBuilder().create().toJson(jsonObject); - - final byte[] bytes = jsonString.getBytes(StandardCharsets.UTF_8); - try (final InputStream inputStream = new ByteArrayInputStream(bytes);) { - - final JsonHandler<OverTheMoonObject> objUnderTest = new JsonHandler<>(); - - final OverTheMoonObject actualObject = objUnderTest.read(OverTheMoonObject.class, inputStream); - assertEquals(VALUE, actualObject.name); - } - - } - - private class OverTheMoonObject { - private final String name; - - public OverTheMoonObject(final String name) { - this.name = name; - } - } -} |