Initial search service commit
[aai/search-data-service.git] / src / test / java / org / openecomp / sa / rest / TestUtils.java
1 /**
2  * ============LICENSE_START=======================================================
3  * Search Data Service
4  * ================================================================================
5  * Copyright © 2017 AT&T Intellectual Property.
6  * Copyright © 2017 Amdocs
7  * All rights reserved.
8  * ================================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License ati
12  *
13  *    http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=========================================================
21  *
22  * ECOMP and OpenECOMP are trademarks
23  * and service marks of AT&T Intellectual Property.
24  */
25 package org.openecomp.sa.rest;
26
27 import static org.junit.Assert.fail;
28
29 import java.io.BufferedReader;
30 import java.io.File;
31 import java.io.FileReader;
32 import java.io.IOException;
33
34 public class TestUtils {
35
36   /**
37    * This helper method reads the contents of a file into a
38    * simple string.
39    *
40    * @param aFile - The file to be imported.
41    *
42    * @return - The file contents expressed as a simple string.
43    *
44    * @throws IOException
45    */
46   public static String readFileToString(File aFile) throws IOException {
47
48     BufferedReader br = new BufferedReader(new FileReader(aFile));
49     try {
50       StringBuilder sb = new StringBuilder();
51       String line = br.readLine();
52
53       while (line != null) {
54         sb.append(line);
55         line = br.readLine();
56       }
57
58       return sb.toString().replaceAll("\\s+", "");
59     } finally {
60       try {
61         br.close();
62       } catch (IOException e) {
63         fail("Unexpected IOException: " + e.getMessage());
64       }
65     }
66   }
67 }