diff options
6 files changed, 176 insertions, 10 deletions
diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/so/SOService.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/so/SOService.java index 4129b8e..7b56e17 100644 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/so/SOService.java +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/so/SOService.java @@ -16,11 +16,12 @@ package org.onap.usecaseui.intentanalysis.adapters.so; import org.onap.usecaseui.intentanalysis.bean.models.CCVPNInstance; +import org.springframework.stereotype.Service; public interface SOService { int createCCVPNInstance(CCVPNInstance instance); - void deleteIntentInstance(String instanceId); + int deleteIntentInstance(String instanceId); } diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/so/impl/SOServiceImpl.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/so/impl/SOServiceImpl.java index e4e1f60..6f5cbcc 100644 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/so/impl/SOServiceImpl.java +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/so/impl/SOServiceImpl.java @@ -21,7 +21,6 @@ import com.alibaba.fastjson.JSONObject; import org.onap.usecaseui.intentanalysis.adapters.aai.apicall.AAIAPICall; import org.onap.usecaseui.intentanalysis.adapters.aai.apicall.AAIAuthConfig; import org.onap.usecaseui.intentanalysis.adapters.policy.apicall.PolicyAPICall; -import org.onap.usecaseui.intentanalysis.adapters.policy.apicall.PolicyAuthConfig; import org.onap.usecaseui.intentanalysis.adapters.so.SOService; import org.onap.usecaseui.intentanalysis.adapters.so.apicall.SOAPICall; import org.onap.usecaseui.intentanalysis.adapters.so.apicall.SOAuthConfig; @@ -30,18 +29,19 @@ import org.onap.usecaseui.intentanalysis.util.RestfulServices; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; import retrofit2.Response; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +@Service public class SOServiceImpl implements SOService { private static final Logger logger = LoggerFactory.getLogger(SOServiceImpl.class); - private SOAPICall soapiCall; private AAIAPICall aaiapiCall; @@ -68,8 +68,16 @@ public class SOServiceImpl implements SOService { return this.aaiapiCall; } + public void setSoApiCall(SOAPICall soApiCall) { + this.soapiCall = soApiCall; + } + + public void setAAIApiCall(AAIAPICall aaiApiCall) { + this.aaiapiCall = aaiApiCall; + } + @Override - public int createCCVPNInstance(CCVPNInstance ccvpnInstance) { + public int createCCVPNInstance(CCVPNInstance ccvpnInstance) { try{ if (null == ccvpnInstance){ logger.error("CCVPN instance is null!"); @@ -100,17 +108,20 @@ public class SOServiceImpl implements SOService { } @Override - public void deleteIntentInstance(String serviceInstanceId) { + public int deleteIntentInstance(String serviceInstanceId) { try { deleteInstanceToSO(serviceInstanceId); }catch (Exception e) { logger.error("delete instance to SO error :" + e); + return 0; } + return 1; } public String createIntentInstanceToSO(CCVPNInstance ccvpnInstance) throws IOException { Map<String, Object> params = paramsSetUp(ccvpnInstance); params.put("additionalProperties",additionalPropertiesSetUp(ccvpnInstance)); + //make sure params are in conformity with format okhttp3.RequestBody requestBody = okhttp3.RequestBody.create(okhttp3.MediaType.parse("application/json"), JSON.toJSONString(params)); Response<JSONObject> response = getSoApiCall().createIntentInstance(requestBody).execute(); if (response.isSuccessful()) { diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/formatintentinputMgt/formatintentinputModule/FormatIntentInputActuationModule.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/formatintentinputMgt/formatintentinputModule/FormatIntentInputActuationModule.java index 1d397fd..2d308c4 100644 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/formatintentinputMgt/formatintentinputModule/FormatIntentInputActuationModule.java +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/formatintentinputMgt/formatintentinputModule/FormatIntentInputActuationModule.java @@ -16,17 +16,31 @@ package org.onap.usecaseui.intentanalysis.formatintentinputMgt.formatintentinputModule; import lombok.extern.log4j.Log4j2; +import org.apache.commons.collections.CollectionUtils; +import org.checkerframework.checker.units.qual.A; +import org.onap.usecaseui.intentanalysis.bean.enums.OperatorType; +import org.onap.usecaseui.intentanalysis.bean.models.Condition; +import org.onap.usecaseui.intentanalysis.bean.models.Context; import org.onap.usecaseui.intentanalysis.bean.models.Intent; +import org.onap.usecaseui.intentanalysis.formatintentinputMgt.FormatIntentInputManagementFunction; import org.onap.usecaseui.intentanalysis.intentBaseService.IntentManagementFunction; import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.ActuationModule; import org.onap.usecaseui.intentanalysis.intentBaseService.intentProcessService.IntentProcessService; +import org.onap.usecaseui.intentanalysis.service.IntentService; +import org.onap.usecaseui.intentanalysis.util.CommonUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.List; + @Log4j2 @Component public class FormatIntentInputActuationModule extends ActuationModule { @Autowired IntentProcessService processService; + @Autowired + IntentService intentService; @Override public void toNextIntentHandler(Intent intent, IntentManagementFunction IntentHandler) { log.info("do nothing"); @@ -43,4 +57,26 @@ public class FormatIntentInputActuationModule extends ActuationModule { @Override public void fulfillIntent(Intent intent, IntentManagementFunction intentHandler) { } + @Override + public void saveIntentToDb(Intent intent){ + List<Context> intentContexts = intent.getIntentContexts(); + if (CollectionUtils.isEmpty(intentContexts)) { + intentContexts = new ArrayList<>(); + } + Context ownerInfoCon = new Context(); + ownerInfoCon.setContextId(CommonUtil.getUUid()); + ownerInfoCon.setContextName("ownerInfo"); + List<Condition> conditionList = new ArrayList<>(); + Condition condition = new Condition(); + condition.setConditionId(CommonUtil.getUUid()); + condition.setConditionName("ownerName"); + condition.setOperator(OperatorType.EQUALTO); + condition.setConditionValue(FormatIntentInputManagementFunction.class.getSimpleName()); + conditionList.add(condition); + ownerInfoCon.setContextConditions(conditionList); + intentContexts.add(ownerInfoCon); + intent.setIntentContexts(intentContexts); + intentService.createIntent(intent); + } + } diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/formatintentinputMgt/formatintentinputModule/FormatIntentInputDecisionModule.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/formatintentinputMgt/formatintentinputModule/FormatIntentInputDecisionModule.java index edb3814..968add2 100644 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/formatintentinputMgt/formatintentinputModule/FormatIntentInputDecisionModule.java +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/formatintentinputMgt/formatintentinputModule/FormatIntentInputDecisionModule.java @@ -75,8 +75,8 @@ public class FormatIntentInputDecisionModule extends DecisionModule { List<String> expectationNameList = intentExpectations.stream().map(Expectation::getExpectationName) .distinct().collect(Collectors.toList()); if (expectationNameList.size() > 1) { - List<String> cllList = expectationNameList.stream().filter(x -> StringUtils.equalsIgnoreCase(x, "cll")).collect(Collectors.toList()); - List<String> slicingList = expectationNameList.stream().filter(x -> StringUtils.equalsIgnoreCase(x, "slicing")).collect(Collectors.toList()); + List<String> cllList = expectationNameList.stream().filter(x -> StringUtils.containsIgnoreCase(x, "cll")).collect(Collectors.toList()); + List<String> slicingList = expectationNameList.stream().filter(x -> StringUtils.containsIgnoreCase(x, "slicing")).collect(Collectors.toList()); if (cllList.size() > 0 && slicingList.size() > 0) { return true; } diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/intentModule/KnowledgeModule.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/intentModule/KnowledgeModule.java index bce9c95..b3dbcc2 100644 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/intentModule/KnowledgeModule.java +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/intentModule/KnowledgeModule.java @@ -17,8 +17,11 @@ package org.onap.usecaseui.intentanalysis.intentBaseService.intentModule; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang.StringUtils; +import org.onap.usecaseui.intentanalysis.bean.enums.OperatorType; import org.onap.usecaseui.intentanalysis.bean.models.*; +import org.onap.usecaseui.intentanalysis.formatintentinputMgt.FormatIntentInputManagementFunction; import org.onap.usecaseui.intentanalysis.service.IntentService; +import org.onap.usecaseui.intentanalysis.util.CommonUtil; import org.springframework.beans.factory.annotation.Autowired; import java.util.ArrayList; @@ -86,9 +89,9 @@ public abstract class KnowledgeModule { List<Condition> contextConditions = context.getContextConditions(); boolean equals = false; for (Condition condition : contextConditions) { - String conditionstr = "ownerName = formatIntentInputManagementFunction"; - String concatStr = condition.getConditionName() + condition.getOperator() + condition.getConditionValue(); - if (StringUtils.equalsIgnoreCase(concatStr.trim(), conditionstr.trim())) { + String conditionstr = "ownerName equal to formatIntentInputManagementFunction"; + String concatStr = condition.getConditionName() + condition.getOperator().name() + condition.getConditionValue(); + if (StringUtils.equalsIgnoreCase(concatStr.trim(), conditionstr.replaceAll(" ",""))) { fiterList.add(intent); equals = true; break; diff --git a/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/adapters/so/SOServiceTest.java b/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/adapters/so/SOServiceTest.java new file mode 100644 index 0000000..033336f --- /dev/null +++ b/intentanalysis/src/test/java/org/onap/usecaseui/intentanalysis/adapters/so/SOServiceTest.java @@ -0,0 +1,115 @@ +package org.onap.usecaseui.intentanalysis.adapters.so; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.*; + + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import java.io.IOException; +import okhttp3.MediaType; +import okhttp3.RequestBody; +import okhttp3.ResponseBody; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import mockit.Mock; +import org.mockito.junit.MockitoJUnitRunner; +import org.onap.usecaseui.intentanalysis.IntentAnalysisApplicationTests; +import org.onap.usecaseui.intentanalysis.adapters.aai.apicall.AAIAPICall; +import org.onap.usecaseui.intentanalysis.adapters.policy.apicall.PolicyAPICall; +import org.onap.usecaseui.intentanalysis.adapters.so.apicall.SOAPICall; +import org.onap.usecaseui.intentanalysis.adapters.so.impl.SOServiceImpl; +import org.onap.usecaseui.intentanalysis.bean.models.CCVPNInstance; +import org.onap.usecaseui.intentanalysis.util.TestCall; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; +import retrofit2.Response; +import org.mockito.MockitoAnnotations; + +@SpringBootTest(classes = IntentAnalysisApplicationTests.class) +@RunWith(SpringRunner.class) +public class SOServiceTest { + + private CCVPNInstance ccvpnInstance; + + @Autowired + private SOServiceImpl soService; + + private SOAPICall soapiCall; + + private AAIAPICall aaiapiCall; + + @Before + public void init(){ + soService = new SOServiceImpl(); + ccvpnInstance = new CCVPNInstance(); + soapiCall = mock(SOAPICall.class); + soService.setSoApiCall(soapiCall); + aaiapiCall = mock(AAIAPICall.class); + soService.setAAIApiCall(aaiapiCall); + } + + @Test + public void testCreateCCVPNInstanceFailedCCVPNInstanceIsNull() throws IOException { + ccvpnInstance = null; + int result = soService.createCCVPNInstance(ccvpnInstance); + Assert.assertEquals(0, result); + } + + @Test + public void testCreateCCVPNInstanceFailedException() throws IOException { + int result = soService.createCCVPNInstance(ccvpnInstance); + Assert.assertEquals(0, result); + } + + @Test + public void testCreateCCVPNInstanceFailedJobIdNull() throws IOException { + JSONObject mockedSuccessJSONObject = mock(JSONObject.class); + when(soapiCall.createIntentInstance(any())).thenReturn(TestCall.successfulCall(mockedSuccessJSONObject)); + + int result = soService.createCCVPNInstance(ccvpnInstance); + Assert.assertEquals(0, result); + } + + @Test + public void testDeleteIntentInstanceFailed() throws IOException { + int result = soService.deleteIntentInstance(anyString()); + Assert.assertEquals(0, result); + } + + @Test + public void testDeleteIntentInstanceSuccess() throws IOException { + JSONObject mockedSuccessJSONObject = mock(JSONObject.class); + when(soapiCall.deleteIntentInstance(any())).thenReturn(TestCall.successfulCall(mockedSuccessJSONObject)); + + int result = soService.deleteIntentInstance("testId"); + Assert.assertEquals(1, result); + } + + @Test + public void testCreateCCVPNInstanceGetCreateStatusFailed() throws IOException { + JSONObject mockedSuccessJSONObject = mock(JSONObject.class); + when(soapiCall.createIntentInstance(any())).thenReturn(TestCall.successfulCall(mockedSuccessJSONObject)); + when(soapiCall.createIntentInstance(any()).execute().body().getString(anyString())).thenReturn("testJobId"); + when(aaiapiCall.getInstanceInfo(anyString())).thenReturn(TestCall.successfulCall(mockedSuccessJSONObject)); + + int result = soService.createCCVPNInstance(ccvpnInstance); + Assert.assertEquals(0, result); + } + + @Test + public void testCreateCCVPNInstanceSuccess() throws IOException { + JSONObject mockedSuccessJSONObject = mock(JSONObject.class); + when(soapiCall.createIntentInstance(any())).thenReturn(TestCall.successfulCall(mockedSuccessJSONObject)); + when(soapiCall.createIntentInstance(any()).execute().body().getString(anyString())).thenReturn("testJobId"); + when(aaiapiCall.getInstanceInfo(anyString())).thenReturn(TestCall.successfulCall(mockedSuccessJSONObject)); + when(aaiapiCall.getInstanceInfo(anyString()).execute().body().getString(anyString())).thenReturn("created"); + + int result = soService.createCCVPNInstance(ccvpnInstance); + Assert.assertEquals(1, result); + } +} |