Add Support for creating model type
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / components / impl / ModelBusinessLogicTest.java
1 /*
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2021 Nordix Foundation
4  *  ================================================================================
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at
8  *
9  *        http://www.apache.org/licenses/LICENSE-2.0
10  *  Unless required by applicable law or agreed to in writing, software
11  *  distributed under the License is distributed on an "AS IS" BASIS,
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License.
15  *
16  *  SPDX-License-Identifier: Apache-2.0
17  *  ============LICENSE_END=========================================================
18  */
19 package org.openecomp.sdc.be.components.impl;
20
21 import static org.assertj.core.api.Assertions.assertThat;
22 import static org.junit.jupiter.api.Assertions.assertThrows;
23 import static org.mockito.Mockito.when;
24
25 import org.junit.jupiter.api.BeforeAll;
26 import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
27 import org.junit.jupiter.api.Order;
28 import org.junit.jupiter.api.Test;
29 import org.junit.jupiter.api.TestInstance;
30 import org.junit.jupiter.api.TestInstance.Lifecycle;
31 import org.junit.jupiter.api.TestMethodOrder;
32 import org.mockito.InjectMocks;
33 import org.mockito.Mock;
34 import org.mockito.MockitoAnnotations;
35 import org.openecomp.sdc.be.dao.api.ActionStatus;
36 import org.openecomp.sdc.be.exception.BusinessException;
37 import org.openecomp.sdc.be.model.Model;
38 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.exception.OperationException;
39 import org.openecomp.sdc.be.model.operations.impl.ModelOperation;
40
41 @TestInstance(Lifecycle.PER_CLASS)
42 @TestMethodOrder(OrderAnnotation.class)
43 class ModelBusinessLogicTest {
44
45     @InjectMocks
46     private ModelBusinessLogic modelBusinessLogic;
47     @Mock
48     private ModelOperation modelOperation;
49     private Model model;
50
51     @BeforeAll
52     void setup() {
53         MockitoAnnotations.openMocks(this);
54         initTestData();
55     }
56
57     private void initTestData() {
58         model = new Model("ETSI-SDC-MODEL-TEST");
59     }
60
61     @Test
62     @Order(1)
63     void createModelTest() {
64         when(modelOperation.createModel(model, false)).thenReturn(model);
65         final Model result = modelBusinessLogic.createModel(model);
66         assertThat(result).isNotNull();
67         assertThat(result.getName()).isEqualTo(model.getName());
68     }
69
70     @Test
71     @Order(2)
72     void createModelFailTest() {
73         when(modelOperation.createModel(model, false))
74             .thenThrow(new OperationException(ActionStatus.MODEL_ALREADY_EXISTS, model.getName()));
75         final BusinessException exception = assertThrows(BusinessException.class, () -> modelBusinessLogic.createModel(model));
76         assertThat(((OperationException) exception).getActionStatus().name()).isEqualTo(ActionStatus.MODEL_ALREADY_EXISTS.name());
77         assertThat(((OperationException) exception).getParams()).contains(model.getName());
78     }
79
80 }