[DMaaP DR] JKD 11 migration
[dmaap/datarouter.git] / datarouter-node / src / test / java / org / onap / dmaap / datarouter / node / StatusLogTest.java
1 /*******************************************************************************
2  * ============LICENSE_START==================================================
3  * * org.onap.dmaap
4  * * ===========================================================================
5  * * Copyright © 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
10  * *
11  *  *      http://www.apache.org/licenses/LICENSE-2.0
12  * *
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====================================================
19  * *
20  * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
21  * *
22  ******************************************************************************/
23 package org.onap.dmaap.datarouter.node;
24
25 import static org.mockito.Mockito.mock;
26 import static org.mockito.Mockito.when;
27
28 import org.junit.Assert;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 import org.powermock.api.mockito.PowerMockito;
33 import org.powermock.core.classloader.annotations.PowerMockIgnore;
34 import org.powermock.core.classloader.annotations.PrepareForTest;
35 import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
36 import org.powermock.modules.junit4.PowerMockRunner;
37
38 @RunWith(PowerMockRunner.class)
39 @SuppressStaticInitializationFor("org.onap.dmaap.datarouter.node.NodeConfigManager")
40 @PrepareForTest(StatusLog.class)
41 @PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*"})
42 public class StatusLogTest {
43
44     @Before
45     public void setUp() {
46         PowerMockito.mockStatic(NodeConfigManager.class);
47         NodeConfigManager config = mock(NodeConfigManager.class);
48         when(config.getEventLogInterval()).thenReturn("5m");
49         when(config.getEventLogPrefix()).thenReturn("logFile");
50         when(config.getEventLogSuffix()).thenReturn(".log");
51         PowerMockito.when(NodeConfigManager.getInstance()).thenReturn(config);
52         PowerMockito.mockStatic(System.class);
53         PowerMockito.when(System.currentTimeMillis()).thenReturn(1535367126000L);
54     }
55
56     @Test
57     public void Given_Time_Interval_Parse_Interval_Returns_Correct_Value() {
58         long parsedTime = StatusLog.parseInterval("2h24m35s", 1);
59         Assert.assertEquals(8640000, parsedTime);
60     }
61
62     @Test
63     public void Given_Time_Interval_In_Seconds_Parse_Interval_Returns_Correct_Value() {
64         long parsedTime = StatusLog.parseInterval("56784", 1);
65         Assert.assertEquals(43200000, parsedTime);
66     }
67
68     @Test
69     public void Validate_Get_Cur_Log_File_Returns_Correct_File_Name() {
70         String logFile = StatusLog.getCurLogFile();
71         Assert.assertTrue(logFile.matches("logFile-201808271[0-1]50.log"));
72     }
73 }