From d697d828df129afa52555e9381d69c45d526c7d6 Mon Sep 17 00:00:00 2001 From: Parshad Patel Date: Mon, 26 Nov 2018 18:22:40 +0900 Subject: Rename test classes in drools-applications Make test classes name consitence by adding 'Support' or 'Dummy' at start of util or dummy type of test classes Issue-ID: POLICY-1258 Change-Id: Idea946375ee46f14512d4c4bc29e65adaa4d2b37 Signed-off-by: Parshad Patel --- .../ActorServiceProviderTest.java | 16 ++--- .../actorserviceprovider/DummyActor.java | 60 +++++++++++++++++++ .../actorserviceprovider/TestActor.java | 60 ------------------- ...licy.controlloop.actorserviceprovider.spi.Actor | 2 +- .../org/onap/policy/controlloop/SupportUtil.java | 69 ++++++++++++++++++++++ .../java/org/onap/policy/controlloop/Util.java | 69 ---------------------- .../eventmanager/ControlLoopEventManagerTest.java | 8 +-- .../ControlLoopOperationManagerTest.java | 6 +- .../java/org/onap/policy/guard/GuardUtilTest.java | 4 +- .../policy/guard/PolicyGuardYamlToXacmlTest.java | 16 ++--- .../onap/policy/guard/SupportTextFileUtils.java | 63 ++++++++++++++++++++ .../java/org/onap/policy/guard/TextFileUtils.java | 63 -------------------- 12 files changed, 218 insertions(+), 218 deletions(-) create mode 100644 controlloop/common/actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/DummyActor.java delete mode 100644 controlloop/common/actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/TestActor.java create mode 100644 controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/SupportUtil.java delete mode 100644 controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/Util.java create mode 100644 controlloop/common/guard/src/test/java/org/onap/policy/guard/SupportTextFileUtils.java delete mode 100644 controlloop/common/guard/src/test/java/org/onap/policy/guard/TextFileUtils.java (limited to 'controlloop/common') diff --git a/controlloop/common/actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/ActorServiceProviderTest.java b/controlloop/common/actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/ActorServiceProviderTest.java index a70216d1e..4e50d855f 100644 --- a/controlloop/common/actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/ActorServiceProviderTest.java +++ b/controlloop/common/actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/ActorServiceProviderTest.java @@ -38,16 +38,16 @@ public class ActorServiceProviderTest { actorService = ActorService.getInstance(); assertNotNull(actorService); - Actor testActor = ActorService.getInstance().actors().get(0); - assertNotNull(testActor); + Actor dummyActor = ActorService.getInstance().actors().get(0); + assertNotNull(dummyActor); - assertEquals("TestActor", testActor.actor()); + assertEquals("DummyActor", dummyActor.actor()); - assertEquals(2, testActor.recipes().size()); - assertEquals("Dorothy", testActor.recipes().get(0)); - assertEquals("Wizard", testActor.recipes().get(1)); + assertEquals(2, dummyActor.recipes().size()); + assertEquals("Dorothy", dummyActor.recipes().get(0)); + assertEquals("Wizard", dummyActor.recipes().get(1)); - assertEquals(2, testActor.recipeTargets("Dorothy").size()); - assertEquals(2, testActor.recipePayloads("Dorothy").size()); + assertEquals(2, dummyActor.recipeTargets("Dorothy").size()); + assertEquals(2, dummyActor.recipePayloads("Dorothy").size()); } } diff --git a/controlloop/common/actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/DummyActor.java b/controlloop/common/actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/DummyActor.java new file mode 100644 index 000000000..2e8512411 --- /dev/null +++ b/controlloop/common/actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/DummyActor.java @@ -0,0 +1,60 @@ +/*- + * ============LICENSE_START======================================================= + * TestActorServiceProvider + * ================================================================================ + * Copyright (C) 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.controlloop.actorserviceprovider; + +import java.util.ArrayList; +import java.util.List; + +import org.onap.policy.controlloop.actorserviceprovider.spi.Actor; + +public class DummyActor implements Actor { + @Override + public String actor() { + return this.getClass().getSimpleName(); + } + + @Override + public List recipes() { + List recipeList = new ArrayList<>(); + recipeList.add("Dorothy"); + recipeList.add("Wizard"); + + return recipeList; + } + + @Override + public List recipeTargets(String recipe) { + List recipeTargetList = new ArrayList<>(); + recipeTargetList.add("Wicked Witch"); + recipeTargetList.add("Wizard of Oz"); + + return recipeTargetList; + } + + @Override + public List recipePayloads(String recipe) { + List recipePayloadList = new ArrayList<>(); + recipePayloadList.add("Dorothy"); + recipePayloadList.add("Toto"); + + return recipePayloadList; + } +} diff --git a/controlloop/common/actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/TestActor.java b/controlloop/common/actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/TestActor.java deleted file mode 100644 index af04cc138..000000000 --- a/controlloop/common/actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/TestActor.java +++ /dev/null @@ -1,60 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * TestActorServiceProvider - * ================================================================================ - * Copyright (C) 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. - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.controlloop.actorserviceprovider; - -import java.util.ArrayList; -import java.util.List; - -import org.onap.policy.controlloop.actorserviceprovider.spi.Actor; - -public class TestActor implements Actor { - @Override - public String actor() { - return this.getClass().getSimpleName(); - } - - @Override - public List recipes() { - List recipeList = new ArrayList<>(); - recipeList.add("Dorothy"); - recipeList.add("Wizard"); - - return recipeList; - } - - @Override - public List recipeTargets(String recipe) { - List recipeTargetList = new ArrayList<>(); - recipeTargetList.add("Wicked Witch"); - recipeTargetList.add("Wizard of Oz"); - - return recipeTargetList; - } - - @Override - public List recipePayloads(String recipe) { - List recipePayloadList = new ArrayList<>(); - recipePayloadList.add("Dorothy"); - recipePayloadList.add("Toto"); - - return recipePayloadList; - } -} diff --git a/controlloop/common/actors/actorServiceProvider/src/test/resources/META-INF/services/org.onap.policy.controlloop.actorserviceprovider.spi.Actor b/controlloop/common/actors/actorServiceProvider/src/test/resources/META-INF/services/org.onap.policy.controlloop.actorserviceprovider.spi.Actor index a15871456..2a4bb5749 100644 --- a/controlloop/common/actors/actorServiceProvider/src/test/resources/META-INF/services/org.onap.policy.controlloop.actorserviceprovider.spi.Actor +++ b/controlloop/common/actors/actorServiceProvider/src/test/resources/META-INF/services/org.onap.policy.controlloop.actorserviceprovider.spi.Actor @@ -1 +1 @@ -org.onap.policy.controlloop.actorserviceprovider.TestActor \ No newline at end of file +org.onap.policy.controlloop.actorserviceprovider.DummyActor \ No newline at end of file diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/SupportUtil.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/SupportUtil.java new file mode 100644 index 000000000..39077e3b3 --- /dev/null +++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/SupportUtil.java @@ -0,0 +1,69 @@ +/*- + * ============LICENSE_START======================================================= + * util + * ================================================================================ + * Copyright (C) 2017-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.controlloop; + +import static org.junit.Assert.fail; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; + +import org.apache.commons.io.IOUtils; +import org.onap.policy.controlloop.policy.ControlLoopPolicy; +import org.yaml.snakeyaml.Yaml; +import org.yaml.snakeyaml.constructor.Constructor; + +public final class SupportUtil { + + public static class Pair { + public final A key; + public final B value; + + public Pair(A key, B value) { + this.key = key; + this.value = value; + } + } + + /** + * Load yaml into a Pair object. + * + * @param testFile the yaml file + * @return a Pair + */ + public static Pair loadYaml(String testFile) { + try (InputStream is = new FileInputStream(new File(testFile))) { + String contents = IOUtils.toString(is, StandardCharsets.UTF_8); + // + // Read the yaml into our Java Object + // + Yaml yaml = new Yaml(new Constructor(ControlLoopPolicy.class)); + Object obj = yaml.load(contents); + return new Pair((ControlLoopPolicy) obj, contents); + } catch (IOException e) { + fail(e.getLocalizedMessage()); + } + return null; + } + +} diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/Util.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/Util.java deleted file mode 100644 index ced419a04..000000000 --- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/Util.java +++ /dev/null @@ -1,69 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * util - * ================================================================================ - * Copyright (C) 2017-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.controlloop; - -import static org.junit.Assert.fail; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.nio.charset.StandardCharsets; - -import org.apache.commons.io.IOUtils; -import org.onap.policy.controlloop.policy.ControlLoopPolicy; -import org.yaml.snakeyaml.Yaml; -import org.yaml.snakeyaml.constructor.Constructor; - -public final class Util { - - public static class Pair { - public final A key; - public final B value; - - public Pair(A key, B value) { - this.key = key; - this.value = value; - } - } - - /** - * Load yaml into a Pair object. - * - * @param testFile the yaml file - * @return a Pair - */ - public static Pair loadYaml(String testFile) { - try (InputStream is = new FileInputStream(new File(testFile))) { - String contents = IOUtils.toString(is, StandardCharsets.UTF_8); - // - // Read the yaml into our Java Object - // - Yaml yaml = new Yaml(new Constructor(ControlLoopPolicy.class)); - Object obj = yaml.load(contents); - return new Pair((ControlLoopPolicy) obj, contents); - } catch (IOException e) { - fail(e.getLocalizedMessage()); - } - return null; - } - -} diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java index 1673df3be..49a6258c1 100644 --- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java +++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java @@ -58,7 +58,7 @@ import org.onap.policy.common.utils.io.Serializer; import org.onap.policy.controlloop.ControlLoopEventStatus; import org.onap.policy.controlloop.ControlLoopException; import org.onap.policy.controlloop.ControlLoopNotificationType; -import org.onap.policy.controlloop.Util; +import org.onap.policy.controlloop.SupportUtil; import org.onap.policy.controlloop.VirtualControlLoopEvent; import org.onap.policy.controlloop.VirtualControlLoopNotification; import org.onap.policy.controlloop.eventmanager.ControlLoopEventManager.NEW_EVENT_STATUS; @@ -124,7 +124,7 @@ public class ControlLoopEventManagerTest { @Test public void testAaiVnfInfo() { - final Util.Pair pair = Util.loadYaml("src/test/resources/test.yaml"); + final SupportUtil.Pair pair = SupportUtil.loadYaml("src/test/resources/test.yaml"); onset.setClosedLoopControlName(pair.key.getControlLoop().getControlLoopName()); try { AaiGetVnfResponse response = getQueryByVnfId2( @@ -143,7 +143,7 @@ public class ControlLoopEventManagerTest { @Test public void testAaiVnfInfo2() { - final Util.Pair pair = Util.loadYaml("src/test/resources/test.yaml"); + final SupportUtil.Pair pair = SupportUtil.loadYaml("src/test/resources/test.yaml"); onset.setClosedLoopControlName(pair.key.getControlLoop().getControlLoopName()); try { AaiGetVnfResponse response = getQueryByVnfName2( @@ -161,7 +161,7 @@ public class ControlLoopEventManagerTest { @Test public void testAaiVserver() { - final Util.Pair pair = Util.loadYaml("src/test/resources/test.yaml"); + final SupportUtil.Pair pair = SupportUtil.loadYaml("src/test/resources/test.yaml"); onset.setClosedLoopControlName(pair.key.getControlLoop().getControlLoopName()); try { AaiGetVserverResponse response = getQueryByVserverName2( diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManagerTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManagerTest.java index dae03aa6e..0afe9d2d3 100644 --- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManagerTest.java +++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManagerTest.java @@ -61,7 +61,7 @@ import org.onap.policy.controlloop.ControlLoopEventStatus; import org.onap.policy.controlloop.ControlLoopException; import org.onap.policy.controlloop.ControlLoopNotificationType; import org.onap.policy.controlloop.ControlLoopTargetType; -import org.onap.policy.controlloop.Util; +import org.onap.policy.controlloop.SupportUtil; import org.onap.policy.controlloop.VirtualControlLoopEvent; import org.onap.policy.controlloop.VirtualControlLoopNotification; import org.onap.policy.controlloop.policy.ControlLoopPolicy; @@ -161,7 +161,7 @@ public class ControlLoopOperationManagerTest { // // Load up the policy // - final Util.Pair pair = Util.loadYaml("src/test/resources/test.yaml"); + final SupportUtil.Pair pair = SupportUtil.loadYaml("src/test/resources/test.yaml"); onset.setClosedLoopControlName(pair.key.getControlLoop().getControlLoopName()); try { // @@ -292,7 +292,7 @@ public class ControlLoopOperationManagerTest { // // Load up the policy // - final Util.Pair pair = Util.loadYaml("src/test/resources/test.yaml"); + final SupportUtil.Pair pair = SupportUtil.loadYaml("src/test/resources/test.yaml"); onset.setClosedLoopControlName(pair.key.getControlLoop().getControlLoopName()); try { // diff --git a/controlloop/common/guard/src/test/java/org/onap/policy/guard/GuardUtilTest.java b/controlloop/common/guard/src/test/java/org/onap/policy/guard/GuardUtilTest.java index 8fc5a83da..1f7002a7d 100644 --- a/controlloop/common/guard/src/test/java/org/onap/policy/guard/GuardUtilTest.java +++ b/controlloop/common/guard/src/test/java/org/onap/policy/guard/GuardUtilTest.java @@ -45,7 +45,7 @@ public class GuardUtilTest { Yaml clYaml = new Yaml(new Constructor(ControlLoopPolicy.class)); String clYamlString = clYaml.dump(clPolicy); - TextFileUtils.putStringAsFile(clYamlString, tempYamlFile); + SupportTextFileUtils.putStringAsFile(clYamlString, tempYamlFile); Pair result = Util.loadYaml(tempYamlFile.getCanonicalPath()); @@ -74,7 +74,7 @@ public class GuardUtilTest { Yaml clYaml = new Yaml(new Constructor(ControlLoopPolicy.class)); String clYamlString = clYaml.dump(clGuardPolicy); - TextFileUtils.putStringAsFile(clYamlString, tempYamlFile); + SupportTextFileUtils.putStringAsFile(clYamlString, tempYamlFile); ControlLoopGuard result = Util.loadYamlGuard(tempYamlFile.getCanonicalPath()); diff --git a/controlloop/common/guard/src/test/java/org/onap/policy/guard/PolicyGuardYamlToXacmlTest.java b/controlloop/common/guard/src/test/java/org/onap/policy/guard/PolicyGuardYamlToXacmlTest.java index 3b517bcc1..dced2889d 100644 --- a/controlloop/common/guard/src/test/java/org/onap/policy/guard/PolicyGuardYamlToXacmlTest.java +++ b/controlloop/common/guard/src/test/java/org/onap/policy/guard/PolicyGuardYamlToXacmlTest.java @@ -86,11 +86,11 @@ public class PolicyGuardYamlToXacmlTest { Yaml clYaml = new Yaml(new Constructor(ControlLoopGuard.class)); String clYamlString = clYaml.dump(clGuard); - TextFileUtils.putStringAsFile(clYamlString, tempYamlFile); + SupportTextFileUtils.putStringAsFile(clYamlString, tempYamlFile); PolicyGuardYamlToXacml.fromYamlToXacml(tempYamlFile.getCanonicalPath(), tempXacmlTemplateFile.getCanonicalPath(), tempXacmlOutputFile.getCanonicalPath()); - String result = TextFileUtils.getTextFileAsString(tempXacmlOutputFile.getCanonicalPath()); + String result = SupportTextFileUtils.getTextFileAsString(tempXacmlOutputFile.getCanonicalPath()); // Assert no mote "${}" are left assertFalse(result.contains("${")); @@ -124,11 +124,11 @@ public class PolicyGuardYamlToXacmlTest { Yaml clYaml = new Yaml(new Constructor(ControlLoopGuard.class)); String clYamlString = clYaml.dump(clGuard); - TextFileUtils.putStringAsFile(clYamlString, tempYamlFile); + SupportTextFileUtils.putStringAsFile(clYamlString, tempYamlFile); PolicyGuardYamlToXacml.fromYamlToXacml(tempYamlFile.getCanonicalPath(), tempXacmlTemplateFile.getCanonicalPath(), tempXacmlOutputFile.getCanonicalPath()); - String result = TextFileUtils.getTextFileAsString(tempXacmlOutputFile.getCanonicalPath()); + String result = SupportTextFileUtils.getTextFileAsString(tempXacmlOutputFile.getCanonicalPath()); // Assert no mote "${}" are left assertFalse(result.contains("${")); @@ -184,11 +184,11 @@ public class PolicyGuardYamlToXacmlTest { Yaml clYaml = new Yaml(new Constructor(ControlLoopGuard.class)); String clYamlString = clYaml.dump(clGuard); - TextFileUtils.putStringAsFile(clYamlString, tempYamlFile); + SupportTextFileUtils.putStringAsFile(clYamlString, tempYamlFile); PolicyGuardYamlToXacml.fromYamlToXacmlBlacklist(tempYamlFile.getCanonicalPath(), tempXacmlTemplateFile.getCanonicalPath(), tempXacmlOutputFile.getCanonicalPath()); - String result = TextFileUtils.getTextFileAsString(tempXacmlOutputFile.getCanonicalPath()); + String result = SupportTextFileUtils.getTextFileAsString(tempXacmlOutputFile.getCanonicalPath()); System.err.println(result); // Assert no mote "${}" are left assertFalse(result.contains("${")); @@ -220,11 +220,11 @@ public class PolicyGuardYamlToXacmlTest { Yaml clYaml = new Yaml(new Constructor(ControlLoopGuard.class)); String clYamlString = clYaml.dump(clGuard); - TextFileUtils.putStringAsFile(clYamlString, tempYamlFile); + SupportTextFileUtils.putStringAsFile(clYamlString, tempYamlFile); PolicyGuardYamlToXacml.fromYamlToXacmlBlacklist(tempYamlFile.getCanonicalPath(), tempXacmlTemplateFile.getCanonicalPath(), tempXacmlOutputFile.getCanonicalPath()); - String result = TextFileUtils.getTextFileAsString(tempXacmlOutputFile.getCanonicalPath()); + String result = SupportTextFileUtils.getTextFileAsString(tempXacmlOutputFile.getCanonicalPath()); System.err.println(result); // Assert no mote "${}" are left assertFalse(result.contains("${")); diff --git a/controlloop/common/guard/src/test/java/org/onap/policy/guard/SupportTextFileUtils.java b/controlloop/common/guard/src/test/java/org/onap/policy/guard/SupportTextFileUtils.java new file mode 100644 index 000000000..03260ada9 --- /dev/null +++ b/controlloop/common/guard/src/test/java/org/onap/policy/guard/SupportTextFileUtils.java @@ -0,0 +1,63 @@ +/*- + * ============LICENSE_START======================================================= + * guard + * ================================================================================ + * Copyright (C) 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.guard; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; + +/** + * The Class TextFileUtils is class that provides useful functions for handling text files. + * Functions to read and wrtie text files to strings and strings are provided. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public abstract class SupportTextFileUtils { + /** + * Method to return the contents of a text file as a string. + * + * @param textFilePath The path to the file as a string + * @return A string containing the contents of the file + * @throws IOException on errors reading text from the file + */ + public static String getTextFileAsString(final String textFilePath) throws IOException { + final File textFile = new File(textFilePath); + final FileInputStream textFileInputStream = new FileInputStream(textFile); + final byte[] textData = new byte[(int) textFile.length()]; + textFileInputStream.read(textData); + textFileInputStream.close(); + return new String(textData); + } + + /** + * Method to write contents of a string to a text file. + * + * @param outString The string to write + * @param textFile The file to write the string to + * @throws IOException on errors reading text from the file + */ + public static void putStringAsFile(final String outString, final File textFile) throws IOException { + final FileOutputStream textFileOutputStream = new FileOutputStream(textFile); + textFileOutputStream.write(outString.getBytes()); + textFileOutputStream.close(); + } +} diff --git a/controlloop/common/guard/src/test/java/org/onap/policy/guard/TextFileUtils.java b/controlloop/common/guard/src/test/java/org/onap/policy/guard/TextFileUtils.java deleted file mode 100644 index 46a2762cc..000000000 --- a/controlloop/common/guard/src/test/java/org/onap/policy/guard/TextFileUtils.java +++ /dev/null @@ -1,63 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * guard - * ================================================================================ - * Copyright (C) 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. - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.guard; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; - -/** - * The Class TextFileUtils is class that provides useful functions for handling text files. - * Functions to read and wrtie text files to strings and strings are provided. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public abstract class TextFileUtils { - /** - * Method to return the contents of a text file as a string. - * - * @param textFilePath The path to the file as a string - * @return A string containing the contents of the file - * @throws IOException on errors reading text from the file - */ - public static String getTextFileAsString(final String textFilePath) throws IOException { - final File textFile = new File(textFilePath); - final FileInputStream textFileInputStream = new FileInputStream(textFile); - final byte[] textData = new byte[(int) textFile.length()]; - textFileInputStream.read(textData); - textFileInputStream.close(); - return new String(textData); - } - - /** - * Method to write contents of a string to a text file. - * - * @param outString The string to write - * @param textFile The file to write the string to - * @throws IOException on errors reading text from the file - */ - public static void putStringAsFile(final String outString, final File textFile) throws IOException { - final FileOutputStream textFileOutputStream = new FileOutputStream(textFile); - textFileOutputStream.write(outString.getBytes()); - textFileOutputStream.close(); - } -} -- cgit 1.2.3-korg