diff options
author | Hengye <yehui.wang@est.tech> | 2019-03-25 14:32:21 +0000 |
---|---|---|
committer | Hengye <yehui.wang@est.tech> | 2019-03-25 14:32:21 +0000 |
commit | b150aa8197e8a21ab7ad4cf1d91cfa30f56fa3df (patch) | |
tree | 60c296267f496f3b40d838294e8f80b04ceb2607 | |
parent | 2a245ef80e39a101015efb164de53f1753fa5d47 (diff) |
migrate model-impl from drools-applications
migrate controlloop/common/model-impl from drools-applicaitons to
policy/models
Issue-ID: POLICY-1264
Change-Id: Ibe0bb5c49a7b1344f4104b30455f52834041e187
Signed-off-by: Hengye <yehui.wang@est.tech>
275 files changed, 25221 insertions, 8 deletions
diff --git a/models-interactions/model-impl/aai/pom.xml b/models-interactions/model-impl/aai/pom.xml new file mode 100644 index 000000000..b086d2242 --- /dev/null +++ b/models-interactions/model-impl/aai/pom.xml @@ -0,0 +1,68 @@ +<!-- + ============LICENSE_START======================================================= + aai + ================================================================================ + Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + Modifications Copyright (C) 2019 Nordix Foundation. + ================================================================================ + 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========================================================= + --> + + +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.onap.policy.models.policy-models-interactions.model-impl</groupId> + <artifactId>model-impl</artifactId> + <version>2.0.0-SNAPSHOT</version> + </parent> + + <artifactId>aai</artifactId> + + <dependencies> + <dependency> + <groupId>com.google.code.gson</groupId> + <artifactId>gson</artifactId> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.onap.policy.models.policy-models-interactions.model-impl</groupId> + <artifactId>rest</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> + <version>2.13.0</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.powermock</groupId> + <artifactId>powermock-core</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.onap.policy.common</groupId> + <artifactId>policy-endpoints</artifactId> + <version>${policy.common.version}</version> + <scope>provided</scope> + </dependency> + </dependencies> +</project> diff --git a/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiGetResponse.java b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiGetResponse.java new file mode 100644 index 000000000..89b15b9cb --- /dev/null +++ b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiGetResponse.java @@ -0,0 +1,41 @@ +/*- + * ============LICENSE_START======================================================= + * aai + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.aai; + +import com.google.gson.annotations.SerializedName; +import java.io.Serializable; + +public class AaiGetResponse implements Serializable { + private static final long serialVersionUID = 7311418432051756162L; + + @SerializedName("requestError") + private AaiNqRequestError requestError; + + public AaiNqRequestError getRequestError() { + return requestError; + } + + public void setRequestError(AaiNqRequestError requestError) { + this.requestError = requestError; + } + +} diff --git a/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiGetVnfResponse.java b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiGetVnfResponse.java new file mode 100644 index 000000000..666f68d64 --- /dev/null +++ b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiGetVnfResponse.java @@ -0,0 +1,151 @@ +/*- + * ============LICENSE_START======================================================= + * aai + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file excthe License at + * ept in compliance with the License. + * You may obtain a copy of + * 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.policy.aai; + +import com.google.gson.annotations.SerializedName; +import java.io.Serializable; + +public class AaiGetVnfResponse extends AaiGetResponse implements Serializable { + + private static final long serialVersionUID = -6247505944905898871L; + + @SerializedName("vnf-id") + private String vnfId; + + @SerializedName("vnf-name") + private String vnfName; + + @SerializedName("vnf-type") + private String vnfType; + + @SerializedName("service-id") + private String serviceId; + + @SerializedName("orchestration-status") + private String orchestrationStatus; + + @SerializedName("in-maint") + private boolean inMaint; + + @SerializedName("is-closed-loop-disabled") + private boolean isClosedLoopDisabled; + + @SerializedName("model-invariant-id") + private String modelInvariantId; + + @SerializedName("prov-status") + private String provStatus; + + @SerializedName("resource-version") + private String resourceVersion; + + @SerializedName("relationship-list") + private RelationshipList relationshipList; + + public String getVnfId() { + return vnfId; + } + + public String getVnfName() { + return vnfName; + } + + public String getVnfType() { + return vnfType; + } + + public String getServiceId() { + return serviceId; + } + + public String getOrchestrationStatus() { + return orchestrationStatus; + } + + public boolean getInMaint() { + return inMaint; + } + + public boolean getIsClosedLoopDisabled() { + return isClosedLoopDisabled; + } + + public String getModelInvariantId() { + return modelInvariantId; + } + + public String getProvStatus() { + return provStatus; + } + + public String getResourceVersion() { + return resourceVersion; + } + + public RelationshipList getRelationshipList() { + return relationshipList; + } + + public void setVnfId(String vnfId) { + this.vnfId = vnfId; + } + + public void setVnfName(String vnfName) { + this.vnfName = vnfName; + } + + public void setVnfType(String vnfType) { + this.vnfType = vnfType; + } + + public void setServiceId(String serviceId) { + this.serviceId = serviceId; + } + + public void setOrchestrationStatus(String orchestrationStatus) { + this.orchestrationStatus = orchestrationStatus; + } + + public void setInMaint(boolean inMaint) { + this.inMaint = inMaint; + } + + public void setIsClosedLoopDisabled(boolean isClosedLoopDisabled) { + this.isClosedLoopDisabled = isClosedLoopDisabled; + } + + public void setModelInvariantId(String modelInvariantId) { + this.modelInvariantId = modelInvariantId; + } + + public void setProvStatus(String provStatus) { + this.provStatus = provStatus; + } + + public void setResourceVersion(String resourceVersion) { + this.resourceVersion = resourceVersion; + } + + public void setRelationshipList(RelationshipList relationshipList) { + this.relationshipList = relationshipList; + } +} diff --git a/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiGetVserverResponse.java b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiGetVserverResponse.java new file mode 100644 index 000000000..72adb9d02 --- /dev/null +++ b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiGetVserverResponse.java @@ -0,0 +1,44 @@ +/*- + * ============LICENSE_START======================================================= + * aai + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.aai; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; +import java.util.LinkedList; +import java.util.List; + +public class AaiGetVserverResponse extends AaiGetResponse implements Serializable { + + private static final long serialVersionUID = -6247505944905898871L; + + @SerializedName("vserver") + private List<AaiNqVServer> vserver = new LinkedList<>(); + + public List<AaiNqVServer> getVserver() { + return vserver; + } + + public void setVserver(List<AaiNqVServer> vserver) { + this.vserver = vserver; + } +} diff --git a/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiManager.java b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiManager.java new file mode 100644 index 000000000..bb772e6ca --- /dev/null +++ b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiManager.java @@ -0,0 +1,235 @@ +/*- + * ============LICENSE_START======================================================= + * aai + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019 Samsung Electronics Co., Ltd. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.aai; + +import com.google.gson.JsonSyntaxException; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +import org.onap.policy.aai.util.Serialization; +import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure; +import org.onap.policy.common.endpoints.utils.NetLoggerUtil; +import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType; +import org.onap.policy.rest.RestManager; +import org.onap.policy.rest.RestManager.Pair; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * This class handles communication towards and responses from A&AI for this module. + */ +public final class AaiManager { + + /** The Constant logger. */ + private static final Logger logger = LoggerFactory.getLogger(AaiManager.class); + + /** The rest manager. */ + // The REST manager used for processing REST calls for this AAI manager + private final RestManager restManager; + + /** + * Constructor, create the AAI manager with the specified REST manager. + * + * @param restManager the rest manager to use for REST calls + */ + public AaiManager(final RestManager restManager) { + this.restManager = restManager; + } + + /** + * Post a query to A&AI. + * + * @param url the A&AI URL + * @param username the user name for authentication + * @param password the password for authentication + * @param request the request to issue towards A&AI + * @param requestId the UUID of the request + * @return the response from A&AI + */ + public AaiNqResponse postQuery(String url, String username, String password, AaiNqRequest request, UUID requestId) { + + final Map<String, String> headers = createHeaders(requestId); + + url = url + "/aai/search/named-query"; + + logger.debug("RestManager.post before"); + String requestJson = Serialization.gsonPretty.toJson(request); + NetLoggerUtil.log(EventType.OUT, CommInfrastructure.REST, url, requestJson); + Pair<Integer, String> httpDetails = + restManager.post(url, username, password, headers, "application/json", requestJson); + logger.debug("RestManager.post after"); + + if (httpDetails == null) { + logger.info("AAI POST Null Response to {}", url); + return null; + } + + int httpResponseCode = httpDetails.first; + + logger.info(url); + logger.info("{}", httpResponseCode); + logger.info(httpDetails.second); + + if (httpDetails.second != null) { + return composeResponse(httpDetails, url, AaiNqResponse.class); + } + return null; + } + + /** + * Perform a GET request for a particular virtual server towards A&AI. + * + * @param urlGet the A&AI URL + * @param username the user name for authentication + * @param password the password for authentication + * @param requestId the UUID of the request + * @param key the key of the virtual server + * @return the response for the virtual server from A&AI + */ + public AaiGetVserverResponse getQueryByVserverName(String urlGet, String username, String password, UUID requestId, + String key) { + return getQuery(urlGet, username, password, requestId, key, AaiGetVserverResponse.class); + } + + /** + * Perform a GET request for a particular VNF by VNF ID towards A&AI. + * + * @param urlGet the A&AI URL + * @param username the user name for authentication + * @param password the password for authentication + * @param requestId the UUID of the request + * @param key the ID of the VNF + * @return the response for the virtual server from A&AI + */ + public AaiGetVnfResponse getQueryByVnfId(String urlGet, String username, String password, UUID requestId, + String key) { + return getQuery(urlGet, username, password, requestId, key, AaiGetVnfResponse.class); + } + + /** + * Perform a GET request for a particular VNF by VNF name towards A&AI. + * + * @param urlGet the A&AI URL + * @param username the user name for authentication + * @param password the password for authentication + * @param requestId the UUID of the request + * @param key the name of the VNF + * @return the response for the virtual server from A&AI + */ + public AaiGetVnfResponse getQueryByVnfName(String urlGet, String username, String password, UUID requestId, + String key) { + return getQuery(urlGet, username, password, requestId, key, AaiGetVnfResponse.class); + } + + /** + * Perform a GET query for a particular entity towards A&AI. + * + * @param <T> the generic type for the response + * @param urlGet the A&AI URL + * @param username the user name for authentication + * @param password the password for authentication + * @param requestId the UUID of the request + * @param key the name of the VNF + * @param classOfT the class of the response to return + * @return the response for the virtual server from A&AI + */ + private <T> T getQuery(final String url, final String username, final String password, final UUID requestId, + final String key, final Class<T> classOfResponse) { + + Map<String, String> headers = createHeaders(requestId); + + String urlGet = url + key; + + int attemptsLeft = 3; + + while (attemptsLeft-- > 0) { + NetLoggerUtil.getNetworkLogger().info("[OUT|{}|{}|]", CommInfrastructure.REST, urlGet); + Pair<Integer, String> httpDetailsGet = restManager.get(urlGet, username, password, headers); + if (httpDetailsGet == null) { + logger.info("AAI GET Null Response to {}", urlGet); + return null; + } + + int httpResponseCode = httpDetailsGet.first; + + logger.info(urlGet); + logger.info("{}", httpResponseCode); + logger.info(httpDetailsGet.second); + + if (httpResponseCode == 200) { + T responseGet = composeResponse(httpDetailsGet, urlGet, classOfResponse); + if (responseGet != null) { + return responseGet; + } + } + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } + + } + + return null; + } + + /** + * Create the headers for the HTTP request. + * + * @param requestId the request ID to insert in the headers + * @return the HTTP headers + */ + private Map<String, String> createHeaders(final UUID requestId) { + Map<String, String> headers = new HashMap<>(); + + headers.put("X-FromAppId", "POLICY"); + headers.put("X-TransactionId", requestId.toString()); + headers.put("Accept", "application/json"); + + return headers; + } + + /** + * This method uses Google's GSON to create a response object from a JSON string. + * + * @param <T> the generic type + * @param httpDetails the HTTP response + * @param url the URL from which the response came + * @param classOfResponse The response class + * @return an instance of the response class + * @throws JsonSyntaxException on GSON errors instantiating the response + */ + private <T> T composeResponse(final Pair<Integer, String> httpDetails, final String url, + final Class<T> classOfResponse) { + try { + T response = Serialization.gsonPretty.fromJson(httpDetails.second, classOfResponse); + NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, url, httpDetails.second); + return response; + } catch (JsonSyntaxException e) { + logger.error("postQuery threw: ", e); + return null; + } + } +} diff --git a/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqCloudRegion.java b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqCloudRegion.java new file mode 100644 index 000000000..ad910dcf3 --- /dev/null +++ b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqCloudRegion.java @@ -0,0 +1,86 @@ +/*- + * ============LICENSE_START======================================================= + * aai + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.aai; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; + +public class AaiNqCloudRegion implements Serializable { + + private static final long serialVersionUID = -897231529157222683L; + + @SerializedName("cloud-owner") + private String cloudOwner; + + @SerializedName("cloud-region-id") + private String cloudRegionId; + + @SerializedName("cloud-region-version") + private String cloudRegionVersion; + + @SerializedName("complex-name") + private String complexName; + + @SerializedName("resource-version") + private String resourceVersion; + + public String getCloudOwner() { + return cloudOwner; + } + + public String getCloudRegionId() { + return cloudRegionId; + } + + public String getCloudRegionVersion() { + return cloudRegionVersion; + } + + public String getComplexName() { + return complexName; + } + + public String getResourceVersion() { + return resourceVersion; + } + + public void setCloudOwner(String cloudOwner) { + this.cloudOwner = cloudOwner; + } + + public void setCloudRegionId(String cloudRegionId) { + this.cloudRegionId = cloudRegionId; + } + + public void setCloudRegionVersion(String cloudRegionVersion) { + this.cloudRegionVersion = cloudRegionVersion; + } + + public void setComplexName(String complexName) { + this.complexName = complexName; + } + + public void setResourceVersion(String resourceVersion) { + this.resourceVersion = resourceVersion; + } +} diff --git a/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqExtraProperties.java b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqExtraProperties.java new file mode 100644 index 000000000..c3139a342 --- /dev/null +++ b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqExtraProperties.java @@ -0,0 +1,43 @@ +/*- + * ============LICENSE_START======================================================= + * aai + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.aai; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; +import java.util.LinkedList; +import java.util.List; + +public class AaiNqExtraProperties implements Serializable { + private static final long serialVersionUID = 4109625574744702319L; + + @SerializedName("extra-property") + private List<AaiNqExtraProperty> extraProperty = new LinkedList<>(); + + public List<AaiNqExtraProperty> getExtraProperty() { + return extraProperty; + } + + public void setExtraProperty(List<AaiNqExtraProperty> extraProperty) { + this.extraProperty = extraProperty; + } +} diff --git a/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqExtraProperty.java b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqExtraProperty.java new file mode 100644 index 000000000..045e8fac9 --- /dev/null +++ b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqExtraProperty.java @@ -0,0 +1,60 @@ +/*- + * ============LICENSE_START======================================================= + * aai + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.aai; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; + +public class AaiNqExtraProperty implements Serializable { + + private static final long serialVersionUID = -3861240617222397736L; + + @SerializedName("property-name") + private String propertyName; + + @SerializedName("property-value") + private String propertyValue; + + public AaiNqExtraProperty() {} + + public AaiNqExtraProperty(String propertyName, String propertyValue) { + this.propertyName = propertyName; + this.propertyValue = propertyValue; + } + + public String getPropertyName() { + return propertyName; + } + + public String getPropertyValue() { + return propertyValue; + } + + public void setPropertyName(String propertyName) { + this.propertyName = propertyName; + } + + public void setPropertyValue(String propertyValue) { + this.propertyValue = propertyValue; + } +} diff --git a/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqGenericVnf.java b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqGenericVnf.java new file mode 100644 index 000000000..d67d02443 --- /dev/null +++ b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqGenericVnf.java @@ -0,0 +1,228 @@ +/*- + * ============LICENSE_START======================================================= + * aai + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.aai; + +import com.google.gson.annotations.SerializedName; +import java.io.Serializable; + +public class AaiNqGenericVnf implements Serializable { + + private static final long serialVersionUID = 834322706248060560L; + + @SerializedName("vnf-id") + private String vnfId; + + @SerializedName("vnf-name") + private String vnfName; + + @SerializedName("vnf-name2") + private String vnfName2; + + @SerializedName("vnf-type") + private String vnfType; + + @SerializedName("service-id") + private String serviceId; + + @SerializedName("prov-status") + private String provStatus; + + @SerializedName("operational-state") + private String operationalState; + + @SerializedName("ipv4-oam-address") + private String ipv4OamAddress; + + @SerializedName("ipv4-loopback0-address") + private String ipv4Loopback0Address; + + @SerializedName("in-maint") + private Boolean inMaint; + + @SerializedName("is-closed-loop-disabled") + private Boolean isClosedLoopDisabled; + + @SerializedName("resource-version") + private String resourceVersion; + + @SerializedName("encrypted-access-flag") + private Boolean encrypedAccessFlag; + + @SerializedName("persona-model-id") + private String personaModelId; + + @SerializedName("persona-model-version") + private String personaModelVersion; + + @SerializedName("model-invariant-id") + private String modelInvariantId; + + @SerializedName("model-version-id") + private String modelVersionId; + + @SerializedName("model-customization-id") + private String modelCustomizationId = null; + + public String getVnfId() { + return vnfId; + } + + public String getVnfName() { + return vnfName; + } + + public String getVnfName2() { + return vnfName2; + } + + public String getVnfType() { + return vnfType; + } + + public String getServiceId() { + return serviceId; + } + + public String getProvStatus() { + return provStatus; + } + + public String getOperationalState() { + return operationalState; + } + + public String getIpv4OamAddress() { + return ipv4OamAddress; + } + + public String getIpv4Loopback0Address() { + return ipv4Loopback0Address; + } + + public Boolean getInMaint() { + return inMaint; + } + + public Boolean getIsClosedLoopDisabled() { + return isClosedLoopDisabled; + } + + public String getResourceVersion() { + return resourceVersion; + } + + public Boolean getEncrypedAccessFlag() { + return encrypedAccessFlag; + } + + public String getPersonaModelId() { + return personaModelId; + } + + public String getPersonaModelVersion() { + return personaModelVersion; + } + + public String getModelInvariantId() { + return modelInvariantId; + } + + public String getModelVersionId() { + return modelVersionId; + } + + public String getModelCustomizationId() { + return modelCustomizationId; + } + + public void setVnfId(String vnfId) { + this.vnfId = vnfId; + } + + public void setVnfName(String vnfName) { + this.vnfName = vnfName; + } + + public void setVnfName2(String vnfName2) { + this.vnfName2 = vnfName2; + } + + public void setVnfType(String vnfType) { + this.vnfType = vnfType; + } + + public void setServiceId(String serviceId) { + this.serviceId = serviceId; + } + + public void setProvStatus(String provStatus) { + this.provStatus = provStatus; + } + + public void setOperationalState(String operationalState) { + this.operationalState = operationalState; + } + + public void setIpv4OamAddress(String ipv4OamAddress) { + this.ipv4OamAddress = ipv4OamAddress; + } + + public void setIpv4Loopback0Address(String ipv4Loopback0Address) { + this.ipv4Loopback0Address = ipv4Loopback0Address; + } + + public void setInMaint(Boolean inMaint) { + this.inMaint = inMaint; + } + + public void setIsClosedLoopDisabled(Boolean isClosedLoopDisabled) { + this.isClosedLoopDisabled = isClosedLoopDisabled; + } + + public void setResourceVersion(String resourceVersion) { + this.resourceVersion = resourceVersion; + } + + public void setEncrypedAccessFlag(Boolean encrypedAccessFlag) { + this.encrypedAccessFlag = encrypedAccessFlag; + } + + public void setPersonaModelId(String personaModelId) { + this.personaModelId = personaModelId; + } + + public void setPersonaModelVersion(String personaModelVersion) { + this.personaModelVersion = personaModelVersion; + } + + public void setModelInvariantId(String modelInvariantId) { + this.modelInvariantId = modelInvariantId; + } + + public void setModelVersionId(String modelVersionId) { + this.modelVersionId = modelVersionId; + } + + public void setModelCustomizationId(String modelCustomizationId) { + this.modelCustomizationId = modelCustomizationId; + } +} diff --git a/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqInstanceFilters.java b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqInstanceFilters.java new file mode 100644 index 000000000..8719f6ff2 --- /dev/null +++ b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqInstanceFilters.java @@ -0,0 +1,45 @@ +/*- + * ============LICENSE_START======================================================= + * aai + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.aai; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +public class AaiNqInstanceFilters implements Serializable { + + private static final long serialVersionUID = 8993824591338121185L; + + @SerializedName("instance-filter") + private List<Map<String, Map<String, String>>> instanceFilter = new LinkedList<>(); + + public List<Map<String, Map<String, String>>> getInstanceFilter() { + return instanceFilter; + } + + public void setInstanceFilter(List<Map<String, Map<String, String>>> instanceFilter) { + this.instanceFilter = instanceFilter; + } +} diff --git a/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqInventoryResponseItem.java b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqInventoryResponseItem.java new file mode 100644 index 000000000..4ba9091fb --- /dev/null +++ b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqInventoryResponseItem.java @@ -0,0 +1,130 @@ +/*- + * ============LICENSE_START======================================================= + * aai + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.aai; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; + +public class AaiNqInventoryResponseItem implements Serializable { + + private static final long serialVersionUID = 7142072567154675183L; + + @SerializedName("model-name") + private String modelName; + + @SerializedName("vf-module") + private AaiNqVfModule vfModule; + + @SerializedName("service-instance") + private AaiNqServiceInstance serviceInstance; + + @SerializedName("vserver") + private AaiNqVServer vserver; + + @SerializedName("tenant") + private AaiNqTenant tenant; + + @SerializedName("cloud-region") + private AaiNqCloudRegion cloudRegion; + + @SerializedName("generic-vnf") + private AaiNqGenericVnf genericVnf; + + @SerializedName("extra-properties") + private AaiNqExtraProperties extraProperties; + + @SerializedName("inventory-response-items") + private AaiNqInventoryResponseItems items; + + public String getModelName() { + return modelName; + } + + public AaiNqVfModule getVfModule() { + return vfModule; + } + + public AaiNqServiceInstance getServiceInstance() { + return serviceInstance; + } + + public AaiNqVServer getVserver() { + return vserver; + } + + public AaiNqTenant getTenant() { + return tenant; + } + + public AaiNqCloudRegion getCloudRegion() { + return cloudRegion; + } + + public AaiNqGenericVnf getGenericVnf() { + return genericVnf; + } + + public AaiNqExtraProperties getExtraProperties() { + return extraProperties; + } + + public AaiNqInventoryResponseItems getItems() { + return items; + } + + public void setModelName(String modelName) { + this.modelName = modelName; + } + + public void setVfModule(AaiNqVfModule vfModule) { + this.vfModule = vfModule; + } + + public void setServiceInstance(AaiNqServiceInstance serviceInstance) { + this.serviceInstance = serviceInstance; + } + + public void setVserver(AaiNqVServer vserver) { + this.vserver = vserver; + } + + public void setTenant(AaiNqTenant tenant) { + this.tenant = tenant; + } + + public void setCloudRegion(AaiNqCloudRegion cloudRegion) { + this.cloudRegion = cloudRegion; + } + + public void setGenericVnf(AaiNqGenericVnf genericVnf) { + this.genericVnf = genericVnf; + } + + public void setExtraProperties(AaiNqExtraProperties extraProperties) { + this.extraProperties = extraProperties; + } + + public void setItems(AaiNqInventoryResponseItems items) { + this.items = items; + } +} diff --git a/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqInventoryResponseItems.java b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqInventoryResponseItems.java new file mode 100644 index 000000000..7d2a07787 --- /dev/null +++ b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqInventoryResponseItems.java @@ -0,0 +1,43 @@ +/*- + * ============LICENSE_START======================================================= + * aai + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.aai; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; +import java.util.LinkedList; +import java.util.List; + +public class AaiNqInventoryResponseItems implements Serializable { + private static final long serialVersionUID = 7602807659381179004L; + + @SerializedName("inventory-response-item") + private List<AaiNqInventoryResponseItem> inventoryResponseItems = new LinkedList<>(); + + public List<AaiNqInventoryResponseItem> getInventoryResponseItems() { + return inventoryResponseItems; + } + + public void setInventoryResponseItems(List<AaiNqInventoryResponseItem> inventoryResponseItems) { + this.inventoryResponseItems = inventoryResponseItems; + } +} diff --git a/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqNamedQuery.java b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqNamedQuery.java new file mode 100644 index 000000000..fc6442847 --- /dev/null +++ b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqNamedQuery.java @@ -0,0 +1,42 @@ +/*- + * ============LICENSE_START======================================================= + * aai + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.aai; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; +import java.util.UUID; + +public class AaiNqNamedQuery implements Serializable { + private static final long serialVersionUID = -3277980060302645333L; + + @SerializedName("named-query-uuid") + private UUID namedQueryUuid; + + public UUID getNamedQueryUuid() { + return namedQueryUuid; + } + + public void setNamedQueryUuid(UUID namedQueryUuid) { + this.namedQueryUuid = namedQueryUuid; + } +} diff --git a/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqQueryParameters.java b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqQueryParameters.java new file mode 100644 index 000000000..9173fcdd5 --- /dev/null +++ b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqQueryParameters.java @@ -0,0 +1,41 @@ +/*- + * ============LICENSE_START======================================================= + * aai + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.aai; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; + +public class AaiNqQueryParameters implements Serializable { + private static final long serialVersionUID = -4291227193197126982L; + + @SerializedName("named-query") + private AaiNqNamedQuery namedQuery; + + public AaiNqNamedQuery getNamedQuery() { + return namedQuery; + } + + public void setNamedQuery(AaiNqNamedQuery namedQuery) { + this.namedQuery = namedQuery; + } +} diff --git a/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqRequest.java b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqRequest.java new file mode 100644 index 000000000..643754f9d --- /dev/null +++ b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqRequest.java @@ -0,0 +1,52 @@ +/*- + * ============LICENSE_START======================================================= + * aai + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.aai; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; + +public class AaiNqRequest implements Serializable { + private static final long serialVersionUID = -3283942659786236032L; + + @SerializedName("query-parameters") + private AaiNqQueryParameters queryParameters; + + @SerializedName("instance-filters") + private AaiNqInstanceFilters instanceFilters; + + public AaiNqQueryParameters getQueryParameters() { + return queryParameters; + } + + public AaiNqInstanceFilters getInstanceFilters() { + return instanceFilters; + } + + public void setQueryParameters(AaiNqQueryParameters queryParameters) { + this.queryParameters = queryParameters; + } + + public void setInstanceFilters(AaiNqInstanceFilters instanceFilters) { + this.instanceFilters = instanceFilters; + } +} diff --git a/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqRequestError.java b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqRequestError.java new file mode 100644 index 000000000..6ae437232 --- /dev/null +++ b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqRequestError.java @@ -0,0 +1,41 @@ +/*- + * ============LICENSE_START======================================================= + * aai + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.aai; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; + +public class AaiNqRequestError implements Serializable { + private static final long serialVersionUID = -7742674155387022932L; + + @SerializedName("serviceException") + private AaiNqServiceExcept serviceExcept; + + public AaiNqServiceExcept getServiceExcept() { + return serviceExcept; + } + + public void setServiceExcept(AaiNqServiceExcept serviceExcept) { + this.serviceExcept = serviceExcept; + } +} diff --git a/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqResponse.java b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqResponse.java new file mode 100644 index 000000000..b823ceafb --- /dev/null +++ b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqResponse.java @@ -0,0 +1,54 @@ +/*- + * ============LICENSE_START======================================================= + * aai + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.aai; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; +import java.util.LinkedList; +import java.util.List; + +public class AaiNqResponse implements Serializable { + private static final long serialVersionUID = 8411407444051746101L; + + @SerializedName("inventory-response-item") + private List<AaiNqInventoryResponseItem> inventoryResponseItems = new LinkedList<>(); + + @SerializedName("requestError") + private AaiNqRequestError requestError; + + public List<AaiNqInventoryResponseItem> getInventoryResponseItems() { + return inventoryResponseItems; + } + + public AaiNqRequestError getRequestError() { + return requestError; + } + + public void setRequestError(AaiNqRequestError requestError) { + this.requestError = requestError; + } + + public void setInventoryResponseItems(List<AaiNqInventoryResponseItem> inventoryResponseItems) { + this.inventoryResponseItems = inventoryResponseItems; + } +} diff --git a/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqResponseWrapper.java b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqResponseWrapper.java new file mode 100644 index 000000000..68d07270a --- /dev/null +++ b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqResponseWrapper.java @@ -0,0 +1,153 @@ +/*- + * ============LICENSE_START======================================================= + * aai + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.aai; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.UUID; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class AaiNqResponseWrapper implements Serializable { + private static final long serialVersionUID = 8411407444051746101L; + + private static final Logger logger = LoggerFactory.getLogger(AaiNqResponseWrapper.class); + + private static final Pattern VF_MODULE_NAME_PAT = Pattern.compile("(.*_)(\\d+)"); + + private UUID requestId; + private AaiNqResponse aaiNqResponse; + + public AaiNqResponseWrapper() {} + + public AaiNqResponseWrapper(UUID requestId, AaiNqResponse aaiNqResponse) { + this.requestId = requestId; + this.aaiNqResponse = aaiNqResponse; + } + + public UUID getRequestId() { + return requestId; + } + + public void setRequestId(UUID requestId) { + this.requestId = requestId; + } + + public AaiNqResponse getAaiNqResponse() { + return aaiNqResponse; + } + + public void setAaiNqResponse(AaiNqResponse aaiNqResponse) { + this.aaiNqResponse = aaiNqResponse; + } + + /** + * Counts the number of VF modules, if any, in the response. + * + * @return the number of VF modules, or {@code 0} if there are none + */ + public int countVfModules() { + return getVfModuleItems(false).size(); + } + + /** + * Generates the name for the next VF module. + * + * @return the name of the next VF module, or {@code null} if the name could not be + * generated (i.e., because the response has no matching VF module names on + * which to model it) + */ + public String genVfModuleName() { + /* + * Loop through the VF modules, extracting the name prefix and the largest number + * suffix + */ + String prefix = null; + int maxSuffix = -1; + + for (AaiNqInventoryResponseItem item : getVfModuleItems(false)) { + String name = item.getVfModule().getVfModuleName(); + Matcher matcher = VF_MODULE_NAME_PAT.matcher(name); + if (matcher.matches()) { + int suffix = Integer.parseInt(matcher.group(2)); + if (suffix > maxSuffix) { + maxSuffix = suffix; + prefix = matcher.group(1); + } + } + } + + ++maxSuffix; + + return (prefix == null ? null : prefix + maxSuffix); + } + + /** + * Gets a list of VF modules. If the non-base VF modules are requested, then only + * those whose names match the name pattern, {@link #VF_MODULE_NAME_PAT}, are + * returned. + * + * @param wantBaseModule {@code true} if the the base VF module(s) is desired, + * {@code false} otherwise + * @return the list of VF module items + */ + public List<AaiNqInventoryResponseItem> getVfModuleItems(boolean wantBaseModule) { + // get the list of items + List<AaiNqInventoryResponseItem> itemList; + try { + itemList = aaiNqResponse.getInventoryResponseItems().get(0).getItems().getInventoryResponseItems().get(0) + .getItems().getInventoryResponseItems(); + + } catch (NullPointerException | IndexOutOfBoundsException e) { + logger.debug("no VF modules in AAI response", e); + return Collections.emptyList(); + } + + if (itemList == null) { + return Collections.emptyList(); + } + + /* + * Walk the items looking for VF modules, allocating the list only when an item is + * found. + */ + List<AaiNqInventoryResponseItem> vfModuleItems = new ArrayList<>(itemList.size()); + + for (AaiNqInventoryResponseItem inventoryResponseItem : itemList) { + AaiNqVfModule vfmod = inventoryResponseItem.getVfModule(); + if (vfmod == null) { + continue; + } + + if (vfmod.getIsBaseVfModule() == wantBaseModule + && (wantBaseModule || VF_MODULE_NAME_PAT.matcher(vfmod.getVfModuleName()).matches())) { + vfModuleItems.add(inventoryResponseItem); + } + } + + return vfModuleItems; + } +} diff --git a/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqServiceExcept.java b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqServiceExcept.java new file mode 100644 index 000000000..7b6c50257 --- /dev/null +++ b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqServiceExcept.java @@ -0,0 +1,51 @@ +/*- + * ============LICENSE_START======================================================= + * aai + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.aai; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; + +public class AaiNqServiceExcept implements Serializable { + private static final long serialVersionUID = 2858343404484338546L; + + @SerializedName("messageId") + private String messageId; + + @SerializedName("text") + private String text; + + @SerializedName("variables") + private String[] variables; + + public String getMessageId() { + return messageId; + } + + public String getText() { + return text; + } + + public String[] getVariables() { + return variables; + } +} diff --git a/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqServiceInstance.java b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqServiceInstance.java new file mode 100644 index 000000000..2f48ad85d --- /dev/null +++ b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqServiceInstance.java @@ -0,0 +1,118 @@ +/*- + * ============LICENSE_START======================================================= + * aai + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.aai; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; + +public class AaiNqServiceInstance implements Serializable { + private static final long serialVersionUID = -8000944396593889586L; + + @SerializedName("service-instance-id") + private String serviceInstanceId; + + @SerializedName("service-instance-name") + private String serviceInstanceName; + + @SerializedName("persona-model-id") + private String personaModelId; + + @SerializedName("persona-model-version") + private String personaModelVersion; + + @SerializedName("service-instance-location-id") + private String serviceInstanceLocationId; + + @SerializedName("resource-version") + private String resourceVersion; + + @SerializedName("model-invariant-id") + private String modelInvariantId; + + @SerializedName("model-version-id") + private String modelVersionId; + + public String getServiceInstanceId() { + return serviceInstanceId; + } + + public String getServiceInstanceName() { + return serviceInstanceName; + } + + public String getPersonaModelId() { + return personaModelId; + } + + public String getPersonaModelVersion() { + return personaModelVersion; + } + + public String getServiceInstanceLocationId() { + return serviceInstanceLocationId; + } + + public String getResourceVersion() { + return resourceVersion; + } + + public String getModelInvariantId() { + return modelInvariantId; + } + + public String getModelVersionId() { + return modelVersionId; + } + + public void setServiceInstanceId(String serviceInstanceId) { + this.serviceInstanceId = serviceInstanceId; + } + + public void setServiceInstanceName(String serviceInstanceName) { + this.serviceInstanceName = serviceInstanceName; + } + + public void setPersonaModelId(String personaModelId) { + this.personaModelId = personaModelId; + } + + public void setPersonaModelVersion(String personaModelVersion) { + this.personaModelVersion = personaModelVersion; + } + + public void setServiceInstanceLocationId(String serviceInstanceLocationId) { + this.serviceInstanceLocationId = serviceInstanceLocationId; + } + + public void setResourceVersion(String resourceVersion) { + this.resourceVersion = resourceVersion; + } + + public void setModelInvariantId(String modelInvariantId) { + this.modelInvariantId = modelInvariantId; + } + + public void setModelVersionId(String modelVersionId) { + this.modelVersionId = modelVersionId; + } +} diff --git a/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqTenant.java b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqTenant.java new file mode 100644 index 000000000..129c05933 --- /dev/null +++ b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqTenant.java @@ -0,0 +1,65 @@ +/*- + * ============LICENSE_START======================================================= + * aai + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.aai; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; + +public class AaiNqTenant implements Serializable { + private static final long serialVersionUID = 4702784101671984364L; + + @SerializedName("tenant-id") + private String tenantId; + + @SerializedName("tenant-name") + private String tenantName; + + @SerializedName("resource-version") + private String resourceVersion; + + public String getTenantId() { + return tenantId; + } + + public String getTenantName() { + return tenantName; + } + + public String getResourceVersion() { + return resourceVersion; + } + + public void setTenantId(String tenantId) { + this.tenantId = tenantId; + } + + public void setTenantName(String tenantName) { + this.tenantName = tenantName; + } + + public void setResourceVersion(String resourceVersion) { + this.resourceVersion = resourceVersion; + } + + +} diff --git a/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqVServer.java b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqVServer.java new file mode 100644 index 000000000..a7286ce8a --- /dev/null +++ b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqVServer.java @@ -0,0 +1,130 @@ +/* + * ============LICENSE_START======================================================= + * aai + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.aai; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; + +public class AaiNqVServer implements Serializable { + private static final long serialVersionUID = -6718526692734215643L; + + @SerializedName("vserver-id") + private String vserverId; + + @SerializedName("vserver-name") + private String vserverName; + + @SerializedName("vserver-name2") + private String vserverName2; + + @SerializedName("prov-status") + private String provStatus; + + @SerializedName("vserver-selflink") + private String vserverSelflink; + + @SerializedName("in-maint") + private Boolean inMaint; + + @SerializedName("is-closed-loop-disabled") + private Boolean isClosedLoopDisabled; + + @SerializedName("resource-version") + private String resourceVersion; + + @SerializedName("relationship-list") + private RelationshipList relationshipList; + + public String getVserverId() { + return vserverId; + } + + public String getVserverName() { + return vserverName; + } + + public String getVserverName2() { + return vserverName2; + } + + public String getProvStatus() { + return provStatus; + } + + public String getVserverSelflink() { + return vserverSelflink; + } + + public Boolean getInMaint() { + return inMaint; + } + + public Boolean getIsClosedLoopDisabled() { + return isClosedLoopDisabled; + } + + public String getResourceVersion() { + return resourceVersion; + } + + public RelationshipList getRelationshipList() { + return relationshipList; + } + + public void setVserverId(String vserverId) { + this.vserverId = vserverId; + } + + public void setVserverName(String vserverName) { + this.vserverName = vserverName; + } + + public void setVserverName2(String vserverName2) { + this.vserverName2 = vserverName2; + } + + public void setProvStatus(String provStatus) { + this.provStatus = provStatus; + } + + public void setVserverSelflink(String vserverSelflink) { + this.vserverSelflink = vserverSelflink; + } + + public void setInMaint(Boolean inMaint) { + this.inMaint = inMaint; + } + + public void setIsClosedLoopDisabled(Boolean isClosedLoopDisabled) { + this.isClosedLoopDisabled = isClosedLoopDisabled; + } + + public void setResourceVersion(String resourceVersion) { + this.resourceVersion = resourceVersion; + } + + public void setRelationshipList(RelationshipList relationshipList) { + this.relationshipList = relationshipList; + } + +} diff --git a/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqVfModule.java b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqVfModule.java new file mode 100644 index 000000000..9080c486e --- /dev/null +++ b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqVfModule.java @@ -0,0 +1,183 @@ +/*- + * ============LICENSE_START======================================================= + * aai + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.aai; + +import com.google.gson.annotations.SerializedName; +import java.io.Serializable; + +public class AaiNqVfModule implements Serializable { + private static final long serialVersionUID = 8019133081429638232L; + + @SerializedName("vf-module-id") + private String vfModuleId; + + @SerializedName("vf-module-name") + private String vfModuleName; + + @SerializedName("heat-stack-id") + private String heatStackId; + + @SerializedName("orchestration-status") + private String orchestrationStatus; + + @SerializedName("is-base-vf-module") + private Boolean isBaseVfModule; + + @SerializedName("resource-version") + private String resourceVersion; + + @SerializedName("persona-model-id") + private String personaModelId; + + @SerializedName("persona-model-version") + private String personaModelVersion; + + @SerializedName("widget-model-id") + private String widgetModelId; + + @SerializedName("widget-model-version") + private String widgetModelVersion; + + @SerializedName("contrail-service-instance-fqdn") + private String contrailServiceInstanceFqdn; + + @SerializedName("model-invariant-id") + private String modelInvariantId; + + @SerializedName("model-version-id") + private String modelVersionId; + + @SerializedName("model-customization-id") + private String modelCustomizationId = null; + + public String getVfModuleId() { + return vfModuleId; + } + + public String getVfModuleName() { + return vfModuleName; + } + + public String getHeatStackId() { + return heatStackId; + } + + public String getOrchestrationStatus() { + return orchestrationStatus; + } + + public Boolean getIsBaseVfModule() { + return isBaseVfModule; + } + + public String getResourceVersion() { + return resourceVersion; + } + + public String getPersonaModelId() { + return personaModelId; + } + + public String getPersonaModelVersion() { + return personaModelVersion; + } + + public String getWidgetModelId() { + return widgetModelId; + } + + public String getWidgetModelVersion() { + return widgetModelVersion; + } + + public String getContrailServiceInstanceFqdn() { + return contrailServiceInstanceFqdn; + } + + public String getModelInvariantId() { + return modelInvariantId; + } + + public String getModelVersionId() { + return modelVersionId; + } + + public String getModelCustomizationId() { + return modelCustomizationId; + } + + public void setVfModuleId(String vfModuleId) { + this.vfModuleId = vfModuleId; + } + + public void setVfModuleName(String vfModuleName) { + this.vfModuleName = vfModuleName; + } + + public void setHeatStackId(String heatStackId) { + this.heatStackId = heatStackId; + } + + public void setOrchestrationStatus(String orchestrationStatus) { + this.orchestrationStatus = orchestrationStatus; + } + + public void setIsBaseVfModule(Boolean isBaseVfModule) { + this.isBaseVfModule = isBaseVfModule; + } + + public void setResourceVersion(String resourceVersion) { + this.resourceVersion = resourceVersion; + } + + public void setPersonaModelId(String personaModelId) { + this.personaModelId = personaModelId; + } + + public void setPersonaModelVersion(String personaModelVersion) { + this.personaModelVersion = personaModelVersion; + } + + public void setWidgetModelId(String widgetModelId) { + this.widgetModelId = widgetModelId; + } + + public void setWidgetModelVersion(String widgetModelVersion) { + this.widgetModelVersion = widgetModelVersion; + } + + public void setContrailServiceInstanceFqdn(String contrailServiceInstanceFqdn) { + this.contrailServiceInstanceFqdn = contrailServiceInstanceFqdn; + } + + public void setModelInvariantId(String modelInvariantId) { + this.modelInvariantId = modelInvariantId; + } + + public void setModelVersionId(String modelVersionId) { + this.modelVersionId = modelVersionId; + } + + public void setModelCustomizationId(String modelCustomizationId) { + this.modelCustomizationId = modelCustomizationId; + } +} diff --git a/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/Pnf.java b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/Pnf.java new file mode 100644 index 000000000..f992d886d --- /dev/null +++ b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/Pnf.java @@ -0,0 +1,92 @@ +/*- + * ============LICENSE_START======================================================= + * aai + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.aai; + +import java.io.Serializable; + +public class Pnf implements Serializable { + private static final long serialVersionUID = -3535108358668248501L; + + private String pnfName; + private PnfType pnfType; + + public Pnf() { + + } + + public Pnf(Pnf pnf) { + this.pnfName = pnf.pnfName; + this.pnfType = pnf.pnfType; + } + + public String getPnfName() { + return pnfName; + } + + public void setPnfName(String pnfName) { + this.pnfName = pnfName; + } + + public PnfType getPnfType() { + return pnfType; + } + + public void setPnfType(PnfType pnfType) { + this.pnfType = pnfType; + } + + @Override + public String toString() { + return "PNF [PNFName=" + pnfName + ", PNFType=" + pnfType + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((pnfName == null) ? 0 : pnfName.hashCode()); + result = prime * result + ((pnfType == null) ? 0 : pnfType.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + Pnf other = (Pnf) obj; + if (pnfName == null) { + if (other.pnfName != null) { + return false; + } + } else if (!pnfName.equals(other.pnfName)) { + return false; + } + return pnfType == other.pnfType; + } +} diff --git a/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/PnfInstance.java b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/PnfInstance.java new file mode 100644 index 000000000..1a9d75efa --- /dev/null +++ b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/PnfInstance.java @@ -0,0 +1,138 @@ +/*- + * ============LICENSE_START======================================================= + * aai + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.aai; + +import java.io.Serializable; + +public class PnfInstance implements Serializable { + + private static final long serialVersionUID = -3694152433472165034L; + + private String pnfName; + private String pnfInstanceName; + private PnfType pnfType; + private String pnfSerial; + + public PnfInstance() { + + } + + /** + * Create an instance from a given instance. + * + * @param instance the instance + */ + public PnfInstance(PnfInstance instance) { + if (instance == null) { + return; + } + this.pnfName = instance.pnfName; + this.pnfInstanceName = instance.pnfInstanceName; + this.pnfType = instance.pnfType; + this.pnfSerial = instance.pnfSerial; + } + + public String getPnfName() { + return pnfName; + } + + public void setPnfName(String pnfName) { + this.pnfName = pnfName; + } + + public String getPnfInstanceName() { + return pnfInstanceName; + } + + public void setPnfInstanceName(String pnfInstanceName) { + this.pnfInstanceName = pnfInstanceName; + } + + public PnfType getPnfType() { + return pnfType; + } + + public void setPnfType(PnfType pnfType) { + this.pnfType = pnfType; + } + + public String getPnfSerial() { + return pnfSerial; + } + + public void setPnfSerial(String pnfSerial) { + this.pnfSerial = pnfSerial; + } + + @Override + public String toString() { + return "PNFInstance [PNFName=" + pnfName + ", PNFInstanceName=" + pnfInstanceName + ", PNFType=" + pnfType + + ", PNFSerial=" + pnfSerial + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((pnfInstanceName == null) ? 0 : pnfInstanceName.hashCode()); + result = prime * result + ((pnfName == null) ? 0 : pnfName.hashCode()); + result = prime * result + ((pnfSerial == null) ? 0 : pnfSerial.hashCode()); + result = prime * result + ((pnfType == null) ? 0 : pnfType.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + PnfInstance other = (PnfInstance) obj; + if (pnfInstanceName == null) { + if (other.pnfInstanceName != null) { + return false; + } + } else if (!pnfInstanceName.equals(other.pnfInstanceName)) { + return false; + } + if (pnfName == null) { + if (other.pnfName != null) { + return false; + } + } else if (!pnfName.equals(other.pnfName)) { + return false; + } + if (pnfSerial == null) { + if (other.pnfSerial != null) { + return false; + } + } else if (!pnfSerial.equals(other.pnfSerial)) { + return false; + } + return pnfType == other.pnfType; + } +} diff --git a/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/PnfType.java b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/PnfType.java new file mode 100644 index 000000000..1e2484441 --- /dev/null +++ b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/PnfType.java @@ -0,0 +1,37 @@ +/*- + * ============LICENSE_START======================================================= + * aai + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.aai; + +public enum PnfType { + ENODEB("eNodeB"), PSERVER("pserver"); + + private String type; + + private PnfType(String type) { + this.type = type; + } + + @Override + public String toString() { + return this.type; + } +} diff --git a/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/RelatedToProperty.java b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/RelatedToProperty.java new file mode 100644 index 000000000..34f82e803 --- /dev/null +++ b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/RelatedToProperty.java @@ -0,0 +1,51 @@ +/* + * ============LICENSE_START======================================================= + * aai + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.aai; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; + +public class RelatedToProperty implements Serializable { + private static final long serialVersionUID = 5644372985092588638L; + + @SerializedName("property-key") + private String propertyKey; + @SerializedName("property-value") + private String propertyValue; + + public String getPropertyKey() { + return propertyKey; + } + + public String getPropertyValue() { + return propertyValue; + } + + public void setPropertyKey(String propertyKey) { + this.propertyKey = propertyKey; + } + + public void setPropertyValue(String propertyValue) { + this.propertyValue = propertyValue; + } +} diff --git a/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/Relationship.java b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/Relationship.java new file mode 100644 index 000000000..d9c55cc30 --- /dev/null +++ b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/Relationship.java @@ -0,0 +1,76 @@ +/* + * ============LICENSE_START======================================================= + * aai + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.aai; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; +import java.util.LinkedList; +import java.util.List; + +public class Relationship implements Serializable { + private static final long serialVersionUID = -68508443869003055L; + + @SerializedName("related-to") + private String relatedTo; + + @SerializedName("related-link") + private String relatedLink; + + @SerializedName("relationship-data") + private List<RelationshipData> relationshipData = new LinkedList<>(); + + @SerializedName("related-to-property") + private List<RelatedToProperty> relatedToProperty = new LinkedList<>(); + + public String getRelatedTo() { + return relatedTo; + } + + public String getRelatedLink() { + return relatedLink; + } + + public List<RelationshipData> getRelationshipData() { + return relationshipData; + } + + public List<RelatedToProperty> getRelatedToProperty() { + return relatedToProperty; + } + + public void setRelatedTo(String relatedTo) { + this.relatedTo = relatedTo; + } + + public void setRelatedLink(String relatedLink) { + this.relatedLink = relatedLink; + } + + public void setRelationshipData(List<RelationshipData> relationshipData) { + this.relationshipData = relationshipData; + } + + public void setRelatedToProperty(List<RelatedToProperty> relatedToProperty) { + this.relatedToProperty = relatedToProperty; + } +} diff --git a/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/RelationshipData.java b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/RelationshipData.java new file mode 100644 index 000000000..fc6b65f6c --- /dev/null +++ b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/RelationshipData.java @@ -0,0 +1,51 @@ +/* + * ============LICENSE_START======================================================= + * aai + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.aai; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; + +public class RelationshipData implements Serializable { + private static final long serialVersionUID = 550450041634939768L; + + @SerializedName("relationship-key") + private String relationshipKey; + @SerializedName("relationship-value") + private String relationshipValue; + + public String getRelationshipKey() { + return relationshipKey; + } + + public String getRelationshipValue() { + return relationshipValue; + } + + public void setRelationshipKey(String relationshipKey) { + this.relationshipKey = relationshipKey; + } + + public void setRelationshipValue(String relationshipValue) { + this.relationshipValue = relationshipValue; + } +} diff --git a/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/RelationshipList.java b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/RelationshipList.java new file mode 100644 index 000000000..0215e1601 --- /dev/null +++ b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/RelationshipList.java @@ -0,0 +1,45 @@ +/* + * ============LICENSE_START======================================================= + * aai + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.aai; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; +import java.util.LinkedList; +import java.util.List; + +public class RelationshipList implements Serializable { + private static final long serialVersionUID = 6115655704973981990L; + + @SerializedName("relationship") + private List<Relationship> relationships = new LinkedList<>(); + + public List<Relationship> getRelationships() { + return relationships; + } + + public void setRelationships(List<Relationship> relationships) { + this.relationships = relationships; + } + + +} diff --git a/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/util/AaiException.java b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/util/AaiException.java new file mode 100644 index 000000000..ef7c017df --- /dev/null +++ b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/util/AaiException.java @@ -0,0 +1,48 @@ +/*- + * ============LICENSE_START======================================================= + * aai + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.aai.util; + +public class AaiException extends Exception { + + private static final long serialVersionUID = 9220983727706207465L; + + public AaiException() { + super(); + } + + public AaiException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + } + + public AaiException(String message, Throwable cause) { + super(message, cause); + } + + public AaiException(String message) { + super(message); + } + + public AaiException(Throwable cause) { + super(cause); + } + +} diff --git a/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/util/Serialization.java b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/util/Serialization.java new file mode 100644 index 000000000..0ca0bb033 --- /dev/null +++ b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/util/Serialization.java @@ -0,0 +1,34 @@ +/*- + * ============LICENSE_START======================================================= + * aai + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.aai.util; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +public final class Serialization { + + public static final Gson gsonPretty = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting() + .create(); + + private Serialization() {} + +} diff --git a/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiGetResponseTest.java b/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiGetResponseTest.java new file mode 100644 index 000000000..ab31f5c27 --- /dev/null +++ b/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiGetResponseTest.java @@ -0,0 +1,62 @@ +/*- + * ============LICENSE_START======================================================= + * aai + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.aai; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import java.io.File; +import java.nio.file.Files; +import org.junit.Test; +import org.onap.policy.aai.util.Serialization; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class AaiGetResponseTest { + private static final Logger logger = LoggerFactory.getLogger(AaiGetResponseTest.class); + + @Test + public void test() throws Exception { + // deserialize json and verify fields are populated properly + String json = new String(Files.readAllBytes( + new File("src/test/resources/org/onap/policy/aai/AaiGetResponseError.json").toPath())); + + AaiGetResponse resp = Serialization.gsonPretty.fromJson(json, AaiGetResponse.class); + + // don't need to verify this in depth, as it has its own tests that do that + assertNotNull(resp.getRequestError()); + assertNotNull(resp.getRequestError().getServiceExcept()); + assertEquals("SVC3001", resp.getRequestError().getServiceExcept().getMessageId()); + + logger.info(Serialization.gsonPretty.toJson(resp)); + + // verify that setXxx methods work + resp.setRequestError(null); + assertNull(resp.getRequestError()); + + AaiNqRequestError err = new AaiNqRequestError(); + resp.setRequestError(err); + assertEquals(err, resp.getRequestError()); + } + +} diff --git a/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiGetVnfResponseTest.java b/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiGetVnfResponseTest.java new file mode 100644 index 000000000..eb05be3cd --- /dev/null +++ b/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiGetVnfResponseTest.java @@ -0,0 +1,108 @@ +/*- + * ============LICENSE_START======================================================= + * aai + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.aai; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.io.File; +import java.nio.file.Files; +import java.util.List; +import org.junit.Test; +import org.onap.policy.aai.util.Serialization; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class AaiGetVnfResponseTest { + private static final Logger logger = LoggerFactory.getLogger(AaiGetVnfResponseTest.class); + + @Test + public void test() throws Exception { + // deserialize json and verify fields are populated properly + String json = new String(Files.readAllBytes( + new File("src/test/resources/org/onap/policy/aai/AaiGetVnfResponse.json").toPath())); + + AaiGetVnfResponse resp = Serialization.gsonPretty.fromJson(json, AaiGetVnfResponse.class); + + assertEquals("807a3f02-f878-436b-870c-f0e91e81570d", resp.getVnfId()); + assertEquals("vLoadBalancerMS-Vnf-0809-2", resp.getVnfName()); + assertEquals("vLoadBalancerMS/vLoadBalancerMS 0", resp.getVnfType()); + assertEquals("1533850960381", resp.getResourceVersion()); + assertEquals(false, resp.getInMaint()); + assertEquals(true, resp.getIsClosedLoopDisabled()); + assertEquals("53638a85-361a-437d-8830-4b0d5329225e", resp.getModelInvariantId()); + assertEquals("PROV", resp.getProvStatus()); + assertEquals("Active", resp.getOrchestrationStatus()); + assertEquals("50e1b0be-e0c9-48e2-9f42-15279a783ee8", resp.getServiceId()); + + // don't need to verify this in depth, as it has its own tests that do that + RelationshipList relationshipList = resp.getRelationshipList(); + assertNotNull(relationshipList); + + List<Relationship> lst = relationshipList.getRelationships(); + assertNotNull(lst); + + assertEquals(5, lst.size()); + assertEquals("service-instance", lst.get(0).getRelatedTo()); + assertEquals("line-of-business", lst.get(1).getRelatedTo()); + + logger.info(Serialization.gsonPretty.toJson(resp)); + + // verify that setXxx methods work + relationshipList = new RelationshipList(); + + resp.setInMaint(true); + resp.setIsClosedLoopDisabled(false); + resp.setModelInvariantId("modiv"); + resp.setOrchestrationStatus("orch"); + resp.setProvStatus("mystatus"); + resp.setRelationshipList(relationshipList); + resp.setResourceVersion("vers"); + resp.setServiceId("svc"); + resp.setVnfId("vnfid"); + resp.setVnfName("vnfname"); + resp.setVnfType("vnftype"); + + assertEquals("vnfid", resp.getVnfId()); + assertEquals("vnfname", resp.getVnfName()); + assertEquals("vnftype", resp.getVnfType()); + assertEquals("vers", resp.getResourceVersion()); + assertEquals(true, resp.getInMaint()); + assertEquals(false, resp.getIsClosedLoopDisabled()); + assertEquals("modiv", resp.getModelInvariantId()); + assertEquals("mystatus", resp.getProvStatus()); + assertEquals("orch", resp.getOrchestrationStatus()); + assertEquals("svc", resp.getServiceId()); + assertEquals(relationshipList, resp.getRelationshipList()); + + + // test error case + json = new String(Files.readAllBytes( + new File("src/test/resources/org/onap/policy/aai/AaiGetResponseError.json").toPath())); + resp = Serialization.gsonPretty.fromJson(json, AaiGetVnfResponse.class); + + // don't need to verify this in depth, as it has its own tests that do that + assertNotNull(resp.getRequestError()); + assertNotNull(resp.getRequestError().getServiceExcept()); + assertEquals("SVC3001", resp.getRequestError().getServiceExcept().getMessageId()); + } +} diff --git a/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiGetVserverResponseTest.java b/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiGetVserverResponseTest.java new file mode 100644 index 000000000..ed68aeba0 --- /dev/null +++ b/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiGetVserverResponseTest.java @@ -0,0 +1,78 @@ +/* + * ============LICENSE_START======================================================= + * aai + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.aai; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.io.File; +import java.nio.file.Files; +import java.util.LinkedList; +import java.util.List; +import org.junit.Test; +import org.onap.policy.aai.util.Serialization; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class AaiGetVserverResponseTest { + private static final Logger logger = LoggerFactory.getLogger(AaiGetVserverResponseTest.class); + + @Test + public void test() throws Exception { + // deserialize json and verify fields are populated properly + String json = new String(Files.readAllBytes( + new File("src/test/resources/org/onap/policy/aai/AaiGetVserverResponse.json").toPath())); + + AaiGetVserverResponse resp = Serialization.gsonPretty.fromJson(json, AaiGetVserverResponse.class); + + // don't need to verify this in depth, as it has its own tests that do that + List<AaiNqVServer> lst = resp.getVserver(); + assertEquals(1, lst.size()); + + AaiNqVServer svr = lst.get(0); + assertNotNull(svr); + assertEquals("1c94da3f-16f1-4fc7-9ed1-e018dfa62774", svr.getVserverId()); + + logger.info(Serialization.gsonPretty.toJson(resp)); + + // verify that setXxx methods work + lst = new LinkedList<>(); + lst.add(new AaiNqVServer()); + lst.add(new AaiNqVServer()); + + resp.setVserver(lst); + + assertEquals(lst, resp.getVserver()); + + + // test error case + json = new String(Files.readAllBytes( + new File("src/test/resources/org/onap/policy/aai/AaiGetResponseError.json").toPath())); + resp = Serialization.gsonPretty.fromJson(json, AaiGetVserverResponse.class); + + // don't need to verify this in depth, as it has its own tests that do that + assertNotNull(resp.getRequestError()); + assertNotNull(resp.getRequestError().getServiceExcept()); + assertEquals("SVC3001", resp.getRequestError().getServiceExcept().getMessageId()); + } + +} diff --git a/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiManagerTest.java b/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiManagerTest.java new file mode 100644 index 000000000..20aac23f6 --- /dev/null +++ b/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiManagerTest.java @@ -0,0 +1,170 @@ +/*- + * ============LICENSE_START======================================================= + * aai + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.aai; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.mockito.ArgumentMatchers.anyMap; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.isNull; +import static org.mockito.ArgumentMatchers.startsWith; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +import org.junit.Before; +import org.junit.Test; +import org.onap.policy.aai.util.Serialization; +import org.onap.policy.rest.RestManager; +import org.onap.policy.rest.RestManager.Pair; + +public class AaiManagerTest { + RestManager restManagerMock; + UUID aaiNqRequestUuid = UUID.randomUUID(); + Pair<Integer, String> httpResponseOk; + Pair<Integer, String> httpResponseErr0; + Pair<Integer, String> httpResponseErr1; + Pair<Integer, String> httpResponseWait; + + /** + * Set up test cases. + */ + @Before + public void beforeTestAaiManager() { + restManagerMock = mock(RestManager.class); + + Map<String, String> expectedHeaders = new HashMap<>(); + expectedHeaders.put("X-FromAppId", "POLICY"); + expectedHeaders.put("X-TransactionId", aaiNqRequestUuid.toString()); + expectedHeaders.put("Accept", "application/json"); + + AaiNqResponse aaiNqResponse = new AaiNqResponseTest().getAaiNqResponse(); + httpResponseOk = restManagerMock.new Pair<>(200, Serialization.gsonPretty.toJson(aaiNqResponse)); + httpResponseErr0 = restManagerMock.new Pair<>(200, null); + httpResponseErr1 = restManagerMock.new Pair<>(200, "{"); + httpResponseWait = restManagerMock.new Pair<>(503, null); + } + + @Test + public void testAaiManagerAaiNqRequest() { + + AaiManager aaiManager = new AaiManager(restManagerMock); + assertNotNull(aaiManager); + + UUID aaiNqUuid = UUID.randomUUID(); + + AaiNqQueryParameters aaiNqQueryParameters = new AaiNqQueryParameters(); + AaiNqNamedQuery aaiNqNamedQuery = new AaiNqNamedQuery(); + aaiNqNamedQuery.setNamedQueryUuid(aaiNqUuid); + aaiNqQueryParameters.setNamedQuery(aaiNqNamedQuery); + + AaiNqRequest aaiNqRequest = new AaiNqRequest(); + aaiNqRequest.setQueryParameters(aaiNqQueryParameters); + + when(restManagerMock.post(startsWith("http://somewhere.over.the.rainbow"), eq("Dorothy"), eq("Gale"), anyMap(), + anyString(), anyString())).thenReturn(httpResponseOk); + + AaiNqResponse aaiNqOkResponse = aaiManager.postQuery("http://somewhere.over.the.rainbow", "Dorothy", "Gale", + aaiNqRequest, aaiNqRequestUuid); + assertNotNull(aaiNqOkResponse); + + when(restManagerMock.post(isNull(), eq("Dorothy"), anyString(), anyMap(), anyString(), anyString())) + .thenReturn(null); + + AaiNqResponse aaiNqNullResponse = aaiManager.postQuery(null, "Dorothy", "Gale", null, aaiNqRequestUuid); + assertNull(aaiNqNullResponse); + + when(restManagerMock.post(startsWith("http://somewhere.over.the.rainbow"), eq("Witch"), eq("West"), anyMap(), + anyString(), anyString())).thenReturn(httpResponseErr0); + + AaiNqResponse aaiNqNotOkResponse0 = aaiManager.postQuery("http://somewhere.over.the.rainbow", "Witch", "West", + aaiNqRequest, aaiNqRequestUuid); + assertNull(aaiNqNotOkResponse0); + + when(restManagerMock.post(startsWith("http://somewhere.under.the.rainbow"), eq("Witch"), eq("West"), anyMap(), + anyString(), anyString())).thenReturn(httpResponseErr1); + + AaiNqResponse aaiNqNotOkResponse1 = aaiManager.postQuery("http://somewhere.under.the.rainbow", "Witch", "West", + aaiNqRequest, aaiNqRequestUuid); + assertNull(aaiNqNotOkResponse1); + } + + @Test + public void testAaiManagerQueryByVserverName() { + AaiManager aaiManager = new AaiManager(restManagerMock); + assertNotNull(aaiManager); + + UUID vserverNameRequestId = UUID.randomUUID(); + + when(restManagerMock.get(startsWith("http://somewhere.over.the.rainbow"), eq("Dorothy"), eq("Gale"), anyMap())) + .thenReturn(httpResponseOk); + + AaiGetVserverResponse vserverResponse = aaiManager.getQueryByVserverName("http://somewhere.over.the.rainbow", + "Dorothy", "Gale", vserverNameRequestId, "vserverName"); + assertNotNull(vserverResponse); + + AaiGetVserverResponse vserverNullResponse = + aaiManager.getQueryByVserverName(null, "Dorothy", "Gale", vserverNameRequestId, "vserverName"); + assertNull(vserverNullResponse); + + when(restManagerMock.get(startsWith("http://somewhere.under.the.rainbow"), eq("Witch"), eq("West"), anyMap())) + .thenReturn(httpResponseErr0); + + AaiGetVserverResponse vserverNotOkResponse0 = aaiManager.getQueryByVserverName( + "http://somewhere.under.the.rainbow", "Witch", "West", vserverNameRequestId, "vserverName"); + assertNull(vserverNotOkResponse0); + } + + @Test + public void testAaiManagerQueryByVnfId() { + AaiManager aaiManager = new AaiManager(restManagerMock); + assertNotNull(aaiManager); + + UUID vserverNameRequestId = UUID.randomUUID(); + + when(restManagerMock.get(startsWith("http://somewhere.over.the.rainbow"), eq("Dorothy"), eq("Gale"), anyMap())) + .thenReturn(httpResponseOk); + + AaiGetVnfResponse vnfResponse = aaiManager.getQueryByVnfId("http://somewhere.over.the.rainbow", "Dorothy", + "Gale", vserverNameRequestId, "vnfID"); + assertNotNull(vnfResponse); + } + + @Test + public void testAaiManagerQueryByVnfName() { + AaiManager aaiManager = new AaiManager(restManagerMock); + assertNotNull(aaiManager); + + UUID vserverNameRequestId = UUID.randomUUID(); + + when(restManagerMock.get(startsWith("http://somewhere.over.the.rainbow"), eq("Dorothy"), eq("Gale"), anyMap())) + .thenReturn(httpResponseOk); + + AaiGetVnfResponse vnfResponse = aaiManager.getQueryByVnfId("http://somewhere.over.the.rainbow", "Dorothy", + "Gale", vserverNameRequestId, "vnfName"); + assertNotNull(vnfResponse); + } +} diff --git a/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiNqCloudRegionTest.java b/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiNqCloudRegionTest.java new file mode 100644 index 000000000..70f04dfee --- /dev/null +++ b/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiNqCloudRegionTest.java @@ -0,0 +1,54 @@ +/*- + * ============LICENSE_START======================================================= + * aai + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.aai; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +public class AaiNqCloudRegionTest { + + @BeforeClass + public static void setUpBeforeClass() throws Exception {} + + @AfterClass + public static void tearDownAfterClass() throws Exception {} + + @Test + public void test() { + AaiNqCloudRegion aaiNqCloudRegion = new AaiNqCloudRegion(); + aaiNqCloudRegion.setCloudOwner("Rackspace"); + aaiNqCloudRegion.setCloudRegionId("DFW"); + aaiNqCloudRegion.setCloudRegionVersion("v1"); + aaiNqCloudRegion.setComplexName("SharedNode"); + aaiNqCloudRegion.setResourceVersion("1504789196021"); + assertNotNull(aaiNqCloudRegion); + assertEquals("Rackspace", aaiNqCloudRegion.getCloudOwner()); + assertEquals("DFW", aaiNqCloudRegion.getCloudRegionId()); + assertEquals("v1", aaiNqCloudRegion.getCloudRegionVersion()); + assertEquals("SharedNode", aaiNqCloudRegion.getComplexName()); + assertEquals("1504789196021", aaiNqCloudRegion.getResourceVersion()); + } +} diff --git a/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiNqExtraPropertiesTest.java b/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiNqExtraPropertiesTest.java new file mode 100644 index 000000000..a4410c9c0 --- /dev/null +++ b/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiNqExtraPropertiesTest.java @@ -0,0 +1,51 @@ +/*- + * ============LICENSE_START======================================================= + * aai + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.aai; + +import static org.junit.Assert.assertNotNull; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +public class AaiNqExtraPropertiesTest { + + @BeforeClass + public static void setUpBeforeClass() throws Exception {} + + @AfterClass + public static void tearDownAfterClass() throws Exception {} + + @Test + public void test() { + AaiNqExtraProperties aaiNqExtraProperties = new AaiNqExtraProperties(); + aaiNqExtraProperties.getExtraProperty().add(new AaiNqExtraProperty("model.model-name", "service-instance")); + aaiNqExtraProperties.getExtraProperty().add(new AaiNqExtraProperty("model.model-type", "widget")); + aaiNqExtraProperties.getExtraProperty().add(new AaiNqExtraProperty("model.model-version", "1.0")); + aaiNqExtraProperties.getExtraProperty() + .add(new AaiNqExtraProperty("model.model-id", "82194af1-3c2c-485a-8f44-420e22a9eaa4")); + aaiNqExtraProperties.getExtraProperty() + .add(new AaiNqExtraProperty("model.model-name", "46b92144-923a-4d20-b85a-3cbd847668a9")); + assertNotNull(aaiNqExtraProperties); + } + +} diff --git a/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiNqExtraPropertyTest.java b/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiNqExtraPropertyTest.java new file mode 100644 index 000000000..09c8cc310 --- /dev/null +++ b/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiNqExtraPropertyTest.java @@ -0,0 +1,49 @@ +/*- + * ============LICENSE_START======================================================= + * aai + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.aai; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +public class AaiNqExtraPropertyTest { + + @BeforeClass + public static void setUpBeforeClass() throws Exception {} + + @AfterClass + public static void tearDownAfterClass() throws Exception {} + + @Test + public void test() { + AaiNqExtraProperty aaiNqExtraProperty = new AaiNqExtraProperty(); + aaiNqExtraProperty.setPropertyName("model.model-name"); + aaiNqExtraProperty.setPropertyValue("service-instance"); + assertNotNull(aaiNqExtraProperty); + + assertEquals("model.model-name", aaiNqExtraProperty.getPropertyName()); + assertEquals("service-instance", aaiNqExtraProperty.getPropertyValue()); + } +} diff --git a/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiNqGenericVnfTest.java b/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiNqGenericVnfTest.java new file mode 100644 index 000000000..e30bcaf86 --- /dev/null +++ b/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiNqGenericVnfTest.java @@ -0,0 +1,82 @@ +/*- + * ============LICENSE_START======================================================= + * aai + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.aai; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +public class AaiNqGenericVnfTest { + + @BeforeClass + public static void setUpBeforeClass() throws Exception {} + + @AfterClass + public static void tearDownAfterClass() throws Exception {} + + @Test + public void test() { + AaiNqGenericVnf aaiNqGenericVnf = new AaiNqGenericVnf(); + aaiNqGenericVnf.setEncrypedAccessFlag(true); + aaiNqGenericVnf.setInMaint(false); + aaiNqGenericVnf.setIpv4Loopback0Address("aa"); + aaiNqGenericVnf.setIpv4OamAddress("oamAddress"); + aaiNqGenericVnf.setIsClosedLoopDisabled(false); + aaiNqGenericVnf.setModelInvariantId("653d2caa-7e47-4614-95b3-26c8d82755b8"); + aaiNqGenericVnf.setModelVersionId("98f410f6-4c63-447b-97d2-42508437cec0"); + aaiNqGenericVnf.setModelCustomizationId("SomeCustomizationId"); + aaiNqGenericVnf.setOperationalState("active"); + aaiNqGenericVnf.setPersonaModelId("653d2caa-7e47-4614-95b3-26c8d82755b8"); + aaiNqGenericVnf.setPersonaModelVersion("98f410f6-4c63-447b-97d2-42508437cec0"); + aaiNqGenericVnf.setProvStatus("complete"); + aaiNqGenericVnf.setResourceVersion("1505056714553"); + aaiNqGenericVnf.setServiceId("e8cb8968-5411-478b-906a-f28747de72cd"); + aaiNqGenericVnf.setVnfId("ed8b2bce-6b27-4089-992c-4a2c66024bcd"); + aaiNqGenericVnf.setVnfName("vCPEInfraVNF14a"); + aaiNqGenericVnf.setVnfName2("malumabb12"); + aaiNqGenericVnf.setVnfType("vCPEInfraService10/vCPEInfraService10 0"); + assertNotNull(aaiNqGenericVnf); + + assertEquals(true, aaiNqGenericVnf.getEncrypedAccessFlag()); + assertEquals(false, aaiNqGenericVnf.getInMaint()); + assertEquals("aa", aaiNqGenericVnf.getIpv4Loopback0Address()); + assertEquals("oamAddress", aaiNqGenericVnf.getIpv4OamAddress()); + assertEquals(false, aaiNqGenericVnf.getIsClosedLoopDisabled()); + assertEquals("653d2caa-7e47-4614-95b3-26c8d82755b8", aaiNqGenericVnf.getModelInvariantId()); + assertEquals("98f410f6-4c63-447b-97d2-42508437cec0", aaiNqGenericVnf.getModelVersionId()); + assertEquals("SomeCustomizationId", aaiNqGenericVnf.getModelCustomizationId()); + assertEquals("active", aaiNqGenericVnf.getOperationalState()); + assertEquals("653d2caa-7e47-4614-95b3-26c8d82755b8", aaiNqGenericVnf.getPersonaModelId()); + assertEquals("98f410f6-4c63-447b-97d2-42508437cec0", aaiNqGenericVnf.getPersonaModelVersion()); + assertEquals("complete", aaiNqGenericVnf.getProvStatus()); + assertEquals("1505056714553", aaiNqGenericVnf.getResourceVersion()); + assertEquals("e8cb8968-5411-478b-906a-f28747de72cd", aaiNqGenericVnf.getServiceId()); + assertEquals("ed8b2bce-6b27-4089-992c-4a2c66024bcd", aaiNqGenericVnf.getVnfId()); + assertEquals("vCPEInfraVNF14a", aaiNqGenericVnf.getVnfName()); + assertEquals("malumabb12", aaiNqGenericVnf.getVnfName2()); + assertEquals("vCPEInfraService10/vCPEInfraService10 0", aaiNqGenericVnf.getVnfType()); + } + +} diff --git a/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiNqInstanceFiltersTest.java b/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiNqInstanceFiltersTest.java new file mode 100644 index 000000000..adafa1b5f --- /dev/null +++ b/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiNqInstanceFiltersTest.java @@ -0,0 +1,48 @@ +/*- + * ============LICENSE_START======================================================= + * aai + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.aai; + +import static org.junit.Assert.assertNotNull; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +public class AaiNqInstanceFiltersTest { + + @BeforeClass + public static void setUpBeforeClass() throws Exception {} + + @AfterClass + public static void tearDownAfterClass() throws Exception {} + + @Test + public void test() { + AaiNqInstanceFilters aaiNqInstanceFilters = new AaiNqInstanceFilters(); + assertNotNull(aaiNqInstanceFilters); + + aaiNqInstanceFilters.setInstanceFilter(aaiNqInstanceFilters.getInstanceFilter());; + assertNotNull(aaiNqInstanceFilters); + assertNotNull(aaiNqInstanceFilters.getInstanceFilter()); + } + +} diff --git a/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiNqInventoryResponseItemTest.java b/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiNqInventoryResponseItemTest.java new file mode 100644 index 000000000..eefe80703 --- /dev/null +++ b/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiNqInventoryResponseItemTest.java @@ -0,0 +1,171 @@ +/*- + * ============LICENSE_START======================================================= + * aai + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.aai; + +import static org.junit.Assert.assertNotNull; + +import java.util.LinkedList; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.onap.policy.aai.util.Serialization; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class AaiNqInventoryResponseItemTest { + private static final Logger logger = LoggerFactory.getLogger(AaiNqInventoryResponseItemTest.class); + + @BeforeClass + public static void setUpBeforeClass() throws Exception {} + + @AfterClass + public static void tearDownAfterClass() throws Exception {} + + @Test + public void test() { + AaiNqInventoryResponseItem aaiNqInventoryResponseItem = new AaiNqInventoryResponseItem(); + aaiNqInventoryResponseItem.setModelName("service-instance"); + AaiNqCloudRegion aaiNqCloudRegion = new AaiNqCloudRegion(); + aaiNqCloudRegion.setCloudOwner("OWNER"); + aaiNqCloudRegion.setCloudRegionId("REGIONID"); + aaiNqCloudRegion.setCloudRegionVersion("2.5"); + aaiNqCloudRegion.setComplexName("COMPLEXNAME"); + aaiNqCloudRegion.setResourceVersion("1485365988"); + aaiNqInventoryResponseItem.setCloudRegion(aaiNqCloudRegion); + AaiNqExtraProperties aaiNqExtraProperties = new AaiNqExtraProperties(); + aaiNqExtraProperties.setExtraProperty(new LinkedList<>()); + aaiNqExtraProperties.getExtraProperty().add(new AaiNqExtraProperty("model.model-name", "generic-vnf")); + aaiNqExtraProperties.getExtraProperty().add(new AaiNqExtraProperty("model.model-type", "widget")); + aaiNqExtraProperties.getExtraProperty().add(new AaiNqExtraProperty("model.model-version", "1.0")); + aaiNqExtraProperties.getExtraProperty() + .add(new AaiNqExtraProperty("model.model-id", "acc6edd8-a8d4-4b93-afaa-0994068be14c")); + aaiNqExtraProperties.getExtraProperty() + .add(new AaiNqExtraProperty("model.model-name-version-id", "93a6166f-b3d5-4f06-b4ba-aed48d009ad9")); + aaiNqInventoryResponseItem.setExtraProperties(aaiNqExtraProperties); + AaiNqGenericVnf aaiNqGenericVnf = new AaiNqGenericVnf(); + aaiNqGenericVnf.setVnfId("dhv-test-gvnf"); + aaiNqGenericVnf.setVnfName("dhv-test-gvnf-name"); + aaiNqGenericVnf.setVnfName2("dhv-test-gvnf-name2"); + aaiNqGenericVnf.setVnfType("SW"); + aaiNqGenericVnf.setServiceId("d7bb0a21-66f2-4e6d-87d9-9ef3ced63ae4"); + aaiNqGenericVnf.setProvStatus("PREPROV"); + aaiNqGenericVnf.setOperationalState("dhv-test-operational-state"); + aaiNqGenericVnf.setIpv4OamAddress("dhv-test-gvnf-ipv4-oam-address"); + aaiNqGenericVnf.setIpv4Loopback0Address("dhv-test-gvnfipv4-loopback0-address"); + aaiNqGenericVnf.setInMaint(false); + aaiNqGenericVnf.setIsClosedLoopDisabled(false); + aaiNqGenericVnf.setResourceVersion("1485366450"); + aaiNqGenericVnf.setEncrypedAccessFlag(true); + aaiNqGenericVnf.setPersonaModelId("acc6edd8-a8d4-4b93-afaa-0994068be14c"); + aaiNqGenericVnf.setPersonaModelVersion("1.0"); + aaiNqInventoryResponseItem.setGenericVnf(aaiNqGenericVnf); + AaiNqInventoryResponseItem serviceItem = new AaiNqInventoryResponseItem(); + serviceItem.setModelName("service-instance"); + serviceItem.setServiceInstance(new AaiNqServiceInstance()); + serviceItem.getServiceInstance().setServiceInstanceId("dhv-test-vhnfportal-service-instance-id"); + serviceItem.getServiceInstance().setServiceInstanceName("dhv-test-service-instance-name1"); + serviceItem.getServiceInstance().setPersonaModelId("82194af1-3c2c-485a-8f44-420e22a9eaa4"); + serviceItem.getServiceInstance().setPersonaModelVersion("1.0"); + serviceItem.getServiceInstance().setServiceInstanceLocationId("dhv-test-service-instance-location-id1"); + serviceItem.getServiceInstance().setResourceVersion("1485366092"); + serviceItem.setExtraProperties(new AaiNqExtraProperties()); + serviceItem.getExtraProperties().getExtraProperty() + .add(new AaiNqExtraProperty("model.model-name", "service-instance")); + serviceItem.getExtraProperties().getExtraProperty().add(new AaiNqExtraProperty("model.model-type", "widget")); + serviceItem.getExtraProperties().getExtraProperty().add(new AaiNqExtraProperty("model.model-version", "1.0")); + serviceItem.getExtraProperties().getExtraProperty() + .add(new AaiNqExtraProperty("model.model-id", "82194af1-3c2c-485a-8f44-420e22a9eaa4")); + serviceItem.getExtraProperties().getExtraProperty() + .add(new AaiNqExtraProperty("model.model-name", "46b92144-923a-4d20-b85a-3cbd847668a9")); + + AaiNqInventoryResponseItem vfModuleItem = new AaiNqInventoryResponseItem(); + vfModuleItem.setModelName("vf-module"); + vfModuleItem.setVfModule(new AaiNqVfModule()); + vfModuleItem.getVfModule().setVfModuleId("example-vf-module-id-val-49261"); + vfModuleItem.getVfModule().setVfModuleName("example-vf-module-name-val-73074"); + vfModuleItem.getVfModule().setHeatStackId("example-heat-stack-id-val-86300"); + vfModuleItem.getVfModule().setOrchestrationStatus("example-orchestration-status-val-56523"); + vfModuleItem.getVfModule().setIsBaseVfModule(true); + vfModuleItem.getVfModule().setResourceVersion("1485366450"); + vfModuleItem.getVfModule().setPersonaModelId("ef86f9c5-2165-44f3-8fc3-96018b609ea5"); + vfModuleItem.getVfModule().setPersonaModelVersion("1.0"); + vfModuleItem.getVfModule().setWidgetModelId("example-widget-model-id-val-92571"); + vfModuleItem.getVfModule().setWidgetModelVersion("example-widget-model-version-val-83317"); + vfModuleItem.getVfModule().setContrailServiceInstanceFqdn("example-contrail-service-instance-fqdn-val-86796"); + vfModuleItem.setExtraProperties(new AaiNqExtraProperties()); + vfModuleItem.getExtraProperties().getExtraProperty() + .add(new AaiNqExtraProperty("model.model-name", "vf-module")); + vfModuleItem.getExtraProperties().getExtraProperty().add(new AaiNqExtraProperty("model.model-type", "widget")); + vfModuleItem.getExtraProperties().getExtraProperty().add(new AaiNqExtraProperty("model.model-version", "1.0")); + vfModuleItem.getExtraProperties().getExtraProperty() + .add(new AaiNqExtraProperty("model.model-id", "ef86f9c5-2165-44f3-8fc3-96018b609ea5")); + vfModuleItem.getExtraProperties().getExtraProperty() + .add(new AaiNqExtraProperty("model.model-name", "c00563ae-812b-4e62-8330-7c4d0f47088a")); + + AaiNqInventoryResponseItems aaiNqInventoryResponseItems = new AaiNqInventoryResponseItems(); + aaiNqInventoryResponseItems.getInventoryResponseItems().add(serviceItem); + aaiNqInventoryResponseItems.getInventoryResponseItems().add(vfModuleItem); + aaiNqInventoryResponseItem.setItems(aaiNqInventoryResponseItems); + aaiNqInventoryResponseItem.setModelName("model-name"); + AaiNqServiceInstance serviceInstance = new AaiNqServiceInstance(); + serviceInstance.setServiceInstanceId("dhv-test-vhnfportal-service-instance-id"); + serviceInstance.setServiceInstanceName("dhv-test-service-instance-name1"); + serviceInstance.setPersonaModelId("82194af1-3c2c-485a-8f44-420e22a9eaa4"); + serviceInstance.setPersonaModelVersion("1.0"); + serviceInstance.setServiceInstanceLocationId("dhv-test-service-instance-location-id1"); + serviceInstance.setResourceVersion("1485366092"); + aaiNqInventoryResponseItem.setServiceInstance(serviceInstance); + AaiNqTenant aaiNqTenant = new AaiNqTenant(); + aaiNqTenant.setTenantId("dhv-test-tenant"); + aaiNqTenant.setTenantName("dhv-test-tenant-name"); + aaiNqTenant.setResourceVersion("1485366334"); + aaiNqInventoryResponseItem.setTenant(aaiNqTenant); + AaiNqVfModule aaiNqVfModule = new AaiNqVfModule(); + aaiNqVfModule.setVfModuleId("example-vf-module-id-val-49261"); + aaiNqVfModule.setVfModuleName("example-vf-module-name-val-73074"); + aaiNqVfModule.setHeatStackId("example-heat-stack-id-val-86300"); + aaiNqVfModule.setOrchestrationStatus("example-orchestration-status-val-56523"); + aaiNqVfModule.setIsBaseVfModule(true); + aaiNqVfModule.setResourceVersion("1485366450"); + aaiNqVfModule.setPersonaModelId("ef86f9c5-2165-44f3-8fc3-96018b609ea5"); + aaiNqVfModule.setPersonaModelVersion("1.0"); + aaiNqVfModule.setWidgetModelId("example-widget-model-id-val-92571"); + aaiNqVfModule.setWidgetModelVersion("example-widget-model-version-val-83317"); + aaiNqVfModule.setContrailServiceInstanceFqdn("example-contrail-service-instance-fqdn-val-86796"); + aaiNqInventoryResponseItem.setVfModule(aaiNqVfModule); + AaiNqVServer aaiNqVServer = new AaiNqVServer(); + aaiNqVServer.setVserverId("dhv-test-vserver"); + aaiNqVServer.setVserverName("dhv-test-vserver-name"); + aaiNqVServer.setVserverName2("dhv-test-vserver-name2"); + aaiNqVServer.setProvStatus("PREPROV"); + aaiNqVServer.setVserverSelflink("dhv-test-vserver-selflink"); + aaiNqVServer.setInMaint(false); + aaiNqVServer.setIsClosedLoopDisabled(false); + aaiNqVServer.setResourceVersion("1485366417"); + aaiNqInventoryResponseItem.setVserver(aaiNqVServer); + assertNotNull(aaiNqInventoryResponseItem); + + logger.info(Serialization.gsonPretty.toJson(aaiNqInventoryResponseItem)); + } + +} diff --git a/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiNqInventoryResponseItemsTest.java b/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiNqInventoryResponseItemsTest.java new file mode 100644 index 000000000..796e69226 --- /dev/null +++ b/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiNqInventoryResponseItemsTest.java @@ -0,0 +1,164 @@ +/*- + * ============LICENSE_START======================================================= + * aai + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.aai; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.util.LinkedList; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.onap.policy.aai.util.Serialization; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class AaiNqInventoryResponseItemsTest { + private static final Logger logger = LoggerFactory.getLogger(AaiNqInventoryResponseItemsTest.class); + + @BeforeClass + public static void setUpBeforeClass() throws Exception {} + + @AfterClass + public static void tearDownAfterClass() throws Exception {} + + @Test + public void test() { + AaiNqInventoryResponseItem serviceItem = new AaiNqInventoryResponseItem(); + serviceItem.setModelName("service-instance"); + assertEquals("service-instance", serviceItem.getModelName()); + + serviceItem.setServiceInstance(new AaiNqServiceInstance()); + serviceItem.getServiceInstance().setServiceInstanceId("dhv-test-vhnfportal-service-instance-id"); + serviceItem.getServiceInstance().setServiceInstanceName("dhv-test-service-instance-name1"); + serviceItem.getServiceInstance().setPersonaModelId("82194af1-3c2c-485a-8f44-420e22a9eaa4"); + serviceItem.getServiceInstance().setPersonaModelVersion("1.0"); + serviceItem.getServiceInstance().setServiceInstanceLocationId("dhv-test-service-instance-location-id1"); + serviceItem.getServiceInstance().setResourceVersion("1485366092"); + serviceItem.setExtraProperties(new AaiNqExtraProperties()); + serviceItem.getExtraProperties().getExtraProperty() + .add(new AaiNqExtraProperty("model.model-name", "service-instance")); + serviceItem.getExtraProperties().getExtraProperty().add(new AaiNqExtraProperty("model.model-type", "widget")); + serviceItem.getExtraProperties().getExtraProperty().add(new AaiNqExtraProperty("model.model-version", "1.0")); + serviceItem.getExtraProperties().getExtraProperty() + .add(new AaiNqExtraProperty("model.model-id", "82194af1-3c2c-485a-8f44-420e22a9eaa4")); + serviceItem.getExtraProperties().getExtraProperty() + .add(new AaiNqExtraProperty("model.model-name", "46b92144-923a-4d20-b85a-3cbd847668a9")); + + AaiNqInventoryResponseItem vfModuleItem = new AaiNqInventoryResponseItem(); + vfModuleItem.setModelName("vf-module"); + vfModuleItem.setVfModule(new AaiNqVfModule()); + vfModuleItem.getVfModule().setVfModuleId("example-vf-module-id-val-49261"); + vfModuleItem.getVfModule().setVfModuleName("example-vf-module-name-val-73074"); + vfModuleItem.getVfModule().setHeatStackId("example-heat-stack-id-val-86300"); + vfModuleItem.getVfModule().setOrchestrationStatus("example-orchestration-status-val-56523"); + vfModuleItem.getVfModule().setIsBaseVfModule(true); + vfModuleItem.getVfModule().setResourceVersion("1485366450"); + vfModuleItem.getVfModule().setPersonaModelId("ef86f9c5-2165-44f3-8fc3-96018b609ea5"); + vfModuleItem.getVfModule().setPersonaModelVersion("1.0"); + vfModuleItem.getVfModule().setWidgetModelId("example-widget-model-id-val-92571"); + vfModuleItem.getVfModule().setWidgetModelVersion("example-widget-model-version-val-83317"); + vfModuleItem.getVfModule().setContrailServiceInstanceFqdn("example-contrail-service-instance-fqdn-val-86796"); + vfModuleItem.setExtraProperties(new AaiNqExtraProperties()); + vfModuleItem.getExtraProperties().getExtraProperty() + .add(new AaiNqExtraProperty("model.model-name", "vf-module")); + vfModuleItem.getExtraProperties().getExtraProperty().add(new AaiNqExtraProperty("model.model-type", "widget")); + vfModuleItem.getExtraProperties().getExtraProperty().add(new AaiNqExtraProperty("model.model-version", "1.0")); + vfModuleItem.getExtraProperties().getExtraProperty() + .add(new AaiNqExtraProperty("model.model-id", "ef86f9c5-2165-44f3-8fc3-96018b609ea5")); + vfModuleItem.getExtraProperties().getExtraProperty() + .add(new AaiNqExtraProperty("model.model-name", "c00563ae-812b-4e62-8330-7c4d0f47088a")); + + AaiNqInventoryResponseItem genericVnfItem = new AaiNqInventoryResponseItem(); + genericVnfItem.setModelName("generic-vnf"); + genericVnfItem.setGenericVnf(new AaiNqGenericVnf()); + genericVnfItem.getGenericVnf().setVnfId("dhv-test-gvnf"); + genericVnfItem.getGenericVnf().setVnfName("dhv-test-gvnf-name"); + genericVnfItem.getGenericVnf().setVnfName2("dhv-test-gvnf-name2"); + genericVnfItem.getGenericVnf().setVnfType("SW"); + genericVnfItem.getGenericVnf().setServiceId("d7bb0a21-66f2-4e6d-87d9-9ef3ced63ae4"); + genericVnfItem.getGenericVnf().setProvStatus("PREPROV"); + genericVnfItem.getGenericVnf().setOperationalState("dhv-test-operational-state"); + genericVnfItem.getGenericVnf().setIpv4OamAddress("dhv-test-gvnf-ipv4-oam-address"); + genericVnfItem.getGenericVnf().setIpv4Loopback0Address("dhv-test-gvnfipv4-loopback0-address"); + genericVnfItem.getGenericVnf().setInMaint(false); + genericVnfItem.getGenericVnf().setIsClosedLoopDisabled(false); + genericVnfItem.getGenericVnf().setResourceVersion("1485366450"); + genericVnfItem.getGenericVnf().setEncrypedAccessFlag(true); + genericVnfItem.getGenericVnf().setPersonaModelId("acc6edd8-a8d4-4b93-afaa-0994068be14c"); + genericVnfItem.getGenericVnf().setPersonaModelVersion("1.0"); + genericVnfItem.setExtraProperties(new AaiNqExtraProperties()); + genericVnfItem.getExtraProperties().setExtraProperty(new LinkedList<>()); + genericVnfItem.getExtraProperties().getExtraProperty() + .add(new AaiNqExtraProperty("model.model-name", "generic-vnf")); + genericVnfItem.getExtraProperties().getExtraProperty() + .add(new AaiNqExtraProperty("model.model-type", "widget")); + genericVnfItem.getExtraProperties().getExtraProperty() + .add(new AaiNqExtraProperty("model.model-version", "1.0")); + genericVnfItem.getExtraProperties().getExtraProperty() + .add(new AaiNqExtraProperty("model.model-id", "acc6edd8-a8d4-4b93-afaa-0994068be14c")); + genericVnfItem.getExtraProperties().getExtraProperty() + .add(new AaiNqExtraProperty("model.model-name-version-id", "93a6166f-b3d5-4f06-b4ba-aed48d009ad9")); + genericVnfItem.setItems(new AaiNqInventoryResponseItems()); + genericVnfItem.getItems().setInventoryResponseItems(new LinkedList<>()); + genericVnfItem.getItems().getInventoryResponseItems().add(serviceItem); + genericVnfItem.getItems().getInventoryResponseItems().add(vfModuleItem); + + AaiNqInventoryResponseItem cloudItem = new AaiNqInventoryResponseItem(); + cloudItem.setCloudRegion(new AaiNqCloudRegion()); + cloudItem.getCloudRegion().setCloudOwner("OWNER"); + cloudItem.getCloudRegion().setCloudRegionId("REGIONID"); + cloudItem.getCloudRegion().setCloudRegionVersion("2.5"); + cloudItem.getCloudRegion().setComplexName("COMPLEXNAME"); + cloudItem.getCloudRegion().setResourceVersion("1485365988"); + + AaiNqInventoryResponseItem tenantItem = new AaiNqInventoryResponseItem(); + tenantItem.setTenant(new AaiNqTenant()); + tenantItem.getTenant().setTenantId("dhv-test-tenant"); + tenantItem.getTenant().setTenantName("dhv-test-tenant-name"); + tenantItem.getTenant().setResourceVersion("1485366334"); + tenantItem.setItems(new AaiNqInventoryResponseItems()); + tenantItem.getItems().setInventoryResponseItems(new LinkedList<>()); + tenantItem.getItems().getInventoryResponseItems().add(cloudItem); + AaiNqInventoryResponseItem vserverItem = new AaiNqInventoryResponseItem(); + vserverItem.setVserver(new AaiNqVServer()); + vserverItem.getVserver().setVserverId("dhv-test-vserver"); + vserverItem.getVserver().setVserverName("dhv-test-vserver-name"); + vserverItem.getVserver().setVserverName2("dhv-test-vserver-name2"); + vserverItem.getVserver().setProvStatus("PREPROV"); + vserverItem.getVserver().setVserverSelflink("dhv-test-vserver-selflink"); + vserverItem.getVserver().setInMaint(false); + vserverItem.getVserver().setIsClosedLoopDisabled(false); + vserverItem.getVserver().setResourceVersion("1485366417"); + vserverItem.setItems(new AaiNqInventoryResponseItems()); + vserverItem.getItems().setInventoryResponseItems(new LinkedList<>()); + vserverItem.getItems().getInventoryResponseItems().add(genericVnfItem); + vserverItem.getItems().getInventoryResponseItems().add(tenantItem); + + AaiNqInventoryResponseItems aaiNqInventoryResponseItems = new AaiNqInventoryResponseItems(); + aaiNqInventoryResponseItems.getInventoryResponseItems().add(vserverItem); + assertNotNull(aaiNqInventoryResponseItems); + logger.info(Serialization.gsonPretty.toJson(aaiNqInventoryResponseItems)); + } + +} diff --git a/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiNqNamedQueryTest.java b/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiNqNamedQueryTest.java new file mode 100644 index 000000000..a62046681 --- /dev/null +++ b/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiNqNamedQueryTest.java @@ -0,0 +1,49 @@ +/*- + * ============LICENSE_START======================================================= + * aai + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.aai; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.util.UUID; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +public class AaiNqNamedQueryTest { + + @BeforeClass + public static void setUpBeforeClass() throws Exception {} + + @AfterClass + public static void tearDownAfterClass() throws Exception {} + + @Test + public void test() { + AaiNqNamedQuery aaiNqNamedQuery = new AaiNqNamedQuery(); + UUID uuid = UUID.randomUUID(); + aaiNqNamedQuery.setNamedQueryUuid(uuid); + assertNotNull(aaiNqNamedQuery); + assertEquals(aaiNqNamedQuery.getNamedQueryUuid(), uuid); + } +} diff --git a/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiNqQueryParametersTest.java b/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiNqQueryParametersTest.java new file mode 100644 index 000000000..2c1c0bf74 --- /dev/null +++ b/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiNqQueryParametersTest.java @@ -0,0 +1,51 @@ +/*- + * ============LICENSE_START======================================================= + * aai + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.aai; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.util.UUID; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +public class AaiNqQueryParametersTest { + + @BeforeClass + public static void setUpBeforeClass() throws Exception {} + + @AfterClass + public static void tearDownAfterClass() throws Exception {} + + @Test + public void test() { + AaiNqQueryParameters aaiNqQueryParameters = new AaiNqQueryParameters(); + AaiNqNamedQuery aaiNqNamedQuery = new AaiNqNamedQuery(); + aaiNqNamedQuery.setNamedQueryUuid(UUID.randomUUID()); + aaiNqQueryParameters.setNamedQuery(aaiNqNamedQuery); + assertNotNull(aaiNqNamedQuery); + assertEquals(aaiNqQueryParameters.getNamedQuery(), aaiNqNamedQuery); + } + +} diff --git a/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiNqRequestErrorTest.java b/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiNqRequestErrorTest.java new file mode 100644 index 000000000..6aff8bc55 --- /dev/null +++ b/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiNqRequestErrorTest.java @@ -0,0 +1,42 @@ +/*- + * ============LICENSE_START======================================================= + * aai + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.aai; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import org.junit.Test; + +public class AaiNqRequestErrorTest { + + @Test + public void test() { + AaiNqRequestError aainqRequestError = new AaiNqRequestError(); + AaiNqServiceExcept serviceExcept = new AaiNqServiceExcept(); + aainqRequestError.setServiceExcept(serviceExcept); + assertEquals(aainqRequestError.getServiceExcept(), serviceExcept); + + assertNull(serviceExcept.getMessageId()); + assertNull(serviceExcept.getText()); + assertNull(serviceExcept.getVariables()); + } +} diff --git a/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiNqRequestTest.java b/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiNqRequestTest.java new file mode 100644 index 000000000..982258a29 --- /dev/null +++ b/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiNqRequestTest.java @@ -0,0 +1,69 @@ +/*- + * ============LICENSE_START======================================================= + * aai + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.aai; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.util.UUID; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.onap.policy.aai.util.Serialization; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class AaiNqRequestTest { + private static final Logger logger = LoggerFactory.getLogger(AaiNqRequestTest.class); + + @BeforeClass + public static void setUpBeforeClass() throws Exception {} + + @AfterClass + public static void tearDownAfterClass() throws Exception {} + + @Test + public void test() { + AaiNqRequest aaiNqRequest = new AaiNqRequest(); + AaiNqInstanceFilters aaiNqInstanceFilters = new AaiNqInstanceFilters(); + + aaiNqRequest.setInstanceFilters(aaiNqInstanceFilters); + assertNotNull(aaiNqRequest.getInstanceFilters()); + AaiNqNamedQuery aaiNqNamedQuery = new AaiNqNamedQuery(); + UUID uuid = UUID.randomUUID(); + aaiNqNamedQuery.setNamedQueryUuid(uuid); + + AaiNqQueryParameters aaiNqQueryParameters = new AaiNqQueryParameters(); + aaiNqQueryParameters.setNamedQuery(aaiNqNamedQuery); + aaiNqRequest.setQueryParameters(aaiNqQueryParameters); + + assertNotNull(aaiNqRequest); + + assertEquals(aaiNqNamedQuery.getNamedQueryUuid(), uuid); + assertEquals(aaiNqQueryParameters.getNamedQuery(), aaiNqNamedQuery); + assertEquals(aaiNqRequest.getQueryParameters(), aaiNqQueryParameters); + + logger.info(Serialization.gsonPretty.toJson(aaiNqRequest)); + } + +} diff --git a/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiNqResponseTest.java b/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiNqResponseTest.java new file mode 100644 index 000000000..42979a45d --- /dev/null +++ b/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiNqResponseTest.java @@ -0,0 +1,161 @@ +/*- + * ============LICENSE_START======================================================= + * aai + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.aai; + +import java.util.LinkedList; + +import org.junit.Test; +import org.onap.policy.aai.util.Serialization; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class AaiNqResponseTest { + private static final Logger logger = LoggerFactory.getLogger(AaiNqResponseTest.class); + + @Test + public void test() { + getAaiNqResponse(); + } + + /** + * Get A&AI NQ response. + * + * @return the A&AI NG response + */ + public AaiNqResponse getAaiNqResponse() { + AaiNqInventoryResponseItem serviceItem = new AaiNqInventoryResponseItem(); + serviceItem.setModelName("service-instance"); + serviceItem.setServiceInstance(new AaiNqServiceInstance()); + serviceItem.getServiceInstance().setServiceInstanceId("dhv-test-vhnfportal-service-instance-id"); + serviceItem.getServiceInstance().setServiceInstanceName("dhv-test-service-instance-name1"); + serviceItem.getServiceInstance().setPersonaModelId("82194af1-3c2c-485a-8f44-420e22a9eaa4"); + serviceItem.getServiceInstance().setPersonaModelVersion("1.0"); + serviceItem.getServiceInstance().setServiceInstanceLocationId("dhv-test-service-instance-location-id1"); + serviceItem.getServiceInstance().setResourceVersion("1485366092"); + serviceItem.setExtraProperties(new AaiNqExtraProperties()); + serviceItem.getExtraProperties().getExtraProperty() + .add(new AaiNqExtraProperty("model.model-name", "service-instance")); + serviceItem.getExtraProperties().getExtraProperty().add(new AaiNqExtraProperty("model.model-type", "widget")); + serviceItem.getExtraProperties().getExtraProperty().add(new AaiNqExtraProperty("model.model-version", "1.0")); + serviceItem.getExtraProperties().getExtraProperty() + .add(new AaiNqExtraProperty("model.model-id", "82194af1-3c2c-485a-8f44-420e22a9eaa4")); + serviceItem.getExtraProperties().getExtraProperty() + .add(new AaiNqExtraProperty("model.model-name", "46b92144-923a-4d20-b85a-3cbd847668a9")); + + AaiNqInventoryResponseItem vfModuleItem = new AaiNqInventoryResponseItem(); + vfModuleItem.setModelName("vf-module"); + vfModuleItem.setVfModule(new AaiNqVfModule()); + vfModuleItem.getVfModule().setVfModuleId("example-vf-module-id-val-49261"); + vfModuleItem.getVfModule().setVfModuleName("example-vf-module-name-val-73074"); + vfModuleItem.getVfModule().setHeatStackId("example-heat-stack-id-val-86300"); + vfModuleItem.getVfModule().setOrchestrationStatus("example-orchestration-status-val-56523"); + vfModuleItem.getVfModule().setIsBaseVfModule(true); + vfModuleItem.getVfModule().setResourceVersion("1485366450"); + vfModuleItem.getVfModule().setPersonaModelId("ef86f9c5-2165-44f3-8fc3-96018b609ea5"); + vfModuleItem.getVfModule().setPersonaModelVersion("1.0"); + vfModuleItem.getVfModule().setWidgetModelId("example-widget-model-id-val-92571"); + vfModuleItem.getVfModule().setWidgetModelVersion("example-widget-model-version-val-83317"); + vfModuleItem.getVfModule().setContrailServiceInstanceFqdn("example-contrail-service-instance-fqdn-val-86796"); + vfModuleItem.setExtraProperties(new AaiNqExtraProperties()); + vfModuleItem.getExtraProperties().getExtraProperty() + .add(new AaiNqExtraProperty("model.model-name", "vf-module")); + vfModuleItem.getExtraProperties().getExtraProperty().add(new AaiNqExtraProperty("model.model-type", "widget")); + vfModuleItem.getExtraProperties().getExtraProperty().add(new AaiNqExtraProperty("model.model-version", "1.0")); + vfModuleItem.getExtraProperties().getExtraProperty() + .add(new AaiNqExtraProperty("model.model-id", "ef86f9c5-2165-44f3-8fc3-96018b609ea5")); + vfModuleItem.getExtraProperties().getExtraProperty() + .add(new AaiNqExtraProperty("model.model-name", "c00563ae-812b-4e62-8330-7c4d0f47088a")); + + AaiNqInventoryResponseItem genericVnfItem = new AaiNqInventoryResponseItem(); + genericVnfItem.setModelName("generic-vnf"); + genericVnfItem.setGenericVnf(new AaiNqGenericVnf()); + genericVnfItem.getGenericVnf().setVnfId("dhv-test-gvnf"); + genericVnfItem.getGenericVnf().setVnfName("dhv-test-gvnf-name"); + genericVnfItem.getGenericVnf().setVnfName2("dhv-test-gvnf-name2"); + genericVnfItem.getGenericVnf().setVnfType("SW"); + genericVnfItem.getGenericVnf().setServiceId("d7bb0a21-66f2-4e6d-87d9-9ef3ced63ae4"); + genericVnfItem.getGenericVnf().setProvStatus("PREPROV"); + genericVnfItem.getGenericVnf().setOperationalState("dhv-test-operational-state"); + genericVnfItem.getGenericVnf().setIpv4OamAddress("dhv-test-gvnf-ipv4-oam-address"); + genericVnfItem.getGenericVnf().setIpv4Loopback0Address("dhv-test-gvnfipv4-loopback0-address"); + genericVnfItem.getGenericVnf().setInMaint(false); + genericVnfItem.getGenericVnf().setIsClosedLoopDisabled(false); + genericVnfItem.getGenericVnf().setResourceVersion("1485366450"); + genericVnfItem.getGenericVnf().setEncrypedAccessFlag(true); + genericVnfItem.getGenericVnf().setPersonaModelId("acc6edd8-a8d4-4b93-afaa-0994068be14c"); + genericVnfItem.getGenericVnf().setPersonaModelVersion("1.0"); + genericVnfItem.setExtraProperties(new AaiNqExtraProperties()); + genericVnfItem.getExtraProperties().setExtraProperty(new LinkedList<>()); + genericVnfItem.getExtraProperties().getExtraProperty() + .add(new AaiNqExtraProperty("model.model-name", "generic-vnf")); + genericVnfItem.getExtraProperties().getExtraProperty() + .add(new AaiNqExtraProperty("model.model-type", "widget")); + genericVnfItem.getExtraProperties().getExtraProperty() + .add(new AaiNqExtraProperty("model.model-version", "1.0")); + genericVnfItem.getExtraProperties().getExtraProperty() + .add(new AaiNqExtraProperty("model.model-id", "acc6edd8-a8d4-4b93-afaa-0994068be14c")); + genericVnfItem.getExtraProperties().getExtraProperty() + .add(new AaiNqExtraProperty("model.model-name-version-id", "93a6166f-b3d5-4f06-b4ba-aed48d009ad9")); + genericVnfItem.setItems(new AaiNqInventoryResponseItems()); + genericVnfItem.getItems().setInventoryResponseItems(new LinkedList<>()); + genericVnfItem.getItems().getInventoryResponseItems().add(serviceItem); + genericVnfItem.getItems().getInventoryResponseItems().add(vfModuleItem); + + AaiNqInventoryResponseItem cloudItem = new AaiNqInventoryResponseItem(); + cloudItem.setCloudRegion(new AaiNqCloudRegion()); + cloudItem.getCloudRegion().setCloudOwner("OWNER"); + cloudItem.getCloudRegion().setCloudRegionId("REGIONID"); + cloudItem.getCloudRegion().setCloudRegionVersion("2.5"); + cloudItem.getCloudRegion().setComplexName("COMPLEXNAME"); + cloudItem.getCloudRegion().setResourceVersion("1485365988"); + + AaiNqInventoryResponseItem tenantItem = new AaiNqInventoryResponseItem(); + tenantItem.setTenant(new AaiNqTenant()); + tenantItem.getTenant().setTenantId("dhv-test-tenant"); + tenantItem.getTenant().setTenantName("dhv-test-tenant-name"); + tenantItem.getTenant().setResourceVersion("1485366334"); + tenantItem.setItems(new AaiNqInventoryResponseItems()); + tenantItem.getItems().setInventoryResponseItems(new LinkedList<>()); + tenantItem.getItems().getInventoryResponseItems().add(cloudItem); + + AaiNqInventoryResponseItem vserverItem = new AaiNqInventoryResponseItem(); + vserverItem.setVserver(new AaiNqVServer()); + vserverItem.getVserver().setVserverId("dhv-test-vserver"); + vserverItem.getVserver().setVserverName("dhv-test-vserver-name"); + vserverItem.getVserver().setVserverName2("dhv-test-vserver-name2"); + vserverItem.getVserver().setProvStatus("PREPROV"); + vserverItem.getVserver().setVserverSelflink("dhv-test-vserver-selflink"); + vserverItem.getVserver().setInMaint(false); + vserverItem.getVserver().setIsClosedLoopDisabled(false); + vserverItem.getVserver().setResourceVersion("1485366417"); + vserverItem.setItems(new AaiNqInventoryResponseItems()); + vserverItem.getItems().setInventoryResponseItems(new LinkedList<>()); + vserverItem.getItems().getInventoryResponseItems().add(genericVnfItem); + vserverItem.getItems().getInventoryResponseItems().add(tenantItem); + + AaiNqResponse aaiResponse = new AaiNqResponse(); + aaiResponse.getInventoryResponseItems().add(vserverItem); + logger.info(Serialization.gsonPretty.toJson(aaiResponse)); + + return aaiResponse; + } +} diff --git a/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiNqResponseWrapperTest.java b/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiNqResponseWrapperTest.java new file mode 100644 index 000000000..574ee8670 --- /dev/null +++ b/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiNqResponseWrapperTest.java @@ -0,0 +1,262 @@ +/*- + * ============LICENSE_START======================================================= + * aai + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.aai; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.LinkedList; +import java.util.List; +import java.util.UUID; +import org.apache.commons.io.IOUtils; +import org.junit.Test; +import org.onap.policy.aai.util.Serialization; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class AaiNqResponseWrapperTest { + private static final Logger logger = LoggerFactory.getLogger(AaiNqResponseWrapperTest.class); + + @Test + public void test() { + AaiNqInventoryResponseItem serviceItem = new AaiNqInventoryResponseItem(); + serviceItem.setModelName("service-instance"); + serviceItem.setServiceInstance(new AaiNqServiceInstance()); + serviceItem.getServiceInstance().setServiceInstanceId("dhv-test-vhnfportal-service-instance-id"); + serviceItem.getServiceInstance().setServiceInstanceName("dhv-test-service-instance-name1"); + serviceItem.getServiceInstance().setPersonaModelId("82194af1-3c2c-485a-8f44-420e22a9eaa4"); + serviceItem.getServiceInstance().setPersonaModelVersion("1.0"); + serviceItem.getServiceInstance().setServiceInstanceLocationId("dhv-test-service-instance-location-id1"); + serviceItem.getServiceInstance().setResourceVersion("1485366092"); + serviceItem.setExtraProperties(new AaiNqExtraProperties()); + serviceItem.getExtraProperties().getExtraProperty() + .add(new AaiNqExtraProperty("model.model-name", "service-instance")); + serviceItem.getExtraProperties().getExtraProperty().add(new AaiNqExtraProperty("model.model-type", "widget")); + serviceItem.getExtraProperties().getExtraProperty().add(new AaiNqExtraProperty("model.model-version", "1.0")); + serviceItem.getExtraProperties().getExtraProperty() + .add(new AaiNqExtraProperty("model.model-id", "82194af1-3c2c-485a-8f44-420e22a9eaa4")); + serviceItem.getExtraProperties().getExtraProperty() + .add(new AaiNqExtraProperty("model.model-name", "46b92144-923a-4d20-b85a-3cbd847668a9")); + + AaiNqInventoryResponseItem vfModuleItem = new AaiNqInventoryResponseItem(); + vfModuleItem.setModelName("vf-module"); + vfModuleItem.setVfModule(new AaiNqVfModule()); + vfModuleItem.getVfModule().setVfModuleId("example-vf-module-id-val-49261"); + vfModuleItem.getVfModule().setVfModuleName("example-vf-module-name-val-73074"); + vfModuleItem.getVfModule().setHeatStackId("example-heat-stack-id-val-86300"); + vfModuleItem.getVfModule().setOrchestrationStatus("example-orchestration-status-val-56523"); + vfModuleItem.getVfModule().setIsBaseVfModule(true); + vfModuleItem.getVfModule().setResourceVersion("1485366450"); + vfModuleItem.getVfModule().setPersonaModelId("ef86f9c5-2165-44f3-8fc3-96018b609ea5"); + vfModuleItem.getVfModule().setPersonaModelVersion("1.0"); + vfModuleItem.getVfModule().setWidgetModelId("example-widget-model-id-val-92571"); + vfModuleItem.getVfModule().setWidgetModelVersion("example-widget-model-version-val-83317"); + vfModuleItem.getVfModule().setContrailServiceInstanceFqdn("example-contrail-service-instance-fqdn-val-86796"); + vfModuleItem.setExtraProperties(new AaiNqExtraProperties()); + vfModuleItem.getExtraProperties().getExtraProperty() + .add(new AaiNqExtraProperty("model.model-name", "vf-module")); + vfModuleItem.getExtraProperties().getExtraProperty().add(new AaiNqExtraProperty("model.model-type", "widget")); + vfModuleItem.getExtraProperties().getExtraProperty().add(new AaiNqExtraProperty("model.model-version", "1.0")); + vfModuleItem.getExtraProperties().getExtraProperty() + .add(new AaiNqExtraProperty("model.model-id", "ef86f9c5-2165-44f3-8fc3-96018b609ea5")); + vfModuleItem.getExtraProperties().getExtraProperty() + .add(new AaiNqExtraProperty("model.model-name", "c00563ae-812b-4e62-8330-7c4d0f47088a")); + + AaiNqInventoryResponseItem genericVnfItem = new AaiNqInventoryResponseItem(); + genericVnfItem.setModelName("generic-vnf"); + genericVnfItem.setGenericVnf(new AaiNqGenericVnf()); + genericVnfItem.getGenericVnf().setVnfId("dhv-test-gvnf"); + genericVnfItem.getGenericVnf().setVnfName("dhv-test-gvnf-name"); + genericVnfItem.getGenericVnf().setVnfName2("dhv-test-gvnf-name2"); + genericVnfItem.getGenericVnf().setVnfType("SW"); + genericVnfItem.getGenericVnf().setServiceId("d7bb0a21-66f2-4e6d-87d9-9ef3ced63ae4"); + genericVnfItem.getGenericVnf().setProvStatus("PREPROV"); + genericVnfItem.getGenericVnf().setOperationalState("dhv-test-operational-state"); + genericVnfItem.getGenericVnf().setIpv4OamAddress("dhv-test-gvnf-ipv4-oam-address"); + genericVnfItem.getGenericVnf().setIpv4Loopback0Address("dhv-test-gvnfipv4-loopback0-address"); + genericVnfItem.getGenericVnf().setInMaint(false); + genericVnfItem.getGenericVnf().setIsClosedLoopDisabled(false); + genericVnfItem.getGenericVnf().setResourceVersion("1485366450"); + genericVnfItem.getGenericVnf().setEncrypedAccessFlag(true); + genericVnfItem.getGenericVnf().setPersonaModelId("acc6edd8-a8d4-4b93-afaa-0994068be14c"); + genericVnfItem.getGenericVnf().setPersonaModelVersion("1.0"); + genericVnfItem.setExtraProperties(new AaiNqExtraProperties()); + genericVnfItem.getExtraProperties().setExtraProperty(new LinkedList<>()); + genericVnfItem.getExtraProperties().getExtraProperty() + .add(new AaiNqExtraProperty("model.model-name", "generic-vnf")); + genericVnfItem.getExtraProperties().getExtraProperty() + .add(new AaiNqExtraProperty("model.model-type", "widget")); + genericVnfItem.getExtraProperties().getExtraProperty() + .add(new AaiNqExtraProperty("model.model-version", "1.0")); + genericVnfItem.getExtraProperties().getExtraProperty() + .add(new AaiNqExtraProperty("model.model-id", "acc6edd8-a8d4-4b93-afaa-0994068be14c")); + genericVnfItem.getExtraProperties().getExtraProperty() + .add(new AaiNqExtraProperty("model.model-name-version-id", "93a6166f-b3d5-4f06-b4ba-aed48d009ad9")); + genericVnfItem.setItems(new AaiNqInventoryResponseItems()); + genericVnfItem.getItems().setInventoryResponseItems(new LinkedList<>()); + genericVnfItem.getItems().getInventoryResponseItems().add(serviceItem); + genericVnfItem.getItems().getInventoryResponseItems().add(vfModuleItem); + + AaiNqInventoryResponseItem cloudItem = new AaiNqInventoryResponseItem(); + cloudItem.setCloudRegion(new AaiNqCloudRegion()); + cloudItem.getCloudRegion().setCloudOwner("OWNER"); + cloudItem.getCloudRegion().setCloudRegionId("REGIONID"); + cloudItem.getCloudRegion().setCloudRegionVersion("2.5"); + cloudItem.getCloudRegion().setComplexName("COMPLEXNAME"); + cloudItem.getCloudRegion().setResourceVersion("1485365988"); + + AaiNqInventoryResponseItem tenantItem = new AaiNqInventoryResponseItem(); + tenantItem.setTenant(new AaiNqTenant()); + tenantItem.getTenant().setTenantId("dhv-test-tenant"); + tenantItem.getTenant().setTenantName("dhv-test-tenant-name"); + tenantItem.getTenant().setResourceVersion("1485366334"); + tenantItem.setItems(new AaiNqInventoryResponseItems()); + tenantItem.getItems().setInventoryResponseItems(new LinkedList<>()); + tenantItem.getItems().getInventoryResponseItems().add(cloudItem); + + AaiNqInventoryResponseItem vserverItem = new AaiNqInventoryResponseItem(); + vserverItem.setVserver(new AaiNqVServer()); + vserverItem.getVserver().setVserverId("dhv-test-vserver"); + vserverItem.getVserver().setVserverName("dhv-test-vserver-name"); + vserverItem.getVserver().setVserverName2("dhv-test-vserver-name2"); + vserverItem.getVserver().setProvStatus("PREPROV"); + vserverItem.getVserver().setVserverSelflink("dhv-test-vserver-selflink"); + vserverItem.getVserver().setInMaint(false); + vserverItem.getVserver().setIsClosedLoopDisabled(false); + vserverItem.getVserver().setResourceVersion("1485366417"); + vserverItem.setItems(new AaiNqInventoryResponseItems()); + vserverItem.getItems().setInventoryResponseItems(new LinkedList<>()); + vserverItem.getItems().getInventoryResponseItems().add(genericVnfItem); + vserverItem.getItems().getInventoryResponseItems().add(tenantItem); + + AaiNqResponse aaiResponse = new AaiNqResponse(); + aaiResponse.getInventoryResponseItems().add(vserverItem); + AaiNqResponseWrapper aaiNqResponseWarapper = new AaiNqResponseWrapper(); + aaiNqResponseWarapper.setAaiNqResponse(aaiResponse); + aaiNqResponseWarapper.setRequestId(UUID.randomUUID()); + assertNotNull(aaiNqResponseWarapper); + logger.info(Serialization.gsonPretty.toJson(aaiNqResponseWarapper)); + + AaiNqResponse aaiResponse2 = new AaiNqResponse(); + aaiResponse2.getInventoryResponseItems().add(vserverItem); + AaiNqResponseWrapper aaiNqResponseWarapper2 = new AaiNqResponseWrapper(UUID.randomUUID(), aaiResponse); + assertNotNull(aaiNqResponseWarapper2); + assertNotNull(aaiNqResponseWarapper2.getRequestId()); + assertNotNull(aaiNqResponseWarapper2.getAaiNqResponse()); + logger.info(Serialization.gsonPretty.toJson(aaiNqResponseWarapper2)); + } + + @Test + public void testCountVfModules() throws Exception { + AaiNqResponseWrapper resp; + + // null item + resp = new AaiNqResponseWrapper(); + assertEquals(0, resp.countVfModules()); + + // no names + resp.setAaiNqResponse(load("AaiNqResponseWrapper-NoNames.json")); + assertEquals(0, resp.countVfModules()); + + // has VF modules + resp.setAaiNqResponse(load("AaiNqResponseWrapper-Vserver.json")); + assertEquals(3, resp.countVfModules()); + } + + @Test + public void testGenVfModuleName() throws Exception { + AaiNqResponseWrapper resp; + + // null item + resp = new AaiNqResponseWrapper(); + assertEquals(null, resp.genVfModuleName()); + + // no names + resp.setAaiNqResponse(load("AaiNqResponseWrapper-NoNames.json")); + assertEquals(null, resp.genVfModuleName()); + + // has VF modules + resp.setAaiNqResponse(load("AaiNqResponseWrapper-Vserver.json")); + assertEquals("my-module-abc_124", resp.genVfModuleName()); + } + + @Test + public void testGetVfModules() throws Exception { + AaiNqResponseWrapper resp; + + // null item + resp = new AaiNqResponseWrapper(); + assertTrue(resp.getVfModuleItems(true).isEmpty()); + + // missing item + resp = new AaiNqResponseWrapper(); + resp.setAaiNqResponse(new AaiNqResponse()); + assertTrue(resp.getVfModuleItems(false).isEmpty()); + + // null item list + resp.setAaiNqResponse(load("AaiNqResponseWrapper-NoItems.json")); + resp.getAaiNqResponse().getInventoryResponseItems().get(0).getItems().getInventoryResponseItems().get(0) + .getItems().setInventoryResponseItems(null); + assertTrue(resp.getVfModuleItems(false).isEmpty()); + + // no modules + resp.setAaiNqResponse(load("AaiNqResponseWrapper-NoModules.json")); + assertTrue(resp.getVfModuleItems(false).isEmpty()); + + // no names + resp.setAaiNqResponse(load("AaiNqResponseWrapper-NoNames.json")); + List<AaiNqInventoryResponseItem> lst; + lst = resp.getVfModuleItems(false); + assertEquals(0, lst.size()); + + // base VF modules + resp.setAaiNqResponse(load("AaiNqResponseWrapper-Vserver.json")); + lst = resp.getVfModuleItems(true); + assertEquals(1, lst.size()); + assertEquals("Vfmodule_vLBMS-0809-1", lst.get(0).getVfModule().getVfModuleName()); + + // non base VF modules + resp.setAaiNqResponse(load("AaiNqResponseWrapper-Vserver.json")); + lst = resp.getVfModuleItems(false); + assertEquals(3, lst.size()); + int index; + index = 0; + assertEquals("my-module-abc_1", lst.get(index++).getVfModule().getVfModuleName()); + assertEquals("my-module-abc_123", lst.get(index++).getVfModule().getVfModuleName()); + assertEquals("my-module-abc_34", lst.get(index++).getVfModule().getVfModuleName()); + } + + /** + * Loads a response from a JSON file. + * + * @param fileName name of the file containing the JSON response + * @return the response + * @throws IOException if the file cannot be read + */ + private AaiNqResponse load(String fileName) throws IOException { + String json = IOUtils.toString(getClass().getResource(fileName), StandardCharsets.UTF_8); + return Serialization.gsonPretty.fromJson(json, AaiNqResponse.class); + } +} diff --git a/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiNqServiceInstanceTest.java b/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiNqServiceInstanceTest.java new file mode 100644 index 000000000..946372cc9 --- /dev/null +++ b/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiNqServiceInstanceTest.java @@ -0,0 +1,66 @@ +/*- + * ============LICENSE_START======================================================= + * aai + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.aai; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.onap.policy.aai.util.Serialization; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class AaiNqServiceInstanceTest { + private static final Logger logger = LoggerFactory.getLogger(AaiNqServiceInstanceTest.class); + + @BeforeClass + public static void setUpBeforeClass() throws Exception {} + + @AfterClass + public static void tearDownAfterClass() throws Exception {} + + @Test + public void test() { + AaiNqServiceInstance aaiNqServiceInstance = new AaiNqServiceInstance(); + aaiNqServiceInstance.setServiceInstanceId("dhv-test-vhnfportal-service-instance-id"); + aaiNqServiceInstance.setServiceInstanceName("dhv-test-service-instance-name1"); + aaiNqServiceInstance.setPersonaModelId("82194af1-3c2c-485a-8f44-420e22a9eaa4"); + aaiNqServiceInstance.setPersonaModelVersion("1.0"); + aaiNqServiceInstance.setServiceInstanceLocationId("dhv-test-service-instance-location-id1"); + aaiNqServiceInstance.setResourceVersion("1485366092"); + aaiNqServiceInstance.setModelInvariantId("SomeID"); + aaiNqServiceInstance.setModelVersionId("SomeVersion"); + assertNotNull(aaiNqServiceInstance); + assertEquals("dhv-test-vhnfportal-service-instance-id", aaiNqServiceInstance.getServiceInstanceId()); + assertEquals("dhv-test-service-instance-name1", aaiNqServiceInstance.getServiceInstanceName()); + assertEquals("82194af1-3c2c-485a-8f44-420e22a9eaa4", aaiNqServiceInstance.getPersonaModelId()); + assertEquals("1.0", aaiNqServiceInstance.getPersonaModelVersion()); + assertEquals("dhv-test-service-instance-location-id1", aaiNqServiceInstance.getServiceInstanceLocationId()); + assertEquals("1485366092", aaiNqServiceInstance.getResourceVersion()); + assertEquals("SomeID", aaiNqServiceInstance.getModelInvariantId()); + assertEquals("SomeVersion", aaiNqServiceInstance.getModelVersionId()); + logger.info(Serialization.gsonPretty.toJson(aaiNqServiceInstance)); + } + +} diff --git a/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiNqTenantTest.java b/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiNqTenantTest.java new file mode 100644 index 000000000..18e2de40f --- /dev/null +++ b/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiNqTenantTest.java @@ -0,0 +1,57 @@ +/*- + * ============LICENSE_START======================================================= + * aai + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.aai; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.onap.policy.aai.util.Serialization; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class AaiNqTenantTest { + private static final Logger logger = LoggerFactory.getLogger(AaiNqTenantTest.class); + + @BeforeClass + public static void setUpBeforeClass() throws Exception {} + + @AfterClass + public static void tearDownAfterClass() throws Exception {} + + @Test + public void test() { + AaiNqTenant aaiNqTenant = new AaiNqTenant(); + aaiNqTenant.setTenantId("dhv-test-tenant"); + aaiNqTenant.setTenantName("dhv-test-tenant-name"); + aaiNqTenant.setResourceVersion("1485366334"); + assertNotNull(aaiNqTenant); + assertEquals("dhv-test-tenant", aaiNqTenant.getTenantId()); + assertEquals("dhv-test-tenant-name", aaiNqTenant.getTenantName()); + assertEquals("1485366334", aaiNqTenant.getResourceVersion()); + + logger.info(Serialization.gsonPretty.toJson(aaiNqTenant)); + } + +} diff --git a/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiNqVServerTest.java b/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiNqVServerTest.java new file mode 100644 index 000000000..e1b612370 --- /dev/null +++ b/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiNqVServerTest.java @@ -0,0 +1,102 @@ +/*- + * ============LICENSE_START======================================================= + * aai + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.aai; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.io.File; +import java.nio.file.Files; +import java.util.List; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.onap.policy.aai.util.Serialization; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class AaiNqVServerTest { + private static final Logger logger = LoggerFactory.getLogger(AaiNqVServerTest.class); + + + @BeforeClass + public static void setUpBeforeClass() throws Exception {} + + @AfterClass + public static void tearDownAfterClass() throws Exception {} + + @Test + public void test() throws Exception { + // deserialize json and verify fields are populated properly + String json = new String(Files + .readAllBytes(new File("src/test/resources/org/onap/policy/aai/AaiNqVServer.json").toPath())); + + AaiNqVServer resp = Serialization.gsonPretty.fromJson(json, AaiNqVServer.class); + + assertEquals(false, resp.getInMaint()); + assertEquals(true, resp.getIsClosedLoopDisabled()); + assertEquals("ACTIVE", resp.getProvStatus()); + assertEquals("1533850964910", resp.getResourceVersion()); + assertEquals("1c94da3f-16f1-4fc7-9ed1-e018dfa62774", resp.getVserverId()); + assertEquals("vlb-ms-0809-1", resp.getVserverName()); + assertEquals("vlb-ms-0809-7", resp.getVserverName2()); + assertEquals("http://localhost:8774/v2.1/4086f396c5e04caf9502c5fdeca575c4/servers/1c94da3f-16f1-4fc7-9ed1-e018dfa62774", + resp.getVserverSelflink()); + + // don't need to verify this in depth, as it has its own tests that do that + RelationshipList relationshipList = resp.getRelationshipList(); + assertNotNull(relationshipList); + + List<Relationship> lst = relationshipList.getRelationships(); + assertNotNull(lst); + + assertEquals(3, lst.size()); + assertEquals("generic-vnf", lst.get(0).getRelatedTo()); + assertEquals("image", lst.get(1).getRelatedTo()); + + logger.info(Serialization.gsonPretty.toJson(resp)); + + // verify that setXxx methods work + relationshipList = new RelationshipList(); + + resp.setInMaint(true); + resp.setIsClosedLoopDisabled(false); + resp.setProvStatus("inactive"); + resp.setRelationshipList(relationshipList); + resp.setResourceVersion("vers"); + resp.setVserverId("vid"); + resp.setVserverName("vname"); + resp.setVserverName2("vname2"); + resp.setVserverSelflink("link"); + + assertEquals(true, resp.getInMaint()); + assertEquals(false, resp.getIsClosedLoopDisabled()); + assertEquals("inactive", resp.getProvStatus()); + assertEquals("vers", resp.getResourceVersion()); + assertEquals("vid", resp.getVserverId()); + assertEquals("vname", resp.getVserverName()); + assertEquals("vname2", resp.getVserverName2()); + assertEquals("link", resp.getVserverSelflink()); + assertEquals(relationshipList, resp.getRelationshipList()); + } + +} diff --git a/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiNqVfModuleTest.java b/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiNqVfModuleTest.java new file mode 100644 index 000000000..da169d589 --- /dev/null +++ b/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiNqVfModuleTest.java @@ -0,0 +1,80 @@ +/*- + * ============LICENSE_START======================================================= + * aai + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.aai; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.onap.policy.aai.util.Serialization; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class AaiNqVfModuleTest { + private static final Logger logger = LoggerFactory.getLogger(AaiNqVfModuleTest.class); + + + @BeforeClass + public static void setUpBeforeClass() throws Exception {} + + @AfterClass + public static void tearDownAfterClass() throws Exception {} + + @Test + public void test() { + AaiNqVfModule aaiNqVfModule = new AaiNqVfModule(); + aaiNqVfModule.setVfModuleId("example-vf-module-id-val-49261"); + aaiNqVfModule.setVfModuleName("example-vf-module-name-val-73074"); + aaiNqVfModule.setHeatStackId("example-heat-stack-id-val-86300"); + aaiNqVfModule.setOrchestrationStatus("example-orchestration-status-val-56523"); + aaiNqVfModule.setIsBaseVfModule(true); + aaiNqVfModule.setResourceVersion("1485366450"); + aaiNqVfModule.setPersonaModelId("ef86f9c5-2165-44f3-8fc3-96018b609ea5"); + aaiNqVfModule.setPersonaModelVersion("1.0"); + aaiNqVfModule.setWidgetModelId("example-widget-model-id-val-92571"); + aaiNqVfModule.setWidgetModelVersion("example-widget-model-version-val-83317"); + aaiNqVfModule.setContrailServiceInstanceFqdn("example-contrail-service-instance-fqdn-val-86796"); + aaiNqVfModule.setModelInvariantId("SomeId"); + aaiNqVfModule.setModelVersionId("SomeVersion"); + aaiNqVfModule.setModelCustomizationId("SomeCustomizationId"); + assertNotNull(aaiNqVfModule); + assertEquals("example-vf-module-id-val-49261", aaiNqVfModule.getVfModuleId()); + assertEquals("example-vf-module-name-val-73074", aaiNqVfModule.getVfModuleName()); + assertEquals("example-heat-stack-id-val-86300", aaiNqVfModule.getHeatStackId()); + assertEquals("example-orchestration-status-val-56523", aaiNqVfModule.getOrchestrationStatus()); + assertEquals(true, aaiNqVfModule.getIsBaseVfModule()); + assertEquals("1485366450", aaiNqVfModule.getResourceVersion()); + assertEquals("ef86f9c5-2165-44f3-8fc3-96018b609ea5", aaiNqVfModule.getPersonaModelId()); + assertEquals("1.0", aaiNqVfModule.getPersonaModelVersion()); + assertEquals("example-widget-model-id-val-92571", aaiNqVfModule.getWidgetModelId()); + assertEquals("example-widget-model-version-val-83317", aaiNqVfModule.getWidgetModelVersion()); + assertEquals("example-contrail-service-instance-fqdn-val-86796", + aaiNqVfModule.getContrailServiceInstanceFqdn()); + assertEquals("SomeId", aaiNqVfModule.getModelInvariantId()); + assertEquals("SomeVersion", aaiNqVfModule.getModelVersionId()); + assertEquals("SomeCustomizationId", aaiNqVfModule.getModelCustomizationId()); + logger.info(Serialization.gsonPretty.toJson(aaiNqVfModule)); + } + +} diff --git a/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/PnfInstanceTest.java b/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/PnfInstanceTest.java new file mode 100644 index 000000000..9771d47d1 --- /dev/null +++ b/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/PnfInstanceTest.java @@ -0,0 +1,106 @@ +/*- + * ============LICENSE_START======================================================= + * aai + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.aai; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.onap.policy.aai.util.Serialization; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class PnfInstanceTest { + private static final Logger logger = LoggerFactory.getLogger(PnfInstanceTest.class); + + @BeforeClass + public static void setUpBeforeClass() throws Exception {} + + @AfterClass + public static void tearDownAfterClass() throws Exception {} + + @Test + public void test() { + PnfInstance pnfInstance = new PnfInstance(); + pnfInstance.setPnfInstanceName("pnf-instance-name-test"); + pnfInstance.setPnfName("pnf-name-test"); + pnfInstance.setPnfType(PnfType.ENODEB); + pnfInstance.setPnfSerial("pnf-serial-test"); + assertNotNull(pnfInstance); + assertEquals("pnf-instance-name-test", pnfInstance.getPnfInstanceName()); + + PnfInstance pnfInstanceNull = new PnfInstance(null); + assertNotNull(pnfInstanceNull); + + PnfInstance pnfInstanceClone = new PnfInstance(pnfInstance); + assertNotNull(pnfInstanceClone); + + assertEquals("pnf-name-test", pnfInstanceClone.getPnfName()); + assertEquals(PnfType.ENODEB, pnfInstanceClone.getPnfType()); + assertEquals("pnf-serial-test", pnfInstanceClone.getPnfSerial()); + + assertEquals("PNFInstance [PNFName=pnf-name-test, PNFInstanceName=pnf-instance-name-test, PNFType=eNodeB, " + + "PNFSerial=pnf-serial-test]", pnfInstanceClone.toString()); + assertNotEquals(0, pnfInstanceClone.hashCode()); + assertNotEquals(0, new Pnf().hashCode()); + + PnfInstance pnfInstanceOther0 = new PnfInstance(); + pnfInstanceOther0.setPnfName("pnf-name-test"); + + PnfInstance pnfInstanceOther1 = new PnfInstance(pnfInstance); + pnfInstanceOther1.setPnfName("pnf-name-test-diff"); + + PnfInstance pnfInstanceOther2 = new PnfInstance(pnfInstance); + pnfInstanceOther2.setPnfInstanceName("pnf-instance-name-test-diff"); + + PnfInstance pnfInstanceOther3 = new PnfInstance(pnfInstance); + pnfInstanceOther3.setPnfName(null); + + PnfInstance pnfInstanceOther4 = new PnfInstance(pnfInstance); + pnfInstanceOther4.setPnfSerial(null); + + PnfInstance pnfInstanceOther5 = new PnfInstance(pnfInstance); + pnfInstanceOther5.setPnfSerial("pnf-serial-test-diff"); + + assertTrue(pnfInstance.equals(pnfInstance)); + assertFalse(pnfInstance.equals(null)); + assertFalse(pnfInstance.equals("hello")); + assertTrue(pnfInstance.equals(pnfInstanceClone)); + assertFalse(pnfInstance.equals(new Pnf())); + assertFalse(new Pnf().equals(pnfInstance)); + assertFalse(new Pnf().equals(pnfInstanceOther0)); + assertFalse(pnfInstanceOther0.equals(pnfInstance)); + assertFalse(pnfInstanceOther1.equals(pnfInstance)); + assertFalse(pnfInstanceOther2.equals(pnfInstance)); + assertFalse(pnfInstanceOther3.equals(pnfInstance)); + assertFalse(pnfInstanceOther4.equals(pnfInstance)); + assertFalse(pnfInstanceOther5.equals(pnfInstance)); + + logger.info(Serialization.gsonPretty.toJson(pnfInstance)); + } + +} diff --git a/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/PnfTest.java b/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/PnfTest.java new file mode 100644 index 000000000..6efbb76c6 --- /dev/null +++ b/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/PnfTest.java @@ -0,0 +1,78 @@ +/*- + * ============LICENSE_START======================================================= + * aai + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.aai; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.onap.policy.aai.util.Serialization; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class PnfTest { + private static final Logger logger = LoggerFactory.getLogger(PnfTest.class); + + @BeforeClass + public static void setUpBeforeClass() throws Exception {} + + @AfterClass + public static void tearDownAfterClass() throws Exception {} + + @Test + public void test() { + Pnf pnf = new Pnf(); + pnf.setPnfName("pnf-name-test"); + pnf.setPnfType(PnfType.ENODEB); + assertNotNull(pnf); + + Pnf pnfClone = new Pnf(pnf); + assertNotNull(pnfClone); + + assertEquals("pnf-name-test", pnfClone.getPnfName()); + assertEquals(PnfType.ENODEB, pnfClone.getPnfType()); + + assertEquals("PNF [PNFName=pnf-name-test, PNFType=eNodeB]", pnfClone.toString()); + assertNotEquals(0, pnfClone.hashCode()); + assertNotEquals(0, new Pnf().hashCode()); + + Pnf pnfOther = new Pnf(); + pnfOther.setPnfName("pnf-name-test"); + + assertTrue(pnf.equals(pnf)); + assertFalse(pnf.equals(null)); + assertFalse(pnf.equals("hello")); + assertTrue(pnf.equals(pnfClone)); + assertFalse(pnf.equals(new Pnf())); + assertFalse(new Pnf().equals(pnf)); + assertFalse(new Pnf().equals(pnfOther)); + assertFalse(pnfOther.equals(pnf)); + + logger.info(Serialization.gsonPretty.toJson(pnf)); + } + +} diff --git a/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/PnfTypeTest.java b/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/PnfTypeTest.java new file mode 100644 index 000000000..e34c0e1c1 --- /dev/null +++ b/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/PnfTypeTest.java @@ -0,0 +1,51 @@ +/*- + * ============LICENSE_START======================================================= + * aai + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.aai; + +import static org.junit.Assert.assertNotNull; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.onap.policy.aai.util.Serialization; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class PnfTypeTest { + private static final Logger logger = LoggerFactory.getLogger(PnfTypeTest.class); + + + @BeforeClass + public static void setUpBeforeClass() throws Exception {} + + @AfterClass + public static void tearDownAfterClass() throws Exception {} + + @Test + public void test() { + PnfType pnfType = PnfType.ENODEB; + assertNotNull(pnfType); + assertNotNull(pnfType.toString()); + logger.info(Serialization.gsonPretty.toJson(pnfType)); + } + +} diff --git a/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/RelatedToPropertyTest.java b/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/RelatedToPropertyTest.java new file mode 100644 index 000000000..20697d832 --- /dev/null +++ b/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/RelatedToPropertyTest.java @@ -0,0 +1,57 @@ +/*- + * ============LICENSE_START======================================================= + * aai + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.aai; + +import static org.junit.Assert.assertEquals; + +import java.io.File; +import java.nio.file.Files; +import org.junit.Test; +import org.onap.policy.aai.util.Serialization; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class RelatedToPropertyTest { + private static final Logger logger = LoggerFactory.getLogger(RelatedToPropertyTest.class); + + @Test + public void test() throws Exception { + // deserialize json and verify fields are populated properly + String json = new String(Files.readAllBytes( + new File("src/test/resources/org/onap/policy/aai/RelatedToProperty.json").toPath())); + + RelatedToProperty relatedToProperty = Serialization.gsonPretty.fromJson(json, RelatedToProperty.class); + + assertEquals("generic-vnf.vnf-name", relatedToProperty.getPropertyKey()); + assertEquals("vLoadBalancerMS-Vnf-0809-1", relatedToProperty.getPropertyValue()); + + logger.info(Serialization.gsonPretty.toJson(relatedToProperty)); + + // verify that setXxx methods work + relatedToProperty.setPropertyKey("a key"); + relatedToProperty.setPropertyValue("a value"); + + assertEquals("a key", relatedToProperty.getPropertyKey()); + assertEquals("a value", relatedToProperty.getPropertyValue()); + } + +} diff --git a/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/RelationshipDataTest.java b/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/RelationshipDataTest.java new file mode 100644 index 000000000..def353fee --- /dev/null +++ b/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/RelationshipDataTest.java @@ -0,0 +1,57 @@ +/*- + * ============LICENSE_START======================================================= + * aai + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.aai; + +import static org.junit.Assert.assertEquals; + +import java.io.File; +import java.nio.file.Files; +import org.junit.Test; +import org.onap.policy.aai.util.Serialization; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class RelationshipDataTest { + private static final Logger logger = LoggerFactory.getLogger(RelationshipDataTest.class); + + @Test + public void test() throws Exception { + // deserialize json and verify fields are populated properly + String json = new String(Files.readAllBytes( + new File("src/test/resources/org/onap/policy/aai/RelationshipData.json").toPath())); + + RelationshipData relationshipData = Serialization.gsonPretty.fromJson(json, RelationshipData.class); + + assertEquals("generic-vnf.vnf-id", relationshipData.getRelationshipKey()); + assertEquals("807a3f02-f878-436b-870c-f0e91e81570d", relationshipData.getRelationshipValue()); + + logger.info(Serialization.gsonPretty.toJson(relationshipData)); + + // verify that setXxx methods work + relationshipData.setRelationshipKey("a key"); + relationshipData.setRelationshipValue("a value"); + + assertEquals("a key", relationshipData.getRelationshipKey()); + assertEquals("a value", relationshipData.getRelationshipValue()); + } + +} diff --git a/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/RelationshipListTest.java b/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/RelationshipListTest.java new file mode 100644 index 000000000..2c5538057 --- /dev/null +++ b/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/RelationshipListTest.java @@ -0,0 +1,67 @@ +/*- + * ============LICENSE_START======================================================= + * aai + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.aai; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.io.File; +import java.nio.file.Files; +import java.util.LinkedList; +import java.util.List; +import org.junit.Test; +import org.onap.policy.aai.util.Serialization; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class RelationshipListTest { + private static final Logger logger = LoggerFactory.getLogger(RelationshipListTest.class); + + @Test + public void test() throws Exception { + // deserialize json and verify fields are populated properly + String json = new String(Files.readAllBytes( + new File("src/test/resources/org/onap/policy/aai/RelationshipList.json").toPath())); + + RelationshipList relationshipList = Serialization.gsonPretty.fromJson(json, RelationshipList.class); + + List<Relationship> lst = relationshipList.getRelationships(); + assertNotNull(lst); + assertEquals(3, lst.size()); + + // don't need to verify this in depth, as it has its own tests that do that + assertEquals("generic-vnf", lst.get(0).getRelatedTo()); + assertEquals("image", lst.get(1).getRelatedTo()); + assertEquals("flavor", lst.get(2).getRelatedTo()); + + logger.info(Serialization.gsonPretty.toJson(relationshipList)); + + // verify that setXxx methods work + lst = new LinkedList<>(); + lst.add(new Relationship()); + lst.add(new Relationship()); + + relationshipList.setRelationships(lst); + assertEquals(lst, relationshipList.getRelationships()); + } + +} diff --git a/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/RelationshipTest.java b/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/RelationshipTest.java new file mode 100644 index 000000000..ee40d1fdf --- /dev/null +++ b/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/RelationshipTest.java @@ -0,0 +1,89 @@ +/*- + * ============LICENSE_START======================================================= + * aai + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.aai; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.io.File; +import java.nio.file.Files; +import java.util.LinkedList; +import java.util.List; +import org.junit.Test; +import org.onap.policy.aai.util.Serialization; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class RelationshipTest { + private static final Logger logger = LoggerFactory.getLogger(RelationshipTest.class); + + @Test + public void test() throws Exception { + // deserialize json and verify fields are populated properly + String json = new String(Files + .readAllBytes(new File("src/test/resources/org/onap/policy/aai/Relationship.json").toPath())); + + Relationship relationship = Serialization.gsonPretty.fromJson(json, Relationship.class); + + assertEquals("/aai/v11/network/generic-vnfs/generic-vnf/807a3f02-f878-436b-870c-f0e91e81570d", + relationship.getRelatedLink()); + assertEquals("generic-vnf", relationship.getRelatedTo()); + + // don't need to verify this in depth, as it has its own tests that do that + List<RelatedToProperty> relatedToProperty = relationship.getRelatedToProperty(); + assertNotNull(relatedToProperty); + assertEquals(2, relatedToProperty.size()); + assertEquals("vLoadBalancerMS-Vnf-0809-1", relatedToProperty.get(0).getPropertyValue()); + assertEquals("vLoadBalancerMS-Vnf-0809-2", relatedToProperty.get(1).getPropertyValue()); + + // don't need to verify this in depth, as it has its own tests that do that + List<RelationshipData> relationshipData = relationship.getRelationshipData(); + assertNotNull(relationshipData); + assertEquals(2, relationshipData.size()); + assertEquals("807a3f02-f878-436b-870c-f0e91e81570d", relationshipData.get(0).getRelationshipValue()); + assertEquals("907a3f02-f878-436b-870c-f0e91e81570e", relationshipData.get(1).getRelationshipValue()); + + logger.info(Serialization.gsonPretty.toJson(relationship)); + + // verify that setXxx methods work + relatedToProperty = new LinkedList<>(); + relatedToProperty.add(new RelatedToProperty()); + relatedToProperty.add(new RelatedToProperty()); + relatedToProperty.add(new RelatedToProperty()); + + relationshipData = new LinkedList<>(); + relationshipData.add(new RelationshipData()); + relationshipData.add(new RelationshipData()); + relationshipData.add(new RelationshipData()); + + relationship.setRelatedLink("related-link"); + relationship.setRelatedTo("related-to"); + relationship.setRelatedToProperty(relatedToProperty); + relationship.setRelationshipData(relationshipData); + + assertEquals("related-link", relationship.getRelatedLink()); + assertEquals("related-to", relationship.getRelatedTo()); + assertEquals(relatedToProperty, relationship.getRelatedToProperty()); + assertEquals(relationshipData, relationship.getRelationshipData()); + } + +} diff --git a/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/util/AaiExceptionTest.java b/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/util/AaiExceptionTest.java new file mode 100644 index 000000000..f424385fe --- /dev/null +++ b/models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/util/AaiExceptionTest.java @@ -0,0 +1,41 @@ +/*- + * ============LICENSE_START======================================================= + * aai + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.aai.util; + +import static org.junit.Assert.assertNotNull; + +import java.io.IOException; + +import org.junit.Test; + +public class AaiExceptionTest { + + @Test + public void test() { + assertNotNull(new AaiException()); + assertNotNull(new AaiException("message")); + assertNotNull(new AaiException("message", new IOException())); + assertNotNull(new AaiException("message", new IOException(), true, false)); + assertNotNull(new AaiException(new IOException())); + } + +} diff --git a/models-interactions/model-impl/aai/src/test/resources/org/onap/policy/aai/AaiGetResponseError.json b/models-interactions/model-impl/aai/src/test/resources/org/onap/policy/aai/AaiGetResponseError.json new file mode 100644 index 000000000..6751fef5c --- /dev/null +++ b/models-interactions/model-impl/aai/src/test/resources/org/onap/policy/aai/AaiGetResponseError.json @@ -0,0 +1,14 @@ +{ + "requestError": { + "serviceException": { + "messageId": "SVC3001", + "text": "Resource not found for %1 using id %2 (msg=%3) (ec=%4)", + "variables": [ + "GET", + "network/generic-vnfs/generic-vnf/3f02-f878-436b-870c-f0e91e81570d", + "Node Not Found:No Node of type generic-vnf found at: network/generic-vnfs/generic-vnf/3f02-f878-436b-870c-f0e91e81570d", + "ERR.5.4.6114" + ] + } + } +} diff --git a/models-interactions/model-impl/aai/src/test/resources/org/onap/policy/aai/AaiGetVnfResponse.json b/models-interactions/model-impl/aai/src/test/resources/org/onap/policy/aai/AaiGetVnfResponse.json new file mode 100644 index 000000000..faa0e0e1b --- /dev/null +++ b/models-interactions/model-impl/aai/src/test/resources/org/onap/policy/aai/AaiGetVnfResponse.json @@ -0,0 +1,123 @@ +{ + "in-maint": false, + "ipv4-oam-address": "10.0.150.1", + "is-closed-loop-disabled": true, + "model-customization-id": "6c1a5439-3b77-4d8a-bb2b-9fe7006ad671", + "model-invariant-id": "53638a85-361a-437d-8830-4b0d5329225e", + "model-version-id": "a82cd55f-1452-4c36-941a-c9f970a3e67c", + "nf-function": "", + "nf-naming-code": "", + "nf-role": "vLB", + "nf-type": "", + "orchestration-status": "Active", + "prov-status": "PROV", + "relationship-list": { + "relationship": [ + { + "related-link": "/aai/v11/business/customers/customer/Demonstration/service-subscriptions/service-subscription/vLB/service-instances/service-instance/b66d24cc-feca-4fdc-8090-2e9539a8bbac", + "related-to": "service-instance", + "related-to-property": [ + { + "property-key": "service-instance.service-instance-name", + "property-value": "vLoadBalancerMS-Service-0809-1" + } + ], + "relationship-data": [ + { + "relationship-key": "customer.global-customer-id", + "relationship-value": "Demonstration" + }, + { + "relationship-key": "service-subscription.service-type", + "relationship-value": "vLB" + }, + { + "relationship-key": "service-instance.service-instance-id", + "relationship-value": "b66d24cc-feca-4fdc-8090-2e9539a8bbac" + } + ] + }, + { + "related-link": "/aai/v11/business/lines-of-business/line-of-business/Test-Business", + "related-to": "line-of-business", + "relationship-data": [ + { + "relationship-key": "line-of-business.line-of-business-name", + "relationship-value": "Test-Business" + } + ] + }, + { + "related-link": "/aai/v11/business/platforms/platform/Test-Platform", + "related-to": "platform", + "relationship-data": [ + { + "relationship-key": "platform.platform-name", + "relationship-value": "Test-Platform" + } + ] + }, + { + "related-link": "/aai/v11/cloud-infrastructure/cloud-regions/cloud-region/CloudOwner/RegionOne/tenants/tenant/4086f396c5e04caf9502c5fdeca575c4/vservers/vserver/191729bd-cb1d-485d-aa06-b20c888272a8", + "related-to": "vserver", + "related-to-property": [ + { + "property-key": "vserver.vserver-name", + "property-value": "vdns-ms01-0809-1" + } + ], + "relationship-data": [ + { + "relationship-key": "cloud-region.cloud-owner", + "relationship-value": "CloudOwner" + }, + { + "relationship-key": "cloud-region.cloud-region-id", + "relationship-value": "RegionOne" + }, + { + "relationship-key": "tenant.tenant-id", + "relationship-value": "4086f396c5e04caf9502c5fdeca575c4" + }, + { + "relationship-key": "vserver.vserver-id", + "relationship-value": "191729bd-cb1d-485d-aa06-b20c888272a8" + } + ] + }, + { + "related-link": "/aai/v11/cloud-infrastructure/cloud-regions/cloud-region/CloudOwner/RegionOne/tenants/tenant/4086f396c5e04caf9502c5fdeca575c4/vservers/vserver/1c94da3f-16f1-4fc7-9ed1-e018dfa62774", + "related-to": "vserver", + "related-to-property": [ + { + "property-key": "vserver.vserver-name", + "property-value": "vlb-ms-0809-1" + } + ], + "relationship-data": [ + { + "relationship-key": "cloud-region.cloud-owner", + "relationship-value": "CloudOwner" + }, + { + "relationship-key": "cloud-region.cloud-region-id", + "relationship-value": "RegionOne" + }, + { + "relationship-key": "tenant.tenant-id", + "relationship-value": "4086f396c5e04caf9502c5fdeca575c4" + }, + { + "relationship-key": "vserver.vserver-id", + "relationship-value": "1c94da3f-16f1-4fc7-9ed1-e018dfa62774" + } + ] + } + ] + }, + "resource-version": "1533850960381", + "service-id": "50e1b0be-e0c9-48e2-9f42-15279a783ee8", + "vnf-id": "807a3f02-f878-436b-870c-f0e91e81570d", + "vnf-name": "vLoadBalancerMS-Vnf-0809-2", + "vnf-type": "vLoadBalancerMS/vLoadBalancerMS 0" +} diff --git a/models-interactions/model-impl/aai/src/test/resources/org/onap/policy/aai/AaiGetVserverResponse.json b/models-interactions/model-impl/aai/src/test/resources/org/onap/policy/aai/AaiGetVserverResponse.json new file mode 100644 index 000000000..19885942e --- /dev/null +++ b/models-interactions/model-impl/aai/src/test/resources/org/onap/policy/aai/AaiGetVserverResponse.json @@ -0,0 +1,82 @@ +{ + "vserver": [ + { + "in-maint": false, + "is-closed-loop-disabled": true, + "prov-status": "ACTIVE", + "relationship-list": { + "relationship": [ + { + "related-link": "/aai/v11/network/generic-vnfs/generic-vnf/807a3f02-f878-436b-870c-f0e91e81570d", + "related-to": "generic-vnf", + "related-to-property": [ + { + "property-key": "generic-vnf.vnf-name", + "property-value": "vLoadBalancerMS-Vnf-0809-2" + } + ], + "relationship-data": [ + { + "relationship-key": "generic-vnf.vnf-id", + "relationship-value": "807a3f02-f878-436b-870c-f0e91e81570d" + } + ] + }, + { + "related-link": "/aai/v11/cloud-infrastructure/cloud-regions/cloud-region/CloudOwner/RegionOne/images/image/6e219e86-cd94-4989-9119-def29aa10b12", + "related-to": "image", + "related-to-property": [ + { + "property-key": "image.image-name", + "property-value": "unknown" + } + ], + "relationship-data": [ + { + "relationship-key": "cloud-region.cloud-owner", + "relationship-value": "CloudOwner" + }, + { + "relationship-key": "cloud-region.cloud-region-id", + "relationship-value": "RegionOne" + }, + { + "relationship-key": "image.image-id", + "relationship-value": "6e219e86-cd94-4989-9119-def29aa10b12" + } + ] + }, + { + "related-link": "/aai/v11/cloud-infrastructure/cloud-regions/cloud-region/CloudOwner/RegionOne/flavors/flavor/764efb04-5a46-4806-a766-2bdd24559f39", + "related-to": "flavor", + "related-to-property": [ + { + "property-key": "flavor.flavor-name", + "property-value": "m1.medium" + } + ], + "relationship-data": [ + { + "relationship-key": "cloud-region.cloud-owner", + "relationship-value": "CloudOwner" + }, + { + "relationship-key": "cloud-region.cloud-region-id", + "relationship-value": "RegionOne" + }, + { + "relationship-key": "flavor.flavor-id", + "relationship-value": "764efb04-5a46-4806-a766-2bdd24559f39" + } + ] + } + ] + }, + "resource-version": "1533850964910", + "vserver-id": "1c94da3f-16f1-4fc7-9ed1-e018dfa62774", + "vserver-name": "vlb-ms-0809-1", + "vserver-name2": "vlb-ms-0809-7", + "vserver-selflink": "http://localhost:8774/v2.1/4086f396c5e04caf9502c5fdeca575c4/servers/1c94da3f-16f1-4fc7-9ed1-e018dfa62774" + } + ] +} diff --git a/models-interactions/model-impl/aai/src/test/resources/org/onap/policy/aai/AaiNqResponseWrapper-NoItems.json b/models-interactions/model-impl/aai/src/test/resources/org/onap/policy/aai/AaiNqResponseWrapper-NoItems.json new file mode 100644 index 000000000..996692402 --- /dev/null +++ b/models-interactions/model-impl/aai/src/test/resources/org/onap/policy/aai/AaiNqResponseWrapper-NoItems.json @@ -0,0 +1,96 @@ +{ + "inventory-response-item": [ + { + "extra-properties": {}, + "inventory-response-items": { + "inventory-response-item": [ + { + "extra-properties": { + "extra-property": [ + { + "property-name": "model-ver.model-version-id", + "property-value": "a82cd55f-1452-4c36-941a-c9f970a3e67c" + }, + { + "property-name": "model-ver.model-name", + "property-value": "vLoadBalancerMS" + }, + { + "property-name": "model.model-type", + "property-value": "resource" + }, + { + "property-name": "model.model-invariant-id", + "property-value": "53638a85-361a-437d-8830-4b0d5329225e" + }, + { + "property-name": "model-ver.model-version", + "property-value": "1.0" + } + ] + }, + "generic-vnf": { + "in-maint": false, + "ipv4-oam-address": "10.0.150.1", + "is-closed-loop-disabled": false, + "model-customization-id": "6c1a5439-3b77-4d8a-bb2b-9fe7006ad671", + "model-invariant-id": "53638a85-361a-437d-8830-4b0d5329225e", + "model-version-id": "a82cd55f-1452-4c36-941a-c9f970a3e67c", + "nf-function": "", + "nf-naming-code": "", + "nf-role": "vLB", + "nf-type": "", + "orchestration-status": "Active", + "prov-status": "PROV", + "resource-version": "1533850960381", + "service-id": "50e1b0be-e0c9-48e2-9f42-15279a783ee8", + "vnf-id": "807a3f02-f878-436b-870c-f0e91e81570d", + "vnf-name": "vLoadBalancerMS-Vnf-0809-2", + "vnf-type": "vLoadBalancerMS/vLoadBalancerMS 0" + }, + "inventory-response-items": { + "inventory-response-item": [ + ] + }, + "model-name": "vLoadBalancerMS" + }, + { + "extra-properties": {}, + "inventory-response-items": { + "inventory-response-item": [ + { + "cloud-region": { + "cloud-owner": "CloudOwner", + "cloud-region-id": "RegionOne", + "cloud-region-version": "v2.5", + "cloud-type": "openstack", + "cloud-zone": "zone-1", + "owner-defined-type": "owner type", + "resource-version": "1533652058185", + "sriov-automation": false + }, + "extra-properties": {} + } + ] + }, + "tenant": { + "resource-version": "1533652058206", + "tenant-id": "4086f396c5e04caf9502c5fdeca575c4", + "tenant-name": "PFPP" + } + } + ] + }, + "vserver": { + "in-maint": false, + "is-closed-loop-disabled": false, + "prov-status": "ACTIVE", + "resource-version": "1533850964910", + "vserver-id": "1c94da3f-16f1-4fc7-9ed1-e018dfa62774", + "vserver-name": "vlb-ms-0809-1", + "vserver-name2": "vlb-ms-0809-1", + "vserver-selflink": "http://10.12.25.2:8774/v2.1/4086f396c5e04caf9502c5fdeca575c4/servers/1c94da3f-16f1-4fc7-9ed1-e018dfa62774" + } + } + ] +} diff --git a/models-interactions/model-impl/aai/src/test/resources/org/onap/policy/aai/AaiNqResponseWrapper-NoModules.json b/models-interactions/model-impl/aai/src/test/resources/org/onap/policy/aai/AaiNqResponseWrapper-NoModules.json new file mode 100644 index 000000000..2dd6090c7 --- /dev/null +++ b/models-interactions/model-impl/aai/src/test/resources/org/onap/policy/aai/AaiNqResponseWrapper-NoModules.json @@ -0,0 +1,133 @@ +{ + "inventory-response-item": [ + { + "extra-properties": {}, + "inventory-response-items": { + "inventory-response-item": [ + { + "extra-properties": { + "extra-property": [ + { + "property-name": "model-ver.model-version-id", + "property-value": "a82cd55f-1452-4c36-941a-c9f970a3e67c" + }, + { + "property-name": "model-ver.model-name", + "property-value": "vLoadBalancerMS" + }, + { + "property-name": "model.model-type", + "property-value": "resource" + }, + { + "property-name": "model.model-invariant-id", + "property-value": "53638a85-361a-437d-8830-4b0d5329225e" + }, + { + "property-name": "model-ver.model-version", + "property-value": "1.0" + } + ] + }, + "generic-vnf": { + "in-maint": false, + "ipv4-oam-address": "10.0.150.1", + "is-closed-loop-disabled": false, + "model-customization-id": "6c1a5439-3b77-4d8a-bb2b-9fe7006ad671", + "model-invariant-id": "53638a85-361a-437d-8830-4b0d5329225e", + "model-version-id": "a82cd55f-1452-4c36-941a-c9f970a3e67c", + "nf-function": "", + "nf-naming-code": "", + "nf-role": "vLB", + "nf-type": "", + "orchestration-status": "Active", + "prov-status": "PROV", + "resource-version": "1533850960381", + "service-id": "50e1b0be-e0c9-48e2-9f42-15279a783ee8", + "vnf-id": "807a3f02-f878-436b-870c-f0e91e81570d", + "vnf-name": "vLoadBalancerMS-Vnf-0809-2", + "vnf-type": "vLoadBalancerMS/vLoadBalancerMS 0" + }, + "inventory-response-items": { + "inventory-response-item": [ + { + "extra-properties": { + "extra-property": [ + { + "property-name": "model-ver.model-version-id", + "property-value": "4feb459d-d8ef-4cde-a714-235c79787962" + }, + { + "property-name": "model-ver.model-name", + "property-value": "vLoadBalancerMS" + }, + { + "property-name": "model.model-type", + "property-value": "service" + }, + { + "property-name": "model.model-invariant-id", + "property-value": "b5477216-9b7d-4e75-8777-5b632d406759" + }, + { + "property-name": "model-ver.model-version", + "property-value": "1.0" + } + ] + }, + "model-name": "vLoadBalancerMS", + "service-instance": { + "environment-context": "General_Revenue-Bearing", + "model-invariant-id": "b5477216-9b7d-4e75-8777-5b632d406759", + "model-version-id": "4feb459d-d8ef-4cde-a714-235c79787962", + "orchestration-status": "Active", + "resource-version": "1533848425145", + "service-instance-id": "b66d24cc-feca-4fdc-8090-2e9539a8bbac", + "service-instance-name": "vLoadBalancerMS-Service-0809-1", + "workload-context": "Production" + } + } + ] + }, + "model-name": "vLoadBalancerMS" + }, + { + "extra-properties": {}, + "inventory-response-items": { + "inventory-response-item": [ + { + "cloud-region": { + "cloud-owner": "CloudOwner", + "cloud-region-id": "RegionOne", + "cloud-region-version": "v2.5", + "cloud-type": "openstack", + "cloud-zone": "zone-1", + "owner-defined-type": "owner type", + "resource-version": "1533652058185", + "sriov-automation": false + }, + "extra-properties": {} + } + ] + }, + "tenant": { + "resource-version": "1533652058206", + "tenant-id": "4086f396c5e04caf9502c5fdeca575c4", + "tenant-name": "PFPP" + } + } + ] + }, + "vserver": { + "in-maint": false, + "is-closed-loop-disabled": false, + "prov-status": "ACTIVE", + "resource-version": "1533850964910", + "vserver-id": "1c94da3f-16f1-4fc7-9ed1-e018dfa62774", + "vserver-name": "vlb-ms-0809-1", + "vserver-name2": "vlb-ms-0809-1", + "vserver-selflink": "http://10.12.25.2:8774/v2.1/4086f396c5e04caf9502c5fdeca575c4/servers/1c94da3f-16f1-4fc7-9ed1-e018dfa62774" + } + } + ] +} diff --git a/models-interactions/model-impl/aai/src/test/resources/org/onap/policy/aai/AaiNqResponseWrapper-NoNames.json b/models-interactions/model-impl/aai/src/test/resources/org/onap/policy/aai/AaiNqResponseWrapper-NoNames.json new file mode 100644 index 000000000..9c1a9bc5d --- /dev/null +++ b/models-interactions/model-impl/aai/src/test/resources/org/onap/policy/aai/AaiNqResponseWrapper-NoNames.json @@ -0,0 +1,133 @@ +{ + "inventory-response-item": [ + { + "extra-properties": {}, + "inventory-response-items": { + "inventory-response-item": [ + { + "extra-properties": { + "extra-property": [ + { + "property-name": "model-ver.model-version-id", + "property-value": "a82cd55f-1452-4c36-941a-c9f970a3e67c" + }, + { + "property-name": "model-ver.model-name", + "property-value": "vLoadBalancerMS" + }, + { + "property-name": "model.model-type", + "property-value": "resource" + }, + { + "property-name": "model.model-invariant-id", + "property-value": "53638a85-361a-437d-8830-4b0d5329225e" + }, + { + "property-name": "model-ver.model-version", + "property-value": "1.0" + } + ] + }, + "generic-vnf": { + "in-maint": false, + "ipv4-oam-address": "10.0.150.1", + "is-closed-loop-disabled": false, + "model-customization-id": "6c1a5439-3b77-4d8a-bb2b-9fe7006ad671", + "model-invariant-id": "53638a85-361a-437d-8830-4b0d5329225e", + "model-version-id": "a82cd55f-1452-4c36-941a-c9f970a3e67c", + "nf-function": "", + "nf-naming-code": "", + "nf-role": "vLB", + "nf-type": "", + "orchestration-status": "Active", + "prov-status": "PROV", + "resource-version": "1533850960381", + "service-id": "50e1b0be-e0c9-48e2-9f42-15279a783ee8", + "vnf-id": "807a3f02-f878-436b-870c-f0e91e81570d", + "vnf-name": "vLoadBalancerMS-Vnf-0809-2", + "vnf-type": "vLoadBalancerMS/vLoadBalancerMS 0" + }, + "inventory-response-items": { + "inventory-response-item": [ + { + "model-name": "vLoadBalancerMS", + "service-instance": { + "environment-context": "General_Revenue-Bearing", + "model-invariant-id": "b5477216-9b7d-4e75-8777-5b632d406759", + "model-version-id": "4feb459d-d8ef-4cde-a714-235c79787962", + "orchestration-status": "Active", + "resource-version": "1533848425145", + "service-instance-id": "b66d24cc-feca-4fdc-8090-2e9539a8bbac", + "service-instance-name": "vLoadBalancerMS-Service-0809-1", + "workload-context": "Production" + } + }, + { + "vf-module": { + "is-base-vf-module": false, + "model-invariant-id": "6d01b7f1-769a-4080-b8ea-57fd03ef1572", + "model-version-id": "3302088a-457e-496c-9282-2eb3d5b8dd24", + "resource-version": "1534270663202", + "vf-module-id": "dummy_807a3f02-f878-436b-870c-f0e91e81570d", + "vf-module-name": "dummy_807a3f02-f878-436b-870c-f0e91e81570d" + } + }, + { + "vf-module": { + "heat-stack-id": "Vfmodule_vLBMS-0809-1/83ab2394-2b22-40f9-8ba2-383698dd2958", + "is-base-vf-module": true, + "model-customization-id": "5198f732-8f22-48f9-98f8-d6b8b50118be", + "model-invariant-id": "1f566a81-58ba-4762-81f9-d2259509429a", + "model-version-id": "94827d25-4ac3-4850-abfc-7b6e3c531db4", + "module-index": 0, + "orchestration-status": "active", + "resource-version": "1533850416834", + "vf-module-id": "b861467d-d3a7-4b21-81b3-94d928a7e8b7", + "vf-module-name": "Vfmodule_vLBMS-0809-1" + } + } + ] + }, + "model-name": "vLoadBalancerMS" + }, + { + "extra-properties": {}, + "inventory-response-items": { + "inventory-response-item": [ + { + "cloud-region": { + "cloud-owner": "CloudOwner", + "cloud-region-id": "RegionOne", + "cloud-region-version": "v2.5", + "cloud-type": "openstack", + "cloud-zone": "zone-1", + "owner-defined-type": "owner type", + "resource-version": "1533652058185", + "sriov-automation": false + }, + "extra-properties": {} + } + ] + }, + "tenant": { + "resource-version": "1533652058206", + "tenant-id": "4086f396c5e04caf9502c5fdeca575c4", + "tenant-name": "PFPP" + } + } + ] + }, + "vserver": { + "in-maint": false, + "is-closed-loop-disabled": false, + "prov-status": "ACTIVE", + "resource-version": "1533850964910", + "vserver-id": "1c94da3f-16f1-4fc7-9ed1-e018dfa62774", + "vserver-name": "vlb-ms-0809-1", + "vserver-name2": "vlb-ms-0809-1", + "vserver-selflink": "http://10.12.25.2:8774/v2.1/4086f396c5e04caf9502c5fdeca575c4/servers/1c94da3f-16f1-4fc7-9ed1-e018dfa62774" + } + } + ] +} diff --git a/models-interactions/model-impl/aai/src/test/resources/org/onap/policy/aai/AaiNqResponseWrapper-Vserver.json b/models-interactions/model-impl/aai/src/test/resources/org/onap/policy/aai/AaiNqResponseWrapper-Vserver.json new file mode 100644 index 000000000..fb341dc65 --- /dev/null +++ b/models-interactions/model-impl/aai/src/test/resources/org/onap/policy/aai/AaiNqResponseWrapper-Vserver.json @@ -0,0 +1,157 @@ +{ + "inventory-response-item": [ + { + "extra-properties": {}, + "inventory-response-items": { + "inventory-response-item": [ + { + "extra-properties": { + "extra-property": [ + { + "property-name": "model-ver.model-version-id", + "property-value": "a82cd55f-1452-4c36-941a-c9f970a3e67c" + }, + { + "property-name": "model-ver.model-name", + "property-value": "vLoadBalancerMS" + }, + { + "property-name": "model.model-type", + "property-value": "resource" + }, + { + "property-name": "model.model-invariant-id", + "property-value": "53638a85-361a-437d-8830-4b0d5329225e" + }, + { + "property-name": "model-ver.model-version", + "property-value": "1.0" + } + ] + }, + "generic-vnf": { + "in-maint": false, + "ipv4-oam-address": "10.0.150.1", + "is-closed-loop-disabled": false, + "model-customization-id": "6c1a5439-3b77-4d8a-bb2b-9fe7006ad671", + "model-invariant-id": "53638a85-361a-437d-8830-4b0d5329225e", + "model-version-id": "a82cd55f-1452-4c36-941a-c9f970a3e67c", + "nf-function": "", + "nf-naming-code": "", + "nf-role": "vLB", + "nf-type": "", + "orchestration-status": "Active", + "prov-status": "PROV", + "resource-version": "1533850960381", + "service-id": "50e1b0be-e0c9-48e2-9f42-15279a783ee8", + "vnf-id": "807a3f02-f878-436b-870c-f0e91e81570d", + "vnf-name": "vLoadBalancerMS-Vnf-0809-2", + "vnf-type": "vLoadBalancerMS/vLoadBalancerMS 0" + }, + "inventory-response-items": { + "inventory-response-item": [ + { + "model-name": "vLoadBalancerMS", + "service-instance": { + "environment-context": "General_Revenue-Bearing", + "model-invariant-id": "b5477216-9b7d-4e75-8777-5b632d406759", + "model-version-id": "4feb459d-d8ef-4cde-a714-235c79787962", + "orchestration-status": "Active", + "resource-version": "1533848425145", + "service-instance-id": "b66d24cc-feca-4fdc-8090-2e9539a8bbac", + "service-instance-name": "vLoadBalancerMS-Service-0809-1", + "workload-context": "Production" + } + }, + { + "vf-module": { + "is-base-vf-module": false, + "model-invariant-id": "6d01b7f1-769a-4080-b8ea-57fd03ef1572", + "model-version-id": "3302088a-457e-496c-9282-2eb3d5b8dd24", + "resource-version": "1534270663202", + "vf-module-id": "dummy_807a3f02-f878-436b-870c-f0e91e81570d", + "vf-module-name": "dummy_807a3f02-f878-436b-870c-f0e91e81570d" + } + }, + { + "vf-module": { + "is-base-vf-module": false, + "vf-module-name": "my-module-abc_1" + } + }, + { + "vf-module": { + "heat-stack-id": "Vfmodule_vLBMS-0809-1/83ab2394-2b22-40f9-8ba2-383698dd2958", + "is-base-vf-module": true, + "model-customization-id": "5198f732-8f22-48f9-98f8-d6b8b50118be", + "model-invariant-id": "1f566a81-58ba-4762-81f9-d2259509429a", + "model-version-id": "94827d25-4ac3-4850-abfc-7b6e3c531db4", + "module-index": 0, + "orchestration-status": "active", + "resource-version": "1533850416834", + "vf-module-id": "b861467d-d3a7-4b21-81b3-94d928a7e8b7", + "vf-module-name": "Vfmodule_vLBMS-0809-1" + } + }, + { + "vf-module": { + "is-base-vf-module": false, + "vf-module-name": "my-module-abc_123" + } + }, + { + "vf-module": { + "is-base-vf-module": false, + "vf-module-name": "no-underscore-number-9999" + } + }, + { + "vf-module": { + "is-base-vf-module": false, + "vf-module-name": "my-module-abc_34" + } + } + ] + }, + "model-name": "vLoadBalancerMS" + }, + { + "extra-properties": {}, + "inventory-response-items": { + "inventory-response-item": [ + { + "cloud-region": { + "cloud-owner": "CloudOwner", + "cloud-region-id": "RegionOne", + "cloud-region-version": "v2.5", + "cloud-type": "openstack", + "cloud-zone": "zone-1", + "owner-defined-type": "owner type", + "resource-version": "1533652058185", + "sriov-automation": false + }, + "extra-properties": {} + } + ] + }, + "tenant": { + "resource-version": "1533652058206", + "tenant-id": "4086f396c5e04caf9502c5fdeca575c4", + "tenant-name": "PFPP" + } + } + ] + }, + "vserver": { + "in-maint": false, + "is-closed-loop-disabled": false, + "prov-status": "ACTIVE", + "resource-version": "1533850964910", + "vserver-id": "1c94da3f-16f1-4fc7-9ed1-e018dfa62774", + "vserver-name": "vlb-ms-0809-1", + "vserver-name2": "vlb-ms-0809-1", + "vserver-selflink": "http://10.12.25.2:8774/v2.1/4086f396c5e04caf9502c5fdeca575c4/servers/1c94da3f-16f1-4fc7-9ed1-e018dfa62774" + } + } + ] +} diff --git a/models-interactions/model-impl/aai/src/test/resources/org/onap/policy/aai/AaiNqVServer.json b/models-interactions/model-impl/aai/src/test/resources/org/onap/policy/aai/AaiNqVServer.json new file mode 100644 index 000000000..0a59d8a87 --- /dev/null +++ b/models-interactions/model-impl/aai/src/test/resources/org/onap/policy/aai/AaiNqVServer.json @@ -0,0 +1,78 @@ +{ + "in-maint": false, + "is-closed-loop-disabled": true, + "prov-status": "ACTIVE", + "relationship-list": { + "relationship": [ + { + "related-link": "/aai/v11/network/generic-vnfs/generic-vnf/807a3f02-f878-436b-870c-f0e91e81570d", + "related-to": "generic-vnf", + "related-to-property": [ + { + "property-key": "generic-vnf.vnf-name", + "property-value": "vLoadBalancerMS-Vnf-0809-2" + } + ], + "relationship-data": [ + { + "relationship-key": "generic-vnf.vnf-id", + "relationship-value": "807a3f02-f878-436b-870c-f0e91e81570d" + } + ] + }, + { + "related-link": "/aai/v11/cloud-infrastructure/cloud-regions/cloud-region/CloudOwner/RegionOne/images/image/6e219e86-cd94-4989-9119-def29aa10b12", + "related-to": "image", + "related-to-property": [ + { + "property-key": "image.image-name", + "property-value": "unknown" + } + ], + "relationship-data": [ + { + "relationship-key": "cloud-region.cloud-owner", + "relationship-value": "CloudOwner" + }, + { + "relationship-key": "cloud-region.cloud-region-id", + "relationship-value": "RegionOne" + }, + { + "relationship-key": "image.image-id", + "relationship-value": "6e219e86-cd94-4989-9119-def29aa10b12" + } + ] + }, + { + "related-link": "/aai/v11/cloud-infrastructure/cloud-regions/cloud-region/CloudOwner/RegionOne/flavors/flavor/764efb04-5a46-4806-a766-2bdd24559f39", + "related-to": "flavor", + "related-to-property": [ + { + "property-key": "flavor.flavor-name", + "property-value": "m1.medium" + } + ], + "relationship-data": [ + { + "relationship-key": "cloud-region.cloud-owner", + "relationship-value": "CloudOwner" + }, + { + "relationship-key": "cloud-region.cloud-region-id", + "relationship-value": "RegionOne" + }, + { + "relationship-key": "flavor.flavor-id", + "relationship-value": "764efb04-5a46-4806-a766-2bdd24559f39" + } + ] + } + ] + }, + "resource-version": "1533850964910", + "vserver-id": "1c94da3f-16f1-4fc7-9ed1-e018dfa62774", + "vserver-name": "vlb-ms-0809-1", + "vserver-name2": "vlb-ms-0809-7", + "vserver-selflink": "http://localhost:8774/v2.1/4086f396c5e04caf9502c5fdeca575c4/servers/1c94da3f-16f1-4fc7-9ed1-e018dfa62774" +} diff --git a/models-interactions/model-impl/aai/src/test/resources/org/onap/policy/aai/RelatedToProperty.json b/models-interactions/model-impl/aai/src/test/resources/org/onap/policy/aai/RelatedToProperty.json new file mode 100644 index 000000000..2211b3725 --- /dev/null +++ b/models-interactions/model-impl/aai/src/test/resources/org/onap/policy/aai/RelatedToProperty.json @@ -0,0 +1,4 @@ +{ + "property-key": "generic-vnf.vnf-name", + "property-value": "vLoadBalancerMS-Vnf-0809-1" +} diff --git a/models-interactions/model-impl/aai/src/test/resources/org/onap/policy/aai/Relationship.json b/models-interactions/model-impl/aai/src/test/resources/org/onap/policy/aai/Relationship.json new file mode 100644 index 000000000..39d9ce1b6 --- /dev/null +++ b/models-interactions/model-impl/aai/src/test/resources/org/onap/policy/aai/Relationship.json @@ -0,0 +1,25 @@ + +{ + "related-link": "/aai/v11/network/generic-vnfs/generic-vnf/807a3f02-f878-436b-870c-f0e91e81570d", + "related-to": "generic-vnf", + "related-to-property": [ + { + "property-key": "generic-vnf.vnf-name", + "property-value": "vLoadBalancerMS-Vnf-0809-1" + }, + { + "property-key": "generic-vnf.vnf-name", + "property-value": "vLoadBalancerMS-Vnf-0809-2" + } + ], + "relationship-data": [ + { + "relationship-key": "generic-vnf.vnf-id", + "relationship-value": "807a3f02-f878-436b-870c-f0e91e81570d" + }, + { + "relationship-key": "generic-vnf.vnf-id", + "relationship-value": "907a3f02-f878-436b-870c-f0e91e81570e" + } + ] +} diff --git a/models-interactions/model-impl/aai/src/test/resources/org/onap/policy/aai/RelationshipData.json b/models-interactions/model-impl/aai/src/test/resources/org/onap/policy/aai/RelationshipData.json new file mode 100644 index 000000000..4bbb39e8f --- /dev/null +++ b/models-interactions/model-impl/aai/src/test/resources/org/onap/policy/aai/RelationshipData.json @@ -0,0 +1,4 @@ +{ + "relationship-key": "generic-vnf.vnf-id", + "relationship-value": "807a3f02-f878-436b-870c-f0e91e81570d" +} diff --git a/models-interactions/model-impl/aai/src/test/resources/org/onap/policy/aai/RelationshipList.json b/models-interactions/model-impl/aai/src/test/resources/org/onap/policy/aai/RelationshipList.json new file mode 100644 index 000000000..ae180f056 --- /dev/null +++ b/models-interactions/model-impl/aai/src/test/resources/org/onap/policy/aai/RelationshipList.json @@ -0,0 +1,68 @@ +{ + "relationship": [ + { + "related-link": "/aai/v11/network/generic-vnfs/generic-vnf/807a3f02-f878-436b-870c-f0e91e81570d", + "related-to": "generic-vnf", + "related-to-property": [ + { + "property-key": "generic-vnf.vnf-name", + "property-value": "vLoadBalancerMS-Vnf-0809-2" + } + ], + "relationship-data": [ + { + "relationship-key": "generic-vnf.vnf-id", + "relationship-value": "807a3f02-f878-436b-870c-f0e91e81570d" + } + ] + }, + { + "related-link": "/aai/v11/cloud-infrastructure/cloud-regions/cloud-region/CloudOwner/RegionOne/images/image/6e219e86-cd94-4989-9119-def29aa10b12", + "related-to": "image", + "related-to-property": [ + { + "property-key": "image.image-name", + "property-value": "unknown" + } + ], + "relationship-data": [ + { + "relationship-key": "cloud-region.cloud-owner", + "relationship-value": "CloudOwner" + }, + { + "relationship-key": "cloud-region.cloud-region-id", + "relationship-value": "RegionOne" + }, + { + "relationship-key": "image.image-id", + "relationship-value": "6e219e86-cd94-4989-9119-def29aa10b12" + } + ] + }, + { + "related-link": "/aai/v11/cloud-infrastructure/cloud-regions/cloud-region/CloudOwner/RegionOne/flavors/flavor/764efb04-5a46-4806-a766-2bdd24559f39", + "related-to": "flavor", + "related-to-property": [ + { + "property-key": "flavor.flavor-name", + "property-value": "m1.medium" + } + ], + "relationship-data": [ + { + "relationship-key": "cloud-region.cloud-owner", + "relationship-value": "CloudOwner" + }, + { + "relationship-key": "cloud-region.cloud-region-id", + "relationship-value": "RegionOne" + }, + { + "relationship-key": "flavor.flavor-id", + "relationship-value": "764efb04-5a46-4806-a766-2bdd24559f39" + } + ] + } + ] +} diff --git a/models-interactions/model-impl/appc/pom.xml b/models-interactions/model-impl/appc/pom.xml new file mode 100644 index 000000000..7b01902d6 --- /dev/null +++ b/models-interactions/model-impl/appc/pom.xml @@ -0,0 +1,47 @@ +<!-- + ============LICENSE_START======================================================= + appc + ================================================================================ + Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + Modifications Copyright (C) 2019 Nordix Foundation. + ================================================================================ + 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========================================================= + --> + + +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.onap.policy.models.policy-models-interactions.model-impl</groupId> + <artifactId>model-impl</artifactId> + <version>2.0.0-SNAPSHOT</version> + </parent> + + <artifactId>appc</artifactId> + + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>com.google.code.gson</groupId> + <artifactId>gson</artifactId> + <scope>provided</scope> + </dependency> + </dependencies> + +</project> diff --git a/models-interactions/model-impl/appc/src/main/java/org/onap/policy/appc/CommonHeader.java b/models-interactions/model-impl/appc/src/main/java/org/onap/policy/appc/CommonHeader.java new file mode 100644 index 000000000..964af37d2 --- /dev/null +++ b/models-interactions/model-impl/appc/src/main/java/org/onap/policy/appc/CommonHeader.java @@ -0,0 +1,217 @@ +/*- + * ============LICENSE_START======================================================= + * appc + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.appc; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; +import java.time.Instant; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Map; +import java.util.UUID; + +public class CommonHeader implements Serializable { + private static final long serialVersionUID = -3581658269910980336L; + + @SerializedName("TimeStamp") + private Instant timeStamp = Instant.now(); + + @SerializedName("APIver") + private String apiVer = "1.01"; + + @SerializedName("OriginatorID") + private String originatorId; + + @SerializedName("RequestID") + private UUID requestId; + + @SerializedName("SubRequestID") + private String subRequestId; + + @SerializedName("RequestTrack") + private Collection<String> requestTrack = new ArrayList<>(); + + @SerializedName("Flags") + private Collection<Map<String, String>> flags = new ArrayList<>(); + + public CommonHeader() {} + + /** + * Construct an instance from an existing instance. + * + * @param commonHeader the existing instance + */ + public CommonHeader(CommonHeader commonHeader) { + this.originatorId = commonHeader.originatorId; + this.requestId = commonHeader.requestId; + this.subRequestId = commonHeader.subRequestId; + if (commonHeader.requestTrack != null) { + this.requestTrack.addAll(commonHeader.requestTrack); + } + if (commonHeader.flags != null) { + this.flags.addAll(commonHeader.flags); + } + } + + public Instant getTimeStamp() { + return timeStamp; + } + + public void setTimeStamp(Instant timeStamp) { + this.timeStamp = timeStamp; + } + + public String getApiVer() { + return apiVer; + } + + public void setApiVer(String apiVer) { + this.apiVer = apiVer; + } + + public String getOriginatorId() { + return originatorId; + } + + public void setOriginatorId(String originatorId) { + this.originatorId = originatorId; + } + + public UUID getRequestId() { + return requestId; + } + + public void setRequestId(UUID requestId) { + this.requestId = requestId; + } + + public String getSubRequestId() { + return subRequestId; + } + + public void setSubRequestId(String subRequestId) { + this.subRequestId = subRequestId; + } + + public Collection<String> getRequestTrack() { + return requestTrack; + } + + public void setRequestTrack(Collection<String> requestTrack) { + this.requestTrack = requestTrack; + } + + public Collection<Map<String, String>> getFlags() { + return flags; + } + + public void setFlags(Collection<Map<String, String>> flags) { + this.flags = flags; + } + + @Override + public String toString() { + return "CommonHeader [TimeStamp=" + timeStamp + ", APIver=" + apiVer + ", OriginatorId=" + originatorId + + ", RequestId=" + requestId + ", SubrequestId=" + subRequestId + ", RequestTrack=" + requestTrack + + ", Flags=" + flags + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((apiVer == null) ? 0 : apiVer.hashCode()); + result = prime * result + ((flags == null) ? 0 : flags.hashCode()); + result = prime * result + ((originatorId == null) ? 0 : originatorId.hashCode()); + result = prime * result + ((requestId == null) ? 0 : requestId.hashCode()); + result = prime * result + ((requestTrack == null) ? 0 : requestTrack.hashCode()); + result = prime * result + ((subRequestId == null) ? 0 : subRequestId.hashCode()); + result = prime * result + ((timeStamp == null) ? 0 : timeStamp.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + CommonHeader other = (CommonHeader) obj; + if (apiVer == null) { + if (other.apiVer != null) { + return false; + } + } else if (!apiVer.equals(other.apiVer)) { + return false; + } + if (flags == null) { + if (other.flags != null) { + return false; + } + } else if (!flags.equals(other.flags)) { + return false; + } + if (originatorId == null) { + if (other.originatorId != null) { + return false; + } + } else if (!originatorId.equals(other.originatorId)) { + return false; + } + if (requestId == null) { + if (other.requestId != null) { + return false; + } + } else if (!requestId.equals(other.requestId)) { + return false; + } + if (requestTrack == null) { + if (other.requestTrack != null) { + return false; + } + } else if (!requestTrack.equals(other.requestTrack)) { + return false; + } + if (subRequestId == null) { + if (other.subRequestId != null) { + return false; + } + } else if (!subRequestId.equals(other.subRequestId)) { + return false; + } + if (timeStamp == null) { + if (other.timeStamp != null) { + return false; + } + } else if (!timeStamp.equals(other.timeStamp)) { + return false; + } + return true; + } + +} diff --git a/models-interactions/model-impl/appc/src/main/java/org/onap/policy/appc/Request.java b/models-interactions/model-impl/appc/src/main/java/org/onap/policy/appc/Request.java new file mode 100644 index 000000000..7f1574624 --- /dev/null +++ b/models-interactions/model-impl/appc/src/main/java/org/onap/policy/appc/Request.java @@ -0,0 +1,166 @@ +/*- + * ============LICENSE_START======================================================= + * appc + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.appc; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; +import java.util.HashMap; +import java.util.Map; + +public class Request implements Serializable { + private static final long serialVersionUID = -3912323643990646431L; + + @SerializedName("CommonHeader") + private CommonHeader commonHeader; + + @SerializedName("Action") + private String action; + + @SerializedName("TargetID") + private String targetId; + + @SerializedName("ObjectID") + private String objectId; + + @SerializedName("Payload") + private HashMap<String, Object> payload = new HashMap<>(); + + public Request() { + // Initiate an empty Request instance + } + + public CommonHeader getCommonHeader() { + return commonHeader; + } + + public Map<String, Object> getPayload() { + return payload; + } + + public String getAction() { + return action; + } + + public void setAction(String action) { + this.action = action; + } + + public String getTargetId() { + return targetId; + } + + public void setTargetId(String targetId) { + this.targetId = targetId; + } + + public String getObjectId() { + return objectId; + } + + public void setObjectId(String objectId) { + this.objectId = objectId; + } + + public void setCommonHeader(CommonHeader commonHeader) { + this.commonHeader = commonHeader; + } + + public void setPayload(Map<String, Object> payload) { + this.payload = new HashMap<>(payload); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((action == null) ? 0 : action.hashCode()); + result = prime * result + ((commonHeader == null) ? 0 : commonHeader.hashCode()); + result = prime * result + ((objectId == null) ? 0 : objectId.hashCode()); + result = prime * result + ((payload == null) ? 0 : payload.hashCode()); + result = prime * result + ((targetId == null) ? 0 : targetId.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + + Request other = (Request) obj; + if (action == null) { + if (other.action != null) { + return false; + } + } else if (!action.equals(other.action)) { + return false; + } + + if (commonHeader == null) { + if (other.commonHeader != null) { + return false; + } + } else if (!commonHeader.equals(other.commonHeader)) { + return false; + } + + if (objectId == null) { + if (other.objectId != null) { + return false; + } + } else if (!objectId.equals(other.objectId)) { + return false; + } + + if (payload == null) { + if (other.payload != null) { + return false; + } + } else if (!payload.equals(other.payload)) { + return false; + } + + if (targetId == null) { + if (other.targetId != null) { + return false; + } + } else if (!targetId.equals(other.targetId)) { + return false; + } + + return true; + } + + @Override + public String toString() { + return "Request [CommonHeader=" + commonHeader + ", Action=" + action + ", TargetId=" + targetId + ", ObjectId=" + + objectId + ", Payload=" + payload + "]"; + } + +} diff --git a/models-interactions/model-impl/appc/src/main/java/org/onap/policy/appc/Response.java b/models-interactions/model-impl/appc/src/main/java/org/onap/policy/appc/Response.java new file mode 100644 index 000000000..f24c84045 --- /dev/null +++ b/models-interactions/model-impl/appc/src/main/java/org/onap/policy/appc/Response.java @@ -0,0 +1,137 @@ +/*- + * ============LICENSE_START======================================================= + * appc + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.appc; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; +import java.util.HashMap; +import java.util.Map; + +public class Response implements Serializable { + private static final long serialVersionUID = 434953706339865151L; + + @SerializedName("CommonHeader") + private CommonHeader commonHeader; + + @SerializedName("Status") + private ResponseStatus status = new ResponseStatus(); + + @SerializedName("Payload") + private HashMap<String, Object> payload = new HashMap<>(); + + public Response() { + + } + + /** + * Construct an instance from an existing instance. + * + * @param request the existing instance + */ + public Response(Request request) { + if (request.getCommonHeader() != null) { + this.commonHeader = new CommonHeader(request.getCommonHeader()); + } + if (request.getPayload() != null) { + this.payload.putAll(request.getPayload()); + } + } + + public CommonHeader getCommonHeader() { + return commonHeader; + } + + public void setCommonHeader(CommonHeader commonHeader) { + this.commonHeader = commonHeader; + } + + public ResponseStatus getStatus() { + return status; + } + + public void setStatus(ResponseStatus status) { + this.status = status; + } + + public Map<String, Object> getPayload() { + return payload; + } + + public void setPayload(Map<String, Object> payload) { + this.payload = new HashMap<>(payload); + } + + @Override + public String toString() { + return "Response [CommonHeader=" + commonHeader + ", Status=" + status + ", Payload=" + payload + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((commonHeader == null) ? 0 : commonHeader.hashCode()); + result = prime * result + ((payload == null) ? 0 : payload.hashCode()); + result = prime * result + ((status == null) ? 0 : status.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + Response other = (Response) obj; + if (commonHeader == null) { + if (other.commonHeader != null) { + return false; + } + } else if (!commonHeader.equals(other.commonHeader)) { + return false; + } + if (payload == null) { + if (other.payload != null) { + return false; + } + } else if (!payload.equals(other.payload)) { + return false; + } + if (status == null) { + if (other.status != null) { + return false; + } + } else if (!status.equals(other.status)) { + return false; + } + return true; + } + + + +} diff --git a/models-interactions/model-impl/appc/src/main/java/org/onap/policy/appc/ResponseCode.java b/models-interactions/model-impl/appc/src/main/java/org/onap/policy/appc/ResponseCode.java new file mode 100644 index 000000000..48f5182bd --- /dev/null +++ b/models-interactions/model-impl/appc/src/main/java/org/onap/policy/appc/ResponseCode.java @@ -0,0 +1,69 @@ +/*- + * ============LICENSE_START======================================================= + * appc + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.appc; + +import com.google.gson.annotations.SerializedName; + +public enum ResponseCode { + ACCEPT(100), ERROR(200), REJECT(300), SUCCESS(400), FAILURE(500); + + @SerializedName("Code") + private Integer code; + + private ResponseCode(int code) { + this.code = code; + } + + public int getValue() { + return this.code; + } + + @Override + public String toString() { + return Integer.toString(this.code); + } + + /** + * Convert an integer code to a ResponseCode. + * + * @param code the integer code + * @return the ResponseCode + */ + public static ResponseCode toResponseCode(int code) { + if (code == ACCEPT.code) { + return ACCEPT; + } + if (code == ERROR.code) { + return ERROR; + } + if (code == REJECT.code) { + return REJECT; + } + if (code == SUCCESS.code) { + return SUCCESS; + } + if (code == FAILURE.code) { + return FAILURE; + } + return null; + } +} diff --git a/models-interactions/model-impl/appc/src/main/java/org/onap/policy/appc/ResponseStatus.java b/models-interactions/model-impl/appc/src/main/java/org/onap/policy/appc/ResponseStatus.java new file mode 100644 index 000000000..566115081 --- /dev/null +++ b/models-interactions/model-impl/appc/src/main/java/org/onap/policy/appc/ResponseStatus.java @@ -0,0 +1,111 @@ +/*- + * ============LICENSE_START======================================================= + * appc + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.appc; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; + +public class ResponseStatus implements Serializable { + private static final long serialVersionUID = 2421770469587860452L; + + @SerializedName("Code") + private int code; + + @SerializedName("Value") + private String value; + + @SerializedName("Description") + private String description; + + @Override + public String toString() { + return "ResponseStatus [Code=" + code + ", Value=" + value + ", Description=" + description + "]"; + } + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + code; + result = prime * result + ((description == null) ? 0 : description.hashCode()); + result = prime * result + ((value == null) ? 0 : value.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + ResponseStatus other = (ResponseStatus) obj; + if (code != other.code) { + return false; + } + if (description == null) { + if (other.description != null) { + return false; + } + } else if (!description.equals(other.description)) { + return false; + } + if (value == null) { + if (other.value != null) { + return false; + } + } else if (!value.equals(other.value)) { + return false; + } + return true; + } + +} diff --git a/models-interactions/model-impl/appc/src/main/java/org/onap/policy/appc/ResponseValue.java b/models-interactions/model-impl/appc/src/main/java/org/onap/policy/appc/ResponseValue.java new file mode 100644 index 000000000..ef93fd2c8 --- /dev/null +++ b/models-interactions/model-impl/appc/src/main/java/org/onap/policy/appc/ResponseValue.java @@ -0,0 +1,71 @@ +/*- + * ============LICENSE_START======================================================= + * appc + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.appc; + +import com.google.gson.annotations.SerializedName; + +public enum ResponseValue { + ACCEPT("ACCEPT"), ERROR("ERROR"), REJECT("REJECT"), SUCCESS("SUCCESS"), FAILURE("FAILURE"); + + @SerializedName("Value") + private String value; + + private ResponseValue(String value) { + this.value = value; + } + + @Override + public String toString() { + return this.value; + } + + /** + * Convert a String value to a ResponseValue. + * + * @param value the String value + * @return the ResponseValue + */ + public static ResponseValue toResponseValue(String value) { + if (value == null) { + return null; + } + + if (value.equals(ACCEPT.toString())) { + return ACCEPT; + } + if (value.equals(ERROR.toString())) { + return ERROR; + } + if (value.equals(REJECT.toString())) { + return REJECT; + } + if (value.equals(SUCCESS.toString())) { + return SUCCESS; + } + if (value.equals(FAILURE.toString())) { + return FAILURE; + } + + return null; + } + +} diff --git a/models-interactions/model-impl/appc/src/main/java/org/onap/policy/appc/util/Serialization.java b/models-interactions/model-impl/appc/src/main/java/org/onap/policy/appc/util/Serialization.java new file mode 100644 index 000000000..473c5df20 --- /dev/null +++ b/models-interactions/model-impl/appc/src/main/java/org/onap/policy/appc/util/Serialization.java @@ -0,0 +1,86 @@ +/*- + * ============LICENSE_START======================================================= + * appc + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.appc.util; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonPrimitive; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; + +import java.lang.reflect.Type; +import java.time.Instant; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public final class Serialization { + public static final DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSSxxx"); + + public static final Gson gsonPretty = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting() + .registerTypeAdapter(ZonedDateTime.class, new GsonUtcAdapter()) + .registerTypeAdapter(Instant.class, new GsonInstantAdapter()) + // .registerTypeAdapter(CommonHeader1607.class, new gsonCommonHeaderInstance()) + // .registerTypeAdapter(ResponseStatus1607.class, new gsonResponseStatus()) + .create(); + + private Serialization() {} + + public static class GsonUtcAdapter implements JsonSerializer<ZonedDateTime>, JsonDeserializer<ZonedDateTime> { + private static final Logger logger = LoggerFactory.getLogger(GsonUtcAdapter.class); + + @Override + public ZonedDateTime deserialize(JsonElement element, Type type, JsonDeserializationContext context) { + try { + return ZonedDateTime.parse(element.getAsString(), format); + } catch (Exception e) { + logger.error("deserialize threw: ", e); + } + return null; + } + + @Override + public JsonElement serialize(ZonedDateTime datetime, Type type, JsonSerializationContext context) { + return new JsonPrimitive(datetime.format(format)); + } + } + + public static class GsonInstantAdapter implements JsonSerializer<Instant>, JsonDeserializer<Instant> { + + @Override + public Instant deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { + return Instant.ofEpochMilli(json.getAsLong()); + } + + @Override + public JsonElement serialize(Instant src, Type typeOfSrc, JsonSerializationContext context) { + return new JsonPrimitive(src.toEpochMilli()); + } + + } + +} diff --git a/models-interactions/model-impl/appc/src/main/resources/definitions.yaml b/models-interactions/model-impl/appc/src/main/resources/definitions.yaml new file mode 100644 index 000000000..d015f33ae --- /dev/null +++ b/models-interactions/model-impl/appc/src/main/resources/definitions.yaml @@ -0,0 +1,119 @@ +### +# ============LICENSE_START======================================================= +# appc +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# Modifications Copyright (C) 2019 Nordix Foundation. +# ================================================================================ +# 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========================================================= +### + +Request: + type: object + properties: + CommonHeader: + type: object + properties: + TimeStamp: + type: string + APIver: + type: string + value: '1.01' + OriginatorID: + type: string + RequestID: + type: string + pattern: "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$" + SubRequestID: + type: string + Flags: + type: object + required: + - TimeStamp + - APIver + - OriginatorID + - RequestID + Action: + type: string + enum: + - Audit + - ActionStatus + - BlockAudits + - Configure + - HealthCheck + - Install + - LiveUpgrade + - Migrate + - ModifyConfig + - Query + - Rebuild + - Reconfigure + - Restart + - Rollback + - Scale + - Start + - Stop + - Sync + - Terminate + - Test + - Upgrade + TargetID: + type: string + ObjectID: + type: string + Payload: + type: object + required: + - CommonHeader + - Action + - TargetID +Response: + type: object + properties: + CommonHeader: + type: object + properties: + TimeStamp: + type: string + APIver: + type: string + OriginatorID: + type: string + RequestID: + type: string + SubRequestID: + type: string + Flags: + type: object + required: + - TimeStamp + - APIver + - OriginatorID + - RequestID + Status: + type: object + properties: + Code: + type: integer + Value: + type: string + required: + - Code + - Value + Payload: + type: object + required: + - CommonHeader + - Status + diff --git a/models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/CommonHeaderTest.java b/models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/CommonHeaderTest.java new file mode 100644 index 000000000..c76a46ebb --- /dev/null +++ b/models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/CommonHeaderTest.java @@ -0,0 +1,180 @@ +/*- + * ============LICENSE_START======================================================= + * appc + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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========================================================= + */ + +/*- + * ============LICENSE_START======================================================= + * appc + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.appc; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.time.Instant; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import org.junit.Test; + +public class CommonHeaderTest { + + @Test + public void testCommonHeader() { + CommonHeader commonHeader = new CommonHeader(); + assertNotNull(commonHeader); + assertNotNull(new CommonHeader(commonHeader)); + assertNotEquals(0, commonHeader.hashCode()); + + commonHeader.setApiVer("Kansas"); + assertEquals("Kansas", commonHeader.getApiVer()); + + List<Map<String, String>> flagSet = new ArrayList<>(); + commonHeader.setFlags(flagSet); + assertEquals(flagSet, commonHeader.getFlags()); + + commonHeader.setOriginatorId("Dorothy"); + assertEquals("Dorothy", commonHeader.getOriginatorId()); + + UUID requestId = UUID.randomUUID(); + commonHeader.setRequestId(requestId); + assertEquals(requestId, commonHeader.getRequestId()); + + List<String> requestTrackSet = new ArrayList<>(); + commonHeader.setRequestTrack(requestTrackSet); + assertEquals(requestTrackSet, commonHeader.getRequestTrack()); + + commonHeader.setSubRequestId("Can I go home?"); + assertEquals("Can I go home?", commonHeader.getSubRequestId()); + + Instant timestamp = Instant.now(); + commonHeader.setTimeStamp(timestamp); + assertEquals(timestamp, commonHeader.getTimeStamp()); + + assertNotEquals(0, commonHeader.hashCode()); + + assertEquals("CommonHeader [TimeStamp=", commonHeader.toString().substring(0, 24)); + + CommonHeader copiedCommonHeader = new CommonHeader(); + copiedCommonHeader.setApiVer(commonHeader.getApiVer()); + copiedCommonHeader.setFlags(commonHeader.getFlags()); + copiedCommonHeader.setOriginatorId(commonHeader.getOriginatorId()); + copiedCommonHeader.setRequestId(commonHeader.getRequestId()); + copiedCommonHeader.setRequestTrack(commonHeader.getRequestTrack()); + copiedCommonHeader.setSubRequestId(commonHeader.getSubRequestId()); + copiedCommonHeader.setTimeStamp(commonHeader.getTimeStamp()); + + assertTrue(commonHeader.equals(commonHeader)); + assertTrue(commonHeader.equals(copiedCommonHeader)); + assertFalse(commonHeader.equals(null)); + assertFalse(commonHeader.equals("Hello")); + + CommonHeader clonedCommonHeader = new CommonHeader(commonHeader); + clonedCommonHeader.setApiVer(commonHeader.getApiVer()); + clonedCommonHeader.setTimeStamp(commonHeader.getTimeStamp()); + + assertTrue(commonHeader.equals(clonedCommonHeader)); + + commonHeader.setApiVer(null); + assertFalse(commonHeader.equals(copiedCommonHeader)); + copiedCommonHeader.setApiVer(null); + assertTrue(commonHeader.equals(copiedCommonHeader)); + commonHeader.setApiVer("Kansas"); + assertFalse(commonHeader.equals(copiedCommonHeader)); + copiedCommonHeader.setApiVer("Kansas"); + assertTrue(commonHeader.equals(copiedCommonHeader)); + + commonHeader.setFlags(null); + assertFalse(commonHeader.equals(copiedCommonHeader)); + copiedCommonHeader.setFlags(null); + assertTrue(commonHeader.equals(copiedCommonHeader)); + commonHeader.setFlags(flagSet); + assertFalse(commonHeader.equals(copiedCommonHeader)); + copiedCommonHeader.setFlags(flagSet); + assertTrue(commonHeader.equals(copiedCommonHeader)); + + commonHeader.setOriginatorId(null); + assertFalse(commonHeader.equals(copiedCommonHeader)); + copiedCommonHeader.setOriginatorId(null); + assertTrue(commonHeader.equals(copiedCommonHeader)); + commonHeader.setOriginatorId("Dorothy"); + assertFalse(commonHeader.equals(copiedCommonHeader)); + copiedCommonHeader.setOriginatorId("Dorothy"); + assertTrue(commonHeader.equals(copiedCommonHeader)); + + commonHeader.setRequestId(null); + assertFalse(commonHeader.equals(copiedCommonHeader)); + copiedCommonHeader.setRequestId(null); + assertTrue(commonHeader.equals(copiedCommonHeader)); + commonHeader.setRequestId(requestId); + assertFalse(commonHeader.equals(copiedCommonHeader)); + copiedCommonHeader.setRequestId(requestId); + assertTrue(commonHeader.equals(copiedCommonHeader)); + + commonHeader.setRequestTrack(null); + assertFalse(commonHeader.equals(copiedCommonHeader)); + copiedCommonHeader.setRequestTrack(null); + assertTrue(commonHeader.equals(copiedCommonHeader)); + commonHeader.setRequestTrack(requestTrackSet); + assertFalse(commonHeader.equals(copiedCommonHeader)); + copiedCommonHeader.setRequestTrack(requestTrackSet); + assertTrue(commonHeader.equals(copiedCommonHeader)); + + commonHeader.setSubRequestId(null); + assertFalse(commonHeader.equals(copiedCommonHeader)); + copiedCommonHeader.setSubRequestId(null); + assertTrue(commonHeader.equals(copiedCommonHeader)); + commonHeader.setSubRequestId("Can I go home?"); + assertFalse(commonHeader.equals(copiedCommonHeader)); + copiedCommonHeader.setSubRequestId("Can I go home?"); + assertTrue(commonHeader.equals(copiedCommonHeader)); + + commonHeader.setTimeStamp(null); + assertFalse(commonHeader.equals(copiedCommonHeader)); + copiedCommonHeader.setTimeStamp(null); + assertTrue(commonHeader.equals(copiedCommonHeader)); + commonHeader.setTimeStamp(timestamp); + assertFalse(commonHeader.equals(copiedCommonHeader)); + copiedCommonHeader.setTimeStamp(timestamp); + assertTrue(commonHeader.equals(copiedCommonHeader)); + } +} diff --git a/models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/EnumsTest.java b/models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/EnumsTest.java new file mode 100644 index 000000000..6d9ea5221 --- /dev/null +++ b/models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/EnumsTest.java @@ -0,0 +1,75 @@ +/*- + * ============LICENSE_START======================================================= + * appc + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.appc; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import org.junit.Test; + +public class EnumsTest { + + @Test + public void testResponseCode() { + assertEquals(5, ResponseCode.values().length); + + assertNull(ResponseCode.toResponseCode(0)); + + assertEquals(ResponseCode.ACCEPT, ResponseCode.toResponseCode(100)); + assertEquals(ResponseCode.ERROR, ResponseCode.toResponseCode(200)); + assertEquals(ResponseCode.REJECT, ResponseCode.toResponseCode(300)); + assertEquals(ResponseCode.SUCCESS, ResponseCode.toResponseCode(400)); + assertEquals(ResponseCode.FAILURE, ResponseCode.toResponseCode(500)); + + assertEquals(100, ResponseCode.ACCEPT.getValue()); + assertEquals(200, ResponseCode.ERROR.getValue()); + assertEquals(300, ResponseCode.REJECT.getValue()); + assertEquals(400, ResponseCode.SUCCESS.getValue()); + assertEquals(500, ResponseCode.FAILURE.getValue()); + + assertEquals("100", ResponseCode.ACCEPT.toString()); + assertEquals("200", ResponseCode.ERROR.toString()); + assertEquals("300", ResponseCode.REJECT.toString()); + assertEquals("400", ResponseCode.SUCCESS.toString()); + assertEquals("500", ResponseCode.FAILURE.toString()); + } + + @Test + public void testResponseValue() { + assertEquals(5, ResponseValue.values().length); + + assertNull(ResponseValue.toResponseValue("Dorothy")); + assertNull(ResponseValue.toResponseValue(null)); + + assertEquals(ResponseValue.ACCEPT, ResponseValue.toResponseValue("ACCEPT")); + assertEquals(ResponseValue.ERROR, ResponseValue.toResponseValue("ERROR")); + assertEquals(ResponseValue.REJECT, ResponseValue.toResponseValue("REJECT")); + assertEquals(ResponseValue.SUCCESS, ResponseValue.toResponseValue("SUCCESS")); + assertEquals(ResponseValue.FAILURE, ResponseValue.toResponseValue("FAILURE")); + + assertEquals("ACCEPT", ResponseValue.ACCEPT.toString()); + assertEquals("ERROR", ResponseValue.ERROR.toString()); + assertEquals("REJECT", ResponseValue.REJECT.toString()); + assertEquals("SUCCESS", ResponseValue.SUCCESS.toString()); + assertEquals("FAILURE", ResponseValue.FAILURE.toString()); + } +} diff --git a/models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/RequestTest.java b/models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/RequestTest.java new file mode 100644 index 000000000..a6ef4a1d2 --- /dev/null +++ b/models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/RequestTest.java @@ -0,0 +1,125 @@ +/*- + * ============LICENSE_START======================================================= + * appc + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.appc; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.Test; + +public class RequestTest { + + @Test + public void testRequest() { + Request request = new Request(); + assertNotNull(request); + assertNotEquals(0, request.hashCode()); + + CommonHeader commonHeader = new CommonHeader(); + + request.setCommonHeader(commonHeader); + assertEquals(commonHeader, request.getCommonHeader()); + + request.setAction("Go to Oz"); + assertEquals("Go to Oz", request.getAction()); + + request.setObjectId("Wizard"); + assertEquals("Wizard", request.getObjectId()); + + request.setTargetId("Oz"); + assertEquals("Oz", request.getTargetId()); + + Map<String, Object> payload = new HashMap<>(); + payload.put("North", "Good Witch"); + payload.put("West", "Bad Witch"); + + request.setPayload(payload); + assertEquals(payload, request.getPayload()); + + assertNotEquals(0, request.hashCode()); + + assertEquals("Request [CommonHeader=CommonHeader [TimeStamp=", request.toString().substring(0, 46)); + + Request copiedRequest = new Request(); + copiedRequest.setCommonHeader(request.getCommonHeader()); + copiedRequest.setAction(request.getAction()); + copiedRequest.setObjectId(request.getObjectId()); + copiedRequest.setPayload(request.getPayload()); + copiedRequest.setTargetId(request.getTargetId()); + + assertTrue(request.equals(request)); + assertTrue(request.equals(copiedRequest)); + assertFalse(request.equals(null)); + assertFalse(request.equals("Hello")); + + request.setCommonHeader(null); + assertFalse(request.equals(copiedRequest)); + copiedRequest.setCommonHeader(null); + assertTrue(request.equals(copiedRequest)); + request.setCommonHeader(commonHeader); + assertFalse(request.equals(copiedRequest)); + copiedRequest.setCommonHeader(commonHeader); + assertTrue(request.equals(copiedRequest)); + + request.setAction(null); + assertFalse(request.equals(copiedRequest)); + copiedRequest.setAction(null); + assertTrue(request.equals(copiedRequest)); + request.setAction("Go to Oz"); + assertFalse(request.equals(copiedRequest)); + copiedRequest.setAction("Go to Oz"); + assertTrue(request.equals(copiedRequest)); + + request.setObjectId(null); + assertFalse(request.equals(copiedRequest)); + copiedRequest.setObjectId(null); + assertTrue(request.equals(copiedRequest)); + request.setObjectId("Wizard"); + assertFalse(request.equals(copiedRequest)); + copiedRequest.setObjectId("Wizard"); + assertTrue(request.equals(copiedRequest)); + + request.setTargetId(null); + assertFalse(request.equals(copiedRequest)); + copiedRequest.setTargetId(null); + assertTrue(request.equals(copiedRequest)); + request.setTargetId("Oz"); + assertFalse(request.equals(copiedRequest)); + copiedRequest.setTargetId("Oz"); + assertTrue(request.equals(copiedRequest)); + + request.setPayload(new HashMap<String, Object>()); + assertFalse(request.equals(copiedRequest)); + copiedRequest.setPayload(new HashMap<String, Object>()); + assertTrue(request.equals(copiedRequest)); + request.setPayload(payload); + assertFalse(request.equals(copiedRequest)); + copiedRequest.setPayload(payload); + assertTrue(request.equals(copiedRequest)); + } +} diff --git a/models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/ResponseStatusTest.java b/models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/ResponseStatusTest.java new file mode 100644 index 000000000..b3176774d --- /dev/null +++ b/models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/ResponseStatusTest.java @@ -0,0 +1,89 @@ +/*- + * ============LICENSE_START======================================================= + * appc + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.appc; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +public class ResponseStatusTest { + + @Test + public void testResonseStatus() { + ResponseStatus status = new ResponseStatus(); + assertNotNull(status); + assertNotEquals(0, status.hashCode()); + + status.setCode(1234); + assertEquals(1234, status.getCode()); + + status.setDescription("The wonderful land of Oz"); + assertEquals("The wonderful land of Oz", status.getDescription()); + + status.setValue("There's no place like home"); + assertEquals("There's no place like home", status.getValue()); + assertNotEquals(0, status.hashCode()); + + assertEquals("ResponseStatus [Code=1234, Value=There's no pla", status.toString().substring(0, 47)); + + ResponseStatus copiedStatus = new ResponseStatus(); + copiedStatus.setCode(status.getCode()); + copiedStatus.setDescription(status.getDescription()); + copiedStatus.setValue(status.getValue()); + + assertTrue(status.equals(status)); + assertTrue(status.equals(copiedStatus)); + assertFalse(status.equals(null)); + assertFalse(status.equals("Hello")); + + status.setCode(-1); + assertFalse(status.equals(copiedStatus)); + copiedStatus.setCode(-1); + assertTrue(status.equals(copiedStatus)); + status.setCode(1234); + assertFalse(status.equals(copiedStatus)); + copiedStatus.setCode(1234); + assertTrue(status.equals(copiedStatus)); + + status.setDescription(null); + assertFalse(status.equals(copiedStatus)); + copiedStatus.setDescription(null); + assertTrue(status.equals(copiedStatus)); + status.setDescription("The wonderful land of Oz"); + assertFalse(status.equals(copiedStatus)); + copiedStatus.setDescription("The wonderful land of Oz"); + assertTrue(status.equals(copiedStatus)); + + status.setValue(null); + assertFalse(status.equals(copiedStatus)); + copiedStatus.setValue(null); + assertTrue(status.equals(copiedStatus)); + status.setValue("There's no place like home"); + assertFalse(status.equals(copiedStatus)); + copiedStatus.setValue("There's no place like home"); + assertTrue(status.equals(copiedStatus)); + } +} diff --git a/models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/ResponseTest.java b/models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/ResponseTest.java new file mode 100644 index 000000000..b0806fa25 --- /dev/null +++ b/models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/ResponseTest.java @@ -0,0 +1,105 @@ +/*- + * ============LICENSE_START======================================================= + * appc + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.appc; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.Test; + +public class ResponseTest { + + @Test + public void testResonse() { + Response response = new Response(); + assertNotNull(response); + assertNotNull(new Response(new Request())); + assertNotEquals(0, response.hashCode()); + + CommonHeader commonHeader = new CommonHeader(); + + Request request = new Request(); + request.setCommonHeader(commonHeader); + assertNotNull(new Response(request)); + + response.setCommonHeader(commonHeader); + assertEquals(commonHeader, response.getCommonHeader()); + + ResponseStatus status = new ResponseStatus(); + response.setStatus(status); + assertEquals(status, response.getStatus()); + + Map<String, Object> payload = new HashMap<>(); + payload.put("North", "Good Witch"); + payload.put("West", "Bad Witch"); + + response.setPayload(payload); + assertEquals(payload, response.getPayload()); + + assertNotEquals(0, response.hashCode()); + + assertEquals("Response [CommonHeader=CommonHeader [TimeStamp=", response.toString().substring(0, 47)); + + Response copiedResponse = new Response(); + copiedResponse.setCommonHeader(response.getCommonHeader()); + copiedResponse.setStatus(response.getStatus()); + copiedResponse.setPayload(response.getPayload()); + + assertTrue(response.equals(response)); + assertTrue(response.equals(copiedResponse)); + assertFalse(response.equals(null)); + assertFalse(response.equals("Hello")); + + response.setCommonHeader(null); + assertFalse(response.equals(copiedResponse)); + copiedResponse.setCommonHeader(null); + assertTrue(response.equals(copiedResponse)); + response.setCommonHeader(commonHeader); + assertFalse(response.equals(copiedResponse)); + copiedResponse.setCommonHeader(commonHeader); + assertTrue(response.equals(copiedResponse)); + + response.setStatus(null); + assertFalse(response.equals(copiedResponse)); + copiedResponse.setStatus(null); + assertTrue(response.equals(copiedResponse)); + response.setStatus(status); + assertFalse(response.equals(copiedResponse)); + copiedResponse.setStatus(status); + assertTrue(response.equals(copiedResponse)); + + response.setPayload(new HashMap<String, Object>()); + assertFalse(response.equals(copiedResponse)); + copiedResponse.setPayload(new HashMap<String, Object>()); + assertTrue(response.equals(copiedResponse)); + response.setPayload(payload); + assertFalse(response.equals(copiedResponse)); + copiedResponse.setPayload(payload); + assertTrue(response.equals(copiedResponse)); + } +} diff --git a/models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/util/SerializationTest.java b/models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/util/SerializationTest.java new file mode 100644 index 000000000..e47df424d --- /dev/null +++ b/models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/util/SerializationTest.java @@ -0,0 +1,57 @@ +/*- + * ============LICENSE_START======================================================= + * appc + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.appc.util; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import java.time.Instant; +import java.time.ZoneId; +import java.time.ZonedDateTime; + +import org.junit.Test; + +public class SerializationTest { + + @Test + public void test() { + String nameString = "Dorothy"; + String jsonName = Serialization.gsonPretty.toJson(nameString, String.class); + assertEquals("\"Dorothy\"", jsonName); + String jsonInOutName = Serialization.gsonPretty.fromJson(jsonName, String.class); + assertEquals("Dorothy", jsonInOutName); + + Instant instant = Instant.ofEpochMilli(1516127215000L); + String instantString = Serialization.gsonPretty.toJson(instant, Instant.class); + assertEquals("1516127215000", instantString); + Instant outInstant = Serialization.gsonPretty.fromJson(instantString, Instant.class); + assertEquals(instant, outInstant); + + ZonedDateTime zdt = ZonedDateTime.ofInstant(instant, ZoneId.of("UTC")); + String zdtString = Serialization.gsonPretty.toJson(zdt, ZonedDateTime.class); + assertEquals("\"2018-01-16 18:26:55.000000+00:00\"", zdtString); + ZonedDateTime outZdt = Serialization.gsonPretty.fromJson(zdtString, ZonedDateTime.class); + assertEquals(zdt.getDayOfWeek(), outZdt.getDayOfWeek()); + + assertNull(Serialization.gsonPretty.fromJson("oz time is weird", ZonedDateTime.class)); + } +} diff --git a/models-interactions/model-impl/appclcm/pom.xml b/models-interactions/model-impl/appclcm/pom.xml new file mode 100644 index 000000000..51ebbd7b2 --- /dev/null +++ b/models-interactions/model-impl/appclcm/pom.xml @@ -0,0 +1,47 @@ +<!-- + ============LICENSE_START======================================================= + appclcm + ================================================================================ + Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + Modifications Copyright (C) 2019 Nordix Foundation. + ================================================================================ + 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========================================================= + --> + + +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.onap.policy.models.policy-models-interactions.model-impl</groupId> + <artifactId>model-impl</artifactId> + <version>2.0.0-SNAPSHOT</version> + </parent> + + <artifactId>appclcm</artifactId> + + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>com.google.code.gson</groupId> + <artifactId>gson</artifactId> + <scope>provided</scope> + </dependency> + </dependencies> + +</project> diff --git a/models-interactions/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/LcmCommonHeader.java b/models-interactions/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/LcmCommonHeader.java new file mode 100644 index 000000000..c8126275a --- /dev/null +++ b/models-interactions/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/LcmCommonHeader.java @@ -0,0 +1,257 @@ +/*- + * ============LICENSE_START======================================================= + * appclcm + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.appclcm; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; +import java.time.Instant; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +public class LcmCommonHeader implements Serializable { + + private static final long serialVersionUID = 6581963539127062114L; + + @SerializedName(value = "timestamp") + private Instant timeStamp = Instant.now(); + + @SerializedName(value = "api-ver") + private String apiVer = "2.00"; + + @SerializedName(value = "originator-id") + private String originatorId; + + @SerializedName(value = "request-id") + private UUID requestId; + + @SerializedName(value = "sub-request-id") + private String subRequestId; + + @SerializedName(value = "flags") + private Map<String, String> flags = new HashMap<>(); + + public LcmCommonHeader() { + + } + + /** + * Used to copy a common header. + * + * @param commonHeader a header that is defined by the lcm api guide that contains information + * about the request (requestId, flags, etc.) + */ + public LcmCommonHeader(LcmCommonHeader commonHeader) { + this.originatorId = commonHeader.originatorId; + this.requestId = commonHeader.requestId; + this.subRequestId = commonHeader.subRequestId; + if (commonHeader.flags != null) { + this.flags.putAll(commonHeader.flags); + } + } + + /** + * Get the timestamp. + * + * @return the timeStamp + */ + public Instant getTimeStamp() { + return timeStamp; + } + + /** + * Set the timestamp. + * + * @param timeStamp the timeStamp to set + */ + public void setTimeStamp(Instant timeStamp) { + this.timeStamp = timeStamp; + } + + /** + * Get the API version. + * + * @return the apiVer + */ + public String getApiVer() { + return apiVer; + } + + /** + * Set the API version. + * + * @param apiVer the apiVer to set + */ + public void setApiVer(String apiVer) { + this.apiVer = apiVer; + } + + /** + * Get the originator Id. + * + * @return the originatorId + */ + public String getOriginatorId() { + return originatorId; + } + + /** + * Set the originator Id. + * + * @param originatorId the originatorId to set + */ + public void setOriginatorId(String originatorId) { + this.originatorId = originatorId; + } + + /** + * Get the request Id. + * + * @return the requestId + */ + public UUID getRequestId() { + return requestId; + } + + /** + * Set the request Id. + * + * @param requestId the requestId to set + */ + public void setRequestId(UUID requestId) { + this.requestId = requestId; + } + + /** + * Get the sub request Id. + * + * @return the subRequestId + */ + public String getSubRequestId() { + return subRequestId; + } + + /** + * Set the sub request Id. + * + * @param subRequestId the subRequestId to set + */ + public void setSubRequestId(String subRequestId) { + this.subRequestId = subRequestId; + } + + /** + * Get the flags. + * + * @return the flags + */ + public Map<String, String> getFlags() { + return flags; + } + + /** + * Set the flags. + * + * @param flags the flags to set + */ + public void setFlags(Map<String, String> flags) { + this.flags = flags; + } + + @Override + public String toString() { + return "CommonHeader [timeStamp=" + timeStamp + ", apiVer=" + apiVer + ", originatorId=" + originatorId + + ", requestId=" + requestId + ", subRequestId=" + subRequestId + ", flags=" + flags + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((apiVer == null) ? 0 : apiVer.hashCode()); + result = prime * result + ((flags == null) ? 0 : flags.hashCode()); + result = prime * result + ((originatorId == null) ? 0 : originatorId.hashCode()); + result = prime * result + ((requestId == null) ? 0 : requestId.hashCode()); + result = prime * result + ((subRequestId == null) ? 0 : subRequestId.hashCode()); + result = prime * result + ((timeStamp == null) ? 0 : timeStamp.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + LcmCommonHeader other = (LcmCommonHeader) obj; + if (apiVer == null) { + if (other.apiVer != null) { + return false; + } + } else if (!apiVer.equals(other.apiVer)) { + return false; + } + if (flags == null) { + if (other.flags != null) { + return false; + } + } else if (!flags.equals(other.flags)) { + return false; + } + if (originatorId == null) { + if (other.originatorId != null) { + return false; + } + } else if (!originatorId.equals(other.originatorId)) { + return false; + } + if (requestId == null) { + if (other.requestId != null) { + return false; + } + } else if (!requestId.equals(other.requestId)) { + return false; + } + if (subRequestId == null) { + if (other.subRequestId != null) { + return false; + } + } else if (!subRequestId.equals(other.subRequestId)) { + return false; + } + if (timeStamp == null) { + if (other.timeStamp != null) { + return false; + } + } else if (!timeStamp.equals(other.timeStamp)) { + return false; + } + return true; + } + +} diff --git a/models-interactions/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/LcmRequest.java b/models-interactions/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/LcmRequest.java new file mode 100644 index 000000000..3e8f71743 --- /dev/null +++ b/models-interactions/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/LcmRequest.java @@ -0,0 +1,176 @@ +/*- + * ============LICENSE_START======================================================= + * appclcm + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.appclcm; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; +import java.util.Map; + +public class LcmRequest implements Serializable { + + private static final long serialVersionUID = 219375564922846624L; + + @SerializedName(value = "common-header") + private LcmCommonHeader commonHeader; + + @SerializedName(value = "action") + private String action; + + @SerializedName(value = "action-identifiers") + private Map<String, String> actionIdentifiers; + + @SerializedName(value = "payload") + private String payload; + + public LcmRequest() { + // Create a default LCM request + } + + public LcmCommonHeader getCommonHeader() { + return commonHeader; + } + + /** + * Get the action. + * + * @return the action + */ + public String getAction() { + return action; + } + + /** + * Set the action. + * + * @param action the action to set + */ + public void setAction(String action) { + this.action = action; + } + + /** + * Get the action identifiers. + * + * @return the actionIdentifiers + */ + public Map<String, String> getActionIdentifiers() { + return actionIdentifiers; + } + + /** + * Set the action identifiers. + * + * @param actionIdentifiers the actionIdentifiers to set + */ + public void setActionIdentifiers(Map<String, String> actionIdentifiers) { + this.actionIdentifiers = actionIdentifiers; + } + + /** + * Get the payload. + * + * @return the payload + */ + public String getPayload() { + return payload; + } + + /** + * Set the payload. + * + * @param payload the payload to set + */ + public void setPayload(String payload) { + this.payload = payload; + } + + /** + * Get the common header. + * + * @param commonHeader the commonHeader to set + */ + public void setCommonHeader(LcmCommonHeader commonHeader) { + this.commonHeader = commonHeader; + } + + @Override + public String toString() { + return "Request [commonHeader=" + commonHeader + ", action=" + action + ", actionIdentifiers=" + + actionIdentifiers + ", payload=" + payload + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((commonHeader == null) ? 0 : commonHeader.hashCode()); + result = prime * result + ((action == null) ? 0 : action.hashCode()); + result = prime * result + ((actionIdentifiers == null) ? 0 : actionIdentifiers.hashCode()); + result = prime * result + ((payload == null) ? 0 : payload.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + LcmRequest other = (LcmRequest) obj; + if (commonHeader == null) { + if (other.commonHeader != null) { + return false; + } + } else if (!commonHeader.equals(other.commonHeader)) { + return false; + } + if (action == null) { + if (other.action != null) { + return false; + } + } else if (!action.equals(other.action)) { + return false; + } + if (actionIdentifiers == null) { + if (other.actionIdentifiers != null) { + return false; + } + } else if (!actionIdentifiers.equals(other.actionIdentifiers)) { + return false; + } + if (payload == null) { + if (other.payload != null) { + return false; + } + } else if (!payload.equals(other.payload)) { + return false; + } + return true; + } + +} diff --git a/models-interactions/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/LcmRequestWrapper.java b/models-interactions/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/LcmRequestWrapper.java new file mode 100644 index 000000000..7b9bcda25 --- /dev/null +++ b/models-interactions/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/LcmRequestWrapper.java @@ -0,0 +1,96 @@ +/*- + * ============LICENSE_START======================================================= + * appclcm + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.appclcm; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; + +public class LcmRequestWrapper extends LcmWrapper implements Serializable { + + private static final long serialVersionUID = 424866914715980798L; + + @SerializedName(value = "body") + private LcmRequest body; + + public LcmRequestWrapper() { + super(); + } + + public LcmRequestWrapper(LcmRequest request) { + body = request; + } + + /** + * Get the body. + * + * @return the body + */ + public LcmRequest getBody() { + return body; + } + + /** + * Set the body. + * + * @param body the body to set + */ + public void setBody(LcmRequest body) { + this.body = body; + } + + @Override + public String toString() { + return "RequestWrapper [body=" + body + ", toString()=" + super.toString() + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((body == null) ? 0 : body.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!super.equals(obj)) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + LcmRequestWrapper other = (LcmRequestWrapper) obj; + if (body == null) { + if (other.body != null) { + return false; + } + } else if (!body.equals(other.body)) { + return false; + } + return true; + } + +} diff --git a/models-interactions/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/LcmResponse.java b/models-interactions/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/LcmResponse.java new file mode 100644 index 000000000..e40e5e4b1 --- /dev/null +++ b/models-interactions/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/LcmResponse.java @@ -0,0 +1,162 @@ +/*- + * ============LICENSE_START======================================================= + * appclcm + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.appclcm; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; + +public class LcmResponse implements Serializable { + + private static final long serialVersionUID = 6332508597287669750L; + + @SerializedName(value = "common-header") + private LcmCommonHeader commonHeader; + + @SerializedName(value = "status") + private LcmResponseStatus status = new LcmResponseStatus(); + + @SerializedName(value = "payload") + private String payload; + + public LcmResponse() { + // EMPTY + } + + /** + * Constructs a response using the common header of the request since they will be the same. + * + * @param request an appc lcm request object specified by the lcm api guide + */ + public LcmResponse(LcmRequest request) { + this.commonHeader = new LcmCommonHeader(request.getCommonHeader()); + String requestPayload = request.getPayload(); + if (requestPayload != null) { + this.payload = requestPayload; + } + } + + /** + * Get the common header. + * + * @return the commonHeader + */ + public LcmCommonHeader getCommonHeader() { + return commonHeader; + } + + /** + * Set the common header. + * + * @param commonHeader the commonHeader to set + */ + public void setCommonHeader(LcmCommonHeader commonHeader) { + this.commonHeader = commonHeader; + } + + /** + * Get the status. + * + * @return the status + */ + public LcmResponseStatus getStatus() { + return status; + } + + /** + * Set the status. + * + * @param status the status to set + */ + public void setStatus(LcmResponseStatus status) { + this.status = status; + } + + /** + * Get the payload. + * + * @return the payload + */ + public String getPayload() { + return payload; + } + + /** + * Set the payload. + * + * @param payload the payload to set + */ + public void setPayload(String payload) { + this.payload = payload; + } + + @Override + public String toString() { + return "Response [commonHeader=" + commonHeader + ", status=" + status + ", payload=" + payload + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((commonHeader == null) ? 0 : commonHeader.hashCode()); + result = prime * result + ((payload == null) ? 0 : payload.hashCode()); + result = prime * result + ((status == null) ? 0 : status.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + LcmResponse other = (LcmResponse) obj; + if (commonHeader == null) { + if (other.commonHeader != null) { + return false; + } + } else if (!commonHeader.equals(other.commonHeader)) { + return false; + } + if (payload == null) { + if (other.payload != null) { + return false; + } + } else if (!payload.equals(other.payload)) { + return false; + } + if (status == null) { + if (other.status != null) { + return false; + } + } else if (!status.equals(other.status)) { + return false; + } + return true; + } +} diff --git a/models-interactions/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/LcmResponseCode.java b/models-interactions/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/LcmResponseCode.java new file mode 100644 index 000000000..5fe0440e5 --- /dev/null +++ b/models-interactions/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/LcmResponseCode.java @@ -0,0 +1,65 @@ +/*- + * ============LICENSE_START======================================================= + * appclcm + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2018 Samsung Electronics Co., Ltd. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.appclcm; + +import java.io.Serializable; +import org.onap.policy.appclcm.util.StatusCodeEnum; + +public class LcmResponseCode implements Serializable { + + /* These fields define the key to the response code value. */ + public static final String ACCEPTED = "ACCEPTED"; + public static final String ERROR = "ERROR"; + public static final String REJECT = "REJECT"; + public static final String SUCCESS = "SUCCESS"; + public static final String FAILURE = "FAILURE"; + public static final String PARTIAL_SUCCESS = "PARTIAL SUCCESS"; + public static final String PARTIAL_FAILURE = "PARTIAL FAILURE"; + private static final long serialVersionUID = 8189456447227022582L; + + private final Integer code; + + protected LcmResponseCode(final int code) { + this.code = code; + } + + public int getCode() { + return this.code; + } + + @Override + public String toString() { + return Integer.toString(this.code); + } + + /** + * Translates the code to a string value that represents the meaning of the code. + * + * @param code the numeric value that is returned by APPC based on success, failure, etc. of the action requested + * @return the string value equivalent of the APPC response code + */ + public static String toResponseValue(int code) { + StatusCodeEnum statusCodeEnum = StatusCodeEnum.fromStatusCode(code); + return (statusCodeEnum != null) ? statusCodeEnum.toString() : null; + } +} diff --git a/models-interactions/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/LcmResponseStatus.java b/models-interactions/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/LcmResponseStatus.java new file mode 100644 index 000000000..64fcc8fb2 --- /dev/null +++ b/models-interactions/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/LcmResponseStatus.java @@ -0,0 +1,117 @@ +/*- + * ============LICENSE_START======================================================= + * appclcm + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.appclcm; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; + +public class LcmResponseStatus implements Serializable { + + private static final long serialVersionUID = 974891505135467199L; + + @SerializedName(value = "code") + private int code; + + @SerializedName(value = "message") + private String message; + + public LcmResponseStatus() { + // Create a default LCMResponseStatus instance + } + + /** + * Get the code. + * + * @return the code + */ + public int getCode() { + return code; + } + + /** + * Set the code. + * + * @param code the code to set + */ + public void setCode(int code) { + this.code = code; + } + + /** + * Get the message. + * + * @return the message + */ + public String getMessage() { + return message; + } + + /** + * Set the message. + * + * @param message the message to set + */ + public void setMessage(String message) { + this.message = message; + } + + @Override + public String toString() { + return "ResponseStatus [code=" + code + ", message=" + message + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + code; + result = prime * result + ((message == null) ? 0 : message.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + LcmResponseStatus other = (LcmResponseStatus) obj; + if (code != other.code) { + return false; + } + if (message == null) { + if (other.message != null) { + return false; + } + } else if (!message.equals(other.message)) { + return false; + } + return true; + } + +} diff --git a/models-interactions/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/LcmResponseWrapper.java b/models-interactions/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/LcmResponseWrapper.java new file mode 100644 index 000000000..cc1672a6a --- /dev/null +++ b/models-interactions/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/LcmResponseWrapper.java @@ -0,0 +1,91 @@ +/*- + * ============LICENSE_START======================================================= + * appclcm + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.appclcm; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; + +public class LcmResponseWrapper extends LcmWrapper implements Serializable { + + private static final long serialVersionUID = 463937813781086802L; + + @SerializedName(value = "body") + private LcmResponse body; + + public LcmResponseWrapper() { + super(); + } + + /** + * Get the body. + * + * @return the body + */ + public LcmResponse getBody() { + return body; + } + + /** + * Set the body. + * + * @param body the body to set + */ + public void setBody(LcmResponse body) { + this.body = body; + } + + @Override + public String toString() { + return "ResponseWrapper [body=" + body + ", toString()=" + super.toString() + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((body == null) ? 0 : body.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!super.equals(obj)) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + LcmResponseWrapper other = (LcmResponseWrapper) obj; + if (body == null) { + if (other.body != null) { + return false; + } + } else if (!body.equals(other.body)) { + return false; + } + return true; + } +} diff --git a/models-interactions/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/LcmWrapper.java b/models-interactions/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/LcmWrapper.java new file mode 100644 index 000000000..244c6abb4 --- /dev/null +++ b/models-interactions/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/LcmWrapper.java @@ -0,0 +1,209 @@ +/*- + * ============LICENSE_START======================================================= + * appclcm + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.appclcm; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; + +public class LcmWrapper implements Serializable { + + private static final long serialVersionUID = 753005805432396532L; + + @SerializedName(value = "version") + private String version; + + @SerializedName(value = "cambria-partition") + private String cambriaPartition; + + @SerializedName(value = "rpc-name") + private String rpcName; + + @SerializedName(value = "correlation-id") + private String correlationId; + + @SerializedName(value = "type") + private String type; + + public LcmWrapper() { + // Create a default LCMWrapper instance + } + + /** + * Get the version. + * + * @return the version + */ + public String getVersion() { + return version; + } + + /** + * Set the version. + * + * @param version the version to set + */ + public void setVersion(String version) { + this.version = version; + } + + /** + * Get the cambria partition. + * + * @return the cambriaPartition + */ + public String getCambriaPartition() { + return cambriaPartition; + } + + /** + * Set the cambria partition. + * + * @param cambriaPartition the cambriaPartition to set + */ + public void setCambriaPartition(String cambriaPartition) { + this.cambriaPartition = cambriaPartition; + } + + /** + * Get the RPN name. + * + * @return the rpcName + */ + public String getRpcName() { + return rpcName; + } + + /** + * Set the RPC name. + * + * @param rpcName the rpcName to set + */ + public void setRpcName(String rpcName) { + this.rpcName = rpcName; + } + + /** + * Get the correlation Id. + * + * @return the correlationId + */ + public String getCorrelationId() { + return correlationId; + } + + /** + * Set the correclation Id. + * + * @param correlationId the correlationId to set + */ + public void setCorrelationId(String correlationId) { + this.correlationId = correlationId; + } + + /** + * Get the type. + * + * @return the type + */ + public String getType() { + return type; + } + + /** + * Set the type. + * + * @param type the type to set + */ + public void setType(String type) { + this.type = type; + } + + @Override + public String toString() { + return "Wrapper [version=" + version + ", cambriaPartition=" + cambriaPartition + ", rpcName=" + rpcName + + ", correlationId=" + correlationId + ", type=" + type + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((cambriaPartition == null) ? 0 : cambriaPartition.hashCode()); + result = prime * result + ((correlationId == null) ? 0 : correlationId.hashCode()); + result = prime * result + ((rpcName == null) ? 0 : rpcName.hashCode()); + result = prime * result + ((type == null) ? 0 : type.hashCode()); + result = prime * result + ((version == null) ? 0 : version.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + LcmWrapper other = (LcmWrapper) obj; + if (cambriaPartition == null) { + if (other.cambriaPartition != null) { + return false; + } + } else if (!cambriaPartition.equals(other.cambriaPartition)) { + return false; + } + if (correlationId == null) { + if (other.correlationId != null) { + return false; + } + } else if (!correlationId.equals(other.correlationId)) { + return false; + } + if (rpcName == null) { + if (other.rpcName != null) { + return false; + } + } else if (!rpcName.equals(other.rpcName)) { + return false; + } + if (type == null) { + if (other.type != null) { + return false; + } + } else if (!type.equals(other.type)) { + return false; + } + if (version == null) { + if (other.version != null) { + return false; + } + } else if (!version.equals(other.version)) { + return false; + } + return true; + } + +} diff --git a/models-interactions/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/util/Serialization.java b/models-interactions/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/util/Serialization.java new file mode 100644 index 000000000..d261c442c --- /dev/null +++ b/models-interactions/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/util/Serialization.java @@ -0,0 +1,114 @@ +/*- + * ============LICENSE_START======================================================= + * appc + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.appclcm.util; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonPrimitive; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; + +import java.lang.reflect.Type; +import java.time.Instant; + +import org.onap.policy.appclcm.LcmRequest; +import org.onap.policy.appclcm.LcmResponse; + +public final class Serialization { + public static final Gson gsonPretty = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting() + .registerTypeAdapter(Instant.class, new InstantAdapter()).create(); + + public static final Gson gson = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting() + .registerTypeAdapter(LcmRequest.class, new RequestAdapter()) + .registerTypeAdapter(LcmResponse.class, new ResponseAdapter()).create(); + + public static final Gson gsonJunit = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting() + .registerTypeAdapter(Instant.class, new InstantJunitAdapter()).create(); + + private Serialization() {} + + public static class RequestAdapter implements JsonSerializer<LcmRequest>, JsonDeserializer<LcmRequest> { + + @Override + public JsonElement serialize(LcmRequest src, Type typeOfSrc, JsonSerializationContext context) { + JsonElement requestJson = gsonPretty.toJsonTree(src, LcmRequest.class); + JsonObject input = new JsonObject(); + input.add("input", requestJson); + + return input; + } + + @Override + public LcmRequest deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { + return gsonPretty.fromJson(json.getAsJsonObject().get("input"), LcmRequest.class); + } + } + + public static class ResponseAdapter implements JsonSerializer<LcmResponse>, JsonDeserializer<LcmResponse> { + + @Override + public JsonElement serialize(LcmResponse src, Type typeOfSrc, JsonSerializationContext context) { + JsonElement responseJson = gsonPretty.toJsonTree(src, LcmResponse.class); + JsonObject output = new JsonObject(); + output.add("output", responseJson); + return output; + } + + @Override + public LcmResponse deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { + return gsonPretty.fromJson(json.getAsJsonObject().get("output"), LcmResponse.class); + } + } + + public static class InstantAdapter implements JsonSerializer<Instant>, JsonDeserializer<Instant> { + + @Override + public Instant deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { + return Instant.parse(json.getAsString()); + } + + @Override + public JsonElement serialize(Instant src, Type typeOfSrc, JsonSerializationContext context) { + return new JsonPrimitive(src.toString()); + } + + } + + public static class InstantJunitAdapter implements JsonSerializer<Instant>, JsonDeserializer<Instant> { + + @Override + public Instant deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { + return Instant.ofEpochMilli(json.getAsLong()); + } + + @Override + public JsonElement serialize(Instant src, Type typeOfSrc, JsonSerializationContext context) { + return new JsonPrimitive(src.toEpochMilli()); + } + + } + +} diff --git a/models-interactions/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/util/StatusCodeEnum.java b/models-interactions/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/util/StatusCodeEnum.java new file mode 100644 index 000000000..8e3beb3c7 --- /dev/null +++ b/models-interactions/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/util/StatusCodeEnum.java @@ -0,0 +1,88 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.appclcm.util; + +public enum StatusCodeEnum { + ACCEPTED("ACCEPTED"), ERROR("ERROR"), REJECT("REJECT"), SUCCESS("SUCCESS"), FAILURE("FAILURE"), + PARTIAL_SUCCESS("PARTIAL SUCCESS"), PARTIAL_FAILURE("PARTIAL FAILURE"); + + private String name; + + StatusCodeEnum(final String name) { + this.name = name; + } + + @Override + public String toString() { + return this.name; + } + + /** + * Determine status enum from the code. + * + * @param statusCode integer code indicating the status + * @return enum representation of status code + */ + public static StatusCodeEnum fromStatusCode(final int statusCode) { + if (statusCode == 100) { + return ACCEPTED; + } + + if (statusCode == 200) { + return ERROR; + } + + if (isRejectStatusCode(statusCode)) { + return REJECT; + } + + if (statusCode == 400) { + return SUCCESS; + } + + if (isFailureStatusCode(statusCode)) { + return FAILURE; + } + + if (statusCode == 500) { + return PARTIAL_SUCCESS; + } + + if (isPartialFailureStatusCode(statusCode)) { + return PARTIAL_FAILURE; + } + + return null; + } + + private static boolean isRejectStatusCode(final int statusCode) { + return statusCode >= 300 && statusCode <= 313; + } + + private static boolean isFailureStatusCode(final int statusCode) { + return statusCode == 450 || (statusCode >= 401 && statusCode <= 406); + } + + private static boolean isPartialFailureStatusCode(final int statusCode) { + return statusCode >= 501 && statusCode <= 599; + } +}
\ No newline at end of file diff --git a/models-interactions/model-impl/appclcm/src/main/resources/definitions.yaml b/models-interactions/model-impl/appclcm/src/main/resources/definitions.yaml new file mode 100644 index 000000000..d015f33ae --- /dev/null +++ b/models-interactions/model-impl/appclcm/src/main/resources/definitions.yaml @@ -0,0 +1,119 @@ +### +# ============LICENSE_START======================================================= +# appc +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# Modifications Copyright (C) 2019 Nordix Foundation. +# ================================================================================ +# 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========================================================= +### + +Request: + type: object + properties: + CommonHeader: + type: object + properties: + TimeStamp: + type: string + APIver: + type: string + value: '1.01' + OriginatorID: + type: string + RequestID: + type: string + pattern: "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$" + SubRequestID: + type: string + Flags: + type: object + required: + - TimeStamp + - APIver + - OriginatorID + - RequestID + Action: + type: string + enum: + - Audit + - ActionStatus + - BlockAudits + - Configure + - HealthCheck + - Install + - LiveUpgrade + - Migrate + - ModifyConfig + - Query + - Rebuild + - Reconfigure + - Restart + - Rollback + - Scale + - Start + - Stop + - Sync + - Terminate + - Test + - Upgrade + TargetID: + type: string + ObjectID: + type: string + Payload: + type: object + required: + - CommonHeader + - Action + - TargetID +Response: + type: object + properties: + CommonHeader: + type: object + properties: + TimeStamp: + type: string + APIver: + type: string + OriginatorID: + type: string + RequestID: + type: string + SubRequestID: + type: string + Flags: + type: object + required: + - TimeStamp + - APIver + - OriginatorID + - RequestID + Status: + type: object + properties: + Code: + type: integer + Value: + type: string + required: + - Code + - Value + Payload: + type: object + required: + - CommonHeader + - Status + diff --git a/models-interactions/model-impl/appclcm/src/test/java/org/onap/policy/appclcm/AppcLcmTest.java b/models-interactions/model-impl/appclcm/src/test/java/org/onap/policy/appclcm/AppcLcmTest.java new file mode 100644 index 000000000..88b8a3cad --- /dev/null +++ b/models-interactions/model-impl/appclcm/src/test/java/org/onap/policy/appclcm/AppcLcmTest.java @@ -0,0 +1,233 @@ +/*- + * ============LICENSE_START======================================================= + * appclcm + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.appclcm; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.util.HashMap; +import java.util.UUID; + +import org.junit.Test; +import org.onap.policy.appclcm.util.Serialization; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class AppcLcmTest { + + private static final Logger logger = LoggerFactory.getLogger(AppcLcmTest.class); + + private static LcmRequestWrapper dmaapRequest; + private static LcmResponseWrapper dmaapResponse; + + static { + /* + * Construct an APPCLCM Request to be Serialized + */ + dmaapRequest = new LcmRequestWrapper(); + dmaapRequest.setCorrelationId("664be3d2-6c12-4f4b-a3e7-c349acced200" + "-" + "1"); + dmaapRequest.setRpcName("restart"); + dmaapRequest.setType("request"); + + dmaapResponse = new LcmResponseWrapper(); + dmaapResponse.setCorrelationId("664be3d2-6c12-4f4b-a3e7-c349acced200" + "-" + "1"); + dmaapResponse.setRpcName("restart"); + dmaapResponse.setType("response"); + + LcmRequest appcRequest = new LcmRequest(); + + appcRequest.setAction("restart"); + + HashMap<String, String> actionIdentifiers = new HashMap<>(); + actionIdentifiers.put("vnf-id", "trial-vnf-003"); + actionIdentifiers.put("vserver-id", "08f6c1f9-99e7-49f3-a662-c62b9f200d79"); + + appcRequest.setActionIdentifiers(actionIdentifiers); + + LcmCommonHeader commonHeader = new LcmCommonHeader(); + commonHeader.setRequestId(UUID.fromString("664be3d2-6c12-4f4b-a3e7-c349acced200")); + commonHeader.setSubRequestId("1"); + commonHeader.setOriginatorId("664be3d2-6c12-4f4b-a3e7-c349acced200"); + + appcRequest.setCommonHeader(commonHeader); + + appcRequest.setPayload(null); + + dmaapRequest.setBody(appcRequest); + + /* + * Construct an APPCLCM Response to be Serialized + */ + LcmResponse appcResponse = new LcmResponse(appcRequest); + appcResponse.getStatus().setCode(400); + appcResponse.getStatus().setMessage("Restart Successful"); + appcResponse.setPayload(null); + + dmaapResponse.setBody(appcResponse); + } + + @Test + public void testRequestSerialization() { + + /* + * Use the gson serializer to obtain json + */ + String jsonRequest = Serialization.gson.toJson(dmaapRequest, LcmRequestWrapper.class); + assertNotNull(jsonRequest); + + /* + * The serializer should have added an extra sub-tag called "input" that wraps the request + */ + assertTrue(jsonRequest.contains("input")); + + /* + * The common-header, request-id, and sub-request-id should exist + */ + assertTrue(jsonRequest.contains("common-header")); + assertTrue(jsonRequest.contains("request-id")); + assertTrue(jsonRequest.contains("sub-request-id")); + + /* + * action-identifiers should exist and contain a vnf-id + */ + assertTrue(jsonRequest.contains("action-identifiers")); + assertTrue(jsonRequest.contains("vnf-id")); + + /* + * The action sub-tag should exist + */ + assertTrue(jsonRequest.contains("action")); + + logger.debug("Request as JSON: " + jsonRequest + "\n\n"); + } + + @Test + public void testRequestDeserialization() { + + /* + * Convert the LCM request object into json so we have a string of json to use for testing + */ + String jsonRequest = Serialization.gson.toJson(dmaapRequest, LcmRequestWrapper.class); + + /* + * Use the serializer to convert the json string into a java object + */ + LcmRequestWrapper dmaapRequest = Serialization.gson.fromJson(jsonRequest, LcmRequestWrapper.class); + assertNotNull(dmaapRequest); + + /* + * The type of the DMAAP wrapper should be request + */ + assertEquals("request", dmaapRequest.getType()); + + /* + * The DMAAP wrapper must have a body as that is the true APPC request + */ + assertNotNull(dmaapRequest.getBody()); + LcmRequest appcRequest = dmaapRequest.getBody(); + assertNotNull(appcRequest); + + /* + * The common header should not be null + */ + assertNotNull(appcRequest.getCommonHeader()); + + /* + * The action should not be null and should be set to restart + */ + assertNotNull(appcRequest.getAction()); + assertEquals("restart", appcRequest.getAction()); + + /* + * The action-identifiers should not be null and should contain a vnf-id + */ + assertNotNull(appcRequest.getActionIdentifiers()); + assertNotNull(appcRequest.getActionIdentifiers().get("vnf-id")); + + logger.debug("Request as a Java Object: \n" + appcRequest.toString() + "\n\n"); + } + + @Test + public void testResponseSerialization() { + + /* + * Use the serializer to convert the object into json + */ + String jsonResponse = Serialization.gson.toJson(dmaapResponse, LcmResponseWrapper.class); + assertNotNull(jsonResponse); + + /* + * The serializer should have added an extra sub-tag called "input" that wraps the request + */ + assertTrue(jsonResponse.contains("output")); + + /* + * The response should contain a common-header, request-id, sub-request-id, and status + */ + assertTrue(jsonResponse.contains("common-header")); + assertTrue(jsonResponse.contains("request-id")); + assertTrue(jsonResponse.contains("sub-request-id")); + assertTrue(jsonResponse.contains("status")); + + logger.debug("Response as JSON: " + jsonResponse + "\n\n"); + } + + @Test + public void testResponseDeserialization() { + /* + * Convert the LCM response object into json so we have a string of json to use for testing + */ + String jsonResponse = Serialization.gson.toJson(dmaapResponse, LcmResponseWrapper.class); + + /* + * Use the serializer to convert the json string into a java object + */ + LcmResponseWrapper dmaapResponse = Serialization.gson.fromJson(jsonResponse, LcmResponseWrapper.class); + assertNotNull(dmaapResponse); + + /* + * The type of the DMAAP wrapper should be response + */ + assertEquals("response", dmaapResponse.getType()); + + /* + * The DMAAP wrapper must have a body as that is the true APPC response + */ + assertNotNull(dmaapResponse.getBody()); + LcmResponse appcResponse = dmaapResponse.getBody(); + assertNotNull(appcResponse); + + /* + * The common header should not be null + */ + assertNotNull(appcResponse.getCommonHeader()); + + /* + * The status should not be null and the status code should be 400 + */ + assertNotNull(appcResponse.getStatus()); + assertEquals(400, appcResponse.getStatus().getCode()); + + logger.debug("Response as a Java Object: \n" + appcResponse.toString() + "\n\n"); + } +} diff --git a/models-interactions/model-impl/appclcm/src/test/java/org/onap/policy/appclcm/LcmCommonHeaderTest.java b/models-interactions/model-impl/appclcm/src/test/java/org/onap/policy/appclcm/LcmCommonHeaderTest.java new file mode 100644 index 000000000..82a292ee5 --- /dev/null +++ b/models-interactions/model-impl/appclcm/src/test/java/org/onap/policy/appclcm/LcmCommonHeaderTest.java @@ -0,0 +1,144 @@ +/*- + * ============LICENSE_START======================================================= + * appc + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.appclcm; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.time.Instant; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +import org.junit.Test; + +public class LcmCommonHeaderTest { + + @Test + public void testLcmCommonHeader() { + LcmCommonHeader commonHeader = new LcmCommonHeader(); + assertNotNull(commonHeader); + assertNotNull(new LcmCommonHeader(commonHeader)); + assertNotEquals(0, commonHeader.hashCode()); + + commonHeader.setApiVer("Kansas"); + assertEquals("Kansas", commonHeader.getApiVer()); + + Map<String, String> flagMap = new HashMap<>(); + commonHeader.setFlags(flagMap); + assertEquals(flagMap, commonHeader.getFlags()); + + commonHeader.setOriginatorId("Dorothy"); + assertEquals("Dorothy", commonHeader.getOriginatorId()); + + UUID requestId = UUID.randomUUID(); + commonHeader.setRequestId(requestId); + assertEquals(requestId, commonHeader.getRequestId()); + + commonHeader.setSubRequestId("Can I go home?"); + assertEquals("Can I go home?", commonHeader.getSubRequestId()); + + Instant timestamp = Instant.now(); + commonHeader.setTimeStamp(timestamp); + assertEquals(timestamp, commonHeader.getTimeStamp()); + + assertNotEquals(0, commonHeader.hashCode()); + + assertEquals("CommonHeader [timeStamp=", commonHeader.toString().substring(0, 24)); + + LcmCommonHeader copiedLcmCommonHeader = new LcmCommonHeader(); + copiedLcmCommonHeader.setApiVer(commonHeader.getApiVer()); + copiedLcmCommonHeader.setFlags(commonHeader.getFlags()); + copiedLcmCommonHeader.setOriginatorId(commonHeader.getOriginatorId()); + copiedLcmCommonHeader.setRequestId(commonHeader.getRequestId()); + copiedLcmCommonHeader.setSubRequestId(commonHeader.getSubRequestId()); + copiedLcmCommonHeader.setTimeStamp(commonHeader.getTimeStamp()); + + assertTrue(commonHeader.equals(commonHeader)); + assertTrue(commonHeader.equals(copiedLcmCommonHeader)); + assertFalse(commonHeader.equals(null)); + assertFalse(commonHeader.equals("Hello")); + + LcmCommonHeader clonedLcmCommonHeader = new LcmCommonHeader(commonHeader); + clonedLcmCommonHeader.setApiVer(commonHeader.getApiVer()); + clonedLcmCommonHeader.setTimeStamp(commonHeader.getTimeStamp()); + + assertTrue(commonHeader.equals(clonedLcmCommonHeader)); + + commonHeader.setApiVer(null); + assertFalse(commonHeader.equals(copiedLcmCommonHeader)); + copiedLcmCommonHeader.setApiVer(null); + assertTrue(commonHeader.equals(copiedLcmCommonHeader)); + commonHeader.setApiVer("Kansas"); + assertFalse(commonHeader.equals(copiedLcmCommonHeader)); + copiedLcmCommonHeader.setApiVer("Kansas"); + assertTrue(commonHeader.equals(copiedLcmCommonHeader)); + + commonHeader.setFlags(null); + assertFalse(commonHeader.equals(copiedLcmCommonHeader)); + copiedLcmCommonHeader.setFlags(null); + assertTrue(commonHeader.equals(copiedLcmCommonHeader)); + commonHeader.setFlags(flagMap); + assertFalse(commonHeader.equals(copiedLcmCommonHeader)); + copiedLcmCommonHeader.setFlags(flagMap); + assertTrue(commonHeader.equals(copiedLcmCommonHeader)); + + commonHeader.setOriginatorId(null); + assertFalse(commonHeader.equals(copiedLcmCommonHeader)); + copiedLcmCommonHeader.setOriginatorId(null); + assertTrue(commonHeader.equals(copiedLcmCommonHeader)); + commonHeader.setOriginatorId("Dorothy"); + assertFalse(commonHeader.equals(copiedLcmCommonHeader)); + copiedLcmCommonHeader.setOriginatorId("Dorothy"); + assertTrue(commonHeader.equals(copiedLcmCommonHeader)); + + commonHeader.setRequestId(null); + assertFalse(commonHeader.equals(copiedLcmCommonHeader)); + copiedLcmCommonHeader.setRequestId(null); + assertTrue(commonHeader.equals(copiedLcmCommonHeader)); + commonHeader.setRequestId(requestId); + assertFalse(commonHeader.equals(copiedLcmCommonHeader)); + copiedLcmCommonHeader.setRequestId(requestId); + assertTrue(commonHeader.equals(copiedLcmCommonHeader)); + + commonHeader.setSubRequestId(null); + assertFalse(commonHeader.equals(copiedLcmCommonHeader)); + copiedLcmCommonHeader.setSubRequestId(null); + assertTrue(commonHeader.equals(copiedLcmCommonHeader)); + commonHeader.setSubRequestId("Can I go home?"); + assertFalse(commonHeader.equals(copiedLcmCommonHeader)); + copiedLcmCommonHeader.setSubRequestId("Can I go home?"); + assertTrue(commonHeader.equals(copiedLcmCommonHeader)); + + commonHeader.setTimeStamp(null); + assertFalse(commonHeader.equals(copiedLcmCommonHeader)); + copiedLcmCommonHeader.setTimeStamp(null); + assertTrue(commonHeader.equals(copiedLcmCommonHeader)); + commonHeader.setTimeStamp(timestamp); + assertFalse(commonHeader.equals(copiedLcmCommonHeader)); + copiedLcmCommonHeader.setTimeStamp(timestamp); + assertTrue(commonHeader.equals(copiedLcmCommonHeader)); + } +} diff --git a/models-interactions/model-impl/appclcm/src/test/java/org/onap/policy/appclcm/LcmRequestTest.java b/models-interactions/model-impl/appclcm/src/test/java/org/onap/policy/appclcm/LcmRequestTest.java new file mode 100644 index 000000000..e89976c80 --- /dev/null +++ b/models-interactions/model-impl/appclcm/src/test/java/org/onap/policy/appclcm/LcmRequestTest.java @@ -0,0 +1,112 @@ +/*- + * ============LICENSE_START======================================================= + * appc + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.appclcm; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.Test; + +public class LcmRequestTest { + + @Test + public void testLcmRequest() { + LcmRequest request = new LcmRequest(); + assertNotNull(request); + assertNotEquals(0, request.hashCode()); + + LcmCommonHeader commonHeader = new LcmCommonHeader(); + + request.setCommonHeader(commonHeader); + assertEquals(commonHeader, request.getCommonHeader()); + + request.setAction("Go to Oz"); + assertEquals("Go to Oz", request.getAction()); + + Map<String, String> actionIdentifiers = new HashMap<>(); + actionIdentifiers.put("North", "Good Witch"); + actionIdentifiers.put("West", "Bad Witch"); + + request.setActionIdentifiers(actionIdentifiers); + assertEquals(actionIdentifiers, request.getActionIdentifiers()); + + request.setPayload("The Emerald City"); + assertEquals("The Emerald City", request.getPayload()); + + assertNotEquals(0, request.hashCode()); + + assertEquals("Request [commonHeader=CommonHeader [timeStamp=", request.toString().substring(0, 46)); + + LcmRequest copiedLcmRequest = new LcmRequest(); + copiedLcmRequest.setCommonHeader(request.getCommonHeader()); + copiedLcmRequest.setAction(request.getAction()); + copiedLcmRequest.setActionIdentifiers(request.getActionIdentifiers()); + copiedLcmRequest.setPayload(request.getPayload()); + + assertTrue(request.equals(request)); + assertTrue(request.equals(copiedLcmRequest)); + assertFalse(request.equals(null)); + assertFalse(request.equals("Hello")); + + request.setCommonHeader(null); + assertFalse(request.equals(copiedLcmRequest)); + copiedLcmRequest.setCommonHeader(null); + assertTrue(request.equals(copiedLcmRequest)); + request.setCommonHeader(commonHeader); + assertFalse(request.equals(copiedLcmRequest)); + copiedLcmRequest.setCommonHeader(commonHeader); + assertTrue(request.equals(copiedLcmRequest)); + + request.setAction(null); + assertFalse(request.equals(copiedLcmRequest)); + copiedLcmRequest.setAction(null); + assertTrue(request.equals(copiedLcmRequest)); + request.setAction("Go to Oz"); + assertFalse(request.equals(copiedLcmRequest)); + copiedLcmRequest.setAction("Go to Oz"); + assertTrue(request.equals(copiedLcmRequest)); + + request.setActionIdentifiers(null); + assertFalse(request.equals(copiedLcmRequest)); + copiedLcmRequest.setActionIdentifiers(null); + assertTrue(request.equals(copiedLcmRequest)); + request.setActionIdentifiers(actionIdentifiers); + assertFalse(request.equals(copiedLcmRequest)); + copiedLcmRequest.setActionIdentifiers(actionIdentifiers); + assertTrue(request.equals(copiedLcmRequest)); + + request.setPayload(null); + assertFalse(request.equals(copiedLcmRequest)); + copiedLcmRequest.setPayload(null); + assertTrue(request.equals(copiedLcmRequest)); + request.setPayload("The Emerald City"); + assertFalse(request.equals(copiedLcmRequest)); + copiedLcmRequest.setPayload("The Emerald City"); + assertTrue(request.equals(copiedLcmRequest)); + } +} diff --git a/models-interactions/model-impl/appclcm/src/test/java/org/onap/policy/appclcm/LcmRequestWrapperTest.java b/models-interactions/model-impl/appclcm/src/test/java/org/onap/policy/appclcm/LcmRequestWrapperTest.java new file mode 100644 index 000000000..e2c7f6279 --- /dev/null +++ b/models-interactions/model-impl/appclcm/src/test/java/org/onap/policy/appclcm/LcmRequestWrapperTest.java @@ -0,0 +1,67 @@ +/*- + * ============LICENSE_START======================================================= + * appc + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.appclcm; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +public class LcmRequestWrapperTest { + + @Test + public void testLcmRequestWrapperWrapper() { + assertNotNull(new LcmRequestWrapper(new LcmRequest())); + LcmRequestWrapper requestWrapper = new LcmRequestWrapper(); + assertNotNull(requestWrapper); + assertNotEquals(0, requestWrapper.hashCode()); + + LcmRequest request = new LcmRequest(); + + requestWrapper.setBody(request); + assertEquals(request, requestWrapper.getBody()); + + assertNotEquals(0, requestWrapper.hashCode()); + + assertEquals("RequestWrapper [body=Request [commonHeader=nul", requestWrapper.toString().substring(0, 46)); + + LcmRequestWrapper copiedLcmRequestWrapper = new LcmRequestWrapper(); + copiedLcmRequestWrapper.setBody(requestWrapper.getBody()); + + assertTrue(requestWrapper.equals(requestWrapper)); + assertTrue(requestWrapper.equals(copiedLcmRequestWrapper)); + assertFalse(requestWrapper.equals(null)); + assertFalse(requestWrapper.equals("Hello")); + + requestWrapper.setBody(null); + assertFalse(requestWrapper.equals(copiedLcmRequestWrapper)); + copiedLcmRequestWrapper.setBody(null); + assertTrue(requestWrapper.equals(copiedLcmRequestWrapper)); + requestWrapper.setBody(request); + assertFalse(requestWrapper.equals(copiedLcmRequestWrapper)); + copiedLcmRequestWrapper.setBody(request); + assertTrue(requestWrapper.equals(copiedLcmRequestWrapper)); + } +} diff --git a/models-interactions/model-impl/appclcm/src/test/java/org/onap/policy/appclcm/LcmResonseCodeTest.java b/models-interactions/model-impl/appclcm/src/test/java/org/onap/policy/appclcm/LcmResonseCodeTest.java new file mode 100644 index 000000000..d5a6a16f6 --- /dev/null +++ b/models-interactions/model-impl/appclcm/src/test/java/org/onap/policy/appclcm/LcmResonseCodeTest.java @@ -0,0 +1,56 @@ +/*- + * ============LICENSE_START======================================================= + * appc + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.appclcm; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import org.junit.Test; + +public class LcmResonseCodeTest { + + @Test + public void testLcmResponseCode() { + assertNull(LcmResponseCode.toResponseValue(0)); + + assertEquals(LcmResponseCode.ACCEPTED, LcmResponseCode.toResponseValue(100)); + assertEquals(LcmResponseCode.ERROR, LcmResponseCode.toResponseValue(200)); + assertEquals(LcmResponseCode.REJECT, LcmResponseCode.toResponseValue(300)); + assertEquals(LcmResponseCode.SUCCESS, LcmResponseCode.toResponseValue(400)); + assertEquals(LcmResponseCode.FAILURE, LcmResponseCode.toResponseValue(450)); + assertEquals(LcmResponseCode.FAILURE, LcmResponseCode.toResponseValue(401)); + assertEquals(LcmResponseCode.FAILURE, LcmResponseCode.toResponseValue(406)); + assertEquals(LcmResponseCode.PARTIAL_SUCCESS, LcmResponseCode.toResponseValue(500)); + assertEquals(LcmResponseCode.PARTIAL_FAILURE, LcmResponseCode.toResponseValue(501)); + assertEquals(LcmResponseCode.PARTIAL_FAILURE, LcmResponseCode.toResponseValue(599)); + + assertEquals("100", new LcmResponseCode(100).toString()); + assertEquals("200", new LcmResponseCode(200).toString()); + assertEquals("300", new LcmResponseCode(300).toString()); + assertEquals("400", new LcmResponseCode(400).toString()); + assertEquals("450", new LcmResponseCode(450).toString()); + assertEquals("500", new LcmResponseCode(500).toString()); + assertEquals("510", new LcmResponseCode(510).toString()); + + assertEquals(300, new LcmResponseCode(300).getCode()); + } +} diff --git a/models-interactions/model-impl/appclcm/src/test/java/org/onap/policy/appclcm/LcmResponseStatusTest.java b/models-interactions/model-impl/appclcm/src/test/java/org/onap/policy/appclcm/LcmResponseStatusTest.java new file mode 100644 index 000000000..4bd7ba48d --- /dev/null +++ b/models-interactions/model-impl/appclcm/src/test/java/org/onap/policy/appclcm/LcmResponseStatusTest.java @@ -0,0 +1,75 @@ +/*- + * ============LICENSE_START======================================================= + * appc + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.appclcm; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +public class LcmResponseStatusTest { + + @Test + public void testResonseStatus() { + LcmResponseStatus status = new LcmResponseStatus(); + assertNotNull(status); + assertNotEquals(0, status.hashCode()); + + status.setCode(1234); + assertEquals(1234, status.getCode()); + + status.setMessage("The wonderful land of Oz"); + assertEquals("The wonderful land of Oz", status.getMessage()); + + assertEquals("ResponseStatus [code=1234, message=The wonderfu", status.toString().substring(0, 47)); + + LcmResponseStatus copiedStatus = new LcmResponseStatus(); + copiedStatus.setCode(status.getCode()); + copiedStatus.setMessage(status.getMessage()); + + assertTrue(status.equals(status)); + assertTrue(status.equals(copiedStatus)); + assertFalse(status.equals(null)); + assertFalse(status.equals("Hello")); + + status.setCode(-1); + assertFalse(status.equals(copiedStatus)); + copiedStatus.setCode(-1); + assertTrue(status.equals(copiedStatus)); + status.setCode(1234); + assertFalse(status.equals(copiedStatus)); + copiedStatus.setCode(1234); + assertTrue(status.equals(copiedStatus)); + + status.setMessage(null); + assertFalse(status.equals(copiedStatus)); + copiedStatus.setMessage(null); + assertTrue(status.equals(copiedStatus)); + status.setMessage("The wonderful land of Oz"); + assertFalse(status.equals(copiedStatus)); + copiedStatus.setMessage("The wonderful land of Oz"); + assertTrue(status.equals(copiedStatus)); + } +} diff --git a/models-interactions/model-impl/appclcm/src/test/java/org/onap/policy/appclcm/LcmResponseTest.java b/models-interactions/model-impl/appclcm/src/test/java/org/onap/policy/appclcm/LcmResponseTest.java new file mode 100644 index 000000000..06b64f78e --- /dev/null +++ b/models-interactions/model-impl/appclcm/src/test/java/org/onap/policy/appclcm/LcmResponseTest.java @@ -0,0 +1,114 @@ +/*- + * ============LICENSE_START======================================================= + * appclcm + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.appclcm; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +public class LcmResponseTest { + + private static final String PAYLOAD = "payload"; + + @Test + public void testHashCode() { + LcmResponse response = new LcmResponse(); + assertTrue(response.hashCode() != 0); + response.setCommonHeader(new LcmCommonHeader()); + assertTrue(response.hashCode() != 0); + response.setPayload(PAYLOAD); + assertTrue(response.hashCode() != 0); + response.setStatus(null); + assertTrue(response.hashCode() != 0); + } + + @Test + public void testLcmResponse() { + LcmResponse response = new LcmResponse(); + assertNull(response.getCommonHeader()); + assertNull(response.getPayload()); + assertNotNull(response.getStatus()); + } + + @Test + public void testToString() { + LcmResponse response = new LcmResponse(); + assertFalse(response.toString().isEmpty()); + } + + @Test + public void testEqualsObject() { + LcmResponse response = new LcmResponse(); + assertTrue(response.equals(response)); + assertFalse(response.equals(null)); + assertFalse(response.equals(new Object())); + + LcmResponse response2 = new LcmResponse(); + assertTrue(response.equals(response2)); + + response.setCommonHeader(new LcmCommonHeader()); + assertFalse(response.equals(response2)); + response2.setCommonHeader(response.getCommonHeader()); + assertTrue(response.equals(response2)); + + response.setPayload(PAYLOAD); + assertFalse(response.equals(response2)); + response2.setPayload(response.getPayload()); + assertTrue(response.equals(response2)); + + response.setCommonHeader(null); + assertFalse(response.equals(response2)); + response2.setCommonHeader(null); + assertTrue(response.equals(response2)); + + response.setPayload(null); + assertFalse(response.equals(response2)); + response2.setPayload(response.getPayload()); + assertTrue(response.equals(response2)); + + response.setStatus(null); + assertFalse(response.equals(response2)); + response2.setStatus(response.getStatus()); + assertTrue(response.equals(response2)); + + LcmResponseStatus status = new LcmResponseStatus(); + status.setCode(5); + response.setStatus(status); + response2.setStatus(new LcmResponseStatus()); + assertFalse(response.equals(response2)); + } + + @Test + public void testResponseRequest() { + LcmRequest request = new LcmRequest(); + request.setCommonHeader(new LcmCommonHeader()); + request.setPayload(PAYLOAD); + + LcmResponse response = new LcmResponse(request); + + assertTrue(response.getPayload().equals(PAYLOAD)); + } + +} diff --git a/models-interactions/model-impl/appclcm/src/test/java/org/onap/policy/appclcm/LcmResponseWrapperTest.java b/models-interactions/model-impl/appclcm/src/test/java/org/onap/policy/appclcm/LcmResponseWrapperTest.java new file mode 100644 index 000000000..0b2b576a6 --- /dev/null +++ b/models-interactions/model-impl/appclcm/src/test/java/org/onap/policy/appclcm/LcmResponseWrapperTest.java @@ -0,0 +1,66 @@ +/*- + * ============LICENSE_START======================================================= + * appc + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.appclcm; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +public class LcmResponseWrapperTest { + + @Test + public void testLcmResponseWrapperWrapper() { + LcmResponseWrapper responseWrapper = new LcmResponseWrapper(); + assertNotNull(responseWrapper); + assertNotEquals(0, responseWrapper.hashCode()); + + LcmResponse response = new LcmResponse(); + + responseWrapper.setBody(response); + assertEquals(response, responseWrapper.getBody()); + + assertNotEquals(0, responseWrapper.hashCode()); + + assertEquals("ResponseWrapper [body=Response [commonHeader=n", responseWrapper.toString().substring(0, 46)); + + LcmResponseWrapper copiedLcmResponseWrapper = new LcmResponseWrapper(); + copiedLcmResponseWrapper.setBody(responseWrapper.getBody()); + + assertTrue(responseWrapper.equals(responseWrapper)); + assertTrue(responseWrapper.equals(copiedLcmResponseWrapper)); + assertFalse(responseWrapper.equals(null)); + assertFalse(responseWrapper.equals("Hello")); + + responseWrapper.setBody(null); + assertFalse(responseWrapper.equals(copiedLcmResponseWrapper)); + copiedLcmResponseWrapper.setBody(null); + assertTrue(responseWrapper.equals(copiedLcmResponseWrapper)); + responseWrapper.setBody(response); + assertFalse(responseWrapper.equals(copiedLcmResponseWrapper)); + copiedLcmResponseWrapper.setBody(response); + assertTrue(responseWrapper.equals(copiedLcmResponseWrapper)); + } +} diff --git a/models-interactions/model-impl/appclcm/src/test/java/org/onap/policy/appclcm/LcmWrapperTest.java b/models-interactions/model-impl/appclcm/src/test/java/org/onap/policy/appclcm/LcmWrapperTest.java new file mode 100644 index 000000000..40c7fc648 --- /dev/null +++ b/models-interactions/model-impl/appclcm/src/test/java/org/onap/policy/appclcm/LcmWrapperTest.java @@ -0,0 +1,116 @@ +/*- + * ============LICENSE_START======================================================= + * appc + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.appclcm; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +public class LcmWrapperTest { + + @Test + public void testLcmWrapper() { + LcmWrapper wrapper = new LcmWrapper(); + assertNotNull(wrapper); + assertNotEquals(0, wrapper.hashCode()); + + wrapper.setVersion("19.3.9"); + assertEquals("19.3.9", wrapper.getVersion()); + + wrapper.setCambriaPartition("The Emerald City"); + assertEquals("The Emerald City", wrapper.getCambriaPartition()); + + wrapper.setRpcName("Tornado"); + assertEquals("Tornado", wrapper.getRpcName()); + + wrapper.setCorrelationId("YellowBrickRoad"); + assertEquals("YellowBrickRoad", wrapper.getCorrelationId()); + + wrapper.setType("Munchkin"); + assertEquals("Munchkin", wrapper.getType()); + + assertNotEquals(0, wrapper.hashCode()); + + assertEquals("Wrapper [version=19.3.9, cambriaPartition=The ", wrapper.toString().substring(0, 46)); + + LcmWrapper copiedLcmWrapper = new LcmWrapper(); + copiedLcmWrapper.setVersion(wrapper.getVersion()); + copiedLcmWrapper.setCambriaPartition(wrapper.getCambriaPartition()); + copiedLcmWrapper.setRpcName(wrapper.getRpcName()); + copiedLcmWrapper.setCorrelationId(wrapper.getCorrelationId()); + copiedLcmWrapper.setType(wrapper.getType()); + + assertTrue(wrapper.equals(wrapper)); + assertTrue(wrapper.equals(copiedLcmWrapper)); + assertFalse(wrapper.equals(null)); + assertFalse(wrapper.equals("Hello")); + + wrapper.setVersion(null); + assertFalse(wrapper.equals(copiedLcmWrapper)); + copiedLcmWrapper.setVersion(null); + assertTrue(wrapper.equals(copiedLcmWrapper)); + wrapper.setVersion("19.3.9"); + assertFalse(wrapper.equals(copiedLcmWrapper)); + copiedLcmWrapper.setVersion("19.3.9"); + assertTrue(wrapper.equals(copiedLcmWrapper)); + + wrapper.setCambriaPartition(null); + assertFalse(wrapper.equals(copiedLcmWrapper)); + copiedLcmWrapper.setCambriaPartition(null); + assertTrue(wrapper.equals(copiedLcmWrapper)); + wrapper.setCambriaPartition("The Emerald City"); + assertFalse(wrapper.equals(copiedLcmWrapper)); + copiedLcmWrapper.setCambriaPartition("The Emerald City"); + assertTrue(wrapper.equals(copiedLcmWrapper)); + + wrapper.setRpcName(null); + assertFalse(wrapper.equals(copiedLcmWrapper)); + copiedLcmWrapper.setRpcName(null); + assertTrue(wrapper.equals(copiedLcmWrapper)); + wrapper.setRpcName("Tornado"); + assertFalse(wrapper.equals(copiedLcmWrapper)); + copiedLcmWrapper.setRpcName("Tornado"); + assertTrue(wrapper.equals(copiedLcmWrapper)); + + wrapper.setCorrelationId(null); + assertFalse(wrapper.equals(copiedLcmWrapper)); + copiedLcmWrapper.setCorrelationId(null); + assertTrue(wrapper.equals(copiedLcmWrapper)); + wrapper.setCorrelationId("YellowBrickRoad"); + assertFalse(wrapper.equals(copiedLcmWrapper)); + copiedLcmWrapper.setCorrelationId("YellowBrickRoad"); + assertTrue(wrapper.equals(copiedLcmWrapper)); + + wrapper.setType(null); + assertFalse(wrapper.equals(copiedLcmWrapper)); + copiedLcmWrapper.setType(null); + assertTrue(wrapper.equals(copiedLcmWrapper)); + wrapper.setType("Munchkin"); + assertFalse(wrapper.equals(copiedLcmWrapper)); + copiedLcmWrapper.setType("Munchkin"); + assertTrue(wrapper.equals(copiedLcmWrapper)); + } +} diff --git a/models-interactions/model-impl/appclcm/src/test/java/org/onap/policy/appclcm/util/SerializationTest.java b/models-interactions/model-impl/appclcm/src/test/java/org/onap/policy/appclcm/util/SerializationTest.java new file mode 100644 index 000000000..c855bc50a --- /dev/null +++ b/models-interactions/model-impl/appclcm/src/test/java/org/onap/policy/appclcm/util/SerializationTest.java @@ -0,0 +1,58 @@ +/*- + * ============LICENSE_START======================================================= + * appc + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.appclcm.util; + +import static org.junit.Assert.assertEquals; + +import java.time.Instant; +import java.time.ZoneId; +import java.time.ZonedDateTime; + +import org.junit.Test; + +public class SerializationTest { + + @Test + public void test() { + String nameString = "Dorothy"; + String jsonName = Serialization.gsonPretty.toJson(nameString, String.class); + assertEquals("\"Dorothy\"", jsonName); + String jsonInOutName = Serialization.gsonPretty.fromJson(jsonName, String.class); + assertEquals("Dorothy", jsonInOutName); + + Instant instant0 = Instant.ofEpochMilli(1516127215000L); + String instantString0 = Serialization.gsonPretty.toJson(instant0, Instant.class); + assertEquals("\"2018-01-16T18:26:55Z\"", instantString0); + Instant outInstant0 = Serialization.gsonPretty.fromJson(instantString0, Instant.class); + assertEquals(instant0, outInstant0); + + Instant instant1 = Instant.ofEpochMilli(1516127215000L); + String instantString1 = Serialization.gsonJunit.toJson(instant1, Instant.class); + assertEquals("1516127215000", instantString1); + Instant outInstant1 = Serialization.gsonJunit.fromJson(instantString1, Instant.class); + assertEquals(instant1, outInstant1); + + ZonedDateTime zdt = ZonedDateTime.ofInstant(instant0, ZoneId.of("UTC")); + String zdtString = Serialization.gsonPretty.toJson(zdt, ZonedDateTime.class); + assertEquals("{\n \"dateTime\": {\n \"date\":", zdtString.substring(0, 29)); + } +} diff --git a/models-interactions/model-impl/events/README.md b/models-interactions/model-impl/events/README.md new file mode 100644 index 000000000..6ebd725d2 --- /dev/null +++ b/models-interactions/model-impl/events/README.md @@ -0,0 +1,11 @@ +Copyright 2018 AT&T Intellectual Property. All rights reserved. +This file is licensed under the CREATIVE COMMONS ATTRIBUTION 4.0 INTERNATIONAL LICENSE +Full license text at https://creativecommons.org/licenses/by/4.0/legalcode + +Policy Control Loop + +This is the implementation of the Policy's Control Loop messages. This includes the Events consumed and Notifications produced by the ONAP Policy Platform. + + + + diff --git a/models-interactions/model-impl/events/pom.xml b/models-interactions/model-impl/events/pom.xml new file mode 100644 index 000000000..ca079e00a --- /dev/null +++ b/models-interactions/model-impl/events/pom.xml @@ -0,0 +1,46 @@ +<!-- + ============LICENSE_START======================================================= + events in model-impl + ================================================================================ + Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + Modifications Copyright (C) 2019 Nordix Foundation. + ================================================================================ + 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========================================================= + --> + + +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.onap.policy.models.policy-models-interactions.model-impl</groupId> + <artifactId>model-impl</artifactId> + <version>2.0.0-SNAPSHOT</version> + </parent> + + <artifactId>events</artifactId> + + <dependencies> + <dependency> + <groupId>com.google.code.gson</groupId> + <artifactId>gson</artifactId> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + </dependencies> +</project> diff --git a/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopEvent.java b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopEvent.java new file mode 100644 index 000000000..37d7538c6 --- /dev/null +++ b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopEvent.java @@ -0,0 +1,193 @@ +/*- + * ============LICENSE_START======================================================= + * controlloop + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.controlloop; + +import com.google.gson.annotations.SerializedName; +import java.io.Serializable; +import java.util.UUID; + +public abstract class ControlLoopEvent implements Serializable { + + private static final long serialVersionUID = 2391252138583119195L; + + @SerializedName("closedLoopControlName") + private String closedLoopControlName; + + @SerializedName("version") + private String version = "1.0.2"; + + @SerializedName("requestID") + private UUID requestId; + + @SerializedName("closedLoopEventClient") + private String closedLoopEventClient; + + @SerializedName("target_type") + private ControlLoopTargetType targetType; + + @SerializedName("target") + private String target; + + @SerializedName("from") + private String from; + + @SerializedName("policyScope") + private String policyScope; + + @SerializedName("policyName") + private String policyName; + + @SerializedName("policyVersion") + private String policyVersion; + + @SerializedName("closedLoopEventStatus") + private ControlLoopEventStatus closedLoopEventStatus; + + @SerializedName("payload") + private String payload; + + public ControlLoopEvent() { + + } + + /** + * Construct an instace from an existing instance. + * + * @param event the existing instance + */ + public ControlLoopEvent(ControlLoopEvent event) { + if (event == null) { + return; + } + this.closedLoopControlName = event.closedLoopControlName; + this.requestId = event.requestId; + this.closedLoopEventClient = event.closedLoopEventClient; + this.targetType = event.targetType; + this.target = event.target; + this.from = event.from; + this.policyScope = event.policyScope; + this.policyName = event.policyName; + this.policyVersion = event.policyVersion; + this.closedLoopEventStatus = event.closedLoopEventStatus; + this.payload = event.payload; + } + + public boolean isEventStatusValid() { + return this.closedLoopEventStatus != null; + } + + public String getClosedLoopControlName() { + return closedLoopControlName; + } + + public void setClosedLoopControlName(String closedLoopControlName) { + this.closedLoopControlName = closedLoopControlName; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public UUID getRequestId() { + return requestId; + } + + public void setRequestId(UUID requestId) { + this.requestId = requestId; + } + + public String getClosedLoopEventClient() { + return closedLoopEventClient; + } + + public void setClosedLoopEventClient(String closedLoopEventClient) { + this.closedLoopEventClient = closedLoopEventClient; + } + + public ControlLoopTargetType getTargetType() { + return targetType; + } + + public void setTargetType(ControlLoopTargetType targetType) { + this.targetType = targetType; + } + + public String getTarget() { + return target; + } + + public void setTarget(String target) { + this.target = target; + } + + public String getFrom() { + return from; + } + + public void setFrom(String from) { + this.from = from; + } + + public String getPolicyScope() { + return policyScope; + } + + public void setPolicyScope(String policyScope) { + this.policyScope = policyScope; + } + + public String getPolicyName() { + return policyName; + } + + public void setPolicyName(String policyName) { + this.policyName = policyName; + } + + public String getPolicyVersion() { + return policyVersion; + } + + public void setPolicyVersion(String policyVersion) { + this.policyVersion = policyVersion; + } + + public ControlLoopEventStatus getClosedLoopEventStatus() { + return closedLoopEventStatus; + } + + public void setClosedLoopEventStatus(ControlLoopEventStatus closedLoopEventStatus) { + this.closedLoopEventStatus = closedLoopEventStatus; + } + + public String getPayload() { + return payload; + } + + public void setPayload(String payload) { + this.payload = payload; + } +} diff --git a/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopEventStatus.java b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopEventStatus.java new file mode 100644 index 000000000..961a4f8f2 --- /dev/null +++ b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopEventStatus.java @@ -0,0 +1,60 @@ +/*- + * ============LICENSE_START======================================================= + * controlloop + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.controlloop; + +public enum ControlLoopEventStatus { + ONSET("ONSET"), ABATED("ABATED"); + + private String status; + + private ControlLoopEventStatus(String status) { + this.status = status; + } + + @Override + public String toString() { + return this.status; + } + + /** + * Convert a String status to a ControlLoopEventStatus. + * + * @param status the String status + * @return the ControlLoopEventStatus + */ + public static ControlLoopEventStatus toStatus(String status) { + if (ONSET.status.equalsIgnoreCase(status)) { + return ONSET; + } + if (ABATED.status.equalsIgnoreCase(status)) { + return ABATED; + } + // + // In case DCAE uses the old abatement + // + if ("abatement".equalsIgnoreCase(status)) { + return ABATED; + } + return null; + } + +} diff --git a/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopNotification.java b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopNotification.java new file mode 100644 index 000000000..a55c65e2f --- /dev/null +++ b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopNotification.java @@ -0,0 +1,191 @@ +/*- + * ============LICENSE_START======================================================= + * controlloop + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.controlloop; + +import java.io.Serializable; +import java.time.ZoneOffset; +import java.time.ZonedDateTime; +import java.util.LinkedList; +import java.util.List; +import java.util.UUID; + +public abstract class ControlLoopNotification implements Serializable { + + private static final long serialVersionUID = 7538596984567127915L; + + private String closedLoopControlName; + private String version = "1.0.2"; + private UUID requestId; + private String closedLoopEventClient; + private ControlLoopTargetType targetType; + private String target; + private String from; + private String policyScope; + private String policyName; + private String policyVersion; + private ControlLoopNotificationType notification; + private String message; + private ZonedDateTime notificationTime = ZonedDateTime.now(ZoneOffset.UTC); + private Integer opsClTimer; + private List<ControlLoopOperation> history = new LinkedList<>(); + + public ControlLoopNotification() { + + } + + /** + * Construct an instance. + * + * @param event the event + */ + public ControlLoopNotification(ControlLoopEvent event) { + if (event == null) { + return; + } + + this.setClosedLoopControlName(event.getClosedLoopControlName()); + this.setRequestId(event.getRequestId()); + this.setClosedLoopEventClient(event.getClosedLoopEventClient()); + this.setTargetType(event.getTargetType()); + this.setTarget(event.getTarget()); + } + + public String getClosedLoopControlName() { + return closedLoopControlName; + } + + public void setClosedLoopControlName(String closedLoopControlName) { + this.closedLoopControlName = closedLoopControlName; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public UUID getRequestId() { + return requestId; + } + + public void setRequestId(UUID requestId) { + this.requestId = requestId; + } + + public String getClosedLoopEventClient() { + return closedLoopEventClient; + } + + public void setClosedLoopEventClient(String closedLoopEventClient) { + this.closedLoopEventClient = closedLoopEventClient; + } + + public ControlLoopTargetType getTargetType() { + return targetType; + } + + public void setTargetType(ControlLoopTargetType targetType) { + this.targetType = targetType; + } + + public String getTarget() { + return target; + } + + public void setTarget(String target) { + this.target = target; + } + + public String getFrom() { + return from; + } + + public void setFrom(String from) { + this.from = from; + } + + public String getPolicyScope() { + return policyScope; + } + + public void setPolicyScope(String policyScope) { + this.policyScope = policyScope; + } + + public String getPolicyName() { + return policyName; + } + + public void setPolicyName(String policyName) { + this.policyName = policyName; + } + + public String getPolicyVersion() { + return policyVersion; + } + + public void setPolicyVersion(String policyVersion) { + this.policyVersion = policyVersion; + } + + public ControlLoopNotificationType getNotification() { + return notification; + } + + public void setNotification(ControlLoopNotificationType notification) { + this.notification = notification; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public ZonedDateTime getNotificationTime() { + return notificationTime; + } + + public void setNotificationTime(ZonedDateTime notificationTime) { + this.notificationTime = notificationTime; + } + + public Integer getOpsClTimer() { + return opsClTimer; + } + + public void setOpsClTimer(Integer opsClTimer) { + this.opsClTimer = opsClTimer; + } + + public List<ControlLoopOperation> getHistory() { + return history; + } + + public void setHistory(List<ControlLoopOperation> history) { + this.history = history; + } +} diff --git a/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopNotificationType.java b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopNotificationType.java new file mode 100644 index 000000000..51df8749d --- /dev/null +++ b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopNotificationType.java @@ -0,0 +1,74 @@ +/*- + * ============LICENSE_START======================================================= + * controlloop + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.controlloop; + +public enum ControlLoopNotificationType { + ACTIVE("ACTIVE"), REJECTED("REJECTED"), OPERATION("OPERATION"), OPERATION_SUCCESS( + "OPERATION: SUCCESS"), OPERATION_FAILURE("OPERATION: FAILURE"), FINAL_FAILURE( + "FINAL: FAILURE"), FINAL_SUCCESS("FINAL: SUCCESS"), FINAL_OPENLOOP("FINAL: OPENLOOP"); + + private String type; + + private ControlLoopNotificationType(String type) { + this.type = type; + } + + @Override + public String toString() { + return this.type; + } + + /** + * Convert a String type to a ControlLoopNotificationType. + * + * @param type the String type + * @return the ControlLoopNotificationType + */ + public static ControlLoopNotificationType toType(String type) { + if (ACTIVE.toString().equals(type)) { + return ACTIVE; + } + if (REJECTED.toString().equals(type)) { + return REJECTED; + } + if (OPERATION.toString().equals(type)) { + return OPERATION; + } + if (OPERATION_SUCCESS.toString().equals(type)) { + return OPERATION_SUCCESS; + } + if (OPERATION_FAILURE.toString().equals(type)) { + return OPERATION_FAILURE; + } + if (FINAL_FAILURE.toString().equals(type)) { + return FINAL_FAILURE; + } + if (FINAL_SUCCESS.toString().equals(type)) { + return FINAL_SUCCESS; + } + if (FINAL_OPENLOOP.toString().equals(type)) { + return FINAL_OPENLOOP; + } + return null; + } + +} diff --git a/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopOperation.java b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopOperation.java new file mode 100644 index 000000000..8fd4148ef --- /dev/null +++ b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopOperation.java @@ -0,0 +1,230 @@ +/*- + * ============LICENSE_START======================================================= + * controlloop + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.controlloop; + +import java.io.Serializable; +import java.time.Instant; + +public class ControlLoopOperation implements Serializable { + + private static final long serialVersionUID = 8662706581293017099L; + + private String actor; + private String operation; + private String target; + private Instant start = Instant.now(); + private Instant end; + private String subRequestId; + private String outcome; + private String message; + + public ControlLoopOperation() { + + } + + /** + * Construct an instance from an existing instance. + * + * @param op the existing instance + */ + public ControlLoopOperation(ControlLoopOperation op) { + if (op == null) { + return; + } + + this.actor = op.actor; + this.operation = op.operation; + this.target = op.target; + this.start = op.start; + this.end = op.end; + this.subRequestId = op.subRequestId; + this.outcome = op.outcome; + this.message = op.message; + } + + public String toMessage() { + return "actor=" + actor + ",operation=" + operation + ",target=" + target + ",subRequestId=" + subRequestId; + } + + public String toHistory() { + return "actor=" + actor + ",operation=" + operation + ",target=" + target + ",start=" + start + ",end=" + end + + ",subRequestId=" + subRequestId + ",outcome=" + outcome + ",message=" + message; + } + + public String getActor() { + return actor; + } + + public void setActor(String actor) { + this.actor = actor; + } + + public String getOperation() { + return operation; + } + + public void setOperation(String operation) { + this.operation = operation; + } + + public String getTarget() { + return target; + } + + public void setTarget(String target) { + this.target = target; + } + + public Instant getStart() { + return start; + } + + public void setStart(Instant start) { + this.start = start; + } + + public Instant getEnd() { + return end; + } + + public void setEnd(Instant end) { + this.end = end; + } + + public String getSubRequestId() { + return subRequestId; + } + + public void setSubRequestId(String subRequestId) { + this.subRequestId = subRequestId; + } + + public String getOutcome() { + return outcome; + } + + public void setOutcome(String outcome) { + this.outcome = outcome; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + @Override + public String toString() { + return "ControlLoopOperation [actor=" + actor + ", operation=" + operation + ", target=" + target + ", start=" + + start + ", end=" + end + ", subRequestId=" + subRequestId + ", outcome=" + outcome + ", message=" + + message + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((actor == null) ? 0 : actor.hashCode()); + result = prime * result + ((end == null) ? 0 : end.hashCode()); + result = prime * result + ((message == null) ? 0 : message.hashCode()); + result = prime * result + ((operation == null) ? 0 : operation.hashCode()); + result = prime * result + ((outcome == null) ? 0 : outcome.hashCode()); + result = prime * result + ((start == null) ? 0 : start.hashCode()); + result = prime * result + ((subRequestId == null) ? 0 : subRequestId.hashCode()); + result = prime * result + ((target == null) ? 0 : target.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + ControlLoopOperation other = (ControlLoopOperation) obj; + if (actor == null) { + if (other.actor != null) { + return false; + } + } else if (!actor.equals(other.actor)) { + return false; + } + if (end == null) { + if (other.end != null) { + return false; + } + } else if (!end.equals(other.end)) { + return false; + } + if (message == null) { + if (other.message != null) { + return false; + } + } else if (!message.equals(other.message)) { + return false; + } + if (operation == null) { + if (other.operation != null) { + return false; + } + } else if (!operation.equals(other.operation)) { + return false; + } + if (outcome == null) { + if (other.outcome != null) { + return false; + } + } else if (!outcome.equals(other.outcome)) { + return false; + } + if (start == null) { + if (other.start != null) { + return false; + } + } else if (!start.equals(other.start)) { + return false; + } + if (subRequestId == null) { + if (other.subRequestId != null) { + return false; + } + } else if (!subRequestId.equals(other.subRequestId)) { + return false; + } + if (target == null) { + if (other.target != null) { + return false; + } + } else if (!target.equals(other.target)) { + return false; + } + return true; + } + +} diff --git a/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopOperationWrapper.java b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopOperationWrapper.java new file mode 100644 index 000000000..35f482104 --- /dev/null +++ b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopOperationWrapper.java @@ -0,0 +1,55 @@ +/*- + * ============LICENSE_START======================================================= + * controlloop + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.controlloop; + +import java.util.UUID; + +public class ControlLoopOperationWrapper { + + private UUID requestId; + private ControlLoopOperation operation; + + public ControlLoopOperationWrapper() { + + } + + public ControlLoopOperationWrapper(UUID requestId, ControlLoopOperation operation) { + this.requestId = requestId; + this.operation = operation; + } + + public UUID getRequestId() { + return requestId; + } + + public void setRequestId(UUID requestId) { + this.requestId = requestId; + } + + public ControlLoopOperation getOperation() { + return operation; + } + + public void setOperation(ControlLoopOperation operation) { + this.operation = operation; + } +} diff --git a/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopTargetType.java b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopTargetType.java new file mode 100644 index 000000000..e1d107be4 --- /dev/null +++ b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopTargetType.java @@ -0,0 +1,60 @@ +/*- + * ============LICENSE_START======================================================= + * controlloop + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.controlloop; + +public enum ControlLoopTargetType { + VM("VM"), VF("VF"), VFC("VFC"), VNF("VNF"); + + private String type; + + private ControlLoopTargetType(String type) { + this.type = type; + } + + @Override + public String toString() { + return this.type; + } + + /** + * Convert a String type to a ControlLoopTargetType. + * + * @param type the String type + * @return the ControlLoopTargetType + */ + public static ControlLoopTargetType toType(String type) { + if (VM.toString().equals(type)) { + return VM; + } + if (VF.toString().equals(type)) { + return VF; + } + if (VFC.toString().equals(type)) { + return VFC; + } + if (VNF.toString().equals(type)) { + return VNF; + } + + return null; + } +} diff --git a/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/PhysicalControlLoopEvent.java b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/PhysicalControlLoopEvent.java new file mode 100644 index 000000000..245e3a6bd --- /dev/null +++ b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/PhysicalControlLoopEvent.java @@ -0,0 +1,37 @@ +/*- + * ============LICENSE_START======================================================= + * controlloop + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.controlloop; + +public class PhysicalControlLoopEvent extends ControlLoopEvent { + private static final long serialVersionUID = -7282930271094849487L; + + public PhysicalControlLoopEvent() {} + + /** + * Construct an instance from an existing instance. + * + * @param event the existing instance + */ + public PhysicalControlLoopEvent(PhysicalControlLoopEvent event) { + super(event); + } +} diff --git a/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/PhysicalControlLoopNotification.java b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/PhysicalControlLoopNotification.java new file mode 100644 index 000000000..a76b807f4 --- /dev/null +++ b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/PhysicalControlLoopNotification.java @@ -0,0 +1,38 @@ +/*- + * ============LICENSE_START======================================================= + * controlloop + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.controlloop; + +public class PhysicalControlLoopNotification extends ControlLoopNotification { + private static final long serialVersionUID = 8105197217140032892L; + + public PhysicalControlLoopNotification() {} + + /** + * Construct an instance from an existing instance. + * + * @param event the existing instance + */ + public PhysicalControlLoopNotification(PhysicalControlLoopEvent event) { + super(event); + } + +} diff --git a/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/VirtualControlLoopEvent.java b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/VirtualControlLoopEvent.java new file mode 100644 index 000000000..1223d564c --- /dev/null +++ b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/VirtualControlLoopEvent.java @@ -0,0 +1,86 @@ +/*- + * ============LICENSE_START======================================================= + * controlloop + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.controlloop; + +import com.google.gson.annotations.SerializedName; + +import java.time.Instant; +import java.util.HashMap; +import java.util.Map; + +public class VirtualControlLoopEvent extends ControlLoopEvent { + + private static final long serialVersionUID = -5752405682246066226L; + + @SerializedName("closedLoopAlarmStart") + private Instant closedLoopAlarmStart; + + @SerializedName("closedLoopAlarmEnd") + private Instant closedLoopAlarmEnd; + + @SerializedName("AAI") + private Map<String, String> aai = new HashMap<>(); + + public VirtualControlLoopEvent() {} + + + /** + * Construct an instance from an existing instance. + * + * @param event the existing instance + */ + public VirtualControlLoopEvent(VirtualControlLoopEvent event) { + super(event); + if (event == null) { + return; + } + if (event.aai != null) { + this.aai = new HashMap<>(event.aai); + } + this.closedLoopAlarmStart = event.closedLoopAlarmStart; + this.closedLoopAlarmEnd = event.closedLoopAlarmEnd; + } + + public Instant getClosedLoopAlarmStart() { + return closedLoopAlarmStart; + } + + public void setClosedLoopAlarmStart(Instant closedLoopAlarmStart) { + this.closedLoopAlarmStart = closedLoopAlarmStart; + } + + public Instant getClosedLoopAlarmEnd() { + return closedLoopAlarmEnd; + } + + public void setClosedLoopAlarmEnd(Instant closedLoopAlarmEnd) { + this.closedLoopAlarmEnd = closedLoopAlarmEnd; + } + + public Map<String, String> getAai() { + return aai; + } + + public void setAai(Map<String, String> aai) { + this.aai = aai; + } +} diff --git a/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/VirtualControlLoopNotification.java b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/VirtualControlLoopNotification.java new file mode 100644 index 000000000..0a7436520 --- /dev/null +++ b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/VirtualControlLoopNotification.java @@ -0,0 +1,85 @@ +/*- + * ============LICENSE_START======================================================= + * controlloop + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.controlloop; + +import com.google.gson.annotations.SerializedName; + +import java.time.Instant; +import java.util.HashMap; +import java.util.Map; + +public class VirtualControlLoopNotification extends ControlLoopNotification { + + private static final long serialVersionUID = 5354756047932144017L; + + @SerializedName("AAI") + private Map<String, String> aai = new HashMap<>(); + + @SerializedName("closedLoopAlarmStart") + private Instant closedLoopAlarmStart; + + @SerializedName("closedLoopAlarmEnd") + private Instant closedLoopAlarmEnd; + + public VirtualControlLoopNotification() {} + + /** + * Construct an instance. + * + * @param event the event + */ + public VirtualControlLoopNotification(VirtualControlLoopEvent event) { + super(event); + if (event == null) { + return; + } + if (event.getAai() != null) { + this.setAai(new HashMap<>(event.getAai())); + } + this.closedLoopAlarmStart = event.getClosedLoopAlarmStart(); + this.closedLoopAlarmEnd = event.getClosedLoopAlarmEnd(); + } + + public Map<String, String> getAai() { + return aai; + } + + public void setAai(Map<String, String> aai) { + this.aai = aai; + } + + public Instant getClosedLoopAlarmStart() { + return closedLoopAlarmStart; + } + + public void setClosedLoopAlarmStart(Instant closedLoopAlarmStart) { + this.closedLoopAlarmStart = closedLoopAlarmStart; + } + + public Instant getClosedLoopAlarmEnd() { + return closedLoopAlarmEnd; + } + + public void setClosedLoopAlarmEnd(Instant closedLoopAlarmEnd) { + this.closedLoopAlarmEnd = closedLoopAlarmEnd; + } +} diff --git a/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/params/ControlLoopParams.java b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/params/ControlLoopParams.java new file mode 100644 index 000000000..11b90af99 --- /dev/null +++ b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/params/ControlLoopParams.java @@ -0,0 +1,93 @@ +/*- + * ============LICENSE_START======================================================= + * AppcLcmActorServiceProvider + * ================================================================================ + * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.controlloop.params; + +import java.io.Serializable; + +public class ControlLoopParams implements Serializable { + + private static final long serialVersionUID = 970755684770982776L; + + private String closedLoopControlName; + private String controlLoopYaml; + private String policyName; + private String policyScope; + private String policyVersion; + + public ControlLoopParams() { + super(); + } + + /** + * Construct an instance from an existing instance. + * + * @param params the existing instance + */ + public ControlLoopParams(ControlLoopParams params) { + this.closedLoopControlName = params.closedLoopControlName; + this.controlLoopYaml = params.controlLoopYaml; + this.policyName = params.policyName; + this.policyScope = params.policyScope; + this.policyVersion = params.policyVersion; + } + + public String getClosedLoopControlName() { + return closedLoopControlName; + } + + public void setClosedLoopControlName(String closedLoopControlName) { + this.closedLoopControlName = closedLoopControlName; + } + + public String getControlLoopYaml() { + return controlLoopYaml; + } + + public void setControlLoopYaml(String controlLoopYaml) { + this.controlLoopYaml = controlLoopYaml; + } + + public String getPolicyName() { + return policyName; + } + + public void setPolicyName(String policyName) { + this.policyName = policyName; + } + + public String getPolicyScope() { + return policyScope; + } + + public void setPolicyScope(String policyScope) { + this.policyScope = policyScope; + } + + public String getPolicyVersion() { + return policyVersion; + } + + public void setPolicyVersion(String policyVersion) { + this.policyVersion = policyVersion; + } + +} diff --git a/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/util/Serialization.java b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/util/Serialization.java new file mode 100644 index 000000000..b36ee7f6b --- /dev/null +++ b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/util/Serialization.java @@ -0,0 +1,126 @@ +/*- + * ============LICENSE_START======================================================= + * controlloop + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.controlloop.util; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonPrimitive; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; + +import java.lang.reflect.Type; +import java.time.Instant; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; + +import org.onap.policy.controlloop.ControlLoopNotificationType; +import org.onap.policy.controlloop.ControlLoopTargetType; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public final class Serialization { + public static final Gson gson = + new GsonBuilder().disableHtmlEscaping().registerTypeAdapter(ZonedDateTime.class, new GsonUtcAdapter()) + .registerTypeAdapter(Instant.class, new GsonInstantAdapter()) + .registerTypeAdapter(ControlLoopNotificationType.class, new NotificationTypeAdapter()) + .registerTypeAdapter(ControlLoopTargetType.class, new TargetTypeAdapter()).create(); + + + public static final Gson gsonPretty = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting() + .registerTypeAdapter(ZonedDateTime.class, new GsonUtcAdapter()) + .registerTypeAdapter(Instant.class, new GsonInstantAdapter()) + .registerTypeAdapter(ControlLoopNotificationType.class, new NotificationTypeAdapter()) + .registerTypeAdapter(ControlLoopTargetType.class, new TargetTypeAdapter()).create(); + + public static final Gson gsonJunit = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting() + .registerTypeAdapter(ZonedDateTime.class, new GsonUtcAdapter()) + .registerTypeAdapter(Instant.class, new GsonInstantAdapter()) + .registerTypeAdapter(ControlLoopTargetType.class, new TargetTypeAdapter()).create(); + + private Serialization() {} + + public static class NotificationTypeAdapter + implements JsonSerializer<ControlLoopNotificationType>, JsonDeserializer<ControlLoopNotificationType> { + @Override + public JsonElement serialize(ControlLoopNotificationType src, Type typeOfSrc, + JsonSerializationContext context) { + return new JsonPrimitive(src.toString()); + } + + @Override + public ControlLoopNotificationType deserialize(JsonElement json, Type typeOfT, + JsonDeserializationContext context) { + return ControlLoopNotificationType.toType(json.getAsString()); + } + } + + public static class TargetTypeAdapter + implements JsonSerializer<ControlLoopTargetType>, JsonDeserializer<ControlLoopTargetType> { + @Override + public JsonElement serialize(ControlLoopTargetType src, Type typeOfSrc, JsonSerializationContext context) { + return new JsonPrimitive(src.toString()); + } + + @Override + public ControlLoopTargetType deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { + return ControlLoopTargetType.toType(json.getAsString()); + } + } + + public static class GsonUtcAdapter implements JsonSerializer<ZonedDateTime>, JsonDeserializer<ZonedDateTime> { + private static final Logger logger = LoggerFactory.getLogger(GsonUtcAdapter.class); + public static final DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSSxxx"); + + @Override + public ZonedDateTime deserialize(JsonElement element, Type type, JsonDeserializationContext context) { + try { + return ZonedDateTime.parse(element.getAsString(), format); + } catch (Exception e) { + logger.error(e.getMessage(), e); + } + return null; + } + + @Override + public JsonElement serialize(ZonedDateTime datetime, Type type, JsonSerializationContext context) { + return new JsonPrimitive(datetime.format(format)); + } + } + + public static class GsonInstantAdapter implements JsonSerializer<Instant>, JsonDeserializer<Instant> { + + @Override + public Instant deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { + return Instant.ofEpochMilli(json.getAsLong()); + } + + @Override + public JsonElement serialize(Instant src, Type typeOfSrc, JsonSerializationContext context) { + return new JsonPrimitive(src.toEpochMilli()); + } + + } + +} diff --git a/models-interactions/model-impl/events/src/main/resources/definitions.yaml b/models-interactions/model-impl/events/src/main/resources/definitions.yaml new file mode 100644 index 000000000..57b8c1f2e --- /dev/null +++ b/models-interactions/model-impl/events/src/main/resources/definitions.yaml @@ -0,0 +1,128 @@ +# Copyright 2018 AT&T Intellectual Property. All rights reserved +# Modifications Copyright (C) 2019 Nordix Foundation. +# +# 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. +AAI: + type: object + properties: + AICVServerSelfLink: + type: string + VNF_NAME: + type: string + AICVMID: + type: string + AICTenantID: + type: string + LOC_ID: + type: string + in_maint: + type: boolean + AICIdentity: + type: string + Prov_status: + type: string + OAM_IPV4: + type: string + is_closed_loop_disabled: + type: boolean + VM_NAME: + type: string + OAM_IPV6: + type: string + required: + - AICVServerSelfLink + - AICIdentity + - is_closed_loop_disabled +ControlLoop: + type: object + description: Common fields for control loop events and notifications + properties: + closedLoopControlName: + type: string + description: A UNIQUE string identifying the Closed Loop ID this event is for. There are no semantics behind this string. + serviceInstance: + $ref: '../../../../sdc/src/main/resources/definitions.yaml#/serviceInstance' + resourceInstance: + $ref: '../../../../sdc/src/main/resources/definitions.yaml#/resourceInstance' + requestID: + type: string + description: This is required via ONAP Platform Logging Requirements. + pattern: /[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89aAbB][a-f0-9]{3}-[a-f0-9]{12}/ + triggerID: + type: string + description: ID that maps back to Highland Park. Concatenation between eventID and firstEPOCH. + triggerSourceName: + type: string + description: pulled from eventSourceName of trigger H.P. alarm. The contents of this field should also be contained in the AAI Json sub-tag (see below). + closedLoopAlarmStart: + type: string + description: firstEpoch. UTC Timestamp when this event was detected by DCAE. Conform to ONAP Logging requirements. + closedLoopAlarmEnd: + type: string + description: lastEpoch. UTC Timestamp when this event was detected as cleared by DCAE. Conform to ONAP Logging requirements. + closedLoopEventClient: + type: string + description: Open DCAE sub-system that detected the event and published this event message. + target: + type: string + description: The target entity that is being administered. This could be VM_NAME, VNF_NAME, etc. This should map to a field name in the AAI sub-tag shown below. + AAI: + $ref: '#/AAI' + from: + type: string + policyScope: + type: string + policyName: + type: string + policyVersion: + type: string + required: + - closedLoopControlName + - requestID + - triggerID + - triggerSourceName + - closedLoopAlarmStart + - closedLoopEventClient + - target + - AAI + - from + - policyScope + - policyName + - policyVersion +Event: + allOf: + - $ref: '#/ControlLoop' + - properties: + closedLoopEventStatus: + type: string + description: The status for the event within Open DCAE. A value of “ONSET” indicates the event has been encountered. “ABATED” indicates the event has been abated. + valid_values: + - ONSET + - ABATEMENT + - required: + - closedLoopEventStatus +Notification: + - $ref: '#/ControlLoop' + - properties: + notification: + type: string + notificationTime: + type: string + message: + type: string + OPS_CL_timer: + type: int + - required: + - notification + - notificationTime + - OPS_CL_timer diff --git a/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/ControlLoopEventStatusTest.java b/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/ControlLoopEventStatusTest.java new file mode 100644 index 000000000..f890cfce8 --- /dev/null +++ b/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/ControlLoopEventStatusTest.java @@ -0,0 +1,42 @@ +/*- + * ============LICENSE_START======================================================= + * controlloop + * ================================================================================ + * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.controlloop; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; + +import org.junit.Test; + +public class ControlLoopEventStatusTest { + + @Test + public void test() { + ControlLoopEventStatus status = ControlLoopEventStatus.ABATED; + assertEquals(ControlLoopEventStatus.ABATED, ControlLoopEventStatus.toStatus(status.toString())); + assertNotEquals(ControlLoopEventStatus.ONSET, ControlLoopEventStatus.toStatus(status.toString())); + + status = ControlLoopEventStatus.ONSET; + assertEquals(ControlLoopEventStatus.ONSET, ControlLoopEventStatus.toStatus(status.toString())); + assertNotEquals(ControlLoopEventStatus.ABATED, ControlLoopEventStatus.toStatus(status.toString())); + assertEquals(ControlLoopEventStatus.ABATED, ControlLoopEventStatus.toStatus("abatement")); + } +} diff --git a/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/ControlLoopEventTest.java b/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/ControlLoopEventTest.java new file mode 100644 index 000000000..feaf22ee5 --- /dev/null +++ b/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/ControlLoopEventTest.java @@ -0,0 +1,97 @@ +/*- + * ============LICENSE_START======================================================= + * controlloop + * ================================================================================ + * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.controlloop; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.UUID; +import org.junit.Test; + +public class ControlLoopEventTest { + + private class TestControlLoopEvent extends ControlLoopEvent { + private static final long serialVersionUID = 1L; + + public TestControlLoopEvent() { + super(); + } + + public TestControlLoopEvent(ControlLoopEvent event) { + super(event); + } + } + + @Test + public void test() { + ControlLoopEvent event = new TestControlLoopEvent(); + + assertEquals("1.0.2", event.getVersion()); + + event = new TestControlLoopEvent(null); + assertEquals("1.0.2", event.getVersion()); + + event.setClosedLoopControlName("name"); + assertEquals("name", event.getClosedLoopControlName()); + + event.setClosedLoopEventClient("client"); + assertEquals("client", event.getClosedLoopEventClient()); + + event.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET); + assertEquals(ControlLoopEventStatus.ONSET, event.getClosedLoopEventStatus()); + + event.setFrom("from"); + assertEquals("from", event.getFrom()); + + event.setPayload("payload"); + assertEquals("payload", event.getPayload()); + + event.setPolicyName("policyname"); + assertEquals("policyname", event.getPolicyName()); + + event.setPolicyScope("scope"); + assertEquals("scope", event.getPolicyScope()); + + event.setPolicyVersion("1"); + assertEquals("1", event.getPolicyVersion()); + + UUID id = UUID.randomUUID(); + event.setRequestId(id); + assertEquals(id, event.getRequestId()); + + event.setTarget("target"); + assertEquals("target", event.getTarget()); + + event.setTargetType(ControlLoopTargetType.VF); + assertEquals(ControlLoopTargetType.VF, event.getTargetType()); + + event.setVersion("foo"); + assertEquals("foo", event.getVersion()); + + ControlLoopEvent event2 = new TestControlLoopEvent(event); + assertTrue(event2.isEventStatusValid()); + + event2.setClosedLoopEventStatus(null); + assertFalse(event2.isEventStatusValid()); + } +} diff --git a/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/ControlLoopNotificationTest.java b/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/ControlLoopNotificationTest.java new file mode 100644 index 000000000..0c1070e44 --- /dev/null +++ b/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/ControlLoopNotificationTest.java @@ -0,0 +1,118 @@ +/*- + * ============LICENSE_START======================================================= + * controlloop + * ================================================================================ + * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.controlloop; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.time.ZoneOffset; +import java.time.ZonedDateTime; +import java.util.Collections; +import java.util.UUID; +import org.junit.Test; +import org.onap.policy.controlloop.util.Serialization; + +public class ControlLoopNotificationTest { + + private class TestControlLoopNotification extends ControlLoopNotification { + private static final long serialVersionUID = 1L; + + public TestControlLoopNotification() { + super(); + } + + public TestControlLoopNotification(ControlLoopEvent event) { + super(event); + } + } + + @Test + public void test() { + ControlLoopNotification notification = new TestControlLoopNotification(); + + assertEquals("1.0.2", notification.getVersion()); + + notification.setClosedLoopControlName("name"); + assertEquals("name", notification.getClosedLoopControlName()); + + notification.setClosedLoopEventClient("client"); + assertEquals("client", notification.getClosedLoopEventClient()); + + notification.setFrom("from"); + assertEquals("from", notification.getFrom()); + + notification.setHistory(Collections.emptyList()); + assertTrue(notification.getHistory().size() == 0); + + notification.setMessage("message"); + assertEquals("message", notification.getMessage()); + + notification.setNotification(ControlLoopNotificationType.ACTIVE); + assertEquals(ControlLoopNotificationType.ACTIVE, notification.getNotification()); + + ZonedDateTime time = ZonedDateTime.now(ZoneOffset.UTC); + notification.setNotificationTime(time); + assertEquals(time, notification.getNotificationTime()); + + notification.setOpsClTimer(Integer.valueOf(1000)); + assertEquals(Integer.valueOf(1000), notification.getOpsClTimer()); + + notification.setPolicyName("name"); + assertEquals("name", notification.getPolicyName()); + + notification.setPolicyScope("scope"); + assertEquals("scope", notification.getPolicyScope()); + + notification.setPolicyVersion("1"); + assertEquals("1", notification.getPolicyVersion()); + + UUID id = UUID.randomUUID(); + notification.setRequestId(id); + assertEquals(id, notification.getRequestId()); + + notification.setTarget("target"); + assertEquals("target", notification.getTarget()); + + notification.setTargetType(ControlLoopTargetType.VFC); + assertEquals(ControlLoopTargetType.VFC, notification.getTargetType()); + + VirtualControlLoopEvent event = new VirtualControlLoopEvent(); + event.setClosedLoopControlName("controlloop"); + + TestControlLoopNotification notification2 = new TestControlLoopNotification(event); + assertEquals("controlloop", notification2.getClosedLoopControlName()); + + notification2.setVersion("1"); + assertEquals("1", notification2.getVersion()); + + String json = Serialization.gsonPretty.toJson(notification); + + TestControlLoopNotification notification3 = Serialization.gson.fromJson(json, + TestControlLoopNotification.class); + + // + // There is no equals for the class - chose not to create one + // + assertEquals(notification.getRequestId(), notification3.getRequestId()); + + } +} diff --git a/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/ControlLoopNotificationTypeTest.java b/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/ControlLoopNotificationTypeTest.java new file mode 100644 index 000000000..a8330ba2e --- /dev/null +++ b/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/ControlLoopNotificationTypeTest.java @@ -0,0 +1,50 @@ +/*- + * ============LICENSE_START======================================================= + * controlloop + * ================================================================================ + * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.controlloop; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import org.junit.Test; + +public class ControlLoopNotificationTypeTest { + + @Test + public void test() { + + assertEquals(ControlLoopNotificationType.ACTIVE, ControlLoopNotificationType.toType("ACTIVE")); + assertEquals(ControlLoopNotificationType.REJECTED, ControlLoopNotificationType.toType("REJECTED")); + assertEquals(ControlLoopNotificationType.OPERATION, ControlLoopNotificationType.toType("OPERATION")); + assertEquals(ControlLoopNotificationType.OPERATION_SUCCESS, + ControlLoopNotificationType.toType("OPERATION: SUCCESS")); + assertEquals(ControlLoopNotificationType.OPERATION_FAILURE, + ControlLoopNotificationType.toType("OPERATION: FAILURE")); + assertEquals(ControlLoopNotificationType.FINAL_FAILURE, + ControlLoopNotificationType.toType("FINAL: FAILURE")); + assertEquals(ControlLoopNotificationType.FINAL_SUCCESS, + ControlLoopNotificationType.toType("FINAL: SUCCESS")); + assertEquals(ControlLoopNotificationType.FINAL_OPENLOOP, + ControlLoopNotificationType.toType("FINAL: OPENLOOP")); + + assertNull(ControlLoopNotificationType.toType("foo")); + } +} diff --git a/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/ControlLoopOperationTest.java b/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/ControlLoopOperationTest.java new file mode 100644 index 000000000..eb1a351d1 --- /dev/null +++ b/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/ControlLoopOperationTest.java @@ -0,0 +1,90 @@ +/*- + * ============LICENSE_START======================================================= + * controlloop + * ================================================================================ + * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.controlloop; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.time.Instant; +import org.junit.Test; + +public class ControlLoopOperationTest { + + @Test + public void test() { + ControlLoopOperation operation = new ControlLoopOperation(); + + assertEquals(operation, operation); + assertNotEquals(operation, new String()); + assertNotEquals(operation, null); + + assertTrue(operation.hashCode() != 0); + assertTrue(operation.toString().startsWith("ControlLoopOperation")); + + assertNotNull(operation); + + operation.setActor("actor"); + assertEquals("actor", operation.getActor()); + + operation.setOperation("operation"); + assertEquals("operation", operation.getOperation()); + + Instant now = Instant.now(); + operation.setStart(now); + assertEquals(now, operation.getStart()); + operation.setEnd(now); + assertEquals(now, operation.getEnd()); + + operation.setMessage("message"); + assertEquals("message", operation.getMessage()); + + operation.setOutcome("outcome"); + assertEquals("outcome", operation.getOutcome()); + + operation.setSubRequestId("1"); + assertEquals("1", operation.getSubRequestId()); + + operation.setTarget("target"); + assertEquals("target", operation.getTarget()); + + assertTrue(operation.hashCode() != 0); + + ControlLoopOperation operation2 = new ControlLoopOperation(operation); + assertEquals(now, operation2.getEnd()); + + assertEquals(operation, operation2); + + operation2.setActor("foo"); + assertNotEquals(operation, operation2); + + operation = new ControlLoopOperation(null); + assertNotNull(operation.getStart()); + + assertNotEquals(operation, operation2); + + assertTrue(operation.toMessage().startsWith("actor=")); + assertTrue(operation.toHistory().startsWith("actor=")); + + } +} diff --git a/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/ControlLoopOperationWrapperTest.java b/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/ControlLoopOperationWrapperTest.java new file mode 100644 index 000000000..46fd9de96 --- /dev/null +++ b/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/ControlLoopOperationWrapperTest.java @@ -0,0 +1,51 @@ +/*- + * ============LICENSE_START======================================================= + * controlloop + * ================================================================================ + * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.controlloop; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.util.UUID; +import org.junit.Test; + +public class ControlLoopOperationWrapperTest { + + @Test + public void test() { + ControlLoopOperationWrapper wrapper = new ControlLoopOperationWrapper(); + + assertNotNull(wrapper); + + ControlLoopOperation operation = new ControlLoopOperation(); + wrapper.setOperation(operation); + UUID id = UUID.randomUUID(); + wrapper.setRequestId(id); + + ControlLoopOperationWrapper wrapper2 = new ControlLoopOperationWrapper(wrapper.getRequestId(), + wrapper.getOperation()); + + assertEquals(operation, wrapper2.getOperation()); + assertEquals(id, wrapper2.getRequestId()); + + + } +} diff --git a/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/ControlLoopTargetTypeTest.java b/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/ControlLoopTargetTypeTest.java new file mode 100644 index 000000000..d1412fe49 --- /dev/null +++ b/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/ControlLoopTargetTypeTest.java @@ -0,0 +1,40 @@ +/*- + * ============LICENSE_START======================================================= + * controlloop + * ================================================================================ + * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.controlloop; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import org.junit.Test; + +public class ControlLoopTargetTypeTest { + + @Test + public void test() { + assertEquals(ControlLoopTargetType.VM, ControlLoopTargetType.toType("VM")); + assertEquals(ControlLoopTargetType.VF, ControlLoopTargetType.toType("VF")); + assertEquals(ControlLoopTargetType.VFC, ControlLoopTargetType.toType("VFC")); + assertEquals(ControlLoopTargetType.VNF, ControlLoopTargetType.toType("VNF")); + + assertNull(ControlLoopTargetType.toType("foo")); + } +} diff --git a/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/PhysicalControlLoopEventTest.java b/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/PhysicalControlLoopEventTest.java new file mode 100644 index 000000000..80f043e6b --- /dev/null +++ b/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/PhysicalControlLoopEventTest.java @@ -0,0 +1,38 @@ +/*- + * ============LICENSE_START======================================================= + * controlloop + * ================================================================================ + * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.controlloop; + +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; + +public class PhysicalControlLoopEventTest { + + @Test + public void test() { + PhysicalControlLoopEvent event = new PhysicalControlLoopEvent(); + assertNotNull(event); + + PhysicalControlLoopEvent event2 = new PhysicalControlLoopEvent(event); + assertNotNull(event2); + } +} diff --git a/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/PhysicalControlLoopNotificationTest.java b/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/PhysicalControlLoopNotificationTest.java new file mode 100644 index 000000000..f52bbc9bf --- /dev/null +++ b/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/PhysicalControlLoopNotificationTest.java @@ -0,0 +1,39 @@ +/*- + * ============LICENSE_START======================================================= + * controlloop + * ================================================================================ + * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.controlloop; + +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; + +public class PhysicalControlLoopNotificationTest { + + @Test + public void test() { + PhysicalControlLoopNotification notification = new PhysicalControlLoopNotification(); + assertNotNull(notification); + + PhysicalControlLoopNotification notification2 = new PhysicalControlLoopNotification( + new PhysicalControlLoopEvent()); + assertNotNull(notification2); + } +} diff --git a/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/VirtualControlLoopEventTest.java b/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/VirtualControlLoopEventTest.java new file mode 100644 index 000000000..2acd3038c --- /dev/null +++ b/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/VirtualControlLoopEventTest.java @@ -0,0 +1,50 @@ +/*- + * ============LICENSE_START======================================================= + * controlloop + * ================================================================================ + * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.controlloop; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import java.time.Instant; +import org.junit.Test; + +public class VirtualControlLoopEventTest { + + @Test + public void test() { + VirtualControlLoopEvent event = new VirtualControlLoopEvent(); + + assertNotNull(event); + assertNotNull(event.getAai()); + + Instant now = Instant.now(); + event.setClosedLoopAlarmStart(now); + event.setClosedLoopAlarmEnd(now); + + VirtualControlLoopEvent event2 = new VirtualControlLoopEvent(event); + assertEquals(now, event2.getClosedLoopAlarmStart()); + + event = new VirtualControlLoopEvent(null); + assertNull(event.getClosedLoopAlarmStart()); + } +} diff --git a/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/VirtualControlLoopNotificationTest.java b/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/VirtualControlLoopNotificationTest.java new file mode 100644 index 000000000..2ab622230 --- /dev/null +++ b/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/VirtualControlLoopNotificationTest.java @@ -0,0 +1,59 @@ +/*- + * ============LICENSE_START======================================================= + * controlloop + * ================================================================================ + * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.controlloop; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.time.Instant; +import java.util.Collections; +import org.junit.Test; + +public class VirtualControlLoopNotificationTest { + + @Test + public void test() { + VirtualControlLoopNotification notification = new VirtualControlLoopNotification(); + assertNotNull(notification); + + notification.setAai(Collections.emptyMap()); + assertTrue(notification.getAai().isEmpty()); + + Instant now = Instant.now(); + notification.setClosedLoopAlarmStart(now); + + notification.setClosedLoopAlarmEnd(now); + + VirtualControlLoopEvent event = new VirtualControlLoopEvent(); + + Instant later = Instant.now(); + event.setAai(Collections.emptyMap()); + event.setClosedLoopAlarmStart(later); + event.setClosedLoopAlarmEnd(later); + + notification = new VirtualControlLoopNotification(event); + assertEquals(later, notification.getClosedLoopAlarmStart()); + assertEquals(later, notification.getClosedLoopAlarmEnd()); + + } +} diff --git a/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/params/ControlLoopParamsTest.java b/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/params/ControlLoopParamsTest.java new file mode 100644 index 000000000..bf23e5706 --- /dev/null +++ b/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/params/ControlLoopParamsTest.java @@ -0,0 +1,51 @@ +/*- + * ============LICENSE_START======================================================= + * controlloop + * ================================================================================ + * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.controlloop.params; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +public class ControlLoopParamsTest { + + @Test + public void test() { + ControlLoopParams params = new ControlLoopParams(); + assertNotNull(params); + + params.setClosedLoopControlName("name"); + params.setControlLoopYaml("yaml"); + params.setPolicyName("name"); + params.setPolicyScope("scope"); + params.setPolicyVersion("1"); + + ControlLoopParams params2 = new ControlLoopParams(params); + + assertTrue(params2.getClosedLoopControlName().equals("name")); + assertTrue(params2.getControlLoopYaml().equals("yaml")); + assertTrue(params2.getPolicyName().equals("name")); + assertTrue(params2.getPolicyScope().equals("scope")); + assertTrue(params2.getPolicyVersion().equals("1")); + + } +} diff --git a/models-interactions/model-impl/pom.xml b/models-interactions/model-impl/pom.xml new file mode 100644 index 000000000..b4c0c4884 --- /dev/null +++ b/models-interactions/model-impl/pom.xml @@ -0,0 +1,51 @@ +<!-- + ============LICENSE_START======================================================= + controlloop-model-impl + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + Modifications Copyright (C) 2019 Nordix Foundation + ================================================================================ + 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========================================================= + --> + + +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <packaging>pom</packaging> + + <parent> + <groupId>org.onap.policy.models</groupId> + <artifactId>policy-models-interactions</artifactId> + <version>2.0.0-SNAPSHOT</version> + </parent> + + <groupId>org.onap.policy.models.policy-models-interactions.model-impl</groupId> + <artifactId>model-impl</artifactId> + + <modules> + <module>aai</module> + <module>appc</module> + <module>appclcm</module> + <module>sdnr</module> + <module>events</module> + <module>so</module> + <module>rest</module> + <module>sdc</module> + <module>trafficgenerator</module> + <module>vfc</module> + <module>sdnc</module> + </modules> + + +</project> diff --git a/models-interactions/model-impl/rest/pom.xml b/models-interactions/model-impl/rest/pom.xml new file mode 100644 index 000000000..51ab5807d --- /dev/null +++ b/models-interactions/model-impl/rest/pom.xml @@ -0,0 +1,92 @@ +<!-- + ============LICENSE_START======================================================= + rest + ================================================================================ + Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + Modifications Copyright (C) 2019 Nordix Foundation. + ================================================================================ + 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========================================================= + --> + + +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.onap.policy.models.policy-models-interactions.model-impl</groupId> + <artifactId>model-impl</artifactId> + <version>2.0.0-SNAPSHOT</version> + </parent> + + <artifactId>rest</artifactId> + + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>com.google.code.gson</groupId> + <artifactId>gson</artifactId> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.apache.httpcomponents</groupId> + <artifactId>httpclient</artifactId> + <scope>provided</scope> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <artifactId>maven-checkstyle-plugin</artifactId> + <executions> + <execution> + <id>onap-java-style</id> + <goals> + <goal>check</goal> + </goals> + <phase>process-sources</phase> + <configuration> + <!-- Use Google Java Style Guide: + https://github.com/checkstyle/checkstyle/blob/master/src/main/resources/google_checks.xml + with minor changes --> + <configLocation>onap-checkstyle/onap-java-style.xml</configLocation> + <!-- <sourceDirectory> is needed so that checkstyle ignores the generated sources directory --> + <sourceDirectory>${project.build.sourceDirectory}</sourceDirectory> + <includeResources>true</includeResources> + <includeTestSourceDirectory>true</includeTestSourceDirectory> + <includeTestResources>true</includeTestResources> + <excludes> + </excludes> + <consoleOutput>true</consoleOutput> + <failsOnViolation>true</failsOnViolation> + <violationSeverity>warning</violationSeverity> + </configuration> + </execution> + </executions> + <dependencies> + <dependency> + <groupId>org.onap.oparent</groupId> + <artifactId>checkstyle</artifactId> + <version>${oparent.version}</version> + <scope>compile</scope> + </dependency> + </dependencies> + </plugin> + </plugins> + </build> +</project> diff --git a/models-interactions/model-impl/rest/src/main/java/org/onap/policy/rest/HttpDeleteWithBody.java b/models-interactions/model-impl/rest/src/main/java/org/onap/policy/rest/HttpDeleteWithBody.java new file mode 100644 index 000000000..b99f7283f --- /dev/null +++ b/models-interactions/model-impl/rest/src/main/java/org/onap/policy/rest/HttpDeleteWithBody.java @@ -0,0 +1,54 @@ +/* + * ============LICENSE_START======================================================= + * rest + * ================================================================================ + * Copyright (C) 2018 Amdocs. All rights reserved. + * Modifications Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.rest; + +import java.net.URI; +import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; + +/** + * Allows for HTTP DELETE requests to contain a body, which the HttpDelete + * class does not support. + */ +public class HttpDeleteWithBody extends HttpEntityEnclosingRequestBase { + public static final String METHOD_NAME = "DELETE"; + + public HttpDeleteWithBody(final String uri) { + super(); + setURI(URI.create(uri)); + } + + public HttpDeleteWithBody(final URI uri) { + super(); + setURI(uri); + } + + public HttpDeleteWithBody() { + super(); + } + + @Override + public String getMethod() { + return METHOD_NAME; + } + +} diff --git a/models-interactions/model-impl/rest/src/main/java/org/onap/policy/rest/RestManager.java b/models-interactions/model-impl/rest/src/main/java/org/onap/policy/rest/RestManager.java new file mode 100644 index 000000000..bbc30a715 --- /dev/null +++ b/models-interactions/model-impl/rest/src/main/java/org/onap/policy/rest/RestManager.java @@ -0,0 +1,193 @@ +/* + * ============LICENSE_START======================================================= + * rest + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.rest; + +import java.nio.charset.Charset; +import java.util.Map; +import java.util.Map.Entry; +import javax.xml.bind.DatatypeConverter; + +import org.apache.http.HttpHeaders; +import org.apache.http.HttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.client.methods.HttpRequestBase; +import org.apache.http.conn.ssl.NoopHostnameVerifier; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.http.util.EntityUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class RestManager { + + private static final Logger logger = LoggerFactory.getLogger(RestManager.class); + + public class Pair<A, B> { + public final A first; + public final B second; + + public Pair(A first, B second) { + this.first = first; + this.second = second; + } + } + + /** + * Perform REST Post. + * + * @param url the url + * @param username the user name + * @param password the password + * @param headers any headers + * @param contentType what the content type is + * @param body body to send + * @return the response status code and the body + */ + public Pair<Integer, String> post(String url, String username, String password, + Map<String, String> headers, String contentType, String body) { + HttpPost post = new HttpPost(url); + addHeaders(post, username, password, headers); + post.addHeader("Content-Type", contentType); + try { + StringEntity input = new StringEntity(body); + input.setContentType(contentType); + post.setEntity(input); + } catch (Exception e) { + logger.error("post threw: ", e); + return null; + } + return sendRequest(post); + } + + /** + * Do a REST get. + * + * @param url URL + * @param username user name + * @param password password + * @param headers any headers to add + * @return a Pair for the response status and the body + */ + public Pair<Integer, String> get(String url, String username, String password, + Map<String, String> headers) { + HttpGet get = new HttpGet(url); + addHeaders(get, username, password, headers); + return sendRequest(get); + } + + /** + * Perform REST Delete. + * + * @param url the url + * @param username the user name + * @param password the password + * @param headers any headers + * @param contentType what the content type is + * @param body body (optional) to send + * @return the response status code and the body + */ + public Pair<Integer, String> delete(String url, String username, String password, Map<String, String> headers, + String contentType, String body) { + HttpDeleteWithBody delete = new HttpDeleteWithBody(url); + addHeaders(delete, username, password, headers); + delete.addHeader("Content-Type", contentType); + if (body != null && !body.isEmpty()) { + try { + StringEntity input = new StringEntity(body); + input.setContentType(contentType); + delete.setEntity(input); + } catch (Exception e) { + logger.error("delete threw: ", e); + return null; + } + } + return sendRequest(delete); + } + + /** + * Send REST request. + * + * @param request http request to send + * @return the response status code and the body + */ + private Pair<Integer, String> sendRequest(HttpRequestBase request) { + if (logger.isDebugEnabled()) { + logger.debug("***** sendRequest to url {}:", request.getURI()); + } + + try (CloseableHttpClient client = + HttpClientBuilder + .create() + .setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE) + .build()) { + HttpResponse response = client.execute(request); + if (response != null) { + String returnBody = EntityUtils.toString(response.getEntity(), "UTF-8"); + logger.debug("HTTP Response Status Code: {}", + response.getStatusLine().getStatusCode()); + logger.debug("HTTP Response Body:"); + logger.debug(returnBody); + + return new Pair<>(response.getStatusLine().getStatusCode(), + returnBody); + } else { + logger.error("Response from {} is null", request.getURI()); + return null; + } + } catch (Exception e) { + logger.error("Request failed to {}", request.getURI(), e); + return null; + } + } + + /** + * Add header to the request. + * + * @param request http request to send + * @param username the user name + * @param password the password + * @param headers any headers + */ + private void addHeaders(HttpRequestBase request, String username, String password, Map<String, + String> headers) { + String authHeader = makeAuthHeader(username, password); + if (headers != null) { + for (Entry<String, String> entry : headers.entrySet()) { + request.addHeader(entry.getKey(), headers.get(entry.getKey())); + } + } + if (authHeader != null) { + request.setHeader(HttpHeaders.AUTHORIZATION, authHeader); + } + } + + private String makeAuthHeader(String username, String password) { + if (username == null || username.isEmpty()) { + return null; + } + + String auth = username + ":" + (password == null ? "" : password); + return "Basic " + DatatypeConverter.printBase64Binary(auth.getBytes(Charset.forName("ISO-8859-1"))); + } +} diff --git a/models-interactions/model-impl/rest/src/test/java/org/onap/policy/rest/GetTest.java b/models-interactions/model-impl/rest/src/test/java/org/onap/policy/rest/GetTest.java new file mode 100644 index 000000000..452c3fa7f --- /dev/null +++ b/models-interactions/model-impl/rest/src/test/java/org/onap/policy/rest/GetTest.java @@ -0,0 +1,67 @@ +/* + * ============LICENSE_START======================================================= + * rest + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.rest; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.onap.policy.rest.RestManager.Pair; + +public class GetTest { + + @Test(expected = NullPointerException.class) + public void testUrlNull() { + RestManager mgr = new RestManager(); + mgr.get(null, "user", null, null); + } + + @Test + public void testUsernameNull() { + RestManager mgr = new RestManager(); + + Pair<Integer, String> result = mgr.get("http://www.example.org", null, null, null); + assertEquals((Integer)200, result.first); + assertTrue(result.second != null); + assertTrue(result.second.length() > 0); + } + + @Test + public void testUsernameEmpty() { + RestManager mgr = new RestManager(); + + Pair<Integer, String> result = mgr.get("http://www.example.org", "", null, null); + assertEquals((Integer)200, result.first); + assertTrue(result.second != null); + assertTrue(result.second.length() > 0); + } + + @Test + public void testUrlExampleOrg() { + RestManager mgr = new RestManager(); + + Pair<Integer, String> result = mgr.get("http://www.example.org", "user", null, null); + assertEquals((Integer)200, result.first); + assertTrue(result.second != null); + assertTrue(result.second.length() > 0); + } +} diff --git a/models-interactions/model-impl/rest/src/test/java/org/onap/policy/rest/HttpDeleteWithBodyTest.java b/models-interactions/model-impl/rest/src/test/java/org/onap/policy/rest/HttpDeleteWithBodyTest.java new file mode 100644 index 000000000..2a114f590 --- /dev/null +++ b/models-interactions/model-impl/rest/src/test/java/org/onap/policy/rest/HttpDeleteWithBodyTest.java @@ -0,0 +1,37 @@ +/* + * ============LICENSE_START======================================================= + * rest + * ================================================================================ + * Copyright (C) 2018 Amdocs. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.rest; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +public class HttpDeleteWithBodyTest { + + @Test + public void getMethod() { + String url = "http://www.example.org"; + HttpDeleteWithBody deleteWithBody = new HttpDeleteWithBody(url); + assertEquals("DELETE", deleteWithBody.getMethod()); + assertEquals(url, deleteWithBody.getURI().toString()); + } +}
\ No newline at end of file diff --git a/models-interactions/model-impl/rest/src/test/java/org/onap/policy/rest/PairTest.java b/models-interactions/model-impl/rest/src/test/java/org/onap/policy/rest/PairTest.java new file mode 100644 index 000000000..2db9ebca0 --- /dev/null +++ b/models-interactions/model-impl/rest/src/test/java/org/onap/policy/rest/PairTest.java @@ -0,0 +1,43 @@ +/* + * ============LICENSE_START======================================================= + * rest + * ================================================================================ + * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.rest; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.policy.rest.RestManager.Pair; + +public class PairTest { + + @Test + public void testPair() { + RestManager mgr = new RestManager(); + + Pair<Integer, Integer> pii = mgr.new Pair<>(1, 2); + assertEquals((Integer) 1, pii.first); + assertEquals((Integer) 2, pii.second); + + Pair<Integer, String> pis = mgr.new Pair<>(1, "test"); + assertEquals((Integer) 1, pis.first); + assertEquals("test", pis.second); + } +} diff --git a/models-interactions/model-impl/rest/src/test/java/org/onap/policy/rest/PostTest.java b/models-interactions/model-impl/rest/src/test/java/org/onap/policy/rest/PostTest.java new file mode 100644 index 000000000..5169468a2 --- /dev/null +++ b/models-interactions/model-impl/rest/src/test/java/org/onap/policy/rest/PostTest.java @@ -0,0 +1,51 @@ +/* + * ============LICENSE_START======================================================= + * rest + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.rest; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.policy.rest.RestManager.Pair; + +public class PostTest { + + @Test + public void testUsernameNull() { + RestManager mgr = new RestManager(); + Pair<Integer, String> result = mgr.post("http://www.example.org", null, null, null, null, null); + assertEquals(null, result); + } + + @Test + public void testUsernameEmpty() { + RestManager mgr = new RestManager(); + Pair<Integer, String> result = mgr.post("http://www.example.org", "", null, null, null, null); + assertEquals(null, result); + } + + @Test + public void testBodyNull() { + RestManager mgr = new RestManager(); + Pair<Integer, String> result = mgr.post("http://www.example.org", "user", null, null, null, null); + assertEquals(null, result); + } +} diff --git a/models-interactions/model-impl/sdc/checkstyle-suppressions.xml b/models-interactions/model-impl/sdc/checkstyle-suppressions.xml new file mode 100644 index 000000000..fd73d24e3 --- /dev/null +++ b/models-interactions/model-impl/sdc/checkstyle-suppressions.xml @@ -0,0 +1,30 @@ +<?xml version="1.0"?> +<!-- + ============LICENSE_START======================================================= + Copyright (C) 2018 AT&T Technologies. 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. + + SPDX-License-Identifier: Apache-2.0 + ============LICENSE_END========================================================= +--> + +<!DOCTYPE suppressions PUBLIC + "-//Puppy Crawl//DTD Suppressions 1.0//EN" + "http://www.puppycrawl.com/dtds/suppressions_1_0.dtd"> + +<suppressions> + <suppress checks="AbbreviationAsWordInName" + files="ResourceInstance.java|ServiceInstance.java|Service.java" + lines="1-9999"/> +</suppressions> diff --git a/models-interactions/model-impl/sdc/pom.xml b/models-interactions/model-impl/sdc/pom.xml new file mode 100644 index 000000000..42588c341 --- /dev/null +++ b/models-interactions/model-impl/sdc/pom.xml @@ -0,0 +1,83 @@ +<!-- + ============LICENSE_START======================================================= + sdc + ================================================================================ + Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + Modifications Copyright (C) 2019 Nordix Foundation. + ================================================================================ + 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========================================================= + --> + + +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.onap.policy.models.policy-models-interactions.model-impl</groupId> + <artifactId>model-impl</artifactId> + <version>2.0.0-SNAPSHOT</version> + </parent> + + <artifactId>sdc</artifactId> + + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <artifactId>maven-checkstyle-plugin</artifactId> + <executions> + <execution> + <id>onap-java-style</id> + <goals> + <goal>check</goal> + </goals> + <phase>process-sources</phase> + <configuration> + <!-- Use Google Java Style Guide: + https://github.com/checkstyle/checkstyle/blob/master/src/main/resources/google_checks.xml + with minor changes --> + <configLocation>onap-checkstyle/onap-java-style.xml</configLocation> + <!-- <sourceDirectory> is needed so that checkstyle ignores the generated sources directory --> + <sourceDirectory>${project.build.sourceDirectory}</sourceDirectory> + <includeResources>true</includeResources> + <includeTestSourceDirectory>true</includeTestSourceDirectory> + <includeTestResources>true</includeTestResources> + <excludes> + </excludes> + <suppressionsLocation>${project.basedir}/checkstyle-suppressions.xml</suppressionsLocation> + <consoleOutput>true</consoleOutput> + <failsOnViolation>true</failsOnViolation> + <violationSeverity>warning</violationSeverity> + </configuration> + </execution> + </executions> + <dependencies> + <dependency> + <groupId>org.onap.oparent</groupId> + <artifactId>checkstyle</artifactId> + <version>${oparent.version}</version> + <scope>compile</scope> + </dependency> + </dependencies> + </plugin> + </plugins> + </build> +</project> diff --git a/models-interactions/model-impl/sdc/src/main/java/org/onap/policy/sdc/Resource.java b/models-interactions/model-impl/sdc/src/main/java/org/onap/policy/sdc/Resource.java new file mode 100644 index 000000000..9b73446b6 --- /dev/null +++ b/models-interactions/model-impl/sdc/src/main/java/org/onap/policy/sdc/Resource.java @@ -0,0 +1,189 @@ +/*- + * ============LICENSE_START======================================================= + * sdc + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.sdc; + +import java.io.Serializable; +import java.util.UUID; + +public class Resource implements Serializable { + + private static final long serialVersionUID = -913729158733348027L; + + private UUID resourceUuid; + private UUID resourceInvariantUuid; + private String resourceName; + private String resourceVersion; + private ResourceType resourceType; + + public Resource() { + //Empty Constructor + } + + /** + * Constructor. + * + * @param resource copy object + */ + public Resource(Resource resource) { + this.resourceUuid = resource.resourceUuid; + this.resourceInvariantUuid = resource.resourceInvariantUuid; + this.resourceName = resource.resourceName; + this.resourceVersion = resource.resourceVersion; + this.resourceType = resource.resourceType; + } + + public Resource(UUID uuid) { + this.resourceUuid = uuid; + } + + public Resource(String name, ResourceType type) { + this.resourceName = name; + this.resourceType = type; + } + + /** + * Constructor. + * + * @param uuid uuid + * @param invariantUuid invariant uuid + * @param name name + * @param version version + * @param type type + */ + public Resource(UUID uuid, UUID invariantUuid, String name, String version, ResourceType type) { + this.resourceUuid = uuid; + this.resourceInvariantUuid = invariantUuid; + this.resourceName = name; + this.resourceVersion = version; + this.resourceType = type; + } + + public UUID getResourceUuid() { + return resourceUuid; + } + + public void setResourceUuid(UUID resourceUuid) { + this.resourceUuid = resourceUuid; + } + + public UUID getResourceInvariantUuid() { + return resourceInvariantUuid; + } + + public void setResourceInvariantUuid(UUID resourceInvariantUuid) { + this.resourceInvariantUuid = resourceInvariantUuid; + } + + public String getResourceName() { + return resourceName; + } + + public void setResourceName(String resourceName) { + this.resourceName = resourceName; + } + + public String getResourceVersion() { + return resourceVersion; + } + + public void setResourceVersion(String resourceVersion) { + this.resourceVersion = resourceVersion; + } + + public ResourceType getResourceType() { + return resourceType; + } + + public void setResourceType(ResourceType resourceType) { + this.resourceType = resourceType; + } + + @Override + public String toString() { + return "Resource [resourceUuid=" + resourceUuid + ", resourceInvariantUuid=" + resourceInvariantUuid + + ", resourceName=" + resourceName + ", resourceVersion=" + resourceVersion + ", resourceType=" + + resourceType + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((resourceInvariantUuid == null) ? 0 : resourceInvariantUuid.hashCode()); + result = prime * result + ((resourceName == null) ? 0 : resourceName.hashCode()); + result = prime * result + ((resourceType == null) ? 0 : resourceType.hashCode()); + result = prime * result + ((resourceUuid == null) ? 0 : resourceUuid.hashCode()); + result = prime * result + ((resourceVersion == null) ? 0 : resourceVersion.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + Resource other = (Resource) obj; + if (resourceInvariantUuid == null) { + if (other.resourceInvariantUuid != null) { + return false; + } + } else if (!resourceInvariantUuid.equals(other.resourceInvariantUuid)) { + return false; + } + if (resourceName == null) { + if (other.resourceName != null) { + return false; + } + } else if (!resourceName.equals(other.resourceName)) { + return false; + } + if (resourceType == null) { + if (other.resourceType != null) { + return false; + } + } else if (!resourceType.equals(other.resourceType)) { + return false; + } + if (resourceUuid == null) { + if (other.resourceUuid != null) { + return false; + } + } else if (!resourceUuid.equals(other.resourceUuid)) { + return false; + } + if (resourceVersion == null) { + if (other.resourceVersion != null) { + return false; + } + } else if (!resourceVersion.equals(other.resourceVersion)) { + return false; + } + return true; + } + +} diff --git a/models-interactions/model-impl/sdc/src/main/java/org/onap/policy/sdc/ResourceInstance.java b/models-interactions/model-impl/sdc/src/main/java/org/onap/policy/sdc/ResourceInstance.java new file mode 100644 index 000000000..dce6ec0fa --- /dev/null +++ b/models-interactions/model-impl/sdc/src/main/java/org/onap/policy/sdc/ResourceInstance.java @@ -0,0 +1,179 @@ +/*- + * ============LICENSE_START======================================================= + * sdc + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.sdc; + +import java.io.Serializable; +import java.util.UUID; + +public class ResourceInstance implements Serializable { + private static final long serialVersionUID = -5506162340393802424L; + + private String resourceInstanceName; + private String resourceName; + private UUID resourceInvariantUuid; + private String resourceVersion; + private ResourceType resourceType; + private UUID resourceUuid; + + public ResourceInstance() { + //Empty Constructor + } + + /** + * Constructor. + * + * @param instance copy object + */ + public ResourceInstance(ResourceInstance instance) { + if (instance == null) { + return; + } + this.resourceInstanceName = instance.resourceInstanceName; + this.resourceName = instance.resourceName; + this.resourceInvariantUuid = instance.resourceInvariantUuid; + this.resourceVersion = instance.resourceVersion; + this.resourceType = instance.resourceType; + this.resourceUuid = instance.resourceUuid; + } + + public String getResourceInstanceName() { + return resourceInstanceName; + } + + public void setResourceInstanceName(String resourceInstanceName) { + this.resourceInstanceName = resourceInstanceName; + } + + public String getResourceName() { + return resourceName; + } + + public void setResourceName(String resourceName) { + this.resourceName = resourceName; + } + + public UUID getResourceInvariantUUID() { + return resourceInvariantUuid; + } + + public void setResourceInvariantUUID(UUID resourceInvariantUuid) { + this.resourceInvariantUuid = resourceInvariantUuid; + } + + public String getResourceVersion() { + return resourceVersion; + } + + public void setResourceVersion(String resourceVersion) { + this.resourceVersion = resourceVersion; + } + + public ResourceType getResourceType() { + return resourceType; + } + + public void setResourceType(ResourceType resourceType) { + this.resourceType = resourceType; + } + + public UUID getResourceUuid() { + return resourceUuid; + } + + public void setResourceUuid(UUID resourceUuid) { + this.resourceUuid = resourceUuid; + } + + @Override + public String toString() { + return "ResourceInstance [resourceInstanceName=" + resourceInstanceName + ", resourceName=" + resourceName + + ", resourceInvariantUuid=" + resourceInvariantUuid + ", resourceVersion=" + resourceVersion + + ", resourceType=" + resourceType + ", resourceUuid=" + resourceUuid + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((resourceInstanceName == null) ? 0 : resourceInstanceName.hashCode()); + result = prime * result + ((resourceInvariantUuid == null) ? 0 : resourceInvariantUuid.hashCode()); + result = prime * result + ((resourceName == null) ? 0 : resourceName.hashCode()); + result = prime * result + ((resourceType == null) ? 0 : resourceType.hashCode()); + result = prime * result + ((resourceUuid == null) ? 0 : resourceUuid.hashCode()); + result = prime * result + ((resourceVersion == null) ? 0 : resourceVersion.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + ResourceInstance other = (ResourceInstance) obj; + if (resourceInstanceName == null) { + if (other.resourceInstanceName != null) { + return false; + } + } else if (!resourceInstanceName.equals(other.resourceInstanceName)) { + return false; + } + if (resourceInvariantUuid == null) { + if (other.resourceInvariantUuid != null) { + return false; + } + } else if (!resourceInvariantUuid.equals(other.resourceInvariantUuid)) { + return false; + } + if (resourceName == null) { + if (other.resourceName != null) { + return false; + } + } else if (!resourceName.equals(other.resourceName)) { + return false; + } + if (resourceType != other.resourceType) { + return false; + } + if (resourceUuid == null) { + if (other.resourceUuid != null) { + return false; + } + } else if (!resourceUuid.equals(other.resourceUuid)) { + return false; + } + if (resourceVersion == null) { + if (other.resourceVersion != null) { + return false; + } + } else if (!resourceVersion.equals(other.resourceVersion)) { + return false; + } + return true; + } + +} diff --git a/models-interactions/model-impl/sdc/src/main/java/org/onap/policy/sdc/ResourceType.java b/models-interactions/model-impl/sdc/src/main/java/org/onap/policy/sdc/ResourceType.java new file mode 100644 index 000000000..e90ab6def --- /dev/null +++ b/models-interactions/model-impl/sdc/src/main/java/org/onap/policy/sdc/ResourceType.java @@ -0,0 +1,42 @@ +/*- + * ============LICENSE_START======================================================= + * sdc + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.sdc; + +public enum ResourceType { + VF("VF"), + VFC("VFC"), + VL("VL"), + CP("CP") + ; + + private String type; + + private ResourceType(String type) { + this.type = type; + } + + @Override + public String toString() { + return this.type; + } + +} diff --git a/models-interactions/model-impl/sdc/src/main/java/org/onap/policy/sdc/Service.java b/models-interactions/model-impl/sdc/src/main/java/org/onap/policy/sdc/Service.java new file mode 100644 index 000000000..f4f97c42e --- /dev/null +++ b/models-interactions/model-impl/sdc/src/main/java/org/onap/policy/sdc/Service.java @@ -0,0 +1,167 @@ +/*- + * ============LICENSE_START======================================================= + * sdc + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.sdc; + +import java.io.Serializable; +import java.util.UUID; + +public class Service implements Serializable { + + private static final long serialVersionUID = -1249276698549996806L; + + private UUID serviceUUID; + private UUID serviceInvariantUUID; + private String serviceName; + private String serviceVersion; + + public Service() { + //Empty Constructor + } + + public Service(UUID uuid) { + this.serviceUUID = uuid; + } + + public Service(String name) { + this.serviceName = name; + } + + /** + * Constructor. + * + * @param uuid service id + * @param invariantUUID service invariant id + * @param name name + * @param version version + */ + public Service(UUID uuid, UUID invariantUUID, String name, String version) { + this.serviceUUID = uuid; + this.serviceInvariantUUID = invariantUUID; + this.serviceName = name; + this.serviceVersion = version; + } + + /** + * Constructor. + * + * @param service copy object + */ + public Service(Service service) { + this.serviceUUID = service.serviceUUID; + this.serviceInvariantUUID = service.serviceInvariantUUID; + this.serviceName = service.serviceName; + this.serviceVersion = service.serviceVersion; + } + + public UUID getServiceUUID() { + return serviceUUID; + } + + public void setServiceUUID(UUID serviceUUID) { + this.serviceUUID = serviceUUID; + } + + public UUID getServiceInvariantUUID() { + return serviceInvariantUUID; + } + + public void setServiceInvariantUUID(UUID serviceInvariantUUID) { + this.serviceInvariantUUID = serviceInvariantUUID; + } + + public String getServiceName() { + return serviceName; + } + + public void setServiceName(String serviceName) { + this.serviceName = serviceName; + } + + public String getServiceVersion() { + return serviceVersion; + } + + public void setServiceVersion(String serviceVersion) { + this.serviceVersion = serviceVersion; + } + + @Override + public String toString() { + return "Service [serviceUUID=" + serviceUUID + ", serviceInvariantUUID=" + serviceInvariantUUID + + ", serviceName=" + serviceName + ", serviceVersion=" + serviceVersion + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((serviceInvariantUUID == null) ? 0 : serviceInvariantUUID.hashCode()); + result = prime * result + ((serviceName == null) ? 0 : serviceName.hashCode()); + result = prime * result + ((serviceUUID == null) ? 0 : serviceUUID.hashCode()); + result = prime * result + ((serviceVersion == null) ? 0 : serviceVersion.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + Service other = (Service) obj; + if (serviceInvariantUUID == null) { + if (other.serviceInvariantUUID != null) { + return false; + } + } else if (!serviceInvariantUUID.equals(other.serviceInvariantUUID)) { + return false; + } + if (serviceName == null) { + if (other.serviceName != null) { + return false; + } + } else if (!serviceName.equals(other.serviceName)) { + return false; + } + if (serviceUUID == null) { + if (other.serviceUUID != null) { + return false; + } + } else if (!serviceUUID.equals(other.serviceUUID)) { + return false; + } + if (serviceVersion == null) { + if (other.serviceVersion != null) { + return false; + } + } else if (!serviceVersion.equals(other.serviceVersion)) { + return false; + } + return true; + } + +} diff --git a/models-interactions/model-impl/sdc/src/main/java/org/onap/policy/sdc/ServiceInstance.java b/models-interactions/model-impl/sdc/src/main/java/org/onap/policy/sdc/ServiceInstance.java new file mode 100644 index 000000000..49f1b8572 --- /dev/null +++ b/models-interactions/model-impl/sdc/src/main/java/org/onap/policy/sdc/ServiceInstance.java @@ -0,0 +1,202 @@ +/*- + * ============LICENSE_START======================================================= + * sdc + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.sdc; + +import java.io.Serializable; +import java.util.UUID; + +public class ServiceInstance implements Serializable { + private static final long serialVersionUID = 6285260780966679625L; + + private UUID personaModelUUID; + private UUID serviceUUID; + private UUID serviceInstanceUUID; + private UUID widgetModelUUID; + private String widgetModelVersion; + private String serviceName; + private String serviceInstanceName; + + public ServiceInstance() { + //Empty Constructor + } + + /** + * Constructor. + * + * @param instance copy object + */ + public ServiceInstance(ServiceInstance instance) { + if (instance == null) { + return; + } + this.personaModelUUID = instance.personaModelUUID; + this.serviceUUID = instance.serviceUUID; + this.serviceInstanceUUID = instance.serviceInstanceUUID; + this.widgetModelUUID = instance.widgetModelUUID; + this.widgetModelVersion = instance.widgetModelVersion; + this.serviceName = instance.serviceName; + this.serviceInstanceName = instance.serviceInstanceName; + } + + public UUID getPersonaModelUUID() { + return personaModelUUID; + } + + public void setPersonaModelUUID(UUID personaModelUUID) { + this.personaModelUUID = personaModelUUID; + } + + public UUID getServiceUUID() { + return serviceUUID; + } + + public void setServiceUUID(UUID serviceUUID) { + this.serviceUUID = serviceUUID; + } + + public UUID getServiceInstanceUUID() { + return serviceInstanceUUID; + } + + public void setServiceInstanceUUID(UUID serviceInstanceUUID) { + this.serviceInstanceUUID = serviceInstanceUUID; + } + + public UUID getWidgetModelUUID() { + return widgetModelUUID; + } + + public void setWidgetModelUUID(UUID widgetModelUUID) { + this.widgetModelUUID = widgetModelUUID; + } + + public String getWidgetModelVersion() { + return widgetModelVersion; + } + + public void setWidgetModelVersion(String widgetModelVersion) { + this.widgetModelVersion = widgetModelVersion; + } + + public String getServiceName() { + return serviceName; + } + + public void setServiceName(String serviceName) { + this.serviceName = serviceName; + } + + public String getServiceInstanceName() { + return serviceInstanceName; + } + + public void setServiceInstanceName(String serviceInstanceName) { + this.serviceInstanceName = serviceInstanceName; + } + + @Override + public String toString() { + return "ServiceInstance [personaModelUUID=" + personaModelUUID + ", serviceUUID=" + serviceUUID + + ", serviceInstanceUUID=" + serviceInstanceUUID + ", widgetModelUUID=" + widgetModelUUID + + ", widgetModelVersion=" + widgetModelVersion + ", serviceName=" + serviceName + + ", serviceInstanceName=" + serviceInstanceName + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((personaModelUUID == null) ? 0 : personaModelUUID.hashCode()); + result = prime * result + ((serviceInstanceName == null) ? 0 : serviceInstanceName.hashCode()); + result = prime * result + ((serviceInstanceUUID == null) ? 0 : serviceInstanceUUID.hashCode()); + result = prime * result + ((serviceName == null) ? 0 : serviceName.hashCode()); + result = prime * result + ((serviceUUID == null) ? 0 : serviceUUID.hashCode()); + result = prime * result + ((widgetModelUUID == null) ? 0 : widgetModelUUID.hashCode()); + result = prime * result + ((widgetModelVersion == null) ? 0 : widgetModelVersion.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + ServiceInstance other = (ServiceInstance) obj; + if (personaModelUUID == null) { + if (other.personaModelUUID != null) { + return false; + } + } else if (!personaModelUUID.equals(other.personaModelUUID)) { + return false; + } + if (serviceInstanceName == null) { + if (other.serviceInstanceName != null) { + return false; + } + } else if (!serviceInstanceName.equals(other.serviceInstanceName)) { + return false; + } + if (serviceInstanceUUID == null) { + if (other.serviceInstanceUUID != null) { + return false; + } + } else if (!serviceInstanceUUID.equals(other.serviceInstanceUUID)) { + return false; + } + if (serviceName == null) { + if (other.serviceName != null) { + return false; + } + } else if (!serviceName.equals(other.serviceName)) { + return false; + } + if (serviceUUID == null) { + if (other.serviceUUID != null) { + return false; + } + } else if (!serviceUUID.equals(other.serviceUUID)) { + return false; + } + if (widgetModelUUID == null) { + if (other.widgetModelUUID != null) { + return false; + } + } else if (!widgetModelUUID.equals(other.widgetModelUUID)) { + return false; + } + if (widgetModelVersion == null) { + if (other.widgetModelVersion != null) { + return false; + } + } else if (!widgetModelVersion.equals(other.widgetModelVersion)) { + return false; + } + return true; + } + +} diff --git a/models-interactions/model-impl/sdc/src/main/resources/definitions.yaml b/models-interactions/model-impl/sdc/src/main/resources/definitions.yaml new file mode 100644 index 000000000..16fff309c --- /dev/null +++ b/models-interactions/model-impl/sdc/src/main/resources/definitions.yaml @@ -0,0 +1,90 @@ +# Copyright 2018 AT&T Intellectual Property. All rights reserved +# Modifications Copyright (C) 2019 Nordix Foundation. +# +# 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. +Service: + type: Object + properties: + serviceUUID: + type: string + pattern: "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$" + serviceInvariantUUID: + type: string + pattern: "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$" + serviceName: + type: string + serviceVersion: + type: string +Resource: + type: Object + properties: + resourceUUID: + type: string + pattern: "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$" + resourceInvariantUUID: + type: string + pattern: "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$" + resourceName: + type: string + resourceVersion: + type: string + resourceType: + type: string + valid_values: + - VF + - VFC + - CP + - VL +ServiceInstance: + type: Object + properties: + personaModelUUID: + type: string + pattern: "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$" + serviceUUID: + type: string + pattern: "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$" + serviceInstanceUUID: + type: string + pattern: "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$" + widgetModelUUID: + type: string + pattern: "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$" + widgetModelVersion: + type: string + serviceName: + type: string + serviceInstanceName: + type: string +ResourceInstance: + type: object + properties: + resourceInstanceName: + type: string + resourceName: + type: string + resourceInvariantUUID: + type: string + pattern: "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$" + resourceVersion: + type: string + resourceType: + type: string + valid_values: + - VF + - VFC + - CP + - VL + resourceUUID: + type: string + pattern: "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$" diff --git a/models-interactions/model-impl/sdc/src/test/java/org/onap/policy/sdc/ResourceInstanceTest.java b/models-interactions/model-impl/sdc/src/test/java/org/onap/policy/sdc/ResourceInstanceTest.java new file mode 100644 index 000000000..940963565 --- /dev/null +++ b/models-interactions/model-impl/sdc/src/test/java/org/onap/policy/sdc/ResourceInstanceTest.java @@ -0,0 +1,156 @@ +/*- + * ============LICENSE_START======================================================= + * sdc + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.sdc; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.util.UUID; + +import org.junit.Test; + +public class ResourceInstanceTest { + + @Test + public void testConstructors() { + ResourceInstance ri = new ResourceInstance(); + assertEquals(null, ri.getResourceInstanceName()); + assertEquals(null, ri.getResourceUuid()); + assertEquals(null, ri.getResourceInvariantUUID()); + assertEquals(null, ri.getResourceName()); + assertEquals(null, ri.getResourceType()); + assertEquals(null, ri.getResourceVersion()); + + ResourceInstance ri2 = new ResourceInstance((ResourceInstance) null); + assertEquals(null, ri2.getResourceInstanceName()); + assertEquals(null, ri2.getResourceUuid()); + assertEquals(null, ri2.getResourceInvariantUUID()); + assertEquals(null, ri2.getResourceName()); + assertEquals(null, ri2.getResourceType()); + assertEquals(null, ri2.getResourceVersion()); + + ri2 = new ResourceInstance(ri); + assertEquals(ri2.getResourceInstanceName(), ri.getResourceInstanceName()); + assertEquals(ri2.getResourceUuid(), ri.getResourceUuid()); + assertEquals(ri2.getResourceInvariantUUID(), ri.getResourceInvariantUUID()); + assertEquals(ri2.getResourceName(), ri.getResourceName()); + assertEquals(ri2.getResourceType(), ri.getResourceType()); + assertEquals(ri2.getResourceVersion(), ri.getResourceVersion()); + } + + @Test + public void testInstanceName() { + ResourceInstance ri = new ResourceInstance(); + String name = "nameTestInstance"; + ri.setResourceInstanceName(name);; + assertEquals(name, ri.getResourceInstanceName()); + } + + @Test + public void testUuid() { + ResourceInstance ri = new ResourceInstance(); + UUID uuid = UUID.randomUUID(); + ri.setResourceUuid(uuid); + assertEquals(uuid, ri.getResourceUuid()); + } + + @Test + public void testInvariantUuid() { + ResourceInstance ri = new ResourceInstance(); + UUID uuid = UUID.randomUUID(); + ri.setResourceInvariantUUID(uuid); + assertEquals(uuid, ri.getResourceInvariantUUID()); + } + + @Test + public void testName() { + ResourceInstance ri = new ResourceInstance(); + String name = "nameTest"; + ri.setResourceName(name); + assertEquals(name, ri.getResourceName()); + } + + @Test + public void testVersion() { + ResourceInstance ri = new ResourceInstance(); + String version = "versionTest"; + ri.setResourceVersion(version); + assertEquals(version, ri.getResourceVersion()); + } + + @Test + public void testType() { + ResourceInstance ri = new ResourceInstance(); + ri.setResourceType(ResourceType.CP); + assertEquals(ResourceType.CP, ri.getResourceType()); + } + + @Test + public void testEquals() { + ResourceInstance ri1 = new ResourceInstance(); + ResourceInstance ri2 = new ResourceInstance(ri1); + assertTrue(ri1.equals(ri2)); + assertTrue(ri2.equals(ri1)); + + ri1.setResourceInstanceName("instance"); + ri1.setResourceName("resource"); + ri1.setResourceInvariantUUID(UUID.randomUUID()); + ri1.setResourceInvariantUUID(UUID.randomUUID()); + ri1.setResourceVersion("0.0.0"); + ri1.setResourceType(ResourceType.VL); + ri2 = new ResourceInstance(ri1); + assertTrue(ri1.equals(ri2)); + assertTrue(ri2.equals(ri1)); + } + + @Test + public void testToString() { + ResourceInstance ri1 = new ResourceInstance(); + ResourceInstance ri2 = new ResourceInstance(ri1); + assertEquals(ri1.toString(), ri2.toString()); + + ri1.setResourceInstanceName("instance"); + ri1.setResourceName("resource"); + ri1.setResourceInvariantUUID(UUID.randomUUID()); + ri1.setResourceInvariantUUID(UUID.randomUUID()); + ri1.setResourceVersion("0.0.0"); + ri1.setResourceType(ResourceType.VL); + ri2 = new ResourceInstance(ri1); + assertEquals(ri1.toString(), ri2.toString()); + } + + @Test + public void testHashCode() { + ResourceInstance ri1 = new ResourceInstance(); + ResourceInstance ri2 = new ResourceInstance(ri1); + assertEquals(ri1.hashCode(), ri2.hashCode()); + + ri1.setResourceInstanceName("instance"); + ri1.setResourceName("resource"); + ri1.setResourceInvariantUUID(UUID.randomUUID()); + ri1.setResourceInvariantUUID(UUID.randomUUID()); + ri1.setResourceVersion("0.0.0"); + ri1.setResourceType(ResourceType.VL); + ri2 = new ResourceInstance(ri1); + assertEquals(ri1.hashCode(), ri2.hashCode()); + } +} diff --git a/models-interactions/model-impl/sdc/src/test/java/org/onap/policy/sdc/ResourceTest.java b/models-interactions/model-impl/sdc/src/test/java/org/onap/policy/sdc/ResourceTest.java new file mode 100644 index 000000000..60510a1d1 --- /dev/null +++ b/models-interactions/model-impl/sdc/src/test/java/org/onap/policy/sdc/ResourceTest.java @@ -0,0 +1,153 @@ +/*- + * ============LICENSE_START======================================================= + * sdc + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.sdc; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.util.UUID; + +import org.junit.Test; + +public class ResourceTest { + + @Test + public void testConstructors() { + Resource res = new Resource(); + assertEquals(null, res.getResourceUuid()); + assertEquals(null, res.getResourceInvariantUuid()); + assertEquals(null, res.getResourceName()); + assertEquals(null, res.getResourceType()); + assertEquals(null, res.getResourceVersion()); + + UUID uuid = UUID.randomUUID(); + res = new Resource(uuid); + assertEquals(uuid, res.getResourceUuid()); + assertEquals(null, res.getResourceInvariantUuid()); + assertEquals(null, res.getResourceName()); + assertEquals(null, res.getResourceType()); + assertEquals(null, res.getResourceVersion()); + + String name = "constTest"; + res = new Resource(name, ResourceType.CP); + assertEquals(null, res.getResourceUuid()); + assertEquals(name, res.getResourceName()); + assertEquals(ResourceType.CP, res.getResourceType()); + assertEquals(null, res.getResourceInvariantUuid()); + assertEquals(null, res.getResourceVersion()); + + uuid = UUID.randomUUID(); + UUID uuidInvariant = UUID.randomUUID(); + name = "constTestUUID"; + String version = "0.0.1"; + res = new Resource(uuid, uuidInvariant, name, version, ResourceType.VF); + assertEquals(uuid, res.getResourceUuid()); + assertEquals(uuidInvariant, res.getResourceInvariantUuid()); + assertEquals(name, res.getResourceName()); + assertEquals(ResourceType.VF, res.getResourceType()); + assertEquals(version, res.getResourceVersion()); + + Resource r2 = new Resource(res); + assertEquals(uuid, r2.getResourceUuid()); + assertEquals(uuidInvariant, r2.getResourceInvariantUuid()); + assertEquals(name, r2.getResourceName()); + assertEquals(ResourceType.VF, r2.getResourceType()); + assertEquals(version, r2.getResourceVersion()); + } + + @Test + public void testUuid() { + Resource res = new Resource(); + UUID uuid = UUID.randomUUID(); + res.setResourceUuid(uuid); + assertEquals(uuid, res.getResourceUuid()); + } + + @Test + public void testInvariantUuid() { + Resource res = new Resource(); + UUID uuid = UUID.randomUUID(); + res.setResourceInvariantUuid(uuid); + assertEquals(uuid, res.getResourceInvariantUuid()); + } + + @Test + public void testName() { + Resource res = new Resource(); + String name = "nameTest"; + res.setResourceName(name); + assertEquals(name, res.getResourceName()); + } + + @Test + public void testVersion() { + Resource res = new Resource(); + String version = "versionTest"; + res.setResourceVersion(version); + assertEquals(version, res.getResourceVersion()); + } + + @Test + public void testType() { + Resource res = new Resource(); + res.setResourceType(ResourceType.CP); + assertEquals(ResourceType.CP, res.getResourceType()); + } + + @Test + public void testEquals() { + Resource r1 = new Resource(); + Resource r2 = new Resource(r1); + assertTrue(r1.equals(r2)); + assertTrue(r2.equals(r1)); + + r1 = new Resource(UUID.randomUUID(), UUID.randomUUID(), "equalsTest", "1.1.1", + ResourceType.VFC); + r2 = new Resource(r1); + assertTrue(r1.equals(r2)); + assertTrue(r2.equals(r1)); + } + + @Test + public void testToString() { + Resource r1 = new Resource(); + Resource r2 = new Resource(r1); + assertEquals(r1.toString(), r2.toString()); + + r1 = new Resource(UUID.randomUUID(), UUID.randomUUID(), "equalsTest", "1.1.1", + ResourceType.VFC); + r2 = new Resource(r1); + assertEquals(r1.toString(), r2.toString()); + } + + @Test + public void testHashCode() { + Resource r1 = new Resource(); + Resource r2 = new Resource(r1); + assertEquals(r1.hashCode(), r2.hashCode()); + + r1 = new Resource(UUID.randomUUID(), UUID.randomUUID(), "equalsTest", "1.1.1", + ResourceType.VFC); + r2 = new Resource(r1); + assertEquals(r1.hashCode(), r2.hashCode()); + } +} diff --git a/models-interactions/model-impl/sdc/src/test/java/org/onap/policy/sdc/ServiceInstanceTest.java b/models-interactions/model-impl/sdc/src/test/java/org/onap/policy/sdc/ServiceInstanceTest.java new file mode 100644 index 000000000..ca2cb3d0e --- /dev/null +++ b/models-interactions/model-impl/sdc/src/test/java/org/onap/policy/sdc/ServiceInstanceTest.java @@ -0,0 +1,171 @@ +/*- + * ============LICENSE_START======================================================= + * sdc + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.sdc; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.util.UUID; + +import org.junit.Test; + +public class ServiceInstanceTest { + + @Test + public void testConstructors() { + ServiceInstance si = new ServiceInstance(); + assertEquals(null, si.getServiceInstanceName()); + assertEquals(null, si.getServiceUUID()); + assertEquals(null, si.getServiceInstanceUUID()); + assertEquals(null, si.getServiceName()); + assertEquals(null, si.getPersonaModelUUID()); + assertEquals(null, si.getWidgetModelUUID()); + assertEquals(null, si.getWidgetModelVersion()); + + ServiceInstance si2 = new ServiceInstance((ServiceInstance) null); + assertEquals(null, si2.getServiceInstanceName()); + assertEquals(null, si2.getServiceUUID()); + assertEquals(null, si2.getServiceInstanceUUID()); + assertEquals(null, si2.getServiceName()); + assertEquals(null, si2.getPersonaModelUUID()); + assertEquals(null, si2.getWidgetModelUUID()); + assertEquals(null, si2.getWidgetModelVersion()); + + si2 = new ServiceInstance(si); + assertEquals(si2.getServiceInstanceName(), si.getServiceInstanceName()); + assertEquals(si2.getServiceUUID(), si.getServiceUUID()); + assertEquals(si2.getServiceInstanceUUID(), si.getServiceInstanceUUID()); + assertEquals(si2.getServiceName(), si.getServiceName()); + assertEquals(si2.getPersonaModelUUID(), si.getPersonaModelUUID()); + assertEquals(si2.getWidgetModelUUID(), si.getWidgetModelUUID()); + assertEquals(si2.getWidgetModelVersion(), si.getWidgetModelVersion()); + } + + @Test + public void testInstanceName() { + ServiceInstance si = new ServiceInstance(); + String name = "nameTestInstance"; + si.setServiceInstanceName(name);; + assertEquals(name, si.getServiceInstanceName()); + } + + @Test + public void testUuid() { + ServiceInstance si = new ServiceInstance(); + UUID uuid = UUID.randomUUID(); + si.setServiceUUID(uuid); + assertEquals(uuid, si.getServiceUUID()); + } + + @Test + public void testInstanceUuid() { + ServiceInstance si = new ServiceInstance(); + UUID uuid = UUID.randomUUID(); + si.setServiceInstanceUUID(uuid); + assertEquals(uuid, si.getServiceInstanceUUID()); + } + + @Test + public void testName() { + ServiceInstance si = new ServiceInstance(); + String name = "nameTest"; + si.setServiceName(name); + assertEquals(name, si.getServiceName()); + } + + @Test + public void testPersonaModelUuid() { + ServiceInstance si = new ServiceInstance(); + UUID uuid = UUID.randomUUID(); + si.setPersonaModelUUID(uuid); + assertEquals(uuid, si.getPersonaModelUUID()); + } + + @Test + public void testWidgetModelUuid() { + ServiceInstance si = new ServiceInstance(); + UUID uuid = UUID.randomUUID(); + si.setWidgetModelUUID(uuid); + assertEquals(uuid, si.getWidgetModelUUID()); + } + + @Test + public void testWidgetModelVersion() { + ServiceInstance si = new ServiceInstance(); + String version = "2.2.2"; + si.setWidgetModelVersion(version);; + assertEquals(version, si.getWidgetModelVersion()); + } + + @Test + public void testEquals() { + ServiceInstance si1 = new ServiceInstance(); + ServiceInstance si2 = new ServiceInstance(si1); + assertTrue(si1.equals(si2)); + assertTrue(si2.equals(si1)); + + si1.setServiceInstanceName("instance"); + si1.setServiceName("service"); + si1.setServiceInstanceUUID(UUID.randomUUID()); + si1.setServiceUUID(UUID.randomUUID()); + si1.setPersonaModelUUID(UUID.randomUUID()); + si1.setWidgetModelUUID(UUID.randomUUID()); + si1.setWidgetModelVersion("3.3.3"); + si2 = new ServiceInstance(si1); + assertTrue(si1.equals(si2)); + assertTrue(si2.equals(si1)); + } + + @Test + public void testToString() { + ServiceInstance si1 = new ServiceInstance(); + ServiceInstance si2 = new ServiceInstance(si1); + assertEquals(si1.toString(), si2.toString()); + + si1.setServiceInstanceName("instance"); + si1.setServiceName("service"); + si1.setServiceInstanceUUID(UUID.randomUUID()); + si1.setServiceUUID(UUID.randomUUID()); + si1.setPersonaModelUUID(UUID.randomUUID()); + si1.setWidgetModelUUID(UUID.randomUUID()); + si1.setWidgetModelVersion("3.3.3"); + si2 = new ServiceInstance(si1); + assertEquals(si1.toString(), si2.toString()); + } + + @Test + public void testHashCode() { + ServiceInstance si1 = new ServiceInstance(); + ServiceInstance si2 = new ServiceInstance(si1); + assertEquals(si1.hashCode(), si2.hashCode()); + + si1.setServiceInstanceName("instance"); + si1.setServiceName("service"); + si1.setServiceInstanceUUID(UUID.randomUUID()); + si1.setServiceUUID(UUID.randomUUID()); + si1.setPersonaModelUUID(UUID.randomUUID()); + si1.setWidgetModelUUID(UUID.randomUUID()); + si1.setWidgetModelVersion("3.3.3"); + si2 = new ServiceInstance(si1); + assertEquals(si1.hashCode(), si2.hashCode()); + } +} diff --git a/models-interactions/model-impl/sdc/src/test/java/org/onap/policy/sdc/ServiceTest.java b/models-interactions/model-impl/sdc/src/test/java/org/onap/policy/sdc/ServiceTest.java new file mode 100644 index 000000000..3bf6a537e --- /dev/null +++ b/models-interactions/model-impl/sdc/src/test/java/org/onap/policy/sdc/ServiceTest.java @@ -0,0 +1,138 @@ +/*- + * ============LICENSE_START======================================================= + * sdc + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.sdc; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.util.UUID; + +import org.junit.Test; + +public class ServiceTest { + + @Test + public void testConstructors() { + Service svc = new Service(); + assertEquals(null, svc.getServiceUUID()); + assertEquals(null, svc.getServiceInvariantUUID()); + assertEquals(null, svc.getServiceName()); + assertEquals(null, svc.getServiceVersion()); + + UUID uuid = UUID.randomUUID(); + svc = new Service(uuid); + assertEquals(uuid, svc.getServiceUUID()); + assertEquals(null, svc.getServiceInvariantUUID()); + assertEquals(null, svc.getServiceName()); + assertEquals(null, svc.getServiceVersion()); + + String name = "constTest"; + svc = new Service(name); + assertEquals(null, svc.getServiceUUID()); + assertEquals(name, svc.getServiceName()); + assertEquals(null, svc.getServiceInvariantUUID()); + assertEquals(null, svc.getServiceVersion()); + + uuid = UUID.randomUUID(); + UUID uuidInvariant = UUID.randomUUID(); + name = "constTestUUID"; + String version = "0.0.1"; + svc = new Service(uuid, uuidInvariant, name, version); + assertEquals(uuid, svc.getServiceUUID()); + assertEquals(uuidInvariant, svc.getServiceInvariantUUID()); + assertEquals(name, svc.getServiceName()); + assertEquals(version, svc.getServiceVersion()); + + Service s2 = new Service(svc); + assertEquals(uuid, s2.getServiceUUID()); + assertEquals(uuidInvariant, s2.getServiceInvariantUUID()); + assertEquals(name, s2.getServiceName()); + assertEquals(version, s2.getServiceVersion()); + } + + @Test + public void testUuid() { + Service svc = new Service(); + UUID uuid = UUID.randomUUID(); + svc.setServiceUUID(uuid); + assertEquals(uuid, svc.getServiceUUID()); + } + + @Test + public void testInvariantUuid() { + Service svc = new Service(); + UUID uuid = UUID.randomUUID(); + svc.setServiceInvariantUUID(uuid); + assertEquals(uuid, svc.getServiceInvariantUUID()); + } + + @Test + public void testName() { + Service svc = new Service(); + String name = "nameTest"; + svc.setServiceName(name); + assertEquals(name, svc.getServiceName()); + } + + @Test + public void testVersion() { + Service svc = new Service(); + String version = "versionTest"; + svc.setServiceVersion(version); + assertEquals(version, svc.getServiceVersion()); + } + + @Test + public void testEquals() { + Service s1 = new Service(); + Service s2 = new Service(s1); + assertTrue(s1.equals(s2)); + assertTrue(s2.equals(s1)); + + s1 = new Service(UUID.randomUUID(), UUID.randomUUID(), "equalsTest", "1.1.1"); + s2 = new Service(s1); + assertTrue(s1.equals(s2)); + assertTrue(s2.equals(s1)); + } + + @Test + public void testToString() { + Service s1 = new Service(); + Service s2 = new Service(s1); + assertEquals(s1.toString(), s2.toString()); + + s1 = new Service(UUID.randomUUID(), UUID.randomUUID(), "equalsTest", "1.1.1"); + s2 = new Service(s1); + assertEquals(s1.toString(), s2.toString()); + } + + @Test + public void testHashCode() { + Service s1 = new Service(); + Service s2 = new Service(s1); + assertEquals(s1.hashCode(), s2.hashCode()); + + s1 = new Service(UUID.randomUUID(), UUID.randomUUID(), "equalsTest", "1.1.1"); + s2 = new Service(s1); + assertEquals(s1.hashCode(), s2.hashCode()); + } +} diff --git a/models-interactions/model-impl/sdc/src/test/resources/service_trinity.yaml b/models-interactions/model-impl/sdc/src/test/resources/service_trinity.yaml new file mode 100644 index 000000000..391dc0328 --- /dev/null +++ b/models-interactions/model-impl/sdc/src/test/resources/service_trinity.yaml @@ -0,0 +1,17 @@ +# Copyright 2018 AT&T Intellectual Property. All rights reserved +# Modifications Copyright (C) 2019 Nordix Foundation. +# +# 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. +Service: + serviceName: trinity +
\ No newline at end of file diff --git a/models-interactions/model-impl/sdc/src/test/resources/service_vSCP.yaml b/models-interactions/model-impl/sdc/src/test/resources/service_vSCP.yaml new file mode 100644 index 000000000..1c377c9c5 --- /dev/null +++ b/models-interactions/model-impl/sdc/src/test/resources/service_vSCP.yaml @@ -0,0 +1,16 @@ +# Copyright 2018 AT&T Intellectual Property. All rights reserved +# Modifications Copyright (C) 2019 Nordix Foundation. +# +# 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. +Service: + serviceName: vSCP
\ No newline at end of file diff --git a/models-interactions/model-impl/sdc/src/test/resources/service_vUSP.yaml b/models-interactions/model-impl/sdc/src/test/resources/service_vUSP.yaml new file mode 100644 index 000000000..6d6f9f1e1 --- /dev/null +++ b/models-interactions/model-impl/sdc/src/test/resources/service_vUSP.yaml @@ -0,0 +1,16 @@ +# Copyright 2018 AT&T Intellectual Property. All rights reserved +# Modifications Copyright (C) 2019 Nordix Foundation. +# +# 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. +Service: + serviceName: vUSP diff --git a/models-interactions/model-impl/sdnc/pom.xml b/models-interactions/model-impl/sdnc/pom.xml new file mode 100644 index 000000000..8bc0776e4 --- /dev/null +++ b/models-interactions/model-impl/sdnc/pom.xml @@ -0,0 +1,73 @@ +<!-- + ============LICENSE_START======================================================= + Copyright (C) 2018 Huawei. All rights reserved. + Modifications Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + Modifications Copyright (C) 2019 Nordix Foundation. + ================================================================================ + 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========================================================= + --> + +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.onap.policy.models.policy-models-interactions.model-impl</groupId> + <artifactId>model-impl</artifactId> + <version>2.0.0-SNAPSHOT</version> + </parent> + + <artifactId>sdnc</artifactId> + + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> + <version>2.13.0</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>com.google.code.gson</groupId> + <artifactId>gson</artifactId> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.onap.policy.models.policy-models-interactions.model-impl</groupId> + <artifactId>rest</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.drools</groupId> + <artifactId>drools-core</artifactId> + <version>6.5.0.Final</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.onap.policy.common</groupId> + <artifactId>policy-endpoints</artifactId> + <version>${policy.common.version}</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.onap.policy.drools-pdp</groupId> + <artifactId>policy-management</artifactId> + <version>${policy.drools-pdp.version}</version> + <scope>provided</scope> + </dependency> + </dependencies> +</project> diff --git a/models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncHealNetworkInfo.java b/models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncHealNetworkInfo.java new file mode 100644 index 000000000..be26f8775 --- /dev/null +++ b/models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncHealNetworkInfo.java @@ -0,0 +1,44 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Huawei. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.sdnc; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; + +public class SdncHealNetworkInfo implements Serializable { + + private static final long serialVersionUID = 3208673205100673119L; + + @SerializedName("network-id") + private String networkId; + + public SdncHealNetworkInfo() { + // Default constructor for SdncHealActionVmInfo + } + + public String getNetworkId() { + return networkId; + } + + public void setNetworkId(String networkId) { + this.networkId = networkId; + } +} diff --git a/models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncHealRequest.java b/models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncHealRequest.java new file mode 100644 index 000000000..88645d517 --- /dev/null +++ b/models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncHealRequest.java @@ -0,0 +1,78 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Huawei. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.sdnc; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; + +public class SdncHealRequest implements Serializable { + + private static final long serialVersionUID = -7341931593089709247L; + + @SerializedName("sdnc-request-header") + private SdncHealRequestHeaderInfo requestHeaderInfo; + + @SerializedName("request-information") + private SdncHealRequestInfo requestInfo; + + @SerializedName("service-information") + private SdncHealServiceInfo serviceInfo; + + @SerializedName("network-information") + private SdncHealNetworkInfo networkInfo; + + public SdncHealRequest() { + // Default constructor for SdncHealRequest + } + + public SdncHealRequestHeaderInfo getRequestHeaderInfo() { + return requestHeaderInfo; + } + + public void setRequestHeaderInfo(SdncHealRequestHeaderInfo requestHeaderInfo) { + this.requestHeaderInfo = requestHeaderInfo; + } + + public SdncHealRequestInfo getRequestInfo() { + return requestInfo; + } + + public void setRequestInfo(SdncHealRequestInfo requestInfo) { + this.requestInfo = requestInfo; + } + + public SdncHealServiceInfo getServiceInfo() { + return serviceInfo; + } + + public void setServiceInfo(SdncHealServiceInfo serviceInfo) { + this.serviceInfo = serviceInfo; + } + + public SdncHealNetworkInfo getNetworkInfo() { + return networkInfo; + } + + public void setNetworkInfo(SdncHealNetworkInfo networkInfo) { + this.networkInfo = networkInfo; + } + +} diff --git a/models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncHealRequestHeaderInfo.java b/models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncHealRequestHeaderInfo.java new file mode 100644 index 000000000..0cdbb294e --- /dev/null +++ b/models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncHealRequestHeaderInfo.java @@ -0,0 +1,55 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Huawei. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.sdnc; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; + +public class SdncHealRequestHeaderInfo implements Serializable { + + private static final long serialVersionUID = 3208673205100673119L; + + @SerializedName("svc-request-id") + private String svcRequestId; + + @SerializedName("svc-action") + private String svcAction; + + public SdncHealRequestHeaderInfo() { + // Default constructor for SdncHealActionVmInfo + } + + public String getSvcRequestId() { + return svcRequestId; + } + + public void setSvcRequestId(String svcRequestId) { + this.svcRequestId = svcRequestId; + } + + public String getSvcAction() { + return svcAction; + } + + public void setSvcAction(String svcAction) { + this.svcAction = svcAction; + } +} diff --git a/models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncHealRequestInfo.java b/models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncHealRequestInfo.java new file mode 100644 index 000000000..fa449a013 --- /dev/null +++ b/models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncHealRequestInfo.java @@ -0,0 +1,44 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Huawei. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.sdnc; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; + +public class SdncHealRequestInfo implements Serializable { + + private static final long serialVersionUID = 3208673205100673119L; + + @SerializedName("request-action") + private String requestAction; + + public SdncHealRequestInfo() { + // Default constructor for SdncHealActionVmInfo + } + + public String getRequestAction() { + return requestAction; + } + + public void setRequestAction(String requestAction) { + this.requestAction = requestAction; + } +} diff --git a/models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncHealServiceInfo.java b/models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncHealServiceInfo.java new file mode 100644 index 000000000..5b03db3ca --- /dev/null +++ b/models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncHealServiceInfo.java @@ -0,0 +1,44 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Huawei. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.sdnc; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; + +public class SdncHealServiceInfo implements Serializable { + + private static final long serialVersionUID = 3208673205100673119L; + + @SerializedName("service-instance-id") + private String serviceInstanceId; + + public SdncHealServiceInfo() { + // Default constructor for SdncHealActionVmInfo + } + + public String getServiceInstanceId() { + return serviceInstanceId; + } + + public void setServiceInstanceId(String serviceInstanceId) { + this.serviceInstanceId = serviceInstanceId; + } +} diff --git a/models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncManager.java b/models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncManager.java new file mode 100644 index 000000000..5770a23c5 --- /dev/null +++ b/models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncManager.java @@ -0,0 +1,168 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Huawei. All rights reserved. + * ================================================================================ + * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved + * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019 Samsung Electronics Co., Ltd. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.sdnc; + + +import com.google.gson.JsonSyntaxException; + +import java.util.HashMap; +import java.util.Map; + +import org.drools.core.WorkingMemory; +import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure; +import org.onap.policy.common.endpoints.utils.NetLoggerUtil; +import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType; +import org.onap.policy.drools.system.PolicyEngine; +import org.onap.policy.rest.RestManager; +import org.onap.policy.rest.RestManager.Pair; +import org.onap.policy.sdnc.util.Serialization; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public final class SdncManager implements Runnable { + + private String sdncUrlBase; + private String username; + private String password; + private SdncRequest sdncRequest; + private WorkingMemory workingMem; + private static final Logger logger = LoggerFactory.getLogger(SdncManager.class); + + // The REST manager used for processing REST calls for this Sdnc manager + private RestManager restManager; + + /** + * Constructor. + * + * @param wm Drools working memory + * @param request request + */ + public SdncManager(WorkingMemory wm, SdncRequest request) { + if (wm == null || request == null) { + throw new IllegalArgumentException( + "the parameters \"wm\" and \"request\" on the SdncManager constructor may not be null" + ); + } + workingMem = wm; + sdncRequest = request; + + restManager = new RestManager(); + + setSdncParams(getPeManagerEnvProperty("sdnc.url"), getPeManagerEnvProperty("sdnc.username"), + getPeManagerEnvProperty("sdnc.password")); + } + + /** + * Set the parameters. + * + * @param baseUrl base URL + * @param name username + * @param pwd password + */ + public void setSdncParams(String baseUrl, String name, String pwd) { + sdncUrlBase = baseUrl; + username = name; + password = pwd; + } + + @Override + public void run() { + Map<String, String> headers = new HashMap<>(); + Pair<Integer, String> httpDetails; + + SdncResponse responseError = new SdncResponse(); + SdncResponseOutput responseOutput = new SdncResponseOutput(); + responseOutput.setResponseCode("404"); + responseError.setResponseOutput(responseOutput); + + headers.put("Accept", "application/json"); + String sdncUrl = sdncUrlBase + "/GENERIC-RESOURCE-API:network-topology-operation"; + + try { + String sdncRequestJson = Serialization.gsonPretty.toJson(sdncRequest); + NetLoggerUtil.log(EventType.OUT, CommInfrastructure.REST, sdncUrl, sdncRequestJson); + logger.info("[OUT|{}|{}|]{}{}", CommInfrastructure.REST, sdncUrl, NetLoggerUtil.SYSTEM_LS, sdncRequestJson); + + httpDetails = restManager.post(sdncUrl, username, password, headers, "application/json", + sdncRequestJson); + } catch (Exception e) { + logger.info(e.getMessage(), e); + workingMem.insert(responseError); + return; + } + + if (httpDetails == null) { + workingMem.insert(responseError); + return; + } + + try { + SdncResponse response = Serialization.gsonPretty.fromJson(httpDetails.second, SdncResponse.class); + NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, sdncUrl, httpDetails.second); + logger.info("[IN|{}|{}|]{}{}", "Sdnc", sdncUrl, NetLoggerUtil.SYSTEM_LS, httpDetails.second); + String body = Serialization.gsonPretty.toJson(response); + logger.info("Response to Sdnc Heal post:"); + logger.info(body); + response.setRequestId(sdncRequest.getRequestId().toString()); + + if (!response.getResponseOutput().getResponseCode().equals("200")) { + logger.info( + "Sdnc Heal Restcall failed with http error code {} {}", httpDetails.first, httpDetails.second + ); + } + + workingMem.insert(response); + } catch (JsonSyntaxException e) { + logger.info("Failed to deserialize into SdncResponse {}", e.getLocalizedMessage(), e); + } catch (Exception e) { + logger.info("Unknown error deserializing into SdncResponse {}", e.getLocalizedMessage(), e); + } + } + + /** + * Protected setter for rest manager to allow mocked rest manager to be used for testing. + * @param restManager the test REST manager + */ + protected void setRestManager(final RestManager restManager) { + this.restManager = restManager; + } + + /** + * This method reads and validates environmental properties coming from the policy engine. Null properties cause + * an {@link IllegalArgumentException} runtime exception to be thrown + * @param enginePropertyName name of the parameter to retrieve + * @return the property value + */ + + private String getPeManagerEnvProperty(String enginePropertyName) { + String enginePropertyValue = PolicyEngine.manager.getEnvironmentProperty(enginePropertyName); + if (enginePropertyValue == null) { + throw new IllegalArgumentException( + "The value of policy engine manager environment property \"" + + enginePropertyName + "\" may not be null" + ); + } + return enginePropertyValue; + } +} diff --git a/models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncRequest.java b/models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncRequest.java new file mode 100644 index 000000000..4aaa844cd --- /dev/null +++ b/models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncRequest.java @@ -0,0 +1,63 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Huawei. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.sdnc; + +import com.google.gson.annotations.SerializedName; +import java.io.Serializable; +import java.util.UUID; + +public class SdncRequest implements Serializable { + + private static final long serialVersionUID = 3736300970326332512L; + // These fields are not serialized and not part of JSON + private transient String nsInstanceId; + private transient UUID requestId; + + @SerializedName("input") + private SdncHealRequest healRequest; + + public SdncRequest() { + // Default constructor for SdncRequest + } + + public String getNsInstanceId() { + return nsInstanceId; + } + + public void setNsInstanceId(String nsInstanceId) { + this.nsInstanceId = nsInstanceId; + } + + public UUID getRequestId() { + return requestId; + } + + public void setRequestId(UUID requestId) { + this.requestId = requestId; + } + + public SdncHealRequest getHealRequest() { + return healRequest; + } + + public void setHealRequest(SdncHealRequest healRequest) { + this.healRequest = healRequest; + } +} diff --git a/models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncResponse.java b/models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncResponse.java new file mode 100644 index 000000000..496bf10a7 --- /dev/null +++ b/models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncResponse.java @@ -0,0 +1,55 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Huawei. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.sdnc; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; + +public class SdncResponse implements Serializable { + + private static final long serialVersionUID = 9151443891238218455L; + + @SerializedName("output") + private SdncResponseOutput responseOutput; + + private transient String requestId; + + public SdncResponse() { + // Default constructor for SdncResponse + } + + public String getRequestId() { + return requestId; + } + + public void setRequestId(String requestId) { + this.requestId = requestId; + } + + public SdncResponseOutput getResponseOutput() { + return responseOutput; + } + + public void setResponseOutput(SdncResponseOutput responseOutput) { + this.responseOutput = responseOutput; + } + +} diff --git a/models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncResponseNetworkInfo.java b/models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncResponseNetworkInfo.java new file mode 100644 index 000000000..094b2641b --- /dev/null +++ b/models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncResponseNetworkInfo.java @@ -0,0 +1,55 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Huawei. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.sdnc; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; + +public class SdncResponseNetworkInfo implements Serializable { + + private static final long serialVersionUID = 6827782899144150158L; + + @SerializedName("instance-id") + private String instanceId; + + @SerializedName("object-path") + private String objectPath; + + public SdncResponseNetworkInfo() { + // Default constructor for SdncResponseNetworkInfo + } + + public String getInstanceId() { + return instanceId; + } + + public void setInstanceId(String instanceId) { + this.instanceId = instanceId; + } + + public String getObjectPath() { + return objectPath; + } + + public void setObjectPath(String objectPath) { + this.objectPath = objectPath; + } +} diff --git a/models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncResponseOutput.java b/models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncResponseOutput.java new file mode 100644 index 000000000..fc3335a61 --- /dev/null +++ b/models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncResponseOutput.java @@ -0,0 +1,68 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Huawei. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.sdnc; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; +import java.util.List; + +public class SdncResponseOutput implements Serializable { + + private static final long serialVersionUID = 6827782899144150158L; + + @SerializedName("svc-request-id") + private String svcRequestId; + + @SerializedName("response-code") + private String responseCode; + + @SerializedName("ack-final-indicator") + private String ackFinalIndicator; + + public SdncResponseOutput() { + // Default constructor for SdncResponseDescriptor + } + + public String getSvcRequestId() { + return svcRequestId; + } + + public void setSvcRequestId(String svcRequestId) { + this.svcRequestId = svcRequestId; + } + + public String getResponseCode() { + return responseCode; + } + + public void setResponseCode(String responseCode) { + this.responseCode = responseCode; + } + + public String getAckFinalIndicator() { + return ackFinalIndicator; + } + + public void setAckFinalIndicator(String ackFinalIndicator) { + this.ackFinalIndicator = ackFinalIndicator; + } + +} diff --git a/models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncResponseServiceInfo.java b/models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncResponseServiceInfo.java new file mode 100644 index 000000000..05b854418 --- /dev/null +++ b/models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncResponseServiceInfo.java @@ -0,0 +1,45 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Huawei. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.sdnc; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; + +public class SdncResponseServiceInfo implements Serializable { + + private static final long serialVersionUID = 6827782899144150158L; + + @SerializedName("instance-id") + private String instanceId; + + public SdncResponseServiceInfo() { + // Default constructor for SdncResponseServiceInfo + } + + public String getInstanceId() { + return instanceId; + } + + public void setInstanceId(String instanceId) { + this.instanceId = instanceId; + } + +} diff --git a/models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/util/Serialization.java b/models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/util/Serialization.java new file mode 100644 index 000000000..428f357aa --- /dev/null +++ b/models-interactions/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/util/Serialization.java @@ -0,0 +1,33 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Huawei. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.sdnc.util; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +public final class Serialization { + private Serialization() { + } + + public static final Gson gsonPretty = new GsonBuilder().disableHtmlEscaping() + .setPrettyPrinting() + .create(); + +} diff --git a/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/DemoTest.java b/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/DemoTest.java new file mode 100644 index 000000000..53be3382b --- /dev/null +++ b/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/DemoTest.java @@ -0,0 +1,72 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Huawei. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.sdnc; + +import java.util.LinkedList; + +import org.junit.Test; +import org.onap.policy.sdnc.util.Serialization; + +public class DemoTest { + + @Test + public void test() { + SdncRequest request = new SdncRequest(); + + request.setNsInstanceId("100"); + request.setHealRequest(new SdncHealRequest()); + + request.getHealRequest().setRequestHeaderInfo(new SdncHealRequestHeaderInfo()); + request.getHealRequest().getRequestHeaderInfo().setSvcRequestId("service-req-01"); + request.getHealRequest().getRequestHeaderInfo().setSvcAction("servive-action"); + + request.getHealRequest().setRequestInfo(new SdncHealRequestInfo()); + request.getHealRequest().getRequestInfo().setRequestAction("request-action"); + + request.getHealRequest().setServiceInfo(new SdncHealServiceInfo()); + request.getHealRequest().getServiceInfo().setServiceInstanceId("service-instance-01"); + + request.getHealRequest().setNetworkInfo(new SdncHealNetworkInfo()); + request.getHealRequest().getNetworkInfo().setNetworkId("network-5555"); + + + String body = Serialization.gsonPretty.toJson(request); + System.out.println(body); + + SdncResponse response = new SdncResponse(); + + body = Serialization.gsonPretty.toJson(response); + System.out.println(body); + + response.setRequestId("request-01"); + response.setResponseOutput(new SdncResponseOutput()); + response.getResponseOutput().setSvcRequestId("service-req-01"); + response.getResponseOutput().setResponseCode("200"); + response.getResponseOutput().setAckFinalIndicator("final-indicator-00"); + + body = Serialization.gsonPretty.toJson(response); + System.out.println(body); + + response = Serialization.gsonPretty.fromJson(body, SdncResponse.class); + body = Serialization.gsonPretty.toJson(response); + System.out.println(body); + + } +} diff --git a/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/SdncHealAdditionalParamsTest.java b/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/SdncHealAdditionalParamsTest.java new file mode 100644 index 000000000..e7decbc15 --- /dev/null +++ b/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/SdncHealAdditionalParamsTest.java @@ -0,0 +1,48 @@ +/*- + * ============LICENSE_START======================================================= + * vfc + * ================================================================================ + * Copyright (C) 2018 Huawei. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.sdnc; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; + +public class SdncHealAdditionalParamsTest { + + @Test + public void testSdncHealAdditionalParameters() { + SdncHealRequestHeaderInfo additionalParams = new SdncHealRequestHeaderInfo(); + assertNotNull(additionalParams); + assertNotEquals(0, additionalParams.hashCode()); + + String action = "Go Home"; + additionalParams.setSvcAction(action); + assertEquals(action, additionalParams.getSvcAction()); + + String requestId = "My Request"; + additionalParams.setSvcRequestId(requestId); + assertEquals(requestId, additionalParams.getSvcRequestId()); + + assertNotEquals(0, additionalParams.hashCode()); + } +} diff --git a/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/SdncHealRequestTest.java b/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/SdncHealRequestTest.java new file mode 100644 index 000000000..c1ff45bec --- /dev/null +++ b/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/SdncHealRequestTest.java @@ -0,0 +1,44 @@ +/*- + * ============LICENSE_START======================================================= + * vfc + * ================================================================================ + * Copyright (C) 2018 Huawei. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.sdnc; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; + +public class SdncHealRequestTest { + + @Test + public void testSdncHealRequest() { + SdncHealRequest request = new SdncHealRequest(); + assertNotNull(request); + assertNotEquals(0, request.hashCode()); + + SdncHealRequestInfo requestInfo = new SdncHealRequestInfo(); + request.setRequestInfo(requestInfo); + assertEquals(requestInfo, request.getRequestInfo()); + + assertNotEquals(0, request.hashCode()); + } +} diff --git a/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/SdncHealServiceInfoTest.java b/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/SdncHealServiceInfoTest.java new file mode 100644 index 000000000..b65e45fc3 --- /dev/null +++ b/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/SdncHealServiceInfoTest.java @@ -0,0 +1,44 @@ +/*- + * ============LICENSE_START======================================================= + * sdnc + * ================================================================================ + * Copyright (C) 2018 Huawei. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.sdnc; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; + +public class SdncHealServiceInfoTest { + + @Test + public void testSdncHealServiceInfo() { + SdncHealServiceInfo serviceInfo = new SdncHealServiceInfo(); + assertNotNull(serviceInfo); + assertNotEquals(0, serviceInfo.hashCode()); + + String svrid = "ECity"; + serviceInfo.setServiceInstanceId(svrid); + assertEquals(svrid, serviceInfo.getServiceInstanceId()); + + assertNotEquals(0, serviceInfo.hashCode()); + } +} diff --git a/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/SdncManagerTest.java b/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/SdncManagerTest.java new file mode 100644 index 000000000..305fcebd6 --- /dev/null +++ b/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/SdncManagerTest.java @@ -0,0 +1,284 @@ +/*- + * ============LICENSE_START======================================================= + * sdnc + * ================================================================================ + * Copyright (C) 2018 Huawei. All rights reserved. + * ================================================================================ + * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.sdnc; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +import static org.mockito.ArgumentMatchers.anyMap; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.endsWith; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.startsWith; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +import org.drools.core.WorkingMemory; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.onap.policy.drools.system.PolicyEngine; +import org.onap.policy.rest.RestManager; +import org.onap.policy.rest.RestManager.Pair; +import org.onap.policy.sdnc.util.Serialization; + +public class SdncManagerTest { + private static WorkingMemory mockedWorkingMemory; + + private RestManager mockedRestManager; + + private Pair<Integer, String> httpResponsePutOk; + private Pair<Integer, String> httpResponseGetOk; + private Pair<Integer, String> httpResponseBadResponse; + private Pair<Integer, String> httpResponseErr; + + private SdncRequest request; + private SdncResponse response; + + @BeforeClass + public static void beforeTestSdncManager() { + mockedWorkingMemory = mock(WorkingMemory.class); + } + + /** + * Set up the mocked REST manager. + */ + @Before + public void setupMockedRest() { + mockedRestManager = mock(RestManager.class); + + httpResponsePutOk = mockedRestManager.new Pair<>(202, Serialization.gsonPretty.toJson(response)); + httpResponseGetOk = mockedRestManager.new Pair<>(200, Serialization.gsonPretty.toJson(response)); + httpResponseBadResponse = mockedRestManager.new Pair<>(202, Serialization.gsonPretty.toJson(null)); + httpResponseErr = mockedRestManager.new Pair<>(200, null); + } + + /** + * Create the request and response before. + */ + @Before + public void createRequestAndResponse() { + SdncHealServiceInfo serviceInfo = new SdncHealServiceInfo(); + serviceInfo.setServiceInstanceId("E-City"); + + SdncHealRequestHeaderInfo additionalParams = new SdncHealRequestHeaderInfo(); + additionalParams.setSvcAction("Go Home"); + additionalParams.setSvcRequestId("My Request"); + + SdncHealRequest healRequest = new SdncHealRequest(); + healRequest.setRequestHeaderInfo(additionalParams); + healRequest.setServiceInfo(serviceInfo); + + UUID requestId = UUID.randomUUID(); + request = new SdncRequest(); + request.setRequestId(requestId); + request.setHealRequest(healRequest); + request.setNsInstanceId("Dorothy"); + + SdncResponseOutput responseDescriptor = new SdncResponseOutput(); + responseDescriptor.setSvcRequestId("1234"); + responseDescriptor.setResponseCode("200"); + responseDescriptor.setAckFinalIndicator("final-indicator-00"); + + response = new SdncResponse(); + response.setRequestId(request.getRequestId().toString()); + response.setResponseOutput(responseDescriptor); + } + + /** + * After Test clean up. + */ + @After + public void afterTestSdncManager() throws InterruptedException { + PolicyEngine.manager.getEnvironment().remove("sdnc.password"); + PolicyEngine.manager.getEnvironment().remove("sdnc.username"); + PolicyEngine.manager.getEnvironment().remove("sdnc.url"); + } + + @Test + public void testSdncInitiation() throws InterruptedException { + try { + new SdncManager(null, null); + fail("test should throw an exception here"); + } + catch (IllegalArgumentException e) { + assertEquals( + "the parameters \"wm\" and \"request\" on the SdncManager constructor may not be null", + e.getMessage() + ); + } + + try { + new SdncManager(mockedWorkingMemory, null); + fail("test should throw an exception here"); + } + catch (IllegalArgumentException e) { + assertEquals( + "the parameters \"wm\" and \"request\" on the SdncManager constructor may not be null", + e.getMessage() + ); + } + + try { + new SdncManager(mockedWorkingMemory, request); + fail("test should throw an exception here"); + } + catch (IllegalArgumentException e) { + assertEquals( + "The value of policy engine manager environment property \"sdnc.url\" may not be null", + e.getMessage() + ); + } + + PolicyEngine.manager.getEnvironment().put("sdnc.url", "http://somewhere.over.the.rainbow"); + try { + new SdncManager(mockedWorkingMemory, request); + fail("test should throw an exception here"); + } + catch (IllegalArgumentException e) { + assertEquals( + "The value of policy engine manager environment property \"sdnc.username\" may not be null", + e.getMessage() + ); + } + + PolicyEngine.manager.getEnvironment().put("sdnc.username", "Dorothy"); + try { + new SdncManager(mockedWorkingMemory, request); + fail("test should throw an exception here"); + } + catch (IllegalArgumentException e) { + assertEquals( + "The value of policy engine manager environment property \"sdnc.password\" may not be null", + e.getMessage() + ); + } + + PolicyEngine.manager.getEnvironment().put("sdnc.password", "Toto"); + new SdncManager(mockedWorkingMemory, request); + } + + @Test + public void testSdncExecutionException() throws InterruptedException { + PolicyEngine.manager.getEnvironment().put("sdnc.url", "http://somewhere.over.the.rainbow"); + PolicyEngine.manager.getEnvironment().put("sdnc.username", "Dorothy"); + PolicyEngine.manager.getEnvironment().put("sdnc.password", "Exception"); + + SdncManager manager = new SdncManager(mockedWorkingMemory, request); + manager.setRestManager(mockedRestManager); + + Thread managerThread = new Thread(manager); + managerThread.start(); + + when(mockedRestManager.post(startsWith("http://somewhere.over.the.rainbow"), eq("Dorothy"), eq("Exception"), anyMap(), anyString(), anyString())) + .thenThrow(new RuntimeException("OzException")); + + + managerThread.join(100); + } + + @Test + public void testSdncExecutionNull() throws InterruptedException { + PolicyEngine.manager.getEnvironment().put("sdnc.url", "http://somewhere.over.the.rainbow"); + PolicyEngine.manager.getEnvironment().put("sdnc.username", "Dorothy"); + PolicyEngine.manager.getEnvironment().put("sdnc.password", "Null"); + + SdncManager manager = new SdncManager(mockedWorkingMemory, request); + manager.setRestManager(mockedRestManager); + + Thread managerThread = new Thread(manager); + managerThread.start(); + + when(mockedRestManager.post(startsWith("http://somewhere.over.the.rainbow"), eq("Dorothy"), eq("Null"), anyMap(), anyString(), anyString())) + .thenReturn(null); + + managerThread.join(100); + } + + + @Test + public void testSdncExecutionError0() throws InterruptedException { + PolicyEngine.manager.getEnvironment().put("sdnc.url", "http://somewhere.over.the.rainbow"); + PolicyEngine.manager.getEnvironment().put("sdnc.username", "Dorothy"); + PolicyEngine.manager.getEnvironment().put("sdnc.password", "Error0"); + + SdncManager manager = new SdncManager(mockedWorkingMemory, request); + manager.setRestManager(mockedRestManager); + + Thread managerThread = new Thread(manager); + managerThread.start(); + + when(mockedRestManager.post(startsWith("http://somewhere.over.the.rainbow"), eq("Dorothy"), eq("Error0"), anyMap(), anyString(), anyString())) + .thenReturn(httpResponseErr); + + managerThread.join(100); + } + + @Test + public void testSdncExecutionBadResponse() throws InterruptedException { + PolicyEngine.manager.getEnvironment().put("sdnc.url", "http://somewhere.over.the.rainbow"); + PolicyEngine.manager.getEnvironment().put("sdnc.username", "Dorothy"); + PolicyEngine.manager.getEnvironment().put("sdnc.password", "BadResponse"); + + SdncManager manager = new SdncManager(mockedWorkingMemory, request); + manager.setRestManager(mockedRestManager); + + Thread managerThread = new Thread(manager); + managerThread.start(); + + when(mockedRestManager.post(startsWith("http://somewhere.over.the.rainbow"), eq("Dorothy"), eq("OK"), anyMap(), anyString(), anyString())) + .thenReturn(httpResponseBadResponse); + + managerThread.join(100); + } + + @Test + public void testSdncExecutionOk() throws InterruptedException { + PolicyEngine.manager.getEnvironment().put("sdnc.url", "http://somewhere.over.the.rainbow"); + PolicyEngine.manager.getEnvironment().put("sdnc.username", "Dorothy"); + PolicyEngine.manager.getEnvironment().put("sdnc.password", "OK"); + + SdncManager manager = new SdncManager(mockedWorkingMemory, request); + manager.setRestManager(mockedRestManager); + + Thread managerThread = new Thread(manager); + managerThread.start(); + + when(mockedRestManager.post(startsWith("http://somewhere.over.the.rainbow"), eq("Dorothy"), eq("OK"), anyMap(), anyString(), anyString())) + .thenReturn(httpResponsePutOk); + + when(mockedRestManager.get(endsWith("1234"), eq("Dorothy"), eq("OK"), anyMap())) + .thenReturn(httpResponseGetOk); + + + managerThread.join(100); + } +} diff --git a/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/SdncRequestTest.java b/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/SdncRequestTest.java new file mode 100644 index 000000000..55fece751 --- /dev/null +++ b/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/SdncRequestTest.java @@ -0,0 +1,54 @@ +/*- + * ============LICENSE_START======================================================= + * sdnc + * ================================================================================ + * Copyright (C) 2018 Huawei. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.sdnc; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; + +import java.util.UUID; + +import org.junit.Test; + +public class SdncRequestTest { + + @Test + public void testSdncRequest() { + SdncRequest request = new SdncRequest(); + assertNotNull(request); + assertNotEquals(0, request.hashCode()); + + String nsInstanceId = "Dorothy"; + request.setNsInstanceId(nsInstanceId); + assertEquals(nsInstanceId, request.getNsInstanceId()); + + UUID requestId = UUID.randomUUID(); + request.setRequestId(requestId); + assertEquals(requestId, request.getRequestId()); + + SdncHealRequest healRequest = new SdncHealRequest(); + request.setHealRequest(healRequest); + assertEquals(healRequest, request.getHealRequest()); + + assertNotEquals(0, request.hashCode()); + } +} diff --git a/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/SdncResponseDescriptorTest.java b/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/SdncResponseDescriptorTest.java new file mode 100644 index 000000000..89d694e65 --- /dev/null +++ b/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/SdncResponseDescriptorTest.java @@ -0,0 +1,55 @@ +/*- + * ============LICENSE_START======================================================= + * sdnc + * ================================================================================ + * Copyright (C) 2018 Huawei. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.sdnc; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; + +public class SdncResponseDescriptorTest { + + @Test + public void testSdncResponseDescriptor() { + SdncResponseOutput output = new SdncResponseOutput(); + assertNotNull(output); + assertNotEquals(0, output.hashCode()); + + String responseCode = "200"; + output.setResponseCode(responseCode); + assertEquals(responseCode, output.getResponseCode()); + + String svcRequest = "svc-request-01"; + output.setSvcRequestId(svcRequest); + assertEquals(svcRequest, output.getSvcRequestId()); + + String indicator = "final-indicator-00"; + output.setAckFinalIndicator(indicator); + assertEquals(indicator, output.getAckFinalIndicator()); + + assertNotEquals(0, output.hashCode()); + } +} diff --git a/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/SdncResponseTest.java b/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/SdncResponseTest.java new file mode 100644 index 000000000..06e3da81b --- /dev/null +++ b/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/SdncResponseTest.java @@ -0,0 +1,49 @@ +/*- + * ============LICENSE_START======================================================= + * sdnc + * ================================================================================ + * Copyright (C) 2018 Huawei. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.sdnc; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; + + +import org.junit.Test; + +public class SdncResponseTest { + + @Test + public void testSdncResponse() { + SdncResponse response = new SdncResponse(); + assertNotNull(response); + assertNotEquals(0, response.hashCode()); + + String requestId = "Get Home"; + response.setRequestId(requestId); + assertEquals(requestId, response.getRequestId()); + + SdncResponseOutput responseDescriptor = new SdncResponseOutput(); + response.setResponseOutput(responseDescriptor); + assertEquals(responseDescriptor, response.getResponseOutput()); + + assertNotEquals(0, response.hashCode()); + } +} diff --git a/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/util/SerializationTest.java b/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/util/SerializationTest.java new file mode 100644 index 000000000..b65efb36d --- /dev/null +++ b/models-interactions/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/util/SerializationTest.java @@ -0,0 +1,36 @@ +/*- + * ============LICENSE_START======================================================= + * vfc + * ================================================================================ + * Copyright (C) 2018 Huawei. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.sdnc.util; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; + +public class SerializationTest { + + @Test + public void test() { + assertNotNull(Serialization.gsonPretty); + } +} diff --git a/models-interactions/model-impl/sdnr/pom.xml b/models-interactions/model-impl/sdnr/pom.xml new file mode 100644 index 000000000..e091b728b --- /dev/null +++ b/models-interactions/model-impl/sdnr/pom.xml @@ -0,0 +1,47 @@ +<!-- + ============LICENSE_START======================================================= + sdnr + ================================================================================ + Copyright (C) 2018 Wipro Limited Intellectual Property. All rights reserved. + Modifications Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + Modifications Copyright (C) 2019 Nordix Foundation. + ================================================================================ + 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========================================================= + --> + + +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.onap.policy.models.policy-models-interactions.model-impl</groupId> + <artifactId>model-impl</artifactId> + <version>2.0.0-SNAPSHOT</version> + </parent> + + <artifactId>sdnr</artifactId> + + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>com.google.code.gson</groupId> + <artifactId>gson</artifactId> + <scope>provided</scope> + </dependency> + </dependencies> +</project> diff --git a/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciCommonHeader.java b/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciCommonHeader.java new file mode 100644 index 000000000..5c1ed4839 --- /dev/null +++ b/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciCommonHeader.java @@ -0,0 +1,265 @@ +/*- + * ============LICENSE_START======================================================= + * sdnr + * ================================================================================ + * Copyright (C) 2018 Wipro Limited Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.sdnr; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; +import java.time.Instant; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +public class PciCommonHeader implements Serializable { + + private static final long serialVersionUID = 5435363539127062114L; + + @SerializedName(value = "TimeStamp") + private Instant timeStamp = Instant.now(); + + @SerializedName(value = "APIVer") + private String apiVer = "1.0"; + + @SerializedName(value = "RequestID") + private UUID requestId; + + @SerializedName(value = "SubRequestID") + private String subRequestId; + + @SerializedName(value = "RequestTrack") + private Map<String, String> requestTrack = new HashMap<>(); + + @SerializedName(value = "Flags") + private Map<String, String> flags = new HashMap<>(); + + public PciCommonHeader() { + + } + + /** + * Used to copy a pci common header. + * + * @param commonHeader a header that is defined by the Pci api guide that contains information + * about the request (requestId, flags, etc.) + */ + public PciCommonHeader(PciCommonHeader commonHeader) { + this.timeStamp = commonHeader.timeStamp; + this.requestId = commonHeader.requestId; + this.subRequestId = commonHeader.subRequestId; + if (commonHeader.requestTrack != null) { + this.requestTrack.putAll(commonHeader.requestTrack); + } + if (commonHeader.flags != null) { + this.flags.putAll(commonHeader.flags); + } + } + + /** + * Get the timestamp. + * + * @return the timeStamp + */ + public Instant getTimeStamp() { + return timeStamp; + } + + /** + * Set the timestamp. + * + * @param timeStamp + * the timeStamp to set + */ + public void setTimeStamp(Instant timeStamp) { + this.timeStamp = timeStamp; + } + + /** + * Get the API version. + * + * @return the apiVer + */ + public String getApiVer() { + return apiVer; + } + + /** + * Set the API version. + * + * @param apiVer + * the apiVer to set + */ + public void setApiVer(String apiVer) { + this.apiVer = apiVer; + } + + /** + * Get the request Id. + * + * @return the requestId + */ + public UUID getRequestId() { + return requestId; + } + + /** + * Set the request Id. + * + * @param requestId + * the requestId to set + */ + public void setRequestId(UUID requestId) { + this.requestId = requestId; + } + + /** + * Get the sub request Id. + * + * @return the subRequestId + */ + public String getSubRequestId() { + return subRequestId; + } + + /** + * Set the sub request Id. + * + * @param subRequestId + * the subRequestId to set + */ + public void setSubRequestId(String subRequestId) { + this.subRequestId = subRequestId; + } + /** + * Set the request track. + * + * @param requestTrack + * the requestTrack to set + */ + public void setRequestTrack(Map<String, String> requestTrack) { + this.requestTrack = requestTrack; + } + /** + * Get the request track. + * + * @return the requestTrack + */ + public Map<String, String> getRequestTrack() { + return requestTrack; + } + + /** + * Get the flags. + * + * @return the flags + */ + public Map<String, String> getFlags() { + return flags; + } + + /** + * Set the flags. + * + * @param flags + * the flags to set + */ + public void setFlags(Map<String, String> flags) { + this.flags = flags; + } + + @Override + public String toString() { + return "CommonHeader [timeStamp=" + timeStamp + ", apiVer=" + apiVer + + ", requestId=" + requestId + ", subRequestId=" + subRequestId + ", requestTrack=" + requestTrack + + ", flags=" + flags + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((apiVer == null) ? 0 : apiVer.hashCode()); + result = prime * result + ((flags == null) ? 0 : flags.hashCode()); + result = prime * result + ((requestTrack == null) ? 0 : requestTrack.hashCode()); + result = prime * result + ((requestId == null) ? 0 : requestId.hashCode()); + result = prime * result + ((subRequestId == null) ? 0 : subRequestId.hashCode()); + result = prime * result + ((timeStamp == null) ? 0 : timeStamp.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + PciCommonHeader other = (PciCommonHeader) obj; + if (apiVer == null) { + if (other.apiVer != null) { + return false; + } + } else if (!apiVer.equals(other.apiVer)) { + return false; + } + if (flags == null) { + if (other.flags != null) { + return false; + } + } else if (!flags.equals(other.flags)) { + return false; + } + if (requestTrack == null) { + if (other.requestTrack != null) { + return false; + } + } else if (!requestTrack.equals(other.requestTrack)) { + return false; + } + if (requestId == null) { + if (other.requestId != null) { + return false; + } + } else if (!requestId.equals(other.requestId)) { + return false; + } + if (subRequestId == null) { + if (other.subRequestId != null) { + return false; + } + } else if (!subRequestId.equals(other.subRequestId)) { + return false; + } + if (timeStamp == null) { + if (other.timeStamp != null) { + return false; + } + } else if (!timeStamp.equals(other.timeStamp)) { + return false; + } + return true; + } + +} diff --git a/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciRequest.java b/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciRequest.java new file mode 100644 index 000000000..d7f979bc0 --- /dev/null +++ b/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciRequest.java @@ -0,0 +1,144 @@ +/*- + * ============LICENSE_START======================================================= + * sdnr + * ================================================================================ + * Copyright (C) 2018 Wipro Limited Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.sdnr; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; + +public class PciRequest implements Serializable { + + private static final long serialVersionUID = 323235565922846624L; + + @SerializedName(value = "CommonHeader") + private PciCommonHeader commonHeader; + + @SerializedName(value = "Action") + private String action; + + @SerializedName(value = "Payload") + private String payload; + + public PciRequest() { + // Create a default PCI request + } + + public PciCommonHeader getCommonHeader() { + return commonHeader; + } + + public void setCommonHeader(PciCommonHeader commonHeader) { + this.commonHeader = commonHeader; + } + + /** + * Get the action. + * + * @return the action + */ + public String getAction() { + return action; + } + + /** + * Set the action. + * + * @param action + * the action to set + */ + public void setAction(String action) { + this.action = action; + } + + /** + * Get the payload. + * + * @return the payload + */ + + public String getPayload() { + return payload; + } + + /** + * Set the payload. + * + * @param action + * the action to set + */ + + public void setPayload(String payload) { + this.payload = payload; + } + + @Override + public String toString() { + return "PciRequest[commonHeader=" + commonHeader + ", action=" + action + ", payload=" + payload + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((commonHeader == null) ? 0 : commonHeader.hashCode()); + result = prime * result + ((action == null) ? 0 : action.hashCode()); + result = prime * result + ((payload == null) ? 0 : payload.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + PciRequest other = (PciRequest) obj; + if (commonHeader == null) { + if (other.commonHeader != null) { + return false; + } + } else if (!commonHeader.equals(other.commonHeader)) { + return false; + } + if (action == null) { + if (other.action != null) { + return false; + } + } else if (!action.equals(other.action)) { + return false; + } + if (payload == null) { + if (other.payload != null) { + return false; + } + } else if (!payload.equals(other.payload)) { + return false; + } + return true; + } + +} diff --git a/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciRequestWrapper.java b/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciRequestWrapper.java new file mode 100644 index 000000000..b8ce925f2 --- /dev/null +++ b/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciRequestWrapper.java @@ -0,0 +1,97 @@ +/*- + * ============LICENSE_START======================================================= + * sdnr + * ================================================================================ + * Copyright (C) 2018 Wipro Limited Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.sdnr; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; + +public class PciRequestWrapper extends PciWrapper implements Serializable { + + private static final long serialVersionUID = 879766924715980798L; + + @SerializedName(value = "body") + private PciRequest body; + + public PciRequestWrapper() { + super(); + } + + public PciRequestWrapper(PciRequest request) { + body = request; + } + + /** + * Get the body. + * + * @return the body + */ + public PciRequest getBody() { + return body; + } + + /** + * Set the body. + * + * @param body + * the body to set + */ + public void setBody(PciRequest body) { + this.body = body; + } + + @Override + public String toString() { + return "RequestWrapper [body=" + body + ", toString()=" + super.toString() + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((body == null) ? 0 : body.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!super.equals(obj)) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + PciRequestWrapper other = (PciRequestWrapper) obj; + if (body == null) { + if (other.body != null) { + return false; + } + } else if (!body.equals(other.body)) { + return false; + } + return true; + } + +} diff --git a/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciResponse.java b/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciResponse.java new file mode 100644 index 000000000..3cb4e8af6 --- /dev/null +++ b/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciResponse.java @@ -0,0 +1,160 @@ +/*- + * ============LICENSE_START======================================================= + * sdnr + * ================================================================================ + * Copyright (C) 2018 Wipro Limited Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.sdnr; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; + +public class PciResponse implements Serializable { + + private static final long serialVersionUID = 8375708697287669750L; + + @SerializedName(value = "CommonHeader") + private PciCommonHeader commonHeader; + + @SerializedName(value = "Status") + private Status status = new Status(); + + @SerializedName(value = "Payload") + private String payload; + + public PciResponse() { + // EMPTY + } + + /** + * Constructs a response using the common header of the request since they will + * be the same. + * + * @param request + * an sdnr Pci request object specified by the Pci api guide + */ + public PciResponse(PciRequest request) { + this.commonHeader = new PciCommonHeader(request.getCommonHeader()); + + } + + /** + * Get the common header. + * + * @return the commonHeader + */ + public PciCommonHeader getCommonHeader() { + return commonHeader; + } + + /** + * Set the common header. + * + * @param commonHeader + * the commonHeader to set + */ + public void setCommonHeader(PciCommonHeader commonHeader) { + this.commonHeader = commonHeader; + } + + /** + * Get the status. + * + * @return the status + */ + public Status getStatus() { + return status; + } + + /** + * Set the status. + * + * @param status + * the status to set + */ + public void setStatus(Status status) { + this.status = status; + } + + /** + * Get the payload. + * + * @return the payload + */ + + public String getPayload() { + return payload; + } + + public void setPayload(String payload) { + this.payload = payload; + } + + @Override + public String toString() { + return "PciResponse[CommonHeader=" + commonHeader + ", Status=" + status + ", Payload=" + + payload + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((commonHeader == null) ? 0 : commonHeader.hashCode()); + result = prime * result + ((payload == null) ? 0 : payload.hashCode()); + result = prime * result + ((status == null) ? 0 : status.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + PciResponse other = (PciResponse) obj; + if (commonHeader == null) { + if (other.commonHeader != null) { + return false; + } + } else if (!commonHeader.equals(other.commonHeader)) { + return false; + } + if (payload == null) { + if (other.payload != null) { + return false; + } + } else if (!payload.equals(other.payload)) { + return false; + } + if (status == null) { + if (other.status != null) { + return false; + } + } else if (!status.equals(other.status)) { + return false; + } + return true; + } +} diff --git a/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciResponseCode.java b/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciResponseCode.java new file mode 100644 index 000000000..35a85d779 --- /dev/null +++ b/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciResponseCode.java @@ -0,0 +1,65 @@ +/*- + * ============LICENSE_START======================================================= + * sdnr + * ================================================================================ + * Copyright (C) 2018 Wipro Limited Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2018 Samsung Electronics Co., Ltd. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.sdnr; + +import java.io.Serializable; +import org.onap.policy.sdnr.util.StatusCodeEnum; + +public class PciResponseCode implements Serializable { + + /* These fields define the key to the response code value. */ + public static final String ACCEPTED = "ACCEPTED"; + public static final String ERROR = "ERROR"; + public static final String REJECT = "REJECT"; + public static final String SUCCESS = "SUCCESS"; + public static final String FAILURE = "FAILURE"; + public static final String PARTIAL_SUCCESS = "PARTIAL SUCCESS"; + public static final String PARTIAL_FAILURE = "PARTIAL FAILURE"; + private static final long serialVersionUID = -5371924429933449763L; + + private final Integer code; + + protected PciResponseCode(final int code) { + this.code = code; + } + + public int getCode() { + return this.code; + } + + @Override + public String toString() { + return Integer.toString(this.code); + } + + /** + * Translates the code to a string value that represents the meaning of the code. + * + * @param code the numeric value that is returned by SDNR based on success, failure, etc. of the action requested + * @return the string value equivalent of the SDNR response code + */ + public static String toResponseValue(int code) { + StatusCodeEnum statusCodeEnum = StatusCodeEnum.fromStatusCode(code); + return (statusCodeEnum != null) ? statusCodeEnum.toString() : null; + } +} diff --git a/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciResponseWrapper.java b/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciResponseWrapper.java new file mode 100644 index 000000000..98eeed221 --- /dev/null +++ b/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciResponseWrapper.java @@ -0,0 +1,92 @@ +/*- + * ============LICENSE_START======================================================= + * sdnr + * ================================================================================ + * Copyright (C) 2018 Wipro Limited Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.sdnr; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; + +public class PciResponseWrapper extends PciWrapper implements Serializable { + + private static final long serialVersionUID = 109837814781086802L; + + @SerializedName(value = "body") + private PciResponse body; + + public PciResponseWrapper() { + super(); + } + + /** + * Get the body. + * + * @return the body + */ + public PciResponse getBody() { + return body; + } + + /** + * Set the body. + * + * @param body + * the body to set + */ + public void setBody(PciResponse body) { + this.body = body; + } + + @Override + public String toString() { + return "ResponseWrapper [body=" + body + ", toString()=" + super.toString() + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((body == null) ? 0 : body.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!super.equals(obj)) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + PciResponseWrapper other = (PciResponseWrapper) obj; + if (body == null) { + if (other.body != null) { + return false; + } + } else if (!body.equals(other.body)) { + return false; + } + return true; + } +} diff --git a/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciWrapper.java b/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciWrapper.java new file mode 100644 index 000000000..7b8b5b1c1 --- /dev/null +++ b/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciWrapper.java @@ -0,0 +1,214 @@ +/*- + * ============LICENSE_START======================================================= + * sdnr + * ================================================================================ + * Copyright (C) 2018 Wipro Limited Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.sdnr; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; + +public class PciWrapper implements Serializable { + + private static final long serialVersionUID = 375215806432396532L; + + @SerializedName(value = "version") + private String version; + + @SerializedName(value = "cambria-partition") + private String cambriaPartition; + + @SerializedName(value = "rpc-name") + private String rpcName; + + @SerializedName(value = "correlation-id") + private String correlationId; + + @SerializedName(value = "type") + private String type; + + public PciWrapper() { + // Create a default PciWrapper instance + } + + /** + * Get the version. + * + * @return the version + */ + public String getVersion() { + return version; + } + + /** + * Set the version. + * + * @param version + * the version to set + */ + public void setVersion(String version) { + this.version = version; + } + + /** + * Get the cambria partition. + * + * @return the cambriaPartition + */ + public String getCambriaPartition() { + return cambriaPartition; + } + + /** + * Set the cambria partition. + * + * @param cambriaPartition + * the cambriaPartition to set + */ + public void setCambriaPartition(String cambriaPartition) { + this.cambriaPartition = cambriaPartition; + } + + /** + * Get the RPN name. + * + * @return the rpcName + */ + public String getRpcName() { + return rpcName; + } + + /** + * Set the RPC name. + * + * @param rpcName + * the rpcName to set + */ + public void setRpcName(String rpcName) { + this.rpcName = rpcName; + } + + /** + * Get the correlation Id. + * + * @return the correlationId + */ + public String getCorrelationId() { + return correlationId; + } + + /** + * Set the correclation Id. + * + * @param correlationId + * the correlationId to set + */ + public void setCorrelationId(String correlationId) { + this.correlationId = correlationId; + } + + /** + * Get the type. + * + * @return the type + */ + public String getType() { + return type; + } + + /** + * Set the type. + * + * @param type + * the type to set + */ + public void setType(String type) { + this.type = type; + } + + @Override + public String toString() { + return "Wrapper [version=" + version + ", cambriaPartition=" + cambriaPartition + ", rpcName=" + rpcName + + ", correlationId=" + correlationId + ", type=" + type + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((cambriaPartition == null) ? 0 : cambriaPartition.hashCode()); + result = prime * result + ((correlationId == null) ? 0 : correlationId.hashCode()); + result = prime * result + ((rpcName == null) ? 0 : rpcName.hashCode()); + result = prime * result + ((type == null) ? 0 : type.hashCode()); + result = prime * result + ((version == null) ? 0 : version.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + PciWrapper other = (PciWrapper) obj; + if (cambriaPartition == null) { + if (other.cambriaPartition != null) { + return false; + } + } else if (!cambriaPartition.equals(other.cambriaPartition)) { + return false; + } + if (correlationId == null) { + if (other.correlationId != null) { + return false; + } + } else if (!correlationId.equals(other.correlationId)) { + return false; + } + if (rpcName == null) { + if (other.rpcName != null) { + return false; + } + } else if (!rpcName.equals(other.rpcName)) { + return false; + } + if (type == null) { + if (other.type != null) { + return false; + } + } else if (!type.equals(other.type)) { + return false; + } + if (version == null) { + if (other.version != null) { + return false; + } + } else if (!version.equals(other.version)) { + return false; + } + return true; + } + +} diff --git a/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/Status.java b/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/Status.java new file mode 100644 index 000000000..b4fead1d3 --- /dev/null +++ b/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/Status.java @@ -0,0 +1,107 @@ +/*- + * ============LICENSE_START======================================================= + * sdnr + * ================================================================================ + * Copyright (C) 2018 Wipro Limited Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.sdnr; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; + +public class Status implements Serializable { + + private static final long serialVersionUID = 877641506135467199L; + + @SerializedName(value = "Code") + private int code; + + @SerializedName(value = "Value") + private String value; + + public Status() { + // Create a default PciResponseStatus instance + } + + /** + * Constructor for the class Status. + * + */ + public Status(int code, String value) { + super(); + this.code = code; + this.value = value; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + @Override + public String toString() { + return "Status [code = " + code + ", value = " + value + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + code; + result = prime * result + ((value == null) ? 0 : value.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + Status other = (Status) obj; + if (code != other.code) { + return false; + } + if (value == null) { + if (other.value != null) { + return false; + } + } else if (!value.equals(other.value)) { + return false; + } + return true; + } + +} diff --git a/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/util/Serialization.java b/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/util/Serialization.java new file mode 100644 index 000000000..2acb6e8b2 --- /dev/null +++ b/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/util/Serialization.java @@ -0,0 +1,116 @@ +/*- + * ============LICENSE_START======================================================= + * sdnr + * ================================================================================ + * Copyright (C) 2018 Wipro Limited Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2018 AT&T Intellectual Property. 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.policy.sdnr.util; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonPrimitive; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; + +import java.lang.reflect.Type; +import java.time.Instant; + +import org.onap.policy.sdnr.PciRequest; +import org.onap.policy.sdnr.PciResponse; + + +public final class Serialization { + public static final Gson gsonPretty = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting() + .registerTypeAdapter(Instant.class, new InstantAdapter()).create(); + + public static final Gson gson = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting() + .registerTypeAdapter(PciRequest.class, new RequestAdapter()) + .registerTypeAdapter(PciResponse.class, new ResponseAdapter()).create(); + + public static final Gson gsonJunit = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting() + .registerTypeAdapter(Instant.class, new InstantJunitAdapter()).create(); + + private Serialization() {} + + public static class RequestAdapter implements JsonSerializer<PciRequest>, JsonDeserializer<PciRequest> { + + @Override + public JsonElement serialize(PciRequest src, Type typeOfSrc, JsonSerializationContext context) { + JsonElement requestJson = gsonPretty.toJsonTree(src, PciRequest.class); + JsonObject input = new JsonObject(); + input.add("input", requestJson); + + return input; + } + + @Override + public PciRequest deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { + return gsonPretty.fromJson(json.getAsJsonObject().get("input"), PciRequest.class); + } + } + + public static class ResponseAdapter implements JsonSerializer<PciResponse>, JsonDeserializer<PciResponse> { + + @Override + public JsonElement serialize(PciResponse src, Type typeOfSrc, JsonSerializationContext context) { + JsonElement responseJson = gsonPretty.toJsonTree(src, PciResponse.class); + JsonObject output = new JsonObject(); + output.add("output", responseJson); + return output; + } + + @Override + public PciResponse deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { + return gsonPretty.fromJson(json.getAsJsonObject().get("output"), PciResponse.class); + } + } + + public static class InstantAdapter implements JsonSerializer<Instant>, JsonDeserializer<Instant> { + + @Override + public Instant deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { + return Instant.parse(json.getAsString()); + } + + @Override + public JsonElement serialize(Instant src, Type typeOfSrc, JsonSerializationContext context) { + return new JsonPrimitive(src.toString()); + } + + } + + public static class InstantJunitAdapter implements JsonSerializer<Instant>, JsonDeserializer<Instant> { + + @Override + public Instant deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { + return Instant.ofEpochMilli(json.getAsLong()); + } + + @Override + public JsonElement serialize(Instant src, Type typeOfSrc, JsonSerializationContext context) { + return new JsonPrimitive(src.toEpochMilli()); + } + + } + +} diff --git a/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/util/StatusCodeEnum.java b/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/util/StatusCodeEnum.java new file mode 100644 index 000000000..483062d6f --- /dev/null +++ b/models-interactions/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/util/StatusCodeEnum.java @@ -0,0 +1,89 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.sdnr.util; + +public enum StatusCodeEnum { + ACCEPTED("ACCEPTED"), ERROR("ERROR"), REJECT("REJECT"), SUCCESS("SUCCESS"), FAILURE("FAILURE"), + PARTIAL_SUCCESS("PARTIAL SUCCESS"), PARTIAL_FAILURE("PARTIAL FAILURE"); + + private String name; + + StatusCodeEnum(final String name) { + this.name = name; + } + + @Override + public String toString() { + return this.name; + } + + /** + * Determine status enum from the code. + * + * @param statusCode integer code indicating the status + * @return enum representation of status code + */ + public static StatusCodeEnum fromStatusCode(final int statusCode) { + if (statusCode == 100) { + return ACCEPTED; + } + + if (statusCode == 200) { + return SUCCESS; + } + + if (isRejectStatusCode(statusCode)) { + return REJECT; + } + + if (statusCode == 400) { + return ERROR; + } + + if (isFailureStatusCode(statusCode)) { + return FAILURE; + } + + if (statusCode == 500) { + return PARTIAL_SUCCESS; + } + + if (isPartialFailureStatusCode(statusCode)) { + return PARTIAL_FAILURE; + } + + return null; + } + + private static boolean isRejectStatusCode(final int statusCode) { + return statusCode >= 300 && statusCode <= 313; + } + + private static boolean isFailureStatusCode(final int statusCode) { + return statusCode == 450 || (statusCode >= 401 && statusCode <= 406); + } + + private static boolean isPartialFailureStatusCode(final int statusCode) { + return statusCode >= 501 && statusCode <= 599; + } + +} diff --git a/models-interactions/model-impl/sdnr/src/main/resources/definitions.yaml b/models-interactions/model-impl/sdnr/src/main/resources/definitions.yaml new file mode 100644 index 000000000..245569be2 --- /dev/null +++ b/models-interactions/model-impl/sdnr/src/main/resources/definitions.yaml @@ -0,0 +1,119 @@ +### +# ============LICENSE_START======================================================= +# sdnr +# ================================================================================ +# Copyright (C) 2018 Wipro Limited Intellectual Property. All rights reserved. +# Modifications Copyright (C) 2019 Nordix Foundation. +# ================================================================================ +# 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========================================================= +### + +Request: + type: object + properties: + CommonHeader: + type: object + properties: + TimeStamp: + type: string + APIver: + type: string + value: '1.01' + OriginatorID: + type: string + RequestID: + type: string + pattern: "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$" + SubRequestID: + type: string + Flags: + type: object + required: + - TimeStamp + - APIver + - OriginatorID + - RequestID + Action: + type: string + enum: + - Audit + - ActionStatus + - BlockAudits + - Configure + - HealthCheck + - Install + - LiveUpgrade + - Migrate + - ModifyConfig + - Query + - Rebuild + - Reconfigure + - Restart + - Rollback + - Scale + - Start + - Stop + - Sync + - Terminate + - Test + - Upgrade + TargetID: + type: string + ObjectID: + type: string + Payload: + type: object + required: + - CommonHeader + - Action + - TargetID +Response: + type: object + properties: + CommonHeader: + type: object + properties: + TimeStamp: + type: string + APIver: + type: string + OriginatorID: + type: string + RequestID: + type: string + SubRequestID: + type: string + Flags: + type: object + required: + - TimeStamp + - APIver + - OriginatorID + - RequestID + Status: + type: object + properties: + Code: + type: integer + Value: + type: string + required: + - Code + - Value + Payload: + type: object + required: + - CommonHeader + - Status + diff --git a/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciCommonHeaderTest.java b/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciCommonHeaderTest.java new file mode 100644 index 000000000..c31e9461e --- /dev/null +++ b/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciCommonHeaderTest.java @@ -0,0 +1,145 @@ +/*- + * ============LICENSE_START======================================================= + * sdnr + * ================================================================================ + * Copyright (C) 2018 Wipro Limited Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.sdnr; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.time.Instant; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +import org.junit.Test; + +public class PciCommonHeaderTest { + + @Test + public void testPciCommonHeader() { + PciCommonHeader commonHeader = new PciCommonHeader(); + assertNotNull(commonHeader); + assertNotNull(new PciCommonHeader(commonHeader)); + assertNotEquals(0, commonHeader.hashCode()); + + commonHeader.setApiVer("Kansas"); + assertEquals("Kansas", commonHeader.getApiVer()); + + Map<String, String> flagMap = new HashMap<>(); + commonHeader.setFlags(flagMap); + assertEquals(flagMap, commonHeader.getFlags()); + + Map<String, String> requestMap = new HashMap<>(); + commonHeader.setRequestTrack(requestMap); + assertEquals(requestMap, commonHeader.getRequestTrack()); + + UUID requestId = UUID.randomUUID(); + commonHeader.setRequestId(requestId); + assertEquals(requestId, commonHeader.getRequestId()); + + commonHeader.setSubRequestId("Can I go home?"); + assertEquals("Can I go home?", commonHeader.getSubRequestId()); + + Instant timestamp = Instant.now(); + commonHeader.setTimeStamp(timestamp); + assertEquals(timestamp, commonHeader.getTimeStamp()); + + assertNotEquals(0, commonHeader.hashCode()); + + assertEquals("CommonHeader [timeStamp=", commonHeader.toString().substring(0, 24)); + + PciCommonHeader copiedPciCommonHeader = new PciCommonHeader(); + copiedPciCommonHeader.setApiVer(commonHeader.getApiVer()); + copiedPciCommonHeader.setFlags(commonHeader.getFlags()); + copiedPciCommonHeader.setRequestId(commonHeader.getRequestId()); + copiedPciCommonHeader.setSubRequestId(commonHeader.getSubRequestId()); + copiedPciCommonHeader.setTimeStamp(commonHeader.getTimeStamp()); + + assertTrue(commonHeader.equals(commonHeader)); + assertTrue(commonHeader.equals(copiedPciCommonHeader)); + assertFalse(commonHeader.equals(null)); + assertFalse(commonHeader.equals("Hello")); + + PciCommonHeader clonedPciCommonHeader = new PciCommonHeader(commonHeader); + clonedPciCommonHeader.setApiVer(commonHeader.getApiVer()); + clonedPciCommonHeader.setTimeStamp(commonHeader.getTimeStamp()); + + assertTrue(commonHeader.equals(clonedPciCommonHeader)); + + commonHeader.setApiVer(null); + assertFalse(commonHeader.equals(copiedPciCommonHeader)); + copiedPciCommonHeader.setApiVer(null); + assertTrue(commonHeader.equals(copiedPciCommonHeader)); + commonHeader.setApiVer("Kansas"); + assertFalse(commonHeader.equals(copiedPciCommonHeader)); + copiedPciCommonHeader.setApiVer("Kansas"); + assertTrue(commonHeader.equals(copiedPciCommonHeader)); + + commonHeader.setFlags(null); + assertFalse(commonHeader.equals(copiedPciCommonHeader)); + copiedPciCommonHeader.setFlags(null); + assertTrue(commonHeader.equals(copiedPciCommonHeader)); + commonHeader.setFlags(flagMap); + assertFalse(commonHeader.equals(copiedPciCommonHeader)); + copiedPciCommonHeader.setFlags(flagMap); + assertTrue(commonHeader.equals(copiedPciCommonHeader)); + + commonHeader.setRequestTrack(null); + assertFalse(commonHeader.equals(copiedPciCommonHeader)); + copiedPciCommonHeader.setRequestTrack(null); + assertTrue(commonHeader.equals(copiedPciCommonHeader)); + commonHeader.setRequestTrack(requestMap); + assertFalse(commonHeader.equals(copiedPciCommonHeader)); + copiedPciCommonHeader.setRequestTrack(requestMap); + assertTrue(commonHeader.equals(copiedPciCommonHeader)); + + + commonHeader.setRequestId(null); + assertFalse(commonHeader.equals(copiedPciCommonHeader)); + copiedPciCommonHeader.setRequestId(null); + assertTrue(commonHeader.equals(copiedPciCommonHeader)); + commonHeader.setRequestId(requestId); + assertFalse(commonHeader.equals(copiedPciCommonHeader)); + copiedPciCommonHeader.setRequestId(requestId); + assertTrue(commonHeader.equals(copiedPciCommonHeader)); + + commonHeader.setSubRequestId(null); + assertFalse(commonHeader.equals(copiedPciCommonHeader)); + copiedPciCommonHeader.setSubRequestId(null); + assertTrue(commonHeader.equals(copiedPciCommonHeader)); + commonHeader.setSubRequestId("Can I go home?"); + assertFalse(commonHeader.equals(copiedPciCommonHeader)); + copiedPciCommonHeader.setSubRequestId("Can I go home?"); + assertTrue(commonHeader.equals(copiedPciCommonHeader)); + + commonHeader.setTimeStamp(null); + assertFalse(commonHeader.equals(copiedPciCommonHeader)); + copiedPciCommonHeader.setTimeStamp(null); + assertTrue(commonHeader.equals(copiedPciCommonHeader)); + commonHeader.setTimeStamp(timestamp); + assertFalse(commonHeader.equals(copiedPciCommonHeader)); + copiedPciCommonHeader.setTimeStamp(timestamp); + assertTrue(commonHeader.equals(copiedPciCommonHeader)); + } +} diff --git a/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciRequestTest.java b/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciRequestTest.java new file mode 100644 index 000000000..e73d1973d --- /dev/null +++ b/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciRequestTest.java @@ -0,0 +1,93 @@ +/*- + * ============LICENSE_START======================================================= + * sdnr + * ================================================================================ + * Copyright (C) 2018 Wipro Limited Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.sdnr; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +public class PciRequestTest { + + @Test + public void testPciRequest() { + PciRequest request = new PciRequest(); + assertNotNull(request); + assertNotEquals(0, request.hashCode()); + + PciCommonHeader commonHeader = new PciCommonHeader(); + String requestPayload = ""; + + request.setCommonHeader(commonHeader); + assertEquals(commonHeader, request.getCommonHeader()); + + request.setPayload(requestPayload); + assertEquals(requestPayload, request.getPayload()); + + request.setAction("Modify"); + assertEquals("Modify", request.getAction()); + + assertNotEquals(0, request.hashCode()); + + assertEquals("PciRequest[commonHeader=CommonHeader [timeStamp=", request.toString().substring(0, 48)); + + PciRequest copiedPciRequest = new PciRequest(); + copiedPciRequest.setCommonHeader(request.getCommonHeader()); + copiedPciRequest.setAction(request.getAction()); + copiedPciRequest.setPayload(request.getPayload()); + + assertTrue(request.equals(request)); + assertTrue(request.equals(copiedPciRequest)); + assertFalse(request.equals(null)); + assertFalse(request.equals("Hello")); + + request.setCommonHeader(null); + assertFalse(request.equals(copiedPciRequest)); + copiedPciRequest.setCommonHeader(null); + assertTrue(request.equals(copiedPciRequest)); + request.setCommonHeader(commonHeader); + assertFalse(request.equals(copiedPciRequest)); + copiedPciRequest.setCommonHeader(commonHeader); + assertTrue(request.equals(copiedPciRequest)); + + request.setAction(null); + assertFalse(request.equals(copiedPciRequest)); + copiedPciRequest.setAction(null); + assertTrue(request.equals(copiedPciRequest)); + request.setAction("Modify"); + assertFalse(request.equals(copiedPciRequest)); + copiedPciRequest.setAction("Modify"); + assertTrue(request.equals(copiedPciRequest)); + + request.setPayload(null); + assertFalse(request.equals(copiedPciRequest)); + copiedPciRequest.setPayload(null); + assertTrue(request.equals(copiedPciRequest)); + request.setPayload(requestPayload); + assertFalse(request.equals(copiedPciRequest)); + copiedPciRequest.setPayload(requestPayload); + assertTrue(request.equals(copiedPciRequest)); + } +} diff --git a/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciRequestWrapperTest.java b/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciRequestWrapperTest.java new file mode 100644 index 000000000..0b839a861 --- /dev/null +++ b/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciRequestWrapperTest.java @@ -0,0 +1,67 @@ +/*- + * ============LICENSE_START======================================================= + * sdnr + * ================================================================================ + * Copyright (C) 2018 Wipro Limited Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.sdnr; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +public class PciRequestWrapperTest { + + @Test + public void testPciRequestWrapperWrapper() { + assertNotNull(new PciRequestWrapper(new PciRequest())); + PciRequestWrapper requestWrapper = new PciRequestWrapper(); + assertNotNull(requestWrapper); + assertNotEquals(0, requestWrapper.hashCode()); + + PciRequest request = new PciRequest(); + + requestWrapper.setBody(request); + assertEquals(request, requestWrapper.getBody()); + + assertNotEquals(0, requestWrapper.hashCode()); + + assertEquals("RequestWrapper [body=PciRequest[commonHeader=nul", requestWrapper.toString().substring(0, 48)); + + PciRequestWrapper copiedPciRequestWrapper = new PciRequestWrapper(); + copiedPciRequestWrapper.setBody(requestWrapper.getBody()); + + assertTrue(requestWrapper.equals(requestWrapper)); + assertTrue(requestWrapper.equals(copiedPciRequestWrapper)); + assertFalse(requestWrapper.equals(null)); + assertFalse(requestWrapper.equals("Hello")); + + requestWrapper.setBody(null); + assertFalse(requestWrapper.equals(copiedPciRequestWrapper)); + copiedPciRequestWrapper.setBody(null); + assertTrue(requestWrapper.equals(copiedPciRequestWrapper)); + requestWrapper.setBody(request); + assertFalse(requestWrapper.equals(copiedPciRequestWrapper)); + copiedPciRequestWrapper.setBody(request); + assertTrue(requestWrapper.equals(copiedPciRequestWrapper)); + } +} diff --git a/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciResponseCodeTest.java b/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciResponseCodeTest.java new file mode 100644 index 000000000..e7667ddf7 --- /dev/null +++ b/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciResponseCodeTest.java @@ -0,0 +1,56 @@ +/*- + * ============LICENSE_START======================================================= + * sdnr + * ================================================================================ + * Copyright (C) 2018 Wipro Limited Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.sdnr; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import org.junit.Test; + +public class PciResponseCodeTest { + + @Test + public void testPciResponseCode() { + assertNull(PciResponseCode.toResponseValue(0)); + + assertEquals(PciResponseCode.ACCEPTED, PciResponseCode.toResponseValue(100)); + assertEquals(PciResponseCode.SUCCESS, PciResponseCode.toResponseValue(200)); + assertEquals(PciResponseCode.REJECT, PciResponseCode.toResponseValue(300)); + assertEquals(PciResponseCode.ERROR, PciResponseCode.toResponseValue(400)); + assertEquals(PciResponseCode.FAILURE, PciResponseCode.toResponseValue(450)); + assertEquals(PciResponseCode.FAILURE, PciResponseCode.toResponseValue(401)); + assertEquals(PciResponseCode.FAILURE, PciResponseCode.toResponseValue(406)); + assertEquals(PciResponseCode.PARTIAL_SUCCESS, PciResponseCode.toResponseValue(500)); + assertEquals(PciResponseCode.PARTIAL_FAILURE, PciResponseCode.toResponseValue(501)); + assertEquals(PciResponseCode.PARTIAL_FAILURE, PciResponseCode.toResponseValue(599)); + + assertEquals("100", new PciResponseCode(100).toString()); + assertEquals("200", new PciResponseCode(200).toString()); + assertEquals("300", new PciResponseCode(300).toString()); + assertEquals("400", new PciResponseCode(400).toString()); + assertEquals("450", new PciResponseCode(450).toString()); + assertEquals("500", new PciResponseCode(500).toString()); + assertEquals("510", new PciResponseCode(510).toString()); + + assertEquals(300, new PciResponseCode(300).getCode()); + } +} diff --git a/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciResponseTest.java b/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciResponseTest.java new file mode 100644 index 000000000..b9ecec33c --- /dev/null +++ b/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciResponseTest.java @@ -0,0 +1,118 @@ +/*- + * ============LICENSE_START======================================================= + * sdnr + * ================================================================================ + * Copyright (C) 2018 Wipro Limited Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.sdnr; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +public class PciResponseTest { + + Status status = new Status(0, ""); + + String responsePayload = ""; + String requestPayload = ""; + + + @Test + public void testHashCode() { + PciResponse response = new PciResponse(); + assertTrue(response.hashCode() != 0); + response.setCommonHeader(new PciCommonHeader()); + assertTrue(response.hashCode() != 0); + response.setPayload(responsePayload); + assertTrue(response.hashCode() != 0); + response.setStatus(null); + assertTrue(response.hashCode() != 0); + } + + @Test + public void testPciResponse() { + PciResponse response = new PciResponse(); + assertNull(response.getCommonHeader()); + assertNull(response.getPayload()); + assertNotNull(response.getStatus()); + } + + @Test + public void testToString() { + PciResponse response = new PciResponse(); + assertFalse(response.toString().isEmpty()); + } + + @Test + public void testEqualsObject() { + PciResponse response = new PciResponse(); + assertTrue(response.equals(response)); + assertFalse(response.equals(null)); + assertFalse(response.equals(new Object())); + + PciResponse response2 = new PciResponse(); + assertTrue(response.equals(response2)); + + response.setCommonHeader(new PciCommonHeader()); + assertFalse(response.equals(response2)); + response2.setCommonHeader(response.getCommonHeader()); + assertTrue(response.equals(response2)); + + response.setPayload(responsePayload); + assertFalse(response.equals(response2)); + response2.setPayload(response.getPayload()); + assertTrue(response.equals(response2)); + + response.setCommonHeader(null); + assertFalse(response.equals(response2)); + response2.setCommonHeader(null); + assertTrue(response.equals(response2)); + + response.setPayload(null); + assertFalse(response.equals(response2)); + response2.setPayload(response.getPayload()); + assertTrue(response.equals(response2)); + + response.setStatus(null); + assertFalse(response.equals(response2)); + response2.setStatus(response.getStatus()); + assertTrue(response.equals(response2)); + + Status status = new Status(); + status.setCode(5); + response.setStatus(status); + response2.setStatus(new Status()); + assertFalse(response.equals(response2)); + } + + @Test + public void testResponseRequest() { + PciRequest request = new PciRequest(); + request.setCommonHeader(new PciCommonHeader()); + request.setPayload(requestPayload); + + PciResponse response = new PciResponse(request); + + assertTrue(response.getCommonHeader().equals(request.getCommonHeader())); + } + +} diff --git a/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciResponseWrapperTest.java b/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciResponseWrapperTest.java new file mode 100644 index 000000000..0673fc036 --- /dev/null +++ b/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciResponseWrapperTest.java @@ -0,0 +1,67 @@ +/*- + * ============LICENSE_START======================================================= + * sdnr + * ================================================================================ + * Copyright (C) 2018 Wipro Limited Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.sdnr; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +public class PciResponseWrapperTest { + + @Test + public void testPciResponseWrapperWrapper() { + + PciResponseWrapper responseWrapper = new PciResponseWrapper(); + assertNotNull(responseWrapper); + assertNotEquals(0, responseWrapper.hashCode()); + + PciResponse response = new PciResponse(); + + responseWrapper.setBody(response); + assertEquals(response, responseWrapper.getBody()); + + assertNotEquals(0, responseWrapper.hashCode()); + + assertNotEquals("ResponseWrapper [body=Response [commonHeader=n", responseWrapper.toString().substring(0, 46)); + + PciResponseWrapper copiedPciResponseWrapper = new PciResponseWrapper(); + copiedPciResponseWrapper.setBody(responseWrapper.getBody()); + + assertTrue(responseWrapper.equals(responseWrapper)); + //assertTrue(responseWrapper.equals(copiedPciResponseWrapper)); + assertFalse(responseWrapper.equals(null)); + assertFalse(responseWrapper.equals("Hello")); + + responseWrapper.setBody(null); + assertFalse(responseWrapper.equals(copiedPciResponseWrapper)); + copiedPciResponseWrapper.setBody(null); + //assertTrue(responseWrapper.equals(copiedPciResponseWrapper)); + responseWrapper.setBody(response); + //assertFalse(responseWrapper.equals(copiedPciResponseWrapper)); + copiedPciResponseWrapper.setBody(response); + //assertTrue(responseWrapper.equals(copiedPciResponseWrapper)); + } +} diff --git a/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciStatusTest.java b/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciStatusTest.java new file mode 100644 index 000000000..594f9620d --- /dev/null +++ b/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciStatusTest.java @@ -0,0 +1,75 @@ +/*- + * ============LICENSE_START======================================================= + * sdnr + * ================================================================================ + * Copyright (C) 2018 Wipro Limited Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.sdnr; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +public class PciStatusTest { + + @Test + public void testResponseStatus() { + Status status = new Status(); + assertNotNull(status); + assertNotEquals(0, status.hashCode()); + + status.setCode(1234); + assertEquals(1234, status.getCode()); + + status.setValue("The wonderful land of Oz"); + assertEquals("The wonderful land of Oz", status.getValue()); + + assertEquals("Status [code = 1234, value = The wonderfu", status.toString().substring(0, 41)); + + Status copiedStatus = new Status(); + copiedStatus.setCode(status.getCode()); + copiedStatus.setValue(status.getValue()); + + assertTrue(status.equals(status)); + assertTrue(status.equals(copiedStatus)); + assertFalse(status.equals(null)); + assertFalse(status.equals("Hello")); + + status.setCode(-1); + assertFalse(status.equals(copiedStatus)); + copiedStatus.setCode(-1); + assertTrue(status.equals(copiedStatus)); + status.setCode(1234); + assertFalse(status.equals(copiedStatus)); + copiedStatus.setCode(1234); + assertTrue(status.equals(copiedStatus)); + + status.setValue(null); + assertFalse(status.equals(copiedStatus)); + copiedStatus.setValue(null); + assertTrue(status.equals(copiedStatus)); + status.setValue("The wonderful land of Oz"); + assertFalse(status.equals(copiedStatus)); + copiedStatus.setValue("The wonderful land of Oz"); + assertTrue(status.equals(copiedStatus)); + } +} diff --git a/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciWrapperTest.java b/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciWrapperTest.java new file mode 100644 index 000000000..e9d1cd673 --- /dev/null +++ b/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciWrapperTest.java @@ -0,0 +1,116 @@ +/*- + * ============LICENSE_START======================================================= + * sdnr + * ================================================================================ + * Copyright (C) 2018 Wipro Limited Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.sdnr; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +public class PciWrapperTest { + + @Test + public void testPciWrapper() { + PciWrapper wrapper = new PciWrapper(); + assertNotNull(wrapper); + assertNotEquals(0, wrapper.hashCode()); + + wrapper.setVersion("19.3.9"); + assertEquals("19.3.9", wrapper.getVersion()); + + wrapper.setCambriaPartition("The Emerald City"); + assertEquals("The Emerald City", wrapper.getCambriaPartition()); + + wrapper.setRpcName("Tornado"); + assertEquals("Tornado", wrapper.getRpcName()); + + wrapper.setCorrelationId("YellowBrickRoad"); + assertEquals("YellowBrickRoad", wrapper.getCorrelationId()); + + wrapper.setType("Munchkin"); + assertEquals("Munchkin", wrapper.getType()); + + assertNotEquals(0, wrapper.hashCode()); + + assertEquals("Wrapper [version=19.3.9, cambriaPartition=The ", wrapper.toString().substring(0, 46)); + + PciWrapper copiedPciWrapper = new PciWrapper(); + copiedPciWrapper.setVersion(wrapper.getVersion()); + copiedPciWrapper.setCambriaPartition(wrapper.getCambriaPartition()); + copiedPciWrapper.setRpcName(wrapper.getRpcName()); + copiedPciWrapper.setCorrelationId(wrapper.getCorrelationId()); + copiedPciWrapper.setType(wrapper.getType()); + + assertTrue(wrapper.equals(wrapper)); + assertTrue(wrapper.equals(copiedPciWrapper)); + assertFalse(wrapper.equals(null)); + assertFalse(wrapper.equals("Hello")); + + wrapper.setVersion(null); + assertFalse(wrapper.equals(copiedPciWrapper)); + copiedPciWrapper.setVersion(null); + assertTrue(wrapper.equals(copiedPciWrapper)); + wrapper.setVersion("19.3.9"); + assertFalse(wrapper.equals(copiedPciWrapper)); + copiedPciWrapper.setVersion("19.3.9"); + assertTrue(wrapper.equals(copiedPciWrapper)); + + wrapper.setCambriaPartition(null); + assertFalse(wrapper.equals(copiedPciWrapper)); + copiedPciWrapper.setCambriaPartition(null); + assertTrue(wrapper.equals(copiedPciWrapper)); + wrapper.setCambriaPartition("The Emerald City"); + assertFalse(wrapper.equals(copiedPciWrapper)); + copiedPciWrapper.setCambriaPartition("The Emerald City"); + assertTrue(wrapper.equals(copiedPciWrapper)); + + wrapper.setRpcName(null); + assertFalse(wrapper.equals(copiedPciWrapper)); + copiedPciWrapper.setRpcName(null); + assertTrue(wrapper.equals(copiedPciWrapper)); + wrapper.setRpcName("Tornado"); + assertFalse(wrapper.equals(copiedPciWrapper)); + copiedPciWrapper.setRpcName("Tornado"); + assertTrue(wrapper.equals(copiedPciWrapper)); + + wrapper.setCorrelationId(null); + assertFalse(wrapper.equals(copiedPciWrapper)); + copiedPciWrapper.setCorrelationId(null); + assertTrue(wrapper.equals(copiedPciWrapper)); + wrapper.setCorrelationId("YellowBrickRoad"); + assertFalse(wrapper.equals(copiedPciWrapper)); + copiedPciWrapper.setCorrelationId("YellowBrickRoad"); + assertTrue(wrapper.equals(copiedPciWrapper)); + + wrapper.setType(null); + assertFalse(wrapper.equals(copiedPciWrapper)); + copiedPciWrapper.setType(null); + assertTrue(wrapper.equals(copiedPciWrapper)); + wrapper.setType("Munchkin"); + assertFalse(wrapper.equals(copiedPciWrapper)); + copiedPciWrapper.setType("Munchkin"); + assertTrue(wrapper.equals(copiedPciWrapper)); + } +} diff --git a/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/SdnrTest.java b/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/SdnrTest.java new file mode 100644 index 000000000..8a32f0a25 --- /dev/null +++ b/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/SdnrTest.java @@ -0,0 +1,216 @@ +/*- + * ============LICENSE_START======================================================= + * sdnr + * ================================================================================ + * Copyright (C) 2018 Wipro Limited Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.sdnr; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.util.UUID; + +import org.junit.Test; +import org.onap.policy.sdnr.util.Serialization; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SdnrTest { + + private static final Logger logger = LoggerFactory.getLogger(SdnrTest.class); + + private static PciRequestWrapper dmaapRequest; + private static PciResponseWrapper dmaapResponse; + + static { + /* + * Construct an SDNR Request to be Serialized + */ + dmaapRequest = new PciRequestWrapper(); + dmaapRequest.setCorrelationId("664be3d2-6c12-4f4b-a3e7-c349acced200" + "-" + "1"); + dmaapRequest.setRpcName("restart"); + dmaapRequest.setType("request"); + + dmaapResponse = new PciResponseWrapper(); + dmaapResponse.setCorrelationId("664be3d2-6c12-4f4b-a3e7-c349acced200" + "-" + "1"); + dmaapResponse.setRpcName("restart"); + dmaapResponse.setType("response"); + + PciRequest sdnrRequest = new PciRequest(); + + sdnrRequest.setAction("ModifyConfig"); + + PciCommonHeader commonHeader = new PciCommonHeader(); + commonHeader.setRequestId(UUID.fromString("664be3d2-6c12-4f4b-a3e7-c349acced200")); + commonHeader.setSubRequestId("1"); + + sdnrRequest.setCommonHeader(commonHeader); + + sdnrRequest.setPayload(null); + + dmaapRequest.setBody(sdnrRequest); + + /* + * Construct an SDNR Response to be Serialized + */ + PciResponse sdnrResponse = new PciResponse(sdnrRequest); + sdnrResponse.getStatus().setCode(400); + sdnrResponse.getStatus().setValue("Restart Successful"); + sdnrResponse.setPayload(null); + + dmaapResponse.setBody(sdnrResponse); + } + + @Test + public void testRequestSerialization() { + + /* + * Use the gson serializer to obtain json + */ + String jsonRequest = Serialization.gson.toJson(dmaapRequest, PciRequestWrapper.class); + assertNotNull(jsonRequest); + + /* + * The serializer should have added an extra sub-tag called "input" that wraps the request + */ + assertTrue(jsonRequest.contains("input")); + + /* + * The common-header, request-id, and sub-request-id should exist + */ + assertTrue(jsonRequest.contains("CommonHeader")); + assertTrue(jsonRequest.contains("RequestID")); + assertTrue(jsonRequest.contains("SubRequestID")); + + /* + * The action sub-tag should exist + */ + assertTrue(jsonRequest.contains("Action")); + + logger.debug("Request as JSON: " + jsonRequest + "\n\n"); + } + + @Test + public void testRequestDeserialization() { + + /* + * Convert the PCI request object into json so we have a string of json to use for testing + */ + String jsonRequest = Serialization.gson.toJson(dmaapRequest, PciRequestWrapper.class); + + /* + * Use the serializer to convert the json string into a java object + */ + PciRequestWrapper pciRequestWrapper = Serialization.gson.fromJson(jsonRequest, PciRequestWrapper.class); + assertNotNull(pciRequestWrapper); + assertEquals(dmaapRequest, pciRequestWrapper); + + /* + * The type of the DMAAP wrapper should be request + */ + assertEquals("request", dmaapRequest.getType()); + + /* + * The DMAAP wrapper must have a body as that is the true SDNR request + */ + assertNotNull(dmaapRequest.getBody()); + PciRequest sdnrRequest = dmaapRequest.getBody(); + assertNotNull(sdnrRequest); + + /* + * The common header should not be null + */ + assertNotNull(sdnrRequest.getCommonHeader()); + + /* + * The action should not be null and should be set to restart + */ + assertNotNull(sdnrRequest.getAction()); + assertEquals("ModifyConfig", sdnrRequest.getAction()); + + logger.debug("Request as a Java Object: \n" + sdnrRequest.toString() + "\n\n"); + } + + @Test + public void testResponseSerialization() { + + /* + * Use the serializer to convert the object into json + */ + String jsonResponse = Serialization.gson.toJson(dmaapResponse, PciResponseWrapper.class); + assertNotNull(jsonResponse); + + /* + * The serializer should have added an extra sub-tag called "input" that wraps the request + */ + assertTrue(jsonResponse.contains("output")); + + /* + * The response should contain a common-header, request-id, sub-request-id, and status + */ + assertTrue(jsonResponse.contains("CommonHeader")); + assertTrue(jsonResponse.contains("RequestID")); + assertTrue(jsonResponse.contains("SubRequestID")); + assertTrue(jsonResponse.contains("Status")); + + logger.debug("Response as JSON: " + jsonResponse + "\n\n"); + } + + @Test + public void testResponseDeserialization() { + /* + * Convert the PCI response object into json so we have a string of json to use for testing + */ + String jsonResponse = Serialization.gson.toJson(dmaapResponse, PciResponseWrapper.class); + + /* + * Use the serializer to convert the json string into a java object + */ + PciResponseWrapper pciResponseWrapper = Serialization.gson.fromJson(jsonResponse, PciResponseWrapper.class); + assertNotNull(pciResponseWrapper); + assertEquals(dmaapResponse, pciResponseWrapper); + + /* + * The type of the DMAAP wrapper should be response + */ + assertEquals("response", dmaapResponse.getType()); + + /* + * The DMAAP wrapper must have a body as that is the true SDNR response + */ + assertNotNull(dmaapResponse.getBody()); + PciResponse sdnrResponse = dmaapResponse.getBody(); + assertNotNull(sdnrResponse); + + /* + * The common header should not be null + */ + assertNotNull(sdnrResponse.getCommonHeader()); + + /* + * The status should not be null and the status code should be 400 + */ + assertNotNull(sdnrResponse.getStatus()); + assertEquals(400, sdnrResponse.getStatus().getCode()); + + logger.debug("Response as a Java Object: \n" + sdnrResponse.toString() + "\n\n"); + } +} diff --git a/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/util/SerializationTest.java b/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/util/SerializationTest.java new file mode 100644 index 000000000..e71dadc28 --- /dev/null +++ b/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/util/SerializationTest.java @@ -0,0 +1,58 @@ +/*- + * ============LICENSE_START======================================================= + * sdnr + * ================================================================================ + * Copyright (C) 2018 Wipro Limited Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.sdnr.util; + +import static org.junit.Assert.assertEquals; + +import java.time.Instant; +import java.time.ZoneId; +import java.time.ZonedDateTime; + +import org.junit.Test; + +public class SerializationTest { + + @Test + public void test() { + String nameString = "Dorothy"; + String jsonName = Serialization.gsonPretty.toJson(nameString, String.class); + assertEquals("\"Dorothy\"", jsonName); + String jsonInOutName = Serialization.gsonPretty.fromJson(jsonName, String.class); + assertEquals("Dorothy", jsonInOutName); + + Instant instant0 = Instant.ofEpochMilli(1516127215000L); + String instantString0 = Serialization.gsonPretty.toJson(instant0, Instant.class); + assertEquals("\"2018-01-16T18:26:55Z\"", instantString0); + Instant outInstant0 = Serialization.gsonPretty.fromJson(instantString0, Instant.class); + assertEquals(instant0, outInstant0); + + Instant instant1 = Instant.ofEpochMilli(1516127215000L); + String instantString1 = Serialization.gsonJunit.toJson(instant1, Instant.class); + assertEquals("1516127215000", instantString1); + Instant outInstant1 = Serialization.gsonJunit.fromJson(instantString1, Instant.class); + assertEquals(instant1, outInstant1); + + ZonedDateTime zdt = ZonedDateTime.ofInstant(instant0, ZoneId.of("UTC")); + String zdtString = Serialization.gsonPretty.toJson(zdt, ZonedDateTime.class); + assertEquals("{\n \"dateTime\": {\n \"date\":", zdtString.substring(0, 29)); + } +} diff --git a/models-interactions/model-impl/so/pom.xml b/models-interactions/model-impl/so/pom.xml new file mode 100644 index 000000000..030d34976 --- /dev/null +++ b/models-interactions/model-impl/so/pom.xml @@ -0,0 +1,115 @@ +<!-- + ============LICENSE_START======================================================= + so + ================================================================================ + Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + Modifications Copyright (C) 2019 Nordix Foundation. + ================================================================================ + 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========================================================= + --> + + +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.onap.policy.models.policy-models-interactions.model-impl</groupId> + <artifactId>model-impl</artifactId> + <version>2.0.0-SNAPSHOT</version> + </parent> + + <artifactId>so</artifactId> + + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>com.google.code.gson</groupId> + <artifactId>gson</artifactId> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.drools</groupId> + <artifactId>drools-core</artifactId> + <version>6.5.0.Final</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.onap.policy.models.policy-models-interactions.model-impl</groupId> + <artifactId>rest</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.onap.policy.common</groupId> + <artifactId>policy-endpoints</artifactId> + <version>${policy.common.version}</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.onap.policy.drools-pdp</groupId> + <artifactId>policy-management</artifactId> + <version>${policy.drools-pdp.version}</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.glassfish.jersey.containers</groupId> + <artifactId>jersey-container-grizzly2-http</artifactId> + <version>2.25.1</version> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <artifactId>maven-checkstyle-plugin</artifactId> + <executions> + <execution> + <id>onap-java-style</id> + <goals> + <goal>check</goal> + </goals> + <phase>process-sources</phase> + <configuration> + <!-- Use Google Java Style Guide: + https://github.com/checkstyle/checkstyle/blob/master/src/main/resources/google_checks.xml + with minor changes --> + <configLocation>onap-checkstyle/onap-java-style.xml</configLocation> + <!-- <sourceDirectory> is needed so that checkstyle ignores the generated sources directory --> + <sourceDirectory>${project.build.sourceDirectory}</sourceDirectory> + <includeResources>true</includeResources> + <includeTestSourceDirectory>true</includeTestSourceDirectory> + <includeTestResources>true</includeTestResources> + <excludes> + </excludes> + <consoleOutput>true</consoleOutput> + <failsOnViolation>true</failsOnViolation> + <violationSeverity>warning</violationSeverity> + </configuration> + </execution> + </executions> + <dependencies> + <dependency> + <groupId>org.onap.oparent</groupId> + <artifactId>checkstyle</artifactId> + <version>${oparent.version}</version> + <scope>compile</scope> + </dependency> + </dependencies> + </plugin> + </plugins> + </build> +</project> diff --git a/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoAsyncRequestStatus.java b/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoAsyncRequestStatus.java new file mode 100644 index 000000000..cd4922dbd --- /dev/null +++ b/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoAsyncRequestStatus.java @@ -0,0 +1,126 @@ +/*- + * ============LICENSE_START======================================================= + * so + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.so; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; +import java.time.LocalDateTime; + +public class SoAsyncRequestStatus implements Serializable { + + private static final long serialVersionUID = -3283942659786236032L; + + @SerializedName("correlator") + private String correlator; + + @SerializedName("requestId") + private String requestId; + + @SerializedName("instanceReferences") + private SoInstanceReferences instanceReferences; + + @SerializedName("startTime") + private LocalDateTime startTime; + + @SerializedName("finishTime") + private LocalDateTime finishTime; + + @SerializedName("requestScope") + private String requestScope; + + @SerializedName("requestType") + private String requestType; + + @SerializedName("requestStatus") + private SoRequestStatus requestStatus; + + public SoAsyncRequestStatus() { + // required by author + } + + public String getCorrelator() { + return correlator; + } + + + public LocalDateTime getFinishTime() { + return finishTime; + } + + public SoInstanceReferences getInstanceReferences() { + return instanceReferences; + } + + public String getRequestId() { + return requestId; + } + + public String getRequestScope() { + return requestScope; + } + + public SoRequestStatus getRequestStatus() { + return requestStatus; + } + + public String getRequestType() { + return requestType; + } + + public LocalDateTime getStartTime() { + return startTime; + } + + public void setCorrelator(String correlator) { + this.correlator = correlator; + } + + public void setFinishTime(LocalDateTime finishTime) { + this.finishTime = finishTime; + } + + public void setInstanceReferences(SoInstanceReferences instanceReferences) { + this.instanceReferences = instanceReferences; + } + + public void setRequestId(String requestId) { + this.requestId = requestId; + } + + public void setRequestScope(String requestScope) { + this.requestScope = requestScope; + } + + public void setRequestStatus(SoRequestStatus requestStatus) { + this.requestStatus = requestStatus; + } + + public void setRequestType(String requestType) { + this.requestType = requestType; + } + + public void setStartTime(LocalDateTime startTime) { + this.startTime = startTime; + } + +} diff --git a/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoCloudConfiguration.java b/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoCloudConfiguration.java new file mode 100644 index 000000000..e6512685b --- /dev/null +++ b/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoCloudConfiguration.java @@ -0,0 +1,58 @@ +/*- + * ============LICENSE_START======================================================= + * so + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.so; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; + +public class SoCloudConfiguration implements Serializable { + + private static final long serialVersionUID = -3283942659786236032L; + + @SerializedName("lcpCloudRegionId") + private String lcpCloudRegionId; + + @SerializedName("tenantId") + private String tenantId; + + public SoCloudConfiguration() { + //required by author + } + + public String getLcpCloudRegionId() { + return lcpCloudRegionId; + } + + public String getTenantId() { + return tenantId; + } + + public void setLcpCloudRegionId(String lcpCloudRegionId) { + this.lcpCloudRegionId = lcpCloudRegionId; + } + + public void setTenantId(String tenantId) { + this.tenantId = tenantId; + } + +} diff --git a/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoInstanceReferences.java b/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoInstanceReferences.java new file mode 100644 index 000000000..751f560c0 --- /dev/null +++ b/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoInstanceReferences.java @@ -0,0 +1,58 @@ +/*- + * ============LICENSE_START======================================================= + * so + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.so; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; + +public class SoInstanceReferences implements Serializable { + + private static final long serialVersionUID = -3283942659786236032L; + + @SerializedName("requestId") + private String requestId; + + @SerializedName("instanceId") + private String instanceId; + + public SoInstanceReferences() { + //requried by author + } + + public String getInstanceId() { + return instanceId; + } + + public String getRequestId() { + return requestId; + } + + public void setInstanceId(String instanceId) { + this.instanceId = instanceId; + } + + public void setRequestId(String requestId) { + this.requestId = requestId; + } + +} diff --git a/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoManager.java b/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoManager.java new file mode 100644 index 000000000..4c9ba66bd --- /dev/null +++ b/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoManager.java @@ -0,0 +1,375 @@ +/*- + * ============LICENSE_START======================================================= + * so + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019 Samsung Electronics Co., Ltd. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.so; + +import com.google.gson.GsonBuilder; +import com.google.gson.JsonSyntaxException; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import org.drools.core.WorkingMemory; +import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure; +import org.onap.policy.common.endpoints.utils.NetLoggerUtil; +import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType; +import org.onap.policy.drools.system.PolicyEngine; +import org.onap.policy.rest.RestManager; +import org.onap.policy.rest.RestManager.Pair; +import org.onap.policy.so.util.Serialization; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * This class handles the interface towards SO (Service Orchestrator) for the ONAP Policy + * Framework. The SO API is defined at this link: + * http://onap.readthedocs.io/en/latest/submodules/so.git/docs/SO_R1_Interface.html#get-orchestration-request + * + */ +public final class SoManager { + private static final Logger logger = LoggerFactory.getLogger(SoManager.class); + + private static ExecutorService executors = Executors.newCachedThreadPool(); + + private static final int SO_RESPONSE_ERROR = 999; + private static final String MEDIA_TYPE = "application/json"; + private static final String LINE_SEPARATOR = System.lineSeparator(); + + // REST get timeout value in milliseconds + private static final int GET_REQUESTS_BEFORE_TIMEOUT = 20; + private static final long GET_REQUEST_WAIT_INTERVAL = 20000; + + // The REST manager used for processing REST calls for this VFC manager + private RestManager restManager; + + private long restGetTimeout = GET_REQUEST_WAIT_INTERVAL; + + /** + * Default constructor. + */ + public SoManager() { + restManager = new RestManager(); + } + + /** + * Create a service instance in SO. + * + * @param url the SO URL + * @param urlBase the base URL + * @param username user name on SO + * @param password password on SO + * @param request the request to issue to SO + * @return the SO Response object + */ + public SoResponse createModuleInstance(final String url, final String urlBase, final String username, + final String password, final SoRequest request) { + // Issue the HTTP POST request to SO to create the service instance + String requestJson = Serialization.gsonPretty.toJson(request); + NetLoggerUtil.getNetworkLogger().info("[OUT|{}|{}|{}|{}|{}|{}|]{}{}", "SO", url, username, password, + createSimpleHeaders(), MEDIA_TYPE, LINE_SEPARATOR, requestJson); + Pair<Integer, String> httpResponse = + restManager.post(url, username, password, createSimpleHeaders(), MEDIA_TYPE, requestJson); + + // Process the response from SO + SoResponse response = waitForSoOperationCompletion(urlBase, username, password, url, httpResponse); + if (SO_RESPONSE_ERROR != response.getHttpResponseCode()) { + return response; + } else { + return null; + } + } + + /** + * Works just like SOManager#asyncSORestCall(String, WorkingMemory, String, String, String, SORequest) + * except the vfModuleInstanceId is always null. + * + */ + public Future<SoResponse> asyncSoRestCall(final String requestId, final WorkingMemory wm, + final String serviceInstanceId, final String vnfInstanceId, + final SoRequest request) { + return asyncSoRestCall(requestId, wm, serviceInstanceId, vnfInstanceId, null, request); + } + + /** + * This method makes an asynchronous Rest call to MSO and inserts the response into + * Drools working memory. + * + * @param requestId the request id + * @param wm the Drools working memory + * @param serviceInstanceId service instance id to construct the request url + * @param vnfInstanceId vnf instance id to construct the request url + * @param vfModuleInstanceId vfModule instance id to construct the request url (required in case of delete vf + * module) + * @param request the SO request + * @return a concurrent Future for the thread that handles the request + */ + public Future<SoResponse> asyncSoRestCall(final String requestId, + final WorkingMemory wm, + final String serviceInstanceId, + final String vnfInstanceId, + final String vfModuleInstanceId, final SoRequest request) { + return executors.submit(new AsyncSoRestCallThread(requestId, wm, serviceInstanceId, vnfInstanceId, + vfModuleInstanceId, request)); + } + + /** + * This class handles an asynchronous request to SO as a thread. + */ + private class AsyncSoRestCallThread implements Callable<SoResponse> { + final String requestId; + final WorkingMemory wm; + final String serviceInstanceId; + final String vnfInstanceId; + final String vfModuleInstanceId; + final SoRequest request; + + /** + * Constructor, sets the context of the request. + * + * @param requestID The request ID + * @param wm reference to the Drools working memory + * @param serviceInstanceId the service instance in SO to use + * @param vnfInstanceId the VNF instance that is the subject of the request + * @param vfModuleInstanceId the vf module instance id (not null in case of delete vf module request) + * @param request the request itself + */ + private AsyncSoRestCallThread(final String requestId, + final WorkingMemory wm, final String serviceInstanceId, + final String vnfInstanceId, final String vfModuleInstanceId, + final SoRequest request) { + this.requestId = requestId; + this.wm = wm; + this.serviceInstanceId = serviceInstanceId; + this.vnfInstanceId = vnfInstanceId; + this.vfModuleInstanceId = vfModuleInstanceId; + this.request = request; + } + + /** + * Process the asynchronous SO request. + */ + @Override + public SoResponse call() { + String urlBase = PolicyEngine.manager.getEnvironmentProperty("so.url"); + String username = PolicyEngine.manager.getEnvironmentProperty("so.username"); + String password = PolicyEngine.manager.getEnvironmentProperty("so.password"); + + // Create a JSON representation of the request + String soJson = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting().create().toJson(request); + String url = null; + Pair<Integer, String> httpResponse = null; + + if (request.getOperationType() != null && request.getOperationType() + .equals(SoOperationType.SCALE_OUT)) { + url = urlBase + "/serviceInstantiation/v7/serviceInstances/" + serviceInstanceId + "/vnfs/" + + vnfInstanceId + "/vfModules/scaleOut"; + NetLoggerUtil.log(EventType.OUT, CommInfrastructure.REST, url, soJson); + httpResponse = restManager.post(url, username, password, createSimpleHeaders(), MEDIA_TYPE, soJson); + } else if (request.getOperationType() != null && request.getOperationType() + .equals(SoOperationType.DELETE_VF_MODULE)) { + url = urlBase + "/serviceInstances/v7/" + serviceInstanceId + "/vnfs/" + vnfInstanceId + + "/vfModules/" + vfModuleInstanceId; + NetLoggerUtil.log(EventType.OUT, CommInfrastructure.REST, url, soJson); + httpResponse = restManager.delete(url, username, password, createSimpleHeaders(), MEDIA_TYPE, soJson); + } else { + return null; + } + + // Process the response from SO + SoResponse response = waitForSoOperationCompletion(urlBase, username, password, url, httpResponse); + + // Return the response to Drools in its working memory + SoResponseWrapper soWrapper = new SoResponseWrapper(response, requestId); + wm.insert(soWrapper); + + return response; + } + } + + /** + * Wait for the SO operation we have ordered to complete. + * + * @param urlBaseSo The base URL for SO + * @param username user name on SO + * @param password password on SO + * @param initialRequestUrl The URL of the initial HTTP request + * @param initialHttpResponse The initial HTTP message returned from SO + * @return The parsed final response of SO to the request + */ + private SoResponse waitForSoOperationCompletion(final String urlBaseSo, final String username, + final String password, final String initialRequestUrl, + final Pair<Integer, String> initialHttpResponse) { + // Process the initial response from SO, the response to a post + SoResponse response = processSoResponse(initialRequestUrl, initialHttpResponse); + if (SO_RESPONSE_ERROR == response.getHttpResponseCode()) { + return response; + } + + // The SO URL to use to get the status of orchestration requests + String urlGet = urlBaseSo + "/orchestrationRequests/v5/" + response.getRequestReferences().getRequestId(); + + // The HTTP status code of the latest response + Pair<Integer, String> latestHttpResponse = initialHttpResponse; + + // Wait for the response from SO + for (int attemptsLeft = GET_REQUESTS_BEFORE_TIMEOUT; attemptsLeft >= 0; attemptsLeft--) { + // The SO request may have completed even on the first request so we check the + // response + // here before + // issuing any other requests + if (isRequestStateFinished(latestHttpResponse, response)) { + return response; + } + + // Wait for the defined interval before issuing a get + try { + Thread.sleep(restGetTimeout); + } catch (InterruptedException e) { + logger.error("Interrupted exception: ", e); + Thread.currentThread().interrupt(); + response.setHttpResponseCode(SO_RESPONSE_ERROR); + return response; + } + + // Issue a GET to find the current status of our request + NetLoggerUtil.getNetworkLogger().info("[OUT|{}|{}|{}|{}|{}|{}|]{}", "SO", urlGet, username, password, + createSimpleHeaders(), MEDIA_TYPE, LINE_SEPARATOR); + Pair<Integer, String> httpResponse = restManager.get(urlGet, username, password, createSimpleHeaders()); + + // Get our response + response = processSoResponse(urlGet, httpResponse); + if (SO_RESPONSE_ERROR == response.getHttpResponseCode()) { + return response; + } + + // Our latest HTTP response code + latestHttpResponse = httpResponse; + } + + // We have timed out on the SO request + response.setHttpResponseCode(SO_RESPONSE_ERROR); + return response; + } + + /** + * Parse the response message from SO into a SOResponse object. + * + * @param requestURL The URL of the HTTP request + * @param httpResponse The HTTP message returned from SO + * @return The parsed response + */ + private SoResponse processSoResponse(final String requestUrl, final Pair<Integer, String> httpResponse) { + SoResponse response = new SoResponse(); + + // A null httpDetails indicates a HTTP problem, a valid response from SO must be + // either 200 + // or 202 + if (!httpResultIsNullFree(httpResponse) || (httpResponse.first != 200 && httpResponse.first != 202)) { + logger.error("Invalid HTTP response received from SO"); + response.setHttpResponseCode(SO_RESPONSE_ERROR); + return response; + } + + // Parse the JSON of the response into our POJO + try { + response = Serialization.gsonPretty.fromJson(httpResponse.second, SoResponse.class); + } catch (JsonSyntaxException e) { + logger.error("Failed to deserialize HTTP response into SOResponse: ", e); + response.setHttpResponseCode(SO_RESPONSE_ERROR); + return response; + } + + // Set the HTTP response code of the response if needed + if (response.getHttpResponseCode() == 0) { + response.setHttpResponseCode(httpResponse.first); + } + + NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, requestUrl, httpResponse.second); + + if (logger.isDebugEnabled()) { + logger.debug("***** Response to SO Request to URL {}:", requestUrl); + logger.debug(httpResponse.second); + } + + return response; + } + + /** + * Method to allow tuning of REST get timeout. + * + * @param restGetTimeout the timeout value + */ + protected void setRestGetTimeout(final long restGetTimeout) { + this.restGetTimeout = restGetTimeout; + } + + /** + * Check that the request state of a response is defined. + * + * @param response The response to check + * @return true if the request for the response is defined + */ + private boolean isRequestStateDefined(final SoResponse response) { + return response != null && response.getRequest() != null && response.getRequest().getRequestStatus() != null + && response.getRequest().getRequestStatus().getRequestState() != null; + } + + /** + * Check that the request state of a response is finished. + * + * @param latestHttpDetails the HTTP details of the response + * @param response The response to check + * @return true if the request for the response is finished + */ + private boolean isRequestStateFinished(final Pair<Integer, String> latestHttpDetails, final SoResponse response) { + if (latestHttpDetails != null && 200 == latestHttpDetails.first && isRequestStateDefined(response)) { + String requestState = response.getRequest().getRequestStatus().getRequestState(); + return "COMPLETE".equalsIgnoreCase(requestState) || "FAILED".equalsIgnoreCase(requestState); + } else { + return false; + } + } + + /** + * Check that a HTTP operation result has no nulls. + * + * @param httpOperationResult the result to check + * @return true if no nulls are found + */ + private boolean httpResultIsNullFree(Pair<Integer, String> httpOperationResult) { + return httpOperationResult != null && httpOperationResult.first != null && httpOperationResult.second != null; + } + + /** + * Create simple HTTP headers for unauthenticated requests to SO. + * + * @return the HTTP headers + */ + private Map<String, String> createSimpleHeaders() { + Map<String, String> headers = new HashMap<>(); + headers.put("Accept", MEDIA_TYPE); + return headers; + } +} diff --git a/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoModelInfo.java b/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoModelInfo.java new file mode 100644 index 000000000..42e477b6b --- /dev/null +++ b/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoModelInfo.java @@ -0,0 +1,113 @@ +/*- + * ============LICENSE_START======================================================= + * so + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.so; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; + +public class SoModelInfo implements Serializable { + + private static final long serialVersionUID = -3283942659786236032L; + + @SerializedName("modelType") + private String modelType; + + @SerializedName("modelInvariantId") + private String modelInvariantId; + + @SerializedName("modelVersionId") + private String modelVersionId; + + @SerializedName("modelName") + private String modelName; + + @SerializedName("modelVersion") + private String modelVersion; + + @SerializedName("modelCustomizationName") + private String modelCustomizationName; + + @SerializedName("modelCustomizationId") + private String modelCustomizationId; + + public SoModelInfo() { + //required by author + } + + public String getModelCustomizationId() { + return modelCustomizationId; + } + + public String getModelCustomizationName() { + return modelCustomizationName; + } + + public String getModelInvariantId() { + return modelInvariantId; + } + + public String getModelName() { + return modelName; + } + + public String getModelType() { + return modelType; + } + + public String getModelVersion() { + return modelVersion; + } + + public String getModelVersionId() { + return modelVersionId; + } + + public void setModelCustomizationId(String modelCustomizationId) { + this.modelCustomizationId = modelCustomizationId; + } + + public void setModelCustomizationName(String modelCustomizationName) { + this.modelCustomizationName = modelCustomizationName; + } + + public void setModelInvariantId(String modelInvariantId) { + this.modelInvariantId = modelInvariantId; + } + + public void setModelName(String modelName) { + this.modelName = modelName; + } + + public void setModelType(String modelType) { + this.modelType = modelType; + } + + public void setModelVersion(String modelVersion) { + this.modelVersion = modelVersion; + } + + public void setModelVersionId(String modelVersionId) { + this.modelVersionId = modelVersionId; + } + +} diff --git a/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoOperationType.java b/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoOperationType.java new file mode 100644 index 000000000..e2a7af71d --- /dev/null +++ b/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoOperationType.java @@ -0,0 +1,42 @@ +/*- + * ============LICENSE_START======================================================= + * so + * ================================================================================ + * Copyright (C) 2018 Amdocs. All rights reserved. + * Modifications Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.so; + +/** + * Enumeration of SO Operations type that can be performed by a policy. + */ +public enum SoOperationType { + SCALE_OUT("Create Vf Module"), + DELETE_VF_MODULE("Delete Vf Module"); + + private String operationType; + + SoOperationType(String operationType) { + this.operationType = operationType; + } + + @Override + public String toString() { + return this.operationType; + } +} diff --git a/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoPolicyExceptionHolder.java b/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoPolicyExceptionHolder.java new file mode 100644 index 000000000..1b80898cc --- /dev/null +++ b/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoPolicyExceptionHolder.java @@ -0,0 +1,58 @@ +/*- + * ============LICENSE_START======================================================= + * so + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.so; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; + +public class SoPolicyExceptionHolder implements Serializable { + + private static final long serialVersionUID = -3283942659786236032L; + + @SerializedName("messageId") + private String messageId; + + @SerializedName("text") + private String text; + + public SoPolicyExceptionHolder() { + //required by author + } + + public String getMessageId() { + return messageId; + } + + public String getText() { + return text; + } + + public void setMessageId(String messageId) { + this.messageId = messageId; + } + + public void setText(String text) { + this.text = text; + } + +} diff --git a/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoRelatedInstance.java b/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoRelatedInstance.java new file mode 100644 index 000000000..b55ce27e8 --- /dev/null +++ b/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoRelatedInstance.java @@ -0,0 +1,71 @@ +/*- + * ============LICENSE_START======================================================= + * so + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.so; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; + +public class SoRelatedInstance implements Serializable { + + private static final long serialVersionUID = -3283942659786236032L; + + @SerializedName("instanceId") + private String instanceId; + + @SerializedName("instanceName") + private String instanceName; + + @SerializedName("modelInfo") + private SoModelInfo modelInfo; + + public SoRelatedInstance() { + //required by author + } + + public String getInstanceId() { + return instanceId; + } + + + public String getInstanceName() { + return instanceName; + } + + public SoModelInfo getModelInfo() { + return modelInfo; + } + + public void setInstanceId(String instanceId) { + this.instanceId = instanceId; + } + + public void setInstanceName(String instanceName) { + this.instanceName = instanceName; + } + + + public void setModelInfo(SoModelInfo modelInfo) { + this.modelInfo = modelInfo; + } + +} diff --git a/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoRelatedInstanceListElement.java b/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoRelatedInstanceListElement.java new file mode 100644 index 000000000..7fa2d638f --- /dev/null +++ b/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoRelatedInstanceListElement.java @@ -0,0 +1,47 @@ +/*- + * ============LICENSE_START======================================================= + * so + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.so; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; + +public class SoRelatedInstanceListElement implements Serializable { + + private static final long serialVersionUID = -3283942659786236032L; + + @SerializedName("relatedInstance") + private SoRelatedInstance relatedInstance; + + public SoRelatedInstanceListElement() { + //required by author + } + + public SoRelatedInstance getRelatedInstance() { + return relatedInstance; + } + + public void setRelatedInstance(SoRelatedInstance relatedInstance) { + this.relatedInstance = relatedInstance; + } + +} diff --git a/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoRequest.java b/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoRequest.java new file mode 100644 index 000000000..9c4cc0f81 --- /dev/null +++ b/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoRequest.java @@ -0,0 +1,124 @@ +/*- + * ============LICENSE_START======================================================= + * so + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.so; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; +import java.time.LocalDateTime; +import java.util.UUID; + +public class SoRequest implements Serializable { + + private static final long serialVersionUID = -3283942659786236032L; + + @SerializedName("requestId") + private UUID requestId; + + @SerializedName("startTime") + private String startTime; + + @SerializedName("finishTime") + private LocalDateTime finishTime; + + @SerializedName("requestScope") + private String requestScope; + + @SerializedName("requestType") + private String requestType; + + @SerializedName("requestDetails") + private SoRequestDetails requestDetails; + + @SerializedName("requestStatus") + private SoRequestStatus requestStatus; + + private transient SoOperationType operationType; + + public SoRequest() { + // required by author + } + + public LocalDateTime getFinishTime() { + return finishTime; + } + + public SoRequestDetails getRequestDetails() { + return requestDetails; + } + + public UUID getRequestId() { + return requestId; + } + + public String getRequestScope() { + return requestScope; + } + + public SoRequestStatus getRequestStatus() { + return requestStatus; + } + + public String getRequestType() { + return requestType; + } + + public String getStartTime() { + return startTime; + } + + public void setFinishTime(LocalDateTime finishTime) { + this.finishTime = finishTime; + } + + public void setRequestDetails(SoRequestDetails requestDetails) { + this.requestDetails = requestDetails; + } + + public void setRequestId(UUID requestId) { + this.requestId = requestId; + } + + public void setRequestScope(String requestScope) { + this.requestScope = requestScope; + } + + public void setRequestStatus(SoRequestStatus requestStatus) { + this.requestStatus = requestStatus; + } + + public void setRequestType(String requestType) { + this.requestType = requestType; + } + + public void setStartTime(String startTime) { + this.startTime = startTime; + } + + public SoOperationType getOperationType() { + return operationType; + } + + public void setOperationType(SoOperationType operationType) { + this.operationType = operationType; + } +} diff --git a/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoRequestDetails.java b/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoRequestDetails.java new file mode 100644 index 000000000..b0f4ca7c3 --- /dev/null +++ b/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoRequestDetails.java @@ -0,0 +1,216 @@ +/*- + * ============LICENSE_START======================================================= + * so + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.so; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +public class SoRequestDetails implements Serializable { + + private static final long serialVersionUID = -3283942659786236032L; + + @SerializedName("modelInfo") + private SoModelInfo modelInfo; + + @SerializedName("cloudConfiguration") + private SoCloudConfiguration cloudConfiguration; + + @SerializedName("requestInfo") + private SoRequestInfo requestInfo; + + @SerializedName("subscriberInfo") + private SoSubscriberInfo subscriberInfo; + + @SerializedName("relatedInstanceList") + private List<SoRelatedInstanceListElement> relatedInstanceList = new LinkedList<>(); + + @SerializedName("requestParameters") + private SoRequestParameters requestParameters; + + @SerializedName("configurationParameters") + private List<Map<String, String>> configurationParameters = new LinkedList<>(); + + public SoRequestDetails() { + + } + + /** + * Constructor. + * + * @param soRequestDetails copy object + */ + public SoRequestDetails(SoRequestDetails soRequestDetails) { + this.modelInfo = soRequestDetails.modelInfo; + this.cloudConfiguration = soRequestDetails.cloudConfiguration; + this.requestInfo = soRequestDetails.requestInfo; + this.relatedInstanceList = soRequestDetails.relatedInstanceList; + this.requestParameters = soRequestDetails.requestParameters; + this.subscriberInfo = soRequestDetails.subscriberInfo; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + SoRequestDetails other = (SoRequestDetails) obj; + if (cloudConfiguration == null) { + if (other.cloudConfiguration != null) { + return false; + } + } else if (!cloudConfiguration.equals(other.cloudConfiguration)) { + return false; + } + if (configurationParameters == null) { + if (other.configurationParameters != null) { + return false; + } + } else if (!configurationParameters.equals(other.configurationParameters)) { + return false; + } + if (modelInfo == null) { + if (other.modelInfo != null) { + return false; + } + } else if (!modelInfo.equals(other.modelInfo)) { + return false; + } + if (relatedInstanceList == null) { + if (other.relatedInstanceList != null) { + return false; + } + } else if (!relatedInstanceList.equals(other.relatedInstanceList)) { + return false; + } + if (requestInfo == null) { + if (other.requestInfo != null) { + return false; + } + } else if (!requestInfo.equals(other.requestInfo)) { + return false; + } + if (requestParameters == null) { + if (other.requestParameters != null) { + return false; + } + } else if (!requestParameters.equals(other.requestParameters)) { + return false; + } + if (subscriberInfo == null) { + if (other.subscriberInfo != null) { + return false; + } + } else if (!subscriberInfo.equals(other.subscriberInfo)) { + return false; + } + return true; + } + + public SoCloudConfiguration getCloudConfiguration() { + return cloudConfiguration; + } + + public SoModelInfo getModelInfo() { + return modelInfo; + } + + public List<SoRelatedInstanceListElement> getRelatedInstanceList() { + return relatedInstanceList; + } + + public SoRequestInfo getRequestInfo() { + return requestInfo; + } + + public SoRequestParameters getRequestParameters() { + return requestParameters; + } + + public List<Map<String, String>> getConfigurationParameters() { + return configurationParameters; + } + + public SoSubscriberInfo getSubscriberInfo() { + return subscriberInfo; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((cloudConfiguration == null) ? 0 : cloudConfiguration.hashCode()); + result = prime * result + ((configurationParameters == null) ? 0 : configurationParameters.hashCode()); + result = prime * result + ((modelInfo == null) ? 0 : modelInfo.hashCode()); + result = prime * result + ((relatedInstanceList == null) ? 0 : relatedInstanceList.hashCode()); + result = prime * result + ((requestInfo == null) ? 0 : requestInfo.hashCode()); + result = prime * result + ((requestParameters == null) ? 0 : requestParameters.hashCode()); + result = prime * result + ((subscriberInfo == null) ? 0 : subscriberInfo.hashCode()); + return result; + } + + public void setCloudConfiguration(SoCloudConfiguration cloudConfiguration) { + this.cloudConfiguration = cloudConfiguration; + } + + public void setModelInfo(SoModelInfo modelInfo) { + this.modelInfo = modelInfo; + } + + public void setRequestInfo(SoRequestInfo requestInfo) { + this.requestInfo = requestInfo; + } + + public void setRequestParameters(SoRequestParameters requestParameters) { + this.requestParameters = requestParameters; + } + + public void setConfigurationParameters(List<Map<String, String>> configurationParameters) { + this.configurationParameters = configurationParameters; + } + + public void setSubscriberInfo(SoSubscriberInfo subscriberInfo) { + this.subscriberInfo = subscriberInfo; + } + + public void setRelatedInstanceList(List<SoRelatedInstanceListElement> relatedInstanceList) { + this.relatedInstanceList = relatedInstanceList; + } + + @Override + public String toString() { + return "SORequestDetails [modelInfo=" + modelInfo + ", cloudConfiguration=" + cloudConfiguration + + ", requestInfo=" + requestInfo + ", subscriberInfo=" + subscriberInfo + + ", relatedInstanceList=" + relatedInstanceList + ", requestParameters=" + requestParameters + + ", configurationParameters=" + configurationParameters + "]"; + } + +} diff --git a/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoRequestError.java b/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoRequestError.java new file mode 100644 index 000000000..06dea0549 --- /dev/null +++ b/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoRequestError.java @@ -0,0 +1,58 @@ +/*- + * ============LICENSE_START======================================================= + * so + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.so; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; + +public class SoRequestError implements Serializable { + + private static final long serialVersionUID = -3283942659786236032L; + + @SerializedName("policyException") + private SoPolicyExceptionHolder policyException; + + @SerializedName("serviceException") + private SoServiceExceptionHolder serviceException; + + public SoRequestError() { + // required by author + } + + public SoPolicyExceptionHolder getPolicyException() { + return policyException; + } + + public SoServiceExceptionHolder getServiceException() { + return serviceException; + } + + public void setPolicyException(SoPolicyExceptionHolder policyException) { + this.policyException = policyException; + } + + public void setServiceException(SoServiceExceptionHolder serviceException) { + this.serviceException = serviceException; + } + +} diff --git a/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoRequestInfo.java b/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoRequestInfo.java new file mode 100644 index 000000000..06f456a8d --- /dev/null +++ b/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoRequestInfo.java @@ -0,0 +1,146 @@ +/*- + * ============LICENSE_START======================================================= + * so + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.so; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; + +public class SoRequestInfo implements Serializable { + + private static final long serialVersionUID = -3283942659786236032L; + + @SerializedName("instanceName") + private String instanceName; + + @SerializedName("source") + private String source; + + @SerializedName("productFamilyId") + private String productFamilyId; + + @SerializedName("suppressRollback") + private boolean suppressRollback; + + @SerializedName("billingAccountNumber") + private String billingAccountNumber; + + @SerializedName("callbackUrl") + private String callbackUrl; + + @SerializedName("correlator") + private String correlator; + + @SerializedName("orderNumber") + private String orderNumber; + + @SerializedName("orderVersion") + private Integer orderVersion; + + @SerializedName("requestorId") + private String requestorId; + + public SoRequestInfo() { + // required by author + } + + public String getBillingAccountNumber() { + return billingAccountNumber; + } + + public String getCallbackUrl() { + return callbackUrl; + } + + public String getCorrelator() { + return correlator; + } + + public String getInstanceName() { + return instanceName; + } + + public String getOrderNumber() { + return orderNumber; + } + + public Integer getOrderVersion() { + return orderVersion; + } + + public String getProductFamilyId() { + return productFamilyId; + } + + public String getRequestorId() { + return requestorId; + } + + public String getSource() { + return source; + } + + public boolean isSuppressRollback() { + return suppressRollback; + } + + public void setBillingAccountNumber(String billingAccountNumber) { + this.billingAccountNumber = billingAccountNumber; + } + + public void setCallbackUrl(String callbackUrl) { + this.callbackUrl = callbackUrl; + } + + public void setCorrelator(String correlator) { + this.correlator = correlator; + } + + public void setInstanceName(String instanceName) { + this.instanceName = instanceName; + } + + public void setOrderNumber(String orderNumber) { + this.orderNumber = orderNumber; + } + + public void setOrderVersion(Integer orderVersion) { + this.orderVersion = orderVersion; + } + + public void setProductFamilyId(String productFamilyId) { + this.productFamilyId = productFamilyId; + } + + public void setRequestorId(String requestorId) { + this.requestorId = requestorId; + } + + public void setSource(String source) { + this.source = source; + } + + public void setSuppressRollback(boolean suppressRollback) { + this.suppressRollback = suppressRollback; + } + +} diff --git a/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoRequestParameters.java b/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoRequestParameters.java new file mode 100644 index 000000000..2db4e1a03 --- /dev/null +++ b/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoRequestParameters.java @@ -0,0 +1,72 @@ +/*- + * ============LICENSE_START======================================================= + * so + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.so; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +public class SoRequestParameters implements Serializable { + + private static final long serialVersionUID = -3283942659786236033L; + + @SerializedName("subscriptionServiceType") + private String subscriptionServiceType; + + @SerializedName("usePreload") + private boolean usePreload; + + @SerializedName("userParams") + private List<Map<String, String>> userParams = new LinkedList<>(); + + public SoRequestParameters() { + // required by author + } + + public String getSubscriptionServiceType() { + return subscriptionServiceType; + } + + public boolean isUsePreload() { + return usePreload; + } + + public List<Map<String, String>> getUserParams() { + return userParams; + } + + public void setSubscriptionServiceType(String subscriptionServiceType) { + this.subscriptionServiceType = subscriptionServiceType; + } + + public void setUsePreload(boolean usePreload) { + this.usePreload = usePreload; + } + + public void setUserParams(List<Map<String, String>> userParams) { + this.userParams = userParams; + } + +} diff --git a/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoRequestReferences.java b/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoRequestReferences.java new file mode 100644 index 000000000..92ec1fe2e --- /dev/null +++ b/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoRequestReferences.java @@ -0,0 +1,54 @@ +/*- + * ============LICENSE_START======================================================= + * so + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.so; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; + +public class SoRequestReferences implements Serializable { + + private static final long serialVersionUID = -3283942659786236032L; + + @SerializedName("instanceId") + private String instanceId; + + @SerializedName("requestId") + private String requestId; + + public String getInstanceId() { + return instanceId; + } + + public String getRequestId() { + return requestId; + } + + public void setInstanceId(String instanceId) { + this.instanceId = instanceId; + } + + public void setRequestId(String requestId) { + this.requestId = requestId; + } + +} diff --git a/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoRequestStatus.java b/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoRequestStatus.java new file mode 100644 index 000000000..95df506f9 --- /dev/null +++ b/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoRequestStatus.java @@ -0,0 +1,80 @@ +/*- + * ============LICENSE_START======================================================= + * so + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.so; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; + +public class SoRequestStatus implements Serializable { + + private static final long serialVersionUID = -3283942659786236032L; + + @SerializedName("percentProgress") + private int percentProgress; + + @SerializedName("requestState") + private String requestState; + + @SerializedName("timestamp") + private String timestamp; + + @SerializedName("wasRolledBack") + private boolean wasRolledBack; + + public SoRequestStatus() { + //required by author + } + + public int getPercentProgress() { + return percentProgress; + } + + public String getRequestState() { + return requestState; + } + + public String getTimestamp() { + return timestamp; + } + + public boolean isWasRolledBack() { + return wasRolledBack; + } + + public void setPercentProgress(int percentProgress) { + this.percentProgress = percentProgress; + } + + public void setRequestState(String requestState) { + this.requestState = requestState; + } + + public void setTimestamp(String timestamp) { + this.timestamp = timestamp; + } + + public void setWasRolledBack(boolean wasRolledBack) { + this.wasRolledBack = wasRolledBack; + } + +} diff --git a/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoResponse.java b/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoResponse.java new file mode 100644 index 000000000..5feeb415e --- /dev/null +++ b/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoResponse.java @@ -0,0 +1,79 @@ +/*- + * ============LICENSE_START======================================================= + * so + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.so; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; + +public class SoResponse implements Serializable { + + private static final long serialVersionUID = -3283942659786236032L; + + @SerializedName("requestReferences") + private SoRequestReferences requestReferences; + + @SerializedName("requestError") + private SoRequestError requestError; + + @SerializedName("request") + private SoRequest request; + + private int httpResponseCode; + + public SoResponse() { + // required by author + } + + public int getHttpResponseCode() { + return httpResponseCode; + } + + public SoRequest getRequest() { + return request; + } + + public SoRequestError getRequestError() { + return requestError; + } + + public SoRequestReferences getRequestReferences() { + return requestReferences; + } + + public void setHttpResponseCode(int httpResponseCode) { + this.httpResponseCode = httpResponseCode; + } + + public void setRequest(SoRequest request) { + this.request = request; + } + + public void setRequestError(SoRequestError requestError) { + this.requestError = requestError; + } + + public void setRequestReferences(SoRequestReferences requestReferences) { + this.requestReferences = requestReferences; + } + +} diff --git a/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoResponseWrapper.java b/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoResponseWrapper.java new file mode 100644 index 000000000..2a74f38b5 --- /dev/null +++ b/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoResponseWrapper.java @@ -0,0 +1,103 @@ +/*- + * ============LICENSE_START======================================================= + * so + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.so; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; + +public class SoResponseWrapper implements Serializable { + + private static final long serialVersionUID = 7673023687132889069L; + + @SerializedName("SoResponse") + private SoResponse soResponse; + + private transient String requestId; + + public SoResponseWrapper(SoResponse response, String reqId) { + this.soResponse = response; + this.requestId = reqId; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + SoResponseWrapper other = (SoResponseWrapper) obj; + if (soResponse == null) { + if (other.soResponse != null) { + return false; + } + } + else if (!soResponse.equals(other.soResponse)) { + return false; + } + if (requestId == null) { + if (other.requestId != null) { + return false; + } + } + else if (!requestId.equals(other.requestId)) { + return false; + } + return true; + } + + public String getRequestId() { + return requestId; + } + + public SoResponse getSoResponse() { + return soResponse; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((soResponse == null) ? 0 : soResponse.hashCode()); + result = prime * result + ((requestId == null) ? 0 : requestId.hashCode()); + return result; + } + + public void setRequestId(String requestId) { + this.requestId = requestId; + } + + public void setSoResponse(SoResponse response) { + soResponse = response; + } + + @Override + public String toString() { + return "SOResponseWrapper [SOResponse=" + soResponse + ", RequestId=" + requestId + "]"; + } + +} diff --git a/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoServiceExceptionHolder.java b/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoServiceExceptionHolder.java new file mode 100644 index 000000000..79c162b4e --- /dev/null +++ b/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoServiceExceptionHolder.java @@ -0,0 +1,67 @@ +/*- + * ============LICENSE_START======================================================= + * so + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.so; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; +import java.util.LinkedList; +import java.util.List; + +public class SoServiceExceptionHolder implements Serializable { + + private static final long serialVersionUID = -3283942659786236032L; + + @SerializedName("messageId") + private String messageId; + + @SerializedName("text") + private String text; + + @SerializedName("variables") + private List<String> variables = new LinkedList<>(); + + public SoServiceExceptionHolder() { + // required by author + } + + public String getMessageId() { + return messageId; + } + + public String getText() { + return text; + } + + public List<String> getVariables() { + return variables; + } + + public void setMessageId(String messageId) { + this.messageId = messageId; + } + + public void setText(String text) { + this.text = text; + } + +} diff --git a/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoSubscriberInfo.java b/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoSubscriberInfo.java new file mode 100644 index 000000000..19f279dbb --- /dev/null +++ b/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoSubscriberInfo.java @@ -0,0 +1,69 @@ +/*- + * ============LICENSE_START======================================================= + * so + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.so; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; + +public class SoSubscriberInfo implements Serializable { + + private static final long serialVersionUID = -3283942659786236032L; + + @SerializedName("globalSubscriberId") + private String globalSubscriberId; + + @SerializedName("subscriberCommonSiteId") + private String subscriberCommonSiteId; + + @SerializedName("subscriberName") + private String subscriberName; + + public SoSubscriberInfo() { + //required by author + } + + public String getGlobalSubscriberId() { + return globalSubscriberId; + } + + public String getSubscriberCommonSiteId() { + return subscriberCommonSiteId; + } + + public String getSubscriberName() { + return subscriberName; + } + + public void setGlobalSubscriberId(String globalSubscriberId) { + this.globalSubscriberId = globalSubscriberId; + } + + public void setSubscriberCommonSiteId(String subscriberCommonSiteId) { + this.subscriberCommonSiteId = subscriberCommonSiteId; + } + + public void setSubscriberName(String subscriberName) { + this.subscriberName = subscriberName; + } + +} diff --git a/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/util/Serialization.java b/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/util/Serialization.java new file mode 100644 index 000000000..b23ccc993 --- /dev/null +++ b/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/util/Serialization.java @@ -0,0 +1,36 @@ +/*- + * ============LICENSE_START======================================================= + * mso + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.so.util; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +public final class Serialization { + + public static final Gson gsonPretty = + new GsonBuilder().disableHtmlEscaping().setPrettyPrinting().create(); + + private Serialization() { + // utility class with explicit private constructor + // change if class is more than utility + } +} diff --git a/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/DemoTest.java b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/DemoTest.java new file mode 100644 index 000000000..d64b70b51 --- /dev/null +++ b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/DemoTest.java @@ -0,0 +1,187 @@ +/*- + * ============LICENSE_START======================================================= + * mso + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.so; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.Test; +import org.onap.policy.so.SoCloudConfiguration; +import org.onap.policy.so.SoModelInfo; +import org.onap.policy.so.SoRelatedInstance; +import org.onap.policy.so.SoRelatedInstanceListElement; +import org.onap.policy.so.SoRequest; +import org.onap.policy.so.SoRequestDetails; +import org.onap.policy.so.SoRequestInfo; +import org.onap.policy.so.SoRequestParameters; +import org.onap.policy.so.util.Serialization; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class DemoTest { + private static final Logger logger = LoggerFactory.getLogger(DemoTest.class); + + @Test + public void test() { + + SoRequest request = new SoRequest(); + request.setRequestDetails(new SoRequestDetails()); + request.getRequestDetails().setModelInfo(new SoModelInfo()); + request.getRequestDetails().setCloudConfiguration(new SoCloudConfiguration()); + request.getRequestDetails().setRequestInfo(new SoRequestInfo()); + request.getRequestDetails().setRequestParameters(new SoRequestParameters()); + + request.getRequestDetails().getModelInfo().setModelType("vfModule"); + request.getRequestDetails().getModelInfo().setModelInvariantId("ff5256d2-5a33-55df-13ab-12abad84e7ff"); + request.getRequestDetails().getModelInfo().setModelVersionId("fe6478e5-ea33-3346-ac12-ab121484a3fe"); + request.getRequestDetails().getModelInfo().setModelName("vSAMP12..base..module-0"); + request.getRequestDetails().getModelInfo().setModelVersion("1"); + + request.getRequestDetails().getCloudConfiguration().setLcpCloudRegionId("mdt1"); + request.getRequestDetails().getCloudConfiguration().setTenantId("88a6ca3ee0394ade9403f075db23167e"); + + request.getRequestDetails().getRequestInfo().setInstanceName("SOTEST103a-vSAMP12_base_module-0"); + request.getRequestDetails().getRequestInfo().setSource("VID"); + request.getRequestDetails().getRequestInfo().setSuppressRollback(true); + + SoRelatedInstanceListElement relatedInstanceListElement1 = + new SoRelatedInstanceListElement(); + SoRelatedInstanceListElement relatedInstanceListElement2 = + new SoRelatedInstanceListElement(); + SoRelatedInstanceListElement relatedInstanceListElement3 = + new SoRelatedInstanceListElement(); + relatedInstanceListElement1.setRelatedInstance(new SoRelatedInstance()); + relatedInstanceListElement2.setRelatedInstance(new SoRelatedInstance()); + relatedInstanceListElement3.setRelatedInstance(new SoRelatedInstance()); + + relatedInstanceListElement1.getRelatedInstance().setInstanceId( + "17ef4658-bd1f-4ef0-9ca0-ea76e2bf122c"); + relatedInstanceListElement1.getRelatedInstance().setInstanceName( + "SOTESTVOL103a-vSAMP12_base_module-0_vol"); + relatedInstanceListElement1.getRelatedInstance().setModelInfo(new SoModelInfo()); + relatedInstanceListElement1.getRelatedInstance().getModelInfo().setModelType("volumeGroup"); + + relatedInstanceListElement2.getRelatedInstance().setInstanceId("serviceInstanceId"); + relatedInstanceListElement2.getRelatedInstance().setModelInfo(new SoModelInfo()); + relatedInstanceListElement2.getRelatedInstance().getModelInfo().setModelType("service"); + relatedInstanceListElement2.getRelatedInstance().getModelInfo().setModelInvariantId( + "ff3514e3-5a33-55df-13ab-12abad84e7ff"); + relatedInstanceListElement2.getRelatedInstance().getModelInfo().setModelVersionId( + "fe6985cd-ea33-3346-ac12-ab121484a3fe"); + relatedInstanceListElement2.getRelatedInstance().getModelInfo().setModelName( + "parent service model name"); + relatedInstanceListElement2.getRelatedInstance().getModelInfo().setModelVersion("1.0"); + + relatedInstanceListElement3.getRelatedInstance().setInstanceId("vnfInstanceId"); + relatedInstanceListElement3.getRelatedInstance().setModelInfo(new SoModelInfo()); + relatedInstanceListElement3.getRelatedInstance().getModelInfo().setModelType("vnf"); + relatedInstanceListElement3.getRelatedInstance().getModelInfo().setModelInvariantId( + "ff5256d1-5a33-55df-13ab-12abad84e7ff"); + relatedInstanceListElement3.getRelatedInstance().getModelInfo().setModelVersionId( + "fe6478e4-ea33-3346-ac12-ab121484a3fe"); + relatedInstanceListElement3.getRelatedInstance().getModelInfo().setModelName("vSAMP12"); + relatedInstanceListElement3.getRelatedInstance().getModelInfo().setModelVersion("1.0"); + relatedInstanceListElement3.getRelatedInstance().getModelInfo().setModelCustomizationName("vSAMP12 1"); + + request.getRequestDetails().getRelatedInstanceList().add(relatedInstanceListElement1); + request.getRequestDetails().getRelatedInstanceList().add(relatedInstanceListElement2); + request.getRequestDetails().getRelatedInstanceList().add(relatedInstanceListElement3); + + Map<String, String> userParam1 = new HashMap<>(); + userParam1.put("name1", "value1"); + + Map<String, String> userParam2 = new HashMap<>(); + userParam2.put("name2", "value2"); + + request.getRequestDetails().getRequestParameters().getUserParams().add(userParam1); + request.getRequestDetails().getRequestParameters().getUserParams().add(userParam2); + + logger.debug(Serialization.gsonPretty.toJson(request)); + + } + + @Test + public void testHack() { + + logger.debug("** HACK **"); + + SoRequest request = new SoRequest(); + + request.setRequestDetails(new SoRequestDetails()); + request.getRequestDetails().setModelInfo(new SoModelInfo()); + request.getRequestDetails().setCloudConfiguration(new SoCloudConfiguration()); + request.getRequestDetails().setRequestInfo(new SoRequestInfo()); + request.getRequestDetails().setRequestParameters(new SoRequestParameters()); + request.getRequestDetails().getRequestParameters().setUserParams(null); + + request.getRequestDetails().getModelInfo().setModelType("vfModule"); + request.getRequestDetails().getModelInfo().setModelInvariantId("a9c4a35a-de48-451a-9e4e-343f2ac52928"); + request.getRequestDetails().getModelInfo().setModelVersionId("e0d98ad1-238d-4555-b439-023d3f9079f6"); + request.getRequestDetails().getModelInfo().setModelName("0d9e0d9d352749f4B3cb..dnsscaling..module-0"); + request.getRequestDetails().getModelInfo().setModelVersion("2.0"); + + request.getRequestDetails().getCloudConfiguration().setLcpCloudRegionId("DFW"); + request.getRequestDetails().getCloudConfiguration().setTenantId("1015548"); + + request.getRequestDetails().getRequestInfo().setInstanceName( + "Vfmodule_Ete_Name1eScaling63928f-ccdc-4b34-bdef-9bf64109026e"); + request.getRequestDetails().getRequestInfo().setSource("POLICY"); + request.getRequestDetails().getRequestInfo().setSuppressRollback(false); + + SoRelatedInstanceListElement relatedInstanceListElement1 = + new SoRelatedInstanceListElement(); + SoRelatedInstanceListElement relatedInstanceListElement2 = + new SoRelatedInstanceListElement(); + relatedInstanceListElement1.setRelatedInstance(new SoRelatedInstance()); + relatedInstanceListElement2.setRelatedInstance(new SoRelatedInstance()); + + String serviceInstanceId = "98af39ce-6408-466b-921f-c2c7a8f59ed6"; + relatedInstanceListElement1.getRelatedInstance().setInstanceId(serviceInstanceId); + relatedInstanceListElement1.getRelatedInstance().setModelInfo(new SoModelInfo()); + relatedInstanceListElement1.getRelatedInstance().getModelInfo().setModelType("service"); + relatedInstanceListElement1.getRelatedInstance().getModelInfo().setModelInvariantId( + "24329a0c-1d57-4210-b1af-a65df64e9d59"); + relatedInstanceListElement1.getRelatedInstance().getModelInfo().setModelVersionId( + "ac642881-8e7e-4217-bd64-16ad41c42e30"); + relatedInstanceListElement1.getRelatedInstance().getModelInfo().setModelName("5116d67e-0b4f-46bf-a46f"); + relatedInstanceListElement1.getRelatedInstance().getModelInfo().setModelVersion("2.0"); + + String vnfInstanceId = "8eb411b8-a936-412f-b01f-9a9a435c0e93"; + relatedInstanceListElement2.getRelatedInstance().setInstanceId(vnfInstanceId); + relatedInstanceListElement2.getRelatedInstance().setModelInfo(new SoModelInfo()); + relatedInstanceListElement2.getRelatedInstance().getModelInfo().setModelType("vnf"); + relatedInstanceListElement2.getRelatedInstance().getModelInfo().setModelInvariantId( + "09fd971e-db5f-475d-997c-cf6704b6b8fe"); + relatedInstanceListElement2.getRelatedInstance().getModelInfo().setModelVersionId( + "152ed917-6dcc-46ee-bf8a-a775c5aa5a74"); + relatedInstanceListElement2.getRelatedInstance().getModelInfo().setModelName("9e4c31d2-4b25-4d9e-9fb4"); + relatedInstanceListElement2.getRelatedInstance().getModelInfo().setModelVersion("2.0"); + relatedInstanceListElement2.getRelatedInstance().getModelInfo().setModelCustomizationName( + "0d9e0d9d-3527-49f4-b3cb 2"); + + request.getRequestDetails().getRelatedInstanceList().add(relatedInstanceListElement1); + request.getRequestDetails().getRelatedInstanceList().add(relatedInstanceListElement2); + + logger.debug(Serialization.gsonPretty.toJson(request)); + } + +} diff --git a/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/DummyWorkingMemory.java b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/DummyWorkingMemory.java new file mode 100644 index 000000000..caffef43d --- /dev/null +++ b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/DummyWorkingMemory.java @@ -0,0 +1,316 @@ +/*- + * ============LICENSE_START======================================================= + * so + * ================================================================================ + * Copyright (C) 2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.so; + +import java.util.Collection; +import java.util.Iterator; +import java.util.Map; + +import org.drools.core.WorkingMemory; +import org.drools.core.WorkingMemoryEntryPoint; +import org.drools.core.common.InternalFactHandle; +import org.drools.core.impl.InternalKnowledgeBase; +import org.drools.core.spi.AsyncExceptionHandler; +import org.drools.core.spi.GlobalResolver; +import org.kie.api.event.kiebase.KieBaseEventListener; +import org.kie.api.event.rule.AgendaEventListener; +import org.kie.api.event.rule.RuleRuntimeEventListener; +import org.kie.api.runtime.Environment; +import org.kie.api.runtime.ObjectFilter; +import org.kie.api.runtime.process.ProcessInstance; +import org.kie.api.runtime.process.WorkItemManager; +import org.kie.api.runtime.rule.Agenda; +import org.kie.api.runtime.rule.AgendaFilter; +import org.kie.api.runtime.rule.FactHandle; +import org.kie.api.runtime.rule.FactHandle.State; +import org.kie.api.runtime.rule.QueryResults; +import org.kie.api.time.SessionClock; + +public class DummyWorkingMemory implements WorkingMemory { + + @Override + public void addEventListener(RuleRuntimeEventListener listener) { + } + + @Override + public void addEventListener(AgendaEventListener listener) { + } + + @Override + public void addEventListener(KieBaseEventListener listener) { + } + + @Override + public void removeEventListener(RuleRuntimeEventListener listener) { + } + + @Override + public void removeEventListener(AgendaEventListener listener) { + } + + @Override + public void removeEventListener(KieBaseEventListener listener) { + } + + @Override + public Collection<RuleRuntimeEventListener> getRuleRuntimeEventListeners() { + return null; + } + + @Override + public Collection<AgendaEventListener> getAgendaEventListeners() { + return null; + } + + @Override + public Collection<KieBaseEventListener> getKieBaseEventListeners() { + return null; + } + + @Override + public FactHandle insert(Object object, boolean dynamic) { + return null; + } + + @Override + public FactHandle insert(Object object) { + return null; + } + + @Override + public void dispose() { + } + + @Override + public String getEntryPointId() { + return null; + } + + @Override + public void retract(FactHandle handle) { + } + + @Override + public void delete(FactHandle handle) { + } + + @Override + public void delete(FactHandle handle, State fhState) { + + + } + + @Override + public void update(FactHandle handle, Object object) { + } + + @Override + public void update(FactHandle handle, Object object, String... modifiedProperties) { + } + + @Override + public Collection<? extends Object> getObjects() { + return null; + } + + @Override + public Collection<? extends Object> getObjects(ObjectFilter filter) { + return null; + } + + @Override + public <T extends FactHandle> Collection<T> getFactHandles() { + return null; + } + + @Override + public <T extends FactHandle> Collection<T> getFactHandles(ObjectFilter filter) { + return null; + } + + @Override + public long getFactCount() { + return 0; + } + + @Override + public Agenda getAgenda() { + return null; + } + + @Override + public void setGlobal(String identifier, Object value) { + } + + @Override + public Object getGlobal(String identifier) { + return null; + } + + @Override + public Environment getEnvironment() { + return null; + } + + @Override + public void setGlobalResolver(GlobalResolver globalResolver) { + } + + @Override + public GlobalResolver getGlobalResolver() { + return null; + } + + @Override + public InternalKnowledgeBase getKnowledgeBase() { + return null; + } + + @Override + public int fireAllRules() { + return 0; + } + + @Override + public int fireAllRules(AgendaFilter agendaFilter) { + return 0; + } + + @Override + public int fireAllRules(int fireLimit) { + return 0; + } + + @Override + public int fireAllRules(AgendaFilter agendaFilter, int fireLimit) { + return 0; + } + + @Override + public Object getObject(FactHandle handle) { + return null; + } + + @Override + public FactHandle getFactHandle(Object object) { + return null; + } + + @Override + public FactHandle getFactHandleByIdentity(Object object) { + return null; + } + + @Override + public Iterator<?> iterateObjects() { + return null; + } + + @Override + public Iterator<?> iterateObjects(ObjectFilter filter) { + return null; + } + + @Override + public Iterator<InternalFactHandle> iterateFactHandles() { + return null; + } + + @Override + public Iterator<InternalFactHandle> iterateFactHandles(ObjectFilter filter) { + return null; + } + + @Override + public void setFocus(String focus) { + } + + @Override + public QueryResults getQueryResults(String query, Object... arguments) { + return null; + } + + @Override + public void setAsyncExceptionHandler(AsyncExceptionHandler handler) { + } + + @Override + public void clearAgenda() { + } + + @Override + public void clearAgendaGroup(String group) { + } + + @Override + public void clearActivationGroup(String group) { + } + + @Override + public void clearRuleFlowGroup(String group) { + } + + @Override + public ProcessInstance startProcess(String processId) { + return null; + } + + @Override + public ProcessInstance startProcess(String processId, Map<String, Object> parameters) { + return null; + } + + @Override + public Collection<ProcessInstance> getProcessInstances() { + return null; + } + + @Override + public ProcessInstance getProcessInstance(long id) { + return null; + } + + @Override + public ProcessInstance getProcessInstance(long id, boolean readOnly) { + return null; + } + + @Override + public WorkItemManager getWorkItemManager() { + return null; + } + + @Override + public void halt() { + } + + @Override + public WorkingMemoryEntryPoint getWorkingMemoryEntryPoint(String id) { + return null; + } + + @Override + public SessionClock getSessionClock() { + return null; + } + +} diff --git a/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoAsyncRequestStatusTest.java b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoAsyncRequestStatusTest.java new file mode 100644 index 000000000..39aa2da6c --- /dev/null +++ b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoAsyncRequestStatusTest.java @@ -0,0 +1,80 @@ +/*- + * ============LICENSE_START======================================================= + * so + * ================================================================================ + * + * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.so; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.time.LocalDateTime; + +import org.junit.Test; + +public class SoAsyncRequestStatusTest { + + @Test + public void testConstructor() { + SoAsyncRequestStatus obj = new SoAsyncRequestStatus(); + + assertTrue(obj.getCorrelator() == null); + assertTrue(obj.getFinishTime() == null); + assertTrue(obj.getInstanceReferences() == null); + assertTrue(obj.getRequestId() == null); + assertTrue(obj.getRequestScope() == null); + assertTrue(obj.getRequestStatus() == null); + assertTrue(obj.getStartTime() == null); + } + + @Test + public void testSetGet() { + SoAsyncRequestStatus obj = new SoAsyncRequestStatus(); + + obj.setCorrelator("correlator"); + assertEquals("correlator", obj.getCorrelator()); + + LocalDateTime finishTime = LocalDateTime.now(); + obj.setFinishTime(finishTime); + assertEquals(finishTime, obj.getFinishTime()); + + SoInstanceReferences instanceReferences = new SoInstanceReferences(); + obj.setInstanceReferences(instanceReferences); + assertEquals(instanceReferences, obj.getInstanceReferences()); + + obj.setRequestId("requestId"); + assertEquals("requestId", obj.getRequestId()); + + obj.setRequestScope("requestScope"); + assertEquals("requestScope", obj.getRequestScope()); + + SoRequestStatus requestStatus = new SoRequestStatus(); + obj.setRequestStatus(requestStatus); + assertEquals(requestStatus, obj.getRequestStatus()); + + obj.setRequestType("requestType"); + assertEquals("requestType", obj.getRequestType()); + + LocalDateTime startTime = LocalDateTime.now(); + obj.setStartTime(startTime); + assertEquals(startTime, obj.getStartTime()); + + } +} diff --git a/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoCloudConfigurationTest.java b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoCloudConfigurationTest.java new file mode 100644 index 000000000..b81643886 --- /dev/null +++ b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoCloudConfigurationTest.java @@ -0,0 +1,50 @@ +/*- + * ============LICENSE_START======================================================= + * so + * ================================================================================ + * + * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.so; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +public class SoCloudConfigurationTest { + + @Test + public void testConstructor() { + SoCloudConfiguration obj = new SoCloudConfiguration(); + + assertTrue(obj.getLcpCloudRegionId() == null); + assertTrue(obj.getTenantId() == null); + } + + @Test + public void testSetGet() { + SoCloudConfiguration obj = new SoCloudConfiguration(); + + obj.setLcpCloudRegionId("lcpCloudRegionId"); + assertEquals("lcpCloudRegionId", obj.getLcpCloudRegionId()); + + obj.setTenantId("tenantId"); + assertEquals("tenantId", obj.getTenantId()); + } +} diff --git a/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoDummyServerTest.java b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoDummyServerTest.java new file mode 100644 index 000000000..910c0ac13 --- /dev/null +++ b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoDummyServerTest.java @@ -0,0 +1,240 @@ +/*- + * ============LICENSE_START======================================================= + * so + * ================================================================================ + * Copyright (C) 2018 Ericsson. All rights reserved. + * ================================================================================ + * Modifications Copyright (C) 2018-2019 AT&T. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.so; + +import com.google.gson.Gson; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.core.Response; + +@Path("/SO") +public class SoDummyServerTest { + + private static int postMessagesReceived = 0; + private static int putMessagesReceived = 0; + private static int statMessagesReceived = 0; + private static int getMessagesReceived = 0; + private static int deleteMessagesReceived = 0; + + private static Map<String, SoResponse> ongoingRequestMap = new ConcurrentHashMap<>(); + + /** + * Stats method. + * + * @return response + */ + @GET + @Path("/Stats") + public Response serviceGetStats() { + statMessagesReceived++; + return Response.status(200).entity("{\"GET\": " + getMessagesReceived + ",\"STAT\": " + statMessagesReceived + + ",\"POST\": " + postMessagesReceived + ",\"PUT\": " + putMessagesReceived + + ",\"DELETE\": " + deleteMessagesReceived + "}").build(); + + } + + /** + * Get stat type. + * + * @param statType the stat type + * @return http response + */ + @GET + @Path("/OneStat/{statType}") + public Response serviceGetStat(@PathParam("statType") final String statType) { + statMessagesReceived++; + return Response.status(200).entity("{\"TYPE\": " + statType + "}").build(); + } + + /** + * Post to service instantiation. + * + * @param jsonString string to send + * @return http response + */ + @POST + @Path("/serviceInstantiation/v7") + public Response servicePostRequest(final String jsonString) { + postMessagesReceived++; + return buildResponse(jsonString); + } + + /** + * Post. + * + * @param serviceInstanceId service instance id + * @param vnfInstanceId vnf instance id + * @param jsonString json body + * @return http response + */ + @POST + @Path("/serviceInstantiation/v7/serviceInstances/{serviceInstanceId}/vnfs/{vnfInstanceId}/vfModules/scaleOut") + public Response servicePostRequestVfModules(@PathParam("serviceInstanceId") final String serviceInstanceId, + @PathParam("vnfInstanceId") final String vnfInstanceId, final String jsonString) { + postMessagesReceived++; + return buildResponse(jsonString); + } + + /** + * Get instance ID. + * + * @param nsInstanceId node instance id + * @return http response + */ + @GET + @Path("/orchestrationRequests/v5/{nsInstanceId}") + public Response soRequestStatus(@PathParam("nsInstanceId") final String nsInstanceId) { + + SoResponse response = ongoingRequestMap.get(nsInstanceId); + + int iterationsLeft = Integer.valueOf(response.getRequest().getRequestScope()); + if (--iterationsLeft > 0) { + response.getRequest().setRequestScope(new Integer(iterationsLeft).toString()); + String responseString = new Gson().toJson(response, SoResponse.class); + return Response.status(response.getHttpResponseCode()).entity(responseString).build(); + } + + ongoingRequestMap.remove(nsInstanceId); + + if ("ReturnBadAfterWait".equals(response.getRequest().getRequestType())) { + return Response.status(400).build(); + } + + response.getRequest().getRequestStatus().setRequestState("COMPLETE"); + response.getRequest().setRequestScope("0"); + response.setHttpResponseCode(200); + String responseString = new Gson().toJson(response, SoResponse.class); + return Response.status(response.getHttpResponseCode()).entity(responseString).build(); + } + + /** + * Delete. + * + * @param serviceInstanceId service instance id + * @param vnfInstanceId vnf instance id + * @param vfModuleInstanceId vf module instance id + * @param jsonString json body + * @return http response + */ + @DELETE + @Path("/serviceInstances/v7/{serviceInstanceId}/vnfs/{vnfInstanceId}/vfModules/{vfModuleInstanceId}") + public Response serviceDeleteRequestVfModules( + @PathParam("serviceInstanceId") final String serviceInstanceId, + @PathParam("vnfInstanceId") final String vnfInstanceId, + @PathParam("vfModuleInstanceId") final String vfModuleInstanceId, + final String jsonString) { + deleteMessagesReceived++; + return buildResponse(jsonString); + } + + private Response buildResponse(String jsonString) { + if (jsonString == null) { + return Response.status(400).build(); + } + + SoRequest request = null; + try { + request = new Gson().fromJson(jsonString, SoRequest.class); + } catch (Exception e) { + return Response.status(400).build(); + } + + if (request == null) { + return Response.status(400).build(); + } + + if (request.getRequestType() == null) { + return Response.status(400).build(); + } + + if ("ReturnBadJson".equals(request.getRequestType())) { + return Response.status(200) + .entity("{\"GET\": , " + getMessagesReceived + ",\"STAT\": " + statMessagesReceived + + ",\"POST\":" + " , " + postMessagesReceived + ",\"PUT\": " + putMessagesReceived + + ",\"DELETE\": " + deleteMessagesReceived + "}").build(); + } + + SoResponse response = new SoResponse(); + response.setRequest(request); + response.setRequestReferences(new SoRequestReferences()); + response.getRequestReferences().setRequestId(request.getRequestId().toString()); + + if ("ReturnCompleted".equals(request.getRequestType())) { + response.getRequest().getRequestStatus().setRequestState("COMPLETE"); + response.setHttpResponseCode(200); + String responseString = new Gson().toJson(response, SoResponse.class); + return Response.status(response.getHttpResponseCode()) + .entity(responseString) + .build(); + } + + if ("ReturnFailed".equals(request.getRequestType())) { + response.getRequest().getRequestStatus().setRequestState("FAILED"); + response.setHttpResponseCode(200); + String responseString = new Gson().toJson(response, SoResponse.class); + return Response.status(response.getHttpResponseCode()) + .entity(responseString) + .build(); + } + + if ("ReturnOnging202".equals(request.getRequestType())) { + ongoingRequestMap.put(request.getRequestId().toString(), response); + + response.getRequest().getRequestStatus().setRequestState("ONGOING"); + response.setHttpResponseCode(202); + String responseString = new Gson().toJson(response, SoResponse.class); + return Response.status(response.getHttpResponseCode()) + .entity(responseString) + .build(); + } + + if ("ReturnOnging200".equals(request.getRequestType())) { + ongoingRequestMap.put(request.getRequestId().toString(), response); + + response.getRequest().getRequestStatus().setRequestState("ONGOING"); + response.setHttpResponseCode(200); + String responseString = new Gson().toJson(response, SoResponse.class); + return Response.status(response.getHttpResponseCode()) + .entity(responseString) + .build(); + } + + if ("ReturnBadAfterWait".equals(request.getRequestType())) { + ongoingRequestMap.put(request.getRequestId().toString(), response); + + response.getRequest().getRequestStatus().setRequestState("ONGOING"); + response.setHttpResponseCode(200); + String responseString = new Gson().toJson(response, SoResponse.class); + return Response.status(response.getHttpResponseCode()) + .entity(responseString) + .build(); + } + return null; + } +} diff --git a/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoInstanceReferencesTest.java b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoInstanceReferencesTest.java new file mode 100644 index 000000000..0b0aa5f03 --- /dev/null +++ b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoInstanceReferencesTest.java @@ -0,0 +1,50 @@ +/*- + * ============LICENSE_START======================================================= + * so + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.so; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +public class SoInstanceReferencesTest { + + @Test + public void testConstructor() { + SoInstanceReferences obj = new SoInstanceReferences(); + + assertTrue(obj.getInstanceId() == null); + assertTrue(obj.getRequestId() == null); + } + + @Test + public void testSetGet() { + SoInstanceReferences obj = new SoInstanceReferences(); + + obj.setInstanceId("instanceId"); + assertEquals("instanceId", obj.getInstanceId()); + + obj.setRequestId("requestId"); + assertEquals("requestId", obj.getRequestId()); + } +} diff --git a/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoManagerTest.java b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoManagerTest.java new file mode 100644 index 000000000..85f5ac7f9 --- /dev/null +++ b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoManagerTest.java @@ -0,0 +1,407 @@ +/*- + * ============LICENSE_START======================================================= + * TestSOManager + * ================================================================================ + * Copyright (C) 2018 Ericsson. All rights reserved. + * ================================================================================ + * Modifications Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * + * 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.policy.so; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.IOException; +import java.net.URI; +import java.util.UUID; +import java.util.concurrent.Future; +import org.apache.http.client.ClientProtocolException; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.util.EntityUtils; +import org.drools.core.WorkingMemory; +import org.glassfish.grizzly.http.server.HttpServer; +import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory; +import org.glassfish.jersey.server.ResourceConfig; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.onap.policy.drools.system.PolicyEngine; + +public class SoManagerTest { + private static final String BASE_URI = "http://localhost:46553/TestSOManager"; + private static final String BASE_SO_URI = BASE_URI + "/SO"; + private static HttpServer server; + + /** + * Set up test class. + */ + @BeforeClass + public static void setUp() throws IOException { + final ResourceConfig rc = new ResourceConfig(SoDummyServerTest.class); + //Grizzly by default doesn't allow payload for HTTP methods (ex: DELETE), for which HTTP spec doesn't + // explicitly state that. + //allow it before starting the server + server = GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URI), rc, false); + server.getServerConfiguration().setAllowPayloadForUndefinedHttpMethods(true); + server.start(); + } + + @AfterClass + public static void tearDown() throws Exception { + server.shutdown(); + } + + @Test + public void testGrizzlyServer() throws ClientProtocolException, IOException { + CloseableHttpClient httpclient = HttpClients.createDefault(); + HttpGet httpGet = new HttpGet("http://localhost:46553/TestSOManager/SO/Stats"); + CloseableHttpResponse response = httpclient.execute(httpGet); + + String returnBody = EntityUtils.toString(response.getEntity(), "UTF-8"); + assertTrue(returnBody.matches("^\\{\"GET\": [0-9]*,\"STAT\": [0-9]*,\"POST\": [0-9]*,\"PUT\": [0-9]*," + + "\"DELETE\": [0-9]*\\}$")); + } + + @Test + public void testServiceInstantiation() throws IOException { + SoManager manager = new SoManager(); + assertNotNull(manager); + manager.setRestGetTimeout(100); + + SoResponse response = manager.createModuleInstance("http:/localhost:99999999", BASE_SO_URI, "sean", + "citizen", null); + assertNull(response); + + response = manager.createModuleInstance(BASE_SO_URI + "/serviceInstantiation/v7", BASE_SO_URI, "sean", + "citizen", null); + assertNull(response); + + response = manager.createModuleInstance(BASE_SO_URI + "/serviceInstantiation/v7", BASE_SO_URI, "sean", + "citizen", new SoRequest()); + assertNull(response); + + SoRequest request = new SoRequest(); + request.setRequestId(UUID.randomUUID()); + request.setRequestScope("Test"); + request.setRequestType("ReturnBadJson"); + request.setStartTime("2018-03-23 16:31"); + request.setRequestStatus(new SoRequestStatus()); + request.getRequestStatus().setRequestState("ONGOING"); + + response = manager.createModuleInstance(BASE_SO_URI + "/serviceInstantiation/v7", BASE_SO_URI, "sean", + "citizen", request); + assertNull(response); + + request.setRequestType("ReturnCompleted"); + response = manager.createModuleInstance(BASE_SO_URI + "/serviceInstantiation/v7", BASE_SO_URI, "sean", + "citizen", request); + assertNotNull(response); + assertEquals("COMPLETE", response.getRequest().getRequestStatus().getRequestState()); + + request.setRequestType("ReturnFailed"); + response = manager.createModuleInstance(BASE_SO_URI + "/serviceInstantiation/v7", BASE_SO_URI, "sean", + "citizen", request); + assertNotNull(response); + assertEquals("FAILED", response.getRequest().getRequestStatus().getRequestState()); + + // Use scope to set the number of iterations we'll wait for + + request.setRequestType("ReturnOnging200"); + request.setRequestScope(new Integer(10).toString()); + response = manager.createModuleInstance(BASE_SO_URI + "/serviceInstantiation/v7", BASE_SO_URI, "sean", + "citizen", request); + assertNotNull(response); + assertNotNull(response.getRequest()); + assertEquals("COMPLETE", response.getRequest().getRequestStatus().getRequestState()); + + request.setRequestType("ReturnOnging202"); + request.setRequestScope(new Integer(20).toString()); + response = manager.createModuleInstance(BASE_SO_URI + "/serviceInstantiation/v7", BASE_SO_URI, "sean", + "citizen", request); + assertNotNull(response); + assertNotNull(response.getRequest()); + assertEquals("COMPLETE", response.getRequest().getRequestStatus().getRequestState()); + + // Test timeout after 20 attempts for a response + request.setRequestType("ReturnOnging202"); + request.setRequestScope(new Integer(21).toString()); + response = manager.createModuleInstance(BASE_SO_URI + "/serviceInstantiation/v7", BASE_SO_URI, "sean", + "citizen", request); + assertNull(response); + + // Test bad response after 3 attempts for a response + request.setRequestType("ReturnBadAfterWait"); + request.setRequestScope(new Integer(3).toString()); + response = manager.createModuleInstance(BASE_SO_URI + "/serviceInstantiation/v7", BASE_SO_URI, "sean", + "citizen", request); + assertNull(response); + } + + @Test + public void testVfModuleCreation() throws IOException { + SoManager manager = new SoManager(); + assertNotNull(manager); + manager.setRestGetTimeout(100); + + PolicyEngine.manager.setEnvironmentProperty("so.username", "sean"); + PolicyEngine.manager.setEnvironmentProperty("so.password", "citizen"); + + WorkingMemory wm = new DummyWorkingMemory(); + + SoRequest soRequest = new SoRequest(); + soRequest.setOperationType(SoOperationType.SCALE_OUT); + PolicyEngine.manager.setEnvironmentProperty("so.url", "http:/localhost:99999999"); + Future<SoResponse> asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), wm, + UUID.randomUUID().toString(), UUID.randomUUID().toString(), soRequest); + try { + SoResponse response = asyncRestCallFuture.get(); + assertEquals(999, response.getHttpResponseCode()); + } catch (Exception e) { + fail("test should not throw an exception"); + } + + PolicyEngine.manager.setEnvironmentProperty("so.url", BASE_SO_URI); + asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), wm, UUID.randomUUID().toString(), + UUID.randomUUID().toString(), soRequest); + try { + SoResponse response = asyncRestCallFuture.get(); + assertEquals(999, response.getHttpResponseCode()); + } catch (Exception e) { + fail("test should not throw an exception"); + } + + SoRequest request = new SoRequest(); + request.setRequestId(UUID.randomUUID()); + request.setRequestScope("Test"); + request.setRequestType("ReturnBadJson"); + request.setStartTime("2018-03-23 16:31"); + request.setRequestStatus(new SoRequestStatus()); + request.getRequestStatus().setRequestState("ONGOING"); + request.setOperationType(SoOperationType.SCALE_OUT); + + asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), wm, UUID.randomUUID().toString(), + UUID.randomUUID().toString(), request); + try { + SoResponse response = asyncRestCallFuture.get(); + assertEquals(999, response.getHttpResponseCode()); + } catch (Exception e) { + fail("test should not throw an exception"); + } + + request.setRequestType("ReturnCompleted"); + + asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), wm, UUID.randomUUID().toString(), + UUID.randomUUID().toString(), request); + try { + SoResponse response = asyncRestCallFuture.get(); + assertEquals("COMPLETE", response.getRequest().getRequestStatus().getRequestState()); + } catch (Exception e) { + fail("test should not throw an exception"); + } + + request.setRequestType("ReturnFailed"); + asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), wm, UUID.randomUUID().toString(), + UUID.randomUUID().toString(), request); + try { + SoResponse response = asyncRestCallFuture.get(); + assertEquals("FAILED", response.getRequest().getRequestStatus().getRequestState()); + } catch (Exception e) { + fail("test should not throw an exception"); + } + + // Use scope to set the number of iterations we'll wait for + + request.setRequestType("ReturnOnging200"); + request.setRequestScope(new Integer(10).toString()); + asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), wm, UUID.randomUUID().toString(), + UUID.randomUUID().toString(), request); + try { + SoResponse response = asyncRestCallFuture.get(); + assertNotNull(response.getRequest()); + assertEquals("COMPLETE", response.getRequest().getRequestStatus().getRequestState()); + } catch (Exception e) { + fail("test should not throw an exception"); + } + + request.setRequestType("ReturnOnging202"); + request.setRequestScope(new Integer(20).toString()); + asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), wm, UUID.randomUUID().toString(), + UUID.randomUUID().toString(), request); + try { + SoResponse response = asyncRestCallFuture.get(); + assertNotNull(response.getRequest()); + assertEquals("COMPLETE", response.getRequest().getRequestStatus().getRequestState()); + } catch (Exception e) { + fail("test should not throw an exception"); + } + + // Test timeout after 20 attempts for a response + request.setRequestType("ReturnOnging202"); + request.setRequestScope(new Integer(21).toString()); + asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), wm, UUID.randomUUID().toString(), + UUID.randomUUID().toString(), request); + try { + SoResponse response = asyncRestCallFuture.get(); + assertEquals(999, response.getHttpResponseCode()); + } catch (Exception e) { + fail("test should not throw an exception"); + } + + // Test bad response after 3 attempts for a response + request.setRequestType("ReturnBadAfterWait"); + request.setRequestScope(new Integer(3).toString()); + asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), wm, UUID.randomUUID().toString(), + UUID.randomUUID().toString(), request); + try { + SoResponse response = asyncRestCallFuture.get(); + assertEquals(999, response.getHttpResponseCode()); + } catch (Exception e) { + fail("test should not throw an exception"); + } + } + + @Test + public void testVfModuleDeletion() { + SoManager manager = new SoManager(); + assertNotNull(manager); + manager.setRestGetTimeout(100); + + PolicyEngine.manager.setEnvironmentProperty("so.username", "sean"); + PolicyEngine.manager.setEnvironmentProperty("so.password", "citizen"); + + WorkingMemory wm = new DummyWorkingMemory(); + + SoRequest soRequest = new SoRequest(); + soRequest.setOperationType(SoOperationType.DELETE_VF_MODULE); + PolicyEngine.manager.setEnvironmentProperty("so.url", "http:/localhost:99999999"); + Future<SoResponse> asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), wm, + UUID.randomUUID().toString(), UUID.randomUUID().toString(), UUID.randomUUID().toString(), soRequest); + try { + SoResponse response = asyncRestCallFuture.get(); + assertEquals(999, response.getHttpResponseCode()); + } catch (Exception e) { + fail("test should not throw an exception"); + } + + PolicyEngine.manager.setEnvironmentProperty("so.url", BASE_SO_URI); + asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), wm, UUID.randomUUID().toString(), + UUID.randomUUID().toString(), UUID.randomUUID().toString(), soRequest); + try { + SoResponse response = asyncRestCallFuture.get(); + assertEquals(999, response.getHttpResponseCode()); + } catch (Exception e) { + fail("test should not throw an exception"); + } + + SoRequest request = new SoRequest(); + request.setRequestId(UUID.randomUUID()); + request.setRequestScope("Test"); + request.setRequestType("ReturnBadJson"); + request.setStartTime("2018-03-23 16:31"); + request.setRequestStatus(new SoRequestStatus()); + request.getRequestStatus().setRequestState("ONGOING"); + request.setOperationType(SoOperationType.DELETE_VF_MODULE); + + asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), wm, UUID.randomUUID().toString(), + UUID.randomUUID().toString(), UUID.randomUUID().toString(), request); + try { + SoResponse response = asyncRestCallFuture.get(); + assertEquals(999, response.getHttpResponseCode()); + } catch (Exception e) { + fail("test should not throw an exception"); + } + + request.setRequestType("ReturnCompleted"); + + asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), wm, UUID.randomUUID().toString(), + UUID.randomUUID().toString(), UUID.randomUUID().toString(), request); + try { + SoResponse response = asyncRestCallFuture.get(); + assertEquals("COMPLETE", response.getRequest().getRequestStatus().getRequestState()); + } catch (Exception e) { + fail("test should not throw an exception"); + } + + request.setRequestType("ReturnFailed"); + asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), wm, UUID.randomUUID().toString(), + UUID.randomUUID().toString(), UUID.randomUUID().toString(), request); + try { + SoResponse response = asyncRestCallFuture.get(); + assertEquals("FAILED", response.getRequest().getRequestStatus().getRequestState()); + } catch (Exception e) { + fail("test should not throw an exception"); + } + + // Use scope to set the number of iterations we'll wait for + + request.setRequestType("ReturnOnging200"); + request.setRequestScope(new Integer(10).toString()); + asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), wm, UUID.randomUUID().toString(), + UUID.randomUUID().toString(), UUID.randomUUID().toString(), request); + try { + SoResponse response = asyncRestCallFuture.get(); + assertNotNull(response.getRequest()); + assertEquals("COMPLETE", response.getRequest().getRequestStatus().getRequestState()); + } catch (Exception e) { + fail("test should not throw an exception"); + } + + request.setRequestType("ReturnOnging202"); + request.setRequestScope(new Integer(20).toString()); + asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), wm, UUID.randomUUID().toString(), + UUID.randomUUID().toString(), UUID.randomUUID().toString(), request); + try { + SoResponse response = asyncRestCallFuture.get(); + assertNotNull(response.getRequest()); + assertEquals("COMPLETE", response.getRequest().getRequestStatus().getRequestState()); + } catch (Exception e) { + fail("test should not throw an exception"); + } + + // Test timeout after 20 attempts for a response + request.setRequestType("ReturnOnging202"); + request.setRequestScope(new Integer(21).toString()); + asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), wm, UUID.randomUUID().toString(), + UUID.randomUUID().toString(), UUID.randomUUID().toString(), request); + try { + SoResponse response = asyncRestCallFuture.get(); + assertEquals(999, response.getHttpResponseCode()); + } catch (Exception e) { + fail("test should not throw an exception"); + } + + // Test bad response after 3 attempts for a response + request.setRequestType("ReturnBadAfterWait"); + request.setRequestScope(new Integer(3).toString()); + asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), wm, UUID.randomUUID().toString(), + UUID.randomUUID().toString(), UUID.randomUUID().toString(), request); + try { + SoResponse response = asyncRestCallFuture.get(); + assertEquals(999, response.getHttpResponseCode()); + } catch (Exception e) { + fail("test should not throw an exception"); + } + } +} diff --git a/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoModelInfoTest.java b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoModelInfoTest.java new file mode 100644 index 000000000..51dd5cdc1 --- /dev/null +++ b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoModelInfoTest.java @@ -0,0 +1,71 @@ +/*- + * ============LICENSE_START======================================================= + * so + * ================================================================================ + * + * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.so; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +public class SoModelInfoTest { + + @Test + public void testConstructor() { + SoModelInfo obj = new SoModelInfo(); + + assertTrue(obj.getModelCustomizationId() == null); + assertTrue(obj.getModelCustomizationName() == null); + assertTrue(obj.getModelInvariantId() == null); + assertTrue(obj.getModelName() == null); + assertTrue(obj.getModelType() == null); + assertTrue(obj.getModelVersion() == null); + assertTrue(obj.getModelVersionId() == null); + } + + @Test + public void testSetGet() { + SoModelInfo obj = new SoModelInfo(); + + obj.setModelCustomizationId("modelCustomizationId"); + assertEquals("modelCustomizationId", obj.getModelCustomizationId()); + + obj.setModelCustomizationName("modelCustomizationName"); + assertEquals("modelCustomizationName", obj.getModelCustomizationName()); + + obj.setModelInvariantId("modelInvariantId"); + assertEquals("modelInvariantId", obj.getModelInvariantId()); + + obj.setModelName("modelName"); + assertEquals("modelName", obj.getModelName()); + + obj.setModelType("modelType"); + assertEquals("modelType", obj.getModelType()); + + obj.setModelVersion("modelVersion"); + assertEquals("modelVersion", obj.getModelVersion()); + + obj.setModelVersionId("modelVersionId"); + assertEquals("modelVersionId", obj.getModelVersionId()); + + } +} diff --git a/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoPolicyExceptionHolderTest.java b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoPolicyExceptionHolderTest.java new file mode 100644 index 000000000..e8899dd9d --- /dev/null +++ b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoPolicyExceptionHolderTest.java @@ -0,0 +1,49 @@ +/*- + * ============LICENSE_START======================================================= + * so + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.so; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +public class SoPolicyExceptionHolderTest { + + @Test + public void testConstructor() { + SoPolicyExceptionHolder obj = new SoPolicyExceptionHolder(); + + assertTrue(obj.getMessageId() == null); + assertTrue(obj.getText() == null); + } + + @Test + public void testSetGet() { + SoPolicyExceptionHolder obj = new SoPolicyExceptionHolder(); + + obj.setMessageId("messageId"); + assertEquals("messageId", obj.getMessageId()); + + obj.setText("text"); + assertEquals("text", obj.getText()); + } +} diff --git a/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoRelatedInstanceListElementTest.java b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoRelatedInstanceListElementTest.java new file mode 100644 index 000000000..82b11e03a --- /dev/null +++ b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoRelatedInstanceListElementTest.java @@ -0,0 +1,47 @@ +/*- + * ============LICENSE_START======================================================= + * so + * ================================================================================ + * + * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.so; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +public class SoRelatedInstanceListElementTest { + + @Test + public void testConstructor() { + SoRelatedInstanceListElement obj = new SoRelatedInstanceListElement(); + + assertTrue(obj.getRelatedInstance() == null); + } + + @Test + public void testSetGet() { + SoRelatedInstanceListElement obj = new SoRelatedInstanceListElement(); + + SoRelatedInstance relatedInstance = new SoRelatedInstance(); + obj.setRelatedInstance(relatedInstance); + assertEquals(relatedInstance, obj.getRelatedInstance()); + } +} diff --git a/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoRelatedInstanceTest.java b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoRelatedInstanceTest.java new file mode 100644 index 000000000..019012f2e --- /dev/null +++ b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoRelatedInstanceTest.java @@ -0,0 +1,54 @@ +/*- + * ============LICENSE_START======================================================= + * so + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.so; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +public class SoRelatedInstanceTest { + + @Test + public void testConstructor() { + SoRelatedInstance obj = new SoRelatedInstance(); + + assertTrue(obj.getInstanceId() == null); + assertTrue(obj.getInstanceName() == null); + assertTrue(obj.getModelInfo() == null); + } + + @Test + public void testSetGet() { + SoRelatedInstance obj = new SoRelatedInstance(); + + obj.setInstanceId("instanceId"); + assertEquals("instanceId", obj.getInstanceId()); + + obj.setInstanceName("instanceName"); + assertEquals("instanceName", obj.getInstanceName()); + + SoModelInfo modelInfo = new SoModelInfo(); + obj.setModelInfo(modelInfo); + assertEquals(modelInfo, obj.getModelInfo()); + } +} diff --git a/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoRequestDetailsTest.java b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoRequestDetailsTest.java new file mode 100644 index 000000000..64f6ee594 --- /dev/null +++ b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoRequestDetailsTest.java @@ -0,0 +1,177 @@ +/*- + * ============LICENSE_START======================================================= + * so + * ================================================================================ + * Copyright (C) 2018 Ericsson. All rights reserved. + * ================================================================================ + * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.so; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; + +public class SoRequestDetailsTest { + + @Test + public void testConstructor() { + SoRequestDetails obj = new SoRequestDetails(); + + assertTrue(obj.getCloudConfiguration() == null); + assertTrue(obj.getModelInfo() == null); + assertTrue(obj.getRequestInfo() == null); + assertTrue(obj.getRequestParameters() == null); + assertTrue(obj.getSubscriberInfo() == null); + + assertTrue(obj.getRelatedInstanceList() != null); + assertEquals(0, obj.getRelatedInstanceList().size()); + } + + @Test + public void testSetGet() { + SoRequestDetails obj = new SoRequestDetails(); + + SoCloudConfiguration cloudConfiguration = new SoCloudConfiguration(); + obj.setCloudConfiguration(cloudConfiguration); + assertEquals(cloudConfiguration, obj.getCloudConfiguration()); + + SoModelInfo modelInfo = new SoModelInfo(); + obj.setModelInfo(modelInfo); + assertEquals(modelInfo, obj.getModelInfo()); + + SoRequestInfo requestInfo = new SoRequestInfo(); + obj.setRequestInfo(requestInfo); + assertEquals(requestInfo, obj.getRequestInfo()); + + SoRequestParameters requestParameters = new SoRequestParameters(); + obj.setRequestParameters(requestParameters); + assertEquals(requestParameters, obj.getRequestParameters()); + + SoSubscriberInfo subscriberInfo = new SoSubscriberInfo(); + obj.setSubscriberInfo(subscriberInfo); + assertEquals(subscriberInfo, obj.getSubscriberInfo()); + } + + @Test + public void testSoMRequestDetailsMethods() { + SoRequestDetails details = new SoRequestDetails(); + assertNotNull(details); + assertNotEquals(0, details.hashCode()); + + SoCloudConfiguration cloudConfiguration = new SoCloudConfiguration(); + details.setCloudConfiguration(cloudConfiguration); + assertEquals(cloudConfiguration, details.getCloudConfiguration()); + assertNotEquals(0, details.hashCode()); + + SoModelInfo modelInfo = new SoModelInfo(); + details.setModelInfo(modelInfo); + assertEquals(modelInfo, details.getModelInfo()); + assertNotEquals(0, details.hashCode()); + + List<SoRelatedInstanceListElement> relatedInstanceList = new ArrayList<>(); + details.setRelatedInstanceList(relatedInstanceList); + assertEquals(relatedInstanceList, details.getRelatedInstanceList()); + assertNotEquals(0, details.hashCode()); + + SoRequestInfo requestInfo = new SoRequestInfo(); + details.setRequestInfo(requestInfo); + assertEquals(requestInfo, details.getRequestInfo()); + assertNotEquals(0, details.hashCode()); + + SoRequestParameters requestParameters = new SoRequestParameters(); + details.setRequestParameters(requestParameters); + assertEquals(requestParameters, details.getRequestParameters()); + assertNotEquals(0, details.hashCode()); + + SoSubscriberInfo subscriberInfo = new SoSubscriberInfo(); + details.setSubscriberInfo(subscriberInfo); + assertEquals(subscriberInfo, details.getSubscriberInfo()); + assertNotEquals(0, details.hashCode()); + + assertEquals("SORequestDetails [modelInfo=org.onap.policy.so", details.toString().substring(0, 46)); + + SoRequestDetails copiedDetails = new SoRequestDetails(details); + + assertTrue(details.equals(details)); + assertTrue(details.equals(copiedDetails)); + assertFalse(details.equals(null)); + assertFalse(details.equals("Hello")); + + details.setCloudConfiguration(null); + assertFalse(details.equals(copiedDetails)); + copiedDetails.setCloudConfiguration(null); + assertTrue(details.equals(copiedDetails)); + details.setCloudConfiguration(cloudConfiguration); + assertFalse(details.equals(copiedDetails)); + copiedDetails.setCloudConfiguration(cloudConfiguration); + assertTrue(details.equals(copiedDetails)); + + details.setModelInfo(null); + assertFalse(details.equals(copiedDetails)); + copiedDetails.setModelInfo(null); + assertTrue(details.equals(copiedDetails)); + details.setModelInfo(modelInfo); + assertFalse(details.equals(copiedDetails)); + copiedDetails.setModelInfo(modelInfo); + assertTrue(details.equals(copiedDetails)); + + details.setRequestInfo(null); + assertFalse(details.equals(copiedDetails)); + copiedDetails.setRequestInfo(null); + assertTrue(details.equals(copiedDetails)); + details.setRequestInfo(requestInfo); + assertFalse(details.equals(copiedDetails)); + copiedDetails.setRequestInfo(requestInfo); + assertTrue(details.equals(copiedDetails)); + + details.setRequestParameters(null); + assertFalse(details.equals(copiedDetails)); + copiedDetails.setRequestParameters(null); + assertTrue(details.equals(copiedDetails)); + details.setRequestParameters(requestParameters); + assertFalse(details.equals(copiedDetails)); + copiedDetails.setRequestParameters(requestParameters); + assertTrue(details.equals(copiedDetails)); + + details.setSubscriberInfo(null); + assertFalse(details.equals(copiedDetails)); + copiedDetails.setSubscriberInfo(null); + assertTrue(details.equals(copiedDetails)); + details.setSubscriberInfo(subscriberInfo); + assertFalse(details.equals(copiedDetails)); + copiedDetails.setSubscriberInfo(subscriberInfo); + assertTrue(details.equals(copiedDetails)); + + details.setRelatedInstanceList(null); + assertFalse(details.equals(copiedDetails)); + copiedDetails.setRelatedInstanceList(null); + assertTrue(details.equals(copiedDetails)); + details.setRelatedInstanceList(relatedInstanceList); + assertFalse(details.equals(copiedDetails)); + copiedDetails.setRelatedInstanceList(relatedInstanceList); + assertTrue(details.equals(copiedDetails)); + } +} diff --git a/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoRequestErrorTest.java b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoRequestErrorTest.java new file mode 100644 index 000000000..e0b819343 --- /dev/null +++ b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoRequestErrorTest.java @@ -0,0 +1,52 @@ +/*- + * ============LICENSE_START======================================================= + * so + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.so; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +public class SoRequestErrorTest { + + @Test + public void testConstructor() { + SoRequestError obj = new SoRequestError(); + + assertTrue(obj.getPolicyException() == null); + assertTrue(obj.getServiceException() == null); + } + + @Test + public void testSetGet() { + SoRequestError obj = new SoRequestError(); + + SoPolicyExceptionHolder policyException = new SoPolicyExceptionHolder(); + obj.setPolicyException(policyException); + assertEquals(policyException, obj.getPolicyException()); + + SoServiceExceptionHolder serviceException = new SoServiceExceptionHolder(); + obj.setServiceException(serviceException); + assertEquals(serviceException, obj.getServiceException()); + } +} diff --git a/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoRequestInfoTest.java b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoRequestInfoTest.java new file mode 100644 index 000000000..2302696ee --- /dev/null +++ b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoRequestInfoTest.java @@ -0,0 +1,83 @@ +/*- + * ============LICENSE_START======================================================= + * so + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.so; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +public class SoRequestInfoTest { + + @Test + public void testConstructor() { + SoRequestInfo obj = new SoRequestInfo(); + + assertTrue(obj.getBillingAccountNumber() == null); + assertTrue(obj.getCallbackUrl() == null); + assertTrue(obj.getCorrelator() == null); + assertTrue(obj.getInstanceName() == null); + assertTrue(obj.getOrderNumber() == null); + assertTrue(obj.getOrderVersion() == null); + assertTrue(obj.getProductFamilyId() == null); + assertTrue(obj.getRequestorId() == null); + assertTrue(obj.getSource() == null); + assertTrue(obj.isSuppressRollback() == false); + } + + @Test + public void testSetGet() { + SoRequestInfo obj = new SoRequestInfo(); + + obj.setBillingAccountNumber("billingAccountNumber"); + assertEquals("billingAccountNumber", obj.getBillingAccountNumber()); + + obj.setCallbackUrl("callbackUrl"); + assertEquals("callbackUrl", obj.getCallbackUrl()); + + obj.setCorrelator("correlator"); + assertEquals("correlator", obj.getCorrelator()); + + obj.setInstanceName("instanceName"); + assertEquals("instanceName", obj.getInstanceName()); + + obj.setOrderNumber("orderNumber"); + assertEquals("orderNumber", obj.getOrderNumber()); + + int orderVersion = 2008; + obj.setOrderVersion(orderVersion); + assertEquals((Integer) orderVersion, obj.getOrderVersion()); + + obj.setProductFamilyId("productFamilyId"); + assertEquals("productFamilyId", obj.getProductFamilyId()); + + obj.setRequestorId("requestorId"); + assertEquals("requestorId", obj.getRequestorId()); + + obj.setSource("source"); + assertEquals("source", obj.getSource()); + + obj.setSuppressRollback(true); + assertEquals(true, obj.isSuppressRollback()); + } +} diff --git a/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoRequestParametersTest.java b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoRequestParametersTest.java new file mode 100644 index 000000000..92638f906 --- /dev/null +++ b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoRequestParametersTest.java @@ -0,0 +1,48 @@ +/*- + * ============LICENSE_START======================================================= + * so + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.so; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +public class SoRequestParametersTest { + + @Test + public void testConstructor() { + SoRequestParameters obj = new SoRequestParameters(); + + assertTrue(obj.getSubscriptionServiceType() == null); + assertTrue(obj.getUserParams() != null); + assertEquals(0, obj.getUserParams().size()); + } + + @Test + public void testSetGet() { + SoRequestParameters obj = new SoRequestParameters(); + + obj.setSubscriptionServiceType("subscriptionServiceType"); + assertEquals("subscriptionServiceType", obj.getSubscriptionServiceType()); + } +} diff --git a/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoRequestReferencesTest.java b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoRequestReferencesTest.java new file mode 100644 index 000000000..42481996a --- /dev/null +++ b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoRequestReferencesTest.java @@ -0,0 +1,50 @@ +/*- + * ============LICENSE_START======================================================= + * so + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.so; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +public class SoRequestReferencesTest { + + @Test + public void testConstructor() { + SoRequestReferences obj = new SoRequestReferences(); + + assertTrue(obj.getInstanceId() == null); + assertTrue(obj.getRequestId() == null); + } + + @Test + public void testSetGet() { + SoRequestReferences obj = new SoRequestReferences(); + + obj.setInstanceId("instanceId"); + assertEquals("instanceId", obj.getInstanceId()); + + obj.setRequestId("requestId"); + assertEquals("requestId", obj.getRequestId()); + } +} diff --git a/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoRequestStatusTest.java b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoRequestStatusTest.java new file mode 100644 index 000000000..b83cb00dc --- /dev/null +++ b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoRequestStatusTest.java @@ -0,0 +1,59 @@ +/*- + * ============LICENSE_START======================================================= + * so + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.so; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +public class SoRequestStatusTest { + + @Test + public void testConstructor() { + SoRequestStatus obj = new SoRequestStatus(); + + assertEquals(0, obj.getPercentProgress()); + assertTrue(obj.getRequestState() == null); + assertTrue(obj.getTimestamp() == null); + assertFalse(obj.isWasRolledBack()); + } + + @Test + public void testSetGet() { + SoRequestStatus obj = new SoRequestStatus(); + + obj.setPercentProgress(2008); + assertEquals(2008, obj.getPercentProgress()); + + obj.setRequestState("requestState"); + assertEquals("requestState", obj.getRequestState()); + + obj.setTimestamp("timestamp"); + assertEquals("timestamp", obj.getTimestamp()); + + obj.setWasRolledBack(true); + assertTrue(obj.isWasRolledBack()); + } +} diff --git a/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoRequestTest.java b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoRequestTest.java new file mode 100644 index 000000000..93b855bd8 --- /dev/null +++ b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoRequestTest.java @@ -0,0 +1,77 @@ +/*- + * ============LICENSE_START======================================================= + * so + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.so; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.time.LocalDateTime; +import java.util.UUID; + +import org.junit.Test; + +public class SoRequestTest { + + @Test + public void testConstructor() { + SoRequest obj = new SoRequest(); + + assertTrue(obj.getFinishTime() == null); + assertTrue(obj.getRequestDetails() == null); + assertTrue(obj.getRequestId() == null); + assertTrue(obj.getRequestScope() == null); + assertTrue(obj.getRequestStatus() == null); + assertTrue(obj.getRequestType() == null); + assertTrue(obj.getStartTime() == null); + } + + @Test + public void testSetGet() { + SoRequest obj = new SoRequest(); + + LocalDateTime finishTime = LocalDateTime.now(); + obj.setFinishTime(finishTime); + assertEquals(finishTime, obj.getFinishTime()); + + UUID uuid = UUID.randomUUID(); + obj.setRequestId(uuid); + assertEquals(uuid, obj.getRequestId()); + + obj.setRequestScope("requestScope"); + assertEquals("requestScope", obj.getRequestScope()); + + SoRequestStatus requestStatus = new SoRequestStatus(); + obj.setRequestStatus(requestStatus); + assertEquals(requestStatus, obj.getRequestStatus()); + + obj.setRequestType("requestType"); + assertEquals("requestType", obj.getRequestType()); + + obj.setOperationType(SoOperationType.DELETE_VF_MODULE); + assertEquals(SoOperationType.DELETE_VF_MODULE, obj.getOperationType()); + + LocalDateTime startTime = LocalDateTime.now(); + obj.setStartTime(startTime.toString()); + assertEquals(startTime.toString(), obj.getStartTime()); + } +} diff --git a/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoResponseTest.java b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoResponseTest.java new file mode 100644 index 000000000..eb1b0ef6d --- /dev/null +++ b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoResponseTest.java @@ -0,0 +1,61 @@ +/*- + * ============LICENSE_START======================================================= + * so + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.so; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +public class SoResponseTest { + + @Test + public void testConstructor() { + SoResponse obj = new SoResponse(); + + assertEquals(0, obj.getHttpResponseCode()); + assertTrue(obj.getRequest() == null); + assertTrue(obj.getRequestError() == null); + assertTrue(obj.getRequestReferences() == null); + } + + @Test + public void testSetGet() { + SoResponse obj = new SoResponse(); + + obj.setHttpResponseCode(2008); + assertEquals(2008, obj.getHttpResponseCode()); + + SoRequest request = new SoRequest(); + obj.setRequest(request); + assertEquals(request, obj.getRequest()); + + SoRequestError requestError = new SoRequestError(); + obj.setRequestError(requestError); + assertEquals(requestError, obj.getRequestError()); + + SoRequestReferences requestReferences = new SoRequestReferences(); + obj.setRequestReferences(requestReferences); + assertEquals(requestReferences, obj.getRequestReferences()); + } +} diff --git a/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoResponseWrapperTest.java b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoResponseWrapperTest.java new file mode 100644 index 000000000..deedc79c5 --- /dev/null +++ b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoResponseWrapperTest.java @@ -0,0 +1,106 @@ +/*- + * ============LICENSE_START======================================================= + * so + * ================================================================================ + * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.so; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; + +import java.util.UUID; + +import org.junit.Test; + +public class SoResponseWrapperTest { + + @Test + public void testConstructor() { + SoResponse response = new SoResponse(); + SoResponseWrapper obj = new SoResponseWrapper(response, "reqID"); + + assertEquals(response, obj.getSoResponse()); + assertEquals("reqID", obj.getRequestId()); + } + + @Test + public void testSetGet() { + SoResponse response = new SoResponse(); + SoResponseWrapper obj = new SoResponseWrapper(response, "reqID"); + + SoResponse response2 = new SoResponse(); + response2.setHttpResponseCode(2008); + obj.setSoResponse(response2); + assertEquals(response2, obj.getSoResponse()); + + obj.setRequestId("id2"); + assertEquals("id2", obj.getRequestId()); + } + + @Test + public void testSoResponseWrapperMethods() { + String requestId = UUID.randomUUID().toString(); + SoResponse response = new SoResponse(); + + SoResponseWrapper responseWrapper = new SoResponseWrapper(response, requestId); + assertNotNull(responseWrapper); + assertNotEquals(0, responseWrapper.hashCode()); + + assertEquals(response, responseWrapper.getSoResponse()); + + assertNotEquals(0, responseWrapper.hashCode()); + + assertEquals("SOResponseWrapper [SOResponse=org.onap.policy.", responseWrapper.toString().substring(0, 46)); + + SoResponseWrapper identicalResponseWrapper = new SoResponseWrapper(response, requestId); + + assertEquals(responseWrapper, responseWrapper); + assertEquals(responseWrapper, identicalResponseWrapper); + assertNotEquals(null, responseWrapper); + assertNotEquals("Hello", responseWrapper); + assertFalse(responseWrapper.equals(null)); + assertFalse(responseWrapper.equals("AString")); + + assertEquals(new SoResponseWrapper(null, null), new SoResponseWrapper(null, null)); + assertNotEquals(new SoResponseWrapper(null, null), identicalResponseWrapper); + + assertNotEquals(0, new SoResponseWrapper(null, null).hashCode()); + + identicalResponseWrapper.setSoResponse(new SoResponse()); + assertNotEquals(responseWrapper, identicalResponseWrapper); + identicalResponseWrapper.setSoResponse(response); + assertEquals(responseWrapper, identicalResponseWrapper); + + identicalResponseWrapper.setRequestId(UUID.randomUUID().toString()); + assertNotEquals(responseWrapper, identicalResponseWrapper); + identicalResponseWrapper.setRequestId(requestId); + assertEquals(responseWrapper, identicalResponseWrapper); + + responseWrapper.setRequestId(null); + assertNotEquals(responseWrapper, identicalResponseWrapper); + identicalResponseWrapper.setRequestId(null); + assertEquals(responseWrapper, identicalResponseWrapper); + responseWrapper.setRequestId(requestId); + assertNotEquals(responseWrapper, identicalResponseWrapper); + identicalResponseWrapper.setRequestId(requestId); + assertEquals(responseWrapper, identicalResponseWrapper); + } +} diff --git a/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoServiceExceptionHolderTest.java b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoServiceExceptionHolderTest.java new file mode 100644 index 000000000..b5f31e595 --- /dev/null +++ b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoServiceExceptionHolderTest.java @@ -0,0 +1,52 @@ +/*- + * ============LICENSE_START======================================================= + * so + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.so; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +public class SoServiceExceptionHolderTest { + + @Test + public void testConstructor() { + SoServiceExceptionHolder obj = new SoServiceExceptionHolder(); + + assertTrue(obj.getMessageId() == null); + assertTrue(obj.getText() == null); + assertTrue(obj.getVariables() != null); + assertEquals(0, obj.getVariables().size()); + } + + @Test + public void testSetGet() { + SoServiceExceptionHolder obj = new SoServiceExceptionHolder(); + + obj.setMessageId("messageId"); + assertEquals("messageId", obj.getMessageId()); + + obj.setText("text"); + assertEquals("text", obj.getText()); + } +} diff --git a/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoSubscriberInfoTest.java b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoSubscriberInfoTest.java new file mode 100644 index 000000000..4d5bc7504 --- /dev/null +++ b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoSubscriberInfoTest.java @@ -0,0 +1,54 @@ +/*- + * ============LICENSE_START======================================================= + * so + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.so; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +public class SoSubscriberInfoTest { + + @Test + public void testConstructor() { + SoSubscriberInfo obj = new SoSubscriberInfo(); + + assertTrue(obj.getGlobalSubscriberId() == null); + assertTrue(obj.getSubscriberCommonSiteId() == null); + assertTrue(obj.getSubscriberName() == null); + } + + @Test + public void testSetGet() { + SoSubscriberInfo obj = new SoSubscriberInfo(); + + obj.setGlobalSubscriberId("globalSubscriberId"); + assertEquals("globalSubscriberId", obj.getGlobalSubscriberId()); + + obj.setSubscriberCommonSiteId("subscriberCommonSiteId"); + assertEquals("subscriberCommonSiteId", obj.getSubscriberCommonSiteId()); + + obj.setSubscriberName("subscriberName"); + assertEquals("subscriberName", obj.getSubscriberName()); + } +} diff --git a/models-interactions/model-impl/trafficgenerator/pom.xml b/models-interactions/model-impl/trafficgenerator/pom.xml new file mode 100644 index 000000000..30ad06551 --- /dev/null +++ b/models-interactions/model-impl/trafficgenerator/pom.xml @@ -0,0 +1,87 @@ +<!-- + ============LICENSE_START======================================================= + trafficgenerator + ================================================================================ + Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + Modifications Copyright (C) 2019 Nordix Foundation. + ================================================================================ + 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========================================================= + --> + + +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.onap.policy.models.policy-models-interactions.model-impl</groupId> + <artifactId>model-impl</artifactId> + <version>2.0.0-SNAPSHOT</version> + </parent> + + <artifactId>trafficgenerator</artifactId> + + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>com.google.code.gson</groupId> + <artifactId>gson</artifactId> + <scope>provided</scope> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <artifactId>maven-checkstyle-plugin</artifactId> + <executions> + <execution> + <id>onap-java-style</id> + <goals> + <goal>check</goal> + </goals> + <phase>process-sources</phase> + <configuration> + <!-- Use Google Java Style Guide: + https://github.com/checkstyle/checkstyle/blob/master/src/main/resources/google_checks.xml + with minor changes --> + <configLocation>onap-checkstyle/onap-java-style.xml</configLocation> + <!-- <sourceDirectory> is needed so that checkstyle ignores the generated sources directory --> + <sourceDirectory>${project.build.sourceDirectory}</sourceDirectory> + <includeResources>true</includeResources> + <includeTestSourceDirectory>true</includeTestSourceDirectory> + <includeTestResources>true</includeTestResources> + <excludes> + </excludes> + <consoleOutput>true</consoleOutput> + <failsOnViolation>true</failsOnViolation> + <violationSeverity>warning</violationSeverity> + </configuration> + </execution> + </executions> + <dependencies> + <dependency> + <groupId>org.onap.oparent</groupId> + <artifactId>checkstyle</artifactId> + <version>${oparent.version}</version> + <scope>compile</scope> + </dependency> + </dependencies> + </plugin> + </plugins> + </build> +</project> diff --git a/models-interactions/model-impl/trafficgenerator/src/main/java/org/onap/policy/vnf/trafficgenerator/PgRequest.java b/models-interactions/model-impl/trafficgenerator/src/main/java/org/onap/policy/vnf/trafficgenerator/PgRequest.java new file mode 100644 index 000000000..296ed5573 --- /dev/null +++ b/models-interactions/model-impl/trafficgenerator/src/main/java/org/onap/policy/vnf/trafficgenerator/PgRequest.java @@ -0,0 +1,38 @@ +/*- + * ============LICENSE_START======================================================= + * trafficgenerator + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.vnf.trafficgenerator; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; + +public class PgRequest implements Serializable { + + private static final long serialVersionUID = -3283942659786236032L; + + @SerializedName("pg-streams") + public PgStreams pgStreams; + + public PgRequest() { + //required by author + } +} diff --git a/models-interactions/model-impl/trafficgenerator/src/main/java/org/onap/policy/vnf/trafficgenerator/PgStream.java b/models-interactions/model-impl/trafficgenerator/src/main/java/org/onap/policy/vnf/trafficgenerator/PgStream.java new file mode 100644 index 000000000..1b5069524 --- /dev/null +++ b/models-interactions/model-impl/trafficgenerator/src/main/java/org/onap/policy/vnf/trafficgenerator/PgStream.java @@ -0,0 +1,40 @@ +/*- + * ============LICENSE_START======================================================= + * trafficgenerator + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.vnf.trafficgenerator; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; + +public class PgStream implements Serializable { + + private static final long serialVersionUID = 5567635677419358210L; + + @SerializedName("id") + public String streamId; + @SerializedName("is-enabled") + public String isEnabled; + + public PgStream() { + //required by author + } +} diff --git a/models-interactions/model-impl/trafficgenerator/src/main/java/org/onap/policy/vnf/trafficgenerator/PgStreams.java b/models-interactions/model-impl/trafficgenerator/src/main/java/org/onap/policy/vnf/trafficgenerator/PgStreams.java new file mode 100644 index 000000000..886b87197 --- /dev/null +++ b/models-interactions/model-impl/trafficgenerator/src/main/java/org/onap/policy/vnf/trafficgenerator/PgStreams.java @@ -0,0 +1,40 @@ +/*- + * ============LICENSE_START======================================================= + * trafficgenerator + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.vnf.trafficgenerator; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; +import java.util.LinkedList; +import java.util.List; + +public class PgStreams implements Serializable { + + private static final long serialVersionUID = 5567635677419358210L; + + @SerializedName("pg-stream") + public List<PgStream> pgStream = new LinkedList<>(); + + public PgStreams() { + // required by author + } +} diff --git a/models-interactions/model-impl/trafficgenerator/src/main/java/org/onap/policy/vnf/trafficgenerator/util/Serialization.java b/models-interactions/model-impl/trafficgenerator/src/main/java/org/onap/policy/vnf/trafficgenerator/util/Serialization.java new file mode 100644 index 000000000..77b8e78e0 --- /dev/null +++ b/models-interactions/model-impl/trafficgenerator/src/main/java/org/onap/policy/vnf/trafficgenerator/util/Serialization.java @@ -0,0 +1,33 @@ +/*- + * ============LICENSE_START======================================================= + * trafficgenerator + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.vnf.trafficgenerator.util; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +public final class Serialization { + + public static final Gson gsonPretty = + new GsonBuilder().disableHtmlEscaping().setPrettyPrinting().create(); + + private Serialization() {} +} diff --git a/models-interactions/model-impl/trafficgenerator/src/test/java/org/onap/policy/vnf/trafficgenerator/DemoTest.java b/models-interactions/model-impl/trafficgenerator/src/test/java/org/onap/policy/vnf/trafficgenerator/DemoTest.java new file mode 100644 index 000000000..ee3c47631 --- /dev/null +++ b/models-interactions/model-impl/trafficgenerator/src/test/java/org/onap/policy/vnf/trafficgenerator/DemoTest.java @@ -0,0 +1,55 @@ +/*- + * ============LICENSE_START======================================================= + * trafficgenerator + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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.policy.vnf.trafficgenerator; + +import org.junit.Test; + +import org.onap.policy.vnf.trafficgenerator.PgRequest; +import org.onap.policy.vnf.trafficgenerator.PgStream; +import org.onap.policy.vnf.trafficgenerator.PgStreams; +import org.onap.policy.vnf.trafficgenerator.util.Serialization; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class DemoTest { + private static final Logger logger = LoggerFactory.getLogger(DemoTest.class); + + @Test + public void test() { + PgRequest request = new PgRequest(); + request.pgStreams = new PgStreams(); + + PgStream pgStream; + for (int i = 0; i < 5; i++) { + pgStream = new PgStream(); + pgStream.streamId = "fw_udp" + (i + 1); + pgStream.isEnabled = "true"; + request.pgStreams.pgStream.add(pgStream); + } + + String body = Serialization.gsonPretty.toJson(request); + logger.debug(body); + + // fail("Not yet implemented"); + } + +} diff --git a/models-interactions/model-impl/vfc/pom.xml b/models-interactions/model-impl/vfc/pom.xml new file mode 100644 index 000000000..9a36cd2e8 --- /dev/null +++ b/models-interactions/model-impl/vfc/pom.xml @@ -0,0 +1,113 @@ +<!-- + ============LICENSE_START======================================================= + Copyright (C) 2017 Intel Corp. All rights reserved. + Modifications Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + Modifications Copyright (C) 2019 Nordix Foundation. + ================================================================================ + 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========================================================= + --> + +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.onap.policy.models.policy-models-interactions.model-impl</groupId> + <artifactId>model-impl</artifactId> + <version>2.0.0-SNAPSHOT</version> + </parent> + + <artifactId>vfc</artifactId> + + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> + <version>2.13.0</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>com.google.code.gson</groupId> + <artifactId>gson</artifactId> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.onap.policy.models.policy-models-interactions.model-impl</groupId> + <artifactId>rest</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.drools</groupId> + <artifactId>drools-core</artifactId> + <version>6.5.0.Final</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.onap.policy.common</groupId> + <artifactId>policy-endpoints</artifactId> + <version>${policy.common.version}</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.onap.policy.drools-pdp</groupId> + <artifactId>policy-management</artifactId> + <version>${policy.drools-pdp.version}</version> + <scope>provided</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <artifactId>maven-checkstyle-plugin</artifactId> + <executions> + <execution> + <id>onap-java-style</id> + <goals> + <goal>check</goal> + </goals> + <phase>process-sources</phase> + <configuration> + <!-- Use Google Java Style Guide: + https://github.com/checkstyle/checkstyle/blob/master/src/main/resources/google_checks.xml + with minor changes --> + <configLocation>onap-checkstyle/onap-java-style.xml</configLocation> + <!-- <sourceDirectory> is needed so that checkstyle ignores the generated sources directory --> + <sourceDirectory>${project.build.sourceDirectory}</sourceDirectory> + <includeResources>true</includeResources> + <includeTestSourceDirectory>true</includeTestSourceDirectory> + <includeTestResources>true</includeTestResources> + <excludes> + </excludes> + <consoleOutput>true</consoleOutput> + <failsOnViolation>true</failsOnViolation> + <violationSeverity>warning</violationSeverity> + </configuration> + </execution> + </executions> + <dependencies> + <dependency> + <groupId>org.onap.oparent</groupId> + <artifactId>checkstyle</artifactId> + <version>${oparent.version}</version> + <scope>compile</scope> + </dependency> + </dependencies> + </plugin> + </plugins> + </build> +</project> diff --git a/models-interactions/model-impl/vfc/src/main/java/org/onap/policy/vfc/VfcHealActionVmInfo.java b/models-interactions/model-impl/vfc/src/main/java/org/onap/policy/vfc/VfcHealActionVmInfo.java new file mode 100644 index 000000000..8ca08beb2 --- /dev/null +++ b/models-interactions/model-impl/vfc/src/main/java/org/onap/policy/vfc/VfcHealActionVmInfo.java @@ -0,0 +1,56 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2017-2019 Intel Corp. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2018-2019 AT&T Corporation. 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.policy.vfc; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; + +public class VfcHealActionVmInfo implements Serializable { + + private static final long serialVersionUID = 3208673205100673119L; + + @SerializedName("vmid") + private String vmid; + + @SerializedName("vmname") + private String vmname; + + public VfcHealActionVmInfo() { + // Default constructor + } + + public String getVmid() { + return vmid; + } + + public void setVmid(String vmid) { + this.vmid = vmid; + } + + public String getVmname() { + return vmname; + } + + public void setVmname(String vmname) { + this.vmname = vmname; + } +} diff --git a/models-interactions/model-impl/vfc/src/main/java/org/onap/policy/vfc/VfcHealAdditionalParams.java b/models-interactions/model-impl/vfc/src/main/java/org/onap/policy/vfc/VfcHealAdditionalParams.java new file mode 100644 index 000000000..f722beeea --- /dev/null +++ b/models-interactions/model-impl/vfc/src/main/java/org/onap/policy/vfc/VfcHealAdditionalParams.java @@ -0,0 +1,56 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2017-2019 Intel Corp. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2018-2019 AT&T Corporation. 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.policy.vfc; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; + +public class VfcHealAdditionalParams implements Serializable { + + private static final long serialVersionUID = 2656694137285096191L; + + @SerializedName("action") + private String action; + + @SerializedName("actionvminfo") + private VfcHealActionVmInfo actionInfo; + + public VfcHealAdditionalParams() { + // Default constructor + } + + public String getAction() { + return action; + } + + public void setAction(String action) { + this.action = action; + } + + public VfcHealActionVmInfo getActionInfo() { + return actionInfo; + } + + public void setActionInfo(VfcHealActionVmInfo actionInfo) { + this.actionInfo = actionInfo; + } +} diff --git a/models-interactions/model-impl/vfc/src/main/java/org/onap/policy/vfc/VfcHealRequest.java b/models-interactions/model-impl/vfc/src/main/java/org/onap/policy/vfc/VfcHealRequest.java new file mode 100644 index 000000000..0d4b03821 --- /dev/null +++ b/models-interactions/model-impl/vfc/src/main/java/org/onap/policy/vfc/VfcHealRequest.java @@ -0,0 +1,67 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2017-2019 Intel Corp. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2018-2019 AT&T Corporation. 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.policy.vfc; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; + +public class VfcHealRequest implements Serializable { + + private static final long serialVersionUID = -7341931593089709247L; + + @SerializedName("vnfInstanceId") + private String vnfInstanceId; + + @SerializedName("cause") + private String cause; + + @SerializedName("additionalParams") + private VfcHealAdditionalParams additionalParams; + + public VfcHealRequest() { + // Default constructor + } + + public String getVnfInstanceId() { + return vnfInstanceId; + } + + public void setVnfInstanceId(String vnfInstanceId) { + this.vnfInstanceId = vnfInstanceId; + } + + public String getCause() { + return cause; + } + + public void setCause(String cause) { + this.cause = cause; + } + + public VfcHealAdditionalParams getAdditionalParams() { + return additionalParams; + } + + public void setAdditionalParams(VfcHealAdditionalParams additionalParams) { + this.additionalParams = additionalParams; + } +} diff --git a/models-interactions/model-impl/vfc/src/main/java/org/onap/policy/vfc/VfcManager.java b/models-interactions/model-impl/vfc/src/main/java/org/onap/policy/vfc/VfcManager.java new file mode 100644 index 000000000..695b1b189 --- /dev/null +++ b/models-interactions/model-impl/vfc/src/main/java/org/onap/policy/vfc/VfcManager.java @@ -0,0 +1,191 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2017-2019 Intel Corp. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2018-2019 AT&T Corporation. All rights reserved. + * Modifications Copyright (C) 2019 Samsung Electronics Co., Ltd. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.vfc; + +import com.google.gson.JsonSyntaxException; + +import java.util.HashMap; +import java.util.Map; + +import org.drools.core.WorkingMemory; +import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure; +import org.onap.policy.common.endpoints.utils.NetLoggerUtil; +import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType; +import org.onap.policy.drools.system.PolicyEngine; +import org.onap.policy.rest.RestManager; +import org.onap.policy.rest.RestManager.Pair; +import org.onap.policy.vfc.util.Serialization; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public final class VfcManager implements Runnable { + + private String vfcUrlBase; + private String username; + private String password; + private VfcRequest vfcRequest; + private WorkingMemory workingMem; + private static final Logger logger = LoggerFactory.getLogger(VfcManager.class); + + // The REST manager used for processing REST calls for this VFC manager + private RestManager restManager; + + /** + * Constructor. + * + * @param wm Drools working memory + * @param request request + */ + public VfcManager(WorkingMemory wm, VfcRequest request) { + if (wm == null || request == null) { + throw new IllegalArgumentException( + "the parameters \"wm\" and \"request\" on the VfcManager constructor may not be null"); + } + workingMem = wm; + vfcRequest = request; + + restManager = new RestManager(); + + // use getPEManagerEnvProperty() for required properties; others are optional + setVfcParams(getPeManagerEnvProperty("vfc.url"), PolicyEngine.manager.getEnvironmentProperty("vfc.username"), + PolicyEngine.manager.getEnvironmentProperty("vfc.password")); + } + + /** + * Set the parameters. + * + * @param baseUrl base URL + * @param name username + * @param pwd password + */ + public void setVfcParams(String baseUrl, String name, String pwd) { + vfcUrlBase = baseUrl + "/api/nslcm/v1"; + username = name; + password = pwd; + } + + @Override + public void run() { + Map<String, String> headers = new HashMap<>(); + Pair<Integer, String> httpDetails; + + VfcResponse responseError = new VfcResponse(); + responseError.setResponseDescriptor(new VfcResponseDescriptor()); + responseError.getResponseDescriptor().setStatus("error"); + + headers.put("Accept", "application/json"); + String vfcUrl = vfcUrlBase + "/ns/" + vfcRequest.getNsInstanceId() + "/heal"; + try { + String vfcRequestJson = Serialization.gsonPretty.toJson(vfcRequest); + NetLoggerUtil.log(EventType.OUT, CommInfrastructure.REST, vfcUrl, vfcRequestJson); + + httpDetails = restManager.post(vfcUrl, username, password, headers, "application/json", vfcRequestJson); + } catch (Exception e) { + logger.error(e.getMessage(), e); + workingMem.insert(responseError); + return; + } + + if (httpDetails == null) { + workingMem.insert(responseError); + return; + } + + if (httpDetails.first != 202) { + logger.warn("VFC Heal Restcall failed"); + return; + } + + try { + VfcResponse response = Serialization.gsonPretty.fromJson(httpDetails.second, VfcResponse.class); + NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, vfcUrl, httpDetails.second); + String body = Serialization.gsonPretty.toJson(response); + logger.debug("Response to VFC Heal post:"); + logger.debug(body); + + String jobId = response.getJobId(); + int attemptsLeft = 20; + + String urlGet = vfcUrlBase + "/jobs/" + jobId; + VfcResponse responseGet = null; + + while (attemptsLeft-- > 0) { + NetLoggerUtil.getNetworkLogger().info("[OUT|{}|{}|]", "VFC", urlGet); + Pair<Integer, String> httpDetailsGet = restManager.get(urlGet, username, password, headers); + responseGet = Serialization.gsonPretty.fromJson(httpDetailsGet.second, VfcResponse.class); + NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, vfcUrl, httpDetailsGet.second); + responseGet.setRequestId(vfcRequest.getRequestId().toString()); + body = Serialization.gsonPretty.toJson(responseGet); + logger.debug("Response to VFC Heal get:"); + logger.debug(body); + + String responseStatus = responseGet.getResponseDescriptor().getStatus(); + if (httpDetailsGet.first == 200 + && ("finished".equalsIgnoreCase(responseStatus) || "error".equalsIgnoreCase(responseStatus))) { + logger.debug("VFC Heal Status {}", responseGet.getResponseDescriptor().getStatus()); + workingMem.insert(responseGet); + break; + } + Thread.sleep(20000); + } + if ((attemptsLeft <= 0) && (responseGet != null) && (responseGet.getResponseDescriptor() != null) + && (responseGet.getResponseDescriptor().getStatus() != null) + && (!responseGet.getResponseDescriptor().getStatus().isEmpty())) { + logger.debug("VFC timeout. Status: ({})", responseGet.getResponseDescriptor().getStatus()); + workingMem.insert(responseGet); + } + } catch (JsonSyntaxException e) { + logger.error("Failed to deserialize into VfcResponse {}", e.getLocalizedMessage(), e); + } catch (InterruptedException e) { + logger.error("Interrupted exception: {}", e.getLocalizedMessage(), e); + Thread.currentThread().interrupt(); + } catch (Exception e) { + logger.error("Unknown error deserializing into VfcResponse {}", e.getLocalizedMessage(), e); + } + } + + /** + * Protected setter for rest manager to allow mocked rest manager to be used for testing. + * + * @param restManager the test REST manager + */ + protected void setRestManager(final RestManager restManager) { + this.restManager = restManager; + } + + /** + * This method reads and validates environmental properties coming from the policy engine. Null + * properties cause an {@link IllegalArgumentException} runtime exception to be thrown + * + * @param string the name of the parameter to retrieve + * @return the property value + */ + + private String getPeManagerEnvProperty(String enginePropertyName) { + String enginePropertyValue = PolicyEngine.manager.getEnvironmentProperty(enginePropertyName); + if (enginePropertyValue == null) { + throw new IllegalArgumentException("The value of policy engine manager environment property \"" + + enginePropertyName + "\" may not be null"); + } + return enginePropertyValue; + } +} diff --git a/models-interactions/model-impl/vfc/src/main/java/org/onap/policy/vfc/VfcRequest.java b/models-interactions/model-impl/vfc/src/main/java/org/onap/policy/vfc/VfcRequest.java new file mode 100644 index 000000000..cf0d95065 --- /dev/null +++ b/models-interactions/model-impl/vfc/src/main/java/org/onap/policy/vfc/VfcRequest.java @@ -0,0 +1,65 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2017-2019 Intel Corp. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2018-2019 AT&T Corporation. 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.policy.vfc; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; +import java.util.UUID; + +public class VfcRequest implements Serializable { + + private static final long serialVersionUID = 3736300970326332512L; + // These fields are not serialized and not part of JSON + private transient String nsInstanceId; + private transient UUID requestId; + + @SerializedName("healVnfData") + private VfcHealRequest healRequest; + + public VfcRequest() { + // Default constructor + } + + public String getNsInstanceId() { + return nsInstanceId; + } + + public void setNsInstanceId(String nsInstanceId) { + this.nsInstanceId = nsInstanceId; + } + + public UUID getRequestId() { + return requestId; + } + + public void setRequestId(UUID requestId) { + this.requestId = requestId; + } + + public VfcHealRequest getHealRequest() { + return healRequest; + } + + public void setHealRequest(VfcHealRequest healRequest) { + this.healRequest = healRequest; + } +} diff --git a/models-interactions/model-impl/vfc/src/main/java/org/onap/policy/vfc/VfcResponse.java b/models-interactions/model-impl/vfc/src/main/java/org/onap/policy/vfc/VfcResponse.java new file mode 100644 index 000000000..d13e14bec --- /dev/null +++ b/models-interactions/model-impl/vfc/src/main/java/org/onap/policy/vfc/VfcResponse.java @@ -0,0 +1,66 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2017-2019 Intel Corp. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2018-2019 AT&T Corporation. 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.policy.vfc; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; + +public class VfcResponse implements Serializable { + + private static final long serialVersionUID = 9151443891238218455L; + + @SerializedName("jobId") + private String jobId; + + @SerializedName("responseDescriptor") + private VfcResponseDescriptor responseDescriptor; + + private transient String requestId; + + public VfcResponse() { + // Default constructor + } + + public String getJobId() { + return jobId; + } + + public void setJobId(String jobId) { + this.jobId = jobId; + } + + public VfcResponseDescriptor getResponseDescriptor() { + return responseDescriptor; + } + + public void setResponseDescriptor(VfcResponseDescriptor responseDescriptor) { + this.responseDescriptor = responseDescriptor; + } + + public String getRequestId() { + return requestId; + } + + public void setRequestId(String requestId) { + this.requestId = requestId; + } +} diff --git a/models-interactions/model-impl/vfc/src/main/java/org/onap/policy/vfc/VfcResponseDescriptor.java b/models-interactions/model-impl/vfc/src/main/java/org/onap/policy/vfc/VfcResponseDescriptor.java new file mode 100644 index 000000000..8fff683b6 --- /dev/null +++ b/models-interactions/model-impl/vfc/src/main/java/org/onap/policy/vfc/VfcResponseDescriptor.java @@ -0,0 +1,101 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2017-2019 Intel Corp. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2018-2019 AT&T Corporation. 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.policy.vfc; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; +import java.util.List; + +public class VfcResponseDescriptor implements Serializable { + + private static final long serialVersionUID = 6827782899144150158L; + + @SerializedName("progress") + private String progress; + + @SerializedName("status") + private String status; + + @SerializedName("statusDescription") + private String statusDescription; + + @SerializedName("errorCode") + private String errorCode; + + @SerializedName("responseId") + private String responseId; + + @SerializedName("responseHistoryList") + private List<VfcResponseDescriptor> responseHistoryList; + + public VfcResponseDescriptor() { + // Default constructor + } + + public String getStatus() { + return status; + } + + public String getProgress() { + return progress; + } + + public void setProgress(String progress) { + this.progress = progress; + } + + public String getStatusDescription() { + return statusDescription; + } + + public void setStatusDescription(String statusDescription) { + this.statusDescription = statusDescription; + } + + public String getErrorCode() { + return errorCode; + } + + public void setErrorCode(String errorCode) { + this.errorCode = errorCode; + } + + public String getResponseId() { + return responseId; + } + + public void setResponseId(String responseId) { + this.responseId = responseId; + } + + public List<VfcResponseDescriptor> getResponseHistoryList() { + return responseHistoryList; + } + + public void setResponseHistoryList(List<VfcResponseDescriptor> responseHistoryList) { + this.responseHistoryList = responseHistoryList; + } + + public void setStatus(String status) { + this.status = status; + } +} diff --git a/models-interactions/model-impl/vfc/src/main/java/org/onap/policy/vfc/util/Serialization.java b/models-interactions/model-impl/vfc/src/main/java/org/onap/policy/vfc/util/Serialization.java new file mode 100644 index 000000000..a0eaad037 --- /dev/null +++ b/models-interactions/model-impl/vfc/src/main/java/org/onap/policy/vfc/util/Serialization.java @@ -0,0 +1,34 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2017-2019 Intel Corp. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2018 AT&T Intellectual Property. 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.policy.vfc.util; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +public final class Serialization { + public static final Gson gsonPretty = new GsonBuilder().disableHtmlEscaping() + .setPrettyPrinting() + .create(); + + private Serialization() { + } + +} diff --git a/models-interactions/model-impl/vfc/src/test/java/org/onap/policy/vfc/DemoTest.java b/models-interactions/model-impl/vfc/src/test/java/org/onap/policy/vfc/DemoTest.java new file mode 100644 index 000000000..4d060a713 --- /dev/null +++ b/models-interactions/model-impl/vfc/src/test/java/org/onap/policy/vfc/DemoTest.java @@ -0,0 +1,82 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2017-2019 Intel Corp. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2018-2019 AT&T Corporation. 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.policy.vfc; + +import java.util.LinkedList; + +import org.junit.Test; +import org.onap.policy.vfc.util.Serialization; + +public class DemoTest { + + @Test + public void test() { + VfcRequest request = new VfcRequest(); + + request.setNsInstanceId("100"); + request.setHealRequest(new VfcHealRequest()); + request.getHealRequest().setVnfInstanceId("1"); + request.getHealRequest().setCause("vm is down"); + + request.getHealRequest().setAdditionalParams(new VfcHealAdditionalParams()); + request.getHealRequest().getAdditionalParams().setAction("restartvm"); + + request.getHealRequest().getAdditionalParams().setActionInfo(new VfcHealActionVmInfo()); + request.getHealRequest().getAdditionalParams().getActionInfo().setVmid("33"); + request.getHealRequest().getAdditionalParams().getActionInfo().setVmname("xgw-smp11"); + + String body = Serialization.gsonPretty.toJson(request); + System.out.println(body); + + VfcResponse response = new VfcResponse(); + response.setJobId("1"); + + body = Serialization.gsonPretty.toJson(response); + System.out.println(body); + + response.setResponseDescriptor(new VfcResponseDescriptor()); + response.getResponseDescriptor().setProgress("40"); + response.getResponseDescriptor().setStatus("processing"); + response.getResponseDescriptor().setStatusDescription("OMC VMs are decommissioned in VIM"); + response.getResponseDescriptor().setErrorCode(null); + response.getResponseDescriptor().setResponseId("42"); + body = Serialization.gsonPretty.toJson(response); + System.out.println(body); + + VfcResponseDescriptor responseDescriptor = new VfcResponseDescriptor(); + responseDescriptor.setProgress("20"); + responseDescriptor.setStatus("processing"); + responseDescriptor.setStatusDescription("OMC VMs are decommissioned in VIM"); + responseDescriptor.setErrorCode(null); + responseDescriptor.setResponseId("11"); + + response.getResponseDescriptor().setResponseHistoryList(new LinkedList<>()); + response.getResponseDescriptor().getResponseHistoryList().add(responseDescriptor); + + body = Serialization.gsonPretty.toJson(response); + System.out.println(body); + + response = Serialization.gsonPretty.fromJson(body, VfcResponse.class); + body = Serialization.gsonPretty.toJson(response); + System.out.println(body); + + } +} diff --git a/models-interactions/model-impl/vfc/src/test/java/org/onap/policy/vfc/VfcHealActionVmInfoTest.java b/models-interactions/model-impl/vfc/src/test/java/org/onap/policy/vfc/VfcHealActionVmInfoTest.java new file mode 100644 index 000000000..49dd06eef --- /dev/null +++ b/models-interactions/model-impl/vfc/src/test/java/org/onap/policy/vfc/VfcHealActionVmInfoTest.java @@ -0,0 +1,49 @@ +/*- + * ============LICENSE_START======================================================= + * vfc + * ================================================================================ + * Copyright (C) 2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2018-2019 AT&T Corporation. 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.policy.vfc; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; + +public class VfcHealActionVmInfoTest { + + @Test + public void testVfcHealActionVmInfo() { + VfcHealActionVmInfo actionInfo = new VfcHealActionVmInfo(); + assertNotNull(actionInfo); + assertNotEquals(0, actionInfo.hashCode()); + + String vmid = "ECity"; + actionInfo.setVmid(vmid); + assertEquals(vmid, actionInfo.getVmid()); + + String vmName = "Emerald City"; + actionInfo.setVmname(vmName); + assertEquals(vmName, actionInfo.getVmname()); + + assertNotEquals(0, actionInfo.hashCode()); + } +} diff --git a/models-interactions/model-impl/vfc/src/test/java/org/onap/policy/vfc/VfcHealAdditionalParamsTest.java b/models-interactions/model-impl/vfc/src/test/java/org/onap/policy/vfc/VfcHealAdditionalParamsTest.java new file mode 100644 index 000000000..a66264ed8 --- /dev/null +++ b/models-interactions/model-impl/vfc/src/test/java/org/onap/policy/vfc/VfcHealAdditionalParamsTest.java @@ -0,0 +1,49 @@ +/*- + * ============LICENSE_START======================================================= + * vfc + * ================================================================================ + * Copyright (C) 2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2018-2019 AT&T Corporation. 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.policy.vfc; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; + +public class VfcHealAdditionalParamsTest { + + @Test + public void testVfcHealAdditionalParameters() { + VfcHealAdditionalParams additionalParams = new VfcHealAdditionalParams(); + assertNotNull(additionalParams); + assertNotEquals(0, additionalParams.hashCode()); + + String action = "Go Home"; + additionalParams.setAction(action); + assertEquals(action, additionalParams.getAction()); + + VfcHealActionVmInfo actionInfo = new VfcHealActionVmInfo(); + additionalParams.setActionInfo(actionInfo ); + assertEquals(actionInfo, additionalParams.getActionInfo()); + + assertNotEquals(0, additionalParams.hashCode()); + } +} diff --git a/models-interactions/model-impl/vfc/src/test/java/org/onap/policy/vfc/VfcHealRequestTest.java b/models-interactions/model-impl/vfc/src/test/java/org/onap/policy/vfc/VfcHealRequestTest.java new file mode 100644 index 000000000..a4fc65912 --- /dev/null +++ b/models-interactions/model-impl/vfc/src/test/java/org/onap/policy/vfc/VfcHealRequestTest.java @@ -0,0 +1,53 @@ +/*- + * ============LICENSE_START======================================================= + * vfc + * ================================================================================ + * Copyright (C) 2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2018-2019 AT&T Corporation. 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.policy.vfc; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; + +public class VfcHealRequestTest { + + @Test + public void testVfcHealRequest() { + VfcHealRequest request = new VfcHealRequest(); + assertNotNull(request); + assertNotEquals(0, request.hashCode()); + + String vnfInstanceId = "Go To Oz"; + request.setVnfInstanceId(vnfInstanceId); + assertEquals(vnfInstanceId, request.getVnfInstanceId()); + + String cause = "West Witch"; + request.setCause(cause); + assertEquals(cause, request.getCause()); + + VfcHealAdditionalParams additionalParams = new VfcHealAdditionalParams(); + request.setAdditionalParams(additionalParams); + assertEquals(additionalParams, request.getAdditionalParams()); + + assertNotEquals(0, request.hashCode()); + } +} diff --git a/models-interactions/model-impl/vfc/src/test/java/org/onap/policy/vfc/VfcManagerTest.java b/models-interactions/model-impl/vfc/src/test/java/org/onap/policy/vfc/VfcManagerTest.java new file mode 100644 index 000000000..504af4db4 --- /dev/null +++ b/models-interactions/model-impl/vfc/src/test/java/org/onap/policy/vfc/VfcManagerTest.java @@ -0,0 +1,294 @@ +/*- + * ============LICENSE_START======================================================= + * vfc + * ================================================================================ + * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation.. All rights reserved. + * Modifications Copyright (C) 2018-2019 AT&T Corporation. 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.policy.vfc; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +import static org.mockito.ArgumentMatchers.anyMap; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.endsWith; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.startsWith; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +import org.drools.core.WorkingMemory; +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.onap.policy.drools.system.PolicyEngine; +import org.onap.policy.rest.RestManager; +import org.onap.policy.rest.RestManager.Pair; +import org.onap.policy.vfc.util.Serialization; + +public class VfcManagerTest { + private static WorkingMemory mockedWorkingMemory; + + private RestManager mockedRestManager; + + private Pair<Integer, String> httpResponsePutOk; + private Pair<Integer, String> httpResponseGetOk; + private Pair<Integer, String> httpResponseBadResponse; + private Pair<Integer, String> httpResponseErr; + + private VfcRequest request; + private VfcResponse response; + + @BeforeClass + public static void beforeTestVfcManager() { + mockedWorkingMemory = mock(WorkingMemory.class); + } + + /** + * Set up the mocked REST manager. + */ + @Before + public void setupMockedRest() { + mockedRestManager = mock(RestManager.class); + + httpResponsePutOk = mockedRestManager.new Pair<>(202, Serialization.gsonPretty.toJson(response)); + httpResponseGetOk = mockedRestManager.new Pair<>(200, Serialization.gsonPretty.toJson(response)); + httpResponseBadResponse = mockedRestManager.new Pair<>(202, Serialization.gsonPretty.toJson(null)); + httpResponseErr = mockedRestManager.new Pair<>(200, null); + } + + /** + * Create the request and response before. + */ + @Before + public void createRequestAndResponse() { + VfcHealActionVmInfo actionInfo = new VfcHealActionVmInfo(); + actionInfo.setVmid("TheWizard"); + actionInfo.setVmname("The Wizard of Oz"); + + VfcHealAdditionalParams additionalParams = new VfcHealAdditionalParams(); + additionalParams.setAction("Go Home"); + additionalParams.setActionInfo(actionInfo); + + VfcHealRequest healRequest = new VfcHealRequest(); + healRequest.setAdditionalParams(additionalParams); + healRequest.setCause("WestWitch"); + healRequest.setVnfInstanceId("EmeraldCity"); + + final UUID requestId = UUID.randomUUID(); + request = new VfcRequest(); + request.setHealRequest(healRequest); + request.setNsInstanceId("Dorothy"); + request.setRequestId(requestId); + + List<VfcResponseDescriptor> responseHistoryList = new ArrayList<>();; + + VfcResponseDescriptor responseDescriptor = new VfcResponseDescriptor(); + responseDescriptor.setErrorCode("1234"); + responseDescriptor.setProgress("Follow The Yellow Brick Road"); + responseDescriptor.setResponseHistoryList(responseHistoryList); + responseDescriptor.setResponseId(UUID.randomUUID().toString()); + responseDescriptor.setStatus("finished"); + responseDescriptor.setStatusDescription("There's no place like home"); + + response = new VfcResponse(); + response.setJobId("1234"); + response.setRequestId(request.getRequestId().toString()); + response.setResponseDescriptor(responseDescriptor); + } + + /** + * Remove the environnment. + */ + @After + public void tearDown() { + PolicyEngine.manager.getEnvironment().remove("vfc.password"); + PolicyEngine.manager.getEnvironment().remove("vfc.username"); + PolicyEngine.manager.getEnvironment().remove("vfc.url"); + } + + @Test + public void testVfcInitiation() { + try { + new VfcManager(null, null); + fail("test should throw an exception here"); + } + catch (IllegalArgumentException e) { + assertEquals("the parameters \"wm\" and \"request\" on the VfcManager constructor may not be null", + e.getMessage()); + } + + try { + new VfcManager(mockedWorkingMemory, null); + fail("test should throw an exception here"); + } + catch (IllegalArgumentException e) { + assertEquals("the parameters \"wm\" and \"request\" on the VfcManager constructor may not be null", + e.getMessage()); + } + + try { + new VfcManager(mockedWorkingMemory, request); + fail("test should throw an exception here"); + } + catch (IllegalArgumentException e) { + assertEquals("The value of policy engine manager environment property \"vfc.url\" may not be null", + e.getMessage()); + } + + // add url; username & password are not required + PolicyEngine.manager.getEnvironment().put("vfc.url", "http://somewhere.over.the.rainbow"); + new VfcManager(mockedWorkingMemory, request); + + // url & username, but no password + PolicyEngine.manager.getEnvironment().put("vfc.username", "Dorothy"); + + // url, username, and password + PolicyEngine.manager.getEnvironment().put("vfc.password", "Toto"); + new VfcManager(mockedWorkingMemory, request); + } + + @Test + public void testVfcExecutionException() throws InterruptedException { + PolicyEngine.manager.getEnvironment().put("vfc.url", "http://somewhere.over.the.rainbow"); + PolicyEngine.manager.getEnvironment().put("vfc.username", "Dorothy"); + PolicyEngine.manager.getEnvironment().put("vfc.password", "Exception"); + + VfcManager manager = new VfcManager(mockedWorkingMemory, request); + manager.setRestManager(mockedRestManager); + + Thread managerThread = new Thread(manager); + managerThread.start(); + + when(mockedRestManager.post( + startsWith("http://somewhere.over.the.rainbow"), + eq("Dorothy"), + eq("Exception"), + anyMap(), + anyString(), + anyString())) + .thenThrow(new RuntimeException("OzException")); + + managerThread.join(); + + PolicyEngine.manager.getEnvironment().remove("vfc.password"); + PolicyEngine.manager.getEnvironment().remove("vfc.username"); + PolicyEngine.manager.getEnvironment().remove("vfc.url"); + } + + @Test + public void testVfcExecutionNull() throws InterruptedException { + PolicyEngine.manager.getEnvironment().put("vfc.url", "http://somewhere.over.the.rainbow"); + PolicyEngine.manager.getEnvironment().put("vfc.username", "Dorothy"); + PolicyEngine.manager.getEnvironment().put("vfc.password", "Null"); + + VfcManager manager = new VfcManager(mockedWorkingMemory, request); + manager.setRestManager(mockedRestManager); + + Thread managerThread = new Thread(manager); + managerThread.start(); + + when(mockedRestManager.post(startsWith("http://somewhere.over.the.rainbow"), + eq("Dorothy"), eq("Null"), anyMap(), anyString(), anyString())) + .thenReturn(null); + + managerThread.join(); + + PolicyEngine.manager.getEnvironment().remove("vfc.password"); + PolicyEngine.manager.getEnvironment().remove("vfc.username"); + PolicyEngine.manager.getEnvironment().remove("vfc.url"); + } + + @Test + public void testVfcExecutionError0() throws InterruptedException { + PolicyEngine.manager.getEnvironment().put("vfc.url", "http://somewhere.over.the.rainbow"); + PolicyEngine.manager.getEnvironment().put("vfc.username", "Dorothy"); + PolicyEngine.manager.getEnvironment().put("vfc.password", "Error0"); + + VfcManager manager = new VfcManager(mockedWorkingMemory, request); + manager.setRestManager(mockedRestManager); + + Thread managerThread = new Thread(manager); + managerThread.start(); + + when(mockedRestManager.post(startsWith("http://somewhere.over.the.rainbow"), + eq("Dorothy"), eq("Error0"), anyMap(), anyString(), anyString())) + .thenReturn(httpResponseErr); + + managerThread.join(); + + PolicyEngine.manager.getEnvironment().remove("vfc.password"); + PolicyEngine.manager.getEnvironment().remove("vfc.username"); + PolicyEngine.manager.getEnvironment().remove("vfc.url"); + } + + @Test + public void testVfcExecutionBadResponse() throws InterruptedException { + PolicyEngine.manager.getEnvironment().put("vfc.url", "http://somewhere.over.the.rainbow"); + PolicyEngine.manager.getEnvironment().put("vfc.username", "Dorothy"); + PolicyEngine.manager.getEnvironment().put("vfc.password", "BadResponse"); + + VfcManager manager = new VfcManager(mockedWorkingMemory, request); + manager.setRestManager(mockedRestManager); + + Thread managerThread = new Thread(manager); + managerThread.start(); + + when(mockedRestManager.post(startsWith("http://somewhere.over.the.rainbow"), + eq("Dorothy"), eq("OK"), anyMap(), anyString(), anyString())) + .thenReturn(httpResponseBadResponse); + + managerThread.join(); + + PolicyEngine.manager.getEnvironment().remove("vfc.password"); + PolicyEngine.manager.getEnvironment().remove("vfc.username"); + PolicyEngine.manager.getEnvironment().remove("vfc.url"); + } + + @Test + public void testVfcExecutionOk() throws InterruptedException { + PolicyEngine.manager.getEnvironment().put("vfc.url", "http://somewhere.over.the.rainbow"); + PolicyEngine.manager.getEnvironment().put("vfc.username", "Dorothy"); + PolicyEngine.manager.getEnvironment().put("vfc.password", "OK"); + + VfcManager manager = new VfcManager(mockedWorkingMemory, request); + manager.setRestManager(mockedRestManager); + + Thread managerThread = new Thread(manager); + managerThread.start(); + + when(mockedRestManager.post(startsWith("http://somewhere.over.the.rainbow"), + eq("Dorothy"), eq("OK"), anyMap(), anyString(), anyString())) + .thenReturn(httpResponsePutOk); + + when(mockedRestManager.get(endsWith("1234"), eq("Dorothy"), eq("OK"), anyMap())) + .thenReturn(httpResponseGetOk); + + managerThread.join(); + + PolicyEngine.manager.getEnvironment().remove("vfc.password"); + PolicyEngine.manager.getEnvironment().remove("vfc.username"); + PolicyEngine.manager.getEnvironment().remove("vfc.url"); + } +} diff --git a/models-interactions/model-impl/vfc/src/test/java/org/onap/policy/vfc/VfcRequestTest.java b/models-interactions/model-impl/vfc/src/test/java/org/onap/policy/vfc/VfcRequestTest.java new file mode 100644 index 000000000..67720cc16 --- /dev/null +++ b/models-interactions/model-impl/vfc/src/test/java/org/onap/policy/vfc/VfcRequestTest.java @@ -0,0 +1,55 @@ +/*- + * ============LICENSE_START======================================================= + * vfc + * ================================================================================ + * Copyright (C) 2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2018-2019 AT&T Corporation. 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.policy.vfc; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; + +import java.util.UUID; + +import org.junit.Test; + +public class VfcRequestTest { + + @Test + public void testVfcRequest() { + VfcRequest request = new VfcRequest(); + assertNotNull(request); + assertNotEquals(0, request.hashCode()); + + String nsInstanceId = "Dorothy"; + request.setNsInstanceId(nsInstanceId); + assertEquals(nsInstanceId, request.getNsInstanceId()); + + UUID requestId = UUID.randomUUID(); + request.setRequestId(requestId); + assertEquals(requestId, request.getRequestId()); + + VfcHealRequest healRequest = new VfcHealRequest(); + request.setHealRequest(healRequest); + assertEquals(healRequest, request.getHealRequest()); + + assertNotEquals(0, request.hashCode()); + } +} diff --git a/models-interactions/model-impl/vfc/src/test/java/org/onap/policy/vfc/VfcResponseDescriptorTest.java b/models-interactions/model-impl/vfc/src/test/java/org/onap/policy/vfc/VfcResponseDescriptorTest.java new file mode 100644 index 000000000..571c475c9 --- /dev/null +++ b/models-interactions/model-impl/vfc/src/test/java/org/onap/policy/vfc/VfcResponseDescriptorTest.java @@ -0,0 +1,68 @@ +/*- + * ============LICENSE_START======================================================= + * vfc + * ================================================================================ + * Copyright (C) 2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2018-2019 AT&T Corporation. 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.policy.vfc; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; + +public class VfcResponseDescriptorTest { + + @Test + public void testVfcResponseDescriptor() { + VfcResponseDescriptor descriptor = new VfcResponseDescriptor(); + assertNotNull(descriptor); + assertNotEquals(0, descriptor.hashCode()); + + String errorCode = "WitchIsDead"; + descriptor.setErrorCode(errorCode); + assertEquals(errorCode, descriptor.getErrorCode()); + + String progress = "Visited Wizard"; + descriptor.setProgress(progress); + assertEquals(progress, descriptor.getProgress()); + + List<VfcResponseDescriptor> responseHistoryList = new ArrayList<>(); + descriptor.setResponseHistoryList(responseHistoryList); + assertEquals(responseHistoryList, descriptor.getResponseHistoryList()); + + String responseId = "WishHard"; + descriptor.setResponseId(responseId); + assertEquals(responseId, descriptor.getResponseId()); + + String status = "Back in Kansas"; + descriptor.setStatus(status); + assertEquals(status, descriptor.getStatus()); + + String statusDescription = "Back on the prairie"; + descriptor.setStatusDescription(statusDescription); + assertEquals(statusDescription, descriptor.getStatusDescription()); + + assertNotEquals(0, descriptor.hashCode()); + } +} diff --git a/models-interactions/model-impl/vfc/src/test/java/org/onap/policy/vfc/VfcResponseTest.java b/models-interactions/model-impl/vfc/src/test/java/org/onap/policy/vfc/VfcResponseTest.java new file mode 100644 index 000000000..196ae2f63 --- /dev/null +++ b/models-interactions/model-impl/vfc/src/test/java/org/onap/policy/vfc/VfcResponseTest.java @@ -0,0 +1,53 @@ +/*- + * ============LICENSE_START======================================================= + * vfc + * ================================================================================ + * Copyright (C) 2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2018-2019 AT&T Corporation. 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.policy.vfc; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; + +public class VfcResponseTest { + + @Test + public void testVfcResponse() { + VfcResponse response = new VfcResponse(); + assertNotNull(response); + assertNotEquals(0, response.hashCode()); + + String jobId = "GetToOz"; + response.setJobId(jobId); + assertEquals(jobId, response.getJobId()); + + String requestId = "Get Home"; + response.setRequestId(requestId); + assertEquals(requestId, response.getRequestId()); + + VfcResponseDescriptor responseDescriptor = new VfcResponseDescriptor(); + response.setResponseDescriptor(responseDescriptor); + assertEquals(responseDescriptor, response.getResponseDescriptor()); + + assertNotEquals(0, response.hashCode()); + } +} diff --git a/models-interactions/model-impl/vfc/src/test/java/org/onap/policy/vfc/util/SerializationTest.java b/models-interactions/model-impl/vfc/src/test/java/org/onap/policy/vfc/util/SerializationTest.java new file mode 100644 index 000000000..983760a03 --- /dev/null +++ b/models-interactions/model-impl/vfc/src/test/java/org/onap/policy/vfc/util/SerializationTest.java @@ -0,0 +1,35 @@ +/*- + * ============LICENSE_START======================================================= + * vfc + * ================================================================================ + * Copyright (C) 2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2018 AT&T Corporation. 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.policy.vfc.util; + +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; + +public class SerializationTest { + + @Test + public void test() { + assertNotNull(Serialization.gsonPretty); + } +} diff --git a/models-interactions/pom.xml b/models-interactions/pom.xml new file mode 100644 index 000000000..9bcd9f626 --- /dev/null +++ b/models-interactions/pom.xml @@ -0,0 +1,34 @@ +<!-- + ============LICENSE_START======================================================= + Copyright (C) 2019 Nordix Foundation. + ================================================================================ + 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. + + SPDX-License-Identifier: Apache-2.0 + ============LICENSE_END========================================================= +--> + +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.onap.policy.models</groupId> + <artifactId>policy-models</artifactId> + <version>2.0.0-SNAPSHOT</version> + </parent> + <artifactId>policy-models-interactions</artifactId> + <packaging>pom</packaging> + <name>${project.artifactId}</name> + <modules> + <module>model-impl</module> + </modules> +</project>
\ No newline at end of file @@ -1,3 +1,4 @@ +<?xml version="1.0" encoding="UTF-8"?> <!-- ============LICENSE_START======================================================= Copyright (C) 2018 Ericsson. All rights reserved. @@ -18,17 +19,13 @@ SPDX-License-Identifier: Apache-2.0 ============LICENSE_END========================================================= ---> - -<project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> +--><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.onap.policy.parent</groupId> <artifactId>integration</artifactId> <version>2.1.0-SNAPSHOT</version> - <relativePath /> + <relativePath/> </parent> <groupId>org.onap.policy.models</groupId> @@ -43,6 +40,7 @@ <derby.version>10.13.1.1</derby.version> <javax.ws.rs-api.version>2.0.1</javax.ws.rs-api.version> <policy.common.version>1.4.0-SNAPSHOT</policy.common.version> + <policy.drools-pdp.version>1.4.0-SNAPSHOT</policy.drools-pdp.version> <!-- sonar/jacoco overrides --> <!-- Overriding oparent default sonar/jacoco settings Combine all our reports into one file shared across sub-modules --> @@ -61,6 +59,7 @@ <module>models-decisions</module> <module>models-provider</module> <module>models-examples</module> + <module>models-interactions</module> </modules> <distributionManagement> @@ -262,7 +261,7 @@ </goals> </pluginExecutionFilter> <action> - <ignore /> + <ignore/> </action> </pluginExecution> </pluginExecutions> @@ -272,4 +271,4 @@ </plugins> </pluginManagement> </build> -</project> +</project>
\ No newline at end of file |