9aba940755abffa71312a9fe7c9e8d5f88467b50
[usecase-ui/intent-analysis.git] /
1 /*
2  * Copyright (C) 2023 CMCC, Inc. and others. All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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 package org.onap.usecaseui.intentanalysis.formatintentinputMgt;
17
18 import org.junit.Assert;
19 import org.junit.Before;
20 import org.junit.Test;
21 import org.junit.runner.RunWith;
22 import org.mockito.InjectMocks;
23 import org.mockito.Mock;
24 import org.onap.usecaseui.intentanalysis.IntentAnalysisApplicationTests;
25 import org.onap.usecaseui.intentanalysis.bean.enums.ExpectationType;
26 import org.onap.usecaseui.intentanalysis.bean.enums.IntentGoalType;
27 import org.onap.usecaseui.intentanalysis.bean.enums.ObjectType;
28 import org.onap.usecaseui.intentanalysis.bean.models.Expectation;
29 import org.onap.usecaseui.intentanalysis.bean.models.ExpectationObject;
30 import org.onap.usecaseui.intentanalysis.bean.models.Intent;
31 import org.onap.usecaseui.intentanalysis.bean.models.IntentGoalBean;
32 import org.onap.usecaseui.intentanalysis.cllBusinessIntentMgt.CLLBusinessIntentManagementFunction;
33 import org.onap.usecaseui.intentanalysis.formatintentinputMgt.formatintentinputModule.FormatIntentInputActuationModule;
34 import org.onap.usecaseui.intentanalysis.formatintentinputMgt.formatintentinputModule.FormatIntentInputDecisionModule;
35 import org.onap.usecaseui.intentanalysis.formatintentinputMgt.formatintentinputModule.FormatIntentInputKnowledgeModule;
36 import org.onap.usecaseui.intentanalysis.intentBaseService.IntentManagementFunction;
37 import org.onap.usecaseui.intentanalysis.intentBaseService.contextService.IntentContextService;
38 import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.ActuationModule;
39 import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.DecisionModule;
40 import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.KnowledgeModule;
41 import org.onap.usecaseui.intentanalysis.intentBaseService.intentinterfaceservice.IntentInterfaceService;
42 import org.onap.usecaseui.intentanalysis.service.IntentService;
43 import org.springframework.boot.test.context.SpringBootTest;
44 import org.springframework.context.ApplicationContext;
45 import org.springframework.test.context.junit4.SpringRunner;
46
47 import java.util.ArrayList;
48 import java.util.LinkedHashMap;
49 import java.util.List;
50
51 import static org.mockito.Mockito.mock;
52
53 @SpringBootTest(classes = IntentAnalysisApplicationTests.class)
54 @RunWith(SpringRunner.class)
55 public class FormatIntentInputManagementFunctionTest {
56     @InjectMocks
57     FormatIntentInputManagementFunction formatIntentInputManagementFunction;
58     KnowledgeModule knowledgeModule = mock(FormatIntentInputKnowledgeModule.class);
59     DecisionModule decisionModule = mock(FormatIntentInputDecisionModule.class);
60     ActuationModule actuationModule = mock(FormatIntentInputActuationModule.class);
61     @Mock
62     CLLBusinessIntentManagementFunction cllBusinessIntentManagementFunction;
63     @Mock
64     IntentInterfaceService intentInterfaceService;
65     @Mock
66     ApplicationContext applicationContext;
67     @Mock
68     IntentService intentService;
69     @Mock
70     IntentContextService intentContextService;
71
72
73     Intent intent = new Intent();
74     IntentGoalBean intentGoalBean = new IntentGoalBean();
75
76     @Before
77     public void before() throws Exception {
78         intent.setIntentName("cllIntent");
79         intent.setIntentId("12345");
80         List<Expectation> expectationList = new ArrayList<>();
81
82         Expectation delivery = new Expectation();
83         delivery.setExpectationId("12345-delivery");
84         delivery.setExpectationName("deliveryExpectation");
85         delivery.setExpectationType(ExpectationType.DELIVERY);
86         ExpectationObject expectationObject = new ExpectationObject();
87         expectationObject.setObjectType(ObjectType.SLICING);
88         //expetationTarget  Context  FulfilmentInfo is empty
89         delivery.setExpectationObject(expectationObject);
90         expectationList.add(delivery);
91
92         Expectation assurance = new Expectation();
93         assurance.setExpectationId("12345-assurance");
94         assurance.setExpectationName("assuranceExpectation");
95         assurance.setExpectationType(ExpectationType.ASSURANCE);
96         ExpectationObject expectationObject1 = new ExpectationObject();
97         expectationObject1.setObjectType(ObjectType.CCVPN);
98         //expetationTarget  Context  FulfilmentInfo  is empty
99         assurance.setExpectationObject(expectationObject1);
100         expectationList.add(assurance);
101
102         intent.setIntentExpectations(expectationList);
103         intentGoalBean.setIntent(intent);
104         intentGoalBean.setIntentGoalType(IntentGoalType.CREATE);
105     }
106
107     @Test
108     public void testDetection() {
109         formatIntentInputManagementFunction.detection(intentGoalBean);
110         Assert.assertTrue(true);
111     }
112
113     @Test
114     public void testInvestigation() {
115         formatIntentInputManagementFunction.investigation(intentGoalBean);
116         Assert.assertTrue(true);
117     }
118
119     @Test
120     public void testImplementIntentCreate() {
121         LinkedHashMap<IntentGoalBean, IntentManagementFunction> map = new LinkedHashMap<>();
122         map.put(intentGoalBean, cllBusinessIntentManagementFunction);
123         formatIntentInputManagementFunction.implementIntent(intent, map);
124         Assert.assertTrue(true);
125     }
126
127     @Test
128     public void testImplementIntentUpdate() {
129         LinkedHashMap<IntentGoalBean, IntentManagementFunction> map = new LinkedHashMap<>();
130         intentGoalBean.setIntentGoalType(IntentGoalType.UPDATE);
131         map.put(intentGoalBean, cllBusinessIntentManagementFunction);
132         formatIntentInputManagementFunction.implementIntent(intent, map);
133         Assert.assertTrue(true);
134     }
135
136     @Test
137     public void testImplementIntentDelete() {
138         LinkedHashMap<IntentGoalBean, IntentManagementFunction> map = new LinkedHashMap<>();
139         intentGoalBean.setIntentGoalType(IntentGoalType.DELETE);
140         map.put(intentGoalBean, cllBusinessIntentManagementFunction);
141         formatIntentInputManagementFunction.implementIntent(intent, map);
142         Assert.assertTrue(true);
143     }
144
145     @Test
146     public void testUpdateIntentInfo() {
147         Intent originalIntent = new Intent();
148
149         originalIntent.setIntentName("cllIntent");
150         originalIntent.setIntentId("12345");
151         List<Expectation> expectationList = new ArrayList<>();
152
153         Expectation delivery = new Expectation();
154         delivery.setExpectationId("12345-delivery");
155         delivery.setExpectationName("deliveryExpectation");
156         delivery.setExpectationType(ExpectationType.DELIVERY);
157         ExpectationObject expectationObject = new ExpectationObject();
158         expectationObject.setObjectType(ObjectType.SLICING);
159         //expetationTarget  Context  FulfilmentInfo is empty
160         delivery.setExpectationObject(expectationObject);
161         expectationList.add(delivery);
162         originalIntent.setIntentExpectations(expectationList);
163
164         formatIntentInputManagementFunction.updateIntentInfo(originalIntent, intent);
165         Assert.assertTrue(true);
166     }
167 }