diff options
author | Sébastien Determe <sebastien.determe@intl.att.com> | 2019-05-08 11:08:35 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2019-05-08 11:08:35 +0000 |
commit | 224df08e29cae9829d805c7b686727eea660d1b1 (patch) | |
tree | 6bf14b765612b2d8fb6c907bef998815edc72d88 /src/test/java/org | |
parent | a333d40e0933c77f60063cd1a91134f7db026b23 (diff) | |
parent | 17bb9da07b049c4d7a0a316b497ce91cefab1288 (diff) |
Merge "Added unit tests for OperationalPolicyDeleteDelegate"
Diffstat (limited to 'src/test/java/org')
-rw-r--r-- | src/test/java/org/onap/clamp/clds/client/OperationalPolicyDeleteDelegateTest.java | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/src/test/java/org/onap/clamp/clds/client/OperationalPolicyDeleteDelegateTest.java b/src/test/java/org/onap/clamp/clds/client/OperationalPolicyDeleteDelegateTest.java new file mode 100644 index 000000000..9d87e7e97 --- /dev/null +++ b/src/test/java/org/onap/clamp/clds/client/OperationalPolicyDeleteDelegateTest.java @@ -0,0 +1,108 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP CLAMP + * ================================================================================ + * Copyright (C) 2019 Samsung. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END============================================ + * =================================================================== + * + */ + +package org.onap.clamp.clds.client; + +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import org.apache.camel.Exchange; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.onap.clamp.clds.client.req.policy.PolicyClient; +import org.onap.clamp.clds.exception.ModelBpmnException; +import org.onap.clamp.clds.model.properties.ModelProperties; + +@RunWith(MockitoJUnitRunner.class) +public class OperationalPolicyDeleteDelegateTest { + + private static final String TEST_KEY = "isTest"; + private static final String MODEL_BPMN_KEY = "modelBpmnProp"; + private static final String MODEL_PROP_KEY = "modelProp"; + private static final String EVENT_ACTION_KEY = "eventAction"; + private static final String POLICY_ID_FROM_JSON = "{policy:[{id:Poli2,from:''}]}"; + private static final String ID_WITH_CHAIN_JSON = "{Poli2:{ab:c,xy:z}}"; + private static final String ID_NO_CHAIN_JSON = "{Poli2:{}}"; + private static final String EVENT_ACTION_VALUE = "still"; + private static final String NOT_JSON = "23e"; + + @Mock + private Exchange exchange; + + @Mock + private PolicyClient policyClient; + + @InjectMocks + private OperationalPolicyDeleteDelegate operationalPolicyDeleteDelegate; + + @Test + public void shouldExecuteSuccessfully() { + // given + when(exchange.getProperty(eq(TEST_KEY))).thenReturn(false); + when(exchange.getProperty(eq(MODEL_BPMN_KEY))).thenReturn(POLICY_ID_FROM_JSON); + when(exchange.getProperty(eq(MODEL_PROP_KEY))).thenReturn(ID_WITH_CHAIN_JSON); + when(exchange.getProperty(eq(EVENT_ACTION_KEY))).thenReturn(EVENT_ACTION_VALUE); + + // when + operationalPolicyDeleteDelegate.execute(exchange); + + // then + verify(policyClient, times(2)).deleteBrms(any(ModelProperties.class)); + } + + @Test + public void shouldExecuteTcaNotFound() { + // given + when(exchange.getProperty(eq(TEST_KEY))).thenReturn(true); + when(exchange.getProperty(eq(MODEL_BPMN_KEY))).thenReturn(POLICY_ID_FROM_JSON); + when(exchange.getProperty(eq(MODEL_PROP_KEY))).thenReturn(ID_NO_CHAIN_JSON); + + // when + operationalPolicyDeleteDelegate.execute(exchange); + + // then + verify(policyClient, never()).deleteBrms(any(ModelProperties.class)); + } + + @Test(expected = ModelBpmnException.class) + public void shouldThrowModelBpmnException() { + // given + when(exchange.getProperty(eq(TEST_KEY))).thenReturn(false); + when(exchange.getProperty(eq(MODEL_BPMN_KEY))).thenReturn(NOT_JSON); + + // when + operationalPolicyDeleteDelegate.execute(exchange); + } + + @Test(expected = NullPointerException.class) + public void shouldThrowNullPointerException() { + // when + operationalPolicyDeleteDelegate.execute(exchange); + } +} |