summaryrefslogtreecommitdiffstats
path: root/models-provider/src
diff options
context:
space:
mode:
authorPamela Dragosh <pdragosh@research.att.com>2020-03-05 07:55:57 -0500
committerPamela Dragosh <pdragosh@research.att.com>2020-03-06 08:37:31 -0500
commit172b8dcd3a772c03ec1d233cfd6602d901c61b99 (patch)
treeddc93d353d4a087f729517befd103f75e0cd5102 /models-provider/src
parent2358a161a4bbd0f0c97696b61fd725c33f7267e6 (diff)
TOSCA Compliant Guard Policies
Fixing the legacy guard policies and renaming them so we are able to differentiate them. Adding newer, cleaner TOSCA Guard Policies that match the operational guard policies. Removing legacy guard policies. Fixing JUnit so that they don't use indexes to test whether versions are changed correctly. Added back in new guard policies. Fixed the guard policy types to use camel case. Issue-ID: POLICY-2243 Change-Id: Ie611f26f73f41e64c0b467f524f470739158f437 Signed-off-by: Pamela Dragosh <pdragosh@research.att.com>
Diffstat (limited to 'models-provider/src')
-rw-r--r--models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProvider.java45
-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.java28
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java53
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyBadProviderImpl.java27
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderTest.java6
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyGuardPersistenceTest.java163
7 files changed, 0 insertions, 357 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 767a0fb6f..a8fc4ed73 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
@@ -22,7 +22,6 @@ package org.onap.policy.models.provider;
import java.util.Date;
import java.util.List;
-import java.util.Map;
import lombok.NonNull;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.pdp.concepts.Pdp;
@@ -35,8 +34,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.LegacyGuardPolicyInput;
-import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyOutput;
import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
/**
@@ -239,48 +236,6 @@ public interface PolicyModelsProvider extends AutoCloseable {
@NonNull final String policyVersion) throws PfModelException;
/**
- * Get legacy guard 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 Map<String, LegacyGuardPolicyOutput> getGuardPolicy(@NonNull final String policyId,
- final String policyVersion) throws PfModelException;
-
- /**
- * Create legacy guard policy.
- *
- * @param legacyGuardPolicy the definition of the policy to be created.
- * @return the created policy
- * @throws PfModelException on errors creating policies
- */
- public Map<String, LegacyGuardPolicyOutput> createGuardPolicy(
- @NonNull final LegacyGuardPolicyInput legacyGuardPolicy) throws PfModelException;
-
- /**
- * Update legacy guard policy.
- *
- * @param legacyGuardPolicy the definition of the policy to be updated
- * @return the updated policy
- * @throws PfModelException on errors updating policies
- */
- public Map<String, LegacyGuardPolicyOutput> updateGuardPolicy(
- @NonNull final LegacyGuardPolicyInput legacyGuardPolicy) throws PfModelException;
-
- /**
- * Delete legacy guard policy.
- *
- * @param policyId ID of the policy.
- * @param policyVersion version of the policy
- * @return the deleted policy
- * @throws PfModelException on errors deleting policies
- */
- public Map<String, LegacyGuardPolicyOutput> deleteGuardPolicy(@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 3cae650a3..195b88247 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
@@ -24,7 +24,6 @@ package org.onap.policy.models.provider.impl;
import java.util.Base64;
import java.util.Date;
import java.util.List;
-import java.util.Map;
import java.util.Properties;
import javax.ws.rs.core.Response;
@@ -55,8 +54,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.LegacyGuardPolicyInput;
-import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyOutput;
import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
import org.onap.policy.models.tosca.legacy.provider.LegacyProvider;
import org.slf4j.Logger;
@@ -280,38 +277,6 @@ public class DatabasePolicyModelsProviderImpl implements PolicyModelsProvider {
}
@Override
- public Map<String, LegacyGuardPolicyOutput> getGuardPolicy(@NonNull final String policyId,
- final String policyVersion) throws PfModelException {
- assertInitialized();
- return new LegacyProvider().getGuardPolicy(pfDao, policyId, policyVersion);
- }
-
- @Override
- public Map<String, LegacyGuardPolicyOutput>
- createGuardPolicy(@NonNull final LegacyGuardPolicyInput legacyGuardPolicy) throws PfModelException {
- assertInitialized();
- return new LegacyProvider().createGuardPolicy(pfDao, legacyGuardPolicy);
- }
-
- @Override
- public Map<String, LegacyGuardPolicyOutput>
- updateGuardPolicy(@NonNull final LegacyGuardPolicyInput legacyGuardPolicy) throws PfModelException {
- assertInitialized();
- return new LegacyProvider().updateGuardPolicy(pfDao, legacyGuardPolicy);
- }
-
- @Override
- public Map<String, LegacyGuardPolicyOutput> deleteGuardPolicy(@NonNull final String policyId,
- @NonNull final String policyVersion) throws PfModelException {
- assertInitialized();
-
- assertPolicyNotDeployedInPdpGroup(
- new ToscaPolicyIdentifier(policyId, policyVersion + LegacyProvider.LEGACY_MINOR_PATCH_SUFFIX));
-
- return new LegacyProvider().deleteGuardPolicy(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 c09c6c233..aece188f9 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
@@ -23,9 +23,7 @@ package org.onap.policy.models.provider.impl;
import java.util.ArrayList;
import java.util.Date;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
import javax.ws.rs.core.Response;
@@ -45,8 +43,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.LegacyGuardPolicyInput;
-import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyOutput;
import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
/**
@@ -171,30 +167,6 @@ public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider {
}
@Override
- public Map<String, LegacyGuardPolicyOutput> getGuardPolicy(final String policyId, final String policyVersion)
- throws PfModelException {
- return new HashMap<>();
- }
-
- @Override
- public Map<String, LegacyGuardPolicyOutput> createGuardPolicy(final LegacyGuardPolicyInput legacyGuardPolicy)
- throws PfModelException {
- return new HashMap<>();
- }
-
- @Override
- public Map<String, LegacyGuardPolicyOutput> updateGuardPolicy(final LegacyGuardPolicyInput legacyGuardPolicy)
- throws PfModelException {
- return new HashMap<>();
- }
-
- @Override
- public Map<String, LegacyGuardPolicyOutput> deleteGuardPolicy(final String policyId, final String policyVersion)
- throws PfModelException {
- return new HashMap<>();
- }
-
- @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 f085605f8..388b6ad98 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
@@ -49,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.LegacyGuardPolicyInput;
import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
/**
@@ -229,38 +228,6 @@ public class DatabasePolicyModelsProviderTest {
}).hasMessageMatching("^policyVersion is marked .*on.*ull but is null$");
assertThatThrownBy(() -> {
- databaseProvider.getGuardPolicy(null, null);
- }).hasMessageMatching(POLICY_ID_IS_NULL);
-
- assertThatThrownBy(() -> {
- databaseProvider.getGuardPolicy(null, "");
- }).hasMessageMatching(POLICY_ID_IS_NULL);
-
- assertThatThrownBy(() -> {
- databaseProvider.getGuardPolicy("", null);
- }).hasMessage("no policy found for policy: :null");
-
- assertThatThrownBy(() -> {
- databaseProvider.createGuardPolicy(null);
- }).hasMessageMatching("^legacyGuardPolicy is marked .*on.*ull but is null$");
-
- assertThatThrownBy(() -> {
- databaseProvider.updateGuardPolicy(null);
- }).hasMessageMatching("^legacyGuardPolicy is marked .*on.*ull but is null$");
-
- assertThatThrownBy(() -> {
- databaseProvider.deleteGuardPolicy(null, null);
- }).hasMessageMatching(POLICY_ID_IS_NULL);
-
- assertThatThrownBy(() -> {
- databaseProvider.deleteGuardPolicy(null, "");
- }).hasMessageMatching(POLICY_ID_IS_NULL);
-
- assertThatThrownBy(() -> {
- databaseProvider.deleteGuardPolicy("", null);
- }).hasMessageMatching("^policyVersion is marked .*on.*ull but is null$");
-
- assertThatThrownBy(() -> {
databaseProvider.getFilteredPdpGroups(null);
}).hasMessageMatching(FILTER_IS_NULL);
@@ -422,26 +389,6 @@ public class DatabasePolicyModelsProviderTest {
databaseProvider.deleteOperationalPolicy(POLICY_ID, "55");
}).hasMessage("no policy found for policy: policy_id:55");
- assertThatThrownBy(() -> {
- databaseProvider.getGuardPolicy(POLICY_ID, null);
- }).hasMessage("no policy found for policy: policy_id:null");
-
- assertThatThrownBy(() -> {
- databaseProvider.getGuardPolicy(POLICY_ID, "6");
- }).hasMessage("no policy found for policy: policy_id:6");
-
- assertThatThrownBy(() -> {
- databaseProvider.createGuardPolicy(new LegacyGuardPolicyInput());
- }).hasMessage("policy type for guard policy \"null\" unknown");
-
- assertThatThrownBy(() -> {
- databaseProvider.updateGuardPolicy(new LegacyGuardPolicyInput());
- }).hasMessage("policy type for guard policy \"null\" unknown");
-
- assertThatThrownBy(() -> {
- databaseProvider.deleteGuardPolicy(POLICY_ID, "33");
- }).hasMessage("no policy found for policy: policy_id:33");
-
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 73940a6b3..80680c1fd 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
@@ -25,7 +25,6 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
-import java.util.Map;
import javax.ws.rs.core.Response;
import lombok.NonNull;
import org.onap.policy.models.base.PfModelException;
@@ -41,8 +40,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.LegacyGuardPolicyInput;
-import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyOutput;
import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
/**
@@ -132,30 +129,6 @@ public class DummyBadProviderImpl implements PolicyModelsProvider {
}
@Override
- public Map<String, LegacyGuardPolicyOutput> getGuardPolicy(@NonNull String policyId, final String policyVersion)
- throws PfModelException {
- return null;
- }
-
- @Override
- public Map<String, LegacyGuardPolicyOutput> createGuardPolicy(@NonNull LegacyGuardPolicyInput legacyGuardPolicy)
- throws PfModelException {
- return null;
- }
-
- @Override
- public Map<String, LegacyGuardPolicyOutput> updateGuardPolicy(@NonNull LegacyGuardPolicyInput legacyGuardPolicy)
- throws PfModelException {
- return null;
- }
-
- @Override
- public Map<String, LegacyGuardPolicyOutput> deleteGuardPolicy(@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 3212428ae..2e2e3daa6 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
@@ -40,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.LegacyGuardPolicyInput;
import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
/**
@@ -103,11 +102,6 @@ public class DummyPolicyModelsProviderTest {
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());
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
deleted file mode 100644
index ecb50cdc3..000000000
--- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyGuardPersistenceTest.java
+++ /dev/null
@@ -1,163 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2019-2020 Nordix Foundation.
- * ================================================================================
- * 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.Map;
-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.LegacyGuardPolicyInput;
-import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyOutput;
-import org.yaml.snakeyaml.Yaml;
-
-/**
- * Test persistence of monitoring policies to and from the database.
- *
- * @author Liam Fallon (liam.fallon@est.tech)
- */
-public class PolicyLegacyGuardPersistenceTest {
- private StandardCoder standardCoder;
-
- private PolicyModelsProvider databaseProvider;
-
- // @formatter:off
- private String[] policyInputResourceNames = {
- "policies/vDNS.policy.guard.frequency.input.json",
- "policies/vDNS.policy.guard.minmax.input.json"
- };
-
- private String[] policyOutputResourceNames = {
- "policies/vDNS.policy.guard.frequency.output.json",
- "policies/vDNS.policy.guard.minmax.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 testLegacyGuardPolicyPersistence() 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 {
- LegacyGuardPolicyInput gip = standardCoder.decode(policyInputString, LegacyGuardPolicyInput.class);
-
- assertNotNull(gip);
-
- Map<String, LegacyGuardPolicyOutput> createdGopm = databaseProvider.createGuardPolicy(gip);
- assertEquals(gip.getPolicyId(), createdGopm.keySet().iterator().next());
- assertEquals(gip.getContent(), createdGopm.get(gip.getPolicyId()).getProperties().values().iterator().next());
-
- Map<String, LegacyGuardPolicyOutput> gotGopm = databaseProvider.getGuardPolicy(gip.getPolicyId(), null);
- assertEquals(gip.getPolicyId(), gotGopm.keySet().iterator().next());
- assertEquals(gip.getContent(), gotGopm.get(gip.getPolicyId()).getProperties().values().iterator().next());
-
- Map<String, LegacyGuardPolicyOutput> updatedGopm = databaseProvider.updateGuardPolicy(gip);
- assertEquals(gip.getPolicyId(), updatedGopm.keySet().iterator().next());
- assertEquals(gip.getContent(), updatedGopm.get(gip.getPolicyId()).getProperties().values().iterator().next());
-
- Map<String, LegacyGuardPolicyOutput> deletedGopm = databaseProvider.deleteGuardPolicy(gip.getPolicyId(), "1");
- assertEquals(gip.getPolicyId(), deletedGopm.keySet().iterator().next());
- assertEquals(gip.getContent(), deletedGopm.get(gip.getPolicyId()).getProperties().values().iterator().next());
-
- String actualRetrievedJson = standardCoder.encode(gotGopm);
-
- // All of this dash/underscore stuff is to avoid a checkstyle error around escaping unicode characters
- assertEquals(policyOutputString.replaceAll("\\s+", ""), actualRetrievedJson.replaceAll("\\s+", ""));
- }
-
- private void createPolicyTypes() throws CoderException, PfModelException, URISyntaxException {
- Set<String> policyTypeResources = ResourceUtils.getDirectoryContents("policytypes");
-
- for (String policyTyoeResource : policyTypeResources) {
- Object yamlObject = new Yaml().load(ResourceUtils.getResourceAsString(policyTyoeResource));
- String yamlAsJsonString = new StandardCoder().encode(yamlObject);
-
- ToscaServiceTemplate toscaServiceTemplatePolicyType =
- standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class);
-
- assertNotNull(toscaServiceTemplatePolicyType);
- databaseProvider.createPolicyTypes(toscaServiceTemplatePolicyType);
- }
- }
-}