summaryrefslogtreecommitdiffstats
path: root/intentanalysis/src/test/java/org
diff options
context:
space:
mode:
authorzhangfan345 <zhangfan345@huawei.com>2022-09-01 11:24:47 +0800
committerzhangfan345 <zhangfan345@huawei.com>2022-09-01 14:40:14 +0800
commit54e7ca4ddf183cd15bd7afff0c53b1970698432b (patch)
tree8b4e8f780b24b409e4e81a375e9e933415e444f5 /intentanalysis/src/test/java/org
parent0699e877538e8ee6179750112a4414848058fe09 (diff)
Add UT to intent service
Issue-ID: USECASEUI-716 Signed-off-by: zhangfan345 <zhangfan345@huawei.com> Change-Id: I45b7faf76bf899510d11939021fd1d788c95a4bf
Diffstat (limited to 'intentanalysis/src/test/java/org')
-rw-r--r--intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/test/service/IntentServiceTest.java121
1 files changed, 118 insertions, 3 deletions
diff --git a/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/test/service/IntentServiceTest.java b/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/test/service/IntentServiceTest.java
index 3a692c0..6dc1062 100644
--- a/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/test/service/IntentServiceTest.java
+++ b/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/test/service/IntentServiceTest.java
@@ -15,11 +15,21 @@
package org.onap.usecaseui.intentanalysis.test.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.FulfilmentInfo;
+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.service.IntentService;
import org.onap.usecaseui.intentanalysis.test.IntentAnalysisApplicationTests;
import org.onap.usecaseui.intentanalysis.util.SpringContextUtil;
@@ -36,6 +46,12 @@ public class IntentServiceTest extends AbstractJUnit4SpringContextTests {
private static final Logger LOGGER = LoggerFactory.getLogger(IntentServiceTest.class);
+ 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;
@@ -47,10 +63,109 @@ public class IntentServiceTest extends AbstractJUnit4SpringContextTests {
@Test
public void testCreateIntentSuccess() throws IOException {
Intent intent = new Intent();
- intent.setIntentId("testUUID");
+ Expectation expectation1 = new Expectation();
+ ExpectationTarget target1 = new ExpectationTarget();
+ ExpectationObject object1 = new ExpectationObject();
+ Context intentContext = new Context();
+ FulfilmentInfo intentFulfilmentInfo = new FulfilmentInfo();
+ 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("OBJECT1"));
+ 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);
+ intentFulfilmentInfo.setFulfilmentStatus(FulfilmentStatus.valueOf("NOT_FULFILLED"));
+ intentFulfilmentInfo.setNotFulfilledReason("NotFulfilledReason");
+ intentFulfilmentInfo.setNotFulfilledState(NotFulfilledState.valueOf("COMPLIANT"));
+ intent.setIntentId("testIntentId");
intent.setIntentName("testIntentName");
- //ToDo
- //Intent intentTmp = intentService.createIntent(intent);
+ intent.setIntentContexts(intentContextList);
+ intent.setIntentExpectations(expectationList);
+ intent.setIntentFulfilmentInfo(intentFulfilmentInfo);
+
+ Intent intentTmp = intentService.createIntent(intent);
+ Assert.assertNotNull(intentTmp);
+ }
+
+ @Test
+ public void testGetIntentListSuccess() {
+ List<Intent> intentList = intentService.getIntentList();
+ Assert.assertNotNull(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);
+ FulfilmentInfo intentFulfilmentInfo = intent.getIntentFulfilmentInfo();
+ intentFulfilmentInfo.setNotFulfilledReason("new reason");
+ intent.setIntentFulfilmentInfo(intentFulfilmentInfo);
+ 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 conditon 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);
+ }
}