diff options
author | Jim Hahn <jrh3@att.com> | 2021-02-08 18:31:06 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2021-02-08 18:31:06 +0000 |
commit | 5f0183ff4608e1c87436967dbc8760fe9a1febaf (patch) | |
tree | 2ebe1db7f44331709030561a617206291093aaca | |
parent | 296a26edcc3102602b494d1be9c23e0265b09f66 (diff) | |
parent | ed54f1f94a43e9fc5e353eb2c7111dcc552be18e (diff) |
Merge "Make filters on TOSCA entities generic"
24 files changed, 287 insertions, 493 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 e0cb44cb6..3bf81adf7 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,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019-2020 Nordix Foundation. + * Copyright (C) 2019-2021 Nordix Foundation. * Modifications Copyright (C) 2020 Bell Canada. All rights reserved. * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ @@ -34,12 +34,11 @@ import org.onap.policy.models.pdp.concepts.PdpPolicyStatus; import org.onap.policy.models.pdp.concepts.PdpStatistics; import org.onap.policy.models.pdp.concepts.PdpSubGroup; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifierOptVersion; +import org.onap.policy.models.tosca.authorative.concepts.ToscaEntityFilter; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; -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.authorative.concepts.ToscaServiceTemplateFilter; +import org.onap.policy.models.tosca.authorative.concepts.ToscaTypedEntityFilter; /** * This interface describes the operations that are provided to users and components for reading objects from and @@ -76,8 +75,8 @@ public interface PolicyModelsProvider extends AutoCloseable { * @return the service templates found * @throws PfModelException on errors getting service templates */ - public List<ToscaServiceTemplate> getFilteredServiceTemplateList(@NonNull final ToscaServiceTemplateFilter filter) - throws PfModelException; + public List<ToscaServiceTemplate> getFilteredServiceTemplateList( + @NonNull final ToscaEntityFilter<ToscaServiceTemplate> filter) throws PfModelException; /** * Create service template. @@ -137,7 +136,7 @@ public interface PolicyModelsProvider extends AutoCloseable { * @return the policy types found * @throws PfModelException on errors getting policy types */ - public ToscaServiceTemplate getFilteredPolicyTypes(@NonNull final ToscaPolicyTypeFilter filter) + public ToscaServiceTemplate getFilteredPolicyTypes(@NonNull final ToscaEntityFilter<ToscaPolicyType> filter) throws PfModelException; /** @@ -147,7 +146,7 @@ public interface PolicyModelsProvider extends AutoCloseable { * @return the policy types found * @throws PfModelException on errors getting policy types */ - public List<ToscaPolicyType> getFilteredPolicyTypeList(@NonNull final ToscaPolicyTypeFilter filter) + public List<ToscaPolicyType> getFilteredPolicyTypeList(@NonNull final ToscaEntityFilter<ToscaPolicyType> filter) throws PfModelException; /** @@ -208,7 +207,8 @@ public interface PolicyModelsProvider extends AutoCloseable { * @return the policies found * @throws PfModelException on errors getting policies */ - public ToscaServiceTemplate getFilteredPolicies(@NonNull final ToscaPolicyFilter filter) throws PfModelException; + public ToscaServiceTemplate getFilteredPolicies(@NonNull final ToscaTypedEntityFilter<ToscaPolicy> filter) + throws PfModelException; /** * Get filtered policies. @@ -217,7 +217,8 @@ public interface PolicyModelsProvider extends AutoCloseable { * @return the policies found * @throws PfModelException on errors getting policies */ - public List<ToscaPolicy> getFilteredPolicyList(@NonNull final ToscaPolicyFilter filter) throws PfModelException; + public List<ToscaPolicy> getFilteredPolicyList(@NonNull final ToscaTypedEntityFilter<ToscaPolicy> filter) + throws PfModelException; /** * Create policies. @@ -378,8 +379,7 @@ public interface PolicyModelsProvider extends AutoCloseable { * @return the deployments found * @throws PfModelException on errors getting PDP groups */ - public List<PdpPolicyStatus> getAllPolicyStatus() - throws PfModelException; + public List<PdpPolicyStatus> getAllPolicyStatus() throws PfModelException; /** * Gets all deployments for a policy. @@ -388,18 +388,16 @@ public interface PolicyModelsProvider extends AutoCloseable { * @throws PfModelException on errors getting PDP groups */ public List<PdpPolicyStatus> getAllPolicyStatus(@NonNull ToscaConceptIdentifierOptVersion policy) - throws PfModelException; + throws PfModelException; /** * Gets the policy deployments for a PDP group. * - * @param groupName the name of the PDP group of interest, null to get results for all - * PDP groups + * @param groupName the name of the PDP group of interest, null to get results for all PDP groups * @return the deployments found * @throws PfModelException on errors getting PDP groups */ - public List<PdpPolicyStatus> getGroupPolicyStatus(@NonNull final String groupName) - throws PfModelException; + public List<PdpPolicyStatus> getGroupPolicyStatus(@NonNull final String groupName) throws PfModelException; /** * Creates, updates, and deletes collections of policy status. @@ -408,6 +406,6 @@ public interface PolicyModelsProvider extends AutoCloseable { * @param updateObjs the objects to update * @param deleteObjs the objects to delete */ - public void cudPolicyStatus(Collection<PdpPolicyStatus> createObjs, - Collection<PdpPolicyStatus> updateObjs, Collection<PdpPolicyStatus> deleteObjs); + public void cudPolicyStatus(Collection<PdpPolicyStatus> createObjs, Collection<PdpPolicyStatus> updateObjs, + Collection<PdpPolicyStatus> deleteObjs); } 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 3094efc27..8c7c5122b 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 @@ -41,12 +41,11 @@ import org.onap.policy.models.provider.PolicyModelsProvider; import org.onap.policy.models.provider.PolicyModelsProviderParameters; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifierOptVersion; +import org.onap.policy.models.tosca.authorative.concepts.ToscaEntityFilter; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; -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.authorative.concepts.ToscaServiceTemplateFilter; +import org.onap.policy.models.tosca.authorative.concepts.ToscaTypedEntityFilter; import org.onap.policy.models.tosca.authorative.provider.AuthorativeToscaProvider; /** @@ -74,8 +73,8 @@ public class DatabasePolicyModelsProviderImpl extends AbstractModelsProvider imp @Override - public List<ToscaServiceTemplate> getFilteredServiceTemplateList(@NonNull ToscaServiceTemplateFilter filter) - throws PfModelException { + public List<ToscaServiceTemplate> getFilteredServiceTemplateList( + @NonNull ToscaEntityFilter<ToscaServiceTemplate> filter) throws PfModelException { assertInitialized(); return new AuthorativeToscaProvider().getFilteredServiceTemplateList(getPfDao(), filter); } @@ -115,13 +114,14 @@ public class DatabasePolicyModelsProviderImpl extends AbstractModelsProvider imp } @Override - public ToscaServiceTemplate getFilteredPolicyTypes(@NonNull ToscaPolicyTypeFilter filter) throws PfModelException { + public ToscaServiceTemplate getFilteredPolicyTypes(@NonNull ToscaEntityFilter<ToscaPolicyType> filter) + throws PfModelException { assertInitialized(); return new AuthorativeToscaProvider().getFilteredPolicyTypes(getPfDao(), filter); } @Override - public List<ToscaPolicyType> getFilteredPolicyTypeList(@NonNull ToscaPolicyTypeFilter filter) + public List<ToscaPolicyType> getFilteredPolicyTypeList(@NonNull ToscaEntityFilter<ToscaPolicyType> filter) throws PfModelException { assertInitialized(); return new AuthorativeToscaProvider().getFilteredPolicyTypeList(getPfDao(), filter); @@ -165,13 +165,15 @@ public class DatabasePolicyModelsProviderImpl extends AbstractModelsProvider imp } @Override - public ToscaServiceTemplate getFilteredPolicies(@NonNull ToscaPolicyFilter filter) throws PfModelException { + public ToscaServiceTemplate getFilteredPolicies(@NonNull ToscaTypedEntityFilter<ToscaPolicy> filter) + throws PfModelException { assertInitialized(); return new AuthorativeToscaProvider().getFilteredPolicies(getPfDao(), filter); } @Override - public List<ToscaPolicy> getFilteredPolicyList(@NonNull ToscaPolicyFilter filter) throws PfModelException { + public List<ToscaPolicy> getFilteredPolicyList(@NonNull ToscaTypedEntityFilter<ToscaPolicy> filter) + throws PfModelException { assertInitialized(); return new AuthorativeToscaProvider().getFilteredPolicyList(getPfDao(), filter); } @@ -288,21 +290,20 @@ public class DatabasePolicyModelsProviderImpl extends AbstractModelsProvider imp @Override public List<PdpPolicyStatus> getAllPolicyStatus(@NonNull ToscaConceptIdentifierOptVersion policy) - throws PfModelException { + throws PfModelException { assertInitialized(); return new PdpProvider().getAllPolicyStatus(getPfDao(), policy); } @Override - public List<PdpPolicyStatus> getGroupPolicyStatus(@NonNull String groupName) - throws PfModelException { + public List<PdpPolicyStatus> getGroupPolicyStatus(@NonNull String groupName) throws PfModelException { assertInitialized(); return new PdpProvider().getGroupPolicyStatus(getPfDao(), groupName); } @Override - public void cudPolicyStatus(Collection<PdpPolicyStatus> createObjs, - Collection<PdpPolicyStatus> updateObjs, Collection<PdpPolicyStatus> deleteObjs) { + public void cudPolicyStatus(Collection<PdpPolicyStatus> createObjs, Collection<PdpPolicyStatus> updateObjs, + Collection<PdpPolicyStatus> deleteObjs) { assertInitialized(); new PdpProvider().cudPolicyStatus(getPfDao(), createObjs, updateObjs, deleteObjs); } 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 0a9ea723f..1b91f07c6 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 @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019-2020 Nordix Foundation. + * Copyright (C) 2019-2021 Nordix Foundation. * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2020 Bell Canada. All rights reserved. * ================================================================================ @@ -41,12 +41,11 @@ import org.onap.policy.models.pdp.concepts.PdpSubGroup; import org.onap.policy.models.provider.PolicyModelsProvider; import org.onap.policy.models.provider.PolicyModelsProviderParameters; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifierOptVersion; +import org.onap.policy.models.tosca.authorative.concepts.ToscaEntityFilter; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; -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.authorative.concepts.ToscaServiceTemplateFilter; +import org.onap.policy.models.tosca.authorative.concepts.ToscaTypedEntityFilter; /** * This class provides a dummy implementation of the Policy Models Provider for the ONAP Policy Framework. @@ -81,8 +80,8 @@ public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider { } @Override - public List<ToscaServiceTemplate> getFilteredServiceTemplateList(@NonNull ToscaServiceTemplateFilter filter) - throws PfModelException { + public List<ToscaServiceTemplate> getFilteredServiceTemplateList( + @NonNull ToscaEntityFilter<ToscaServiceTemplate> filter) throws PfModelException { return new ArrayList<>(); } @@ -115,12 +114,13 @@ public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider { } @Override - public ToscaServiceTemplate getFilteredPolicyTypes(ToscaPolicyTypeFilter filter) throws PfModelException { + public ToscaServiceTemplate getFilteredPolicyTypes(ToscaEntityFilter<ToscaPolicyType> filter) + throws PfModelException { return getDummyResponse("dummyimpl/DummyToscaPolicyTypeGetResponse.json"); } @Override - public List<ToscaPolicyType> getFilteredPolicyTypeList(ToscaPolicyTypeFilter filter) { + public List<ToscaPolicyType> getFilteredPolicyTypeList(ToscaEntityFilter<ToscaPolicyType> filter) { return new ArrayList<>(); } @@ -150,12 +150,13 @@ public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider { } @Override - public ToscaServiceTemplate getFilteredPolicies(ToscaPolicyFilter filter) throws PfModelException { + public ToscaServiceTemplate getFilteredPolicies(ToscaTypedEntityFilter<ToscaPolicy> filter) + throws PfModelException { return getDummyResponse("dummyimpl/DummyToscaPolicyGetResponse.json"); } @Override - public List<ToscaPolicy> getFilteredPolicyList(ToscaPolicyFilter filter) throws PfModelException { + public List<ToscaPolicy> getFilteredPolicyList(ToscaTypedEntityFilter<ToscaPolicy> filter) throws PfModelException { return new ArrayList<>(); } @@ -249,7 +250,7 @@ public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider { @Override public List<PdpPolicyStatus> getAllPolicyStatus(@NonNull ToscaConceptIdentifierOptVersion policy) - throws PfModelException { + throws PfModelException { // Not implemented return new ArrayList<>(); } @@ -262,7 +263,7 @@ public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider { @Override public void cudPolicyStatus(Collection<PdpPolicyStatus> createObjs, Collection<PdpPolicyStatus> updateObjs, - Collection<PdpPolicyStatus> deleteObjs) { + Collection<PdpPolicyStatus> deleteObjs) { // Not implemented } 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 fb5af1e1b..596f9fa0d 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 @@ -47,9 +47,11 @@ import org.onap.policy.models.provider.PolicyModelsProviderFactory; import org.onap.policy.models.provider.PolicyModelsProviderParameters; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifierOptVersion; -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.ToscaEntityFilter; +import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; +import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; +import org.onap.policy.models.tosca.authorative.concepts.ToscaTypedEntityFilter; /** * Test the database models provider implementation. @@ -296,10 +298,12 @@ public class DatabasePolicyModelsProviderTest { assertTrue(databaseProvider.getPolicyTypeList(NAME, VERSION_100).isEmpty()); - assertThatThrownBy(() -> databaseProvider.getFilteredPolicyTypes(ToscaPolicyTypeFilter.builder().build())) - .hasMessage("service template not found in database"); + assertThatThrownBy( + () -> databaseProvider.getFilteredPolicyTypes(ToscaEntityFilter.<ToscaPolicyType>builder().build())) + .hasMessage("service template not found in database"); - assertTrue(databaseProvider.getFilteredPolicyTypeList(ToscaPolicyTypeFilter.builder().build()).isEmpty()); + assertTrue(databaseProvider.getFilteredPolicyTypeList(ToscaEntityFilter.<ToscaPolicyType>builder().build()) + .isEmpty()); assertThatThrownBy(() -> { databaseProvider.createPolicyTypes(new ToscaServiceTemplate()); @@ -317,10 +321,12 @@ public class DatabasePolicyModelsProviderTest { assertTrue(databaseProvider.getPolicyList(NAME, VERSION_100).isEmpty()); - assertThatThrownBy(() -> databaseProvider.getFilteredPolicies(ToscaPolicyFilter.builder().build())) - .hasMessage("service template not found in database"); + assertThatThrownBy( + () -> databaseProvider.getFilteredPolicies(ToscaTypedEntityFilter.<ToscaPolicy>builder().build())) + .hasMessage("service template not found in database"); - assertTrue(databaseProvider.getFilteredPolicyList(ToscaPolicyFilter.builder().build()).isEmpty()); + assertTrue(databaseProvider.getFilteredPolicyList(ToscaTypedEntityFilter.<ToscaPolicy>builder().build()) + .isEmpty()); assertThatThrownBy(() -> { databaseProvider.createPolicies(new ToscaServiceTemplate()); @@ -428,7 +434,7 @@ public class DatabasePolicyModelsProviderTest { assertThat(databaseProvider.getAllPolicyStatus()).isEmpty(); assertThat(databaseProvider.getAllPolicyStatus(new ToscaConceptIdentifierOptVersion("MyPolicy", null))) - .isEmpty(); + .isEmpty(); assertThat(databaseProvider.getGroupPolicyStatus(GROUP)).isEmpty(); assertThatCode(() -> databaseProvider.cudPolicyStatus(null, null, null)).doesNotThrowAnyException(); 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 008a1ccf9..f2e8e8489 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,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019-2020 Nordix Foundation. + * Copyright (C) 2019-2021 Nordix Foundation. * Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2020 Bell Canada. All rights reserved. * ================================================================================ @@ -39,12 +39,11 @@ import org.onap.policy.models.pdp.concepts.PdpStatistics; import org.onap.policy.models.pdp.concepts.PdpSubGroup; import org.onap.policy.models.provider.PolicyModelsProvider; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifierOptVersion; +import org.onap.policy.models.tosca.authorative.concepts.ToscaEntityFilter; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; -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.authorative.concepts.ToscaServiceTemplateFilter; +import org.onap.policy.models.tosca.authorative.concepts.ToscaTypedEntityFilter; /** * Dummy implementation of {@link PolicyModelsProvider} with bad constructor. @@ -67,8 +66,8 @@ public class DummyBadProviderImpl implements PolicyModelsProvider { } @Override - public List<ToscaServiceTemplate> getFilteredServiceTemplateList(@NonNull ToscaServiceTemplateFilter filter) - throws PfModelException { + public List<ToscaServiceTemplate> getFilteredServiceTemplateList( + @NonNull ToscaEntityFilter<ToscaServiceTemplate> filter) throws PfModelException { return null; } @@ -164,12 +163,13 @@ public class DummyBadProviderImpl implements PolicyModelsProvider { } @Override - public ToscaServiceTemplate getFilteredPolicyTypes(@NonNull ToscaPolicyTypeFilter filter) throws PfModelException { + public ToscaServiceTemplate getFilteredPolicyTypes(@NonNull ToscaEntityFilter<ToscaPolicyType> filter) + throws PfModelException { return null; } @Override - public List<ToscaPolicyType> getFilteredPolicyTypeList(@NonNull ToscaPolicyTypeFilter filter) + public List<ToscaPolicyType> getFilteredPolicyTypeList(@NonNull ToscaEntityFilter<ToscaPolicyType> filter) throws PfModelException { return Collections.emptyList(); } @@ -180,12 +180,14 @@ public class DummyBadProviderImpl implements PolicyModelsProvider { } @Override - public ToscaServiceTemplate getFilteredPolicies(@NonNull ToscaPolicyFilter filter) throws PfModelException { + public ToscaServiceTemplate getFilteredPolicies(@NonNull ToscaTypedEntityFilter<ToscaPolicy> filter) + throws PfModelException { return null; } @Override - public List<ToscaPolicy> getFilteredPolicyList(@NonNull ToscaPolicyFilter filter) throws PfModelException { + public List<ToscaPolicy> getFilteredPolicyList(@NonNull ToscaTypedEntityFilter<ToscaPolicy> filter) + throws PfModelException { return Collections.emptyList(); } @@ -240,7 +242,7 @@ public class DummyBadProviderImpl implements PolicyModelsProvider { @Override public List<PdpPolicyStatus> getAllPolicyStatus(@NonNull ToscaConceptIdentifierOptVersion policy) - throws PfModelException { + throws PfModelException { // Not implemented return null; } @@ -253,7 +255,7 @@ public class DummyBadProviderImpl implements PolicyModelsProvider { @Override public void cudPolicyStatus(Collection<PdpPolicyStatus> createObjs, Collection<PdpPolicyStatus> updateObjs, - Collection<PdpPolicyStatus> deleteObjs) { + Collection<PdpPolicyStatus> deleteObjs) { // Not implemented } 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 223aa5b36..a57cc956d 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,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019-2020 Nordix Foundation. + * Copyright (C) 2019-2021 Nordix Foundation. * Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2020 Bell Canada. All rights reserved. * ================================================================================ @@ -40,9 +40,11 @@ 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.ToscaConceptIdentifierOptVersion; -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.ToscaEntityFilter; +import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; +import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; +import org.onap.policy.models.tosca.authorative.concepts.ToscaTypedEntityFilter; /** * Test the dummy models provider implementation. @@ -83,17 +85,17 @@ public class DummyPolicyModelsProviderTest { dummyProvider.init(); assertNotNull(dummyProvider.getPolicyTypes("name", VERSION)); - assertNotNull(dummyProvider.getFilteredPolicyTypes(ToscaPolicyTypeFilter.builder().build())); + assertNotNull(dummyProvider.getFilteredPolicyTypes(ToscaEntityFilter.<ToscaPolicyType>builder().build())); assertNotNull(dummyProvider.getPolicyTypeList("name", VERSION)); - assertNotNull(dummyProvider.getFilteredPolicyTypeList(ToscaPolicyTypeFilter.builder().build())); + assertNotNull(dummyProvider.getFilteredPolicyTypeList(ToscaEntityFilter.<ToscaPolicyType>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.getFilteredPolicies(ToscaTypedEntityFilter.<ToscaPolicy>builder().build())); assertNotNull(dummyProvider.getPolicyList("name", VERSION)); - assertNotNull(dummyProvider.getFilteredPolicyList(ToscaPolicyFilter.builder().build())); + assertNotNull(dummyProvider.getFilteredPolicyList(ToscaTypedEntityFilter.<ToscaPolicy>builder().build())); assertNotNull(dummyProvider.createPolicies(new ToscaServiceTemplate())); assertNotNull(dummyProvider.updatePolicies(new ToscaServiceTemplate())); assertNotNull(dummyProvider.deletePolicy("name", VERSION)); 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 a42aae4b6..ac62569b3 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 @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019-2020 Nordix Foundation. + * Copyright (C) 2019-2021 Nordix Foundation. * Modifications Copyright (C) 2020 Bell Canada. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -44,10 +44,11 @@ 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.ToscaEntityFilter; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; -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.ToscaPolicyType; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; +import org.onap.policy.models.tosca.authorative.concepts.ToscaTypedEntityFilter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -114,15 +115,15 @@ public class PolicyToscaPersistenceTest { public void testHpaPolicyTypeGet() throws PfModelException { long getStartTime = System.currentTimeMillis(); ToscaServiceTemplate hpaServiceTemplate = - databaseProvider.getPolicyTypes("onap.policies.optimization.resource.HpaPolicy", "1.0.0"); + databaseProvider.getPolicyTypes("onap.policies.optimization.resource.HpaPolicy", "1.0.0"); LOGGER.trace("HPA policy normal get time (ms): {}", System.currentTimeMillis() - getStartTime); assertEquals(3, hpaServiceTemplate.getPolicyTypesAsMap().size()); assertEquals(5, hpaServiceTemplate.getDataTypesAsMap().size()); getStartTime = System.currentTimeMillis(); - ToscaPolicyTypeFilter hpaFilter = ToscaPolicyTypeFilter.builder() - .name("onap.policies.optimization.resource.HpaPolicy").version("1.0.0").build(); + ToscaEntityFilter<ToscaPolicyType> hpaFilter = ToscaEntityFilter.<ToscaPolicyType>builder() + .name("onap.policies.optimization.resource.HpaPolicy").version("1.0.0").build(); hpaServiceTemplate = databaseProvider.getFilteredPolicyTypes(hpaFilter); LOGGER.trace("HPA policy filter name version get time (ms): {}", System.currentTimeMillis() - getStartTime); @@ -130,7 +131,8 @@ public class PolicyToscaPersistenceTest { assertEquals(5, hpaServiceTemplate.getDataTypesAsMap().size()); getStartTime = System.currentTimeMillis(); - hpaFilter = ToscaPolicyTypeFilter.builder().name("onap.policies.optimization.resource.HpaPolicy").build(); + hpaFilter = ToscaEntityFilter.<ToscaPolicyType>builder().name("onap.policies.optimization.resource.HpaPolicy") + .build(); hpaServiceTemplate = databaseProvider.getFilteredPolicyTypes(hpaFilter); LOGGER.trace("HPA policy filter name only get time (ms): {}", System.currentTimeMillis() - getStartTime); @@ -142,7 +144,7 @@ public class PolicyToscaPersistenceTest { public void testNamingPolicyGet() throws PfModelException { String policyYamlString = ResourceUtils.getResourceAsString("policies/sdnc.policy.naming.input.tosca.yaml"); ToscaServiceTemplate serviceTemplate = - yamlJsonTranslator.fromYaml(policyYamlString, ToscaServiceTemplate.class); + yamlJsonTranslator.fromYaml(policyYamlString, ToscaServiceTemplate.class); long createStartTime = System.currentTimeMillis(); databaseProvider.createPolicies(serviceTemplate); @@ -150,7 +152,7 @@ public class PolicyToscaPersistenceTest { long getStartTime = System.currentTimeMillis(); ToscaServiceTemplate namingServiceTemplate = - databaseProvider.getPolicies("SDNC_Policy.ONAP_NF_NAMING_TIMESTAMP", "1.0.0"); + databaseProvider.getPolicies("SDNC_Policy.ONAP_NF_NAMING_TIMESTAMP", "1.0.0"); LOGGER.trace("Naming policy normal get time (ms): {}", System.currentTimeMillis() - getStartTime); assertEquals(1, namingServiceTemplate.getToscaTopologyTemplate().getPoliciesAsMap().size()); @@ -158,8 +160,8 @@ public class PolicyToscaPersistenceTest { assertEquals(3, namingServiceTemplate.getDataTypesAsMap().size()); getStartTime = System.currentTimeMillis(); - ToscaPolicyFilter filter = - ToscaPolicyFilter.builder().name("SDNC_Policy.ONAP_NF_NAMING_TIMESTAMP").version("1.0.0").build(); + ToscaTypedEntityFilter<ToscaPolicy> filter = ToscaTypedEntityFilter.<ToscaPolicy>builder() + .name("SDNC_Policy.ONAP_NF_NAMING_TIMESTAMP").version("1.0.0").build(); namingServiceTemplate = databaseProvider.getFilteredPolicies(filter); LOGGER.trace("Naming policy filtered get time (ms): {}", System.currentTimeMillis() - getStartTime); @@ -168,7 +170,7 @@ public class PolicyToscaPersistenceTest { assertEquals(3, namingServiceTemplate.getDataTypesAsMap().size()); getStartTime = System.currentTimeMillis(); - filter = ToscaPolicyFilter.builder().name("SDNC_Policy.ONAP_NF_NAMING_TIMESTAMP").build(); + filter = ToscaTypedEntityFilter.<ToscaPolicy>builder().name("SDNC_Policy.ONAP_NF_NAMING_TIMESTAMP").build(); namingServiceTemplate = databaseProvider.getFilteredPolicies(filter); LOGGER.trace("Naming policy filtered name only get time (ms): {}", System.currentTimeMillis() - getStartTime); @@ -178,7 +180,7 @@ public class PolicyToscaPersistenceTest { long deleteStartTime = System.currentTimeMillis(); ToscaServiceTemplate deletedServiceTemplate = - databaseProvider.deletePolicy("SDNC_Policy.ONAP_NF_NAMING_TIMESTAMP", "1.0.0"); + databaseProvider.deletePolicy("SDNC_Policy.ONAP_NF_NAMING_TIMESTAMP", "1.0.0"); LOGGER.trace("Naming policy delete time (ms): {}", System.currentTimeMillis() - deleteStartTime); assertEquals(1, deletedServiceTemplate.getToscaTopologyTemplate().getPoliciesAsMap().size()); @@ -188,7 +190,7 @@ public class PolicyToscaPersistenceTest { public void testNamingPolicyVersions() throws PfModelException { String policyYamlString = ResourceUtils.getResourceAsString("policies/sdnc.policy.naming.input.tosca.yaml"); ToscaServiceTemplate serviceTemplate = - yamlJsonTranslator.fromYaml(policyYamlString, ToscaServiceTemplate.class); + yamlJsonTranslator.fromYaml(policyYamlString, ToscaServiceTemplate.class); // Create policy types and data types List<Map<String, ToscaPolicy>> policyMapList = serviceTemplate.getToscaTopologyTemplate().getPolicies(); @@ -211,26 +213,26 @@ public class PolicyToscaPersistenceTest { for (int i = 1; i < 22; i++) { ToscaServiceTemplate namingServiceTemplate = - databaseProvider.getPolicies("SDNC_Policy.ONAP_NF_NAMING_TIMESTAMP", i + ".0.0"); + databaseProvider.getPolicies("SDNC_Policy.ONAP_NF_NAMING_TIMESTAMP", i + ".0.0"); assertEquals(i + ".0.0", namingServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).values() - .iterator().next().getVersion()); + .iterator().next().getVersion()); - ToscaPolicyFilter policyFilter = - ToscaPolicyFilter.builder().name("SDNC_Policy.ONAP_NF_NAMING_TIMESTAMP").version(i + ".0.0").build(); + ToscaTypedEntityFilter<ToscaPolicy> policyFilter = ToscaTypedEntityFilter.<ToscaPolicy>builder() + .name("SDNC_Policy.ONAP_NF_NAMING_TIMESTAMP").version(i + ".0.0").build(); namingServiceTemplate = databaseProvider.getFilteredPolicies(policyFilter); assertEquals(i + ".0.0", namingServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).values() - .iterator().next().getVersion()); + .iterator().next().getVersion()); } - ToscaPolicyFilter policyFilter = ToscaPolicyFilter.builder().name("SDNC_Policy.ONAP_NF_NAMING_TIMESTAMP") - .version(ToscaPolicyFilter.LATEST_VERSION).build(); + ToscaTypedEntityFilter<ToscaPolicy> policyFilter = ToscaTypedEntityFilter.<ToscaPolicy>builder() + .name("SDNC_Policy.ONAP_NF_NAMING_TIMESTAMP").version(ToscaTypedEntityFilter.LATEST_VERSION).build(); ToscaServiceTemplate namingServiceTemplate = databaseProvider.getFilteredPolicies(policyFilter); assertEquals("21.0.0", namingServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).values().iterator() - .next().getVersion()); + .next().getVersion()); for (int i = 1; i < 22; i++) { ToscaServiceTemplate deletedServiceTemplate = - databaseProvider.deletePolicy("SDNC_Policy.ONAP_NF_NAMING_TIMESTAMP", i + ".0.0"); + databaseProvider.deletePolicy("SDNC_Policy.ONAP_NF_NAMING_TIMESTAMP", i + ".0.0"); assertEquals(1, deletedServiceTemplate.getToscaTopologyTemplate().getPoliciesAsMap().size()); } } @@ -262,28 +264,29 @@ public class PolicyToscaPersistenceTest { for (Map<String, ToscaPolicy> policyMap : serviceTemplate.getToscaTopologyTemplate().getPolicies()) { for (ToscaPolicy policy : policyMap.values()) { ToscaServiceTemplate gotToscaServiceTemplate = - databaseProvider.getPolicies(policy.getName(), policy.getVersion()); + databaseProvider.getPolicies(policy.getName(), policy.getVersion()); assertEquals(policy.getType(), gotToscaServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0) - .get(policy.getName()).getType()); + .get(policy.getName()).getType()); - gotToscaServiceTemplate = databaseProvider.getFilteredPolicies(ToscaPolicyFilter.builder().build()); + gotToscaServiceTemplate = + databaseProvider.getFilteredPolicies(ToscaTypedEntityFilter.<ToscaPolicy>builder().build()); assertEquals(policy.getType(), - getToscaPolicyFromMapList(gotToscaServiceTemplate.getToscaTopologyTemplate().getPolicies(), - policy.getName()).getType()); + getToscaPolicyFromMapList(gotToscaServiceTemplate.getToscaTopologyTemplate().getPolicies(), + policy.getName()).getType()); - gotToscaServiceTemplate = databaseProvider.getFilteredPolicies( - ToscaPolicyFilter.builder().name(policy.getName()).version(policy.getVersion()).build()); + gotToscaServiceTemplate = databaseProvider.getFilteredPolicies(ToscaTypedEntityFilter + .<ToscaPolicy>builder().name(policy.getName()).version(policy.getVersion()).build()); assertEquals(policy.getType(), gotToscaServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0) - .get(policy.getName()).getType()); + .get(policy.getName()).getType()); } } } private ToscaPolicy getToscaPolicyFromMapList(List<Map<String, ToscaPolicy>> toscaPolicyMapList, - String policyName) { + String policyName) { ToscaPolicy toscaPolicy = new ToscaPolicy(); for (Map<String, ToscaPolicy> policyMap : toscaPolicyMapList) { toscaPolicy = policyMap.get(policyName); @@ -300,7 +303,7 @@ public class PolicyToscaPersistenceTest { for (String policyTypeResource : policyTypeResources) { String policyTypeYamlString = ResourceUtils.getResourceAsString(policyTypeResource); ToscaServiceTemplate toscaServiceTemplatePolicyType = - yamlJsonTranslator.fromYaml(policyTypeYamlString, ToscaServiceTemplate.class); + yamlJsonTranslator.fromYaml(policyTypeYamlString, ToscaServiceTemplate.class); assertNotNull(toscaServiceTemplatePolicyType); databaseProvider.createPolicyTypes(toscaServiceTemplatePolicyType); diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaConceptIdentifier.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaConceptIdentifier.java index ade1a28d4..4cc8892c2 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaConceptIdentifier.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaConceptIdentifier.java @@ -21,6 +21,7 @@ package org.onap.policy.models.tosca.authorative.concepts; +import java.io.Serializable; import lombok.Data; import lombok.NoArgsConstructor; import lombok.NonNull; @@ -35,7 +36,8 @@ import org.onap.policy.models.base.PfKey; */ @Data @NoArgsConstructor -public class ToscaConceptIdentifier implements Comparable<ToscaConceptIdentifier> { +public class ToscaConceptIdentifier implements Serializable, Comparable<ToscaConceptIdentifier> { + private static final long serialVersionUID = 8010649773816325786L; @NonNull private String name; diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntity.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntity.java index 5c1167c7d..98efd1991 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntity.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntity.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP Policy Model * ================================================================================ - * Copyright (C) 2019-2020 Nordix Foundation. + * Copyright (C) 2019-2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -140,4 +140,22 @@ public class ToscaEntity implements PfNameVersion { return entityMap; } + + /** + * Method that should be specialised to return the type of the entity if the entity has a type. + * + * @return the type of the entity or null if it has no type + */ + public String getType() { + return null; + } + + /** + * Method that should be specialised to return the type version of the entity if the entity has a type. + * + * @return the type of the entity or null if it has no type + */ + public String getTypeVersion() { + return null; + } } diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyComparator.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntityComparator.java index 8bbe70db2..9b8c98675 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyComparator.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntityComparator.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix Foundation. + * Copyright (C) 2020-2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,12 +23,12 @@ package org.onap.policy.models.tosca.authorative.concepts; import java.util.Comparator; /** - * Compare two ToscaPolicy objects. + * Compare two ToscaEntity objects. */ -public class ToscaPolicyComparator implements Comparator<ToscaPolicy> { +public class ToscaEntityComparator<T extends ToscaEntity> implements Comparator<T> { @Override - public int compare(final ToscaPolicy left, final ToscaPolicy right) { + public int compare(final ToscaEntity left, final ToscaEntity right) { return left.compareNameVersion(left, right); } } diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeFilter.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntityFilter.java index 4e9810b98..ef0b6b183 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeFilter.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntityFilter.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019-2020 Nordix Foundation. + * Copyright (C) 2019-2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,13 +28,13 @@ import lombok.NonNull; import org.onap.policy.models.base.PfObjectFilter; /** - * Filter class for searches for {@link ToscaPolicyType} instances. If any fields are null, they are ignored. + * Filter class for searches for {@link ToscaEntity} instances. If any fields are null, they are ignored. * * @author Liam Fallon (liam.fallon@est.tech) */ @Builder @Data -public class ToscaPolicyTypeFilter implements PfObjectFilter<ToscaPolicyType> { +public class ToscaEntityFilter<T extends ToscaEntity> implements PfObjectFilter<T> { public static final String LATEST_VERSION = "LATEST"; // Regular expression @@ -44,10 +44,10 @@ public class ToscaPolicyTypeFilter implements PfObjectFilter<ToscaPolicyType> { private String version; @Override - public List<ToscaPolicyType> filter(@NonNull final List<ToscaPolicyType> originalList) { + public List<T> filter(@NonNull final List<T> originalList) { // @formatter:off - List<ToscaPolicyType> returnList = originalList.stream() + List<T> returnList = originalList.stream() .filter(p -> filterString(p.getName(), name)) .filter(p -> LATEST_VERSION.equals(version) || filterString(p.getVersion(), version)) @@ -55,7 +55,7 @@ public class ToscaPolicyTypeFilter implements PfObjectFilter<ToscaPolicyType> { // @formatter:off if (LATEST_VERSION.equals(version)) { - return this.latestVersionFilter(returnList, new ToscaPolicyTypeComparator()); + return this.latestVersionFilter(returnList, new ToscaEntityComparator<T>()); } else { return returnList; } diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeComparator.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeComparator.java deleted file mode 100644 index 9f45a7854..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeComparator.java +++ /dev/null @@ -1,34 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 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.tosca.authorative.concepts; - -import java.util.Comparator; - -/** - * Compare two ToscaPolicyType objects. - */ -public class ToscaPolicyTypeComparator implements Comparator<ToscaPolicyType> { - - @Override - public int compare(final ToscaPolicyType left, final ToscaPolicyType right) { - return left.compareNameVersion(left, right); - } -} diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaServiceTemplateComparator.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaServiceTemplateComparator.java deleted file mode 100644 index 015c10bdd..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaServiceTemplateComparator.java +++ /dev/null @@ -1,34 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 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.tosca.authorative.concepts; - -import java.util.Comparator; - -/** - * Compare two ToscaServiceTemplate objects. - */ -public class ToscaServiceTemplateComparator implements Comparator<ToscaServiceTemplate> { - - @Override - public int compare(final ToscaServiceTemplate left, final ToscaServiceTemplate right) { - return left.compareNameVersion(left, right); - } -} diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaServiceTemplateFilter.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaServiceTemplateFilter.java deleted file mode 100644 index 75b13969d..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaServiceTemplateFilter.java +++ /dev/null @@ -1,63 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 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.tosca.authorative.concepts; - -import java.util.List; -import java.util.stream.Collectors; -import lombok.Builder; -import lombok.Data; -import lombok.NonNull; -import org.onap.policy.models.base.PfObjectFilter; - -/** - * Filter class for searches for {@link ToscaServiceTemplate} instances. If any fields are null, they are ignored. - * - * @author Liam Fallon (liam.fallon@est.tech) - */ -@Builder -@Data -public class ToscaServiceTemplateFilter implements PfObjectFilter<ToscaServiceTemplate> { - public static final String LATEST_VERSION = "LATEST"; - - // Regular expression - private String name; - - // Regular Expression, set to LATEST_VERRSION to get the latest version - private String version; - - @Override - public List<ToscaServiceTemplate> filter(@NonNull final List<ToscaServiceTemplate> originalList) { - - // @formatter:off - List<ToscaServiceTemplate> returnList = originalList.stream() - .filter(p -> filterString(p.getName(), name)) - .filter(p -> LATEST_VERSION.equals(version) - || filterString(p.getVersion(), version)) - .collect(Collectors.toList()); - // @formatter:off - - if (LATEST_VERSION.equals(version)) { - return this.latestVersionFilter(returnList, new ToscaServiceTemplateComparator()); - } else { - return returnList; - } - } -} diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyFilter.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaTypedEntityFilter.java index 86c2e6f3e..b6ff86b3c 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyFilter.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaTypedEntityFilter.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019-2020 Nordix Foundation. + * Copyright (C) 2019-2021 Nordix Foundation. * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -35,7 +35,7 @@ import org.onap.policy.models.base.PfObjectFilter; */ @Builder @Data -public class ToscaPolicyFilter implements PfObjectFilter<ToscaPolicy> { +public class ToscaTypedEntityFilter<T extends ToscaEntity> implements PfObjectFilter<T> { public static final String LATEST_VERSION = "LATEST"; // Exact expression @@ -54,20 +54,20 @@ public class ToscaPolicyFilter implements PfObjectFilter<ToscaPolicy> { private String typeVersion; @Override - public List<ToscaPolicy> filter(@NonNull final List<ToscaPolicy> originalList) { + public List<T> filter(@NonNull final List<T> originalList) { // @formatter:off - List<ToscaPolicy> returnList = originalList.stream() - .filter(filterStringPred(name, ToscaPolicy::getName)) - .filter(filterStringPred((LATEST_VERSION.equals(version) ? null : version), ToscaPolicy::getVersion)) - .filter(filterPrefixPred(versionPrefix, ToscaPolicy::getVersion)) - .filter(filterStringPred(type, ToscaPolicy::getType)) - .filter(filterStringPred(typeVersion, ToscaPolicy::getTypeVersion)) + List<T> returnList = originalList.stream() + .filter(filterStringPred(name, T::getName)) + .filter(filterStringPred((LATEST_VERSION.equals(version) ? null : version), T::getVersion)) + .filter(filterPrefixPred(versionPrefix, T::getVersion)) + .filter(filterStringPred(type, T::getType)) + .filter(filterStringPred(typeVersion, T::getTypeVersion)) .collect(Collectors.toList()); // @formatter:off if (LATEST_VERSION.equals(version)) { - return this.latestVersionFilter(returnList, new ToscaPolicyComparator()); + return this.latestVersionFilter(returnList, new ToscaEntityComparator<T>()); } else { return returnList; } diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProvider.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProvider.java index d20f5d080..c43aadf0f 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProvider.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProvider.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019-2020 Nordix Foundation. + * Copyright (C) 2019-2021 Nordix Foundation. * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -34,12 +34,11 @@ import org.onap.policy.models.base.PfModelException; import org.onap.policy.models.base.PfModelRuntimeException; import org.onap.policy.models.dao.PfDao; import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity; +import org.onap.policy.models.tosca.authorative.concepts.ToscaEntityFilter; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; -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.authorative.concepts.ToscaServiceTemplateFilter; +import org.onap.policy.models.tosca.authorative.concepts.ToscaTypedEntityFilter; import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate; import org.onap.policy.models.tosca.simple.provider.SimpleToscaProvider; import org.onap.policy.models.tosca.utils.ToscaServiceTemplateUtils; @@ -97,7 +96,7 @@ public class AuthorativeToscaProvider { * @throws PfModelException on errors getting service templates */ public List<ToscaServiceTemplate> getFilteredServiceTemplateList(PfDao pfDao, - @NonNull ToscaServiceTemplateFilter filter) throws PfModelException { + @NonNull ToscaEntityFilter<ToscaServiceTemplate> filter) throws PfModelException { LOGGER.debug("->getFilteredServiceTemplateList: filter={}", filter); @@ -240,7 +239,7 @@ public class AuthorativeToscaProvider { * @throws PfModelException on errors getting policy types */ public ToscaServiceTemplate getFilteredPolicyTypes(@NonNull final PfDao dao, - @NonNull final ToscaPolicyTypeFilter filter) throws PfModelException { + @NonNull final ToscaEntityFilter<ToscaPolicyType> filter) throws PfModelException { synchronized (providerLockObject) { LOGGER.debug("->getFilteredPolicyTypes: filter={}", filter); @@ -282,7 +281,7 @@ public class AuthorativeToscaProvider { * @throws PfModelException on errors getting policy types */ public List<ToscaPolicyType> getFilteredPolicyTypeList(@NonNull final PfDao dao, - @NonNull final ToscaPolicyTypeFilter filter) throws PfModelException { + @NonNull final ToscaEntityFilter<ToscaPolicyType> filter) throws PfModelException { LOGGER.debug("->getFilteredPolicyTypeList: filter={}", filter); @@ -423,12 +422,13 @@ public class AuthorativeToscaProvider { * @return the policies found * @throws PfModelException on errors getting policies */ - public ToscaServiceTemplate getFilteredPolicies(@NonNull final PfDao dao, @NonNull final ToscaPolicyFilter filter) - throws PfModelException { + public ToscaServiceTemplate getFilteredPolicies(@NonNull final PfDao dao, + @NonNull final ToscaTypedEntityFilter<ToscaPolicy> filter) throws PfModelException { synchronized (providerLockObject) { LOGGER.debug("->getFilteredPolicies: filter={}", filter); - String version = ToscaPolicyFilter.LATEST_VERSION.equals(filter.getVersion()) ? null : filter.getVersion(); + String version = + ToscaTypedEntityFilter.LATEST_VERSION.equals(filter.getVersion()) ? null : filter.getVersion(); SimpleToscaProvider simpleToscaProvider = new SimpleToscaProvider(); final JpaToscaServiceTemplate dbServiceTemplate = @@ -468,11 +468,11 @@ public class AuthorativeToscaProvider { * @return the policies found * @throws PfModelException on errors getting policies */ - public List<ToscaPolicy> getFilteredPolicyList(@NonNull final PfDao dao, @NonNull final ToscaPolicyFilter filter) - throws PfModelException { + public List<ToscaPolicy> getFilteredPolicyList(@NonNull final PfDao dao, + @NonNull final ToscaTypedEntityFilter<ToscaPolicy> filter) throws PfModelException { LOGGER.debug("->getFilteredPolicyList: filter={}", filter); - String version = ToscaPolicyFilter.LATEST_VERSION.equals(filter.getVersion()) ? null : filter.getVersion(); + String version = ToscaTypedEntityFilter.LATEST_VERSION.equals(filter.getVersion()) ? null : filter.getVersion(); List<ToscaPolicy> policyList = filter.filter(getPolicyList(dao, filter.getName(), version)); diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/PojosTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/PojosTest.java index c9f162a3a..fe60a52c9 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/PojosTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/PojosTest.java @@ -3,6 +3,7 @@ * ONAP Policy Model * ================================================================================ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -57,9 +58,9 @@ public class PojosTest { validator.validate(POJO_PACKAGE, new FilterPackageInfo(), new FilterClassName( - org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyFilter.class.getName()), + org.onap.policy.models.tosca.authorative.concepts.ToscaTypedEntityFilter.class.getName()), new FilterClassName( - org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeFilter.class.getName()), + org.onap.policy.models.tosca.authorative.concepts.ToscaEntityFilter.class.getName()), new FilterClassName( ToscaIdentifierTestBase.class.getName()) ); diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeFilterTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntityFilterTest.java index 031fceb9a..ec2a91733 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeFilterTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntityFilterTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019-2020 Nordix Foundation. + * Copyright (C) 2019-2021 Nordix Foundation. * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -42,13 +42,13 @@ import org.slf4j.LoggerFactory; import org.yaml.snakeyaml.Yaml; /** - * Test of the {@link ToscaPolicyTypeFilter} class. + * Test of the {@link ToscaEntityFilter} class. * * @author Liam Fallon (liam.fallon@est.tech) */ -public class ToscaPolicyTypeFilterTest { +public class ToscaEntityFilterTest { // Logger for this class - private static final Logger LOGGER = LoggerFactory.getLogger(ToscaPolicyTypeFilterTest.class); + private static final Logger LOGGER = LoggerFactory.getLogger(ToscaEntityFilterTest.class); private static final String VERSION_100 = "1.0.0"; private static final String VERSION_000 = "0.0.0"; @@ -117,7 +117,7 @@ public class ToscaPolicyTypeFilterTest { @Test public void testNullList() { - ToscaPolicyTypeFilter filter = ToscaPolicyTypeFilter.builder().build(); + ToscaEntityFilter<ToscaPolicyType> filter = ToscaEntityFilter.<ToscaPolicyType>builder().build(); assertThatThrownBy(() -> { filter.filter(null); @@ -126,7 +126,7 @@ public class ToscaPolicyTypeFilterTest { @Test public void testFilterNothing() { - ToscaPolicyTypeFilter filter = ToscaPolicyTypeFilter.builder().build(); + ToscaEntityFilter<ToscaPolicyType> filter = ToscaEntityFilter.<ToscaPolicyType>builder().build(); List<ToscaPolicyType> filteredList = filter.filter(typeList); assertTrue(filteredList.containsAll(typeList)); @@ -134,8 +134,8 @@ public class ToscaPolicyTypeFilterTest { @Test public void testFilterLatestVersion() { - ToscaPolicyTypeFilter filter = - ToscaPolicyTypeFilter.builder().version(ToscaPolicyTypeFilter.LATEST_VERSION).build(); + ToscaEntityFilter<ToscaPolicyType> filter = + ToscaEntityFilter.<ToscaPolicyType>builder().version(ToscaEntityFilter.LATEST_VERSION).build(); List<ToscaPolicyType> filteredList = filter.filter(typeList); assertEquals(19, filteredList.size()); @@ -165,28 +165,30 @@ public class ToscaPolicyTypeFilterTest { @Test public void testFilterNameVersion() { - ToscaPolicyTypeFilter filter = ToscaPolicyTypeFilter.builder().name("onap.policies.Monitoring").build(); + ToscaEntityFilter<ToscaPolicyType> filter = + ToscaEntityFilter.<ToscaPolicyType>builder().name("onap.policies.Monitoring").build(); List<ToscaPolicyType> filteredList = filter.filter(typeList); assertEquals(1, filteredList.size()); - filter = ToscaPolicyTypeFilter.builder().name("onap.policies.monitoring.tcagen2").build(); + filter = ToscaEntityFilter.<ToscaPolicyType>builder().name("onap.policies.monitoring.tcagen2").build(); filteredList = filter.filter(typeList); assertEquals(1, filteredList.size()); - filter = ToscaPolicyTypeFilter.builder().name("onap.policies.optimization.LpaPolicy").build(); + filter = ToscaEntityFilter.<ToscaPolicyType>builder().name("onap.policies.optimization.LpaPolicy").build(); filteredList = filter.filter(typeList); assertEquals(0, filteredList.size()); - filter = ToscaPolicyTypeFilter.builder().version(VERSION_100).build(); + filter = ToscaEntityFilter.<ToscaPolicyType>builder().version(VERSION_100).build(); filteredList = filter.filter(typeList); assertEquals(19, filteredList.size()); - filter = ToscaPolicyTypeFilter.builder().name("onap.policies.optimization.Vim_fit").version(VERSION_000) - .build(); + filter = ToscaEntityFilter.<ToscaPolicyType>builder().name("onap.policies.optimization.Vim_fit") + .version(VERSION_000).build(); filteredList = filter.filter(typeList); assertEquals(0, filteredList.size()); - filter = ToscaPolicyTypeFilter.builder().name("onap.policies.optimization.Vim_fit").version("0.0.1").build(); + filter = ToscaEntityFilter.<ToscaPolicyType>builder().name("onap.policies.optimization.Vim_fit") + .version("0.0.1").build(); filteredList = filter.filter(typeList); assertEquals(0, filteredList.size()); } diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTest.java index ba39621c6..1dc9e535e 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTest.java @@ -23,6 +23,7 @@ package org.onap.policy.models.tosca.authorative.concepts; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; import java.util.LinkedHashMap; import org.junit.Test; @@ -45,6 +46,10 @@ public class ToscaPolicyTest { policy.setType("my_type"); policy.setTypeVersion("3.2.1"); + ToscaEntity te = new ToscaEntity(); + assertNull(te.getType()); + assertNull(te.getTypeVersion()); + assertEquals("ToscaEntityKey(name=my_name, version=1.2.3)", policy.getKey().toString()); assertEquals(new ToscaConceptIdentifier("my_name", "1.2.3"), policy.getKey().asIdentifier()); @@ -57,11 +62,11 @@ public class ToscaPolicyTest { assertEquals("3.2.1", type.getVersion()); ToscaPolicy clonedPolicy0 = new ToscaPolicy(policy); - assertEquals(0, new ToscaPolicyComparator().compare(policy, clonedPolicy0)); + assertEquals(0, new ToscaEntityComparator<ToscaPolicy>().compare(policy, clonedPolicy0)); policy.setProperties(new LinkedHashMap<String, Object>()); policy.getProperties().put("PropertyKey", "PropertyValue"); ToscaPolicy clonedPolicy1 = new ToscaPolicy(policy); - assertEquals(0, new ToscaPolicyComparator().compare(policy, clonedPolicy1)); + assertEquals(0, new ToscaEntityComparator<ToscaPolicy>().compare(policy, clonedPolicy1)); } } diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeTest.java index 75c6b51e3..81e9c4f63 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019-2020 Nordix Foundation. + * Copyright (C) 2019-2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -46,7 +46,7 @@ public class ToscaPolicyTypeTest { tpt.setDescription("Desc"); ToscaPolicyType clonedTpt0 = new ToscaPolicyType(tpt); - assertEquals(0, new ToscaPolicyTypeComparator().compare(tpt, clonedTpt0)); + assertEquals(0, new ToscaEntityComparator<ToscaPolicyType>().compare(tpt, clonedTpt0)); tpt.setMetadata(new LinkedHashMap<>()); tpt.setProperties(new LinkedHashMap<>()); @@ -57,6 +57,6 @@ public class ToscaPolicyTypeTest { tpt.getProperties().put("Property0", tp); ToscaPolicyType clonedTpt1 = new ToscaPolicyType(tpt); - assertEquals(0, new ToscaPolicyTypeComparator().compare(tpt, clonedTpt1)); + assertEquals(0, new ToscaEntityComparator<ToscaPolicyType>().compare(tpt, clonedTpt1)); } } diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaServiceTemplateFilterTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaServiceTemplateFilterTest.java deleted file mode 100644 index ba72e621b..000000000 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaServiceTemplateFilterTest.java +++ /dev/null @@ -1,125 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2019-2020 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. - * 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.tosca.authorative.concepts; - -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.io.File; -import java.util.List; -import org.junit.Test; -import org.onap.policy.common.utils.coder.CoderException; -import org.onap.policy.common.utils.coder.StandardYamlCoder; -import org.onap.policy.models.base.PfKey; - -/** - * Test of the {@link ToscaServiceTemplateFilter} class. - * - * @author Liam Fallon (liam.fallon@est.tech) - */ -public class ToscaServiceTemplateFilterTest { - @Test - public void testNullList() { - ToscaServiceTemplateFilter filter = ToscaServiceTemplateFilter.builder().build(); - - assertThatThrownBy(() -> { - filter.filter(null); - }).hasMessageMatching("originalList is marked .*on.*ull but is null"); - } - - @Test - public void testFilterNothing() throws CoderException { - ToscaServiceTemplates serviceTemplates = new StandardYamlCoder().decode( - new File("src/test/resources/servicetemplates/TestServiceTemplates.yaml"), ToscaServiceTemplates.class); - - ToscaServiceTemplateFilter filter = ToscaServiceTemplateFilter.builder().build(); - - List<ToscaServiceTemplate> filteredList = filter.filter(serviceTemplates.getServiceTemplates()); - assertTrue(filteredList.containsAll(serviceTemplates.getServiceTemplates())); - } - - @Test - public void testFilterLatestVersion() throws CoderException { - ToscaServiceTemplates serviceTemplates = new StandardYamlCoder().decode( - new File("src/test/resources/servicetemplates/TestServiceTemplates.yaml"), ToscaServiceTemplates.class); - - ToscaServiceTemplateFilter filter = - ToscaServiceTemplateFilter.builder().version(ToscaServiceTemplateFilter.LATEST_VERSION).build(); - - List<ToscaServiceTemplate> filteredList = filter.filter(serviceTemplates.getServiceTemplates()); - assertEquals(4, filteredList.size()); - assertEquals("0.0.0", filteredList.get(0).getVersion()); - assertEquals("1.2.8", filteredList.get(1).getVersion()); - assertEquals("1.2.3", filteredList.get(2).getVersion()); - assertEquals("1.8.3", filteredList.get(3).getVersion()); - - filter = ToscaServiceTemplateFilter.builder().version("1.2.3").build(); - filteredList = filter.filter(serviceTemplates.getServiceTemplates()); - assertEquals(3, filteredList.size()); - filter = ToscaServiceTemplateFilter.builder().version(PfKey.NULL_KEY_VERSION).build(); - filteredList = filter.filter(serviceTemplates.getServiceTemplates()); - assertEquals(6, filteredList.size()); - - serviceTemplates.getServiceTemplates().get(12).setVersion("0.0.0"); - filteredList = filter.filter(serviceTemplates.getServiceTemplates()); - assertEquals(7, filteredList.size()); - assertEquals(PfKey.NULL_KEY_VERSION, filteredList.get(0).getVersion()); - assertEquals(PfKey.NULL_KEY_VERSION, filteredList.get(6).getVersion()); - } - - @Test - public void testFilterNameVersion() throws CoderException { - ToscaServiceTemplates serviceTemplates = new StandardYamlCoder().decode( - new File("src/test/resources/servicetemplates/TestServiceTemplates.yaml"), ToscaServiceTemplates.class); - - ToscaServiceTemplateFilter filter = ToscaServiceTemplateFilter.builder().name("name0").build(); - List<ToscaServiceTemplate> filteredList = filter.filter(serviceTemplates.getServiceTemplates()); - assertEquals(13, filteredList.size()); - - filter = ToscaServiceTemplateFilter.builder().name("not.found").build(); - filteredList = filter.filter(serviceTemplates.getServiceTemplates()); - assertEquals(0, filteredList.size()); - - filter = ToscaServiceTemplateFilter.builder().name(PfKey.NULL_KEY_NAME).build(); - filteredList = filter.filter(serviceTemplates.getServiceTemplates()); - assertEquals(2, filteredList.size()); - - filter = ToscaServiceTemplateFilter.builder().version(PfKey.NULL_KEY_VERSION).build(); - filteredList = filter.filter(serviceTemplates.getServiceTemplates()); - assertEquals(6, filteredList.size()); - - filter = ToscaServiceTemplateFilter.builder().name(PfKey.NULL_KEY_NAME).version(PfKey.NULL_KEY_VERSION).build(); - filteredList = filter.filter(serviceTemplates.getServiceTemplates()); - assertEquals(2, filteredList.size()); - - filter = ToscaServiceTemplateFilter.builder().name("name2").build(); - filteredList = filter.filter(serviceTemplates.getServiceTemplates()); - assertEquals(1, filteredList.size()); - - filter = ToscaServiceTemplateFilter.builder().name("name2").version("1.8.3").build(); - filteredList = filter.filter(serviceTemplates.getServiceTemplates()); - assertEquals(1, filteredList.size()); - assertEquals("name2", filteredList.get(0).getName()); - assertEquals("1.8.3", filteredList.get(0).getVersion()); - } -} diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyFilterTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaTypedEntityFilterTest.java index 01c5ff813..b83245d1f 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyFilterTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaTypedEntityFilterTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019-2020 Nordix Foundation. + * Copyright (C) 2019-2021 Nordix Foundation. * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -43,17 +43,17 @@ import org.slf4j.LoggerFactory; import org.yaml.snakeyaml.Yaml; /** - * Test of the {@link ToscaPolicyFilter} class. + * Test of the {@link ToscaTypedEntityFilter} class. * * @author Liam Fallon (liam.fallon@est.tech) */ -public class ToscaPolicyFilterTest { +public class ToscaTypedEntityFilterTest { private static final String VERSION_100 = "1.0.0"; private static final String VERSION_000 = "0.0.0"; // Logger for this class - private static final Logger LOGGER = LoggerFactory.getLogger(ToscaPolicyFilterTest.class); + private static final Logger LOGGER = LoggerFactory.getLogger(ToscaTypedEntityFilterTest.class); // @formatter:off private static final String[] policyResourceNames = { @@ -121,7 +121,7 @@ public class ToscaPolicyFilterTest { @Test public void testNullList() { - ToscaPolicyFilter filter = ToscaPolicyFilter.builder().build(); + ToscaTypedEntityFilter<ToscaPolicy> filter = ToscaTypedEntityFilter.<ToscaPolicy>builder().build(); assertThatThrownBy(() -> { filter.filter(null); @@ -130,7 +130,7 @@ public class ToscaPolicyFilterTest { @Test public void testFilterNothing() { - ToscaPolicyFilter filter = ToscaPolicyFilter.builder().build(); + ToscaTypedEntityFilter<ToscaPolicy> filter = ToscaTypedEntityFilter.<ToscaPolicy>builder().build(); List<ToscaPolicy> filteredList = filter.filter(policyList); assertTrue(filteredList.containsAll(policyList)); @@ -138,7 +138,8 @@ public class ToscaPolicyFilterTest { @Test public void testFilterLatestVersion() { - ToscaPolicyFilter filter = ToscaPolicyFilter.builder().version(ToscaPolicyFilter.LATEST_VERSION).build(); + ToscaTypedEntityFilter<ToscaPolicy> filter = + ToscaTypedEntityFilter.<ToscaPolicy>builder().version(ToscaTypedEntityFilter.LATEST_VERSION).build(); List<ToscaPolicy> filteredList = filter.filter(policyList); assertEquals(22, filteredList.size()); @@ -199,27 +200,30 @@ public class ToscaPolicyFilterTest { @Test public void testFilterNameVersion() { - ToscaPolicyFilter filter = ToscaPolicyFilter.builder().name("operational.modifyconfig").build(); + ToscaTypedEntityFilter<ToscaPolicy> filter = + ToscaTypedEntityFilter.<ToscaPolicy>builder().name("operational.modifyconfig").build(); List<ToscaPolicy> filteredList = filter.filter(policyList); assertEquals(1, filteredList.size()); - filter = ToscaPolicyFilter.builder().name("guard.frequency.scaleout").build(); + filter = ToscaTypedEntityFilter.<ToscaPolicy>builder().name("guard.frequency.scaleout").build(); filteredList = filter.filter(policyList); assertEquals(1, filteredList.size()); - filter = ToscaPolicyFilter.builder().name("guard.frequency.scalein").build(); + filter = ToscaTypedEntityFilter.<ToscaPolicy>builder().name("guard.frequency.scalein").build(); filteredList = filter.filter(policyList); assertEquals(0, filteredList.size()); - filter = ToscaPolicyFilter.builder().version(VERSION_100).build(); + filter = ToscaTypedEntityFilter.<ToscaPolicy>builder().version(VERSION_100).build(); filteredList = filter.filter(policyList); assertEquals(22, filteredList.size()); - filter = ToscaPolicyFilter.builder().name("OSDF_CASABLANCA.SubscriberPolicy_v1").version(VERSION_100).build(); + filter = ToscaTypedEntityFilter.<ToscaPolicy>builder().name("OSDF_CASABLANCA.SubscriberPolicy_v1") + .version(VERSION_100).build(); filteredList = filter.filter(policyList); assertEquals(1, filteredList.size()); - filter = ToscaPolicyFilter.builder().name("operational.modifyconfig").version(VERSION_100).build(); + filter = ToscaTypedEntityFilter.<ToscaPolicy>builder().name("operational.modifyconfig").version(VERSION_100) + .build(); filteredList = filter.filter(policyList); assertEquals(1, filteredList.size()); } @@ -227,52 +231,56 @@ public class ToscaPolicyFilterTest { @Test public void testFilterVersionPrefix() { // null pattern - ToscaPolicyFilter filter = ToscaPolicyFilter.builder().versionPrefix(null).build(); + ToscaTypedEntityFilter<ToscaPolicy> filter = + ToscaTypedEntityFilter.<ToscaPolicy>builder().versionPrefix(null).build(); List<ToscaPolicy> filteredList = filter.filter(policyList); assertEquals(22, filteredList.size()); - filter = ToscaPolicyFilter.builder().versionPrefix("1.").build(); + filter = ToscaTypedEntityFilter.<ToscaPolicy>builder().versionPrefix("1.").build(); filteredList = filter.filter(policyList); assertEquals(22, filteredList.size()); - filter = ToscaPolicyFilter.builder().versionPrefix("100.").build(); + filter = ToscaTypedEntityFilter.<ToscaPolicy>builder().versionPrefix("100.").build(); filteredList = filter.filter(policyList); assertEquals(0, filteredList.size()); } @Test public void testFilterTypeVersion() { - ToscaPolicyFilter filter = ToscaPolicyFilter.builder().type("onap.policies.controlloop.Operational").build(); + ToscaTypedEntityFilter<ToscaPolicy> filter = + ToscaTypedEntityFilter.<ToscaPolicy>builder().type("onap.policies.controlloop.Operational").build(); List<ToscaPolicy> filteredList = filter.filter(policyList); assertEquals(0, filteredList.size()); - filter = ToscaPolicyFilter.builder().type("onap.policies.controlloop.operational.common.Apex").build(); + filter = ToscaTypedEntityFilter.<ToscaPolicy>builder().type("onap.policies.controlloop.operational.common.Apex") + .build(); filteredList = filter.filter(policyList); assertEquals(0, filteredList.size()); - filter = ToscaPolicyFilter.builder().type("onap.policies.controlloop.operational.common.Drools").build(); + filter = ToscaTypedEntityFilter.<ToscaPolicy>builder() + .type("onap.policies.controlloop.operational.common.Drools").build(); filteredList = filter.filter(policyList); assertEquals(3, filteredList.size()); - filter = ToscaPolicyFilter.builder().type("onap.policies.monitoring.tcagen2").build(); + filter = ToscaTypedEntityFilter.<ToscaPolicy>builder().type("onap.policies.monitoring.tcagen2").build(); filteredList = filter.filter(policyList); assertEquals(3, filteredList.size()); - filter = ToscaPolicyFilter.builder().type("onap.policies.controlloop.NonOperational").build(); + filter = ToscaTypedEntityFilter.<ToscaPolicy>builder().type("onap.policies.controlloop.NonOperational").build(); filteredList = filter.filter(policyList); assertEquals(0, filteredList.size()); - filter = ToscaPolicyFilter.builder().typeVersion(VERSION_000).build(); + filter = ToscaTypedEntityFilter.<ToscaPolicy>builder().typeVersion(VERSION_000).build(); filteredList = filter.filter(policyList); assertEquals(0, filteredList.size()); - filter = ToscaPolicyFilter.builder().type("onap.policies.optimization.resource.HpaPolicy") + filter = ToscaTypedEntityFilter.<ToscaPolicy>builder().type("onap.policies.optimization.resource.HpaPolicy") .typeVersion(VERSION_100).build(); filteredList = filter.filter(policyList); assertEquals(2, filteredList.size()); - filter = ToscaPolicyFilter.builder().type("onap.policies.controlloop.Operational").typeVersion(VERSION_000) - .build(); + filter = ToscaTypedEntityFilter.<ToscaPolicy>builder().type("onap.policies.controlloop.Operational") + .typeVersion(VERSION_000).build(); filteredList = filter.filter(policyList); assertEquals(0, filteredList.size()); } diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderPolicyTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderPolicyTest.java index f66a8e8a5..0f9adf89a 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderPolicyTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderPolicyTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019-2020 Nordix Foundation. + * Copyright (C) 2019-2021 Nordix Foundation. * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -45,9 +45,9 @@ import org.onap.policy.models.dao.PfDaoFactory; import org.onap.policy.models.dao.impl.DefaultPfDao; import org.onap.policy.models.tosca.authorative.concepts.ToscaDataType; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; -import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyFilter; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; import org.onap.policy.models.tosca.authorative.concepts.ToscaTopologyTemplate; +import org.onap.policy.models.tosca.authorative.concepts.ToscaTypedEntityFilter; import org.yaml.snakeyaml.Yaml; /** @@ -166,7 +166,8 @@ public class AuthorativeToscaProviderPolicyTest { }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { - new AuthorativeToscaProvider().getFilteredPolicies(null, ToscaPolicyFilter.builder().build()); + new AuthorativeToscaProvider().getFilteredPolicies(null, + ToscaTypedEntityFilter.<ToscaPolicy>builder().build()); }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { @@ -178,7 +179,8 @@ public class AuthorativeToscaProviderPolicyTest { }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { - new AuthorativeToscaProvider().getFilteredPolicyList(null, ToscaPolicyFilter.builder().build()); + new AuthorativeToscaProvider().getFilteredPolicyList(null, + ToscaTypedEntityFilter.<ToscaPolicy>builder().build()); }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { @@ -203,8 +205,8 @@ public class AuthorativeToscaProviderPolicyTest { assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, createdPolicy)); assertEquals(beforePolicy.getType(), createdPolicy.getType()); - ToscaServiceTemplate gotServiceTemplate = - new AuthorativeToscaProvider().getFilteredPolicies(pfDao, ToscaPolicyFilter.builder().build()); + ToscaServiceTemplate gotServiceTemplate = new AuthorativeToscaProvider().getFilteredPolicies(pfDao, + ToscaTypedEntityFilter.<ToscaPolicy>builder().build()); ToscaPolicy gotPolicy = gotServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName()); @@ -212,14 +214,14 @@ public class AuthorativeToscaProviderPolicyTest { assertEquals(beforePolicy.getType(), gotPolicy.getType()); gotServiceTemplate = new AuthorativeToscaProvider().getFilteredPolicies(pfDao, - ToscaPolicyFilter.builder().name(policyKey.getName()).build()); + ToscaTypedEntityFilter.<ToscaPolicy>builder().name(policyKey.getName()).build()); gotPolicy = gotServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName()); assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicy)); assertEquals(beforePolicy.getType(), gotPolicy.getType()); gotServiceTemplate = new AuthorativeToscaProvider().getFilteredPolicies(pfDao, - ToscaPolicyFilter.builder().name(policyKey.getName()).version(VERSION_100).build()); + ToscaTypedEntityFilter.<ToscaPolicy>builder().name(policyKey.getName()).version(VERSION_100).build()); gotPolicy = gotServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName()); assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicy)); @@ -229,18 +231,18 @@ public class AuthorativeToscaProviderPolicyTest { assertEquals(1, gotPolicyList.size()); assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicyList.get(0))); - gotPolicyList = - new AuthorativeToscaProvider().getFilteredPolicyList(pfDao, ToscaPolicyFilter.builder().build()); + gotPolicyList = new AuthorativeToscaProvider().getFilteredPolicyList(pfDao, + ToscaTypedEntityFilter.<ToscaPolicy>builder().build()); assertEquals(1, gotPolicyList.size()); assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicyList.get(0))); gotPolicyList = new AuthorativeToscaProvider().getFilteredPolicyList(pfDao, - ToscaPolicyFilter.builder().name(policyKey.getName()).build()); + ToscaTypedEntityFilter.<ToscaPolicy>builder().name(policyKey.getName()).build()); assertEquals(1, gotPolicyList.size()); assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicyList.get(0))); gotPolicyList = new AuthorativeToscaProvider().getFilteredPolicyList(pfDao, - ToscaPolicyFilter.builder().name(policyKey.getName()).version(VERSION_100).build()); + ToscaTypedEntityFilter.<ToscaPolicy>builder().name(policyKey.getName()).version(VERSION_100).build()); assertEquals(1, gotPolicyList.size()); assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicyList.get(0))); } diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderPolicyTypeTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderPolicyTypeTest.java index 0e1164598..088e8e847 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderPolicyTypeTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderPolicyTypeTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019-2020 Nordix Foundation. + * Copyright (C) 2019-2021 Nordix Foundation. * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -43,16 +43,14 @@ import org.onap.policy.models.dao.DaoParameters; import org.onap.policy.models.dao.PfDao; import org.onap.policy.models.dao.PfDaoFactory; import org.onap.policy.models.dao.impl.DefaultPfDao; +import org.onap.policy.models.tosca.authorative.concepts.ToscaEntityFilter; 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.authorative.concepts.ToscaTopologyTemplate; import org.yaml.snakeyaml.Yaml; /** * Test of the {@link AuthorativeToscaProvider} class. - * - * @author Liam Fallon (liam.fallon@est.tech) */ public class AuthorativeToscaProviderPolicyTypeTest { private static final String VERSION = "version"; @@ -131,7 +129,7 @@ public class AuthorativeToscaProviderPolicyTypeTest { assertNotNull(toscaServiceTemplate); ToscaServiceTemplate createdServiceTemplate = - new AuthorativeToscaProvider().createPolicyTypes(pfDao, toscaServiceTemplate); + new AuthorativeToscaProvider().createPolicyTypes(pfDao, toscaServiceTemplate); PfConceptKey policyTypeKey = new PfConceptKey(POLICY_NO_VERSION_VERSION1); @@ -140,15 +138,15 @@ public class AuthorativeToscaProviderPolicyTypeTest { assertEquals(true, beforePolicyType.getName().equals(createdPolicyType.getName())); assertEquals(0, ObjectUtils.compare(beforePolicyType.getDescription(), createdPolicyType.getDescription())); - ToscaServiceTemplate gotServiceTemplate = - new AuthorativeToscaProvider().getPolicyTypes(pfDao, policyTypeKey.getName(), policyTypeKey.getVersion()); + ToscaServiceTemplate gotServiceTemplate = new AuthorativeToscaProvider().getPolicyTypes(pfDao, + policyTypeKey.getName(), policyTypeKey.getVersion()); ToscaPolicyType gotPolicyType = gotServiceTemplate.getPolicyTypes().get(policyTypeKey.getName()); assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName())); assertEquals(0, ObjectUtils.compare(beforePolicyType.getDescription(), createdPolicyType.getDescription())); List<ToscaPolicyType> gotPolicyTypeList = - new AuthorativeToscaProvider().getPolicyTypeList(pfDao, POLICY_NO_VERSION, VERSION_001); + new AuthorativeToscaProvider().getPolicyTypeList(pfDao, POLICY_NO_VERSION, VERSION_001); assertEquals(2, gotPolicyTypeList.size()); assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName())); @@ -164,9 +162,8 @@ public class AuthorativeToscaProviderPolicyTypeTest { assertEquals(2, gotPolicyTypeList.size()); assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName())); - assertThatThrownBy( - () -> new AuthorativeToscaProvider().getPolicyTypeList(new DefaultPfDao(), POLICY_NO_VERSION, VERSION_001)) - .hasMessageContaining("Policy Framework DAO has not been initialized"); + assertThatThrownBy(() -> new AuthorativeToscaProvider().getPolicyTypeList(new DefaultPfDao(), POLICY_NO_VERSION, + VERSION_001)).hasMessageContaining("Policy Framework DAO has not been initialized"); assertTrue(new AuthorativeToscaProvider().getPolicyTypeList(pfDao, "i.dont.Exist", VERSION_001).isEmpty()); } @@ -178,7 +175,8 @@ public class AuthorativeToscaProviderPolicyTypeTest { }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { - new AuthorativeToscaProvider().getFilteredPolicyTypes(null, ToscaPolicyTypeFilter.builder().build()); + new AuthorativeToscaProvider().getFilteredPolicyTypes(null, + ToscaEntityFilter.<ToscaPolicyType>builder().build()); }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { @@ -190,7 +188,8 @@ public class AuthorativeToscaProviderPolicyTypeTest { }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { - new AuthorativeToscaProvider().getFilteredPolicyTypeList(null, ToscaPolicyTypeFilter.builder().build()); + new AuthorativeToscaProvider().getFilteredPolicyTypeList(null, + ToscaEntityFilter.<ToscaPolicyType>builder().build()); }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { @@ -198,17 +197,17 @@ public class AuthorativeToscaProviderPolicyTypeTest { }).hasMessageMatching("^filter is marked .*on.*ull but is null$"); assertThatThrownBy(() -> new AuthorativeToscaProvider().getFilteredPolicyTypeList(new DefaultPfDao(), - ToscaPolicyTypeFilter.builder().name("i.dont.Exist").build())) - .hasMessageContaining("Policy Framework DAO has not been initialized"); + ToscaEntityFilter.<ToscaPolicyType>builder().name("i.dont.Exist").build())) + .hasMessageContaining("Policy Framework DAO has not been initialized"); - assertTrue(new AuthorativeToscaProvider() - .getFilteredPolicyTypeList(pfDao, ToscaPolicyTypeFilter.builder().name("i.dont.Exist").build()).isEmpty()); + assertTrue(new AuthorativeToscaProvider().getFilteredPolicyTypeList(pfDao, + ToscaEntityFilter.<ToscaPolicyType>builder().name("i.dont.Exist").build()).isEmpty()); ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class); assertNotNull(toscaServiceTemplate); ToscaServiceTemplate createdServiceTemplate = - new AuthorativeToscaProvider().createPolicyTypes(pfDao, toscaServiceTemplate); + new AuthorativeToscaProvider().createPolicyTypes(pfDao, toscaServiceTemplate); PfConceptKey policyTypeKey = new PfConceptKey(POLICY_NO_VERSION_VERSION1); @@ -217,49 +216,49 @@ public class AuthorativeToscaProviderPolicyTypeTest { assertEquals(true, beforePolicyType.getName().equals(createdPolicyType.getName())); assertEquals(0, ObjectUtils.compare(beforePolicyType.getDescription(), createdPolicyType.getDescription())); - ToscaServiceTemplate gotServiceTemplate = - new AuthorativeToscaProvider().getFilteredPolicyTypes(pfDao, ToscaPolicyTypeFilter.builder().build()); + ToscaServiceTemplate gotServiceTemplate = new AuthorativeToscaProvider().getFilteredPolicyTypes(pfDao, + ToscaEntityFilter.<ToscaPolicyType>builder().build()); ToscaPolicyType gotPolicyType = gotServiceTemplate.getPolicyTypes().get(policyTypeKey.getName()); assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName())); assertEquals(0, ObjectUtils.compare(beforePolicyType.getDescription(), gotPolicyType.getDescription())); gotServiceTemplate = new AuthorativeToscaProvider().getFilteredPolicyTypes(pfDao, - ToscaPolicyTypeFilter.builder().name(policyTypeKey.getName()).build()); + ToscaEntityFilter.<ToscaPolicyType>builder().name(policyTypeKey.getName()).build()); gotPolicyType = gotServiceTemplate.getPolicyTypes().get(policyTypeKey.getName()); assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName())); assertEquals(0, ObjectUtils.compare(beforePolicyType.getDescription(), gotPolicyType.getDescription())); - gotServiceTemplate = new AuthorativeToscaProvider().getFilteredPolicyTypes(pfDao, - ToscaPolicyTypeFilter.builder().name(policyTypeKey.getName()).version(VERSION_001).build()); + gotServiceTemplate = new AuthorativeToscaProvider().getFilteredPolicyTypes(pfDao, ToscaEntityFilter + .<ToscaPolicyType>builder().name(policyTypeKey.getName()).version(VERSION_001).build()); gotPolicyType = gotServiceTemplate.getPolicyTypes().get(policyTypeKey.getName()); assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName())); assertEquals(0, ObjectUtils.compare(beforePolicyType.getDescription(), gotPolicyType.getDescription())); List<ToscaPolicyType> gotPolicyTypeList = - new AuthorativeToscaProvider().getPolicyTypeList(pfDao, POLICY_NO_VERSION, VERSION_001); + new AuthorativeToscaProvider().getPolicyTypeList(pfDao, POLICY_NO_VERSION, VERSION_001); assertEquals(2, gotPolicyTypeList.size()); assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName())); - gotPolicyTypeList = - new AuthorativeToscaProvider().getFilteredPolicyTypeList(pfDao, ToscaPolicyTypeFilter.builder().build()); + gotPolicyTypeList = new AuthorativeToscaProvider().getFilteredPolicyTypeList(pfDao, + ToscaEntityFilter.<ToscaPolicyType>builder().build()); assertEquals(2, gotPolicyTypeList.size()); assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName())); gotPolicyTypeList = new AuthorativeToscaProvider().getFilteredPolicyTypeList(pfDao, - ToscaPolicyTypeFilter.builder().name(policyTypeKey.getName()).build()); + ToscaEntityFilter.<ToscaPolicyType>builder().name(policyTypeKey.getName()).build()); assertEquals(1, gotPolicyTypeList.size()); assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName())); - gotPolicyTypeList = new AuthorativeToscaProvider().getFilteredPolicyTypeList(pfDao, - ToscaPolicyTypeFilter.builder().name(policyTypeKey.getName()).version(VERSION_001).build()); + gotPolicyTypeList = new AuthorativeToscaProvider().getFilteredPolicyTypeList(pfDao, ToscaEntityFilter + .<ToscaPolicyType>builder().name(policyTypeKey.getName()).version(VERSION_001).build()); assertEquals(1, gotPolicyTypeList.size()); assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName())); gotPolicyTypeList = new AuthorativeToscaProvider().getFilteredPolicyTypeList(pfDao, - ToscaPolicyTypeFilter.builder().version("1.0.0").build()); + ToscaEntityFilter.<ToscaPolicyType>builder().version("1.0.0").build()); assertEquals(1, gotPolicyTypeList.size()); assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName())); } @@ -292,7 +291,7 @@ public class AuthorativeToscaProviderPolicyTypeTest { assertNotNull(toscaServiceTemplate); ToscaServiceTemplate createdServiceTemplate = - new AuthorativeToscaProvider().createPolicyTypes(pfDao, toscaServiceTemplate); + new AuthorativeToscaProvider().createPolicyTypes(pfDao, toscaServiceTemplate); PfConceptKey policyTypeKey = new PfConceptKey(POLICY_NO_VERSION_VERSION1); @@ -324,7 +323,7 @@ public class AuthorativeToscaProviderPolicyTypeTest { assertNotNull(toscaServiceTemplate); ToscaServiceTemplate createdServiceTemplate = - new AuthorativeToscaProvider().createPolicyTypes(pfDao, toscaServiceTemplate); + new AuthorativeToscaProvider().createPolicyTypes(pfDao, toscaServiceTemplate); PfConceptKey policyTypeKey = new PfConceptKey(POLICY_NO_VERSION_VERSION1); @@ -334,7 +333,7 @@ public class AuthorativeToscaProviderPolicyTypeTest { assertEquals(0, ObjectUtils.compare(beforePolicyType.getDescription(), createdPolicyType.getDescription())); ToscaServiceTemplate updatedServiceTemplate = - new AuthorativeToscaProvider().updatePolicyTypes(pfDao, toscaServiceTemplate); + new AuthorativeToscaProvider().updatePolicyTypes(pfDao, toscaServiceTemplate); ToscaPolicyType updatedPolicy = updatedServiceTemplate.getPolicyTypes().get(policyTypeKey.getName()); assertEquals(true, beforePolicyType.getName().equals(updatedPolicy.getName())); @@ -375,7 +374,7 @@ public class AuthorativeToscaProviderPolicyTypeTest { assertNotNull(toscaServiceTemplate); ToscaServiceTemplate createdServiceTemplate = - new AuthorativeToscaProvider().createPolicyTypes(pfDao, toscaServiceTemplate); + new AuthorativeToscaProvider().createPolicyTypes(pfDao, toscaServiceTemplate); PfConceptKey policyTypeKey = new PfConceptKey(POLICY_NO_VERSION_VERSION1); @@ -384,8 +383,8 @@ public class AuthorativeToscaProviderPolicyTypeTest { assertEquals(true, beforePolicyType.getName().equals(createdPolicyType.getName())); assertEquals(0, ObjectUtils.compare(beforePolicyType.getDescription(), createdPolicyType.getDescription())); - ToscaServiceTemplate deletedServiceTemplate = - new AuthorativeToscaProvider().deletePolicyType(pfDao, policyTypeKey.getName(), policyTypeKey.getVersion()); + ToscaServiceTemplate deletedServiceTemplate = new AuthorativeToscaProvider().deletePolicyType(pfDao, + policyTypeKey.getName(), policyTypeKey.getVersion()); ToscaPolicyType deletedPolicy = deletedServiceTemplate.getPolicyTypes().get(policyTypeKey.getName()); assertEquals(true, beforePolicyType.getName().equals(deletedPolicy.getName())); @@ -422,6 +421,6 @@ public class AuthorativeToscaProviderPolicyTypeTest { @Test public void testNullParameters() throws Exception { assertThatThrownBy(() -> new AuthorativeToscaProvider().getPolicyTypeList(null, null, null)) - .hasMessageMatching("^dao is marked .*on.*ull but is null$"); + .hasMessageMatching("^dao is marked .*on.*ull but is null$"); } } |