diff options
46 files changed, 1175 insertions, 548 deletions
diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfObjectFilter.java b/models-base/src/main/java/org/onap/policy/models/base/PfObjectFilter.java index 10ce4ea60..35319b4fd 100644 --- a/models-base/src/main/java/org/onap/policy/models/base/PfObjectFilter.java +++ b/models-base/src/main/java/org/onap/policy/models/base/PfObjectFilter.java @@ -25,8 +25,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -import lombok.NonNull; - /** * Interface for filtering a list of concepts. * diff --git a/models-dao/src/main/java/org/onap/policy/models/dao/impl/DefaultPfDao.java b/models-dao/src/main/java/org/onap/policy/models/dao/impl/DefaultPfDao.java index 182017693..c44d05fe2 100644 --- a/models-dao/src/main/java/org/onap/policy/models/dao/impl/DefaultPfDao.java +++ b/models-dao/src/main/java/org/onap/policy/models/dao/impl/DefaultPfDao.java @@ -173,7 +173,7 @@ public class DefaultPfDao implements PfDao { mg.getTransaction().begin(); mg.createQuery(setQueryTable(DELETE_BY_CONCEPT_KEY, someClass), someClass) .setParameter(NAME, key.getName()) - .setParameter("version", key.getVersion()) + .setParameter(VERSION, key.getVersion()) .executeUpdate(); mg.getTransaction().commit(); // @formatter:on @@ -250,7 +250,7 @@ public class DefaultPfDao implements PfDao { for (final PfConceptKey key : keys) { deletedCount += mg.createQuery(setQueryTable(DELETE_BY_CONCEPT_KEY, someClass), someClass) .setParameter(NAME, key.getName()) - .setParameter("version", key.getVersion()) + .setParameter(VERSION, key.getVersion()) .executeUpdate(); } mg.getTransaction().commit(); diff --git a/models-pdp/pom.xml b/models-pdp/pom.xml index 029c76b8f..8eb7231f0 100644 --- a/models-pdp/pom.xml +++ b/models-pdp/pom.xml @@ -45,10 +45,6 @@ <version>${project.version}</version> </dependency> <dependency> - <groupId>org.mariadb.jdbc</groupId> - <artifactId>mariadb-java-client</artifactId> - </dependency> - <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> <scope>test</scope> diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpGroup.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpGroup.java index d0fc216c2..1e77c099d 100644 --- a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpGroup.java +++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpGroup.java @@ -238,16 +238,7 @@ public class JpaPdpGroup extends PfConcept implements PfAuthorative<PdpGroup> { } if (properties != null) { - for (Entry<String, String> propertyEntry : properties.entrySet()) { - if (!ParameterValidationUtils.validateStringParameter(propertyEntry.getKey())) { - result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "a property key may not be null or blank")); - } - if (!ParameterValidationUtils.validateStringParameter(propertyEntry.getValue())) { - result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "a property value may not be null or blank")); - } - } + result = validateProperties(result); } if (pdpSubGroups == null) { @@ -262,6 +253,29 @@ public class JpaPdpGroup extends PfConcept implements PfAuthorative<PdpGroup> { return result; } + /** + * Validate the properties. + * + * @param resultIn the incoming validation results so far + * @return the revalidation results including the property validation results + */ + private PfValidationResult validateProperties(PfValidationResult resultIn) { + PfValidationResult result = resultIn; + + for (Entry<String, String> propertyEntry : properties.entrySet()) { + if (!ParameterValidationUtils.validateStringParameter(propertyEntry.getKey())) { + result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, + "a property key may not be null or blank")); + } + if (!ParameterValidationUtils.validateStringParameter(propertyEntry.getValue())) { + result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, + "a property value may not be null or blank")); + } + } + + return result; + } + @Override public int compareTo(final PfConcept otherConcept) { if (otherConcept == null) { diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/ModelsTest.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/ModelsTest.java index d22642d98..541e00b02 100644 --- a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/ModelsTest.java +++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/ModelsTest.java @@ -36,11 +36,12 @@ import org.onap.policy.common.utils.validation.ToStringTester; * @author Ram Krishna Verma (ram.krishna.verma@est.tech) */ public class ModelsTest { + private static final String POJO_PACKAGE = "org.onap.policy.models.pdp.concepts"; @Test public void testPdpModels() { final Validator validator = ValidatorBuilder.create().with(new ToStringTester()).with(new SetterTester()) .with(new GetterTester()).build(); - validator.validate(ModelsTest.class.getPackage().getName(), new FilterPackageInfo()); + validator.validate(POJO_PACKAGE, new FilterPackageInfo()); } } diff --git a/models-provider/pom.xml b/models-provider/pom.xml index fb0e302dd..41a5a2cfe 100644 --- a/models-provider/pom.xml +++ b/models-provider/pom.xml @@ -69,12 +69,6 @@ </dependency> <dependency> - <groupId>org.mariadb.jdbc</groupId> - <artifactId>mariadb-java-client</artifactId> - <scope>test</scope> - </dependency> - - <dependency> <groupId>org.mockito</groupId> <artifactId>mockito-all</artifactId> <scope>test</scope> 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 cf40a57f9..b186e2b36 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 @@ -361,9 +361,10 @@ public interface PolicyModelsProvider extends AutoCloseable { * @param pdpGroupVersion the version of the PDP group containing the PDP that the statistics are for * @param pdpType the PDP type of the subgroup containing the PDP that the statistics are for * @param pdpInstanceId the instance ID of the PDP to update statistics for + * @param pdpStatistics the PDP statistics * @throws PfModelException on errors updating statistics */ public void updatePdpStatistics(@NonNull final String pdpGroupName, @NonNull final String pdpGroupVersion, @NonNull final String pdpType, @NonNull final String pdpInstanceId, - @NonNull final PdpStatistics pdppStatistics) throws PfModelException; + @NonNull final PdpStatistics pdpStatistics) throws PfModelException; } 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 2fe52e935..cc70df903 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 @@ -348,10 +348,10 @@ public class DatabasePolicyModelsProviderImpl implements PolicyModelsProvider { @Override public void updatePdpStatistics(@NonNull final String pdpGroupName, @NonNull final String pdpGroupVersion, @NonNull final String pdpType, @NonNull final String pdpInstanceId, - @NonNull final PdpStatistics pdppStatistics) throws PfModelException { + @NonNull final PdpStatistics pdpStatistics) throws PfModelException { assertInitilized(); new PdpProvider().updatePdpStatistics(pfDao, pdpGroupName, pdpGroupVersion, pdpType, pdpInstanceId, - pdppStatistics); + pdpStatistics); } /** 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 0bf529730..90545f389 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 @@ -27,7 +27,6 @@ import java.util.List; import java.util.Map; import javax.ws.rs.core.Response; -import lombok.NonNull; import org.onap.policy.common.utils.coder.StandardCoder; import org.onap.policy.common.utils.resources.ResourceUtils; @@ -61,7 +60,7 @@ public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider { * * @param parameters the parameters for the provider */ - public DummyPolicyModelsProviderImpl(@NonNull final PolicyModelsProviderParameters parameters) {} + public DummyPolicyModelsProviderImpl(final PolicyModelsProviderParameters parameters) {} @Override public void init() throws PfModelException { @@ -84,29 +83,29 @@ public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider { } @Override - public ToscaServiceTemplate getFilteredPolicyTypes(@NonNull ToscaPolicyTypeFilter filter) throws PfModelException { - return null; + public ToscaServiceTemplate getFilteredPolicyTypes(ToscaPolicyTypeFilter filter) throws PfModelException { + return getDummyResponse("dummyimpl/DummyToscaPolicyTypeGetResponse.json"); } @Override - public List<ToscaPolicyType> getFilteredPolicyTypeList(@NonNull ToscaPolicyTypeFilter filter) { + public List<ToscaPolicyType> getFilteredPolicyTypeList(ToscaPolicyTypeFilter filter) { return new ArrayList<>(); } @Override - public ToscaServiceTemplate createPolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate) + public ToscaServiceTemplate createPolicyTypes(final ToscaServiceTemplate serviceTemplate) throws PfModelException { return serviceTemplate; } @Override - public ToscaServiceTemplate updatePolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate) + public ToscaServiceTemplate updatePolicyTypes(final ToscaServiceTemplate serviceTemplate) throws PfModelException { return serviceTemplate; } @Override - public ToscaServiceTemplate deletePolicyType(@NonNull final String name, @NonNull final String version) + public ToscaServiceTemplate deletePolicyType(final String name, final String version) throws PfModelException { return getDummyResponse("dummyimpl/DummyToscaPolicyTypeDeleteResponse.json"); } @@ -122,75 +121,75 @@ public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider { } @Override - public ToscaServiceTemplate getFilteredPolicies(@NonNull ToscaPolicyFilter filter) throws PfModelException { - return null; + public ToscaServiceTemplate getFilteredPolicies(ToscaPolicyFilter filter) throws PfModelException { + return getDummyResponse("dummyimpl/DummyToscaPolicyGetResponse.json"); } @Override - public List<ToscaPolicy> getFilteredPolicyList(@NonNull ToscaPolicyFilter filter) throws PfModelException { + public List<ToscaPolicy> getFilteredPolicyList(ToscaPolicyFilter filter) throws PfModelException { return new ArrayList<>(); } @Override - public ToscaServiceTemplate createPolicies(@NonNull final ToscaServiceTemplate serviceTemplate) + public ToscaServiceTemplate createPolicies(final ToscaServiceTemplate serviceTemplate) throws PfModelException { return serviceTemplate; } @Override - public ToscaServiceTemplate updatePolicies(@NonNull final ToscaServiceTemplate serviceTemplate) + public ToscaServiceTemplate updatePolicies(final ToscaServiceTemplate serviceTemplate) throws PfModelException { return serviceTemplate; } @Override - public ToscaServiceTemplate deletePolicy(@NonNull final String name, @NonNull final String version) + public ToscaServiceTemplate deletePolicy(final String name, final String version) throws PfModelException { return getDummyResponse("dummyimpl/DummyToscaPolicyDeleteResponse.json"); } @Override - public LegacyOperationalPolicy getOperationalPolicy(@NonNull final String policyId) throws PfModelException { + public LegacyOperationalPolicy getOperationalPolicy(final String policyId) throws PfModelException { return new LegacyOperationalPolicy(); } @Override public LegacyOperationalPolicy createOperationalPolicy( - @NonNull final LegacyOperationalPolicy legacyOperationalPolicy) throws PfModelException { + final LegacyOperationalPolicy legacyOperationalPolicy) throws PfModelException { return legacyOperationalPolicy; } @Override public LegacyOperationalPolicy updateOperationalPolicy( - @NonNull final LegacyOperationalPolicy legacyOperationalPolicy) throws PfModelException { + final LegacyOperationalPolicy legacyOperationalPolicy) throws PfModelException { return legacyOperationalPolicy; } @Override - public LegacyOperationalPolicy deleteOperationalPolicy(@NonNull final String policyId) throws PfModelException { + public LegacyOperationalPolicy deleteOperationalPolicy(final String policyId) throws PfModelException { return new LegacyOperationalPolicy(); } @Override - public Map<String, LegacyGuardPolicyOutput> getGuardPolicy(@NonNull final String policyId) throws PfModelException { + public Map<String, LegacyGuardPolicyOutput> getGuardPolicy(final String policyId) throws PfModelException { return new HashMap<>(); } @Override public Map<String, LegacyGuardPolicyOutput> createGuardPolicy( - @NonNull final LegacyGuardPolicyInput legacyGuardPolicy) throws PfModelException { + final LegacyGuardPolicyInput legacyGuardPolicy) throws PfModelException { return new HashMap<>(); } @Override public Map<String, LegacyGuardPolicyOutput> updateGuardPolicy( - @NonNull final LegacyGuardPolicyInput legacyGuardPolicy) throws PfModelException { + final LegacyGuardPolicyInput legacyGuardPolicy) throws PfModelException { return new HashMap<>(); } @Override - public Map<String, LegacyGuardPolicyOutput> deleteGuardPolicy(@NonNull final String policyId) + public Map<String, LegacyGuardPolicyOutput> deleteGuardPolicy(final String policyId) throws PfModelException { return new HashMap<>(); } @@ -201,34 +200,34 @@ public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider { } @Override - public List<PdpGroup> getFilteredPdpGroups(@NonNull PdpGroupFilter filter) throws PfModelException { + public List<PdpGroup> getFilteredPdpGroups(PdpGroupFilter filter) throws PfModelException { return new ArrayList<>(); } @Override - public List<PdpGroup> createPdpGroups(@NonNull final List<PdpGroup> pdpGroups) throws PfModelException { + public List<PdpGroup> createPdpGroups(final List<PdpGroup> pdpGroups) throws PfModelException { return new ArrayList<>(); } @Override - public List<PdpGroup> updatePdpGroups(@NonNull final List<PdpGroup> pdpGroups) throws PfModelException { + public List<PdpGroup> updatePdpGroups(final List<PdpGroup> pdpGroups) throws PfModelException { return new ArrayList<>(); } @Override - public void updatePdpSubGroup(@NonNull final String pdpGroupName, @NonNull final String pdpGroupVersion, - @NonNull final PdpSubGroup pdpSubGroup) throws PfModelException { + public void updatePdpSubGroup(final String pdpGroupName, final String pdpGroupVersion, + final PdpSubGroup pdpSubGroup) throws PfModelException { // Not implemented } @Override - public void updatePdp(@NonNull String pdpGroupName, @NonNull String pdpGroupVersion, - @NonNull String pdpSubGroup, @NonNull Pdp pdp) throws PfModelException { + public void updatePdp(String pdpGroupName, String pdpGroupVersion, + String pdpSubGroup, Pdp pdp) throws PfModelException { // Not implemented } @Override - public PdpGroup deletePdpGroup(@NonNull final String name, @NonNull final String version) throws PfModelException { + public PdpGroup deletePdpGroup(final String name, final String version) throws PfModelException { return null; } @@ -238,9 +237,9 @@ public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider { } @Override - public void updatePdpStatistics(@NonNull final String pdpGroupName, @NonNull final String pdpGroupVersion, - @NonNull final String pdpType, @NonNull final String pdpInstanceId, - @NonNull final PdpStatistics pdppStatistics) throws PfModelException { + public void updatePdpStatistics(final String pdpGroupName, final String pdpGroupVersion, + final String pdpType, final String pdpInstanceId, + final PdpStatistics pdppStatistics) throws PfModelException { // Not implemented } @@ -250,7 +249,7 @@ public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider { * @param fileName the file name containing the dummy response * @return the ToscaServiceTemplate with the dummy response */ - protected ToscaServiceTemplate getDummyResponse(@NonNull final String fileName) { + protected ToscaServiceTemplate getDummyResponse(final String fileName) { StandardCoder standardCoder = new StandardCoder(); ToscaServiceTemplate serviceTemplate; 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 38a5ae114..99358c4c6 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 @@ -27,13 +27,23 @@ import static org.junit.Assert.fail; import java.util.ArrayList; import java.util.Base64; +import java.util.List; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; +import org.onap.policy.models.pdp.concepts.Pdp; +import org.onap.policy.models.pdp.concepts.PdpGroup; +import org.onap.policy.models.pdp.concepts.PdpGroupFilter; +import org.onap.policy.models.pdp.concepts.PdpStatistics; +import org.onap.policy.models.pdp.concepts.PdpSubGroup; +import org.onap.policy.models.pdp.enums.PdpHealthStatus; +import org.onap.policy.models.pdp.enums.PdpState; 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.ToscaPolicyFilter; +import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeFilter; +import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyInput; import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy; @@ -65,6 +75,10 @@ public class DatabasePolicyModelsProviderTest { @Test public void testInitAndClose() throws Exception { + assertThatThrownBy(() -> { + new DatabasePolicyModelsProviderImpl(null); + }).hasMessage("parameters is marked @NonNull but is null"); + PolicyModelsProvider databaseProvider = new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters); @@ -101,6 +115,17 @@ public class DatabasePolicyModelsProviderTest { fail("test shold not throw an exception here"); } + assertThatThrownBy(() -> { + databaseProvider.init(); + databaseProvider.init(); + }).hasMessage("provider is already initialized"); + + try { + databaseProvider.close(); + } catch (Exception pfme) { + fail("test shold not throw an exception here"); + } + try { databaseProvider.close(); } catch (Exception pfme) { @@ -115,23 +140,18 @@ public class DatabasePolicyModelsProviderTest { }).hasMessage("could not close connection to database with URL \"jdbc:h2:mem:testdb\""); } - @Ignore @Test public void testProviderMethodsNull() throws Exception { PolicyModelsProvider databaseProvider = new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters); assertThatThrownBy(() -> { - databaseProvider.getPolicyTypes(null, null); - }).hasMessage("name is marked @NonNull but is null"); + databaseProvider.getFilteredPolicyTypes(null); + }).hasMessage("filter is marked @NonNull but is null"); assertThatThrownBy(() -> { - databaseProvider.getPolicyTypes("aaa", null); - }).hasMessage("version is marked @NonNull but is null"); - - assertThatThrownBy(() -> { - databaseProvider.getPolicyTypes(null, "aaa"); - }).hasMessage("name is marked @NonNull but is null"); + databaseProvider.getFilteredPolicyTypeList(null); + }).hasMessage("filter is marked @NonNull but is null"); assertThatThrownBy(() -> { databaseProvider.createPolicyTypes(null); @@ -154,16 +174,12 @@ public class DatabasePolicyModelsProviderTest { }).hasMessage("name is marked @NonNull but is null"); assertThatThrownBy(() -> { - databaseProvider.getPolicies(null, null); - }).hasMessage("name is marked @NonNull but is null"); + databaseProvider.getFilteredPolicies(null); + }).hasMessage("filter is marked @NonNull but is null"); assertThatThrownBy(() -> { - databaseProvider.getPolicies(null, "aaa"); - }).hasMessage("name is marked @NonNull but is null"); - - assertThatThrownBy(() -> { - databaseProvider.getPolicies("aaa", null); - }).hasMessage("version is marked @NonNull but is null"); + databaseProvider.getFilteredPolicyList(null); + }).hasMessage("filter is marked @NonNull but is null"); assertThatThrownBy(() -> { databaseProvider.createPolicies(null); @@ -218,6 +234,10 @@ public class DatabasePolicyModelsProviderTest { }).hasMessage("policyId is marked @NonNull but is null"); assertThatThrownBy(() -> { + databaseProvider.getFilteredPdpGroups(null); + }).hasMessage("filter is marked @NonNull but is null"); + + assertThatThrownBy(() -> { databaseProvider.createPdpGroups(null); }).hasMessage("pdpGroups is marked @NonNull but is null"); @@ -226,11 +246,230 @@ public class DatabasePolicyModelsProviderTest { }).hasMessage("pdpGroups is marked @NonNull but is null"); assertThatThrownBy(() -> { + databaseProvider.updatePdpSubGroup(null, null, null); + }).hasMessage("pdpGroupName is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + databaseProvider.updatePdpSubGroup(null, null, new PdpSubGroup()); + }).hasMessage("pdpGroupName is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + databaseProvider.updatePdpSubGroup(null, "version", null); + }).hasMessage("pdpGroupName is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + databaseProvider.updatePdpSubGroup(null, "version", new PdpSubGroup()); + }).hasMessage("pdpGroupName is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + databaseProvider.updatePdpSubGroup("name", null, null); + }).hasMessage("pdpGroupVersion is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + databaseProvider.updatePdpSubGroup("name", null, new PdpSubGroup()); + }).hasMessage("pdpGroupVersion is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + databaseProvider.updatePdpSubGroup("name", "version", null); + }).hasMessage("pdpSubGroup is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + databaseProvider.updatePdp(null, null, null, null); + }).hasMessage("pdpGroupName is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + databaseProvider.updatePdp(null, null, null, new Pdp()); + }).hasMessage("pdpGroupName is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + databaseProvider.updatePdp(null, null, "sub", null); + }).hasMessage("pdpGroupName is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + databaseProvider.updatePdp(null, null, "sub", new Pdp()); + }).hasMessage("pdpGroupName is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + databaseProvider.updatePdp(null, "version", null, null); + }).hasMessage("pdpGroupName is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + databaseProvider.updatePdp(null, "version", null, new Pdp()); + }).hasMessage("pdpGroupName is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + databaseProvider.updatePdp(null, "version", "sub", null); + }).hasMessage("pdpGroupName is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + databaseProvider.updatePdp(null, "version", "sub", new Pdp()); + }).hasMessage("pdpGroupName is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + databaseProvider.updatePdp("name", null, null, null); + }).hasMessage("pdpGroupVersion is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + databaseProvider.updatePdp("name", null, null, new Pdp()); + }).hasMessage("pdpGroupVersion is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + databaseProvider.updatePdp("name", null, "sub", null); + }).hasMessage("pdpGroupVersion is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + databaseProvider.updatePdp("name", null, "sub", new Pdp()); + }).hasMessage("pdpGroupVersion is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + databaseProvider.updatePdp("name", "version", null, null); + }).hasMessage("pdpSubGroup is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + databaseProvider.updatePdp("name", "version", null, new Pdp()); + }).hasMessage("pdpSubGroup is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + databaseProvider.updatePdp("name", "version", "sub", null); + }).hasMessage("pdp is marked @NonNull but is null"); + + assertThatThrownBy(() -> { databaseProvider.deletePdpGroup(null, null); }).hasMessage("name is marked @NonNull but is null"); - databaseProvider.close(); + assertThatThrownBy(() -> { + databaseProvider.deletePdpGroup(null, "version"); + }).hasMessage("name is marked @NonNull but is null"); + assertThatThrownBy(() -> { + databaseProvider.deletePdpGroup("name", null); + }).hasMessage("version is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + databaseProvider.updatePdpStatistics(null, null, null, null, null); + }).hasMessage("pdpGroupName is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + databaseProvider.updatePdpStatistics(null, null, null, null, new PdpStatistics()); + }).hasMessage("pdpGroupName is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + databaseProvider.updatePdpStatistics(null, null, null, "Instance", null); + }).hasMessage("pdpGroupName is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + databaseProvider.updatePdpStatistics(null, null, null, "Instance", new PdpStatistics()); + }).hasMessage("pdpGroupName is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + databaseProvider.updatePdpStatistics(null, null, "type", null, null); + }).hasMessage("pdpGroupName is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + databaseProvider.updatePdpStatistics(null, null, "type", null, new PdpStatistics()); + }).hasMessage("pdpGroupName is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + databaseProvider.updatePdpStatistics(null, null, "type", "Instance", null); + }).hasMessage("pdpGroupName is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + databaseProvider.updatePdpStatistics(null, null, "type", "Instance", new PdpStatistics()); + }).hasMessage("pdpGroupName is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + databaseProvider.updatePdpStatistics(null, "ver", null, null, null); + }).hasMessage("pdpGroupName is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + databaseProvider.updatePdpStatistics(null, "ver", null, null, new PdpStatistics()); + }).hasMessage("pdpGroupName is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + databaseProvider.updatePdpStatistics(null, "ver", null, "Instance", null); + }).hasMessage("pdpGroupName is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + databaseProvider.updatePdpStatistics(null, "ver", null, "Instance", new PdpStatistics()); + }).hasMessage("pdpGroupName is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + databaseProvider.updatePdpStatistics(null, "ver", "type", null, null); + }).hasMessage("pdpGroupName is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + databaseProvider.updatePdpStatistics(null, "ver", "type", null, new PdpStatistics()); + }).hasMessage("pdpGroupName is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + databaseProvider.updatePdpStatistics(null, "ver", "type", "Instance", null); + }).hasMessage("pdpGroupName is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + databaseProvider.updatePdpStatistics(null, "ver", "type", "Instance", new PdpStatistics()); + }).hasMessage("pdpGroupName is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + databaseProvider.updatePdpStatistics("name", null, null, null, null); + }).hasMessage("pdpGroupVersion is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + databaseProvider.updatePdpStatistics("name", null, null, null, new PdpStatistics()); + }).hasMessage("pdpGroupVersion is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + databaseProvider.updatePdpStatistics("name", null, null, "Instance", null); + }).hasMessage("pdpGroupVersion is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + databaseProvider.updatePdpStatistics("name", null, null, "Instance", new PdpStatistics()); + }).hasMessage("pdpGroupVersion is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + databaseProvider.updatePdpStatistics("name", null, "type", null, null); + }).hasMessage("pdpGroupVersion is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + databaseProvider.updatePdpStatistics("name", null, "type", null, new PdpStatistics()); + }).hasMessage("pdpGroupVersion is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + databaseProvider.updatePdpStatistics("name", null, "type", "Instance", null); + }).hasMessage("pdpGroupVersion is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + databaseProvider.updatePdpStatistics("name", null, "type", "Instance", new PdpStatistics()); + }).hasMessage("pdpGroupVersion is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + databaseProvider.updatePdpStatistics("name", "ver", null, null, null); + }).hasMessage("pdpType is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + databaseProvider.updatePdpStatistics("name", "ver", null, null, new PdpStatistics()); + }).hasMessage("pdpType is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + databaseProvider.updatePdpStatistics("name", "ver", null, "Instance", null); + }).hasMessage("pdpType is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + databaseProvider.updatePdpStatistics("name", "ver", null, "Instance", new PdpStatistics()); + }).hasMessage("pdpType is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + databaseProvider.updatePdpStatistics("name", "ver", "type", null, null); + }).hasMessage("pdpInstanceId is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + databaseProvider.updatePdpStatistics("name", "ver", "type", null, new PdpStatistics()); + }).hasMessage("pdpInstanceId is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + databaseProvider.updatePdpStatistics("name", "ver", "type", "Instance", null); + }).hasMessage("pdpStatistics is marked @NonNull but is null"); + + databaseProvider.close(); } @Test @@ -245,15 +484,16 @@ public class DatabasePolicyModelsProviderTest { }).hasMessage("policy models provider is not initilaized"); } - @Ignore @Test public void testProviderMethods() { try (PolicyModelsProvider databaseProvider = new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters)) { - assertThatThrownBy(() -> { - databaseProvider.getPolicyTypes("name", "version"); - }).hasMessage("policy type not found: name:version"); + assertEquals(0, databaseProvider.getPolicyTypes("name", "version").getPolicyTypes().get(0).size()); + assertEquals(0, databaseProvider.getPolicyTypeList("name", "version").size()); + assertEquals(0, databaseProvider.getFilteredPolicyTypes(ToscaPolicyTypeFilter.builder().build()) + .getPolicyTypes().get(0).size()); + assertEquals(0, databaseProvider.getFilteredPolicyTypeList(ToscaPolicyTypeFilter.builder().build()).size()); assertThatThrownBy(() -> { databaseProvider.createPolicyTypes(new ToscaServiceTemplate()); @@ -263,13 +503,16 @@ public class DatabasePolicyModelsProviderTest { databaseProvider.updatePolicyTypes(new ToscaServiceTemplate()); }).hasMessage("no policy types specified on service template"); - assertThatThrownBy(() -> { - databaseProvider.deletePolicyType("name", "version"); - }).hasMessage("policy type not found: name:version"); + assertEquals(0, databaseProvider.deletePolicyType("name", "version").getPolicyTypes().get(0).size()); - assertThatThrownBy(() -> { - databaseProvider.getPolicies("name", "version"); - }).hasMessage("policy not found: name:version"); + assertEquals(0, databaseProvider.deletePolicyType("name", "version").getPolicyTypes().get(0).size()); + + assertEquals(0, databaseProvider.getPolicies("name", "version").getToscaTopologyTemplate().getPolicies() + .get(0).size()); + assertEquals(0, databaseProvider.getPolicyList("name", "version").size()); + assertEquals(0, databaseProvider.getFilteredPolicies(ToscaPolicyFilter.builder().build()) + .getToscaTopologyTemplate().getPolicies().get(0).size()); + assertEquals(0, databaseProvider.getFilteredPolicyList(ToscaPolicyFilter.builder().build()).size()); assertThatThrownBy(() -> { databaseProvider.createPolicies(new ToscaServiceTemplate()); @@ -279,9 +522,8 @@ public class DatabasePolicyModelsProviderTest { databaseProvider.updatePolicies(new ToscaServiceTemplate()); }).hasMessage("topology template not specified on service template"); - assertThatThrownBy(() -> { - databaseProvider.deletePolicy("name", "version"); - }).hasMessage("policy not found: name:version"); + assertEquals(0, databaseProvider.deletePolicy("Policy", "0.0.0").getToscaTopologyTemplate().getPolicies() + .get(0).size()); assertThatThrownBy(() -> { databaseProvider.getOperationalPolicy("policy_id"); @@ -316,14 +558,59 @@ public class DatabasePolicyModelsProviderTest { }).hasMessage("no policy found for policy ID: policy_id"); assertEquals(0, databaseProvider.getPdpGroups("name", "version").size()); + assertEquals(0, databaseProvider.getFilteredPdpGroups(PdpGroupFilter.builder().build()).size()); assertNotNull(databaseProvider.createPdpGroups(new ArrayList<>())); assertNotNull(databaseProvider.updatePdpGroups(new ArrayList<>())); + PdpGroup pdpGroup = new PdpGroup(); + pdpGroup.setName("group"); + pdpGroup.setVersion("1.2.3"); + pdpGroup.setPdpGroupState(PdpState.ACTIVE); + pdpGroup.setPdpSubgroups(new ArrayList<>()); + List<PdpGroup> groupList = new ArrayList<>(); + groupList.add(pdpGroup); + + PdpSubGroup pdpSubGroup = new PdpSubGroup(); + pdpSubGroup.setPdpType("type"); + pdpSubGroup.setDesiredInstanceCount(123); + pdpSubGroup.setSupportedPolicyTypes(new ArrayList<>()); + pdpSubGroup.getSupportedPolicyTypes().add(new ToscaPolicyTypeIdentifier("type", "7.8.9")); + pdpGroup.getPdpSubgroups().add(pdpSubGroup); + + Pdp pdp = new Pdp(); + pdp.setInstanceId("type-0"); + pdp.setMessage("Hello"); + pdp.setPdpState(PdpState.ACTIVE); + pdp.setHealthy(PdpHealthStatus.UNKNOWN); + pdpSubGroup.setPdpInstances(new ArrayList<>()); + pdpSubGroup.getPdpInstances().add(pdp); + + assertEquals(123, databaseProvider.createPdpGroups(groupList).get(0).getPdpSubgroups().get(0) + .getDesiredInstanceCount()); + assertEquals(1, databaseProvider.getPdpGroups("group", "1.2.3").size()); + + pdpSubGroup.setDesiredInstanceCount(234); + databaseProvider.updatePdpSubGroup("group", "1.2.3", pdpSubGroup); + assertEquals(234, databaseProvider.getPdpGroups("group", "1.2.3").get(0).getPdpSubgroups() + .get(0).getDesiredInstanceCount()); + + assertEquals("Hello", databaseProvider.getPdpGroups("group", "1.2.3").get(0).getPdpSubgroups() + .get(0).getPdpInstances().get(0).getMessage()); + pdp.setMessage("Howdy"); + databaseProvider.updatePdp("group", "1.2.3", "type", pdp); + assertEquals("Howdy", databaseProvider.getPdpGroups("group", "1.2.3").get(0).getPdpSubgroups() + .get(0).getPdpInstances().get(0).getMessage()); + assertThatThrownBy(() -> { databaseProvider.deletePdpGroup("name", "version"); }).hasMessage("delete of PDP group \"name:version\" failed, PDP group does not exist"); + assertEquals(pdpGroup.getName(), databaseProvider.deletePdpGroup("group", "1.2.3").getName()); + + assertEquals(0, databaseProvider.getPdpStatistics(null, null).size()); + + databaseProvider.updatePdpStatistics("group", "1.2.3", "type", "type-0", new PdpStatistics()); } catch (Exception exc) { LOGGER.warn("test should not throw an exception", exc); fail("test should not throw an exception"); diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderTest.java index 01da44924..5a0cddb03 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 @@ -20,7 +20,6 @@ package org.onap.policy.models.provider.impl; -import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; @@ -30,9 +29,15 @@ import static org.junit.Assert.fail; import java.util.ArrayList; import org.junit.Test; +import org.onap.policy.models.pdp.concepts.Pdp; +import org.onap.policy.models.pdp.concepts.PdpGroupFilter; +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.provider.PolicyModelsProviderFactory; import org.onap.policy.models.provider.PolicyModelsProviderParameters; +import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyFilter; +import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeFilter; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyInput; import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy; @@ -74,11 +79,17 @@ public class DummyPolicyModelsProviderTest { dummyProvider.init(); assertNotNull(dummyProvider.getPolicyTypes("name", "version")); + assertNotNull(dummyProvider.getFilteredPolicyTypes(ToscaPolicyTypeFilter.builder().build())); + assertNotNull(dummyProvider.getPolicyTypeList("name", "version")); + assertNotNull(dummyProvider.getFilteredPolicyTypeList(ToscaPolicyTypeFilter.builder().build())); assertNotNull(dummyProvider.createPolicyTypes(new ToscaServiceTemplate())); assertNotNull(dummyProvider.updatePolicyTypes(new ToscaServiceTemplate())); assertNotNull(dummyProvider.deletePolicyType("name", "version")); assertNotNull(dummyProvider.getPolicies("name", "version")); + assertNotNull(dummyProvider.getFilteredPolicies(ToscaPolicyFilter.builder().build())); + assertNotNull(dummyProvider.getPolicyList("name", "version")); + assertNotNull(dummyProvider.getFilteredPolicyList(ToscaPolicyFilter.builder().build())); assertNotNull(dummyProvider.createPolicies(new ToscaServiceTemplate())); assertNotNull(dummyProvider.updatePolicies(new ToscaServiceTemplate())); assertNotNull(dummyProvider.deletePolicy("name", "version")); @@ -94,46 +105,15 @@ public class DummyPolicyModelsProviderTest { assertNotNull(dummyProvider.deleteGuardPolicy("policy_id")); assertTrue(dummyProvider.getPdpGroups("name", "version").isEmpty()); + assertTrue(dummyProvider.getFilteredPdpGroups(PdpGroupFilter.builder().build()).isEmpty()); assertTrue(dummyProvider.createPdpGroups(new ArrayList<>()).isEmpty()); assertTrue(dummyProvider.updatePdpGroups(new ArrayList<>()).isEmpty()); assertNull(dummyProvider.deletePdpGroup("name", "version")); - - assertThatThrownBy(() -> { - dummyProvider.getOperationalPolicy(null); - }).hasMessage("policyId is marked @NonNull but is null"); - assertThatThrownBy(() -> { - dummyProvider.createOperationalPolicy(null); - }).hasMessage("legacyOperationalPolicy is marked @NonNull but is null"); - assertThatThrownBy(() -> { - dummyProvider.updateOperationalPolicy(null); - }).hasMessage("legacyOperationalPolicy is marked @NonNull but is null"); - assertThatThrownBy(() -> { - dummyProvider.deleteOperationalPolicy(null); - }).hasMessage("policyId is marked @NonNull but is null"); - - assertThatThrownBy(() -> { - dummyProvider.getGuardPolicy(null); - }).hasMessage("policyId is marked @NonNull but is null"); - assertThatThrownBy(() -> { - dummyProvider.createGuardPolicy(null); - }).hasMessage("legacyGuardPolicy is marked @NonNull but is null"); - assertThatThrownBy(() -> { - dummyProvider.updateGuardPolicy(null); - }).hasMessage("legacyGuardPolicy is marked @NonNull but is null"); - assertThatThrownBy(() -> { - dummyProvider.deleteGuardPolicy(null); - }).hasMessage("policyId is marked @NonNull but is null"); - - assertThatThrownBy(() -> { - dummyProvider.createPdpGroups(null); - }).hasMessage("pdpGroups is marked @NonNull but is null"); - assertThatThrownBy(() -> { - dummyProvider.updatePdpGroups(null); - }).hasMessage("pdpGroups is marked @NonNull but is null"); - assertThatThrownBy(() -> { - dummyProvider.deletePdpGroup(null, null); - }).hasMessage("name is marked @NonNull but is null"); + dummyProvider.updatePdpSubGroup("name", "version", new PdpSubGroup()); + dummyProvider.updatePdp("name", "version", "type", new Pdp()); + dummyProvider.updatePdpStatistics("name", "version", "type", "type-0", new PdpStatistics()); + assertTrue(dummyProvider.getPdpStatistics("name", "version").isEmpty()); dummyProvider.close(); } @@ -159,7 +139,7 @@ public class DummyPolicyModelsProviderTest { resp.getBadDummyResponse2(); fail("test should throw an exception"); } catch (Exception npe) { - assertEquals("fileName is marked @NonNull but is null", npe.getMessage()); + assertEquals("error serializing object", npe.getMessage()); } finally { if (resp != null) { resp.close(); diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyGuardPersistenceTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyGuardPersistenceTest.java index 47f099a73..5ebb44814 100644 --- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyGuardPersistenceTest.java +++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyGuardPersistenceTest.java @@ -134,6 +134,16 @@ public class PolicyLegacyGuardPersistenceTest { assertEquals(gip.getContent(), gotGopm.get(gip.getPolicyId()).getProperties().values().iterator().next()); + Map<String, LegacyGuardPolicyOutput> updatedGopm = databaseProvider.updateGuardPolicy(gip); + assertEquals(gip.getPolicyId(), updatedGopm.keySet().iterator().next()); + assertEquals(gip.getContent(), + updatedGopm.get(gip.getPolicyId()).getProperties().values().iterator().next()); + + Map<String, LegacyGuardPolicyOutput> deletedGopm = databaseProvider.deleteGuardPolicy(gip.getPolicyId()); + assertEquals(gip.getPolicyId(), deletedGopm.keySet().iterator().next()); + assertEquals(gip.getContent(), + deletedGopm.get(gip.getPolicyId()).getProperties().values().iterator().next()); + String actualRetrievedJson = standardCoder.encode(gotGopm); // All of this dash/underscore stuff is to avoid a checkstyle error around escaping unicode characters diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyOperationalPersistenceTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyOperationalPersistenceTest.java index 65e6a2f54..af6c4a4cc 100644 --- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyOperationalPersistenceTest.java +++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyOperationalPersistenceTest.java @@ -130,6 +130,12 @@ public class PolicyLegacyOperationalPersistenceTest { LegacyOperationalPolicy gotLop = databaseProvider.getOperationalPolicy(lop.getPolicyId()); assertEquals(gotLop, lop); + LegacyOperationalPolicy updatedLop = databaseProvider.updateOperationalPolicy(lop); + assertEquals(gotLop, updatedLop); + + LegacyOperationalPolicy deletedLop = databaseProvider.deleteOperationalPolicy(lop.getPolicyId()); + assertEquals(gotLop, deletedLop); + String actualRetrievedJson = standardCoder.encode(gotLop); // All of this dash/underscore stuff is to avoid a checkstyle error around escaping unicode characters diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyPersistenceTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyPersistenceTest.java index e8c344189..81795dbda 100644 --- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyPersistenceTest.java +++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyPersistenceTest.java @@ -143,6 +143,7 @@ public class PolicyPersistenceTest { assertNotNull(serviceTemplate); databaseProvider.createPolicies(serviceTemplate); + databaseProvider.updatePolicies(serviceTemplate); for (Map<String, ToscaPolicy> policyMap : serviceTemplate.getToscaTopologyTemplate().getPolicies()) { for (ToscaPolicy policy : policyMap.values()) { diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyTypePersistenceTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyTypePersistenceTest.java index 96360ec93..528395efc 100644 --- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyTypePersistenceTest.java +++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyTypePersistenceTest.java @@ -106,7 +106,7 @@ public class PolicyTypePersistenceTest { } @Test - public void testPolicyPersistence() { + public void testPolicyTypePersistence() { try { for (String policyTypeResourceName : policyTypeResourceNames) { String policyTypeString = ResourceUtils.getResourceAsString(policyTypeResourceName); @@ -118,7 +118,7 @@ public class PolicyTypePersistenceTest { } } } catch (Exception exc) { - LOGGER.warn("error processing policies", exc); + LOGGER.warn("error processing policy types", exc); fail("test should not throw an exception"); } } @@ -143,6 +143,7 @@ public class PolicyTypePersistenceTest { ToscaPolicyType inPolicyType = serviceTemplate.getPolicyTypes().get(0).values().iterator().next(); databaseProvider.createPolicyTypes(serviceTemplate); + databaseProvider.updatePolicyTypes(serviceTemplate); List<ToscaPolicyType> policyTypeList = databaseProvider.getPolicyTypeList(inPolicyType.getName(), inPolicyType.getVersion()); diff --git a/models-tosca/pom.xml b/models-tosca/pom.xml index 5b857c13b..36ee69b9c 100644 --- a/models-tosca/pom.xml +++ b/models-tosca/pom.xml @@ -64,12 +64,6 @@ </dependency> <dependency> - <groupId>org.mariadb.jdbc</groupId> - <artifactId>mariadb-java-client</artifactId> - <scope>test</scope> - </dependency> - - <dependency> <groupId>io.swagger</groupId> <artifactId>swagger-jersey2-jaxrs</artifactId> </dependency> 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 4bf014644..46f920cf4 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 @@ -276,10 +276,6 @@ public class AuthorativeToscaProvider { * @return the plain list */ private <T> List<T> asConceptList(final List<Map<String, T>> listOfMaps) { - if (listOfMaps == null) { - return Collections.emptyList(); - } - List<T> returnList = new ArrayList<>(); for (Map<String, T> conceptMap : listOfMaps) { for (T concept : conceptMap.values()) { diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/mapping/LegacyGuardPolicyMapper.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/mapping/LegacyGuardPolicyMapper.java index cc37338e4..85b5e6df8 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/mapping/LegacyGuardPolicyMapper.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/mapping/LegacyGuardPolicyMapper.java @@ -139,12 +139,6 @@ public class LegacyGuardPolicyMapper propertiesMap.put("content", content); legacyGuardPolicyOutput.setProperties(propertiesMap); - if (toscaPolicy.getProperties() == null) { - String errorMessage = "property \"Content\" not defined on TOSCA policy"; - LOGGER.warn(errorMessage); - throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage); - } - legacyGuardPolicyOutputMap.put(toscaPolicy.getKey().getName(), legacyGuardPolicyOutput); } diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/mapping/LegacyOperationalPolicyMapper.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/mapping/LegacyOperationalPolicyMapper.java index b6c5d3bba..7caba98d8 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/mapping/LegacyOperationalPolicyMapper.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/mapping/LegacyOperationalPolicyMapper.java @@ -106,8 +106,8 @@ public class LegacyOperationalPolicyMapper } final String content = toscaPolicy.getProperties().get(CONTENT_PROPERTY); - if (toscaPolicy.getProperties() == null) { - String errorMessage = "property \"Content\" not defined on TOSCA policy"; + if (content == null) { + String errorMessage = "property \"content\" not defined on TOSCA policy"; LOGGER.warn(errorMessage); throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage); } diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraint.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraint.java index fad227c34..6369f7996 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraint.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraint.java @@ -53,9 +53,7 @@ public abstract class JpaToscaConstraint } @Override - public int compareTo(JpaToscaConstraint otherConstraint) { - return 0; - } + public abstract int compareTo(JpaToscaConstraint otherConstraint); /** * Create instances of constraints of various types. diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogical.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogical.java index 9841cbe82..632f84add 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogical.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogical.java @@ -73,30 +73,33 @@ public class JpaToscaConstraintLogical extends JpaToscaConstraint { public ToscaConstraint toAuthorative() { ToscaConstraint toscaConstraint = new ToscaConstraint(); + if (operation == null) { + return null; + } + switch (operation) { - case EQ: { + case EQ: toscaConstraint.setEqual(compareTo); break; - } - case GT: { + + case GT: toscaConstraint.setGreaterThan(compareTo); break; - } - case GE: { + + case GE: toscaConstraint.setGreaterOrEqual(compareTo); break; - } - case LT: { + + case LT: toscaConstraint.setLessThan(compareTo); break; - } - case LE: { + + case LE: toscaConstraint.setLessOrEqual(compareTo); break; - } - default: { + + default: // Can't happen - } } return toscaConstraint; diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicy.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicy.java index 671b5ccac..3bc472243 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicy.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicy.java @@ -129,6 +129,8 @@ public class JpaToscaPolicy extends JpaToscaEntityType<ToscaPolicy> implements P * @param authorativeConcept the authorative concept to copy from */ public JpaToscaPolicy(final ToscaPolicy authorativeConcept) { + super(new PfConceptKey()); + type = new PfConceptKey(); this.fromAuthorative(authorativeConcept); } @@ -215,7 +217,7 @@ public class JpaToscaPolicy extends JpaToscaEntityType<ToscaPolicy> implements P PfValidationResult result = super.validate(resultIn); if (type == null || type.isNullKey()) { - result.addValidationMessage(new PfValidationMessage(type, this.getClass(), ValidationResult.INVALID, + result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID, "type is null or a null key")); } else { result = type.validate(result); @@ -238,7 +240,7 @@ public class JpaToscaPolicy extends JpaToscaEntityType<ToscaPolicy> implements P * @param result The result of validations up to now * @return the validation result */ - private PfValidationResult validateProperties(@NonNull final PfValidationResult resultIn) { + private PfValidationResult validateProperties(final PfValidationResult resultIn) { PfValidationResult result = resultIn; for (Entry<String, String> propertyEntry : properties.entrySet()) { diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProvider.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProvider.java index a207c4267..ef8ac05ec 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProvider.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProvider.java @@ -24,14 +24,11 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import javax.ws.rs.core.Response; - import lombok.NonNull; import org.onap.policy.models.base.PfConcept; import org.onap.policy.models.base.PfConceptKey; 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.simple.concepts.JpaToscaPolicies; import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy; @@ -40,8 +37,6 @@ import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyTypes; import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate; import org.onap.policy.models.tosca.simple.concepts.JpaToscaTopologyTemplate; import org.onap.policy.models.tosca.utils.ToscaUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * This class provides the provision of information on TOSCA concepts in the database to callers. @@ -49,8 +44,6 @@ import org.slf4j.LoggerFactory; * @author Liam Fallon (liam.fallon@est.tech) */ public class SimpleToscaProvider { - private static final Logger LOGGER = LoggerFactory.getLogger(SimpleToscaProvider.class); - /** * Get policy types. * @@ -69,14 +62,9 @@ public class SimpleToscaProvider { // Add the policy type to the TOSCA service template List<JpaToscaPolicyType> jpaPolicyTypeList = dao.getFiltered(JpaToscaPolicyType.class, name, version); - if (jpaPolicyTypeList != null) { - serviceTemplate.getPolicyTypes().getConceptMap().putAll(asConceptMap(jpaPolicyTypeList)); - return serviceTemplate; - } else { - String errorMessage = "policy type not found: " + name + ":" + version; - LOGGER.warn(errorMessage); - throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage); - } + serviceTemplate.getPolicyTypes().getConceptMap().putAll(asConceptMap(jpaPolicyTypeList)); + + return serviceTemplate; } /** @@ -178,14 +166,8 @@ public class SimpleToscaProvider { // Add the policy type to the TOSCA service template List<JpaToscaPolicy> jpaPolicyList = dao.getFiltered(JpaToscaPolicy.class, name, version); - if (jpaPolicyList != null) { - serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().putAll(asConceptMap(jpaPolicyList)); - return serviceTemplate; - } else { - String errorMessage = "policy not found: " + name + ":" + version; - LOGGER.warn(errorMessage); - throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage); - } + serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().putAll(asConceptMap(jpaPolicyList)); + return serviceTemplate; } /** 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 441bbcb18..a7d016bf3 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 @@ -143,8 +143,10 @@ public class AuthorativeToscaProviderPolicyTest { gotPolicyList = new AuthorativeToscaProvider().getPolicyList(pfDao, null, "1.0.0"); assertEquals(1, gotPolicyList.size()); assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicyList.get(0))); - } + gotPolicyList = new AuthorativeToscaProvider().getPolicyList(pfDao, "Nonexistant", "1.0.0"); + assertEquals(0, gotPolicyList.size()); + } @Test public void testPoliciesGetFiltered() throws Exception { 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 fbb5abf62..7dc4a9497 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 @@ -23,15 +23,18 @@ package org.onap.policy.models.tosca.authorative.provider; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; + +import com.google.gson.GsonBuilder; import java.sql.Connection; import java.sql.DriverManager; import java.util.ArrayList; import java.util.List; +import org.apache.commons.lang3.ObjectUtils; import org.junit.After; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; import org.onap.policy.common.utils.coder.StandardCoder; import org.onap.policy.common.utils.resources.ResourceUtils; @@ -41,10 +44,11 @@ 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.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.ToscaTopologyTemplate; +import org.yaml.snakeyaml.Yaml; /** * Test of the {@link AuthorativeToscaProvider} class. @@ -52,10 +56,26 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaTopologyTemplate; * @author Liam Fallon (liam.fallon@est.tech) */ public class AuthorativeToscaProviderPolicyTypeTest { + private static String yamlAsJsonString; private Connection connection; private PfDao pfDao; private StandardCoder standardCoder; + + /** + * Read the policy type definition. + * + * @throws Exception on errors + */ + @BeforeClass + public static void readPolicyDefinition() { + String yamlString = + ResourceUtils.getResourceAsString("policytypes/onap.policies.optimization.AffinityPolicy.yaml"); + + Object yamlObject = new Yaml().load(yamlString); + yamlAsJsonString = new GsonBuilder().setPrettyPrinting().create().toJson(yamlObject); + } + /** * Set up the DAO towards the database. * @@ -93,281 +113,272 @@ public class AuthorativeToscaProviderPolicyTypeTest { } @Test - public void testPoliciesGet() throws Exception { + public void testPolicyTypesGet() throws Exception { assertThatThrownBy(() -> { - new AuthorativeToscaProvider().getPolicies(null, null, null); + new AuthorativeToscaProvider().getPolicyTypes(null, null, null); }).hasMessage("dao is marked @NonNull but is null"); assertThatThrownBy(() -> { new AuthorativeToscaProvider().getPolicyList(null, null, null); }).hasMessage("dao is marked @NonNull but is null"); - ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode( - ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"), - ToscaServiceTemplate.class); + ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class); assertNotNull(toscaServiceTemplate); ToscaServiceTemplate createdServiceTemplate = - new AuthorativeToscaProvider().createPolicies(pfDao, toscaServiceTemplate); + new AuthorativeToscaProvider().createPolicyTypes(pfDao, toscaServiceTemplate); - PfConceptKey policyKey = new PfConceptKey("onap.restart.tca:1.0.0"); + PfConceptKey policyTypeKey = new PfConceptKey("onap.policies.optimization.AffinityPolicy:0.0.0"); - ToscaPolicy beforePolicy = - toscaServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName()); - ToscaPolicy createdPolicy = - createdServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName()); - assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, createdPolicy)); - assertTrue(beforePolicy.getType().equals(createdPolicy.getType())); + ToscaPolicyType beforePolicyType = toscaServiceTemplate.getPolicyTypes().get(1).get(policyTypeKey.getName()); + ToscaPolicyType createdPolicyType = createdServiceTemplate.getPolicyTypes().get(0).get(policyTypeKey.getName()); + assertEquals(true, beforePolicyType.getName().equals(createdPolicyType.getName())); + assertEquals(0, ObjectUtils.compare(beforePolicyType.getDescription(), createdPolicyType.getDescription())); - ToscaServiceTemplate gotServiceTemplate = - new AuthorativeToscaProvider().getPolicies(pfDao, policyKey.getName(), policyKey.getVersion()); + ToscaServiceTemplate gotServiceTemplate = new AuthorativeToscaProvider().getPolicyTypes(pfDao, + policyTypeKey.getName(), policyTypeKey.getVersion()); - ToscaPolicy gotPolicy = - gotServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName()); - assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicy)); - assertTrue(beforePolicy.getType().equals(gotPolicy.getType())); + ToscaPolicyType gotPolicyType = gotServiceTemplate.getPolicyTypes().get(0).get(policyTypeKey.getName()); + assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName())); + assertEquals(0, ObjectUtils.compare(beforePolicyType.getDescription(), createdPolicyType.getDescription())); - List<ToscaPolicy> gotPolicyList = - new AuthorativeToscaProvider().getPolicyList(pfDao, "onap.restart.tca", "1.0.0"); - assertEquals(1, gotPolicyList.size()); - assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicyList.get(0))); + List<ToscaPolicyType> gotPolicyTypeList = new AuthorativeToscaProvider().getPolicyTypeList(pfDao, + "onap.policies.optimization.AffinityPolicy", "0.0.0"); + assertEquals(1, gotPolicyTypeList.size()); + assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName())); - gotPolicyList = new AuthorativeToscaProvider().getPolicyList(pfDao, "onap.restart.tca", null); - assertEquals(1, gotPolicyList.size()); - assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicyList.get(0))); + gotPolicyTypeList = new AuthorativeToscaProvider().getPolicyTypeList(pfDao, + "onap.policies.optimization.AffinityPolicy", null); + assertEquals(1, gotPolicyTypeList.size()); + assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName())); - gotPolicyList = new AuthorativeToscaProvider().getPolicyList(pfDao, null, null); - assertEquals(1, gotPolicyList.size()); - assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicyList.get(0))); + gotPolicyTypeList = new AuthorativeToscaProvider().getPolicyTypeList(pfDao, null, null); + assertEquals(2, gotPolicyTypeList.size()); + assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName())); - gotPolicyList = new AuthorativeToscaProvider().getPolicyList(pfDao, null, "1.0.0"); - assertEquals(1, gotPolicyList.size()); - assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicyList.get(0))); + gotPolicyTypeList = new AuthorativeToscaProvider().getPolicyTypeList(pfDao, null, "0.0.0"); + assertEquals(2, gotPolicyTypeList.size()); + assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName())); } @Test - public void testPoliciesGetFiltered() throws Exception { + public void testPolicyTypesGetFiltered() throws Exception { assertThatThrownBy(() -> { - new AuthorativeToscaProvider().getFilteredPolicies(null, null); + new AuthorativeToscaProvider().getFilteredPolicyTypes(null, null); }).hasMessage("dao is marked @NonNull but is null"); assertThatThrownBy(() -> { - new AuthorativeToscaProvider().getFilteredPolicies(null, ToscaPolicyFilter.builder().build()); + new AuthorativeToscaProvider().getFilteredPolicyTypes(null, ToscaPolicyTypeFilter.builder().build()); }).hasMessage("dao is marked @NonNull but is null"); assertThatThrownBy(() -> { - new AuthorativeToscaProvider().getFilteredPolicies(pfDao, null); + new AuthorativeToscaProvider().getFilteredPolicyTypes(pfDao, null); }).hasMessage("filter is marked @NonNull but is null"); assertThatThrownBy(() -> { - new AuthorativeToscaProvider().getFilteredPolicyList(null, null); + new AuthorativeToscaProvider().getFilteredPolicyTypeList(null, null); }).hasMessage("dao is marked @NonNull but is null"); assertThatThrownBy(() -> { - new AuthorativeToscaProvider().getFilteredPolicyList(null, ToscaPolicyFilter.builder().build()); + new AuthorativeToscaProvider().getFilteredPolicyTypeList(null, ToscaPolicyTypeFilter.builder().build()); }).hasMessage("dao is marked @NonNull but is null"); assertThatThrownBy(() -> { - new AuthorativeToscaProvider().getFilteredPolicyList(pfDao, null); + new AuthorativeToscaProvider().getFilteredPolicyTypeList(pfDao, null); }).hasMessage("filter is marked @NonNull but is null"); - ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode( - ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"), - ToscaServiceTemplate.class); + ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class); assertNotNull(toscaServiceTemplate); ToscaServiceTemplate createdServiceTemplate = - new AuthorativeToscaProvider().createPolicies(pfDao, toscaServiceTemplate); + new AuthorativeToscaProvider().createPolicyTypes(pfDao, toscaServiceTemplate); - PfConceptKey policyKey = new PfConceptKey("onap.restart.tca:1.0.0"); + PfConceptKey policyTypeKey = new PfConceptKey("onap.policies.optimization.AffinityPolicy:0.0.0"); - ToscaPolicy beforePolicy = - toscaServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName()); - ToscaPolicy createdPolicy = - createdServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName()); - assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, createdPolicy)); - assertTrue(beforePolicy.getType().equals(createdPolicy.getType())); + ToscaPolicyType beforePolicyType = toscaServiceTemplate.getPolicyTypes().get(1).get(policyTypeKey.getName()); + ToscaPolicyType createdPolicyType = createdServiceTemplate.getPolicyTypes().get(0).get(policyTypeKey.getName()); + assertEquals(true, beforePolicyType.getName().equals(createdPolicyType.getName())); + assertEquals(0, ObjectUtils.compare(beforePolicyType.getDescription(), createdPolicyType.getDescription())); ToscaServiceTemplate gotServiceTemplate = - new AuthorativeToscaProvider().getFilteredPolicies(pfDao, ToscaPolicyFilter.builder().build()); - - ToscaPolicy gotPolicy = - gotServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName()); - assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicy)); - assertTrue(beforePolicy.getType().equals(gotPolicy.getType())); - - gotServiceTemplate = new AuthorativeToscaProvider().getFilteredPolicies(pfDao, - ToscaPolicyFilter.builder().name(policyKey.getName()).build()); - - gotPolicy = gotServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName()); - assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicy)); - assertTrue(beforePolicy.getType().equals(gotPolicy.getType())); - - gotServiceTemplate = new AuthorativeToscaProvider().getFilteredPolicies(pfDao, - ToscaPolicyFilter.builder().name(policyKey.getName()).version("1.0.0").build()); - - gotPolicy = gotServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName()); - assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicy)); - assertTrue(beforePolicy.getType().equals(gotPolicy.getType())); - - List<ToscaPolicy> gotPolicyList = - new AuthorativeToscaProvider().getPolicyList(pfDao, "onap.restart.tca", "1.0.0"); - assertEquals(1, gotPolicyList.size()); - assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicyList.get(0))); - - gotPolicyList = - new AuthorativeToscaProvider().getFilteredPolicyList(pfDao, ToscaPolicyFilter.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()); - assertEquals(1, gotPolicyList.size()); - assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicyList.get(0))); - - gotPolicyList = new AuthorativeToscaProvider().getFilteredPolicyList(pfDao, - ToscaPolicyFilter.builder().name(policyKey.getName()).version("1.0.0").build()); - assertEquals(1, gotPolicyList.size()); - assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicyList.get(0))); + new AuthorativeToscaProvider().getFilteredPolicyTypes(pfDao, ToscaPolicyTypeFilter.builder().build()); + + ToscaPolicyType gotPolicyType = gotServiceTemplate.getPolicyTypes().get(0).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()); + + gotPolicyType = gotServiceTemplate.getPolicyTypes().get(0).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("0.0.0").build()); + + gotPolicyType = gotServiceTemplate.getPolicyTypes().get(0).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, + "onap.policies.optimization.AffinityPolicy", "0.0.0"); + assertEquals(1, gotPolicyTypeList.size()); + assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName())); + + gotPolicyTypeList = new AuthorativeToscaProvider().getFilteredPolicyTypeList(pfDao, + ToscaPolicyTypeFilter.builder().build()); + assertEquals(2, gotPolicyTypeList.size()); + assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName())); + + gotPolicyTypeList = new AuthorativeToscaProvider().getFilteredPolicyTypeList(pfDao, + ToscaPolicyTypeFilter.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("0.0.0").build()); + assertEquals(1, gotPolicyTypeList.size()); + assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName())); + + gotPolicyTypeList = new AuthorativeToscaProvider().getFilteredPolicyTypeList(pfDao, + ToscaPolicyTypeFilter.builder().version("1.0.0").build()); + assertEquals(1, gotPolicyTypeList.size()); + assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName())); } @Test - public void testPolicyCreate() throws Exception { + public void testPolicyTypesCreate() throws Exception { assertThatThrownBy(() -> { - new AuthorativeToscaProvider().createPolicies(null, null); + new AuthorativeToscaProvider().createPolicyTypes(null, null); }).hasMessage("dao is marked @NonNull but is null"); assertThatThrownBy(() -> { - new AuthorativeToscaProvider().createPolicies(null, new ToscaServiceTemplate()); + new AuthorativeToscaProvider().createPolicyTypes(null, new ToscaServiceTemplate()); }).hasMessage("dao is marked @NonNull but is null"); assertThatThrownBy(() -> { - new AuthorativeToscaProvider().createPolicies(pfDao, null); + new AuthorativeToscaProvider().createPolicyTypes(pfDao, null); }).hasMessage("serviceTemplate is marked @NonNull but is null"); - ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode( - ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"), - ToscaServiceTemplate.class); + ToscaServiceTemplate testToscaServiceTemplate = new ToscaServiceTemplate(); + assertThatThrownBy(() -> { + new AuthorativeToscaProvider().createPolicyTypes(pfDao, testToscaServiceTemplate); + }).hasMessage("no policy types specified on service template"); + + testToscaServiceTemplate.setPolicyTypes(new ArrayList<>()); + assertThatThrownBy(() -> { + new AuthorativeToscaProvider().createPolicyTypes(pfDao, testToscaServiceTemplate); + }).hasMessage("An incoming list of concepts must have at least one entry"); + + ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class); assertNotNull(toscaServiceTemplate); ToscaServiceTemplate createdServiceTemplate = - new AuthorativeToscaProvider().createPolicies(pfDao, toscaServiceTemplate); + new AuthorativeToscaProvider().createPolicyTypes(pfDao, toscaServiceTemplate); - PfConceptKey policyKey = new PfConceptKey("onap.restart.tca:1.0.0"); + PfConceptKey policyTypeKey = new PfConceptKey("onap.policies.optimization.AffinityPolicy:0.0.0"); - ToscaPolicy beforePolicy = - toscaServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName()); - ToscaPolicy createdPolicy = - createdServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName()); - assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, createdPolicy)); - assertTrue(beforePolicy.getType().equals(createdPolicy.getType())); + ToscaPolicyType beforePolicyType = toscaServiceTemplate.getPolicyTypes().get(1).get(policyTypeKey.getName()); + ToscaPolicyType createdPolicyType = createdServiceTemplate.getPolicyTypes().get(0).get(policyTypeKey.getName()); + assertEquals(true, beforePolicyType.getName().equals(createdPolicyType.getName())); + assertEquals(0, ObjectUtils.compare(beforePolicyType.getDescription(), createdPolicyType.getDescription())); } - @Test - public void testPolicyUpdate() throws Exception { + public void testPolicyTypesUpdate() throws Exception { assertThatThrownBy(() -> { - new AuthorativeToscaProvider().createPolicies(null, null); + new AuthorativeToscaProvider().createPolicyTypes(null, null); }).hasMessage("dao is marked @NonNull but is null"); assertThatThrownBy(() -> { - new AuthorativeToscaProvider().updatePolicies(null, null); + new AuthorativeToscaProvider().updatePolicyTypes(null, null); }).hasMessage("dao is marked @NonNull but is null"); assertThatThrownBy(() -> { - new AuthorativeToscaProvider().updatePolicies(null, new ToscaServiceTemplate()); + new AuthorativeToscaProvider().updatePolicyTypes(null, new ToscaServiceTemplate()); }).hasMessage("dao is marked @NonNull but is null"); assertThatThrownBy(() -> { - new AuthorativeToscaProvider().updatePolicies(pfDao, null); + new AuthorativeToscaProvider().updatePolicyTypes(pfDao, null); }).hasMessage("serviceTemplate is marked @NonNull but is null"); - ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode( - ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"), - ToscaServiceTemplate.class); + ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class); assertNotNull(toscaServiceTemplate); ToscaServiceTemplate createdServiceTemplate = - new AuthorativeToscaProvider().createPolicies(pfDao, toscaServiceTemplate); + new AuthorativeToscaProvider().createPolicyTypes(pfDao, toscaServiceTemplate); - PfConceptKey policyKey = new PfConceptKey("onap.restart.tca:1.0.0"); + PfConceptKey policyTypeKey = new PfConceptKey("onap.policies.optimization.AffinityPolicy:0.0.0"); - ToscaPolicy beforePolicy = - toscaServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName()); - ToscaPolicy createdPolicy = - createdServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName()); - assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, createdPolicy)); - assertTrue(beforePolicy.getType().equals(createdPolicy.getType())); + ToscaPolicyType beforePolicyType = toscaServiceTemplate.getPolicyTypes().get(1).get(policyTypeKey.getName()); + ToscaPolicyType createdPolicyType = createdServiceTemplate.getPolicyTypes().get(0).get(policyTypeKey.getName()); + assertEquals(true, beforePolicyType.getName().equals(createdPolicyType.getName())); + assertEquals(0, ObjectUtils.compare(beforePolicyType.getDescription(), createdPolicyType.getDescription())); ToscaServiceTemplate updatedServiceTemplate = - new AuthorativeToscaProvider().updatePolicies(pfDao, toscaServiceTemplate); + new AuthorativeToscaProvider().updatePolicyTypes(pfDao, toscaServiceTemplate); - ToscaPolicy updatedPolicy = - updatedServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName()); - assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, updatedPolicy)); - assertTrue(beforePolicy.getType().equals(updatedPolicy.getType())); + ToscaPolicyType updatedPolicy = updatedServiceTemplate.getPolicyTypes().get(0).get(policyTypeKey.getName()); + assertEquals(true, beforePolicyType.getName().equals(updatedPolicy.getName())); + assertEquals(0, ObjectUtils.compare(beforePolicyType.getDescription(), updatedPolicy.getDescription())); } @Test - public void testPoliciesDelete() throws Exception { + public void testPolicyTypesDelete() throws Exception { assertThatThrownBy(() -> { - new AuthorativeToscaProvider().deletePolicy(null, null, null); + new AuthorativeToscaProvider().deletePolicyType(null, null, null); }).hasMessage("dao is marked @NonNull but is null"); assertThatThrownBy(() -> { - new AuthorativeToscaProvider().deletePolicy(null, null, "version"); + new AuthorativeToscaProvider().deletePolicyType(null, null, "version"); }).hasMessage("dao is marked @NonNull but is null"); assertThatThrownBy(() -> { - new AuthorativeToscaProvider().deletePolicy(null, "name", null); + new AuthorativeToscaProvider().deletePolicyType(null, "name", null); }).hasMessage("dao is marked @NonNull but is null"); assertThatThrownBy(() -> { - new AuthorativeToscaProvider().deletePolicy(null, "name", "version"); + new AuthorativeToscaProvider().deletePolicyType(null, "name", "version"); }).hasMessage("dao is marked @NonNull but is null"); assertThatThrownBy(() -> { - new AuthorativeToscaProvider().deletePolicy(pfDao, null, null); + new AuthorativeToscaProvider().deletePolicyType(pfDao, null, null); }).hasMessage("name is marked @NonNull but is null"); assertThatThrownBy(() -> { - new AuthorativeToscaProvider().deletePolicy(pfDao, null, "version"); + new AuthorativeToscaProvider().deletePolicyType(pfDao, null, "version"); }).hasMessage("name is marked @NonNull but is null"); assertThatThrownBy(() -> { - new AuthorativeToscaProvider().deletePolicy(pfDao, "name", null); + new AuthorativeToscaProvider().deletePolicyType(pfDao, "name", null); }).hasMessage("version is marked @NonNull but is null"); - ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode( - ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"), - ToscaServiceTemplate.class); + ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class); assertNotNull(toscaServiceTemplate); ToscaServiceTemplate createdServiceTemplate = - new AuthorativeToscaProvider().createPolicies(pfDao, toscaServiceTemplate); + new AuthorativeToscaProvider().createPolicyTypes(pfDao, toscaServiceTemplate); - PfConceptKey policyKey = new PfConceptKey("onap.restart.tca:1.0.0"); + PfConceptKey policyTypeKey = new PfConceptKey("onap.policies.optimization.AffinityPolicy:0.0.0"); - ToscaPolicy beforePolicy = - toscaServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName()); - ToscaPolicy createdPolicy = - createdServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName()); - assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, createdPolicy)); - assertTrue(beforePolicy.getType().equals(createdPolicy.getType())); + ToscaPolicyType beforePolicyType = toscaServiceTemplate.getPolicyTypes().get(1).get(policyTypeKey.getName()); + ToscaPolicyType createdPolicyType = createdServiceTemplate.getPolicyTypes().get(0).get(policyTypeKey.getName()); + assertEquals(true, beforePolicyType.getName().equals(createdPolicyType.getName())); + assertEquals(0, ObjectUtils.compare(beforePolicyType.getDescription(), createdPolicyType.getDescription())); - ToscaServiceTemplate deletedServiceTemplate = - new AuthorativeToscaProvider().deletePolicy(pfDao, policyKey.getName(), policyKey.getVersion()); + ToscaServiceTemplate deletedServiceTemplate = new AuthorativeToscaProvider().deletePolicyType(pfDao, + policyTypeKey.getName(), policyTypeKey.getVersion()); - ToscaPolicy deletedPolicy = - deletedServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName()); - assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, createdPolicy)); - assertTrue(beforePolicy.getType().equals(deletedPolicy.getType())); + ToscaPolicyType deletedPolicy = deletedServiceTemplate.getPolicyTypes().get(0).get(policyTypeKey.getName()); + assertEquals(true, beforePolicyType.getName().equals(deletedPolicy.getName())); + assertEquals(0, ObjectUtils.compare(beforePolicyType.getDescription(), deletedPolicy.getDescription())); - ToscaServiceTemplate gotServiceTemplate = - new AuthorativeToscaProvider().getPolicies(pfDao, policyKey.getName(), policyKey.getVersion()); + ToscaServiceTemplate gotServiceTemplate = new AuthorativeToscaProvider().getPolicyTypes(pfDao, + policyTypeKey.getName(), policyTypeKey.getVersion()); - assertEquals(0, gotServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).size()); + assertEquals(0, gotServiceTemplate.getPolicyTypes().get(0).size()); } @Test @@ -375,21 +386,21 @@ public class AuthorativeToscaProviderPolicyTypeTest { ToscaServiceTemplate testServiceTemplate = new ToscaServiceTemplate(); assertThatThrownBy(() -> { - new AuthorativeToscaProvider().deletePolicy(pfDao, "name", null); + new AuthorativeToscaProvider().deletePolicyType(pfDao, "name", null); }).hasMessage("version is marked @NonNull but is null"); assertThatThrownBy(() -> { - new AuthorativeToscaProvider().createPolicies(pfDao, testServiceTemplate); - }).hasMessage("topology template not specified on service template"); + new AuthorativeToscaProvider().createPolicyTypes(pfDao, testServiceTemplate); + }).hasMessage("no policy types specified on service template"); testServiceTemplate.setToscaTopologyTemplate(new ToscaTopologyTemplate()); assertThatThrownBy(() -> { - new AuthorativeToscaProvider().createPolicies(pfDao, testServiceTemplate); - }).hasMessage("no policies specified on topology template of service template"); + new AuthorativeToscaProvider().createPolicyTypes(pfDao, testServiceTemplate); + }).hasMessage("no policy types specified on service template"); - testServiceTemplate.getToscaTopologyTemplate().setPolicies(new ArrayList<>()); + testServiceTemplate.setPolicyTypes(new ArrayList<>()); assertThatThrownBy(() -> { - new AuthorativeToscaProvider().createPolicies(pfDao, testServiceTemplate); + new AuthorativeToscaProvider().createPolicyTypes(pfDao, testServiceTemplate); }).hasMessage("An incoming list of concepts must have at least one entry"); } } diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/concepts/LegacyGuardPolicyTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/concepts/LegacyGuardPolicyTest.java index 5720b5594..9c2344080 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/concepts/LegacyGuardPolicyTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/concepts/LegacyGuardPolicyTest.java @@ -20,6 +20,7 @@ package org.onap.policy.models.tosca.legacy.concepts; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -28,6 +29,7 @@ import java.util.Map; import org.junit.Test; import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyInput; +import org.onap.policy.models.tosca.legacy.concepts.testconcepts.DummyBadLegacyGuardPolicyContent; public class LegacyGuardPolicyTest { @@ -45,6 +47,10 @@ public class LegacyGuardPolicyTest { content.setActor("SO"); guard.setContent(content); assertEquals("SO", guard.getContent().getActor()); - } + DummyBadLegacyGuardPolicyContent dblgpc = new DummyBadLegacyGuardPolicyContent(); + assertThatThrownBy(() -> { + dblgpc.getAsPropertyMap(); + }).hasMessage("could not convert content to a property map"); + } } diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/concepts/TestPojos.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/concepts/TestPojos.java index f35a4e668..26077189e 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/concepts/TestPojos.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/concepts/TestPojos.java @@ -44,9 +44,19 @@ public class TestPojos { @Test public void testPojos() { - final Validator validator = ValidatorBuilder.create().with(new ToStringTester()) - .with(new SetterMustExistRule()).with(new GetterMustExistRule()).with(new SetterTester()) - .with(new GetterTester()).build(); - validator.validate(POJO_PACKAGE, new FilterPackageInfo()); + // @formatter:off + final Validator validator = ValidatorBuilder + .create() + .with(new ToStringTester()) + .with(new SetterMustExistRule()) + .with(new GetterMustExistRule()) + .with(new SetterTester()) + .with(new GetterTester()) + .build(); + validator.validate(POJO_PACKAGE, + new FilterPackageInfo() + ); + + // @formatter:on } } diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/concepts/testconcepts/DummyBadLegacyGuardPolicyContent.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/concepts/testconcepts/DummyBadLegacyGuardPolicyContent.java new file mode 100644 index 000000000..1b149416c --- /dev/null +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/concepts/testconcepts/DummyBadLegacyGuardPolicyContent.java @@ -0,0 +1,34 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 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.legacy.concepts.testconcepts; + +import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyContent; + +/** + * Dummy {@link LegacyGuardPolicyContent} class to force exception for testing. + * + * @author Liam Fallon (liam.fallon@est.tech) + */ +public class DummyBadLegacyGuardPolicyContent extends LegacyGuardPolicyContent { + public static final String TO_TRIGGER_EXCEPTION = "Dummy"; + @SuppressWarnings("unused") + private final transient String aaa = "aaa"; +} diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/mapping/LegacyGuardPolicyMapperTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/mapping/LegacyGuardPolicyMapperTest.java new file mode 100644 index 000000000..b1dac8f20 --- /dev/null +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/mapping/LegacyGuardPolicyMapperTest.java @@ -0,0 +1,52 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 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.legacy.mapping; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import org.junit.Test; +import org.onap.policy.models.base.PfConceptKey; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicies; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaTopologyTemplate; + +/** + * Test the {@link LegacyGuardPolicyMapper} class. + * + * @author Liam Fallon (liam.fallon@est.tech) + */ +public class LegacyGuardPolicyMapperTest { + + @Test + public void testLegacyGuardPolicyMapper() { + JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate(); + serviceTemplate.setTopologyTemplate(new JpaToscaTopologyTemplate()); + serviceTemplate.getTopologyTemplate().setPolicies(new JpaToscaPolicies()); + + JpaToscaPolicy policy = new JpaToscaPolicy(new PfConceptKey("PolicyName", "0.0.1")); + serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().put(policy.getKey(), policy); + + assertThatThrownBy(() -> { + new LegacyGuardPolicyMapper().fromToscaServiceTemplate(serviceTemplate); + }).hasMessageContaining("no properties defined on TOSCA policy"); + } +} diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/serialization/LegacyOperationalPolicySerializationTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/mapping/LegacyOperationalPolicyMapperTest.java index 26242611b..4df62aff0 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/serialization/LegacyOperationalPolicySerializationTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/mapping/LegacyOperationalPolicyMapperTest.java @@ -18,20 +18,27 @@ * ============LICENSE_END========================================================= */ -package org.onap.policy.models.tosca.legacy.serialization; +package org.onap.policy.models.tosca.legacy.mapping; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import java.util.LinkedHashMap; + import org.junit.Before; import org.junit.Test; import org.onap.policy.common.utils.coder.StandardCoder; import org.onap.policy.common.utils.resources.ResourceUtils; +import org.onap.policy.models.base.PfConceptKey; import org.onap.policy.models.base.PfValidationResult; import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy; import org.onap.policy.models.tosca.legacy.mapping.LegacyOperationalPolicyMapper; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicies; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy; import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaTopologyTemplate; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -40,9 +47,9 @@ import org.slf4j.LoggerFactory; * * @author Liam Fallon (liam.fallon@est.tech) */ -public class LegacyOperationalPolicySerializationTest { +public class LegacyOperationalPolicyMapperTest { // Logger for this class - private static final Logger LOGGER = LoggerFactory.getLogger(LegacyOperationalPolicySerializationTest.class); + private static final Logger LOGGER = LoggerFactory.getLogger(LegacyOperationalPolicyMapperTest.class); private StandardCoder standardCoder; @@ -68,4 +75,31 @@ public class LegacyOperationalPolicySerializationTest { assertEquals("operational.restart:1.0.0", serviceTemplate.getTopologyTemplate().getPolicies().get("operational.restart").getId()); } + + @Test + public void testOperationalPolicyMapper() throws Exception { + JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate(); + serviceTemplate.setTopologyTemplate(new JpaToscaTopologyTemplate()); + serviceTemplate.getTopologyTemplate().setPolicies(new JpaToscaPolicies()); + + JpaToscaPolicy policy0 = new JpaToscaPolicy(new PfConceptKey("PolicyName0", "0.0.1")); + serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().put(policy0.getKey(), policy0); + JpaToscaPolicy policy1 = new JpaToscaPolicy(new PfConceptKey("PolicyName1", "0.0.1")); + serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().put(policy1.getKey(), policy1); + + assertThatThrownBy(() -> { + new LegacyOperationalPolicyMapper().fromToscaServiceTemplate(serviceTemplate); + }).hasMessage("more than one policy found in service template"); + + serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().remove(policy1.getKey()); + + assertThatThrownBy(() -> { + new LegacyOperationalPolicyMapper().fromToscaServiceTemplate(serviceTemplate); + }).hasMessage("no properties defined on TOSCA policy"); + + policy0.setProperties(new LinkedHashMap<>()); + assertThatThrownBy(() -> { + new LegacyOperationalPolicyMapper().fromToscaServiceTemplate(serviceTemplate); + }).hasMessage("property \"content\" not defined on TOSCA policy"); + } } diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogicalTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogicalTest.java index de0c813e2..d3239da73 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogicalTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogicalTest.java @@ -21,44 +21,55 @@ package org.onap.policy.models.tosca.simple.concepts; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNull; + +import java.util.ArrayList; import org.junit.Test; -import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraintLogical; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConstraint; /** - * DAO test for ToscaConstraintLogicalString. + * Test the {@link JpaToscaConstraintLogical} class. * * @author Liam Fallon (liam.fallon@est.tech) */ public class JpaToscaConstraintLogicalTest { @Test - public void testConstraintLogicalStringPojo() { - assertNotNull(new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, "Constraint")); + public void testLogicalConstraint() { + ToscaConstraint c0 = new ToscaConstraint(); + c0.setEqual("Hello"); + JpaToscaConstraintLogical jc0 = new JpaToscaConstraintLogical(c0); + assertEquals(c0, jc0.toAuthorative()); + + ToscaConstraint c1 = new ToscaConstraint(); + c1.setGreaterOrEqual("Hello"); + JpaToscaConstraintLogical jc1 = new JpaToscaConstraintLogical(c1); + assertEquals(c1, jc1.toAuthorative()); + + ToscaConstraint c2 = new ToscaConstraint(); + c2.setGreaterThan("Hello"); + JpaToscaConstraintLogical jc2 = new JpaToscaConstraintLogical(c2); + assertEquals(c2, jc2.toAuthorative()); - try { - new JpaToscaConstraintLogical((JpaToscaConstraintOperation) null, null); - fail("test should throw an exception"); - } catch (Exception exc) { - assertEquals("operation is marked @NonNull but is null", exc.getMessage()); - } + ToscaConstraint c3 = new ToscaConstraint(); + c3.setLessOrEqual("Hello"); + JpaToscaConstraintLogical jc3 = new JpaToscaConstraintLogical(c3); + assertEquals(c3, jc3.toAuthorative()); - try { - new JpaToscaConstraintLogical((JpaToscaConstraintOperation) null, "Hello"); - fail("test should throw an exception"); - } catch (Exception exc) { - assertEquals("operation is marked @NonNull but is null", exc.getMessage()); - } + ToscaConstraint c4 = new ToscaConstraint(); + c4.setLessThan("Hello"); + JpaToscaConstraintLogical jc4 = new JpaToscaConstraintLogical(c4); + assertEquals(c4, jc4.toAuthorative()); - try { - new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, null); - fail("test should throw an exception"); - } catch (Exception exc) { - assertEquals("compareTo is marked @NonNull but is null", exc.getMessage()); - } + ToscaConstraint c5 = new ToscaConstraint(); + JpaToscaConstraintLogical jc5 = new JpaToscaConstraintLogical(c5); + assertNull(jc5.toAuthorative()); - assertNotNull(new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, "Constraint")); + assertEquals(-1, jc0.compareTo(null)); + assertEquals(0, jc0.compareTo(jc0)); + assertNotEquals(0, jc0.compareTo(new JpaToscaConstraintValidValues(new ArrayList<>()))); + assertEquals(-2, jc0.compareTo(jc1)); } } diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintTest.java new file mode 100644 index 000000000..ff4187a47 --- /dev/null +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintTest.java @@ -0,0 +1,88 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 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.simple.concepts; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConstraint; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraintLogical; + +/** + * DAO test for ToscaConstraintLogicalString. + * + * @author Liam Fallon (liam.fallon@est.tech) + */ +public class JpaToscaConstraintTest { + + @Test + public void testConstraintLogicalStringPojo() { + assertNotNull(new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, "Constraint")); + + try { + new JpaToscaConstraintLogical((JpaToscaConstraintOperation) null, null); + fail("test should throw an exception"); + } catch (Exception exc) { + assertEquals("operation is marked @NonNull but is null", exc.getMessage()); + } + + try { + new JpaToscaConstraintLogical((JpaToscaConstraintOperation) null, "Hello"); + fail("test should throw an exception"); + } catch (Exception exc) { + assertEquals("operation is marked @NonNull but is null", exc.getMessage()); + } + + try { + new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, null); + fail("test should throw an exception"); + } catch (Exception exc) { + assertEquals("compareTo is marked @NonNull but is null", exc.getMessage()); + } + + assertNotNull(new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, "Constraint")); + + assertEquals(0, new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, "") + .compareTo(new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, ""))); + + JpaToscaConstraintOperation op = JpaToscaConstraintOperation.EQ; + assertEquals("equal_to", op.getToscaToken()); + + List<String> validValues = new ArrayList<>(); + validValues.add("hello"); + validValues.add("goodbye"); + JpaToscaConstraintValidValues cvv0 = new JpaToscaConstraintValidValues(validValues); + assertEquals(-1, cvv0.compareTo(null)); + assertEquals(0, cvv0.compareTo(cvv0)); + assertNotEquals(0, cvv0.compareTo(new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, "Constraint"))); + JpaToscaConstraintValidValues cvv1 = new JpaToscaConstraintValidValues(validValues); + assertEquals(0, cvv0.compareTo(cvv1)); + + cvv1.fromAuthorative(new ToscaConstraint()); + assertNotNull(cvv1.getValidValues()); + } +} diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataTypeTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataTypeTest.java index efdddccb0..66cde51fc 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataTypeTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataTypeTest.java @@ -20,11 +20,11 @@ package org.onap.policy.models.tosca.simple.concepts; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; import java.util.ArrayList; import java.util.LinkedHashMap; @@ -35,6 +35,8 @@ import org.junit.Test; import org.onap.policy.models.base.PfConceptKey; import org.onap.policy.models.base.PfReferenceKey; import org.onap.policy.models.base.PfValidationResult; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConstraint; +import org.onap.policy.models.tosca.authorative.concepts.ToscaDataType; import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraint; import org.onap.policy.models.tosca.simple.concepts.JpaToscaDataType; import org.onap.policy.models.tosca.simple.concepts.JpaToscaProperty; @@ -51,20 +53,15 @@ public class JpaToscaDataTypeTest { assertNotNull(new JpaToscaDataType()); assertNotNull(new JpaToscaDataType(new PfConceptKey())); assertNotNull(new JpaToscaDataType(new JpaToscaDataType())); + assertNotNull(new JpaToscaDataType(new ToscaDataType())); - try { + assertThatThrownBy(() -> { new JpaToscaDataType((PfConceptKey) null); - fail("test should throw an exception"); - } catch (Exception exc) { - assertEquals("key is marked @NonNull but is null", exc.getMessage()); - } + }).hasMessage("key is marked @NonNull but is null"); - try { + assertThatThrownBy(() -> { new JpaToscaDataType((JpaToscaDataType) null); - fail("test should throw an exception"); - } catch (Exception exc) { - assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage()); - } + }).hasMessage("copyConcept is marked @NonNull but is null"); PfConceptKey dtKey = new PfConceptKey("tdt", "0.0.1"); JpaToscaDataType tdt = new JpaToscaDataType(dtKey); @@ -105,12 +102,9 @@ public class JpaToscaDataTypeTest { otherDt.setProperties(properties); assertEquals(0, tdt.compareTo(otherDt)); - try { + assertThatThrownBy(() -> { tdt.copyTo(null); - fail("test should throw an exception"); - } catch (Exception exc) { - assertEquals("target is marked @NonNull but is null", exc.getMessage()); - } + }).hasMessage("target is marked @NonNull but is null"); assertEquals(3, tdt.getKeys().size()); assertEquals(1, new JpaToscaDataType().getKeys().size()); @@ -132,12 +126,23 @@ public class JpaToscaDataTypeTest { tdt.getProperties().remove(null); assertTrue(tdt.validate(new PfValidationResult()).isValid()); - try { + assertThatThrownBy(() -> { tdt.validate(null); - fail("test should throw an exception"); - } catch (Exception exc) { - assertEquals("resultIn is marked @NonNull but is null", exc.getMessage()); - } - + }).hasMessage("resultIn is marked @NonNull but is null"); + + ToscaDataType dat = new ToscaDataType(); + dat.setName("name"); + dat.setVersion("1.2.3"); + dat.setConstraints(new ArrayList<>()); + ToscaConstraint constraint = new ToscaConstraint(); + constraint.setEqual("EqualTo"); + dat.getConstraints().add(constraint); + + JpaToscaDataType tdta = new JpaToscaDataType(); + tdta.fromAuthorative(dat); + assertEquals("name", tdta.getKey().getName()); + + ToscaDataType datOut = tdta.toAuthorative(); + assertNotNull(datOut); } } diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataTypesTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataTypesTest.java index ce90e372c..c732fa604 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataTypesTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataTypesTest.java @@ -24,10 +24,15 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.fail; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; import java.util.TreeMap; import org.junit.Test; import org.onap.policy.models.base.PfConceptKey; +import org.onap.policy.models.tosca.authorative.concepts.ToscaDataType; import org.onap.policy.models.tosca.simple.concepts.JpaToscaDataType; import org.onap.policy.models.tosca.simple.concepts.JpaToscaDataTypes; @@ -74,5 +79,10 @@ public class JpaToscaDataTypesTest { } catch (Exception exc) { assertEquals("key is marked @NonNull but is null", exc.getMessage()); } + + List<Map<String, ToscaDataType>> dtMapList = new ArrayList<>(); + dtMapList.add(new LinkedHashMap<>()); + dtMapList.get(0).put("policyType", new ToscaDataType()); + assertNotNull(new JpaToscaDataTypes(dtMapList)); } } diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPoliciesTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPoliciesTest.java index 6f6141c5b..db3635ecb 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPoliciesTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPoliciesTest.java @@ -24,10 +24,15 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.fail; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; import java.util.TreeMap; import org.junit.Test; import org.onap.policy.models.base.PfConceptKey; +import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicies; import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy; @@ -74,5 +79,10 @@ public class JpaToscaPoliciesTest { } catch (Exception exc) { assertEquals("key is marked @NonNull but is null", exc.getMessage()); } + + List<Map<String, ToscaPolicy>> polMapList = new ArrayList<>(); + polMapList.add(new LinkedHashMap<>()); + polMapList.get(0).put("policyType", new ToscaPolicy()); + assertNotNull(new JpaToscaPolicies(polMapList)); } } diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTest.java index ec8e6da8f..571cde485 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTest.java @@ -20,11 +20,11 @@ package org.onap.policy.models.tosca.simple.concepts; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; import java.util.ArrayList; import java.util.HashMap; @@ -33,7 +33,9 @@ import java.util.Map; import org.junit.Test; import org.onap.policy.models.base.PfConceptKey; +import org.onap.policy.models.base.PfKey; import org.onap.policy.models.base.PfValidationResult; +import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy; /** @@ -50,40 +52,29 @@ public class JpaToscaPolicyTest { assertNotNull(new JpaToscaPolicy(new PfConceptKey(), new PfConceptKey())); assertNotNull(new JpaToscaPolicy(new JpaToscaPolicy())); - try { + ToscaPolicy pol = new ToscaPolicy(); + pol.setType("type"); + assertNotNull(new JpaToscaPolicy(pol)); + + assertThatThrownBy(() -> { new JpaToscaPolicy((PfConceptKey) null); - fail("test should throw an exception"); - } catch (Exception exc) { - assertEquals("key is marked @NonNull but is null", exc.getMessage()); - } + }).hasMessage("key is marked @NonNull but is null"); - try { + assertThatThrownBy(() -> { new JpaToscaPolicy(null, null); - fail("test should throw an exception"); - } catch (Exception exc) { - assertEquals("key is marked @NonNull but is null", exc.getMessage()); - } + }).hasMessage("key is marked @NonNull but is null"); - try { + assertThatThrownBy(() -> { new JpaToscaPolicy(new PfConceptKey(), null); - fail("test should throw an exception"); - } catch (Exception exc) { - assertEquals("type is marked @NonNull but is null", exc.getMessage()); - } + }).hasMessage("type is marked @NonNull but is null"); - try { + assertThatThrownBy(() -> { new JpaToscaPolicy(null, new PfConceptKey()); - fail("test should throw an exception"); - } catch (Exception exc) { - assertEquals("key is marked @NonNull but is null", exc.getMessage()); - } + }).hasMessage("key is marked @NonNull but is null"); - try { + assertThatThrownBy(() -> { new JpaToscaPolicy((JpaToscaPolicy) null); - fail("test should throw an exception"); - } catch (Exception exc) { - assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage()); - } + }).hasMessage("copyConcept is marked @NonNull but is null"); PfConceptKey tpKey = new PfConceptKey("tdt", "0.0.1"); PfConceptKey ptKey = new PfConceptKey("policyType", "0.0.1"); @@ -126,12 +117,9 @@ public class JpaToscaPolicyTest { otherDt.setTargets(targets); assertEquals(0, tp.compareTo(otherDt)); - try { + assertThatThrownBy(() -> { tp.copyTo(null); - fail("test should throw an exception"); - } catch (Exception exc) { - assertEquals("target is marked @NonNull but is null", exc.getMessage()); - } + }).hasMessage("target is marked @NonNull but is null"); assertEquals(3, tp.getKeys().size()); assertEquals(2, new JpaToscaPolicy().getKeys().size()); @@ -164,11 +152,35 @@ public class JpaToscaPolicyTest { tp.getTargets().remove(null); assertTrue(tp.validate(new PfValidationResult()).isValid()); - try { + PfConceptKey tpTypeKey = tp.getKey(); + assertNotNull(tpTypeKey); + tp.setType(null); + assertFalse(tp.validate(new PfValidationResult()).isValid()); + tp.setType(PfConceptKey.getNullKey()); + assertFalse(tp.validate(new PfValidationResult()).isValid()); + tp.setType(tpTypeKey); + assertTrue(tp.validate(new PfValidationResult()).isValid()); + + assertThatThrownBy(() -> { tp.validate(null); - fail("test should throw an exception"); - } catch (Exception exc) { - assertEquals("resultIn is marked @NonNull but is null", exc.getMessage()); - } + }).hasMessage("resultIn is marked @NonNull but is null"); + + assertNotNull(tp.toAuthorative()); + tp.getType().setVersion(PfKey.NULL_KEY_VERSION); + assertNotNull(tp.toAuthorative()); + tp.setProperties(null); + assertNotNull(tp.toAuthorative()); + + assertThatThrownBy(() -> { + tp.fromAuthorative(null); + }).hasMessage("toscaPolicy is marked @NonNull but is null"); + + pol = new ToscaPolicy(); + pol.setName("policy"); + pol.setVersion("1.2.3"); + pol.setType("poltype"); + pol.setTypeVersion("2.2.3"); + tp.fromAuthorative(pol); + assertEquals("2.2.3", tp.getType().getVersion()); } -}
\ No newline at end of file +} diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypeTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypeTest.java index 870640e75..3cdcd9552 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypeTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypeTest.java @@ -37,6 +37,7 @@ import org.onap.policy.models.base.PfConceptKey; import org.onap.policy.models.base.PfReferenceKey; import org.onap.policy.models.base.PfValidationResult; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; +import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType; import org.onap.policy.models.tosca.simple.concepts.JpaToscaEntityType; import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyType; import org.onap.policy.models.tosca.simple.concepts.JpaToscaProperty; @@ -209,5 +210,9 @@ public class JpaToscaPolicyTypeTest { assertEquals(-1, tet.compareTo(null)); assertEquals(0, tet.compareTo(tet)); assertFalse(tet.compareTo(tet.getKey()) == 0); + + assertNotNull(new JpaToscaPolicyType(new ToscaPolicyType())); + + assertNotNull(new JpaToscaEntityType<ToscaPolicyType>(new ToscaPolicyType())); } } diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypesTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypesTest.java index d0ea1782f..e02df235f 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypesTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypesTest.java @@ -24,10 +24,15 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.fail; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; import java.util.TreeMap; import org.junit.Test; import org.onap.policy.models.base.PfConceptKey; +import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType; import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyType; import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyTypes; @@ -74,5 +79,10 @@ public class JpaToscaPolicyTypesTest { } catch (Exception exc) { assertEquals("key is marked @NonNull but is null", exc.getMessage()); } + + List<Map<String, ToscaPolicyType>> ptMapList = new ArrayList<>(); + ptMapList.add(new LinkedHashMap<>()); + ptMapList.get(0).put("policyType", new ToscaPolicyType()); + assertNotNull(new JpaToscaPolicyTypes(ptMapList)); } } diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPropertyTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPropertyTest.java index b8766601b..706011bcf 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPropertyTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPropertyTest.java @@ -191,6 +191,8 @@ public class JpaToscaPropertyTest { tp.setDefaultValue(null); assertTrue(tp.validate(new PfValidationResult()).isValid()); + tp.setDefaultValue(""); + assertFalse(tp.validate(new PfValidationResult()).isValid()); tp.setDefaultValue("defaultKey"); assertTrue(tp.validate(new PfValidationResult()).isValid()); diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplatesTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplatesTest.java index 91d6d0bd3..354fe8b78 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplatesTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplatesTest.java @@ -20,14 +20,18 @@ package org.onap.policy.models.tosca.simple.concepts; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; import java.util.TreeMap; import org.junit.Test; import org.onap.policy.models.base.PfConceptKey; +import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate; import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplates; @@ -41,39 +45,29 @@ public class JpaToscaServiceTemplatesTest { new JpaToscaServiceTemplates(new PfConceptKey(), new TreeMap<PfConceptKey, JpaToscaServiceTemplate>())); assertNotNull(new JpaToscaServiceTemplates(new JpaToscaServiceTemplates())); - try { + assertThatThrownBy(() -> { new JpaToscaServiceTemplates((PfConceptKey) null); - fail("test should throw an exception"); - } catch (Exception exc) { - assertEquals("key is marked @NonNull but is null", exc.getMessage()); - } + }).hasMessage("key is marked @NonNull but is null"); - try { + assertThatThrownBy(() -> { new JpaToscaServiceTemplates((JpaToscaServiceTemplates) null); - fail("test should throw an exception"); - } catch (Exception exc) { - assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage()); - } + }).hasMessage("copyConcept is marked @NonNull but is null"); - try { + assertThatThrownBy(() -> { new JpaToscaServiceTemplates(null, null); - fail("test should throw an exception"); - } catch (Exception exc) { - assertEquals("key is marked @NonNull but is null", exc.getMessage()); - } + }).hasMessage("key is marked @NonNull but is null"); - try { + assertThatThrownBy(() -> { new JpaToscaServiceTemplates(new PfConceptKey(), null); - fail("test should throw an exception"); - } catch (Exception exc) { - assertEquals("conceptMap is marked @NonNull but is null", exc.getMessage()); - } + }).hasMessage("conceptMap is marked @NonNull but is null"); - try { + assertThatThrownBy(() -> { new JpaToscaServiceTemplates(null, new TreeMap<PfConceptKey, JpaToscaServiceTemplate>()); - fail("test should throw an exception"); - } catch (Exception exc) { - assertEquals("key is marked @NonNull but is null", exc.getMessage()); - } + }).hasMessage("key is marked @NonNull but is null"); + + List<Map<String, ToscaServiceTemplate>> tsMapList = new ArrayList<>(); + tsMapList.add(new LinkedHashMap<>()); + tsMapList.get(0).put("serviceTemplate", new ToscaServiceTemplate()); + assertNotNull(new JpaToscaServiceTemplates(tsMapList)); } } diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTopologyTemplateTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTopologyTemplateTest.java index 417f202f5..61ce3d077 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTopologyTemplateTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTopologyTemplateTest.java @@ -33,6 +33,7 @@ import org.junit.Test; import org.onap.policy.models.base.PfConceptKey; import org.onap.policy.models.base.PfReferenceKey; import org.onap.policy.models.base.PfValidationResult; +import org.onap.policy.models.tosca.authorative.concepts.ToscaTopologyTemplate; import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicies; import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy; import org.onap.policy.models.tosca.simple.concepts.JpaToscaTopologyTemplate; @@ -49,6 +50,7 @@ public class JpaToscaTopologyTemplateTest { assertNotNull(new JpaToscaTopologyTemplate()); assertNotNull(new JpaToscaTopologyTemplate(new PfReferenceKey())); assertNotNull(new JpaToscaTopologyTemplate(new JpaToscaTopologyTemplate())); + assertNotNull(new JpaToscaTopologyTemplate(new ToscaTopologyTemplate())); try { new JpaToscaTopologyTemplate((PfReferenceKey) null); @@ -121,6 +123,11 @@ public class JpaToscaTopologyTemplateTest { assertTrue(new JpaToscaTopologyTemplate().validate(new PfValidationResult()).isValid()); assertTrue(ttt.validate(new PfValidationResult()).isValid()); + ttt.setKey(PfReferenceKey.getNullKey()); + assertFalse(ttt.validate(new PfValidationResult()).isValid()); + ttt.setKey(tttKey); + assertTrue(ttt.validate(new PfValidationResult()).isValid()); + ttt.setDescription(null); assertTrue(ttt.validate(new PfValidationResult()).isValid()); ttt.setDescription(""); diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/TestPojos.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/TestPojos.java index e5be49860..edb6e2e58 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/TestPojos.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/TestPojos.java @@ -40,7 +40,6 @@ import org.onap.policy.common.utils.validation.ToStringTester; * */ public class TestPojos { - private static final String POJO_PACKAGE = "org.onap.policy.models.tosca.simple.concepts"; @Test diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/testconcepts/DummyToscaConstraint.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/testconcepts/DummyToscaConstraint.java index b13cb4b0b..f8e422160 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/testconcepts/DummyToscaConstraint.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/testconcepts/DummyToscaConstraint.java @@ -45,4 +45,9 @@ public class DummyToscaConstraint extends JpaToscaConstraint { @Override public void fromAuthorative(ToscaConstraint authorativeConcept) { } + + @Override + public int compareTo(JpaToscaConstraint otherConstraint) { + return 0; + } } diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProviderTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProviderTest.java index d94c39936..ddfb5676a 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProviderTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProviderTest.java @@ -20,6 +20,7 @@ package org.onap.policy.models.tosca.simple.provider; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; @@ -92,13 +93,6 @@ public class SimpleToscaProviderTest { @Test public void testPoliciesGet() throws Exception { - try { - new SimpleToscaProvider().getPolicies(null, null, null); - fail("test should throw an exception here"); - } catch (Exception exc) { - assertEquals("dao is marked @NonNull but is null", exc.getMessage()); - } - ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode( ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"), ToscaServiceTemplate.class); @@ -124,27 +118,6 @@ public class SimpleToscaProviderTest { @Test public void testPolicyCreate() throws Exception { - try { - new SimpleToscaProvider().createPolicies(null, null); - fail("test should throw an exception here"); - } catch (Exception exc) { - assertEquals("dao is marked @NonNull but is null", exc.getMessage()); - } - - try { - new SimpleToscaProvider().createPolicies(null, new JpaToscaServiceTemplate()); - fail("test should throw an exception here"); - } catch (Exception exc) { - assertEquals("dao is marked @NonNull but is null", exc.getMessage()); - } - - try { - new SimpleToscaProvider().createPolicies(pfDao, null); - fail("test should throw an exception here"); - } catch (Exception exc) { - assertEquals("serviceTemplate is marked @NonNull but is null", exc.getMessage()); - } - ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode( ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"), ToscaServiceTemplate.class); @@ -161,27 +134,6 @@ public class SimpleToscaProviderTest { @Test public void testPolicyUpdate() throws Exception { - try { - new SimpleToscaProvider().updatePolicies(null, null); - fail("test should throw an exception here"); - } catch (Exception exc) { - assertEquals("dao is marked @NonNull but is null", exc.getMessage()); - } - - try { - new SimpleToscaProvider().updatePolicies(null, new JpaToscaServiceTemplate()); - fail("test should throw an exception here"); - } catch (Exception exc) { - assertEquals("dao is marked @NonNull but is null", exc.getMessage()); - } - - try { - new SimpleToscaProvider().updatePolicies(pfDao, null); - fail("test should throw an exception here"); - } catch (Exception exc) { - assertEquals("serviceTemplate is marked @NonNull but is null", exc.getMessage()); - } - ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode( ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"), ToscaServiceTemplate.class); @@ -198,27 +150,6 @@ public class SimpleToscaProviderTest { @Test public void testPoliciesDelete() throws Exception { - try { - new SimpleToscaProvider().deletePolicy(null, null); - fail("test should throw an exception here"); - } catch (Exception exc) { - assertEquals("dao is marked @NonNull but is null", exc.getMessage()); - } - - try { - new SimpleToscaProvider().deletePolicy(null, new PfConceptKey()); - fail("test should throw an exception here"); - } catch (Exception exc) { - assertEquals("dao is marked @NonNull but is null", exc.getMessage()); - } - - try { - new SimpleToscaProvider().deletePolicy(pfDao, null); - fail("test should throw an exception here"); - } catch (Exception exc) { - assertEquals("policyKey is marked @NonNull but is null", exc.getMessage()); - } - ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode( ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"), ToscaServiceTemplate.class); @@ -271,6 +202,88 @@ public class SimpleToscaProviderTest { assertEquals("list of policies specified on topology template of service template is empty", exc.getMessage()); } + } + + @Test + public void testNonNulls() { + assertThatThrownBy(() -> { + new SimpleToscaProvider().getPolicyTypes(null, null, null); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new SimpleToscaProvider().createPolicyTypes(null, null); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new SimpleToscaProvider().createPolicyTypes(null, new JpaToscaServiceTemplate()); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new SimpleToscaProvider().createPolicyTypes(pfDao, null); + }).hasMessage("serviceTemplate is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new SimpleToscaProvider().updatePolicyTypes(null, null); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new SimpleToscaProvider().updatePolicyTypes(null, new JpaToscaServiceTemplate()); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new SimpleToscaProvider().updatePolicyTypes(pfDao, null); + }).hasMessage("serviceTemplate is marked @NonNull but is null"); + assertThatThrownBy(() -> { + new SimpleToscaProvider().deletePolicyType(null, null); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new SimpleToscaProvider().deletePolicyType(null, new PfConceptKey()); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new SimpleToscaProvider().deletePolicyType(pfDao, null); + }).hasMessage("policyTypeKey is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new SimpleToscaProvider().getPolicies(null, null, null); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new SimpleToscaProvider().createPolicies(null, null); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new SimpleToscaProvider().createPolicies(null, new JpaToscaServiceTemplate()); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new SimpleToscaProvider().createPolicies(pfDao, null); + }).hasMessage("serviceTemplate is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new SimpleToscaProvider().updatePolicies(null, null); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new SimpleToscaProvider().updatePolicies(null, new JpaToscaServiceTemplate()); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new SimpleToscaProvider().updatePolicies(pfDao, null); + }).hasMessage("serviceTemplate is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new SimpleToscaProvider().deletePolicy(null, null); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new SimpleToscaProvider().deletePolicy(null, new PfConceptKey()); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new SimpleToscaProvider().deletePolicy(pfDao, null); + }).hasMessage("policyKey is marked @NonNull but is null"); } } diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/utils/ToscaUtilsTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/utils/ToscaUtilsTest.java new file mode 100644 index 000000000..40a2fd29a --- /dev/null +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/utils/ToscaUtilsTest.java @@ -0,0 +1,45 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 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.utils; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import org.junit.Test; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyTypes; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate; + +/** + * Import the {@link ToscaUtils} class. + * + * @author Liam Fallon (liam.fallon@est.tech) + */ +public class ToscaUtilsTest { + + @Test + public void test() { + JpaToscaServiceTemplate jpaToscaServiceTemplate = new JpaToscaServiceTemplate(); + jpaToscaServiceTemplate.setPolicyTypes(new JpaToscaPolicyTypes()); + + assertThatThrownBy(() -> { + ToscaUtils.assertPolicyTypesExist(jpaToscaServiceTemplate); + }).hasMessage("list of policy types specified on service template is empty"); + } +} @@ -112,6 +112,11 @@ </dependency> <dependency> + <groupId>org.mariadb.jdbc</groupId> + <artifactId>mariadb-java-client</artifactId> + </dependency> + + <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <scope>test</scope> |