2 * ============LICENSE_START=======================================================
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
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============================================
19 * ===================================================================
23 package org.onap.clamp.clds.client;
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;
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;
40 @RunWith(MockitoJUnitRunner.class)
41 public class HolmesPolicyDeleteDelegateTest {
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";
47 private static final String HOLMES_ID_FROM_JSON = "{\"holmes\":[{\"id\":\"\",\"from\":\"\"}]}";
48 private static final String TCA_ID_FROM_JSON = "{\"tca\":[{\"id\":\"\",\"from\":\"\"}]}";
49 private static final String ID_JSON = "{\"id\":\"\"}";
50 private static final String NOT_JSON = "not json";
53 private Exchange exchange;
56 private PolicyClient policyClient;
59 private HolmesPolicyDeleteDelegate holmesPolicyDeleteDelegate;
62 public void shouldExecuteSuccessfully() {
64 when(exchange.getProperty(eq(MODEL_BPMN_KEY))).thenReturn(HOLMES_ID_FROM_JSON);
65 when(exchange.getProperty(eq(MODEL_PROP_KEY))).thenReturn(ID_JSON);
66 when(exchange.getProperty(eq(TEST_KEY))).thenReturn(false);
69 holmesPolicyDeleteDelegate.execute(exchange);
72 verify(policyClient).deleteBasePolicy(any());
76 public void shouldExecuteHolmesNotFound() {
78 when(exchange.getProperty(eq(MODEL_BPMN_KEY))).thenReturn(TCA_ID_FROM_JSON);
79 when(exchange.getProperty(eq(MODEL_PROP_KEY))).thenReturn(ID_JSON);
80 when(exchange.getProperty(eq(TEST_KEY))).thenReturn(false);
83 holmesPolicyDeleteDelegate.execute(exchange);
86 verify(policyClient, never()).deleteBasePolicy(any());
89 @Test(expected = ModelBpmnException.class)
90 public void shouldThrowModelBpmnException() {
92 when(exchange.getProperty(eq(MODEL_BPMN_KEY))).thenReturn(NOT_JSON);
93 when(exchange.getProperty(eq(TEST_KEY))).thenReturn(false);
96 holmesPolicyDeleteDelegate.execute(exchange);
99 @Test(expected = NullPointerException.class)
100 public void shouldThrowNullPointerException() {
102 holmesPolicyDeleteDelegate.execute(exchange);