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 PolicyModelsProvider dummyProvider = new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters);
84 assertNotNull(dummyProvider.getPolicyTypes("name", VERSION));
85 assertNotNull(dummyProvider.getFilteredPolicyTypes(ToscaPolicyTypeFilter.builder().build()));
86 assertNotNull(dummyProvider.getPolicyTypeList("name", VERSION));
87 assertNotNull(dummyProvider.getFilteredPolicyTypeList(ToscaPolicyTypeFilter.builder().build()));
88 assertNotNull(dummyProvider.createPolicyTypes(new ToscaServiceTemplate()));
89 assertNotNull(dummyProvider.updatePolicyTypes(new ToscaServiceTemplate()));
90 assertNotNull(dummyProvider.deletePolicyType("name", VERSION));
92 assertNotNull(dummyProvider.getPolicies("name", VERSION));
93 assertNotNull(dummyProvider.getFilteredPolicies(ToscaPolicyFilter.builder().build()));
94 assertNotNull(dummyProvider.getPolicyList("name", VERSION));
95 assertNotNull(dummyProvider.getFilteredPolicyList(ToscaPolicyFilter.builder().build()));
96 assertNotNull(dummyProvider.createPolicies(new ToscaServiceTemplate()));
97 assertNotNull(dummyProvider.updatePolicies(new ToscaServiceTemplate()));
98 assertNotNull(dummyProvider.deletePolicy("name", VERSION));
100 assertNotNull(dummyProvider.getOperationalPolicy(POLICY_ID, "1"));
101 assertNotNull(dummyProvider.createOperationalPolicy(new LegacyOperationalPolicy()));
102 assertNotNull(dummyProvider.updateOperationalPolicy(new LegacyOperationalPolicy()));
103 assertNotNull(dummyProvider.deleteOperationalPolicy(POLICY_ID, "1"));
105 assertNotNull(dummyProvider.getGuardPolicy(POLICY_ID, "1"));
106 assertNotNull(dummyProvider.createGuardPolicy(new LegacyGuardPolicyInput()));
107 assertNotNull(dummyProvider.updateGuardPolicy(new LegacyGuardPolicyInput()));
108 assertNotNull(dummyProvider.deleteGuardPolicy(POLICY_ID, "1"));
110 assertTrue(dummyProvider.getPdpGroups("name").isEmpty());
111 assertTrue(dummyProvider.getFilteredPdpGroups(PdpGroupFilter.builder().build()).isEmpty());
112 assertTrue(dummyProvider.createPdpGroups(new ArrayList<>()).isEmpty());
113 assertTrue(dummyProvider.updatePdpGroups(new ArrayList<>()).isEmpty());
114 assertNull(dummyProvider.deletePdpGroup("name"));
116 dummyProvider.updatePdpSubGroup("name", new PdpSubGroup());
117 dummyProvider.updatePdp("name", "type", new Pdp());
118 dummyProvider.updatePdpStatistics(new ArrayList<>());
119 assertTrue(dummyProvider.getPdpStatistics("name", null).isEmpty());
123 public void testDummyResponse() {
124 try (DummyPolicyModelsProviderSubImpl resp =
125 new DummyPolicyModelsProviderSubImpl(new PolicyModelsProviderParameters())) {
126 assertThatThrownBy(resp::getBadDummyResponse1).hasMessage("error serializing object");
129 try (DummyPolicyModelsProviderSubImpl resp =
130 new DummyPolicyModelsProviderSubImpl(new PolicyModelsProviderParameters())) {
131 assertThatThrownBy(resp::getBadDummyResponse2).hasMessage("error serializing object");