From 8640a6e4b2d50cf2068207b1ddec965c07cec3aa Mon Sep 17 00:00:00 2001 From: liamfallon Date: Thu, 14 Mar 2019 14:24:14 +0000 Subject: Add support for TOSCA JSON Parsing Added a getter to allow the Gson object to be retrieved from a GSON message body handler, useful for testing. Moved the TextFileUtils utility class from APEX utilites to policy common utils Issue-ID: POLICY-1195 Change-Id: I7c8074e8177a90b292c6dfd6e7f0d352063818e7 Signed-off-by: liamfallon --- .../common/utils/resources/TextFileUtilsTest.java | 53 ++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 utils/src/test/java/org/onap/policy/common/utils/resources/TextFileUtilsTest.java (limited to 'utils/src/test/java') diff --git a/utils/src/test/java/org/onap/policy/common/utils/resources/TextFileUtilsTest.java b/utils/src/test/java/org/onap/policy/common/utils/resources/TextFileUtilsTest.java new file mode 100644 index 00000000..7f246ab2 --- /dev/null +++ b/utils/src/test/java/org/onap/policy/common/utils/resources/TextFileUtilsTest.java @@ -0,0 +1,53 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 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.common.utils.resources; + +import static org.junit.Assert.assertEquals; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; + +import org.junit.Test; + +/** + * Test text file utilities. + * @author Liam Fallon (liam.fallon@est.tech) + */ +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); + + } +} -- cgit 1.2.3-korg