summaryrefslogtreecommitdiffstats
path: root/models-provider/src/test/java/org
diff options
context:
space:
mode:
authorPamela Dragosh <pdragosh@research.att.com>2019-06-18 12:22:21 +0000
committerGerrit Code Review <gerrit@onap.org>2019-06-18 12:22:21 +0000
commit26e7f16c6e3f224d38e09441be30c1d4fa795c2a (patch)
treed784ca790e8865577d6e2b0b44ee869af4eab45e /models-provider/src/test/java/org
parent92bd3a4d89a3f7740094e0c5dac278722fc3f27c (diff)
parent77df45928640808633af05908c680955848e4cd2 (diff)
Merge "Fix simple sonar issues in models: errors to sim-pdp"
Diffstat (limited to 'models-provider/src/test/java/org')
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/PolicyModelsProviderFactoryTest.java51
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java491
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyBadProviderImpl.java40
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderTest.java133
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyGuardPersistenceTest.java2
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyOperationalPersistenceTest.java2
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyPersistenceTest.java2
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyToscaPersistenceTest.java2
8 files changed, 357 insertions, 366 deletions
diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/PolicyModelsProviderFactoryTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/PolicyModelsProviderFactoryTest.java
index 628d9fc53..5e87f808d 100644
--- a/models-provider/src/test/java/org/onap/policy/models/provider/PolicyModelsProviderFactoryTest.java
+++ b/models-provider/src/test/java/org/onap/policy/models/provider/PolicyModelsProviderFactoryTest.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019 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.
@@ -20,11 +21,9 @@
package org.onap.policy.models.provider;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import lombok.ToString;
-
import org.junit.Test;
/**
@@ -39,52 +38,38 @@ public class PolicyModelsProviderFactoryTest {
public void testFactory() {
PolicyModelsProviderFactory factory = new PolicyModelsProviderFactory();
- try {
+ assertThatThrownBy(() -> {
factory.createPolicyModelsProvider(null);
- fail("test should throw an exception here");
- } catch (Exception exc) {
- assertEquals("parameters is marked @NonNull but is null", exc.getMessage());
- }
+ }).hasMessage("parameters is marked @NonNull but is null");
- try {
+ assertThatThrownBy(() -> {
PolicyModelsProviderParameters pars = new PolicyModelsProviderParameters();
pars.setImplementation(null);
factory.createPolicyModelsProvider(pars);
- fail("test should throw an exception here");
- } catch (Exception exc) {
- assertEquals("could not find implementation of the \"PolicyModelsProvider\" interface \"null\"",
- exc.getMessage());
- }
+ }).hasMessage("could not find implementation of the \"PolicyModelsProvider\" interface \"null\"");
- try {
+ assertThatThrownBy(() -> {
PolicyModelsProviderParameters pars = new PolicyModelsProviderParameters();
pars.setImplementation("com.acmecorp.RoadRunner");
factory.createPolicyModelsProvider(pars);
- fail("test should throw an exception here");
- } catch (Exception exc) {
- assertEquals("could not find implementation of the \"PolicyModelsProvider\" "
- + "interface \"com.acmecorp.RoadRunner\"", exc.getMessage());
- }
+ })
+ .hasMessage("could not find implementation of the \"PolicyModelsProvider\" "
+ + "interface \"com.acmecorp.RoadRunner\"");
- try {
+ assertThatThrownBy(() -> {
PolicyModelsProviderParameters pars = new PolicyModelsProviderParameters();
pars.setImplementation("java.lang.String");
factory.createPolicyModelsProvider(pars);
- fail("test should throw an exception here");
- } catch (Exception exc) {
- assertEquals(
- "the class \"java.lang.String\" is not an implementation of the \"PolicyModelsProvider\" interface",
- exc.getMessage());
- }
+ })
+ .hasMessage(
+ "the class \"java.lang.String\" is not an implementation of the \"PolicyModelsProvider\" interface");
- try {
+ assertThatThrownBy(() -> {
PolicyModelsProviderParameters pars = new PolicyModelsProviderParameters();
pars.setImplementation("org.onap.policy.models.provider.impl.DummyBadProviderImpl");
factory.createPolicyModelsProvider(pars);
- fail("test should throw an exception here");
- } catch (Exception exc) {
- assertEquals("could not create an instance of PolicyModelsProvider "
- + "\"org.onap.policy.models.provider.impl.DummyBadProviderImpl\"", exc.getMessage());
- }
+ })
+ .hasMessage("could not create an instance of PolicyModelsProvider "
+ + "\"org.onap.policy.models.provider.impl.DummyBadProviderImpl\"");
}
}
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 c188560e5..d5c03a2cd 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,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019 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.
@@ -57,6 +58,30 @@ import org.slf4j.LoggerFactory;
* @author Liam Fallon (liam.fallon@est.tech)
*/
public class DatabasePolicyModelsProviderTest {
+ private static final String NAME = "name";
+
+ private static final String TEMPLATE_IS_NULL = "serviceTemplate is marked @NonNull but is null";
+
+ private static final String POLICY_ID_IS_NULL = "policyId is marked @NonNull but is null";
+
+ private static final String PDP_TYPE_IS_NULL = "pdpType is marked @NonNull but is null";
+
+ private static final String SUBGROUP_IS_NULL = "pdpSubGroup is marked @NonNull but is null";
+
+ private static final String GROUP_IS_NULL = "pdpGroupName is marked @NonNull but is null";
+
+ private static final String NAME_IS_NULL = "name is marked @NonNull but is null";
+
+ private static final String FILTER_IS_NULL = "filter is marked @NonNull but is null";
+
+ private static final String INSTANCE = "Instance";
+
+ private static final String POLICY_ID = "policy_id";
+
+ private static final String GROUP = "group";
+
+ private static final String VERSION_100 = "1.0.0";
+
private static final Logger LOGGER = LoggerFactory.getLogger(DatabasePolicyModelsProviderTest.class);
PolicyModelsProviderParameters parameters;
@@ -85,302 +110,284 @@ public class DatabasePolicyModelsProviderTest {
parameters.setDatabaseUrl("jdbc://www.acmecorp.nonexist");
- try {
- databaseProvider.close();
- databaseProvider.init();
- } catch (Exception pfme) {
- fail("test shold not throw an exception here");
- }
+ databaseProvider.close();
+ databaseProvider.init();
+
databaseProvider.close();
parameters.setDatabaseUrl("jdbc:h2:mem:testdb");
parameters.setPersistenceUnit("WileECoyote");
- assertThatThrownBy(() -> {
- databaseProvider.init();
- }).hasMessageContaining("could not create Data Access Object (DAO)");
+ assertThatThrownBy(databaseProvider::init).hasMessageContaining("could not create Data Access Object (DAO)");
parameters.setPersistenceUnit("ToscaConceptTest");
- try {
- databaseProvider.init();
- databaseProvider.close();
- } catch (Exception pfme) {
- pfme.printStackTrace();
- fail("test shold not throw an exception here");
- }
+ databaseProvider.init();
+ databaseProvider.close();
assertThatThrownBy(() -> {
databaseProvider.init();
databaseProvider.init();
}).hasMessage("provider is already initialized");
- try {
- databaseProvider.close();
- } catch (Exception pfme) {
- fail("test shold not throw an exception here");
- }
+ databaseProvider.close();
- try {
- databaseProvider.close();
- } catch (Exception pfme) {
- fail("test shold not throw an exception here");
- }
+ databaseProvider.close();
}
@Test
public void testProviderMethodsNull() throws Exception {
- PolicyModelsProvider databaseProvider =
- new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters);
- assertThatThrownBy(() -> {
- databaseProvider.getFilteredPolicyTypes(null);
- }).hasMessage("filter is marked @NonNull but is null");
+ try (PolicyModelsProvider databaseProvider =
+ new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters)) {
- assertThatThrownBy(() -> {
- databaseProvider.getFilteredPolicyTypeList(null);
- }).hasMessage("filter is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.getFilteredPolicyTypes(null);
+ }).hasMessage(FILTER_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.createPolicyTypes(null);
- }).hasMessage("serviceTemplate is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.getFilteredPolicyTypeList(null);
+ }).hasMessage(FILTER_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.updatePolicyTypes(null);
- }).hasMessage("serviceTemplate is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.createPolicyTypes(null);
+ }).hasMessage(TEMPLATE_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.deletePolicyType(null, null);
- }).hasMessage("name is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.updatePolicyTypes(null);
+ }).hasMessage(TEMPLATE_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.deletePolicyType("aaa", null);
- }).hasMessage("version is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.deletePolicyType(null, null);
+ }).hasMessage(NAME_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.deletePolicyType(null, "aaa");
- }).hasMessage("name is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.deletePolicyType("aaa", null);
+ }).hasMessage("version is marked @NonNull but is null");
- assertThatThrownBy(() -> {
- databaseProvider.getFilteredPolicies(null);
- }).hasMessage("filter is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.deletePolicyType(null, "aaa");
+ }).hasMessage(NAME_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.getFilteredPolicyList(null);
- }).hasMessage("filter is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.getFilteredPolicies(null);
+ }).hasMessage(FILTER_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.createPolicies(null);
- }).hasMessage("serviceTemplate is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.getFilteredPolicyList(null);
+ }).hasMessage(FILTER_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.updatePolicies(null);
- }).hasMessage("serviceTemplate is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.createPolicies(null);
+ }).hasMessage(TEMPLATE_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.deletePolicy(null, null);
- }).hasMessage("name is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.updatePolicies(null);
+ }).hasMessage(TEMPLATE_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.deletePolicy(null, "aaa");
- }).hasMessage("name is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.deletePolicy(null, null);
+ }).hasMessage(NAME_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.deletePolicy("aaa", null);
- }).hasMessage("version is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.deletePolicy(null, "aaa");
+ }).hasMessage(NAME_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.getOperationalPolicy(null, null);
- }).hasMessage("policyId is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.deletePolicy("aaa", null);
+ }).hasMessage("version is marked @NonNull but is null");
- assertThatThrownBy(() -> {
- databaseProvider.getOperationalPolicy(null, "");
- }).hasMessage("policyId is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.getOperationalPolicy(null, null);
+ }).hasMessage(POLICY_ID_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.getOperationalPolicy("", null);
- }).hasMessage("no policy found for policy: :null");
+ assertThatThrownBy(() -> {
+ databaseProvider.getOperationalPolicy(null, "");
+ }).hasMessage(POLICY_ID_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.createOperationalPolicy(null);
- }).hasMessage("legacyOperationalPolicy is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.getOperationalPolicy("", null);
+ }).hasMessage("no policy found for policy: :null");
- assertThatThrownBy(() -> {
- databaseProvider.updateOperationalPolicy(null);
- }).hasMessage("legacyOperationalPolicy is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.createOperationalPolicy(null);
+ }).hasMessage("legacyOperationalPolicy is marked @NonNull but is null");
- assertThatThrownBy(() -> {
- databaseProvider.deleteOperationalPolicy(null, null);
- }).hasMessage("policyId is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.updateOperationalPolicy(null);
+ }).hasMessage("legacyOperationalPolicy is marked @NonNull but is null");
- assertThatThrownBy(() -> {
- databaseProvider.deleteOperationalPolicy(null, "");
- }).hasMessage("policyId is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.deleteOperationalPolicy(null, null);
+ }).hasMessage(POLICY_ID_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.deleteOperationalPolicy("", null);
- }).hasMessage("policyVersion is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.deleteOperationalPolicy(null, "");
+ }).hasMessage(POLICY_ID_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.getGuardPolicy(null, null);
- }).hasMessage("policyId is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.deleteOperationalPolicy("", null);
+ }).hasMessage("policyVersion is marked @NonNull but is null");
- assertThatThrownBy(() -> {
- databaseProvider.getGuardPolicy(null, "");
- }).hasMessage("policyId is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.getGuardPolicy(null, null);
+ }).hasMessage(POLICY_ID_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.getGuardPolicy("", null);
- }).hasMessage("no policy found for policy: :null");
+ assertThatThrownBy(() -> {
+ databaseProvider.getGuardPolicy(null, "");
+ }).hasMessage(POLICY_ID_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.createGuardPolicy(null);
- }).hasMessage("legacyGuardPolicy is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.getGuardPolicy("", null);
+ }).hasMessage("no policy found for policy: :null");
- assertThatThrownBy(() -> {
- databaseProvider.updateGuardPolicy(null);
- }).hasMessage("legacyGuardPolicy is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.createGuardPolicy(null);
+ }).hasMessage("legacyGuardPolicy is marked @NonNull but is null");
- assertThatThrownBy(() -> {
- databaseProvider.deleteGuardPolicy(null, null);
- }).hasMessage("policyId is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.updateGuardPolicy(null);
+ }).hasMessage("legacyGuardPolicy is marked @NonNull but is null");
- assertThatThrownBy(() -> {
- databaseProvider.deleteGuardPolicy(null, "");
- }).hasMessage("policyId is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.deleteGuardPolicy(null, null);
+ }).hasMessage(POLICY_ID_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.deleteGuardPolicy("", null);
- }).hasMessage("policyVersion is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.deleteGuardPolicy(null, "");
+ }).hasMessage(POLICY_ID_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.getFilteredPdpGroups(null);
- }).hasMessage("filter is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.deleteGuardPolicy("", null);
+ }).hasMessage("policyVersion is marked @NonNull but is null");
- assertThatThrownBy(() -> {
- databaseProvider.createPdpGroups(null);
- }).hasMessage("pdpGroups is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.getFilteredPdpGroups(null);
+ }).hasMessage(FILTER_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.updatePdpGroups(null);
- }).hasMessage("pdpGroups is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.createPdpGroups(null);
+ }).hasMessage("pdpGroups is marked @NonNull but is null");
- assertThatThrownBy(() -> {
- databaseProvider.updatePdpSubGroup(null, null);
- }).hasMessage("pdpGroupName is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.updatePdpGroups(null);
+ }).hasMessage("pdpGroups is marked @NonNull but is null");
- assertThatThrownBy(() -> {
- databaseProvider.updatePdpSubGroup(null, new PdpSubGroup());
- }).hasMessage("pdpGroupName is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.updatePdpSubGroup(null, null);
+ }).hasMessage(GROUP_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.updatePdpSubGroup("name", null);
- }).hasMessage("pdpSubGroup is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.updatePdpSubGroup(null, new PdpSubGroup());
+ }).hasMessage(GROUP_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.updatePdpSubGroup("name", new PdpSubGroup());
- }).hasMessage("parameter \"localName\" is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.updatePdpSubGroup(NAME, null);
+ }).hasMessage(SUBGROUP_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.updatePdp(null, null, null);
- }).hasMessage("pdpGroupName is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.updatePdpSubGroup(NAME, new PdpSubGroup());
+ }).hasMessage("parameter \"localName\" is null");
- assertThatThrownBy(() -> {
- databaseProvider.updatePdp(null, null, new Pdp());
- }).hasMessage("pdpGroupName is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.updatePdp(null, null, null);
+ }).hasMessage(GROUP_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.updatePdp(null, "sub", null);
- }).hasMessage("pdpGroupName is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.updatePdp(null, null, new Pdp());
+ }).hasMessage(GROUP_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.updatePdp(null, "sub", new Pdp());
- }).hasMessage("pdpGroupName is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.updatePdp(null, "sub", null);
+ }).hasMessage(GROUP_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.updatePdp("name", null, null);
- }).hasMessage("pdpSubGroup is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.updatePdp(null, "sub", new Pdp());
+ }).hasMessage(GROUP_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.updatePdp("name", null, new Pdp());
- }).hasMessage("pdpSubGroup is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.updatePdp(NAME, null, null);
+ }).hasMessage(SUBGROUP_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.updatePdp("name", "sub", null);
- }).hasMessage("pdp is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.updatePdp(NAME, null, new Pdp());
+ }).hasMessage(SUBGROUP_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.updatePdp("name", "sub", new Pdp());
- }).hasMessage("parameter \"localName\" is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.updatePdp(NAME, "sub", null);
+ }).hasMessage("pdp is marked @NonNull but is null");
- assertThatThrownBy(() -> {
- databaseProvider.deletePdpGroup(null);
- }).hasMessage("name is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.updatePdp(NAME, "sub", new Pdp());
+ }).hasMessage("parameter \"localName\" is null");
- assertThatThrownBy(() -> {
- databaseProvider.updatePdpStatistics(null, null, null, null);
- }).hasMessage("pdpGroupName is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.deletePdpGroup(null);
+ }).hasMessage(NAME_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.updatePdpStatistics(null, null, null, new PdpStatistics());
- }).hasMessage("pdpGroupName is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.updatePdpStatistics(null, null, null, null);
+ }).hasMessage(GROUP_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.updatePdpStatistics(null, null, "Instance", null);
- }).hasMessage("pdpGroupName is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.updatePdpStatistics(null, null, null, new PdpStatistics());
+ }).hasMessage(GROUP_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.updatePdpStatistics(null, null, "Instance", new PdpStatistics());
- }).hasMessage("pdpGroupName is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.updatePdpStatistics(null, null, INSTANCE, null);
+ }).hasMessage(GROUP_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.updatePdpStatistics(null, "type", null, null);
- }).hasMessage("pdpGroupName is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.updatePdpStatistics(null, null, INSTANCE, new PdpStatistics());
+ }).hasMessage(GROUP_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.updatePdpStatistics(null, "type", null, new PdpStatistics());
- }).hasMessage("pdpGroupName is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.updatePdpStatistics(null, "type", null, null);
+ }).hasMessage(GROUP_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.updatePdpStatistics(null, "type", "Instance", null);
- }).hasMessage("pdpGroupName is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.updatePdpStatistics(null, "type", null, new PdpStatistics());
+ }).hasMessage(GROUP_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.updatePdpStatistics(null, "type", "Instance", new PdpStatistics());
- }).hasMessage("pdpGroupName is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.updatePdpStatistics(null, "type", INSTANCE, null);
+ }).hasMessage(GROUP_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.updatePdpStatistics("name", null, null, null);
- }).hasMessage("pdpType is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.updatePdpStatistics(null, "type", INSTANCE, new PdpStatistics());
+ }).hasMessage(GROUP_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.updatePdpStatistics("name", null, null, new PdpStatistics());
- }).hasMessage("pdpType is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.updatePdpStatistics(NAME, null, null, null);
+ }).hasMessage(PDP_TYPE_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.updatePdpStatistics("name", null, "Instance", null);
- }).hasMessage("pdpType is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.updatePdpStatistics(NAME, null, null, new PdpStatistics());
+ }).hasMessage(PDP_TYPE_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.updatePdpStatistics("name", null, "Instance", new PdpStatistics());
- }).hasMessage("pdpType is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.updatePdpStatistics(NAME, null, INSTANCE, null);
+ }).hasMessage(PDP_TYPE_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.updatePdpStatistics("name", "type", null, null);
- }).hasMessage("pdpInstanceId is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.updatePdpStatistics(NAME, null, INSTANCE, new PdpStatistics());
+ }).hasMessage(PDP_TYPE_IS_NULL);
- assertThatThrownBy(() -> {
- databaseProvider.updatePdpStatistics("name", "type", null, new PdpStatistics());
- }).hasMessage("pdpInstanceId is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.updatePdpStatistics(NAME, "type", null, null);
+ }).hasMessage("pdpInstanceId is marked @NonNull but is null");
- assertThatThrownBy(() -> {
- databaseProvider.updatePdpStatistics("name", "type", "Instance", null);
- }).hasMessage("pdpStatistics is marked @NonNull but is null");
+ assertThatThrownBy(() -> {
+ databaseProvider.updatePdpStatistics(NAME, "type", null, new PdpStatistics());
+ }).hasMessage("pdpInstanceId is marked @NonNull but is null");
- databaseProvider.updatePdpStatistics("name", "type", "Instance", new PdpStatistics());
+ assertThatThrownBy(() -> {
+ databaseProvider.updatePdpStatistics(NAME, "type", INSTANCE, null);
+ }).hasMessage("pdpStatistics is marked @NonNull but is null");
- databaseProvider.close();
+ databaseProvider.updatePdpStatistics(NAME, "type", INSTANCE, new PdpStatistics());
+ }
}
@Test
@@ -391,7 +398,7 @@ public class DatabasePolicyModelsProviderTest {
databaseProvider.close();
assertThatThrownBy(() -> {
- databaseProvider.getPolicyTypes("name", "version");
+ databaseProvider.getPolicyTypes(NAME, "version");
}).hasMessage("policy models provider is not initilaized");
}
@@ -400,8 +407,8 @@ public class DatabasePolicyModelsProviderTest {
try (PolicyModelsProvider databaseProvider =
new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters)) {
- assertTrue(databaseProvider.getPolicyTypes("name", "1.0.0").getPolicyTypes().isEmpty());
- assertEquals(0, databaseProvider.getPolicyTypeList("name", "1.0.0").size());
+ assertTrue(databaseProvider.getPolicyTypes(NAME, VERSION_100).getPolicyTypes().isEmpty());
+ assertTrue(databaseProvider.getPolicyTypeList(NAME, VERSION_100).isEmpty());
assertEquals(0, databaseProvider.getFilteredPolicyTypes(ToscaPolicyTypeFilter.builder().build())
.getPolicyTypes().size());
assertEquals(0, databaseProvider.getFilteredPolicyTypeList(ToscaPolicyTypeFilter.builder().build()).size());
@@ -414,13 +421,13 @@ public class DatabasePolicyModelsProviderTest {
databaseProvider.updatePolicyTypes(new ToscaServiceTemplate());
}).hasMessage("no policy types specified on service template");
- assertTrue(databaseProvider.deletePolicyType("name", "1.0.0").getPolicyTypes().isEmpty());
+ assertTrue(databaseProvider.deletePolicyType(NAME, VERSION_100).getPolicyTypes().isEmpty());
- assertTrue(databaseProvider.deletePolicyType("name", "1.0.0").getPolicyTypes().isEmpty());
+ assertTrue(databaseProvider.deletePolicyType(NAME, VERSION_100).getPolicyTypes().isEmpty());
assertTrue(
- databaseProvider.getPolicies("name", "1.0.0").getToscaTopologyTemplate().getPolicies().isEmpty());
- assertEquals(0, databaseProvider.getPolicyList("name", "1.0.0").size());
+ databaseProvider.getPolicies(NAME, VERSION_100).getToscaTopologyTemplate().getPolicies().isEmpty());
+ assertTrue(databaseProvider.getPolicyList(NAME, VERSION_100).isEmpty());
assertEquals(0, databaseProvider.getFilteredPolicies(ToscaPolicyFilter.builder().build())
.getToscaTopologyTemplate().getPolicies().size());
assertEquals(0, databaseProvider.getFilteredPolicyList(ToscaPolicyFilter.builder().build()).size());
@@ -437,31 +444,31 @@ public class DatabasePolicyModelsProviderTest {
.isEmpty());
assertThatThrownBy(() -> {
- databaseProvider.getOperationalPolicy("policy_id", null);
+ databaseProvider.getOperationalPolicy(POLICY_ID, null);
}).hasMessage("no policy found for policy: policy_id:null");
assertThatThrownBy(() -> {
- databaseProvider.getOperationalPolicy("policy_id", "10");
+ databaseProvider.getOperationalPolicy(POLICY_ID, "10");
}).hasMessage("no policy found for policy: policy_id:10");
assertThatThrownBy(() -> {
databaseProvider.createOperationalPolicy(new LegacyOperationalPolicy());
- }).hasMessage("name is marked @NonNull but is null");
+ }).hasMessage(NAME_IS_NULL);
assertThatThrownBy(() -> {
databaseProvider.updateOperationalPolicy(new LegacyOperationalPolicy());
- }).hasMessage("name is marked @NonNull but is null");
+ }).hasMessage(NAME_IS_NULL);
assertThatThrownBy(() -> {
- databaseProvider.deleteOperationalPolicy("policy_id", "55");
+ databaseProvider.deleteOperationalPolicy(POLICY_ID, "55");
}).hasMessage("no policy found for policy: policy_id:55");
assertThatThrownBy(() -> {
- databaseProvider.getGuardPolicy("policy_id", null);
+ databaseProvider.getGuardPolicy(POLICY_ID, null);
}).hasMessage("no policy found for policy: policy_id:null");
assertThatThrownBy(() -> {
- databaseProvider.getGuardPolicy("policy_id", "6");
+ databaseProvider.getGuardPolicy(POLICY_ID, "6");
}).hasMessage("no policy found for policy: policy_id:6");
assertThatThrownBy(() -> {
@@ -473,17 +480,17 @@ public class DatabasePolicyModelsProviderTest {
}).hasMessage("policy type for guard policy \"null\" unknown");
assertThatThrownBy(() -> {
- databaseProvider.deleteGuardPolicy("policy_id", "33");
+ databaseProvider.deleteGuardPolicy(POLICY_ID, "33");
}).hasMessage("no policy found for policy: policy_id:33");
- assertEquals(0, databaseProvider.getPdpGroups("name").size());
+ assertEquals(0, databaseProvider.getPdpGroups(NAME).size());
assertEquals(0, databaseProvider.getFilteredPdpGroups(PdpGroupFilter.builder().build()).size());
assertNotNull(databaseProvider.createPdpGroups(new ArrayList<>()));
assertNotNull(databaseProvider.updatePdpGroups(new ArrayList<>()));
PdpGroup pdpGroup = new PdpGroup();
- pdpGroup.setName("group");
+ pdpGroup.setName(GROUP);
pdpGroup.setVersion("1.2.3");
pdpGroup.setPdpGroupState(PdpState.ACTIVE);
pdpGroup.setPdpSubgroups(new ArrayList<>());
@@ -507,29 +514,29 @@ public class DatabasePolicyModelsProviderTest {
assertEquals(123, databaseProvider.createPdpGroups(groupList).get(0).getPdpSubgroups().get(0)
.getDesiredInstanceCount());
- assertEquals(1, databaseProvider.getPdpGroups("group").size());
+ assertEquals(1, databaseProvider.getPdpGroups(GROUP).size());
pdpSubGroup.setDesiredInstanceCount(234);
- databaseProvider.updatePdpSubGroup("group", pdpSubGroup);
- assertEquals(234,
- databaseProvider.getPdpGroups("group").get(0).getPdpSubgroups().get(0).getDesiredInstanceCount());
+ databaseProvider.updatePdpSubGroup(GROUP, pdpSubGroup);
+ assertEquals(234, databaseProvider.getPdpGroups(GROUP).get(0).getPdpSubgroups()
+ .get(0).getDesiredInstanceCount());
- assertEquals("Hello", databaseProvider.getPdpGroups("group").get(0).getPdpSubgroups().get(0)
- .getPdpInstances().get(0).getMessage());
+ assertEquals("Hello", databaseProvider.getPdpGroups(GROUP).get(0).getPdpSubgroups()
+ .get(0).getPdpInstances().get(0).getMessage());
pdp.setMessage("Howdy");
- databaseProvider.updatePdp("group", "type", pdp);
- assertEquals("Howdy", databaseProvider.getPdpGroups("group").get(0).getPdpSubgroups().get(0)
- .getPdpInstances().get(0).getMessage());
+ databaseProvider.updatePdp(GROUP, "type", pdp);
+ assertEquals("Howdy", databaseProvider.getPdpGroups(GROUP).get(0).getPdpSubgroups()
+ .get(0).getPdpInstances().get(0).getMessage());
assertThatThrownBy(() -> {
- databaseProvider.deletePdpGroup("name");
+ databaseProvider.deletePdpGroup(NAME);
}).hasMessage("delete of PDP group \"name:0.0.0\" failed, PDP group does not exist");
- assertEquals(pdpGroup.getName(), databaseProvider.deletePdpGroup("group").getName());
+ assertEquals(pdpGroup.getName(), databaseProvider.deletePdpGroup(GROUP).getName());
assertEquals(0, databaseProvider.getPdpStatistics(null).size());
- databaseProvider.updatePdpStatistics("group", "type", "type-0", new PdpStatistics());
+ databaseProvider.updatePdpStatistics(GROUP, "type", "type-0", new PdpStatistics());
} catch (Exception exc) {
LOGGER.warn("test should not throw an exception", exc);
fail("test should not throw an exception");
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 07f4ed72d..21d13fd83 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,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019 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.
@@ -20,6 +21,7 @@
package org.onap.policy.models.provider.impl;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
@@ -55,10 +57,14 @@ public class DummyBadProviderImpl implements PolicyModelsProvider {
}
@Override
- public void close() throws PfModelException {}
+ public void close() throws PfModelException {
+ // do nothing
+ }
@Override
- public void init() throws PfModelException {}
+ public void init() throws PfModelException {
+ // do nothing
+ }
@Override
public ToscaServiceTemplate getPolicyTypes(final String name, final String version) throws PfModelException {
@@ -152,22 +158,24 @@ public class DummyBadProviderImpl implements PolicyModelsProvider {
@Override
public List<PdpGroup> getPdpGroups(String name) throws PfModelException {
- return null;
+ return Collections.emptyList();
}
@Override
public List<PdpGroup> createPdpGroups(@NonNull List<PdpGroup> pdpGroups) throws PfModelException {
- return null;
+ return Collections.emptyList();
}
@Override
public List<PdpGroup> updatePdpGroups(@NonNull List<PdpGroup> pdpGroups) throws PfModelException {
- return null;
+ return Collections.emptyList();
}
@Override
public void updatePdp(@NonNull String pdpGroupName, @NonNull String pdpSubGroup, @NonNull Pdp pdp)
- throws PfModelException {}
+ throws PfModelException {
+ // do nothing
+ }
@Override
public PdpGroup deletePdpGroup(@NonNull String name) throws PfModelException {
@@ -176,7 +184,7 @@ public class DummyBadProviderImpl implements PolicyModelsProvider {
@Override
public List<ToscaPolicyType> getPolicyTypeList(String name, String version) throws PfModelException {
- return null;
+ return Collections.emptyList();
}
@Override
@@ -187,12 +195,12 @@ public class DummyBadProviderImpl implements PolicyModelsProvider {
@Override
public List<ToscaPolicyType> getFilteredPolicyTypeList(@NonNull ToscaPolicyTypeFilter filter)
throws PfModelException {
- return null;
+ return Collections.emptyList();
}
@Override
public List<ToscaPolicy> getPolicyList(String name, String version) throws PfModelException {
- return null;
+ return Collections.emptyList();
}
@Override
@@ -202,24 +210,28 @@ public class DummyBadProviderImpl implements PolicyModelsProvider {
@Override
public List<ToscaPolicy> getFilteredPolicyList(@NonNull ToscaPolicyFilter filter) throws PfModelException {
- return null;
+ return Collections.emptyList();
}
@Override
public List<PdpGroup> getFilteredPdpGroups(@NonNull PdpGroupFilter filter) throws PfModelException {
- return null;
+ return Collections.emptyList();
}
@Override
public void updatePdpSubGroup(@NonNull String pdpGroupName, @NonNull PdpSubGroup pdpSubGroup)
- throws PfModelException {}
+ throws PfModelException {
+ // do nothing
+ }
@Override
public List<PdpStatistics> getPdpStatistics(String name) throws PfModelException {
- return null;
+ return Collections.emptyList();
}
@Override
public void updatePdpStatistics(@NonNull String pdpGroupName, @NonNull String pdpType,
- @NonNull String pdpInstanceId, @NonNull PdpStatistics pdppStatistics) {}
+ @NonNull String pdpInstanceId, @NonNull PdpStatistics pdppStatistics) {
+ // do nothing
+ }
}
diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderTest.java
index 93cb89165..e05c1067e 100644
--- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderTest.java
+++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderTest.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019 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.
@@ -20,14 +21,13 @@
package org.onap.policy.models.provider.impl;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
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.util.ArrayList;
-
import org.junit.Test;
import org.onap.policy.models.pdp.concepts.Pdp;
import org.onap.policy.models.pdp.concepts.PdpGroupFilter;
@@ -49,6 +49,9 @@ import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
*/
public class DummyPolicyModelsProviderTest {
+ private static final String POLICY_ID = "policy_id";
+ private static final String VERSION = "version";
+
@Test
public void testProvider() throws Exception {
PolicyModelsProviderParameters parameters = new PolicyModelsProviderParameters();
@@ -56,16 +59,16 @@ public class DummyPolicyModelsProviderTest {
parameters.setDatabaseUrl("jdbc:dummy");
parameters.setPersistenceUnit("dummy");
- PolicyModelsProvider dummyProvider = new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters);
-
- dummyProvider.init();
+ try (PolicyModelsProvider dummyProvider =
+ new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters)) {
- ToscaServiceTemplate serviceTemplate = dummyProvider.getPolicies("onap.vcpe.tca", "1.0.0");
- assertNotNull(serviceTemplate);
- assertEquals("onap.policies.monitoring.cdap.tca.hi.lo.app",
- serviceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get("onap.vcpe.tca").getType());
+ dummyProvider.init();
- dummyProvider.close();
+ ToscaServiceTemplate serviceTemplate = dummyProvider.getPolicies("onap.vcpe.tca", "1.0.0");
+ assertNotNull(serviceTemplate);
+ assertEquals("onap.policies.monitoring.cdap.tca.hi.lo.app",
+ serviceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get("onap.vcpe.tca").getType());
+ }
}
@Test
@@ -75,75 +78,59 @@ public class DummyPolicyModelsProviderTest {
parameters.setDatabaseUrl("jdbc:dummy");
parameters.setPersistenceUnit("dummy");
- PolicyModelsProvider dummyProvider = new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters);
- dummyProvider.init();
-
- assertNotNull(dummyProvider.getPolicyTypes("name", "version"));
- assertNotNull(dummyProvider.getFilteredPolicyTypes(ToscaPolicyTypeFilter.builder().build()));
- assertNotNull(dummyProvider.getPolicyTypeList("name", "version"));
- assertNotNull(dummyProvider.getFilteredPolicyTypeList(ToscaPolicyTypeFilter.builder().build()));
- assertNotNull(dummyProvider.createPolicyTypes(new ToscaServiceTemplate()));
- assertNotNull(dummyProvider.updatePolicyTypes(new ToscaServiceTemplate()));
- assertNotNull(dummyProvider.deletePolicyType("name", "version"));
-
- assertNotNull(dummyProvider.getPolicies("name", "version"));
- assertNotNull(dummyProvider.getFilteredPolicies(ToscaPolicyFilter.builder().build()));
- assertNotNull(dummyProvider.getPolicyList("name", "version"));
- assertNotNull(dummyProvider.getFilteredPolicyList(ToscaPolicyFilter.builder().build()));
- assertNotNull(dummyProvider.createPolicies(new ToscaServiceTemplate()));
- assertNotNull(dummyProvider.updatePolicies(new ToscaServiceTemplate()));
- assertNotNull(dummyProvider.deletePolicy("name", "version"));
-
- assertNotNull(dummyProvider.getOperationalPolicy("policy_id", "1"));
- assertNotNull(dummyProvider.createOperationalPolicy(new LegacyOperationalPolicy()));
- assertNotNull(dummyProvider.updateOperationalPolicy(new LegacyOperationalPolicy()));
- assertNotNull(dummyProvider.deleteOperationalPolicy("policy_id", "1"));
-
- assertNotNull(dummyProvider.getGuardPolicy("policy_id", "1"));
- assertNotNull(dummyProvider.createGuardPolicy(new LegacyGuardPolicyInput()));
- assertNotNull(dummyProvider.updateGuardPolicy(new LegacyGuardPolicyInput()));
- assertNotNull(dummyProvider.deleteGuardPolicy("policy_id", "1"));
-
- assertTrue(dummyProvider.getPdpGroups("name").isEmpty());
- assertTrue(dummyProvider.getFilteredPdpGroups(PdpGroupFilter.builder().build()).isEmpty());
- assertTrue(dummyProvider.createPdpGroups(new ArrayList<>()).isEmpty());
- assertTrue(dummyProvider.updatePdpGroups(new ArrayList<>()).isEmpty());
- assertNull(dummyProvider.deletePdpGroup("name"));
-
- dummyProvider.updatePdpSubGroup("name", new PdpSubGroup());
- dummyProvider.updatePdp("name", "type", new Pdp());
- dummyProvider.updatePdpStatistics("name", "type", "type-0", new PdpStatistics());
- assertTrue(dummyProvider.getPdpStatistics("name").isEmpty());
-
- dummyProvider.close();
+ try (PolicyModelsProvider dummyProvider =
+ new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters)) {
+ dummyProvider.init();
+
+ assertNotNull(dummyProvider.getPolicyTypes("name", VERSION));
+ assertNotNull(dummyProvider.getFilteredPolicyTypes(ToscaPolicyTypeFilter.builder().build()));
+ assertNotNull(dummyProvider.getPolicyTypeList("name", VERSION));
+ assertNotNull(dummyProvider.getFilteredPolicyTypeList(ToscaPolicyTypeFilter.builder().build()));
+ assertNotNull(dummyProvider.createPolicyTypes(new ToscaServiceTemplate()));
+ assertNotNull(dummyProvider.updatePolicyTypes(new ToscaServiceTemplate()));
+ assertNotNull(dummyProvider.deletePolicyType("name", VERSION));
+
+ assertNotNull(dummyProvider.getPolicies("name", VERSION));
+ assertNotNull(dummyProvider.getFilteredPolicies(ToscaPolicyFilter.builder().build()));
+ assertNotNull(dummyProvider.getPolicyList("name", VERSION));
+ assertNotNull(dummyProvider.getFilteredPolicyList(ToscaPolicyFilter.builder().build()));
+ assertNotNull(dummyProvider.createPolicies(new ToscaServiceTemplate()));
+ assertNotNull(dummyProvider.updatePolicies(new ToscaServiceTemplate()));
+ assertNotNull(dummyProvider.deletePolicy("name", VERSION));
+
+ assertNotNull(dummyProvider.getOperationalPolicy(POLICY_ID, "1"));
+ assertNotNull(dummyProvider.createOperationalPolicy(new LegacyOperationalPolicy()));
+ assertNotNull(dummyProvider.updateOperationalPolicy(new LegacyOperationalPolicy()));
+ assertNotNull(dummyProvider.deleteOperationalPolicy(POLICY_ID, "1"));
+
+ assertNotNull(dummyProvider.getGuardPolicy(POLICY_ID, "1"));
+ assertNotNull(dummyProvider.createGuardPolicy(new LegacyGuardPolicyInput()));
+ assertNotNull(dummyProvider.updateGuardPolicy(new LegacyGuardPolicyInput()));
+ assertNotNull(dummyProvider.deleteGuardPolicy(POLICY_ID, "1"));
+
+ assertTrue(dummyProvider.getPdpGroups("name").isEmpty());
+ assertTrue(dummyProvider.getFilteredPdpGroups(PdpGroupFilter.builder().build()).isEmpty());
+ assertTrue(dummyProvider.createPdpGroups(new ArrayList<>()).isEmpty());
+ assertTrue(dummyProvider.updatePdpGroups(new ArrayList<>()).isEmpty());
+ assertNull(dummyProvider.deletePdpGroup("name"));
+
+ dummyProvider.updatePdpSubGroup("name", new PdpSubGroup());
+ dummyProvider.updatePdp("name", "type", new Pdp());
+ dummyProvider.updatePdpStatistics("name", "type", "type-0", new PdpStatistics());
+ assertTrue(dummyProvider.getPdpStatistics("name").isEmpty());
+ }
}
@Test
public void testDummyResponse() {
- DummyPolicyModelsProviderSubImpl resp = null;
-
- try {
- resp = new DummyPolicyModelsProviderSubImpl(new PolicyModelsProviderParameters());
- resp.getBadDummyResponse1();
- fail("test should throw an exception");
- } catch (Exception npe) {
- assertEquals("error serializing object", npe.getMessage());
- } finally {
- if (resp != null) {
- resp.close();
- }
+ try (DummyPolicyModelsProviderSubImpl resp =
+ new DummyPolicyModelsProviderSubImpl(new PolicyModelsProviderParameters())) {
+ assertThatThrownBy(resp::getBadDummyResponse1).hasMessage("error serializing object");
}
- try {
- resp = new DummyPolicyModelsProviderSubImpl(new PolicyModelsProviderParameters());
- resp.getBadDummyResponse2();
- fail("test should throw an exception");
- } catch (Exception npe) {
- assertEquals("error serializing object", npe.getMessage());
- } finally {
- if (resp != null) {
- resp.close();
- }
+ try (DummyPolicyModelsProviderSubImpl resp =
+ new DummyPolicyModelsProviderSubImpl(new PolicyModelsProviderParameters())) {
+ assertThatThrownBy(resp::getBadDummyResponse2).hasMessage("error serializing object");
}
}
}
diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyGuardPersistenceTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyGuardPersistenceTest.java
index fbbbaed9a..ef83ea669 100644
--- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyGuardPersistenceTest.java
+++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyGuardPersistenceTest.java
@@ -78,7 +78,7 @@ public class PolicyLegacyGuardPersistenceTest {
* @throws CoderException on JSON encoding and decoding errors
*/
@Before
- public void setupParameters() throws PfModelException, CoderException {
+ public void setupParameters() throws Exception {
// H2, use "org.mariadb.jdbc.Driver" and "jdbc:mariadb://localhost:3306/policy" for locally installed MariaDB
PolicyModelsProviderParameters parameters = new PolicyModelsProviderParameters();
diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyOperationalPersistenceTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyOperationalPersistenceTest.java
index 77a0cac9c..e6ecf5ade 100644
--- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyOperationalPersistenceTest.java
+++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyOperationalPersistenceTest.java
@@ -78,7 +78,7 @@ public class PolicyLegacyOperationalPersistenceTest {
* @throws CoderException on JSON encoding and decoding errors
*/
@Before
- public void setupParameters() throws PfModelException, CoderException {
+ public void setupParameters() throws Exception {
// H2, use "org.mariadb.jdbc.Driver" and "jdbc:mariadb://localhost:3306/policy" for locally installed MariaDB
PolicyModelsProviderParameters parameters = new PolicyModelsProviderParameters();
diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyPersistenceTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyPersistenceTest.java
index a08ad6669..1f577ae21 100644
--- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyPersistenceTest.java
+++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyPersistenceTest.java
@@ -86,7 +86,7 @@ public class PolicyPersistenceTest {
* @throws CoderException on JSON encoding and decoding errors
*/
@Before
- public void setupParameters() throws PfModelException, CoderException {
+ public void setupParameters() throws Exception {
// H2, use "org.mariadb.jdbc.Driver" and "jdbc:mariadb://localhost:3306/policy" for locally installed MariaDB
PolicyModelsProviderParameters parameters = new PolicyModelsProviderParameters();
diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyToscaPersistenceTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyToscaPersistenceTest.java
index 140194276..9012d84b1 100644
--- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyToscaPersistenceTest.java
+++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyToscaPersistenceTest.java
@@ -83,7 +83,7 @@ public class PolicyToscaPersistenceTest {
* @throws CoderException on JSON encoding and decoding errors
*/
@Before
- public void setupParameters() throws PfModelException, CoderException {
+ public void setupParameters() throws Exception {
PolicyModelsProviderParameters parameters = new PolicyModelsProviderParameters();
parameters.setDatabaseDriver("org.h2.Driver");
parameters.setDatabaseUrl("jdbc:h2:mem:testdb");