2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. 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=========================================================
21 package org.onap.so.bpmn.infrastructure.pnf.delegate;
23 import static org.mockito.ArgumentMatchers.eq;
24 import static org.mockito.Mockito.mock;
25 import static org.mockito.Mockito.verify;
26 import static org.mockito.Mockito.when;
27 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.CORRELATION_ID;
28 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.TIMEOUT_FOR_NOTIFICATION;
30 import org.camunda.bpm.engine.delegate.BpmnError;
31 import org.camunda.bpm.engine.delegate.DelegateExecution;
32 import org.junit.Rule;
33 import org.junit.Test;
34 import org.junit.rules.ExpectedException;
36 public class PnfCheckInputsTest {
38 private static final String DEFAULT_TIMEOUT = "P1D";
41 public ExpectedException expectedException = ExpectedException.none();
43 private DelegateExecution mockDelegateExecution() {
44 new PnfCheckInputs(DEFAULT_TIMEOUT);
45 DelegateExecution delegateExecution = mock(DelegateExecution.class);
46 when(delegateExecution.getVariable("testProcessKey")).thenReturn("testProcessKeyValue");
47 return delegateExecution;
51 public void shouldThrowException_whenPnfIdNotSet() {
53 PnfCheckInputs testedObject = new PnfCheckInputs(DEFAULT_TIMEOUT);
54 DelegateExecution delegateExecution = mockDelegateExecution();
56 expectedException.expect(BpmnError.class);
57 testedObject.execute(delegateExecution);
61 public void shouldThrowException_whenPnfIdIsEmptyString() throws Exception {
63 PnfCheckInputs testedObject = new PnfCheckInputs(DEFAULT_TIMEOUT);
64 DelegateExecution delegateExecution = mockDelegateExecution();
65 when(delegateExecution.getVariable(CORRELATION_ID)).thenReturn("");
67 expectedException.expect(BpmnError.class);
68 testedObject.execute(delegateExecution);
71 private DelegateExecution mockDelegateExecutionWithCorrelationId() {
72 new PnfCheckInputs(DEFAULT_TIMEOUT);
73 DelegateExecution delegateExecution = mockDelegateExecution();
74 when(delegateExecution.getVariable(CORRELATION_ID)).thenReturn("testCorrelationId");
75 return delegateExecution;
79 public void shouldThrowException_whenTimeoutIsNotSetAndDefaultIsNotDefined() {
81 PnfCheckInputs testedObject = new PnfCheckInputs(null);
82 DelegateExecution delegateExecution = mockDelegateExecutionWithCorrelationId();
84 expectedException.expect(BpmnError.class);
85 testedObject.execute(delegateExecution);
89 public void shouldThrowException_whenTimeoutIsEmptyStringAndDefaultIsNotDefined() throws Exception {
91 PnfCheckInputs testedObject = new PnfCheckInputs(null);
92 DelegateExecution delegateExecution = mockDelegateExecutionWithCorrelationId();
93 when(delegateExecution.getVariable(TIMEOUT_FOR_NOTIFICATION)).thenReturn("");
95 expectedException.expect(BpmnError.class);
96 testedObject.execute(delegateExecution);
100 public void shouldSetDefaultTimeout_whenTimeoutIsNotSet() {
102 PnfCheckInputs testedObject = new PnfCheckInputs(DEFAULT_TIMEOUT);
103 DelegateExecution delegateExecution = mockDelegateExecutionWithCorrelationId();
105 testedObject.execute(delegateExecution);
107 verify(delegateExecution).setVariable(eq(TIMEOUT_FOR_NOTIFICATION), eq(DEFAULT_TIMEOUT));