eae144e545ad92c6e188d394b520218a6e20a5a3
[usecase-ui/intent-analysis.git] /
1 /*
2  * Copyright (C) 2022 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  */
17
18 package org.onap.usecaseui.intentanalysis.formatintentinputMgt.formatintentinputModule;
19
20 import org.junit.Assert;
21 import org.junit.Before;
22 import org.junit.Test;
23 import org.junit.runner.RunWith;
24 import org.mockito.InjectMocks;
25 import org.mockito.Mock;
26 import org.mockito.Mockito;
27 import org.onap.usecaseui.intentanalysis.IntentAnalysisApplicationTests;
28 import org.onap.usecaseui.intentanalysis.bean.enums.ExpectationType;
29 import org.onap.usecaseui.intentanalysis.bean.enums.IntentGoalType;
30 import org.onap.usecaseui.intentanalysis.bean.enums.ObjectType;
31 import org.onap.usecaseui.intentanalysis.bean.enums.OperatorType;
32 import org.onap.usecaseui.intentanalysis.bean.models.*;
33 import org.onap.usecaseui.intentanalysis.service.IntentService;
34 import org.springframework.boot.test.context.SpringBootTest;
35 import org.springframework.test.context.junit4.SpringRunner;
36
37 import java.util.ArrayList;
38 import java.util.List;
39
40 import static org.mockito.ArgumentMatchers.anyString;
41
42 @SpringBootTest(classes = IntentAnalysisApplicationTests.class)
43 @RunWith(SpringRunner.class)
44 public class FormatIntentInputKnowledgeModuleTest {
45     @InjectMocks
46     FormatIntentInputKnowledgeModule formatIntentInputKnowledgeModule;
47
48     @Mock
49     IntentService intentService;
50     IntentGoalBean intentGoalBean = new IntentGoalBean();
51     Intent intent = new Intent();
52
53     @Before
54     public void before() throws Exception {
55         intent.setIntentName("cllIntent");
56         intent.setIntentId("12345");
57         List<Expectation> expectationList = new ArrayList<>();
58
59         Expectation delivery = new Expectation();
60         delivery.setExpectationId("12345-delivery");
61         delivery.setExpectationName("deliveryExpectation");
62         delivery.setExpectationType(ExpectationType.DELIVERY);
63         ExpectationObject expectationObject = new ExpectationObject();
64         expectationObject.setObjectType(ObjectType.OBJECT1);
65         //expetationTarget  Context  FulfilmentInfo is empty
66         delivery.setExpectationObject(expectationObject);
67         List<ExpectationTarget> expectationTargets = new ArrayList<>();
68         ExpectationTarget expectationTarget = new ExpectationTarget();
69         expectationTarget.setTargetName("aaaa");
70         expectationTargets.add(expectationTarget);
71         delivery.setExpectationTargets(expectationTargets);
72         expectationList.add(delivery);
73
74         Expectation assurance = new Expectation();
75         assurance.setExpectationId("12345-assurance");
76         assurance.setExpectationName("assuranceExpectation");
77         assurance.setExpectationType(ExpectationType.ASSURANCE);
78         ExpectationObject expectationObject1 = new ExpectationObject();
79         expectationObject1.setObjectType(ObjectType.OBJECT2);
80         //expetationTarget  Context  FulfilmentInfo  is empty
81         assurance.setExpectationObject(expectationObject1);
82
83         List<ExpectationTarget> expectationTarget2 = new ArrayList<>();
84         ExpectationTarget expectationTargetAssu = new ExpectationTarget();
85         expectationTargetAssu.setTargetName("aaaa");
86         expectationTarget2.add(expectationTargetAssu);
87         assurance.setExpectationTargets(expectationTarget2);
88
89         expectationList.add(assurance);
90
91         intent.setIntentExpectations(expectationList);
92         intent.setIntentExpectations(expectationList);
93         intent.setIntentExpectations(expectationList);
94
95         List<Context> intentContexts = new ArrayList<>();
96         Context context = new Context();
97         context.setContextName("owninfo");
98
99         List<Condition> conditionList = new ArrayList<>();//ownerName = formatIntentInputManagementFunction"
100         Condition condition = new Condition();
101         condition.setConditionName("ownerName");
102         condition.setOperator(OperatorType.EQUALTO);
103         condition.setConditionValue("formatIntentInputManagementFunction");
104         conditionList.add(condition);
105         context.setContextConditions(conditionList);
106         intentContexts.add(context);
107         intent.setIntentContexts(intentContexts);
108
109         intentGoalBean.setIntent(intent);
110         intentGoalBean.setIntentGoalType(IntentGoalType.CREATE);
111     }
112
113     @Test
114     public void testFormatIntentInputKnowledgeModule() {
115         List<Intent> list = new ArrayList<>();
116         list.add(intent);
117         Mockito.when(intentService.getIntentByName(anyString())).thenReturn(list);
118         formatIntentInputKnowledgeModule.intentCognition(intent);
119         Assert.assertTrue(true);
120     }
121 }