summaryrefslogtreecommitdiffstats
path: root/datacollector/src/test/java/org/onap/rapp/datacollector/TestHelpers.java
blob: bd13330f95519a8841fc60efbe4a7f9ccd9a16b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package org.onap.rapp.datacollector;

import static java.util.Objects.nonNull;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.stream.Collectors;

import lombok.experimental.UtilityClass;

@UtilityClass
public class TestHelpers {

    /**
     * Get empty string event
     *
     * @return empty event, without header and measurement data
     */
    public static String getEmptyEvent() {
        return "{\"event\":{}}";
    }

    /**
     * Get Event as string from file
     *
     * @param fileName location of test file
     * @return Event file as string
     */
    public static String getTestEventFromFile(String fileName) {
        InputStream in = TestHelpers.class.getResourceAsStream(fileName);
        if (nonNull(in)) {
            try (in) {
                BufferedReader inr = new BufferedReader(new InputStreamReader(in));
                return inr.lines().collect(Collectors.joining(" "));
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return "";
    }

}