Remove dead code
[clamp.git] / src / test / java / org / onap / clamp / clds / client / GuardPolicyDeleteDelegateTest.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 static org.mockito.Mockito.any;
26 import static org.mockito.Mockito.eq;
27 import static org.mockito.Mockito.never;
28 import static org.mockito.Mockito.verify;
29 import static org.mockito.Mockito.when;
30
31 import org.apache.camel.Exchange;
32 import org.junit.Test;
33 import org.junit.runner.RunWith;
34 import org.mockito.InjectMocks;
35 import org.mockito.Mock;
36 import org.mockito.runners.MockitoJUnitRunner;
37 import org.onap.clamp.clds.client.req.policy.PolicyClient;
38 import org.onap.clamp.clds.exception.ModelBpmnException;
39
40 @RunWith(MockitoJUnitRunner.class)
41 public class GuardPolicyDeleteDelegateTest {
42
43     private static final String MODEL_BPMN_KEY = "modelBpmnProp";
44     private static final String MODEL_PROP_KEY = "modelProp";
45     private static final String TEST_KEY = "isTest";
46     private static final String EVENT_ACTION_KEY = "eventAction";
47
48     private static final String POLICY_ID_FROM_JSON = "{policy:[{id:Policy_7,from:''}]}";
49     private static final String TCA_ID_FROM_JSON = "{tca:[{id:'',from:''}]}";
50     private static final String ID_JSON = "{Policy_7:{r:["
51             + "{name:pid,value:pid334},"
52             + "{name:timeout,value:50},"
53             + "{name:policyType,value:pt},"
54             + "{policyConfigurations:[["
55             + "{name:_id,value:ret345},"
56             + "{name:recipe,value:make},"
57             + "{name:maxRetries,value:5},"
58             + "{name:retryTimeLimit,value:100},"
59             + "{name:enableGuardPolicy,value:on}]]}]}}";
60     private static final String NOT_JSON = "not json";
61     private static final String EVENT_ACTION_VALUE = "action";
62
63     @Mock
64     private Exchange exchange;
65
66     @Mock
67     private PolicyClient policyClient;
68
69     @InjectMocks
70     private GuardPolicyDeleteDelegate guardPolicyDeleteDelegate;
71
72     @Test
73     public void shouldExecuteSuccessfully() {
74         // given
75         when(exchange.getProperty(eq(MODEL_BPMN_KEY))).thenReturn(POLICY_ID_FROM_JSON);
76         when(exchange.getProperty(eq(MODEL_PROP_KEY))).thenReturn(ID_JSON);
77         when(exchange.getProperty(eq(TEST_KEY))).thenReturn(false);
78         when(exchange.getProperty(eq(EVENT_ACTION_KEY))).thenReturn(EVENT_ACTION_VALUE);
79
80         // when
81         guardPolicyDeleteDelegate.execute(exchange);
82
83         // then
84         verify(policyClient).deleteGuard(any());
85     }
86
87     @Test
88     public void shouldExecutePolicyNotFound() {
89         // given
90         when(exchange.getProperty(eq(MODEL_BPMN_KEY))).thenReturn(TCA_ID_FROM_JSON);
91         when(exchange.getProperty(eq(MODEL_PROP_KEY))).thenReturn(ID_JSON);
92         when(exchange.getProperty(eq(TEST_KEY))).thenReturn(false);
93         when(exchange.getProperty(eq(EVENT_ACTION_KEY))).thenReturn(EVENT_ACTION_VALUE);
94
95         // when
96         guardPolicyDeleteDelegate.execute(exchange);
97
98         // then
99         verify(policyClient, never()).deleteGuard(any());
100     }
101
102     @Test(expected = ModelBpmnException.class)
103     public void shouldThrowModelBpmnException() {
104         // given
105         when(exchange.getProperty(eq(MODEL_BPMN_KEY))).thenReturn(NOT_JSON);
106         when(exchange.getProperty(eq(TEST_KEY))).thenReturn(false);
107
108         // when
109         guardPolicyDeleteDelegate.execute(exchange);
110     }
111
112     @Test(expected = NullPointerException.class)
113     public void shouldThrowNullPointerException() {
114         // when
115         guardPolicyDeleteDelegate.execute(exchange);
116     }
117 }