summaryrefslogtreecommitdiffstats
path: root/models-provider/src/test/java
diff options
context:
space:
mode:
authorrameshiyer27 <ramesh.murugan.iyer@est.tech>2022-02-07 17:07:38 +0000
committerrameshiyer27 <ramesh.murugan.iyer@est.tech>2022-02-10 14:20:42 +0000
commit45b653fc5a8d641452247eca5c80cf580609e9bf (patch)
tree06cfd4529db05dc23cbd63d2fe2e53799eb07bdf /models-provider/src/test/java
parent303d42453fbfcf2381f810b10a496b69aa8bc34b (diff)
Add policy metadataSet handling as node templates
Each metadataSet is represented as a 'node_template' in Tosca mapped to a specific node type. Support added for db operations of node templates as independent entities. Detailed documentation available here : https://wiki.onap.org/display/DW/Enable+Handling+of+Policy+Type+Metadata Issue-ID: POLICY-3832 Signed-off-by: zrrmmua <ramesh.murugan.iyer@est.tech> Change-Id: I6c189142b1778ba858aae27cd92d4f136d950208
Diffstat (limited to 'models-provider/src/test/java')
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java48
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyBadProviderImpl.java38
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderImpl.java359
3 files changed, 443 insertions, 2 deletions
diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java
index 57c261cb5..561ef5daa 100644
--- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java
+++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019-2021 Nordix Foundation.
+ * Copyright (C) 2019-2022 Nordix Foundation.
* Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
* ================================================================================
@@ -32,6 +32,7 @@ import static org.junit.Assert.assertTrue;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -53,9 +54,12 @@ import org.onap.policy.models.provider.PolicyModelsProviderParameters;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifierOptVersion;
import org.onap.policy.models.tosca.authorative.concepts.ToscaEntityFilter;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeType;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaTopologyTemplate;
import org.onap.policy.models.tosca.authorative.concepts.ToscaTypedEntityFilter;
/**
@@ -567,6 +571,31 @@ public class DatabasePolicyModelsProviderTest {
databaseProvider.close();
}
+ @Test
+ public void testToscaNodeTemplateHandling() throws PfModelException {
+ databaseProvider = new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters);
+
+ ToscaServiceTemplate serviceTemplate = makeNodeTemplate();
+
+ assertEquals("1.0.1",
+ databaseProvider.createToscaNodeTemplates(serviceTemplate).getToscaTopologyTemplate().getNodeTemplates()
+ .get("metadataSet1").getVersion());
+ assertEquals(1, databaseProvider.getNodeTemplateMetadataSets(null, null).size());
+
+ ToscaNodeTemplate nodeTemplate1 = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates()
+ .get("metadataSet1");
+ nodeTemplate1.setMetadata(Map.of("dummyKey", "updatedValue"));
+ serviceTemplate.getToscaTopologyTemplate().setNodeTemplates(Map.of("metadataSet1:1.0.1", nodeTemplate1));
+ assertEquals("updatedValue", databaseProvider.updateToscaNodeTemplates(serviceTemplate)
+ .getToscaTopologyTemplate().getNodeTemplates().get("metadataSet1").getMetadata().get("dummyKey"));
+
+ assertThatThrownBy(() -> {
+ databaseProvider.deleteToscaNodeTemplate("invalidName", "1.0.1");
+ }).hasMessage("node template invalidName:1.0.1 not found");
+
+ databaseProvider.close();
+ }
+
private List<PdpStatistics> makePdpStatisticsList() {
PdpStatistics pdpStatistics = new PdpStatistics();
pdpStatistics.setPdpInstanceId(NAME);
@@ -576,4 +605,21 @@ public class DatabasePolicyModelsProviderTest {
List<PdpStatistics> statisticsArrayList = List.of(pdpStatistics);
return statisticsArrayList;
}
+
+ private ToscaServiceTemplate makeNodeTemplate() {
+ ToscaServiceTemplate serviceTemplate = new ToscaServiceTemplate();
+ serviceTemplate.setToscaDefinitionsVersion("sample:1.1.0");
+ serviceTemplate.setToscaTopologyTemplate(new ToscaTopologyTemplate());
+ serviceTemplate.setNodeTypes(Map.of("org.onap.policy.metadataSet:1.0.0", new ToscaNodeType()));
+ ToscaNodeTemplate nodeTemplate1 = new ToscaNodeTemplate();
+ nodeTemplate1.setName("metadataSet1");
+ nodeTemplate1.setVersion("1.0.1");
+ nodeTemplate1.setType("org.onap.policy.metadataSet");
+ nodeTemplate1.setTypeVersion("1.0.0");
+ nodeTemplate1.setMetadata(Map.of("dummyKey", "dummyValue"));
+
+ serviceTemplate.getToscaTopologyTemplate().setNodeTemplates(Map.of("metadataSet1", nodeTemplate1));
+
+ return serviceTemplate;
+ }
}
diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyBadProviderImpl.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyBadProviderImpl.java
index 6cb95ee54..410ecf26a 100644
--- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyBadProviderImpl.java
+++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyBadProviderImpl.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019-2021 Nordix Foundation.
+ * Copyright (C) 2019-2022 Nordix Foundation.
* Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
* ================================================================================
@@ -27,8 +27,10 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
+import java.util.Map;
import javax.ws.rs.core.Response;
import lombok.NonNull;
+import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.base.PfModelRuntimeException;
import org.onap.policy.models.pap.concepts.PolicyAudit;
@@ -43,6 +45,8 @@ import org.onap.policy.models.pdp.persistence.provider.PdpFilterParameters;
import org.onap.policy.models.provider.PolicyModelsProvider;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifierOptVersion;
import org.onap.policy.models.tosca.authorative.concepts.ToscaEntityFilter;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaEntityKey;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
@@ -135,6 +139,38 @@ public class DummyBadProviderImpl implements PolicyModelsProvider {
}
@Override
+ public ToscaServiceTemplate createToscaNodeTemplates(@NonNull ToscaServiceTemplate serviceTemplate)
+ throws PfModelException {
+ return null;
+ }
+
+ @Override
+ public ToscaServiceTemplate updateToscaNodeTemplates(@NonNull ToscaServiceTemplate serviceTemplate)
+ throws PfModelRuntimeException, PfModelException {
+ return null;
+ }
+
+ @Override
+ public ToscaServiceTemplate deleteToscaNodeTemplate(@NonNull String name, @NonNull String version)
+ throws PfModelException {
+ return null;
+ }
+
+ @Override
+ public List<Map<ToscaEntityKey, Map<String, Object>>> getNodeTemplateMetadataSets(@NonNull String name,
+ @NonNull String version)
+ throws PfModelException {
+ return null;
+ }
+
+ @Override
+ public List<Map<PfConceptKey, ToscaNodeTemplate>> getToscaNodeTemplate(final String name,
+ final String version)
+ throws PfModelException {
+ return null;
+ }
+
+ @Override
public List<PdpGroup> getPdpGroups(String name) throws PfModelException {
return Collections.emptyList();
}
diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderImpl.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderImpl.java
new file mode 100644
index 000000000..dcc436a05
--- /dev/null
+++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderImpl.java
@@ -0,0 +1,359 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019-2022 Nordix Foundation.
+ * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2020 Bell Canada. 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=========================================================
+ */
+
+package org.onap.policy.models.provider.impl;
+
+import java.time.Instant;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import javax.ws.rs.core.Response;
+import lombok.NonNull;
+import org.onap.policy.common.utils.coder.StandardCoder;
+import org.onap.policy.common.utils.resources.ResourceUtils;
+import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.base.PfModelException;
+import org.onap.policy.models.base.PfModelRuntimeException;
+import org.onap.policy.models.pap.concepts.PolicyAudit;
+import org.onap.policy.models.pap.persistence.provider.PolicyAuditProvider.AuditFilter;
+import org.onap.policy.models.pdp.concepts.Pdp;
+import org.onap.policy.models.pdp.concepts.PdpGroup;
+import org.onap.policy.models.pdp.concepts.PdpGroupFilter;
+import org.onap.policy.models.pdp.concepts.PdpPolicyStatus;
+import org.onap.policy.models.pdp.concepts.PdpStatistics;
+import org.onap.policy.models.pdp.concepts.PdpSubGroup;
+import org.onap.policy.models.pdp.persistence.provider.PdpFilterParameters;
+import org.onap.policy.models.provider.PolicyModelsProvider;
+import org.onap.policy.models.provider.PolicyModelsProviderParameters;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifierOptVersion;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaEntityFilter;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaEntityKey;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaTypedEntityFilter;
+
+/**
+ * This class provides a dummy implementation of the Policy Models Provider for the ONAP Policy Framework.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ * @author Chenfei Gao (cgao@research.att.com)
+ */
+public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider {
+ /**
+ * Constructor that takes the parameters.
+ *
+ * @param parameters the parameters for the provider
+ */
+ public DummyPolicyModelsProviderImpl(final PolicyModelsProviderParameters parameters) {
+ // Default constructor
+ }
+
+ @Override
+ public void init() throws PfModelException {
+ // Not required on the dummy provider
+ }
+
+ @Override
+ public void close() {
+ // Not required on the dummy provider
+ }
+
+
+ @Override
+ public List<ToscaServiceTemplate> getServiceTemplateList(String name, String version) throws PfModelException {
+ return new ArrayList<>();
+ }
+
+ @Override
+ public List<ToscaServiceTemplate> getFilteredServiceTemplateList(
+ @NonNull ToscaEntityFilter<ToscaServiceTemplate> filter) throws PfModelException {
+ return new ArrayList<>();
+ }
+
+ @Override
+ public ToscaServiceTemplate createServiceTemplate(@NonNull ToscaServiceTemplate serviceTemplate)
+ throws PfModelException {
+ return serviceTemplate;
+ }
+
+ @Override
+ public ToscaServiceTemplate updateServiceTemplate(@NonNull ToscaServiceTemplate serviceTemplate)
+ throws PfModelException {
+ return serviceTemplate;
+ }
+
+ @Override
+ public ToscaServiceTemplate deleteServiceTemplate(@NonNull String name, @NonNull String version)
+ throws PfModelException {
+ return getDummyResponse("dummyimpl/DummyToscaServiceTemplateDeleteResponse.json");
+ }
+
+ @Override
+ public ToscaServiceTemplate getPolicyTypes(final String name, final String version) throws PfModelException {
+ return getDummyResponse("dummyimpl/DummyToscaPolicyTypeGetResponse.json");
+ }
+
+ @Override
+ public List<ToscaPolicyType> getPolicyTypeList(final String name, final String version) throws PfModelException {
+ return new ArrayList<>();
+ }
+
+ @Override
+ public ToscaServiceTemplate getFilteredPolicyTypes(ToscaEntityFilter<ToscaPolicyType> filter)
+ throws PfModelException {
+ return getDummyResponse("dummyimpl/DummyToscaPolicyTypeGetResponse.json");
+ }
+
+ @Override
+ public List<ToscaPolicyType> getFilteredPolicyTypeList(ToscaEntityFilter<ToscaPolicyType> filter) {
+ return new ArrayList<>();
+ }
+
+ @Override
+ public ToscaServiceTemplate createPolicyTypes(final ToscaServiceTemplate serviceTemplate) throws PfModelException {
+ return serviceTemplate;
+ }
+
+ @Override
+ public ToscaServiceTemplate updatePolicyTypes(final ToscaServiceTemplate serviceTemplate) throws PfModelException {
+ return serviceTemplate;
+ }
+
+ @Override
+ public ToscaServiceTemplate deletePolicyType(final String name, final String version) throws PfModelException {
+ return getDummyResponse("dummyimpl/DummyToscaPolicyTypeDeleteResponse.json");
+ }
+
+ @Override
+ public ToscaServiceTemplate getPolicies(final String name, final String version) throws PfModelException {
+ return getDummyResponse("dummyimpl/DummyToscaPolicyGetResponse.json");
+ }
+
+ @Override
+ public List<ToscaPolicy> getPolicyList(final String name, final String version) throws PfModelException {
+ return new ArrayList<>();
+ }
+
+ @Override
+ public ToscaServiceTemplate getFilteredPolicies(ToscaTypedEntityFilter<ToscaPolicy> filter)
+ throws PfModelException {
+ return getDummyResponse("dummyimpl/DummyToscaPolicyGetResponse.json");
+ }
+
+ @Override
+ public List<ToscaPolicy> getFilteredPolicyList(ToscaTypedEntityFilter<ToscaPolicy> filter) throws PfModelException {
+ return new ArrayList<>();
+ }
+
+ @Override
+ public ToscaServiceTemplate createPolicies(final ToscaServiceTemplate serviceTemplate) throws PfModelException {
+ return serviceTemplate;
+ }
+
+ @Override
+ public ToscaServiceTemplate updatePolicies(final ToscaServiceTemplate serviceTemplate) throws PfModelException {
+ return serviceTemplate;
+ }
+
+ @Override
+ public ToscaServiceTemplate deletePolicy(final String name, final String version) throws PfModelException {
+ return getDummyResponse("dummyimpl/DummyToscaPolicyDeleteResponse.json");
+ }
+
+ @Override
+ public ToscaServiceTemplate createToscaNodeTemplates(@NonNull ToscaServiceTemplate serviceTemplate)
+ throws PfModelException {
+ return getDummyNodeTemplateResponse("dummyimpl/DummyToscaNodeTemplateResponse.json");
+ }
+
+ @Override
+ public ToscaServiceTemplate updateToscaNodeTemplates(@NonNull ToscaServiceTemplate serviceTemplate)
+ throws PfModelRuntimeException, PfModelException {
+ return getDummyNodeTemplateResponse("dummyimpl/DummyToscaNodeTemplateResponse.json");
+ }
+
+ @Override
+ public ToscaServiceTemplate deleteToscaNodeTemplate(@NonNull String name, @NonNull String version)
+ throws PfModelException {
+ return getDummyNodeTemplateResponse("dummyimpl/DummyToscaNodeTemplateResponse.json");
+ }
+
+ @Override
+ public List<Map<ToscaEntityKey, Map<String, Object>>> getNodeTemplateMetadataSets(@NonNull String name,
+ @NonNull String version)
+ throws PfModelException {
+ return new ArrayList<>();
+ }
+
+ @Override
+ public List<Map<PfConceptKey, ToscaNodeTemplate>> getToscaNodeTemplate(final String name,
+ final String version)
+ throws PfModelException {
+ return new ArrayList<>();
+ }
+
+ @Override
+ public List<PdpGroup> getPdpGroups(final String name) throws PfModelException {
+ return new ArrayList<>();
+ }
+
+ @Override
+ public List<PdpGroup> getFilteredPdpGroups(PdpGroupFilter filter) throws PfModelException {
+ return new ArrayList<>();
+ }
+
+ @Override
+ public List<PdpGroup> createPdpGroups(final List<PdpGroup> pdpGroups) throws PfModelException {
+ return new ArrayList<>();
+ }
+
+ @Override
+ public List<PdpGroup> updatePdpGroups(final List<PdpGroup> pdpGroups) throws PfModelException {
+ return new ArrayList<>();
+ }
+
+ @Override
+ public void updatePdpSubGroup(final String pdpGroupName, final PdpSubGroup pdpSubGroup) throws PfModelException {
+ // Not implemented
+ }
+
+ @Override
+ public void updatePdp(String pdpGroupName, String pdpSubGroup, Pdp pdp) throws PfModelException {
+ // Not implemented
+ }
+
+ @Override
+ public PdpGroup deletePdpGroup(final String name) throws PfModelException {
+ return null;
+ }
+
+ @Override
+ public List<PdpStatistics> getFilteredPdpStatistics(PdpFilterParameters filterParams) throws PfModelException {
+ // Not implemented
+ return new ArrayList<>();
+ }
+
+ @Override
+ public List<PdpStatistics> createPdpStatistics(final List<PdpStatistics> pdpStatisticsList)
+ throws PfModelException {
+ // Not implemented
+ return new ArrayList<>();
+ }
+
+ @Override
+ public List<PdpStatistics> updatePdpStatistics(final List<PdpStatistics> pdpStatisticsList)
+ throws PfModelException {
+ // Not implemented
+ return new ArrayList<>();
+ }
+
+ @Override
+ public List<PdpStatistics> deletePdpStatistics(final String name, final Instant timestamp) {
+ // Not implemented
+ return new ArrayList<>();
+ }
+
+ @Override
+ public List<PdpPolicyStatus> getAllPolicyStatus() throws PfModelException {
+ // Not implemented
+ return new ArrayList<>();
+ }
+
+ @Override
+ public List<PdpPolicyStatus> getAllPolicyStatus(@NonNull ToscaConceptIdentifierOptVersion policy)
+ throws PfModelException {
+ // Not implemented
+ return new ArrayList<>();
+ }
+
+ @Override
+ public List<PdpPolicyStatus> getGroupPolicyStatus(String groupName) throws PfModelException {
+ // Not implemented
+ return new ArrayList<>();
+ }
+
+ @Override
+ public void cudPolicyStatus(Collection<PdpPolicyStatus> createObjs, Collection<PdpPolicyStatus> updateObjs,
+ Collection<PdpPolicyStatus> deleteObjs) {
+ // Not implemented
+ }
+
+ @Override
+ public void createAuditRecords(List<PolicyAudit> auditRecords) {
+ // Not implemented
+ }
+
+ @Override
+ public List<PolicyAudit> getAuditRecords(AuditFilter auditFilter) {
+ // Not implemented
+ return new ArrayList<>();
+ }
+
+ /**
+ * Return a ToscaServicetemplate dummy response.
+ *
+ * @param fileName the file name containing the dummy response
+ * @return the ToscaServiceTemplate with the dummy response
+ */
+ protected ToscaServiceTemplate getDummyResponse(final String fileName) {
+ var standardCoder = new StandardCoder();
+ ToscaServiceTemplate serviceTemplate;
+
+ try {
+ serviceTemplate =
+ standardCoder.decode(ResourceUtils.getResourceAsString(fileName), ToscaServiceTemplate.class);
+ if (serviceTemplate == null) {
+ throw new PfModelException(Response.Status.INTERNAL_SERVER_ERROR, "error reading specified file");
+ }
+ } catch (Exception exc) {
+ throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, "error serializing object", exc);
+ }
+
+ return serviceTemplate;
+ }
+
+ /**
+ * Return a tosca node template dummy response.
+ *
+ * @param fileName the file name containing the dummy response
+ * @return the service template with the dummy response
+ */
+ protected ToscaServiceTemplate getDummyNodeTemplateResponse(final String fileName) {
+ var standardCoder = new StandardCoder();
+ ToscaServiceTemplate serviceTemplate;
+
+ try {
+ serviceTemplate =
+ standardCoder.decode(ResourceUtils.getResourceAsString(fileName), ToscaServiceTemplate.class);
+ if (serviceTemplate == null) {
+ throw new PfModelException(Response.Status.INTERNAL_SERVER_ERROR, "error reading specified file");
+ }
+ } catch (Exception exc) {
+ throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, "error serializing object", exc);
+ }
+
+ return serviceTemplate;
+ }
+}