2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.mso.adapter_utils.tests;
24 import static org.junit.Assert.assertNull;
25 import static org.junit.Assert.assertTrue;
27 import java.io.BufferedReader;
29 import java.io.FileInputStream;
30 import java.io.IOException;
31 import java.io.InputStreamReader;
32 import java.io.PrintWriter;
34 import org.junit.BeforeClass;
35 import org.junit.Test;
37 import org.openecomp.mso.logger.MsoAlarmLogger;
38 import org.openecomp.mso.properties.MsoJavaProperties;
39 import org.openecomp.mso.properties.MsoPropertiesException;
40 import org.openecomp.mso.properties.MsoPropertiesFactory;
43 * This junit test very roughly the alarm logger
46 public class MsoAlarmLoggerTest {
48 public static MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory();
49 public static MsoAlarmLogger msoAlarmLogger;
52 public static final void createObjects() throws MsoPropertiesException
55 File outputFile = new File ("target/alarm-test.log");
56 if (outputFile.exists()) {
59 msoAlarmLogger = new MsoAlarmLogger("target/alarm-test.log");
63 public void testAlarmConfig() throws MsoPropertiesException, IOException {
65 msoAlarmLogger.sendAlarm("test", 0, "detail message");
67 FileInputStream inputStream = new FileInputStream("target/alarm-test.log");
68 BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
70 String line = reader.readLine();
71 String[] splitLine = line.split("\\|");
72 assertTrue(splitLine.length==4);
73 assertTrue("test".equals(splitLine[1]));
74 assertTrue("0".equals(splitLine[2]));
75 assertTrue("detail message".equals(splitLine[3]));
77 line = reader.readLine();
82 // Reset the file for others tests
83 PrintWriter writer = new PrintWriter(new File("target/alarm-test.log"));
90 public void testAlarm() throws IOException {
92 msoAlarmLogger.sendAlarm("test", 0, "detail message");
93 msoAlarmLogger.sendAlarm("test2", 1, "detail message2");
94 msoAlarmLogger.sendAlarm("test3", 2, "detail message3");
96 FileInputStream inputStream = new FileInputStream("target/alarm-test.log");
97 BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
99 String line = reader.readLine();
100 String[] splitLine = line.split("\\|");
101 assertTrue(splitLine.length==4);
102 assertTrue("test".equals(splitLine[1]));
103 assertTrue("0".equals(splitLine[2]));
104 assertTrue("detail message".equals(splitLine[3]));
106 line = reader.readLine();
107 splitLine = line.split("\\|");
108 assertTrue(splitLine.length==4);
109 assertTrue("test2".equals(splitLine[1]));
110 assertTrue("1".equals(splitLine[2]));
111 assertTrue("detail message2".equals(splitLine[3]));
113 line = reader.readLine();
114 splitLine = line.split("\\|");
115 assertTrue(splitLine.length==4);
116 assertTrue("test3".equals(splitLine[1]));
117 assertTrue("2".equals(splitLine[2]));
118 assertTrue("detail message3".equals(splitLine[3]));
120 line = reader.readLine();
125 // Reset the file for others tests
126 PrintWriter writer = new PrintWriter(new File("target/alarm-test.log"));