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