2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019-2020 Nordix Foundation.
4 * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.models.provider.impl;
24 import static org.assertj.core.api.Assertions.assertThatThrownBy;
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertNotNull;
27 import static org.junit.Assert.assertNull;
28 import static org.junit.Assert.assertTrue;
30 import java.util.ArrayList;
32 import org.junit.Test;
33 import org.onap.policy.models.pdp.concepts.Pdp;
34 import org.onap.policy.models.pdp.concepts.PdpGroupFilter;
35 import org.onap.policy.models.pdp.concepts.PdpSubGroup;
36 import org.onap.policy.models.provider.PolicyModelsProvider;
37 import org.onap.policy.models.provider.PolicyModelsProviderFactory;
38 import org.onap.policy.models.provider.PolicyModelsProviderParameters;
39 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyFilter;
40 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeFilter;
41 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
42 import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyInput;
43 import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
46 * Test the dummy models provider implementation.
48 * @author Liam Fallon (liam.fallon@est.tech)
50 public class DummyPolicyModelsProviderTest {
52 private static final String POLICY_ID = "policy_id";
53 private static final String VERSION = "version";
56 public void testProvider() throws Exception {
57 PolicyModelsProviderParameters parameters = new PolicyModelsProviderParameters();
58 parameters.setImplementation(DummyPolicyModelsProviderImpl.class.getName());
59 parameters.setDatabaseUrl("jdbc:dummy");
60 parameters.setPersistenceUnit("dummy");
62 try (PolicyModelsProvider dummyProvider =
63 new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters)) {
67 ToscaServiceTemplate serviceTemplate = dummyProvider.getPolicies("onap.vcpe.tca", "1.0.0");
68 assertNotNull(serviceTemplate);
69 assertEquals("onap.policies.monitoring.cdap.tca.hi.lo.app",
70 serviceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get("onap.vcpe.tca").getType());
75 public void testProviderMethods() throws Exception {
76 PolicyModelsProviderParameters parameters = new PolicyModelsProviderParameters();
77 parameters.setImplementation(DummyPolicyModelsProviderImpl.class.getName());
78 parameters.setDatabaseUrl("jdbc:dummy");
79 parameters.setPersistenceUnit("dummy");
81 try (PolicyModelsProvider dummyProvider =
82 new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters)) {
85 assertNotNull(dummyProvider.getPolicyTypes("name", VERSION));
86 assertNotNull(dummyProvider.getFilteredPolicyTypes(ToscaPolicyTypeFilter.builder().build()));
87 assertNotNull(dummyProvider.getPolicyTypeList("name", VERSION));
88 assertNotNull(dummyProvider.getFilteredPolicyTypeList(ToscaPolicyTypeFilter.builder().build()));
89 assertNotNull(dummyProvider.createPolicyTypes(new ToscaServiceTemplate()));
90 assertNotNull(dummyProvider.updatePolicyTypes(new ToscaServiceTemplate()));
91 assertNotNull(dummyProvider.deletePolicyType("name", VERSION));
93 assertNotNull(dummyProvider.getPolicies("name", VERSION));
94 assertNotNull(dummyProvider.getFilteredPolicies(ToscaPolicyFilter.builder().build()));
95 assertNotNull(dummyProvider.getPolicyList("name", VERSION));
96 assertNotNull(dummyProvider.getFilteredPolicyList(ToscaPolicyFilter.builder().build()));
97 assertNotNull(dummyProvider.createPolicies(new ToscaServiceTemplate()));
98 assertNotNull(dummyProvider.updatePolicies(new ToscaServiceTemplate()));
99 assertNotNull(dummyProvider.deletePolicy("name", VERSION));
101 assertNotNull(dummyProvider.getOperationalPolicy(POLICY_ID, "1"));
102 assertNotNull(dummyProvider.createOperationalPolicy(new LegacyOperationalPolicy()));
103 assertNotNull(dummyProvider.updateOperationalPolicy(new LegacyOperationalPolicy()));
104 assertNotNull(dummyProvider.deleteOperationalPolicy(POLICY_ID, "1"));
106 assertNotNull(dummyProvider.getGuardPolicy(POLICY_ID, "1"));
107 assertNotNull(dummyProvider.createGuardPolicy(new LegacyGuardPolicyInput()));
108 assertNotNull(dummyProvider.updateGuardPolicy(new LegacyGuardPolicyInput()));
109 assertNotNull(dummyProvider.deleteGuardPolicy(POLICY_ID, "1"));
111 assertTrue(dummyProvider.getPdpGroups("name").isEmpty());
112 assertTrue(dummyProvider.getFilteredPdpGroups(PdpGroupFilter.builder().build()).isEmpty());
113 assertTrue(dummyProvider.createPdpGroups(new ArrayList<>()).isEmpty());
114 assertTrue(dummyProvider.updatePdpGroups(new ArrayList<>()).isEmpty());
115 assertNull(dummyProvider.deletePdpGroup("name"));
117 dummyProvider.updatePdpSubGroup("name", new PdpSubGroup());
118 dummyProvider.updatePdp("name", "type", new Pdp());
119 dummyProvider.updatePdpStatistics(new ArrayList<>());
120 assertTrue(dummyProvider.getPdpStatistics("name", null).isEmpty());
125 public void testDummyResponse() {
126 try (DummyPolicyModelsProviderSubImpl resp =
127 new DummyPolicyModelsProviderSubImpl(new PolicyModelsProviderParameters())) {
128 assertThatThrownBy(resp::getBadDummyResponse1).hasMessage("error serializing object");
131 try (DummyPolicyModelsProviderSubImpl resp =
132 new DummyPolicyModelsProviderSubImpl(new PolicyModelsProviderParameters())) {
133 assertThatThrownBy(resp::getBadDummyResponse2).hasMessage("error serializing object");