aboutsummaryrefslogtreecommitdiffstats
path: root/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/service/IntentServiceTest.java
blob: f1003f04417a9d57cd43c41b18ba5f3cefb3d6e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*
 * Copyright 2022 Huawei Technologies Co., Ltd.
 *
 * 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.
 */

package org.onap.usecaseui.intentanalysis.service;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.onap.usecaseui.intentanalysis.bean.enums.*;
import org.onap.usecaseui.intentanalysis.bean.models.Intent;
import org.onap.usecaseui.intentanalysis.bean.models.Condition;
import org.onap.usecaseui.intentanalysis.bean.models.FulfillmentInfo;
import org.onap.usecaseui.intentanalysis.bean.models.Context;
import org.onap.usecaseui.intentanalysis.bean.models.Expectation;
import org.onap.usecaseui.intentanalysis.bean.models.ExpectationTarget;
import org.onap.usecaseui.intentanalysis.bean.models.ExpectationObject;
import org.onap.usecaseui.intentanalysis.IntentAnalysisApplicationTests;
import org.onap.usecaseui.intentanalysis.util.SpringContextUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.util.CollectionUtils;

@SpringBootTest(classes = IntentAnalysisApplicationTests.class)
@RunWith(SpringRunner.class)
public class IntentServiceTest extends AbstractJUnit4SpringContextTests {

    private static final String TEST_INTENT_ID_1 = "intentId1";

    private static final String TEST_INTENT_ID_2 = "intentId2";

    private static final String TEST_INTENT_NAME = "CLL Business intent";

    @Autowired
    private IntentService intentService;

    @Before
    public void setUp() {
        SpringContextUtil.setApplicationContext(applicationContext);
    }

    @Test
    public void testCreateIntentSuccess() throws IOException {
        Intent intent = new Intent();
        Expectation expectation1 = new Expectation();
        ExpectationTarget target1 = new ExpectationTarget();
        ExpectationObject object1 = new ExpectationObject();
        Context intentContext = new Context();
        FulfillmentInfo intentFulfillmentInfo = new FulfillmentInfo();
        Condition targetCondition1 = new Condition();
        targetCondition1.setConditionId("conditionId");
        targetCondition1.setConditionName("conditionName");
        targetCondition1.setOperator(OperatorType.valueOf("EQUALTO"));
        targetCondition1.setConditionValue("conditionValue");
        List<Condition> targetConditionList = new ArrayList<>();
        targetConditionList.add(targetCondition1);
        target1.setTargetId("targetId");
        target1.setTargetName("targetName");
        target1.setTargetConditions(targetConditionList);
        List<ExpectationTarget> expectationTargetList = new ArrayList<>();
        expectationTargetList.add(target1);
        object1.setObjectType(ObjectType.valueOf("SLICING"));
        object1.setObjectInstance("objectInstance");
        expectation1.setExpectationId("expectationId");
        expectation1.setExpectationName("expectationName");
        expectation1.setExpectationType(ExpectationType.valueOf("DELIVERY"));
        expectation1.setExpectationObject(object1);
        expectation1.setExpectationTargets(expectationTargetList);
        List<Expectation> expectationList = new ArrayList<>();
        expectationList.add(expectation1);
        intentContext.setContextId("intentContextId");
        intentContext.setContextName("intentContextName");
        List<Context> intentContextList = new ArrayList<>();
        intentContextList.add(intentContext);
        intentFulfillmentInfo.setFulfillmentStatus(FulfillmentStatus.valueOf("NOT_FULFILLED"));
        intentFulfillmentInfo.setNotFulfilledReason("NotFulfilledReason");
        intentFulfillmentInfo.setNotFulfilledState(NotFulfilledState.valueOf("COMPLIANT"));
        intent.setIntentId("testIntentId");
        intent.setIntentName("testIntentName");
        intent.setIntentContexts(intentContextList);
        intent.setIntentExpectations(expectationList);
        intent.setIntentFulfillmentInfo(intentFulfillmentInfo);

        Intent intentTmp = intentService.createIntent(intent);
        Assert.assertNotNull(intentTmp);
    }

    @Test
    public void testGetIntentListSuccess() {
        List<Intent> intentList = intentService.getIntentList();
        Assert.assertFalse(CollectionUtils.isEmpty(intentList));
    }

    @Test
    public void testGetIntentSuccess() {
        Intent intent = intentService.getIntent(TEST_INTENT_ID_1);
        Assert.assertNotNull(intent);
    }

    @Test
    public void testGetIntentByNameSuccess() {
        List<Intent> intentList = intentService.getIntentByName(TEST_INTENT_NAME);
        Assert.assertNotNull(intentList);

    }

    @Test
    public void testUpdateIntentSuccess() {
        Intent intent = intentService.getIntent(TEST_INTENT_ID_1);
        intent.setIntentName("new intent name");
        List<Context> contextList = intent.getIntentContexts();
        Context intentContext = contextList.get(0);
        intentContext.setContextName("new context name");
        contextList.set(0, intentContext);
        intent.setIntentContexts(contextList);
        FulfillmentInfo intentFulfillmentInfo = intent.getIntentFulfillmentInfo();
        intentFulfillmentInfo.setNotFulfilledReason("new reason");
        intent.setIntentFulfillmentInfo(intentFulfillmentInfo);
        List<Expectation> expectationList = intent.getIntentExpectations();
        Expectation expectation = expectationList.get(0);
        expectation.setExpectationName("new expectation name");
        ExpectationObject expectationObject = expectation.getExpectationObject();
        expectationObject.setObjectInstance("new object instance");
        expectation.setExpectationObject(expectationObject);
        List<ExpectationTarget> expectationTargetList = expectation.getExpectationTargets();
        ExpectationTarget expectationTarget = expectationTargetList.get(0);
        expectationTarget.setTargetName("new target name");
        List<Condition> targetConditionList = expectationTarget.getTargetConditions();
        Condition targetCondition = targetConditionList.get(0);
        targetCondition.setConditionName("new condition name");
        targetConditionList.set(0, targetCondition);
        expectationTarget.setTargetConditions(targetConditionList);
        expectationTargetList.remove(2);
        expectationTargetList.set(0, expectationTarget);
        expectation.setExpectationTargets(expectationTargetList);
        expectationList.set(0, expectation);
        intent.setIntentExpectations(expectationList);

        Intent updatedIntent = intentService.updateIntent(intent);
        Assert.assertEquals("new intent name", updatedIntent.getIntentName());

    }

    @Test
    public void testDeleteIntentSuccess() {
        intentService.deleteIntent(TEST_INTENT_ID_2);
        Intent intent = intentService.getIntent(TEST_INTENT_ID_2);
        Assert.assertNull(intent);
    }
}