1 /*******************************************************************************
2 * ============LICENSE_START==================================================
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
11 * * http://www.apache.org/licenses/LICENSE-2.0
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====================================================
20 * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 ******************************************************************************/
23 package org.onap.dmaap.datarouter.node;
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;
36 import java.io.IOException;
37 import java.util.Hashtable;
39 import static org.mockito.Mockito.mock;
40 import static org.mockito.Mockito.times;
41 import static org.mockito.Mockito.verify;
43 @RunWith(PowerMockRunner.class)
44 @SuppressStaticInitializationFor("org.onap.dmaap.datarouter.node.NodeConfigManager")
45 public class DeliveryTest {
48 private DeliveryQueue deliveryQueue;
50 private File nDir = new File("tmp/n");
51 private File sDir = new File("tmp/s");
54 public void setUp() throws IOException {
57 File newNDir = new File("tmp/n/0");
59 File newNFile = new File("tmp/n/0/testN.txt");
60 newNFile.createNewFile();
61 File newSDir = new File("tmp/s/0/1");
63 File newSpoolFile = new File("tmp/s/0/1/testSpool.txt");
64 newSpoolFile.createNewFile();
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();
79 public void tearDown() {
82 File tmpDir = new File("tmp");
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");
98 private DestInfo[] createDestInfoObjects() {
99 DestInfo[] destInfos = new DestInfo[1];
100 DestInfo destInfo = new DestInfo("node.datarouternew.com", "spool/s/0/1", "1", "logs/", "/subs/1", "user1", "Basic dXNlcjE6cGFzc3dvcmQx", false, true, false, false);
101 destInfos[0] = destInfo;