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 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;
35 @RunWith(MockitoJUnitRunner.class)
36 public class TcaPolicyDeleteDelegateTest {
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";
49 private Exchange camelExchange;
52 private PolicyClient policyClient;
55 private TcaPolicyDeleteDelegate tcaPolicyDeleteDelegate;
58 public void shouldExecuteSuccessfully() {
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);
64 Mockito.when(policyClient.deleteMicrosService(Mockito.any())).thenReturn(MESSAGE);
67 tcaPolicyDeleteDelegate.execute(camelExchange);
70 Mockito.verify(camelExchange).setProperty(PROPERTY_NAME, MESSAGE.getBytes());
74 public void shouldExecuteTcaNotFound() {
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);
81 tcaPolicyDeleteDelegate.execute(camelExchange);
84 Mockito.verify(policyClient, Mockito.never()).deleteMicrosService(Mockito.any());
85 Mockito.verify(camelExchange, Mockito.never()).setProperty(Mockito.any(), Mockito.any());
88 @Test(expected = ModelBpmnException.class)
89 public void shouldThrowModelBpmnException() {
91 Mockito.when(camelExchange.getProperty(MODEL_BPMN_KEY)).thenReturn(NOT_JSON);
92 Mockito.when(camelExchange.getProperty(TEST_KEY)).thenReturn(false);
95 tcaPolicyDeleteDelegate.execute(camelExchange);
98 @Test(expected = NullPointerException.class)
99 public void shouldThrowNullPointerException() {
101 tcaPolicyDeleteDelegate.execute(camelExchange);