diff options
author | Enbo Wang <wangenbo@huawei.com> | 2020-02-28 15:48:15 +0800 |
---|---|---|
committer | Enbo Wang <wangenbo@huawei.com> | 2020-03-01 22:55:38 +0800 |
commit | 904c1cfe90952407b197228f94050b0bdcee1dbb (patch) | |
tree | f49c332fcc00d37e0a3d4df94d3bf9b5fcd8aa80 /bpmn/MSOCommonBPMN | |
parent | ab9eb6aba42457ed9adb21d7239c7729bb26bd15 (diff) |
Support SDNC LCM Client
Issue-ID: SO-2588
Signed-off-by: Enbo Wang <wangenbo@huawei.com>
Change-Id: I631d0d6030acc5c6c3d63e3c77a37ea8730ffc8f
Diffstat (limited to 'bpmn/MSOCommonBPMN')
29 files changed, 2050 insertions, 1 deletions
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/restproperties/SDNCLcmPropertiesImpl.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/restproperties/SDNCLcmPropertiesImpl.java new file mode 100644 index 0000000000..eb2567d47c --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/restproperties/SDNCLcmPropertiesImpl.java @@ -0,0 +1,117 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.restproperties; + +import java.net.MalformedURLException; +import java.net.URL; +import org.onap.so.bpmn.core.UrnPropertiesReader; +import org.onap.so.client.sdnc.common.SDNCConstants; +import org.onap.so.client.sdnc.lcm.SDNCLcmProperties; + +public class SDNCLcmPropertiesImpl implements SDNCLcmProperties { + + public static final String SDNC_HOST = "sdnc.host"; + public static final String SDNC_AUTH = "sdnc.auth"; + public static final String LCM_PATH = "sdnc.lcm.path"; + + public static final String DMAAP_HOST = "sdnc.dmaap.host"; + public static final String DMAAP_AUTH = "sdnc.dmaap.auth"; + public static final String DMAAP_PARTITION = "sdnc.dmaap.partition"; + public static final String DMAAP_TIMEOUT = "sdnc.dmaap.timeout"; + public static final String DMAAP_ENVIRONMENT = "sdnc.dmaap.environment"; + public static final String LCM_DMAAP_READ_TOPIC = "sdnc.lcm.dmapp.readTopic"; + public static final String LCM_DMAAP_WRITE_TOPIC = "sdnc.lcm.dmaap.writeTopic"; + + public static final String MSO_KEY = "mso.msoKey"; + + public SDNCLcmPropertiesImpl() {} + + @Override + public String getHost() { + return UrnPropertiesReader.getVariable(SDNC_HOST); + } + + @Override + public String getPath() { + String path = UrnPropertiesReader.getVariable(LCM_PATH); + return (path != null) ? path : SDNCConstants.LCM_API_BASE_PATH; + } + + @Override + public String getBasicAuth() { + return UrnPropertiesReader.getVariable(SDNC_AUTH); + } + + @Override + public String getDmaapHost() { + return UrnPropertiesReader.getVariable(DMAAP_HOST); + } + + @Override + public String getDmaapAuth() { + return UrnPropertiesReader.getVariable(DMAAP_AUTH); + } + + @Override + public String getDmaapPartition() { + String partition = UrnPropertiesReader.getVariable(DMAAP_PARTITION); + return (partition != null) ? partition : SDNCConstants.LCM_DMAAP_PARTITION; + } + + @Override + public String getDmaapTimeout() { + String timeout = UrnPropertiesReader.getVariable(DMAAP_TIMEOUT); + return (timeout != null) ? timeout : SDNCConstants.LCM_DMAAP_TIMEOUT; + } + + @Override + public String getDmaapEnvironment() { + String environment = UrnPropertiesReader.getVariable(DMAAP_ENVIRONMENT); + return (environment != null) ? environment : SDNCConstants.LCM_DMAAP_ENVIRONMENT; + } + + @Override + public String getDmaaPLcmReadTopic() { + String readTopic = UrnPropertiesReader.getVariable(LCM_DMAAP_READ_TOPIC); + return (readTopic != null) ? readTopic : SDNCConstants.LCM_DMAAP_READ_TOPIC; + } + + @Override + public String getDmaaPLcmWriteTopic() { + String writeTopic = UrnPropertiesReader.getVariable(LCM_DMAAP_WRITE_TOPIC); + return (writeTopic != null) ? writeTopic : SDNCConstants.LCM_DMAAP_WRITE_TOPIC; + } + + @Override + public String getKey() { + return UrnPropertiesReader.getVariable(MSO_KEY); + } + + @Override + public URL getEndpoint() throws MalformedURLException { + return new URL(getHost()); + } + + @Override + public String getSystemName() { + return SDNCConstants.SYSTEM_NAME; + } +} diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/sdnc/common/SDNCConstants.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/sdnc/common/SDNCConstants.java new file mode 100644 index 0000000000..fd9412e70e --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/sdnc/common/SDNCConstants.java @@ -0,0 +1,49 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.sdnc.common; + +public interface SDNCConstants { + String SYSTEM_NAME = "MSO"; + + String LCM_API_VER = "2.00"; + + String LCM_FLAGS_MODE_NORMAL = "NORMAL"; + String LCM_FLAGS_MODE_EXCLUSIVE = "EXCLUSIVE"; + + String LCM_FLAGS_FORCE_TRUE = "TRUE"; + String LCM_FLAGS_FORCE_FALSE = "FALSE"; + + int LCM_FLAGS_TTL = 65000; + + String LCM_API_BASE_PATH = "/restconf/operations/LCM:"; + + String LCM_DMAAP_MSG_VER = "1.0"; + String LCM_DMAAP_MSG_TYPE_REQUEST = "request"; + String LCM_DMAAP_MSG_TYPE_RESPONSE = "response"; + + String LCM_DMAAP_PARTITION = "MSOLCM"; + String LCM_DMAAP_TIMEOUT = "20000"; + String LCM_DMAAP_ENVIRONMENT = "TEST"; + String LCM_DMAAP_READ_TOPIC = "SDNC-LCM-WRITE"; + String LCM_DMAAP_WRITE_TOPIC = "SDNC-LCM-READ"; + + int LCM_TIMEOUT = 300; +} diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/sdnc/lcm/SDNCLcmClientBuilder.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/sdnc/lcm/SDNCLcmClientBuilder.java new file mode 100644 index 0000000000..5616db3577 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/sdnc/lcm/SDNCLcmClientBuilder.java @@ -0,0 +1,77 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.sdnc.lcm; + +import java.net.URI; +import org.onap.so.client.RestPropertiesLoader; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SDNCLcmClientBuilder { + + private static Logger logger = LoggerFactory.getLogger(SDNCLcmClientBuilder.class); + + private final SDNCLcmProperties sdncLcmProperties; + + public SDNCLcmClientBuilder() { + sdncLcmProperties = RestPropertiesLoader.getInstance().getNewImpl(SDNCLcmProperties.class); + } + + public SDNCLcmClientBuilder(SDNCLcmProperties pros) { + sdncLcmProperties = pros; + } + + public SDNCLcmRestClient newSDNCLcmRestClient(String operation) throws SDNCLcmClientBuilderException { + URI pathUri; + try { + String path = sdncLcmProperties.getPath() + operation; + pathUri = new URI(path); + logger.debug("SDNC host: " + sdncLcmProperties.getHost()); + logger.debug("SDNC API path: " + pathUri.getPath()); + } catch (Exception e) { + String msg = "Error API path syntax: "; + logger.error(msg, e); + throw new SDNCLcmClientBuilderException(msg + e.toString()); + } + + try { + SDNCLcmRestClient sdncLcmRestClient = new SDNCLcmRestClient(sdncLcmProperties, pathUri); + logger.debug("Create SDNCLcmRestClient success"); + return sdncLcmRestClient; + } catch (Exception e) { + String msg = "Create SDNCLcmRestClient failure: "; + logger.error(msg, e); + throw new SDNCLcmClientBuilderException(msg + e.toString()); + } + } + + public SDNCLcmDmaapClient newSDNCLcmDmaapClient() throws SDNCLcmClientBuilderException { + try { + SDNCLcmDmaapClient sdncLcmDmaapClient = new SDNCLcmDmaapClient(sdncLcmProperties); + logger.debug("Create SDNCLcmDmaapClient success"); + return sdncLcmDmaapClient; + } catch (Exception e) { + String msg = "Create SDNCLcmDmaapClient failure: "; + logger.error(msg, e); + throw new SDNCLcmClientBuilderException(msg + e.toString()); + } + } +} diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/sdnc/lcm/SDNCLcmClientBuilderException.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/sdnc/lcm/SDNCLcmClientBuilderException.java new file mode 100644 index 0000000000..9160d4e352 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/sdnc/lcm/SDNCLcmClientBuilderException.java @@ -0,0 +1,30 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.sdnc.lcm; + +public class SDNCLcmClientBuilderException extends Exception { + + private static final long serialVersionUID = -1525705272349747712L; + + public SDNCLcmClientBuilderException(String message) { + super(message); + } +} diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/sdnc/lcm/SDNCLcmDmaapClient.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/sdnc/lcm/SDNCLcmDmaapClient.java new file mode 100644 index 0000000000..f6e4ffce59 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/sdnc/lcm/SDNCLcmDmaapClient.java @@ -0,0 +1,90 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.sdnc.lcm; + +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.onap.so.client.sdnc.lcm.beans.LcmDmaapRequest; +import org.onap.so.client.sdnc.lcm.beans.LcmDmaapResponse; +import org.onap.so.client.dmaap.rest.RestPublisher; +import org.onap.so.client.dmaap.rest.RestConsumer; + +public class SDNCLcmDmaapClient { + + private static Logger logger = LoggerFactory.getLogger(SDNCLcmDmaapClient.class); + + private RestPublisher dmaapPublisher; + private RestConsumer dmaapConsumer; + + public SDNCLcmDmaapClient(SDNCLcmProperties sdncLcmProperties) { + Properties properties = new Properties(); + + properties.put("host", sdncLcmProperties.getDmaapHost()); + if (sdncLcmProperties.getDmaapAuth() != null && sdncLcmProperties.getKey() != null) { + properties.put("auth", sdncLcmProperties.getDmaapAuth()); + properties.put("key", sdncLcmProperties.getKey()); + } + properties.put("partition", sdncLcmProperties.getDmaapPartition()); + properties.put("timeout", sdncLcmProperties.getDmaapTimeout()); + properties.put("environment", sdncLcmProperties.getDmaapEnvironment()); + + properties.put("topic", sdncLcmProperties.getDmaaPLcmWriteTopic()); + dmaapPublisher = new RestPublisher(properties); + + properties.put("topic", sdncLcmProperties.getDmaaPLcmReadTopic()); + dmaapConsumer = new RestConsumer(properties); + } + + public void sendRequest(LcmDmaapRequest lcmDmaapRequest) throws Exception { + ObjectMapper mapper = new ObjectMapper(); + String lcmRestRequestString = mapper.writeValueAsString(lcmDmaapRequest); + + dmaapPublisher.send(lcmRestRequestString); + } + + public Iterable<String> fetch() { + return dmaapConsumer.fetch(); + } + + public List<LcmDmaapResponse> getResponse() { + List<LcmDmaapResponse> responseList = new ArrayList<>(); + + ObjectMapper mapper = new ObjectMapper(); + Iterable<String> itrString = dmaapConsumer.fetch(); + for (String message : itrString) { + LcmDmaapResponse lcmDmaapResponse; + try { + lcmDmaapResponse = mapper.readValue(message, LcmDmaapResponse.class); + } catch (Exception e) { + logger.warn("Invalid SDNC LCM DMaaP response: " + message); + continue; + } + + responseList.add(lcmDmaapResponse); + } + + return responseList; + } +} diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/sdnc/lcm/SDNCLcmMessageBuilder.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/sdnc/lcm/SDNCLcmMessageBuilder.java new file mode 100644 index 0000000000..bf1229a310 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/sdnc/lcm/SDNCLcmMessageBuilder.java @@ -0,0 +1,87 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.sdnc.lcm; + +import java.time.Instant; +import org.onap.so.client.sdnc.common.SDNCConstants; +import org.onap.so.client.sdnc.lcm.beans.*; + +public class SDNCLcmMessageBuilder { + + public static LcmFlags getSDNCFlags() { + LcmFlags lcmFlags = new LcmFlags(); + + lcmFlags.setMode(SDNCConstants.LCM_FLAGS_MODE_NORMAL); + lcmFlags.setForce(SDNCConstants.LCM_FLAGS_FORCE_FALSE); + lcmFlags.setTtl(SDNCConstants.LCM_FLAGS_TTL); + + return lcmFlags; + } + + public static LcmCommonHeader buildLcmCommonHeader(String requestId, String subRequestId) { + LcmCommonHeader lcmCommonHeader = new LcmCommonHeader(); + + lcmCommonHeader.setApiVer(SDNCConstants.LCM_API_VER); + lcmCommonHeader.setOriginatorId(SDNCConstants.SYSTEM_NAME); + lcmCommonHeader.setRequestId(requestId); + lcmCommonHeader.setSubRequestId(subRequestId); + lcmCommonHeader.setFlags(getSDNCFlags()); + lcmCommonHeader.setTimestamp(Instant.now().toString()); + + return lcmCommonHeader; + } + + public static LcmInput buildLcmInputForPnf(String requestId, String subRequestId, String pnfName, String action, + String payload) { + LcmInput lcmInput = new LcmInput(); + + LcmCommonHeader lcmCommonHeader = buildLcmCommonHeader(requestId, subRequestId); + + LcmActionIdentifiers sdncActionIdentifiers = new LcmActionIdentifiers(); + sdncActionIdentifiers.setPnfName(pnfName); + + lcmInput.setCommonHeader(lcmCommonHeader); + lcmInput.setAction(action); + lcmInput.setActionIdentifiers(sdncActionIdentifiers); + lcmInput.setPayload(payload); + + return lcmInput; + } + + public static LcmDmaapRequest buildLcmDmaapRequest(String operation, LcmInput lcmInput) { + LcmDmaapRequest lcmDmaapRequest = new LcmDmaapRequest(); + + LcmRestRequest lcmRestRequest = new LcmRestRequest(); + lcmRestRequest.setInput(lcmInput); + + String correlationId = + lcmInput.getCommonHeader().getRequestId() + "-" + lcmInput.getCommonHeader().getSubRequestId(); + + lcmDmaapRequest.setVersion(SDNCConstants.LCM_DMAAP_MSG_VER); + lcmDmaapRequest.setType(SDNCConstants.LCM_DMAAP_MSG_TYPE_REQUEST); + lcmDmaapRequest.setCambriaPartition(SDNCConstants.SYSTEM_NAME); + lcmDmaapRequest.setCorrelationId(correlationId); + lcmDmaapRequest.setRpcName(operation); + lcmDmaapRequest.setBody(lcmRestRequest); + + return lcmDmaapRequest; + } +} diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/sdnc/lcm/SDNCLcmProperties.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/sdnc/lcm/SDNCLcmProperties.java new file mode 100644 index 0000000000..df5fb3be0b --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/sdnc/lcm/SDNCLcmProperties.java @@ -0,0 +1,47 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.sdnc.lcm; + +import org.onap.so.client.RestProperties; + +public interface SDNCLcmProperties extends RestProperties { + String getHost(); + + String getPath(); + + String getBasicAuth(); + + String getDmaapHost(); + + String getDmaapAuth(); + + String getDmaapPartition(); + + String getDmaapTimeout(); + + String getDmaapEnvironment(); + + String getDmaaPLcmReadTopic(); + + String getDmaaPLcmWriteTopic(); + + String getKey(); +} diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/sdnc/lcm/SDNCLcmRestClient.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/sdnc/lcm/SDNCLcmRestClient.java new file mode 100644 index 0000000000..3faf58ec28 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/sdnc/lcm/SDNCLcmRestClient.java @@ -0,0 +1,67 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.sdnc.lcm; + +import java.net.URI; +import java.util.Map; +import java.util.Optional; +import org.onap.so.client.RestClient; +import org.onap.logging.filter.base.ONAPComponents; +import org.onap.so.client.sdnc.lcm.beans.LcmInput; +import org.onap.so.client.sdnc.lcm.beans.LcmOutput; +import org.onap.so.client.sdnc.lcm.beans.LcmRestRequest; +import org.onap.so.client.sdnc.lcm.beans.LcmRestResponse; + +public class SDNCLcmRestClient extends RestClient { + + private final SDNCLcmProperties sdncLcmProperties; + + public SDNCLcmRestClient(SDNCLcmProperties props, URI path) { + this(props, path, "application/json", "application/json"); + } + + public SDNCLcmRestClient(SDNCLcmProperties props, URI path, String accept, String contentType) { + super(props, Optional.of(path), accept, contentType); + this.sdncLcmProperties = props; + } + + @Override + protected void initializeHeaderMap(Map<String, String> headerMap) { + headerMap.put("Authorization", sdncLcmProperties.getBasicAuth()); + } + + @Override + public ONAPComponents getTargetEntity() { + return ONAPComponents.SDNC; + } + + public LcmRestResponse sendRequest(LcmRestRequest lcmRestRequest) { + return post(lcmRestRequest, LcmRestResponse.class); + } + + public LcmOutput sendRequest(LcmInput lcmInput) { + LcmRestRequest lcmRestRequest = new LcmRestRequest(); + lcmRestRequest.setInput(lcmInput); + + LcmRestResponse lcmRestResponse = sendRequest(lcmRestRequest); + return lcmRestResponse.getOutput(); + } +} diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/sdnc/lcm/beans/LcmActionIdentifiers.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/sdnc/lcm/beans/LcmActionIdentifiers.java new file mode 100644 index 0000000000..883fd02c78 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/sdnc/lcm/beans/LcmActionIdentifiers.java @@ -0,0 +1,97 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.sdnc.lcm.beans; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({"serviceInstanceId", "vnfId", "vfModuleId", "vnfcName", "vserverId", "pnfName"}) +public class LcmActionIdentifiers { + + @JsonProperty("service-instance-id") + private String serviceInstanceId; + + @JsonProperty("vnf-id") + private String vnfId; + + @JsonProperty("vf-module-id") + private String vfModuleId; + + @JsonProperty("vnfc-name") + private String vnfcName; + + @JsonProperty("vserver-id") + private String vserverId; + + @JsonProperty("pnf-name") + private String pnfName; + + public String getServiceInstanceId() { + return serviceInstanceId; + } + + public void setServiceInstanceId(String value) { + this.serviceInstanceId = value; + } + + public String getVnfId() { + return vnfId; + } + + public void setVnfId(String value) { + this.vnfId = value; + } + + public String getVfModuleId() { + return vfModuleId; + } + + public void setVfModuleId(String value) { + this.vfModuleId = value; + } + + public String getVnfcName() { + return vnfcName; + } + + public void setVnfcName(String value) { + this.vnfcName = value; + } + + public String getVserverId() { + return vserverId; + } + + public void setVserverId(String value) { + this.vserverId = value; + } + + public String getPnfName() { + return pnfName; + } + + public void setPnfName(String value) { + this.pnfName = value; + } + +} diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/sdnc/lcm/beans/LcmCommonHeader.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/sdnc/lcm/beans/LcmCommonHeader.java new file mode 100644 index 0000000000..f3fd2ca11d --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/sdnc/lcm/beans/LcmCommonHeader.java @@ -0,0 +1,97 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.sdnc.lcm.beans; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({"apiVer", "flags", "originatorId", "requestId", "subRequestId", "timestamp"}) +public class LcmCommonHeader { + + @JsonProperty(value = "api-ver", required = true) + private String apiVer; + + @JsonProperty(value = "flags") + private LcmFlags flags; + + @JsonProperty(value = "originator-id", required = true) + private String originatorId; + + @JsonProperty(value = "request-id", required = true) + private String requestId; + + @JsonProperty(value = "sub-request-id") + private String subRequestId; + + @JsonProperty(value = "timestamp", required = true) + private String timestamp; + + public String getApiVer() { + return apiVer; + } + + public void setApiVer(String value) { + this.apiVer = value; + } + + public String getOriginatorId() { + return originatorId; + } + + public void setOriginatorId(String value) { + this.originatorId = value; + } + + public String getRequestId() { + return requestId; + } + + public void setRequestId(String value) { + this.requestId = value; + } + + public String getSubRequestId() { + return subRequestId; + } + + public void setSubRequestId(String value) { + this.subRequestId = value; + } + + public LcmFlags getFlags() { + return flags; + } + + public void setFlags(LcmFlags value) { + this.flags = value; + } + + public String getTimestamp() { + return timestamp; + } + + public void setTimestamp(String value) { + this.timestamp = value; + } + +} diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/sdnc/lcm/beans/LcmDmaapRequest.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/sdnc/lcm/beans/LcmDmaapRequest.java new file mode 100644 index 0000000000..db62e8b20b --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/sdnc/lcm/beans/LcmDmaapRequest.java @@ -0,0 +1,97 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.sdnc.lcm.beans; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({"version", "type", "cambriaPartition", "correlationId", "rpcName", "body"}) +public class LcmDmaapRequest { + + @JsonProperty(value = "version", required = true) + private String version; + + @JsonProperty(value = "type", required = true) + private String type; + + @JsonProperty(value = "cambria.partition", required = true) + private String cambriaPartition; + + @JsonProperty(value = "correlation-id", required = true) + private String correlationId; + + @JsonProperty(value = "rpc-name", required = true) + private String rpcName; + + @JsonProperty(value = "body") + private LcmRestRequest body; + + public String getVersion() { + return version; + } + + public void setVersion(String value) { + this.version = value; + } + + public String getType() { + return type; + } + + public void setType(String value) { + this.type = value; + } + + public String getCambriaPartition() { + return cambriaPartition; + } + + public void setCambriaPartition(String value) { + this.cambriaPartition = value; + } + + public String getCorrelationId() { + return correlationId; + } + + public void setCorrelationId(String value) { + this.correlationId = value; + } + + public String getRpcName() { + return rpcName; + } + + public void setRpcName(String value) { + this.rpcName = value; + } + + public LcmRestRequest getBody() { + return body; + } + + public void setBody(LcmRestRequest value) { + this.body = value; + } + +} diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/sdnc/lcm/beans/LcmDmaapResponse.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/sdnc/lcm/beans/LcmDmaapResponse.java new file mode 100644 index 0000000000..35f4a26b17 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/sdnc/lcm/beans/LcmDmaapResponse.java @@ -0,0 +1,97 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.sdnc.lcm.beans; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({"version", "type", "cambriaPartition", "correlationId", "rpcName", "body"}) +public class LcmDmaapResponse { + + @JsonProperty(value = "version", required = true) + private String version; + + @JsonProperty(value = "type", required = true) + private String type; + + @JsonProperty(value = "cambria.partition", required = true) + private String cambriaPartition; + + @JsonProperty(value = "correlation-id", required = true) + private String correlationId; + + @JsonProperty(value = "rpc-name", required = true) + private String rpcName; + + @JsonProperty(value = "body") + private LcmRestResponse body; + + public String getVersion() { + return version; + } + + public void setVersion(String value) { + this.version = value; + } + + public String getType() { + return type; + } + + public void setType(String value) { + this.type = value; + } + + public String getCambriaPartition() { + return cambriaPartition; + } + + public void setCambriaPartition(String value) { + this.cambriaPartition = value; + } + + public String getCorrelationId() { + return correlationId; + } + + public void setCorrelationId(String value) { + this.correlationId = value; + } + + public String getRpcName() { + return rpcName; + } + + public void setRpcName(String value) { + this.rpcName = value; + } + + public LcmRestResponse getBody() { + return body; + } + + public void setBody(LcmRestResponse value) { + this.body = value; + } + +} diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/sdnc/lcm/beans/LcmFlags.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/sdnc/lcm/beans/LcmFlags.java new file mode 100644 index 0000000000..36527ec887 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/sdnc/lcm/beans/LcmFlags.java @@ -0,0 +1,64 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.sdnc.lcm.beans; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({"mode", "force", "ttl"}) +public class LcmFlags { + + @JsonProperty("mode") + private String mode; + + @JsonProperty("force") + private String force; + + @JsonProperty("ttl") + private int ttl; + + public String getMode() { + return mode; + } + + public void setMode(String value) { + this.mode = value; + } + + public String getForce() { + return force; + } + + public void setForce(String value) { + this.force = value; + } + + public Integer getTtl() { + return ttl; + } + + public void setTtl(Integer value) { + this.ttl = value; + } + +} diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/sdnc/lcm/beans/LcmInput.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/sdnc/lcm/beans/LcmInput.java new file mode 100644 index 0000000000..6634430bed --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/sdnc/lcm/beans/LcmInput.java @@ -0,0 +1,75 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.sdnc.lcm.beans; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({"commonHeader", "action", "actionIdentifiers", "payload"}) +public class LcmInput { + + @JsonProperty(value = "common-header", required = true) + private LcmCommonHeader commonHeader; + + @JsonProperty(value = "action", required = true) + private String action; + + @JsonProperty(value = "action-identifiers", required = true) + private LcmActionIdentifiers actionIdentifiers; + + @JsonProperty(value = "payload") + private String payload; + + public LcmCommonHeader getCommonHeader() { + return commonHeader; + } + + public void setCommonHeader(LcmCommonHeader value) { + this.commonHeader = value; + } + + public String getAction() { + return action; + } + + public void setAction(String value) { + this.action = value; + } + + public LcmActionIdentifiers getActionIdentifiers() { + return actionIdentifiers; + } + + public void setActionIdentifiers(LcmActionIdentifiers value) { + this.actionIdentifiers = value; + } + + public String getPayload() { + return payload; + } + + public void setPayload(String value) { + this.payload = value; + } + +} diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/sdnc/lcm/beans/LcmOutput.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/sdnc/lcm/beans/LcmOutput.java new file mode 100644 index 0000000000..3741786671 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/sdnc/lcm/beans/LcmOutput.java @@ -0,0 +1,64 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.sdnc.lcm.beans; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({"commonHeader", "status", "payload"}) +public class LcmOutput { + + @JsonProperty(value = "common-header", required = true) + private LcmCommonHeader commonHeader; + + @JsonProperty(value = "status", required = true) + private LcmStatus status; + + @JsonProperty(value = "payload") + private String payload; + + public LcmCommonHeader getCommonHeader() { + return commonHeader; + } + + public void setCommonHeader(LcmCommonHeader value) { + this.commonHeader = value; + } + + public LcmStatus getStatus() { + return status; + } + + public void setStatus(LcmStatus value) { + this.status = value; + } + + public String getPayload() { + return payload; + } + + public void setPayload(String value) { + this.payload = value; + } + +} diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/sdnc/lcm/beans/LcmRestRequest.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/sdnc/lcm/beans/LcmRestRequest.java new file mode 100644 index 0000000000..146eb8a4f6 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/sdnc/lcm/beans/LcmRestRequest.java @@ -0,0 +1,42 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.sdnc.lcm.beans; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({"input"}) +public class LcmRestRequest { + + @JsonProperty(value = "input", required = true) + private LcmInput input; + + public LcmInput getInput() { + return input; + } + + public void setInput(LcmInput value) { + this.input = value; + } + +} diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/sdnc/lcm/beans/LcmRestResponse.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/sdnc/lcm/beans/LcmRestResponse.java new file mode 100644 index 0000000000..6920f95ce2 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/sdnc/lcm/beans/LcmRestResponse.java @@ -0,0 +1,42 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.sdnc.lcm.beans; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({"output"}) +public class LcmRestResponse { + + @JsonProperty(value = "output", required = true) + private LcmOutput output; + + public LcmOutput getOutput() { + return output; + } + + public void setOutput(LcmOutput value) { + this.output = value; + } + +} diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/sdnc/lcm/beans/LcmStatus.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/sdnc/lcm/beans/LcmStatus.java new file mode 100644 index 0000000000..8a2a142792 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/sdnc/lcm/beans/LcmStatus.java @@ -0,0 +1,53 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.sdnc.lcm.beans; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({"code", "message"}) +public class LcmStatus { + + @JsonProperty(value = "code", required = true) + private int code; + + @JsonProperty(value = "message", required = true) + private String message; + + public int getCode() { + return code; + } + + public void setCode(int value) { + this.code = value; + } + + public String getMessage() { + return message; + } + + public void setMessage(String value) { + this.message = value; + } + +} diff --git a/bpmn/MSOCommonBPMN/src/main/resources/META-INF/services/org.onap.so.client.RestProperties b/bpmn/MSOCommonBPMN/src/main/resources/META-INF/services/org.onap.so.client.RestProperties index 27da189456..147bc2ee95 100644 --- a/bpmn/MSOCommonBPMN/src/main/resources/META-INF/services/org.onap.so.client.RestProperties +++ b/bpmn/MSOCommonBPMN/src/main/resources/META-INF/services/org.onap.so.client.RestProperties @@ -1,3 +1,4 @@ org.onap.so.client.restproperties.AAIPropertiesImpl org.onap.so.client.restproperties.CDSPropertiesImpl -org.onap.so.client.restproperties.PolicyRestPropertiesImpl
\ No newline at end of file +org.onap.so.client.restproperties.PolicyRestPropertiesImpl +org.onap.so.client.restproperties.SDNCLcmPropertiesImpl diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/sdnc/lcm/SDNCLcmDmaapClientTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/sdnc/lcm/SDNCLcmDmaapClientTest.java new file mode 100644 index 0000000000..5483792a84 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/sdnc/lcm/SDNCLcmDmaapClientTest.java @@ -0,0 +1,139 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.sdnc.lcm; + +import java.util.List; +import org.apache.http.HttpStatus; +import com.fasterxml.jackson.core.JsonProcessingException; +import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.fail; +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.post; +import static com.github.tomakehurst.wiremock.client.WireMock.get; +import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; +import org.onap.so.BaseTest; +import org.onap.so.client.restproperties.SDNCLcmPropertiesImpl; +import org.onap.so.client.sdnc.lcm.beans.*; + +public class SDNCLcmDmaapClientTest extends BaseTest { + + protected SDNCLcmMessageBuilderTest sdncLcmMessageBuilderTest = new SDNCLcmMessageBuilderTest(); + + protected static final String DMAAP_HOST_PROP = SDNCLcmPropertiesImpl.DMAAP_HOST; + protected static final String DMAAP_WRITE_TOPIC_PROP = SDNCLcmPropertiesImpl.LCM_DMAAP_WRITE_TOPIC; + protected static final String DMAAP_READ_TOPIC_PROP = SDNCLcmPropertiesImpl.LCM_DMAAP_READ_TOPIC; + protected static final String DMAAP_PARTITION_PROP = SDNCLcmPropertiesImpl.DMAAP_PARTITION; + + protected String testWriteTopic = "TEST-WRITE-TOPIC"; + protected String testReadTopic = "TEST-READ-TOPIC"; + protected String testPartition = "TESTMSO"; + protected final String defaultConsumerName = "consumer1"; + + private void clearSystemProperty() { + System.clearProperty(DMAAP_HOST_PROP); + System.clearProperty(DMAAP_WRITE_TOPIC_PROP); + System.clearProperty(DMAAP_READ_TOPIC_PROP); + System.clearProperty(DMAAP_PARTITION_PROP); + } + + public SDNCLcmDmaapClient buildSDNCLcmDmaapClient() { + String testHost = "http://localhost:" + wireMockPort; + + System.setProperty(DMAAP_HOST_PROP, testHost); + System.setProperty(DMAAP_WRITE_TOPIC_PROP, testWriteTopic); + System.setProperty(DMAAP_READ_TOPIC_PROP, testReadTopic); + System.setProperty(DMAAP_PARTITION_PROP, testPartition); + + SDNCLcmProperties sdncLcmProperties = new SDNCLcmPropertiesImpl(); + SDNCLcmClientBuilder sdncLcmClientBuilder = new SDNCLcmClientBuilder(sdncLcmProperties); + + try { + return sdncLcmClientBuilder.newSDNCLcmDmaapClient(); + } catch (Exception e) { + clearSystemProperty(); + fail("Create SDNCLcmDmaapClient error: " + e.toString()); + return null; + } + } + + @Test + public final void testSDNCLcmDmaapClientSendRequest() { + SDNCLcmDmaapClient sdncLcmDmaapClient = buildSDNCLcmDmaapClient(); + + assertNotEquals(null, sdncLcmDmaapClient); + + String testDmaapWritePath = "/events/" + testWriteTopic; + String expectedWriteResponse = "{\"serverTimeMs\":2,\"count\":1}"; + wireMockServer.stubFor(post(urlPathEqualTo(testDmaapWritePath)) + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(expectedWriteResponse) + .withStatus(HttpStatus.SC_OK))); + + LcmInput lcmInput = sdncLcmMessageBuilderTest.buildLcmInputForPnf(); + LcmDmaapRequest lcmDmaapRequest = + SDNCLcmMessageBuilder.buildLcmDmaapRequest(sdncLcmMessageBuilderTest.getOperation(), lcmInput); + + try { + sdncLcmDmaapClient.sendRequest(lcmDmaapRequest); + } catch (Exception e) { + clearSystemProperty(); + fail("SDNCLcmDmaapClient sends request error: " + e.toString()); + return; + } + + String testDmaapReadPath = "/events/" + testReadTopic + "/" + testPartition + "/" + defaultConsumerName; + + String expectedLcmDmaapResponse = LcmDmaapResponseTest.getExpectedLcmDmaapResponse(); + String expectedResponseListItem; + try { + expectedResponseListItem = sdncLcmMessageBuilderTest.convertToSting(expectedLcmDmaapResponse); + } catch (JsonProcessingException e) { + clearSystemProperty(); + fail("Convert LcmDmaapResponse String to List item error: " + e.toString()); + return; + } + String expectedReadResponse = "[" + expectedResponseListItem + "]"; + wireMockServer.stubFor(get(urlPathEqualTo(testDmaapReadPath)) + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(expectedReadResponse) + .withStatus(HttpStatus.SC_OK))); + + List<LcmDmaapResponse> LcmDmaapResponseList = sdncLcmDmaapClient.getResponse(); + + clearSystemProperty(); + + if (LcmDmaapResponseList.size() < 1) { + clearSystemProperty(); + fail("Can not get LcmDmaapResponse list"); + return; + } + + LcmOutput lcmOutput = LcmDmaapResponseList.get(0).getBody().getOutput(); + + String expectedLcmOutput = LcmOutputTest.getExpectedLcmOutput(); + try { + String lcmOutputString = sdncLcmMessageBuilderTest.convertToSting(lcmOutput); + assertEquals(expectedLcmOutput, lcmOutputString); + } catch (Exception e) { + fail("Convert LcmOutput to String error: " + e.toString()); + } + } +} diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/sdnc/lcm/SDNCLcmMessageBuilderTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/sdnc/lcm/SDNCLcmMessageBuilderTest.java new file mode 100644 index 0000000000..d930c6728c --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/sdnc/lcm/SDNCLcmMessageBuilderTest.java @@ -0,0 +1,53 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.sdnc.lcm; + +import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; +import org.onap.so.client.sdnc.lcm.beans.LcmBeanTest; +import org.onap.so.client.sdnc.lcm.beans.LcmInput; +import org.onap.so.client.sdnc.lcm.beans.LcmInputTest; + +public class SDNCLcmMessageBuilderTest extends LcmBeanTest { + + public LcmInput buildLcmInputForPnf() { + LcmInput lcmInput = + SDNCLcmMessageBuilder.buildLcmInputForPnf(requestId, subRequestId, pnfName, action, inputPayload); + + lcmInput.getCommonHeader().setTimestamp(timestamp); + + return lcmInput; + } + + @Test + public final void testBuildLcmRestRequestForPnf() { + LcmInput lcmInput = buildLcmInputForPnf(); + + String expectedLcmInput = LcmInputTest.getExpectedLcmInput(); + try { + String lcmInputString = convertToSting(lcmInput); + assertEquals(expectedLcmInput, lcmInputString); + } catch (Exception e) { + fail("Convert LcmInput to String error: " + e.toString()); + } + } +} diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/sdnc/lcm/SDNCLcmRestClientTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/sdnc/lcm/SDNCLcmRestClientTest.java new file mode 100644 index 0000000000..04cfc6e3c8 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/sdnc/lcm/SDNCLcmRestClientTest.java @@ -0,0 +1,93 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.sdnc.lcm; + +import org.apache.http.HttpStatus; +import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.fail; +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.post; +import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; +import org.onap.logging.filter.base.ONAPComponents; +import org.onap.so.BaseTest; +import org.onap.so.client.restproperties.SDNCLcmPropertiesImpl; +import org.onap.so.client.sdnc.common.SDNCConstants; +import org.onap.so.client.sdnc.lcm.beans.*; + +public class SDNCLcmRestClientTest extends BaseTest { + + protected SDNCLcmMessageBuilderTest sdncLcmMessageBuilderTest = new SDNCLcmMessageBuilderTest(); + + protected static final String SDNC_HOST_PROP = SDNCLcmPropertiesImpl.SDNC_HOST; + protected static final String SDNC_PATH_PROP = SDNCLcmPropertiesImpl.LCM_PATH; + + private void clearSystemProperty() { + System.clearProperty(SDNC_HOST_PROP); + System.clearProperty(SDNC_PATH_PROP); + } + + public SDNCLcmRestClient buildSDNCLcmRestClient() { + String testHost = "http://localhost:" + wireMockPort; + + System.setProperty(SDNC_HOST_PROP, testHost); + System.setProperty(SDNC_PATH_PROP, SDNCConstants.LCM_API_BASE_PATH); + + SDNCLcmProperties sdncLcmProperties = new SDNCLcmPropertiesImpl(); + SDNCLcmClientBuilder sdncLcmClientBuilder = new SDNCLcmClientBuilder(sdncLcmProperties); + + try { + return sdncLcmClientBuilder.newSDNCLcmRestClient(sdncLcmMessageBuilderTest.getOperation()); + } catch (Exception e) { + clearSystemProperty(); + fail("Create SDNCLcmRestClient error: " + e.toString()); + return null; + } + } + + @Test + public final void testSDNCLcmRestClientSendRequest() { + SDNCLcmRestClient sdncLcmRestClient = buildSDNCLcmRestClient(); + + assertNotEquals(null, sdncLcmRestClient); + assertEquals(ONAPComponents.SDNC, sdncLcmRestClient.getTargetEntity()); + + String testLcmApiPath = SDNCConstants.LCM_API_BASE_PATH + sdncLcmMessageBuilderTest.getOperation(); + String expectedLcmRestResponse = LcmRestResponseTest.getExpectedLcmRestResponse(); + wireMockServer.stubFor(post(urlPathEqualTo(testLcmApiPath)) + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(expectedLcmRestResponse) + .withStatus(HttpStatus.SC_OK))); + + LcmInput lcmInput = sdncLcmMessageBuilderTest.buildLcmInputForPnf(); + LcmOutput lcmOutput = sdncLcmRestClient.sendRequest(lcmInput); + + clearSystemProperty(); + + String expectedLcmOutput = LcmOutputTest.getExpectedLcmOutput(); + try { + String lcmOutputString = sdncLcmMessageBuilderTest.convertToSting(lcmOutput); + assertEquals(expectedLcmOutput, lcmOutputString); + } catch (Exception e) { + fail("Convert LcmOutput to String error: " + e.toString()); + } + } +} diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/sdnc/lcm/beans/LcmBeanTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/sdnc/lcm/beans/LcmBeanTest.java new file mode 100644 index 0000000000..5562444a46 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/sdnc/lcm/beans/LcmBeanTest.java @@ -0,0 +1,78 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.sdnc.lcm.beans; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.onap.so.client.sdnc.common.SDNCConstants; + +public class LcmBeanTest { + private static Logger logger = LoggerFactory.getLogger(LcmBeanTest.class); + + protected String requestId = "9f77f437-1515-44bd-a420-0aaf8a3c31a0"; + protected String subRequestId = "c197a4b5-18d9-48a2-ad2d-a3b56858501c"; + protected String timestamp = "2020-02-25T10:20:28.116Z"; + + protected String pnfName = "testpnf"; + protected String action = "TestAction"; + protected String operation = "test-operation"; + + protected String inputPayload = "{\"testPayload\": \"input test\"}"; + protected String outputPayload = "{\"testPayload\": \"output test\"}"; + + public String getOperation() { + return operation; + } + + public LcmFlags buildSDNCFlags() { + LcmFlags lcmFlags = new LcmFlags(); + + lcmFlags.setMode(SDNCConstants.LCM_FLAGS_MODE_NORMAL); + lcmFlags.setForce(SDNCConstants.LCM_FLAGS_FORCE_FALSE); + lcmFlags.setTtl(SDNCConstants.LCM_FLAGS_TTL); + + return lcmFlags; + } + + public LcmCommonHeader buildLcmCommonHeader() { + LcmCommonHeader lcmCommonHeader = new LcmCommonHeader(); + + lcmCommonHeader.setApiVer(SDNCConstants.LCM_API_VER); + lcmCommonHeader.setFlags(buildSDNCFlags()); + lcmCommonHeader.setOriginatorId(SDNCConstants.SYSTEM_NAME); + lcmCommonHeader.setRequestId(requestId); + lcmCommonHeader.setSubRequestId(subRequestId); + lcmCommonHeader.setTimestamp(timestamp); + + return lcmCommonHeader; + } + + public String convertToSting(Object msgObject) throws JsonProcessingException { + ObjectMapper mapper = new ObjectMapper(); + + String msgString = mapper.writeValueAsString(msgObject); + logger.debug(msgObject.getClass().getSimpleName() + "\n" + msgString); + + return msgString; + } +} diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/sdnc/lcm/beans/LcmDmaapRequestTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/sdnc/lcm/beans/LcmDmaapRequestTest.java new file mode 100644 index 0000000000..709a557937 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/sdnc/lcm/beans/LcmDmaapRequestTest.java @@ -0,0 +1,67 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.sdnc.lcm.beans; + +import org.junit.Test; +import org.onap.so.client.sdnc.common.SDNCConstants; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +public class LcmDmaapRequestTest extends LcmBeanTest { + private static String expectedLcmDmaapRequest = "{" + "\"version\":\"1.0\"," + "\"type\":\"request\"," + + "\"cambria.partition\":\"MSO\"," + + "\"correlation-id\":\"9f77f437-1515-44bd-a420-0aaf8a3c31a0-c197a4b5-18d9-48a2-ad2d-a3b56858501c\"," + + "\"rpc-name\":\"test-operation\"," + "\"body\":" + LcmRestRequestTest.getExpectedLcmRestRequest() + "}"; + + public LcmDmaapRequest buildLcmDmaapRequest() { + LcmDmaapRequest lcmDmaapRequest = new LcmDmaapRequest(); + + LcmRestRequestTest lcmRestRequestTest = new LcmRestRequestTest(); + LcmRestRequest lcmRestRequest = lcmRestRequestTest.buildLcmRestRequest(); + LcmCommonHeader lcmCommonHeader = lcmRestRequest.getInput().getCommonHeader(); + String correlationId = lcmCommonHeader.getRequestId() + "-" + lcmCommonHeader.getSubRequestId(); + + lcmDmaapRequest.setVersion(SDNCConstants.LCM_DMAAP_MSG_VER); + lcmDmaapRequest.setType(SDNCConstants.LCM_DMAAP_MSG_TYPE_REQUEST); + lcmDmaapRequest.setCambriaPartition(SDNCConstants.SYSTEM_NAME); + lcmDmaapRequest.setCorrelationId(correlationId); + lcmDmaapRequest.setRpcName(operation); + lcmDmaapRequest.setBody(lcmRestRequest); + + return lcmDmaapRequest; + } + + public static String getExpectedLcmDmaapRequest() { + return expectedLcmDmaapRequest; + } + + @Test + public final void testLcmDmaapRequest() { + LcmDmaapRequest lcmDmaapRequest = buildLcmDmaapRequest(); + + try { + String lcmDmaapRequestString = convertToSting(lcmDmaapRequest); + assertEquals(expectedLcmDmaapRequest, lcmDmaapRequestString); + } catch (Exception e) { + fail("Convert LcmDmaapRequest to String error: " + e.toString()); + } + } +} diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/sdnc/lcm/beans/LcmDmaapResponseTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/sdnc/lcm/beans/LcmDmaapResponseTest.java new file mode 100644 index 0000000000..0cdbeebb27 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/sdnc/lcm/beans/LcmDmaapResponseTest.java @@ -0,0 +1,67 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.sdnc.lcm.beans; + +import org.junit.Test; +import org.onap.so.client.sdnc.common.SDNCConstants; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +public class LcmDmaapResponseTest extends LcmBeanTest { + private static String expectedLcmDmaapResponse = "{" + "\"version\":\"1.0\"," + "\"type\":\"response\"," + + "\"cambria.partition\":\"MSO\"," + + "\"correlation-id\":\"9f77f437-1515-44bd-a420-0aaf8a3c31a0-c197a4b5-18d9-48a2-ad2d-a3b56858501c\"," + + "\"rpc-name\":\"test-operation\"," + "\"body\":" + LcmRestResponseTest.getExpectedLcmRestResponse() + "}"; + + public LcmDmaapResponse buildLcmDmaapResponse() { + LcmDmaapResponse lcmDmaapResponse = new LcmDmaapResponse(); + + LcmRestResponseTest lcmRestResponseTest = new LcmRestResponseTest(); + LcmRestResponse lcmRestResponse = lcmRestResponseTest.buildLcmRestResponse(); + LcmCommonHeader lcmCommonHeader = lcmRestResponse.getOutput().getCommonHeader(); + String correlationId = lcmCommonHeader.getRequestId() + "-" + lcmCommonHeader.getSubRequestId(); + + lcmDmaapResponse.setVersion(SDNCConstants.LCM_DMAAP_MSG_VER); + lcmDmaapResponse.setType(SDNCConstants.LCM_DMAAP_MSG_TYPE_RESPONSE); + lcmDmaapResponse.setCambriaPartition(SDNCConstants.SYSTEM_NAME); + lcmDmaapResponse.setCorrelationId(correlationId); + lcmDmaapResponse.setRpcName(operation); + lcmDmaapResponse.setBody(lcmRestResponse); + + return lcmDmaapResponse; + } + + public static String getExpectedLcmDmaapResponse() { + return expectedLcmDmaapResponse; + } + + @Test + public final void testLcmDmaapResponse() { + LcmDmaapResponse lcmDmaapResponse = buildLcmDmaapResponse(); + + try { + String lcmDmaapResponseString = convertToSting(lcmDmaapResponse); + assertEquals(expectedLcmDmaapResponse, lcmDmaapResponseString); + } catch (Exception e) { + fail("Convert LcmDmaapResponse to String error: " + e.toString()); + } + } +} diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/sdnc/lcm/beans/LcmInputTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/sdnc/lcm/beans/LcmInputTest.java new file mode 100644 index 0000000000..b8c34fcbc7 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/sdnc/lcm/beans/LcmInputTest.java @@ -0,0 +1,67 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.sdnc.lcm.beans; + +import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +public class LcmInputTest extends LcmBeanTest { + private static String expectedLcmInput = "{" + "\"common-header\":{" + "\"api-ver\":\"2.00\"," + + "\"flags\":{\"mode\":\"NORMAL\",\"force\":\"FALSE\",\"ttl\":65000}," + "\"originator-id\":\"MSO\"," + + "\"request-id\":\"9f77f437-1515-44bd-a420-0aaf8a3c31a0\"," + + "\"sub-request-id\":\"c197a4b5-18d9-48a2-ad2d-a3b56858501c\"," + + "\"timestamp\":\"2020-02-25T10:20:28.116Z\"" + "}," + "\"action\":\"TestAction\"," + + "\"action-identifiers\":{\"pnf-name\":\"testpnf\"}," + + "\"payload\":\"{\\\"testPayload\\\": \\\"input test\\\"}\"}"; + + public LcmInput buildLcmInput() { + LcmInput lcmInput = new LcmInput(); + + LcmCommonHeader lcmCommonHeader = buildLcmCommonHeader(); + + LcmActionIdentifiers lcmActionIdentifiers = new LcmActionIdentifiers(); + lcmActionIdentifiers.setPnfName(pnfName); + + lcmInput.setCommonHeader(lcmCommonHeader); + lcmInput.setAction(action); + lcmInput.setActionIdentifiers(lcmActionIdentifiers); + lcmInput.setPayload(inputPayload); + + return lcmInput; + } + + public static String getExpectedLcmInput() { + return expectedLcmInput; + } + + @Test + public final void testLcmInput() { + LcmInput lcmInput = buildLcmInput(); + + try { + String lcmInputString = convertToSting(lcmInput); + assertEquals(expectedLcmInput, lcmInputString); + } catch (Exception e) { + fail("Convert LcmInput to String error: " + e.toString()); + } + } +} diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/sdnc/lcm/beans/LcmOutputTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/sdnc/lcm/beans/LcmOutputTest.java new file mode 100644 index 0000000000..1530be38a7 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/sdnc/lcm/beans/LcmOutputTest.java @@ -0,0 +1,84 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.sdnc.lcm.beans; + +import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; +import org.onap.so.client.sdnc.common.SDNCConstants; + +public class LcmOutputTest extends LcmBeanTest { + private static String expectedLcmOutput = "{" + "\"common-header\":{" + "\"api-ver\":\"2.00\"," + + "\"originator-id\":\"MSO\"," + "\"request-id\":\"9f77f437-1515-44bd-a420-0aaf8a3c31a0\"," + + "\"sub-request-id\":\"c197a4b5-18d9-48a2-ad2d-a3b56858501c\"" + "}," + + "\"status\":{\"code\":400,\"message\":\"Test output message\"}," + + "\"payload\":\"{\\\"testPayload\\\": \\\"output test\\\"}\"}"; + + @Override + public LcmCommonHeader buildLcmCommonHeader() { + LcmCommonHeader lcmCommonHeader = new LcmCommonHeader(); + + lcmCommonHeader.setApiVer(SDNCConstants.LCM_API_VER); + lcmCommonHeader.setOriginatorId(SDNCConstants.SYSTEM_NAME); + lcmCommonHeader.setRequestId(requestId); + lcmCommonHeader.setSubRequestId(subRequestId); + + return lcmCommonHeader; + } + + public LcmStatus buildLcmStatus() { + LcmStatus lcmStatus = new LcmStatus(); + + lcmStatus.setCode(400); + lcmStatus.setMessage("Test output message"); + + return lcmStatus; + } + + public LcmOutput buildLcmOutput() { + LcmOutput lcmOutput = new LcmOutput(); + + LcmCommonHeader lcmCommonHeader = buildLcmCommonHeader(); + LcmStatus lcmStatus = buildLcmStatus(); + + lcmOutput.setCommonHeader(lcmCommonHeader); + lcmOutput.setStatus(lcmStatus); + lcmOutput.setPayload(outputPayload); + + return lcmOutput; + } + + public static String getExpectedLcmOutput() { + return expectedLcmOutput; + } + + @Test + public final void testLcmOutput() { + LcmOutput lcmOutput = buildLcmOutput(); + + try { + String lcmOutputString = convertToSting(lcmOutput); + assertEquals(expectedLcmOutput, lcmOutputString); + } catch (Exception e) { + fail("Convert LcmOutput to String error: " + e.toString()); + } + } +} diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/sdnc/lcm/beans/LcmRestRequestTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/sdnc/lcm/beans/LcmRestRequestTest.java new file mode 100644 index 0000000000..c078326c82 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/sdnc/lcm/beans/LcmRestRequestTest.java @@ -0,0 +1,54 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.sdnc.lcm.beans; + +import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +public class LcmRestRequestTest extends LcmBeanTest { + private static String expectedLcmRestRequest = "{" + "\"input\":" + LcmInputTest.getExpectedLcmInput() + "}"; + + public LcmRestRequest buildLcmRestRequest() { + LcmRestRequest lcmRestRequest = new LcmRestRequest(); + + LcmInputTest lcmInputTest = new LcmInputTest(); + lcmRestRequest.setInput(lcmInputTest.buildLcmInput()); + + return lcmRestRequest; + } + + public static String getExpectedLcmRestRequest() { + return expectedLcmRestRequest; + } + + @Test + public final void testLcmRestRequest() { + LcmRestRequest lcmRestRequest = buildLcmRestRequest(); + + try { + String lcmRestRequestString = convertToSting(lcmRestRequest); + assertEquals(expectedLcmRestRequest, lcmRestRequestString); + } catch (Exception e) { + fail("Convert LcmRestRequest to String error: " + e.toString()); + } + } +} diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/sdnc/lcm/beans/LcmRestResponseTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/sdnc/lcm/beans/LcmRestResponseTest.java new file mode 100644 index 0000000000..5867acb421 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/sdnc/lcm/beans/LcmRestResponseTest.java @@ -0,0 +1,54 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.sdnc.lcm.beans; + +import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +public class LcmRestResponseTest extends LcmBeanTest { + private static String expectedLcmRestResponse = "{" + "\"output\":" + LcmOutputTest.getExpectedLcmOutput() + "}"; + + public LcmRestResponse buildLcmRestResponse() { + LcmRestResponse lcmRestResponse = new LcmRestResponse(); + + LcmOutputTest lcmOutputTest = new LcmOutputTest(); + lcmRestResponse.setOutput(lcmOutputTest.buildLcmOutput()); + + return lcmRestResponse; + } + + public static String getExpectedLcmRestResponse() { + return expectedLcmRestResponse; + } + + @Test + public final void testLcmRestResponse() { + LcmRestResponse lcmRestResponse = buildLcmRestResponse(); + + try { + String lcmRestResponseString = convertToSting(lcmRestResponse); + assertEquals(expectedLcmRestResponse, lcmRestResponseString); + } catch (Exception e) { + fail("Convert LcmRestResponse to String error: " + e.toString()); + } + } +} |