Add test cases for 65% branch coverage
[dmaap/datarouter.git] / datarouter-node / src / test / java / org / onap / dmaap / datarouter / node / DeliveryTaskTest.java
1 /*
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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.dmaap.datarouter.node;
22
23 import static org.mockito.Mockito.mock;
24 import static org.mockito.Mockito.when;
25
26 import org.junit.Assert;
27 import org.junit.Test;
28 import org.mockito.Mock;
29
30 public class DeliveryTaskTest {
31
32     @Mock
33     private DeliveryQueue deliveryQueue;
34
35     @Test
36     public void Validate_Delivery_Task_Equals() {
37         DestInfo destInfo = getDestInfo();
38         deliveryQueue = mockDelvieryQueue(destInfo);
39         DeliveryTask task = new DeliveryTask(deliveryQueue, "123456789.test-dr-datafile");
40         DeliveryTask task2 = new DeliveryTask(deliveryQueue, "123456789.test-dr-datafile");
41         Assert.assertEquals(task, task2);
42         Assert.assertEquals(task.hashCode(), task2.hashCode());
43         Assert.assertEquals(task.toString(), task2.toString());
44         Assert.assertEquals(0, task.compareTo(task2));
45     }
46
47     @Test
48     public void Validate_Delivery_Tasks_Not_Equal() {
49         DestInfo destInfo = getDestInfo();
50         deliveryQueue = mockDelvieryQueue(destInfo);
51         DeliveryTask task = new DeliveryTask(deliveryQueue, "123456789.test-dr-node");
52         DeliveryTask task2 = new DeliveryTask(deliveryQueue, "123456789.test-dr-datafile");
53         Assert.assertNotEquals(task, task2);
54         Assert.assertNotEquals(0, task.compareTo(task2));
55     }
56
57     private DestInfo getDestInfo() {
58         return new DestInfoBuilder().setName("n:" + "dmaap-dr-node")
59                 .setSpool(System.getProperty("user.dir") + "/src/test/resources")
60                 .setSubid("1").setLogdata("n2n-dmaap-dr-node").setUrl("https://dmaap-dr-node:8443/internal/publish")
61                 .setAuthuser("dmaap-dr-node").setAuthentication("Auth").setMetaonly(false).setUse100(true)
62                 .setPrivilegedSubscriber(false).setFollowRedirects(false).setDecompress(false).createDestInfo();
63     }
64
65     private DeliveryQueue mockDelvieryQueue(DestInfo destInfo) {
66         DeliveryQueue mockedDeliveryQueue = mock(DeliveryQueue.class);
67         when(mockedDeliveryQueue.getDestinationInfo()).thenReturn(destInfo);
68         return mockedDeliveryQueue;
69     }
70
71 }