Added more unit tests to reach the minimum threshold of 65 % coverage
[clamp.git] / src / test / java / org / onap / clamp / clds / client / TcaPolicyDeleteDelegateTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2019 Samsung. 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  *
21  */
22
23 package org.onap.clamp.clds.client;
24
25 import org.apache.camel.Exchange;
26 import org.junit.Test;
27 import org.junit.runner.RunWith;
28 import org.mockito.InjectMocks;
29 import org.mockito.Mock;
30 import org.mockito.Mockito;
31 import org.mockito.runners.MockitoJUnitRunner;
32 import org.onap.clamp.clds.client.req.policy.PolicyClient;
33 import org.onap.clamp.clds.exception.ModelBpmnException;
34
35 @RunWith(MockitoJUnitRunner.class)
36 public class TcaPolicyDeleteDelegateTest {
37
38     private static final String TCA_ID_FROM_JSON = "{\"tca\":[{\"id\":\"\",\"from\":\"\"}]}";
39     private static final String HOLMES_ID_FROM_JSON = "{\"holmes\":[{\"id\":\"\",\"from\":\"\"}]}";
40     private static final String ID_JSON = "{\"id\":\"\"}";
41     private static final String NOT_JSON = "not json";
42     private static final String MODEL_BPMN_KEY = "modelBpmnProp";
43     private static final String MODEL_PROP_KEY = "modelProp";
44     private static final String TEST_KEY = "isTest";
45     private static final String PROPERTY_NAME = "tcaPolicyDeleteResponseMessage";
46     private static final String MESSAGE = "message";
47
48     @Mock
49     private Exchange camelExchange;
50
51     @Mock
52     private PolicyClient policyClient;
53
54     @InjectMocks
55     private TcaPolicyDeleteDelegate tcaPolicyDeleteDelegate;
56
57     @Test
58     public void shouldExecuteSuccessfully() {
59         //given
60         Mockito.when(camelExchange.getProperty(MODEL_BPMN_KEY)).thenReturn(TCA_ID_FROM_JSON);
61         Mockito.when(camelExchange.getProperty(MODEL_PROP_KEY)).thenReturn(ID_JSON);
62         Mockito.when(camelExchange.getProperty(TEST_KEY)).thenReturn(false);
63
64         Mockito.when(policyClient.deleteMicrosService(Mockito.any())).thenReturn(MESSAGE);
65
66         //when
67         tcaPolicyDeleteDelegate.execute(camelExchange);
68
69         //then
70         Mockito.verify(camelExchange).setProperty(PROPERTY_NAME, MESSAGE.getBytes());
71     }
72
73     @Test
74     public void shouldExecuteTcaNotFound() {
75         //given
76         Mockito.when(camelExchange.getProperty(MODEL_BPMN_KEY)).thenReturn(HOLMES_ID_FROM_JSON);
77         Mockito.when(camelExchange.getProperty(MODEL_PROP_KEY)).thenReturn(ID_JSON);
78         Mockito.when(camelExchange.getProperty(TEST_KEY)).thenReturn(false);
79
80         //when
81         tcaPolicyDeleteDelegate.execute(camelExchange);
82
83         //then
84         Mockito.verify(policyClient, Mockito.never()).deleteMicrosService(Mockito.any());
85         Mockito.verify(camelExchange, Mockito.never()).setProperty(Mockito.any(), Mockito.any());
86     }
87
88     @Test(expected = ModelBpmnException.class)
89     public void shouldThrowModelBpmnException() {
90         //given
91         Mockito.when(camelExchange.getProperty(MODEL_BPMN_KEY)).thenReturn(NOT_JSON);
92         Mockito.when(camelExchange.getProperty(TEST_KEY)).thenReturn(false);
93
94         //when
95         tcaPolicyDeleteDelegate.execute(camelExchange);
96     }
97
98     @Test(expected = NullPointerException.class)
99     public void shouldThrowNullPointerException() {
100         //when
101         tcaPolicyDeleteDelegate.execute(camelExchange);
102     }
103 }