2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.dmaap.datarouter.node;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertNull;
26 import static org.junit.Assert.assertTrue;
29 import java.io.IOException;
30 import java.util.Timer;
31 import org.apache.commons.io.FileUtils;
32 import org.apache.commons.lang3.reflect.FieldUtils;
33 import org.junit.After;
34 import org.junit.Before;
35 import org.junit.Test;
36 import org.junit.runner.RunWith;
37 import org.mockito.Mock;
38 import org.onap.dmaap.datarouter.node.LogManager.Uploader;
39 import org.powermock.api.mockito.PowerMockito;
40 import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
41 import org.powermock.modules.junit4.PowerMockRunner;
43 @RunWith(PowerMockRunner.class)
44 @SuppressStaticInitializationFor({"org.onap.dmaap.datarouter.node.NodeConfigManager"})
45 public class LogManagerTest {
48 private NodeConfigManager config;
50 private LogManager logManager;
53 public void setUp() throws IllegalAccessException {
54 mockNodeConfigManager();
55 FieldUtils.writeDeclaredStaticField(StatusLog.class, "config", config, true);
56 logManager = new LogManager(config);
60 public void tearDown() throws IOException {
61 File spoolDir = new File(System.getProperty("user.dir") + "/src/test/resources/.spool");
62 FileUtils.deleteDirectory(spoolDir);
66 public void Verify_LogManager_Attempts_To_Deliver_Log_Files_To_Prov() {
70 } catch (Exception e) {
71 System.out.println("Exception caught: " + e.getMessage());
73 File file = new File(System.getProperty("user.dir") + "/src/test/resources/.spool/.lastqueued");
74 assertTrue(file.isFile());
78 public void Validate_Uploader_Getters() {
79 Uploader worker = logManager.getWorker();
80 assertEquals(10000L, worker.getInitFailureTimer());
81 assertEquals(600000L, worker.getWaitForFileProcessFailureTimer());
82 assertEquals(2.0, worker.getFailureBackoff(), 0.0);
83 assertEquals(150000L, worker.getMaxFailureTimer());
84 assertEquals(604800000L, worker.getExpirationTimer());
85 assertEquals(10000, worker.getFairFileLimit());
86 assertEquals(86400000, worker.getFairTimeLimit());
87 assertEquals("https://dmaap-dr-prov:8443/internal/logs",
88 worker.getDestURL(new DestInfoBuilder().createDestInfo(), "String"));
89 assertFalse(worker.handleRedirection(new DestInfoBuilder().createDestInfo(), "", ""));
90 assertFalse(worker.isFollowRedirects());
91 assertNull(worker.getFeedId(""));
94 private void mockNodeConfigManager() {
95 PowerMockito.when(config.getLogDir()).thenReturn(System.getProperty("user.dir") + "/src/test/resources");
96 PowerMockito.when(config.getTimer()).thenReturn(new Timer("Node Configuration Timer", true));
97 PowerMockito.when(config.getEventLogPrefix())
98 .thenReturn(System.getProperty("user.dir") + "/src/test/resources/events");
99 PowerMockito.when(config.getEventLogSuffix()).thenReturn(".log");
100 PowerMockito.when(config.getLogRetention()).thenReturn(94608000000L);
101 PowerMockito.when(config.getEventLogInterval()).thenReturn("30s");
102 PowerMockito.when(config.getPublishId()).thenReturn("123456789.dmaap-dr-node");
103 PowerMockito.when(config.getEventLogUrl()).thenReturn("https://dmaap-dr-prov:8443/internal/logs");