Add test cases for 65% branch coverage
[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.PrepareForTest;
34 import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
35 import org.powermock.modules.junit4.PowerMockRunner;
36
37 @RunWith(PowerMockRunner.class)
38 @SuppressStaticInitializationFor("org.onap.dmaap.datarouter.node.NodeConfigManager")
39 @PrepareForTest(StatusLog.class)
40 public class StatusLogTest {
41
42     @Before
43     public void setUp() {
44         PowerMockito.mockStatic(NodeConfigManager.class);
45         NodeConfigManager config = mock(NodeConfigManager.class);
46         when(config.getEventLogInterval()).thenReturn("5m");
47         when(config.getEventLogPrefix()).thenReturn("logFile");
48         when(config.getEventLogSuffix()).thenReturn(".log");
49         PowerMockito.when(NodeConfigManager.getInstance()).thenReturn(config);
50         PowerMockito.mockStatic(System.class);
51         PowerMockito.when(System.currentTimeMillis()).thenReturn(1535367126000L);
52     }
53
54     @Test
55     public void Given_Time_Interval_Parse_Interval_Returns_Correct_Value() {
56         long parsedTime = StatusLog.parseInterval("2h24m35s", 1);
57         Assert.assertEquals(8640000, parsedTime);
58     }
59
60     @Test
61     public void Given_Time_Interval_In_Seconds_Parse_Interval_Returns_Correct_Value() {
62         long parsedTime = StatusLog.parseInterval("56784", 1);
63         Assert.assertEquals(43200000, parsedTime);
64     }
65
66     @Test
67     public void Validate_Get_Cur_Log_File_Returns_Correct_File_Name() {
68         String logFile = StatusLog.getCurLogFile();
69         Assert.assertTrue(logFile.matches("logFile-201808271[0-1]50.log"));
70     }
71 }