Sonar fix too many method param
[dmaap/datarouter.git] / datarouter-node / src / test / java / org / onap / dmaap / datarouter / node / DeliveryTest.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 org.apache.commons.lang3.reflect.FieldUtils;
26 import org.junit.After;
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.junit.runner.RunWith;
30 import org.mockito.Mock;
31 import org.powermock.api.mockito.PowerMockito;
32 import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
33 import org.powermock.modules.junit4.PowerMockRunner;
34
35 import java.io.File;
36 import java.io.IOException;
37 import java.util.Hashtable;
38
39 import static org.mockito.Mockito.mock;
40 import static org.mockito.Mockito.times;
41 import static org.mockito.Mockito.verify;
42
43 @RunWith(PowerMockRunner.class)
44 @SuppressStaticInitializationFor("org.onap.dmaap.datarouter.node.NodeConfigManager")
45 public class DeliveryTest {
46
47   @Mock
48   private DeliveryQueue deliveryQueue;
49
50   private File nDir = new File("tmp/n");
51   private File sDir = new File("tmp/s");
52
53   @Before
54   public void setUp() throws IOException {
55     nDir.mkdirs();
56     sDir.mkdirs();
57     File newNDir = new File("tmp/n/0");
58     newNDir.mkdirs();
59     File newNFile = new File("tmp/n/0/testN.txt");
60     newNFile.createNewFile();
61     File newSDir = new File("tmp/s/0/1");
62     newSDir.mkdirs();
63     File newSpoolFile = new File("tmp/s/0/1/testSpool.txt");
64     newSpoolFile.createNewFile();
65   }
66
67   @Test
68   public void Validate_Reset_Queue_Calls_Reset_Queue_On_Delivery_Queue_Object() throws IllegalAccessException {
69     NodeConfigManager config = mockNodeConfigManager();
70     Delivery delivery = new Delivery(config);
71     Hashtable<String, DeliveryQueue> dqs = new Hashtable<>();
72     dqs.put("spool/s/0/1", deliveryQueue);
73     FieldUtils.writeDeclaredField(delivery, "dqs", dqs, true);
74     delivery.resetQueue("spool/s/0/1");
75     verify(deliveryQueue, times(1)).resetQueue();
76   }
77
78   @After
79   public void tearDown() {
80     nDir.delete();
81     sDir.delete();
82     File tmpDir = new File("tmp");
83     tmpDir.delete();
84   }
85
86   private NodeConfigManager mockNodeConfigManager() {
87     PowerMockito.mockStatic(NodeConfigManager.class);
88     NodeConfigManager config = mock(NodeConfigManager.class);
89     PowerMockito.when(config.isConfigured()).thenReturn(true);
90     PowerMockito.when(config.getAllDests()).thenReturn(createDestInfoObjects());
91     PowerMockito.when(config.getFreeDiskStart()).thenReturn(0.49);
92     PowerMockito.when(config.getFreeDiskStop()).thenReturn(0.5);
93     PowerMockito.when(config.getDeliveryThreads()).thenReturn(0);
94     PowerMockito.when(config.getSpoolBase()).thenReturn("tmp");
95     return config;
96   }
97
98   private DestInfo[] createDestInfoObjects() {
99     DestInfo[] destInfos = new DestInfo[1];
100     DestInfo destInfo = new DestInfo.DestInfoBuilder().setName("node.datarouternew.com").setSpool("spool/s/0/1").setSubid("1")
101         .setLogdata("logs/").setUrl("/subs/1").setAuthuser("user1").setAuthentication("Basic dXNlcjE6cGFzc3dvcmQx")
102         .setMetaonly(false).setUse100(true).setPrivilegedSubscriber(false).setFollowRedirects(false)
103         .setDecompress(false).createDestInfo();
104     destInfos[0] = destInfo;
105     return destInfos;
106   }
107 }