summaryrefslogtreecommitdiffstats
path: root/models-provider
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2020-08-24 15:05:04 +0000
committerGerrit Code Review <gerrit@onap.org>2020-08-24 15:05:04 +0000
commit43aaa62cdf9a7dadfb6d688f1fe83c5bd355a86d (patch)
tree4958fd36b50129329aba24327c2af875b65050ff /models-provider
parent09c388b5c9781383a0577bf8c2f574f806abe85c (diff)
parent001fe2af138c08755f68025eeffd8c7a25cc8e5c (diff)
Merge "Remove legacy operational policy from models"
Diffstat (limited to 'models-provider')
-rw-r--r--models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProvider.java44
-rw-r--r--models-provider/src/main/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderImpl.java35
-rw-r--r--models-provider/src/main/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderImpl.java27
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java58
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyBadProviderImpl.java26
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderTest.java8
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyOperationalPersistenceTest.java161
7 files changed, 6 insertions, 353 deletions
diff --git a/models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProvider.java b/models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProvider.java
index a8fc4ed73..f2f7318e8 100644
--- a/models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProvider.java
+++ b/models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProvider.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019-2020 Nordix Foundation.
+ * 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.
@@ -34,7 +35,6 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyFilter;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeFilter;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
-import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
/**
* This interface describes the operations that are provided to users and components for reading objects from and
@@ -194,48 +194,6 @@ public interface PolicyModelsProvider extends AutoCloseable {
throws PfModelException;
/**
- * Get legacy operational policy.
- *
- * @param policyId ID of the policy
- * @param policyVersion version of the policy, set to null to get the latest policy
- * @return the policies found
- * @throws PfModelException on errors getting policies
- */
- public LegacyOperationalPolicy getOperationalPolicy(@NonNull final String policyId, final String policyVersion)
- throws PfModelException;
-
- /**
- * Create legacy operational policy.
- *
- * @param legacyOperationalPolicy the definition of the policy to be created.
- * @return the created policy
- * @throws PfModelException on errors creating policies
- */
- public LegacyOperationalPolicy createOperationalPolicy(
- @NonNull final LegacyOperationalPolicy legacyOperationalPolicy) throws PfModelException;
-
- /**
- * Update legacy operational policy.
- *
- * @param legacyOperationalPolicy the definition of the policy to be updated
- * @return the updated policy
- * @throws PfModelException on errors updating policies
- */
- public LegacyOperationalPolicy updateOperationalPolicy(
- @NonNull final LegacyOperationalPolicy legacyOperationalPolicy) throws PfModelException;
-
- /**
- * Delete legacy operational policy.
- *
- * @param policyId ID of the policy.
- * @param policyVersion version of the policy
- * @return the deleted policy
- * @throws PfModelException on errors deleting policies
- */
- public LegacyOperationalPolicy deleteOperationalPolicy(@NonNull final String policyId,
- @NonNull final String policyVersion) throws PfModelException;
-
- /**
* Get PDP groups.
*
* @param name the name of the policy to get, null to get all PDP groups
diff --git a/models-provider/src/main/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderImpl.java b/models-provider/src/main/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderImpl.java
index 7d28b61c3..77a72adb0 100644
--- a/models-provider/src/main/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderImpl.java
+++ b/models-provider/src/main/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderImpl.java
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2019-2020 Nordix Foundation.
* Modifications Copyright (C) 2019-2020 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.
@@ -51,8 +52,6 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeFilter;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.onap.policy.models.tosca.authorative.provider.AuthorativeToscaProvider;
-import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
-import org.onap.policy.models.tosca.legacy.provider.LegacyProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -242,38 +241,6 @@ public class DatabasePolicyModelsProviderImpl implements PolicyModelsProvider {
}
@Override
- public LegacyOperationalPolicy getOperationalPolicy(@NonNull final String policyId, final String policyVersion)
- throws PfModelException {
- assertInitialized();
- return new LegacyProvider().getOperationalPolicy(pfDao, policyId, policyVersion);
- }
-
- @Override
- public LegacyOperationalPolicy createOperationalPolicy(
- @NonNull final LegacyOperationalPolicy legacyOperationalPolicy) throws PfModelException {
- assertInitialized();
- return new LegacyProvider().createOperationalPolicy(pfDao, legacyOperationalPolicy);
- }
-
- @Override
- public LegacyOperationalPolicy updateOperationalPolicy(
- @NonNull final LegacyOperationalPolicy legacyOperationalPolicy) throws PfModelException {
- assertInitialized();
- return new LegacyProvider().updateOperationalPolicy(pfDao, legacyOperationalPolicy);
- }
-
- @Override
- public LegacyOperationalPolicy deleteOperationalPolicy(@NonNull final String policyId,
- @NonNull final String policyVersion) throws PfModelException {
- assertInitialized();
-
- assertPolicyNotDeployedInPdpGroup(
- new ToscaPolicyIdentifier(policyId, policyVersion + LegacyProvider.LEGACY_MINOR_PATCH_SUFFIX));
-
- return new LegacyProvider().deleteOperationalPolicy(pfDao, policyId, policyVersion);
- }
-
- @Override
public List<PdpGroup> getPdpGroups(final String name) throws PfModelException {
assertInitialized();
return new PdpProvider().getPdpGroups(pfDao, name);
diff --git a/models-provider/src/main/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderImpl.java b/models-provider/src/main/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderImpl.java
index 465685c3e..16f5a2b74 100644
--- a/models-provider/src/main/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderImpl.java
+++ b/models-provider/src/main/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderImpl.java
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2019-2020 Nordix Foundation.
* Copyright (C) 2019 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.
@@ -41,7 +42,6 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyFilter;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeFilter;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
-import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
/**
* This class provides a dummy implementation of the Policy Models Provider for the ONAP Policy Framework.
@@ -140,31 +140,6 @@ public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider {
}
@Override
-
- public LegacyOperationalPolicy getOperationalPolicy(final String policyId, final String policyVersion)
- throws PfModelException {
- return new LegacyOperationalPolicy();
- }
-
- @Override
- public LegacyOperationalPolicy createOperationalPolicy(final LegacyOperationalPolicy legacyOperationalPolicy)
- throws PfModelException {
- return legacyOperationalPolicy;
- }
-
- @Override
- public LegacyOperationalPolicy updateOperationalPolicy(final LegacyOperationalPolicy legacyOperationalPolicy)
- throws PfModelException {
- return legacyOperationalPolicy;
- }
-
- @Override
- public LegacyOperationalPolicy deleteOperationalPolicy(final String policyId, final String policyVersion)
- throws PfModelException {
- return new LegacyOperationalPolicy();
- }
-
- @Override
public List<PdpGroup> getPdpGroups(final String name) throws PfModelException {
return new ArrayList<>();
}
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 2a52c87ea..ac42304fd 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
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2019-2020 Nordix Foundation.
* Modifications Copyright (C) 2019 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.
@@ -48,7 +49,6 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeFilter;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
-import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
/**
* Test the database models provider implementation.
@@ -60,8 +60,6 @@ public class DatabasePolicyModelsProviderTest {
private static final String TEMPLATE_IS_NULL = "^serviceTemplate is marked .*on.*ull but is null$";
- private static final String POLICY_ID_IS_NULL = "^policyId is marked .*on.*ull but is null$";
-
private static final String SUBGROUP_IS_NULL = "^pdpSubGroup is marked .*on.*ull but is null$";
private static final String GROUP_IS_NULL = "^pdpGroupName is marked .*on.*ull but is null$";
@@ -70,8 +68,6 @@ public class DatabasePolicyModelsProviderTest {
private static final String FILTER_IS_NULL = "^filter is marked .*on.*ull but is null$";
- private static final String POLICY_ID = "policy_id";
-
private static final String GROUP = "group";
private static final String VERSION_100 = "1.0.0";
@@ -195,38 +191,6 @@ public class DatabasePolicyModelsProviderTest {
}).hasMessageMatching("^version is marked .*on.*ull but is null$");
assertThatThrownBy(() -> {
- databaseProvider.getOperationalPolicy(null, null);
- }).hasMessageMatching(POLICY_ID_IS_NULL);
-
- assertThatThrownBy(() -> {
- databaseProvider.getOperationalPolicy(null, "");
- }).hasMessageMatching(POLICY_ID_IS_NULL);
-
- assertThatThrownBy(() -> {
- databaseProvider.getOperationalPolicy("", null);
- }).hasMessage("service template not found in database");
-
- assertThatThrownBy(() -> {
- databaseProvider.createOperationalPolicy(null);
- }).hasMessageMatching("^legacyOperationalPolicy is marked .*on.*ull but is null$");
-
- assertThatThrownBy(() -> {
- databaseProvider.updateOperationalPolicy(null);
- }).hasMessageMatching("^legacyOperationalPolicy is marked .*on.*ull but is null$");
-
- assertThatThrownBy(() -> {
- databaseProvider.deleteOperationalPolicy(null, null);
- }).hasMessageMatching(POLICY_ID_IS_NULL);
-
- assertThatThrownBy(() -> {
- databaseProvider.deleteOperationalPolicy(null, "");
- }).hasMessageMatching(POLICY_ID_IS_NULL);
-
- assertThatThrownBy(() -> {
- databaseProvider.deleteOperationalPolicy("", null);
- }).hasMessageMatching("^policyVersion is marked .*on.*ull but is null$");
-
- assertThatThrownBy(() -> {
databaseProvider.getFilteredPdpGroups(null);
}).hasMessageMatching(FILTER_IS_NULL);
@@ -368,26 +332,6 @@ public class DatabasePolicyModelsProviderTest {
assertThatThrownBy(() -> databaseProvider.deletePolicy("Policy", "0.0.0").getToscaTopologyTemplate())
.hasMessage("service template not found in database");
- assertThatThrownBy(() -> {
- databaseProvider.getOperationalPolicy(POLICY_ID, null);
- }).hasMessage("service template not found in database");
-
- assertThatThrownBy(() -> {
- databaseProvider.getOperationalPolicy(POLICY_ID, "10");
- }).hasMessage("service template not found in database");
-
- assertThatThrownBy(() -> {
- databaseProvider.createOperationalPolicy(new LegacyOperationalPolicy());
- }).hasMessageMatching(NAME_IS_NULL);
-
- assertThatThrownBy(() -> {
- databaseProvider.updateOperationalPolicy(new LegacyOperationalPolicy());
- }).hasMessageMatching(NAME_IS_NULL);
-
- assertThatThrownBy(() -> {
- databaseProvider.deleteOperationalPolicy(POLICY_ID, "55");
- }).hasMessage("service template not found in database");
-
assertEquals(0, databaseProvider.getPdpGroups(NAME).size());
assertEquals(0, databaseProvider.getFilteredPdpGroups(PdpGroupFilter.builder().build()).size());
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 80680c1fd..453f86633 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
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2019-2020 Nordix Foundation.
* Modifications Copyright (C) 2019 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.
@@ -40,7 +41,6 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyFilter;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeFilter;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
-import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
/**
* Dummy implementation of {@link PolicyModelsProvider} with bad constructor.
@@ -105,30 +105,6 @@ public class DummyBadProviderImpl implements PolicyModelsProvider {
}
@Override
- public LegacyOperationalPolicy getOperationalPolicy(@NonNull final String policyId, final String policyVersion)
- throws PfModelException {
- return null;
- }
-
- @Override
- public LegacyOperationalPolicy createOperationalPolicy(@NonNull LegacyOperationalPolicy legacyOperationalPolicy)
- throws PfModelException {
- return null;
- }
-
- @Override
- public LegacyOperationalPolicy updateOperationalPolicy(@NonNull LegacyOperationalPolicy legacyOperationalPolicy)
- throws PfModelException {
- return null;
- }
-
- @Override
- public LegacyOperationalPolicy deleteOperationalPolicy(@NonNull String policyId,
- @NonNull final String policyVersion) 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/DummyPolicyModelsProviderTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderTest.java
index 484922e20..7fc37afe9 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
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2019-2020 Nordix Foundation.
* Modifications Copyright (C) 2019 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.
@@ -39,7 +40,6 @@ import org.onap.policy.models.provider.PolicyModelsProviderParameters;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyFilter;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeFilter;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
-import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
/**
* Test the dummy models provider implementation.
@@ -48,7 +48,6 @@ 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
@@ -96,11 +95,6 @@ public class DummyPolicyModelsProviderTest {
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"));
-
assertTrue(dummyProvider.getPdpGroups("name").isEmpty());
assertTrue(dummyProvider.getFilteredPdpGroups(PdpGroupFilter.builder().build()).isEmpty());
assertTrue(dummyProvider.createPdpGroups(new ArrayList<>()).isEmpty());
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
deleted file mode 100644
index e0250dc3a..000000000
--- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyOperationalPersistenceTest.java
+++ /dev/null
@@ -1,161 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2019-2020 Nordix Foundation.
- * Modifications Copyright (C) 2020 AT&T.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT 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 static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import java.net.URISyntaxException;
-import java.util.Base64;
-import java.util.Set;
-import lombok.NonNull;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.onap.policy.common.utils.coder.CoderException;
-import org.onap.policy.common.utils.coder.StandardCoder;
-import org.onap.policy.common.utils.resources.ResourceUtils;
-import org.onap.policy.models.base.PfModelException;
-import org.onap.policy.models.provider.PolicyModelsProvider;
-import org.onap.policy.models.provider.PolicyModelsProviderFactory;
-import org.onap.policy.models.provider.PolicyModelsProviderParameters;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
-import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
-import org.yaml.snakeyaml.Yaml;
-
-/**
- * Test persistence of monitoring policies to and from the database.
- *
- * @author Liam Fallon (liam.fallon@est.tech)
- */
-public class PolicyLegacyOperationalPersistenceTest {
- private StandardCoder standardCoder;
-
- private PolicyModelsProvider databaseProvider;
-
- // @formatter:off
- private String[] policyInputResourceNames = {
- "policies/vCPE.policy.operational.legacy.input.json",
- "policies/vDNS.policy.operational.legacy.input.json",
- "policies/vFirewall.policy.operational.legacy.input.json"
- };
-
- private String[] policyOutputResourceNames = {
- "policies/vCPE.policy.operational.legacy.output.json",
- "policies/vDNS.policy.operational.legacy.output.json",
- "policies/vFirewall.policy.operational.legacy.output.json"
- };
- // @formatter:on
-
- /**
- * Initialize provider.
- *
- * @throws PfModelException on exceptions in the tests
- * @throws CoderException on JSON encoding and decoding errors
- */
- @Before
- 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();
- parameters.setDatabaseDriver("org.h2.Driver");
- parameters.setDatabaseUrl("jdbc:h2:mem:testdb");
- parameters.setDatabaseUser("policy");
- parameters.setDatabasePassword(Base64.getEncoder().encodeToString("P01icY".getBytes()));
- parameters.setPersistenceUnit("ToscaConceptTest");
-
- databaseProvider = new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters);
-
- createPolicyTypes();
- }
-
- /**
- * Set up standard coder.
- */
- @Before
- public void setupStandardCoder() {
- standardCoder = new StandardCoder();
- }
-
- @After
- public void teardown() throws Exception {
- databaseProvider.close();
- }
-
- @Test
- public void testLegacyOperationalPolicyPersistence() throws Exception {
- for (int i = 0; i < policyInputResourceNames.length; i++) {
- String policyInputString = ResourceUtils.getResourceAsString(policyInputResourceNames[i]);
- String policyOutputString = ResourceUtils.getResourceAsString(policyOutputResourceNames[i]);
- testJsonStringPolicyPersistence(policyInputString, policyOutputString);
- }
- }
-
- /**
- * Check persistence of a policy.
- *
- * @param policyInputString the policy as a string
- * @param policyOutputString the expected output string
- * @throws Exception any exception thrown
- */
- public void testJsonStringPolicyPersistence(@NonNull final String policyInputString,
- final String policyOutputString) throws Exception {
- LegacyOperationalPolicy lop = standardCoder.decode(policyInputString, LegacyOperationalPolicy.class);
-
- assertNotNull(lop);
-
- LegacyOperationalPolicy createdLop = databaseProvider.createOperationalPolicy(lop);
- assertEquals(createdLop, lop);
-
- LegacyOperationalPolicy gotLop = databaseProvider.getOperationalPolicy(lop.getPolicyId(), null);
- assertEquals(gotLop, lop);
-
- LegacyOperationalPolicy updatedLop = databaseProvider.updateOperationalPolicy(lop);
- assertEquals(gotLop, updatedLop);
-
- LegacyOperationalPolicy deletedLop = databaseProvider.deleteOperationalPolicy(lop.getPolicyId(), "1");
- assertEquals(gotLop, deletedLop);
-
- String actualRetrievedJson = standardCoder.encode(gotLop);
-
- // All of this dash/underscore stuff is to avoid a checkstyle error around escaping unicode characters
- assertEquals(
- policyOutputString.replaceAll("\\s+", "").replaceAll("u0027", "_-_-_-_").replaceAll("\\\\_-_-_-_", "'"),
- actualRetrievedJson.replaceAll("\\s+", "").replaceAll("u0027", "_-_-_-_").replaceAll("\\\\_-_-_-_",
- "'"));
- }
-
- private void createPolicyTypes() throws CoderException, PfModelException, URISyntaxException {
- Set<String> policyTypeResources = ResourceUtils.getDirectoryContents("policytypes");
-
- for (String policyTypeResource : policyTypeResources) {
- Object yamlObject = new Yaml().load(ResourceUtils.getResourceAsString(policyTypeResource));
- String yamlAsJsonString = new StandardCoder().encode(yamlObject);
-
- ToscaServiceTemplate toscaServiceTemplatePolicyType =
- standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class);
-
- assertNotNull(toscaServiceTemplatePolicyType);
- databaseProvider.createPolicyTypes(toscaServiceTemplatePolicyType);
- }
- }
-}