From e53df8d3f8ab0464b0876bdb339fa91dc9085cd2 Mon Sep 17 00:00:00 2001 From: liamfallon Date: Thu, 2 Feb 2023 14:43:12 +0000 Subject: Replace Eclipselink with Hibernate Issue-ID: POLICY-4533 Change-Id: I77a6c44c96013963e141265758629cae83e49876 Signed-off-by: liamfallon --- .../tosca/simple/concepts/JpaToscaEntityType.java | 9 +- .../tosca/simple/concepts/JpaToscaModel.java | 9 +- .../simple/concepts/JpaToscaNodeTemplate.java | 15 +- .../tosca/simple/concepts/JpaToscaNodeType.java | 9 +- .../simple/concepts/JpaToscaServiceTemplate.java | 43 ++-- .../simple/concepts/JpaToscaTopologyTemplate.java | 16 +- .../JpaToscaWithTypeAndStringProperties.java | 9 +- .../AuthorativeToscaProviderGenericTest.java | 51 +++-- .../AuthorativeToscaProviderNodeTemplateTest.java | 17 +- .../AuthorativeToscaProviderPolicyTest.java | 17 +- .../AuthorativeToscaProviderPolicyTypeTest.java | 17 +- .../simple/provider/SimpleToscaProviderTest.java | 233 +++++++++++++-------- .../SimpleToscaServiceTemplateProviderTest.java | 29 ++- .../src/test/resources/META-INF/persistence.xml | 22 +- 14 files changed, 284 insertions(+), 212 deletions(-) (limited to 'models-tosca') diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEntityType.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEntityType.java index 14c8ca4a3..b9acde26c 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEntityType.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEntityType.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019-2020,2022 Nordix Foundation. + * Copyright (C) 2019-2020,2022-2023 Nordix Foundation. * Modifications Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -26,6 +26,7 @@ import java.util.Map; import java.util.Map.Entry; import java.util.TreeMap; import javax.persistence.AttributeOverride; +import javax.persistence.AttributeOverrides; import javax.persistence.Column; import javax.persistence.ElementCollection; import javax.persistence.EmbeddedId; @@ -67,8 +68,10 @@ public class JpaToscaEntityType extends PfConcept impleme // @formatter:off @Column - @AttributeOverride(name = "name", column = @Column(name = "derived_from_name")) - @AttributeOverride(name = "version", column = @Column(name = "derived_from_version")) + @AttributeOverrides({ + @AttributeOverride(name = "name", column = @Column(name = "derived_from_name")), + @AttributeOverride(name = "version", column = @Column(name = "derived_from_version")) + }) @VerifyKey private PfConceptKey derivedFrom; diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaModel.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaModel.java index 09c406ea6..5f72e2ba8 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaModel.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaModel.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019-2020 Nordix Foundation. + * Copyright (C) 2019-2020,2023 Nordix Foundation. * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2022 Bell Canada. All rights reserved. * ================================================================================ @@ -29,6 +29,7 @@ import javax.persistence.FetchType; import javax.persistence.Inheritance; import javax.persistence.InheritanceType; import javax.persistence.JoinColumn; +import javax.persistence.JoinColumns; import javax.persistence.OneToOne; import javax.persistence.Table; import lombok.Data; @@ -57,8 +58,10 @@ public class JpaToscaModel extends PfModel { private static final long serialVersionUID = 8800599637708309945L; @OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true) - @JoinColumn(name = "serviceTemplatesName", referencedColumnName = "name") - @JoinColumn(name = "serviceTemplatesVersion", referencedColumnName = "version") + @JoinColumns({ + @JoinColumn(name = "serviceTemplatesName", referencedColumnName = "name"), + @JoinColumn(name = "serviceTemplatesVersion", referencedColumnName = "version") + }) @Valid private JpaToscaServiceTemplates serviceTemplates; diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaNodeTemplate.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaNodeTemplate.java index bd1dfd4d5..0a5f0c688 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaNodeTemplate.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaNodeTemplate.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2020-2021 Nordix Foundation. + * Copyright (C) 2020-2021,2023 Nordix Foundation. * Modifications Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -31,6 +31,7 @@ import javax.persistence.FetchType; import javax.persistence.Inheritance; import javax.persistence.InheritanceType; import javax.persistence.JoinColumn; +import javax.persistence.JoinColumns; import javax.persistence.OneToOne; import javax.persistence.Table; import javax.ws.rs.core.Response; @@ -63,14 +64,18 @@ public class JpaToscaNodeTemplate extends JpaToscaWithTypeAndStringProperties // formatter:off @OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true) - @JoinColumn(name = "requirementsName", referencedColumnName = "name") - @JoinColumn(name = "requirementsVersion", referencedColumnName = "version") + @JoinColumns({ + @JoinColumn(name = "requirementsName", referencedColumnName = "name"), + @JoinColumn(name = "requirementsVersion", referencedColumnName = "version") + }) // @formatter:on @Valid private JpaToscaRequirements requirements; diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplate.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplate.java index 769b623c7..109f1f0a8 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplate.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplate.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019-2021 Nordix Foundation. + * Copyright (C) 2019-2021,2023 Nordix Foundation. * Modifications Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -34,6 +34,7 @@ import javax.persistence.FetchType; import javax.persistence.Inheritance; import javax.persistence.InheritanceType; import javax.persistence.JoinColumn; +import javax.persistence.JoinColumns; import javax.persistence.OneToOne; import javax.persistence.Table; import lombok.Data; @@ -78,45 +79,57 @@ public class JpaToscaServiceTemplate extends JpaToscaEntityType inputs; @OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true) - @JoinColumn(name = "nodeTemplatesName", referencedColumnName = "name") - @JoinColumn(name = "nodeTemplatessVersion", referencedColumnName = "version") + @JoinColumns({ + @JoinColumn(name = "nodeTemplatesName", referencedColumnName = "name"), + @JoinColumn(name = "nodeTemplatessVersion", referencedColumnName = "version") + }) @SerializedName("data_types") @Valid private JpaToscaNodeTemplates nodeTemplates; @OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true) - @JoinColumn(name = "policyName", referencedColumnName = "name") - @JoinColumn(name = "policyVersion", referencedColumnName = "version") + @JoinColumns({ + @JoinColumn(name = "policyName", referencedColumnName = "name"), + @JoinColumn(name = "policyVersion", referencedColumnName = "version") + + }) // @formatter:on @Valid private JpaToscaPolicies policies; diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaWithTypeAndStringProperties.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaWithTypeAndStringProperties.java index 55acc0653..cb0ff4e5d 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaWithTypeAndStringProperties.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaWithTypeAndStringProperties.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2021 Nordix Foundation. + * Modifications Copyright (C) 2021,2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,6 +25,7 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import javax.persistence.AttributeOverride; +import javax.persistence.AttributeOverrides; import javax.persistence.Column; import javax.persistence.ElementCollection; import javax.persistence.Lob; @@ -56,8 +57,10 @@ public abstract class JpaToscaWithTypeAndStringProperties gotServiceTemplateList = - new AuthorativeToscaProvider().getServiceTemplateList(pfDao, null, null); + new AuthorativeToscaProvider().getServiceTemplateList(pfDao, null, null); ToscaPolicyType gotPolicyType = gotServiceTemplateList.get(0).getPolicyTypes().get(policyTypeKey.getName()); assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName())); assertEquals(0, ObjectUtils.compare(beforePolicyType.getDescription(), createdPolicyType.getDescription())); List gotPolicyTypeList = - new AuthorativeToscaProvider().getPolicyTypeList(pfDao, POLICY_NO_VERSION, VERSION_001); + new AuthorativeToscaProvider().getPolicyTypeList(pfDao, POLICY_NO_VERSION, VERSION_001); assertEquals(2, gotPolicyTypeList.size()); assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName())); @@ -161,48 +158,48 @@ public class AuthorativeToscaProviderGenericTest { assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName())); assertThatThrownBy(() -> new AuthorativeToscaProvider().getPolicyTypeList(new DefaultPfDao(), POLICY_NO_VERSION, - VERSION_001)).hasMessageContaining("Policy Framework DAO has not been initialized"); + VERSION_001)).hasMessageContaining("Policy Framework DAO has not been initialized"); assertTrue(new AuthorativeToscaProvider().getPolicyTypeList(pfDao, "i.dont.Exist", VERSION_001).isEmpty()); ToscaServiceTemplate deletedServiceTemplate = - new AuthorativeToscaProvider().deleteServiceTemplate(pfDao, "Dummy", "0.0.1"); + new AuthorativeToscaProvider().deleteServiceTemplate(pfDao, "Dummy", "0.0.1"); assertEquals(2, deletedServiceTemplate.getPolicyTypes().size()); } @Test public void testNullParameters() throws Exception { assertThatThrownBy(() -> new AuthorativeToscaProvider().getServiceTemplateList(null, null, null)) - .hasMessageMatching("^dao is marked .*on.*ull but is null$"); + .hasMessageMatching("^dao is marked .*on.*ull but is null$"); assertThatThrownBy(() -> new AuthorativeToscaProvider().createServiceTemplate(null, null)) - .hasMessageMatching("^dao is marked .*on.*ull but is null$"); + .hasMessageMatching("^dao is marked .*on.*ull but is null$"); assertThatThrownBy(() -> new AuthorativeToscaProvider().createServiceTemplate(pfDao, null)) - .hasMessageMatching("^serviceTemplate is marked .*on.*ull but is null$"); + .hasMessageMatching("^serviceTemplate is marked .*on.*ull but is null$"); assertThatThrownBy(() -> new AuthorativeToscaProvider().createServiceTemplate(null, new ToscaServiceTemplate())) - .hasMessageMatching("^dao is marked .*on.*ull but is null$"); + .hasMessageMatching("^dao is marked .*on.*ull but is null$"); assertThatThrownBy(() -> new AuthorativeToscaProvider().deleteServiceTemplate(null, null, null)) - .hasMessageMatching("^dao is marked .*on.*ull but is null$"); + .hasMessageMatching("^dao is marked .*on.*ull but is null$"); assertThatThrownBy(() -> new AuthorativeToscaProvider().deleteServiceTemplate(null, null, "0.0.1")) - .hasMessageMatching("^dao is marked .*on.*ull but is null$"); + .hasMessageMatching("^dao is marked .*on.*ull but is null$"); assertThatThrownBy(() -> new AuthorativeToscaProvider().deleteServiceTemplate(null, "Dummy", null)) - .hasMessageMatching("^dao is marked .*on.*ull but is null$"); + .hasMessageMatching("^dao is marked .*on.*ull but is null$"); assertThatThrownBy(() -> new AuthorativeToscaProvider().deleteServiceTemplate(null, "Dummy", "0.0.1")) - .hasMessageMatching("^dao is marked .*on.*ull but is null$"); + .hasMessageMatching("^dao is marked .*on.*ull but is null$"); assertThatThrownBy(() -> new AuthorativeToscaProvider().deleteServiceTemplate(pfDao, null, null)) - .hasMessageMatching("^name is marked .*on.*ull but is null$"); + .hasMessageMatching("^name is marked .*on.*ull but is null$"); assertThatThrownBy(() -> new AuthorativeToscaProvider().deleteServiceTemplate(pfDao, null, "0.0.1")) - .hasMessageMatching("^name is marked .*on.*ull but is null$"); + .hasMessageMatching("^name is marked .*on.*ull but is null$"); assertThatThrownBy(() -> new AuthorativeToscaProvider().deleteServiceTemplate(pfDao, "Dummy", null)) - .hasMessageMatching("^version is marked .*on.*ull but is null$"); + .hasMessageMatching("^version is marked .*on.*ull but is null$"); } } diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderNodeTemplateTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderNodeTemplateTest.java index cc034d8fb..64c164796 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderNodeTemplateTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderNodeTemplateTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2022 Nordix Foundation. + * Copyright (C) 2022-2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,7 +29,6 @@ import static org.junit.Assert.assertTrue; import java.util.List; import java.util.Map; import java.util.Properties; -import org.eclipse.persistence.config.PersistenceUnitProperties; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -96,18 +95,16 @@ public class AuthorativeToscaProviderNodeTemplateTest { daoParameters.setPersistenceUnit("ToscaConceptTest"); Properties jdbcProperties = new Properties(); - jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_USER, "policy"); - jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_PASSWORD, "P01icY"); - + jdbcProperties.setProperty("javax.persistence.jdbc.user", "policy"); + jdbcProperties.setProperty("javax.persistence.jdbc.password", "P01icY"); if (System.getProperty("USE-MARIADB") != null) { - jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_DRIVER, "org.mariadb.jdbc.Driver"); - jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_URL, "jdbc:mariadb://localhost:3306/policy"); + jdbcProperties.setProperty("javax.persistence.jdbc.driver", "org.mariadb.jdbc.Driver"); + jdbcProperties.setProperty("javax.persistence.jdbc.url", "jdbc:mariadb://localhost:3306/policy"); } else { - jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_DRIVER, "org.h2.Driver"); - jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_URL, + jdbcProperties.setProperty("javax.persistence.jdbc.driver", "org.h2.Driver"); + jdbcProperties.setProperty("javax.persistence.jdbc.url", "jdbc:h2:mem:AuthorativeToscaProviderNodeTemplatesTest"); } - daoParameters.setJdbcProperties(jdbcProperties); pfDao = new PfDaoFactory().createPfDao(daoParameters); 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 250b3e2ee..954f21eec 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderPolicyTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderPolicyTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019-2021 Nordix Foundation. + * Copyright (C) 2019-2021,2023 Nordix Foundation. * Modifications Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -30,7 +30,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Properties; -import org.eclipse.persistence.config.PersistenceUnitProperties; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -78,18 +77,16 @@ public class AuthorativeToscaProviderPolicyTest { daoParameters.setPersistenceUnit("ToscaConceptTest"); Properties jdbcProperties = new Properties(); - jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_USER, "policy"); - jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_PASSWORD, "P01icY"); - + jdbcProperties.setProperty("javax.persistence.jdbc.user", "policy"); + jdbcProperties.setProperty("javax.persistence.jdbc.password", "P01icY"); if (System.getProperty("USE-MARIADB") != null) { - jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_DRIVER, "org.mariadb.jdbc.Driver"); - jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_URL, "jdbc:mariadb://localhost:3306/policy"); + jdbcProperties.setProperty("javax.persistence.jdbc.driver", "org.mariadb.jdbc.Driver"); + jdbcProperties.setProperty("javax.persistence.jdbc.url", "jdbc:mariadb://localhost:3306/policy"); } else { - jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_DRIVER, "org.h2.Driver"); - jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_URL, + jdbcProperties.setProperty("javax.persistence.jdbc.driver", "org.h2.Driver"); + jdbcProperties.setProperty("javax.persistence.jdbc.url", "jdbc:h2:mem:AuthorativeToscaProviderPolicyTest"); } - daoParameters.setJdbcProperties(jdbcProperties); pfDao = new PfDaoFactory().createPfDao(daoParameters); 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 fff1aca50..3511bc8fa 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderPolicyTypeTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderPolicyTypeTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019-2021 Nordix Foundation. + * Copyright (C) 2019-2021,2023 Nordix Foundation. * Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -31,7 +31,6 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Properties; import org.apache.commons.lang3.ObjectUtils; -import org.eclipse.persistence.config.PersistenceUnitProperties; import org.junit.After; import org.junit.Before; import org.junit.BeforeClass; @@ -89,18 +88,16 @@ public class AuthorativeToscaProviderPolicyTypeTest { daoParameters.setPersistenceUnit("ToscaConceptTest"); Properties jdbcProperties = new Properties(); - jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_USER, "policy"); - jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_PASSWORD, "P01icY"); - + jdbcProperties.setProperty("javax.persistence.jdbc.user", "policy"); + jdbcProperties.setProperty("javax.persistence.jdbc.password", "P01icY"); if (System.getProperty("USE-MARIADB") != null) { - jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_DRIVER, "org.mariadb.jdbc.Driver"); - jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_URL, "jdbc:mariadb://localhost:3306/policy"); + jdbcProperties.setProperty("javax.persistence.jdbc.driver", "org.mariadb.jdbc.Driver"); + jdbcProperties.setProperty("javax.persistence.jdbc.url", "jdbc:mariadb://localhost:3306/policy"); } else { - jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_DRIVER, "org.h2.Driver"); - jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_URL, + jdbcProperties.setProperty("javax.persistence.jdbc.driver", "org.h2.Driver"); + jdbcProperties.setProperty("javax.persistence.jdbc.url", "jdbc:h2:mem:AuthorativeToscaProviderPolicyTypeTest"); } - daoParameters.setJdbcProperties(jdbcProperties); pfDao = new PfDaoFactory().createPfDao(daoParameters); 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 55cd11e40..2382c5a03 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 @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019-2021 Nordix Foundation. + * Copyright (C) 2019-2021,2023 Nordix Foundation. * Modifications Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -26,9 +26,10 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; +import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.Properties; -import org.eclipse.persistence.config.PersistenceUnitProperties; +import java.util.TreeMap; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -46,6 +47,7 @@ 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.ToscaServiceTemplate; import org.onap.policy.models.tosca.authorative.provider.AuthorativeToscaProvider; +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.JpaToscaDataTypes; import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicies; @@ -55,6 +57,7 @@ import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyTypes; import org.onap.policy.models.tosca.simple.concepts.JpaToscaProperty; import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate; import org.onap.policy.models.tosca.simple.concepts.JpaToscaTopologyTemplate; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaTrigger; import org.yaml.snakeyaml.Yaml; /** @@ -84,15 +87,15 @@ public class SimpleToscaProviderTest { daoParameters.setPersistenceUnit("ToscaConceptTest"); Properties jdbcProperties = new Properties(); - jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_USER, "policy"); - jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_PASSWORD, "P01icY"); + jdbcProperties.setProperty("javax.persistence.jdbc.user", "policy"); + jdbcProperties.setProperty("javax.persistence.jdbc.password", "P01icY"); if (System.getProperty("USE-MARIADB") != null) { - jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_DRIVER, "org.mariadb.jdbc.Driver"); - jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_URL, "jdbc:mariadb://localhost:3306/policy"); + jdbcProperties.setProperty("javax.persistence.jdbc.driver", "org.mariadb.jdbc.Driver"); + jdbcProperties.setProperty("javax.persistence.jdbc.url", "jdbc:mariadb://localhost:3306/policy"); } else { - jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_DRIVER, "org.h2.Driver"); - jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_URL, "jdbc:h2:mem:SimpleToscaProviderTest"); + jdbcProperties.setProperty("javax.persistence.jdbc.driver", "org.h2.Driver"); + jdbcProperties.setProperty("javax.persistence.jdbc.url", "jdbc:h2:mem:SimpleToscaProviderTest"); } daoParameters.setJdbcProperties(jdbcProperties); @@ -116,16 +119,19 @@ public class SimpleToscaProviderTest { @Test public void testCreateUpdateGetDeleteDataType() throws PfModelException { - JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate(); - PfConceptKey dataType0Key = new PfConceptKey("DataType0", "0.0.1"); JpaToscaDataType dataType0 = new JpaToscaDataType(); dataType0.setKey(dataType0Key); + dataType0.setConstraints(new ArrayList()); + dataType0.setMetadata(new TreeMap()); + dataType0.setProperties(new LinkedHashMap()); + + JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate(); serviceTemplate.setDataTypes(new JpaToscaDataTypes()); serviceTemplate.getDataTypes().getConceptMap().put(dataType0Key, dataType0); JpaToscaServiceTemplate createdServiceTemplate = - new SimpleToscaProvider().createDataTypes(pfDao, serviceTemplate); + new SimpleToscaProvider().createDataTypes(pfDao, serviceTemplate); assertEquals(1, createdServiceTemplate.getDataTypes().getConceptMap().size()); assertEquals(dataType0, createdServiceTemplate.getDataTypes().get(dataType0Key)); @@ -134,19 +140,19 @@ public class SimpleToscaProviderTest { dataType0.setDescription("Updated Description"); JpaToscaServiceTemplate updatedServiceTemplate = - new SimpleToscaProvider().updateDataTypes(pfDao, serviceTemplate); + new SimpleToscaProvider().updateDataTypes(pfDao, serviceTemplate); assertEquals(dataType0, updatedServiceTemplate.getDataTypes().get(dataType0Key)); assertEquals("Updated Description", updatedServiceTemplate.getDataTypes().get(dataType0Key).getDescription()); JpaToscaServiceTemplate gotServiceTemplate = - new SimpleToscaProvider().getDataTypes(pfDao, dataType0Key.getName(), dataType0Key.getVersion()); + new SimpleToscaProvider().getDataTypes(pfDao, dataType0Key.getName(), dataType0Key.getVersion()); assertEquals(dataType0, gotServiceTemplate.getDataTypes().get(dataType0Key)); assertEquals("Updated Description", gotServiceTemplate.getDataTypes().get(dataType0Key).getDescription()); assertThatThrownBy(() -> new SimpleToscaProvider().deleteDataType(pfDao, new PfConceptKey("IDontExist:0.0.1"))) - .hasMessage("data type IDontExist:0.0.1 not found"); + .hasMessage("data type IDontExist:0.0.1 not found"); JpaToscaServiceTemplate deletedServiceTemplate = new SimpleToscaProvider().deleteDataType(pfDao, dataType0Key); @@ -167,7 +173,7 @@ public class SimpleToscaProviderTest { assertEquals("Updated Description", deletedServiceTemplate.getDataTypes().get(dataType0Key).getDescription()); assertThatThrownBy(() -> new SimpleToscaProvider().deleteDataType(pfDao, dataType0Key)) - .hasMessage("no data types found"); + .hasMessage("no data types found"); // Create the data type again new SimpleToscaProvider().createDataTypes(pfDao, serviceTemplate); @@ -181,9 +187,12 @@ public class SimpleToscaProviderTest { new SimpleToscaProvider().createPolicyTypes(pfDao, updatedServiceTemplate); assertThatThrownBy(() -> new SimpleToscaProvider().deleteDataType(pfDao, dataType0Key)) - .hasMessage("data type DataType0:0.0.1 is in use, it is referenced in policy type pt0:0.0.2"); + .hasMessage("data type DataType0:0.0.1 is in use, it is referenced in policy type pt0:0.0.2"); JpaToscaDataType dataType0v2 = new JpaToscaDataType(new PfConceptKey("DataType0:0.0.2")); + dataType0v2.setConstraints(new ArrayList()); + dataType0v2.setMetadata(new TreeMap()); + dataType0v2.setProperties(new LinkedHashMap()); updatedServiceTemplate.getDataTypes().getConceptMap().put(dataType0v2.getKey(), dataType0v2); new SimpleToscaProvider().createDataTypes(pfDao, updatedServiceTemplate); @@ -193,7 +202,7 @@ public class SimpleToscaProviderTest { assertNull(deletedServiceTemplate.getDataTypes().get(dataType0v2.getKey()).getDescription()); assertThatThrownBy(() -> new SimpleToscaProvider().deleteDataType(pfDao, dataType0Key)) - .hasMessage("data type DataType0:0.0.1 is in use, it is referenced in policy type pt0:0.0.2"); + .hasMessage("data type DataType0:0.0.1 is in use, it is referenced in policy type pt0:0.0.2"); JpaToscaDataType dataType1 = new JpaToscaDataType(new PfConceptKey("DataType1:0.0.3")); JpaToscaProperty prop1 = new JpaToscaProperty(new PfReferenceKey(dataType1.getKey(), "prop1")); @@ -204,7 +213,7 @@ public class SimpleToscaProviderTest { new SimpleToscaProvider().createDataTypes(pfDao, updatedServiceTemplate); assertThatThrownBy(() -> new SimpleToscaProvider().deleteDataType(pfDao, dataType0v2.getKey())) - .hasMessage("data type DataType0:0.0.2 is in use, it is referenced in data type DataType1:0.0.3"); + .hasMessage("data type DataType0:0.0.2 is in use, it is referenced in data type DataType1:0.0.3"); } @Test @@ -220,11 +229,15 @@ public class SimpleToscaProviderTest { PfConceptKey policyType0Key = new PfConceptKey("PolicyType0", "0.0.1"); JpaToscaPolicyType policyType0 = new JpaToscaPolicyType(); policyType0.setKey(policyType0Key); + policyType0.setMetadata(new TreeMap()); + policyType0.setProperties(new LinkedHashMap()); + policyType0.setTargets(new ArrayList()); + policyType0.setTriggers(new ArrayList()); serviceTemplate.setPolicyTypes(new JpaToscaPolicyTypes()); serviceTemplate.getPolicyTypes().getConceptMap().put(policyType0Key, policyType0); JpaToscaServiceTemplate createdServiceTemplate = - new SimpleToscaProvider().createPolicyTypes(pfDao, serviceTemplate); + new SimpleToscaProvider().createPolicyTypes(pfDao, serviceTemplate); assertEquals(1, createdServiceTemplate.getPolicyTypes().getConceptMap().size()); assertEquals(policyType0, createdServiceTemplate.getPolicyTypes().get(policyType0Key)); @@ -233,14 +246,14 @@ public class SimpleToscaProviderTest { policyType0.setDescription("Updated Description"); JpaToscaServiceTemplate updatedServiceTemplate = - new SimpleToscaProvider().updatePolicyTypes(pfDao, serviceTemplate); + new SimpleToscaProvider().updatePolicyTypes(pfDao, serviceTemplate); assertEquals(policyType0, updatedServiceTemplate.getPolicyTypes().get(policyType0Key)); assertEquals("Updated Description", - updatedServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription()); + updatedServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription()); JpaToscaServiceTemplate gotServiceTemplate = - new SimpleToscaProvider().getPolicyTypes(pfDao, policyType0Key.getName(), policyType0Key.getVersion()); + new SimpleToscaProvider().getPolicyTypes(pfDao, policyType0Key.getName(), policyType0Key.getVersion()); assertEquals(policyType0, gotServiceTemplate.getPolicyTypes().get(policyType0Key)); assertEquals("Updated Description", gotServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription()); @@ -255,7 +268,7 @@ public class SimpleToscaProviderTest { new SimpleToscaProvider().createPolicyTypes(pfDao, serviceTemplate); assertThatThrownBy(() -> new SimpleToscaProvider().deletePolicyType(pfDao, policyType0Key)) - .hasMessage("policy type PolicyType0:0.0.1 is in use, it is referenced in policy type pt1:0.0.2"); + .hasMessage("policy type PolicyType0:0.0.1 is in use, it is referenced in policy type pt1:0.0.2"); serviceTemplate.setTopologyTemplate(new JpaToscaTopologyTemplate()); serviceTemplate.getTopologyTemplate().setPolicies(new JpaToscaPolicies()); @@ -270,10 +283,10 @@ public class SimpleToscaProviderTest { new SimpleToscaProvider().createPolicies(pfDao, serviceTemplate); assertThatThrownBy(() -> new SimpleToscaProvider().deletePolicyType(pfDao, policyType0Key)) - .hasMessage("policy type PolicyType0:0.0.1 is in use, it is referenced in policy type pt1:0.0.2"); + .hasMessage("policy type PolicyType0:0.0.1 is in use, it is referenced in policy type pt1:0.0.2"); assertThatThrownBy(() -> new SimpleToscaProvider().deletePolicyType(pfDao, pt1.getKey())) - .hasMessage("policy type pt1:0.0.2 is in use, it is referenced in policy p1:0.0.1"); + .hasMessage("policy type pt1:0.0.2 is in use, it is referenced in policy p1:0.0.1"); new SimpleToscaProvider().deletePolicy(pfDao, p1.getKey()); @@ -282,32 +295,36 @@ public class SimpleToscaProviderTest { new SimpleToscaProvider().deletePolicy(pfDao, p0.getKey()); JpaToscaServiceTemplate deletedServiceTemplate = - new SimpleToscaProvider().deletePolicyType(pfDao, policyType0Key); + new SimpleToscaProvider().deletePolicyType(pfDao, policyType0Key); assertEquals(policyType0, deletedServiceTemplate.getPolicyTypes().get(policyType0Key)); assertEquals("Updated Description", - deletedServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription()); + deletedServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription()); assertThatThrownBy(() -> new SimpleToscaProvider().deletePolicyType(pfDao, policyType0Key)) - .hasMessage("no policy types found"); + .hasMessage("no policy types found"); JpaToscaServiceTemplate newServiceTemplate = - new SimpleToscaProvider().createPolicyTypes(pfDao, serviceTemplate); + new SimpleToscaProvider().createPolicyTypes(pfDao, serviceTemplate); assertEquals(serviceTemplate, newServiceTemplate); } @Test public void testCreateUpdateGetDeletePolicyTypeWithDataType() throws PfModelException { - JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate(); - PfConceptKey policyType0Key = new PfConceptKey("PolicyType0", "0.0.1"); JpaToscaPolicyType policyType0 = new JpaToscaPolicyType(); policyType0.setKey(policyType0Key); + policyType0.setMetadata(new TreeMap()); + policyType0.setProperties(new LinkedHashMap()); + policyType0.setTargets(new ArrayList()); + policyType0.setTriggers(new ArrayList()); + + JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate(); serviceTemplate.setPolicyTypes(new JpaToscaPolicyTypes()); serviceTemplate.getPolicyTypes().getConceptMap().put(policyType0Key, policyType0); JpaToscaServiceTemplate createdServiceTemplate = - new SimpleToscaProvider().createPolicyTypes(pfDao, serviceTemplate); + new SimpleToscaProvider().createPolicyTypes(pfDao, serviceTemplate); assertEquals(policyType0, createdServiceTemplate.getPolicyTypes().get(policyType0Key)); assertEquals(null, createdServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription()); @@ -315,33 +332,33 @@ public class SimpleToscaProviderTest { policyType0.setDescription("Updated Description"); JpaToscaServiceTemplate updatedServiceTemplate = - new SimpleToscaProvider().updatePolicyTypes(pfDao, serviceTemplate); + new SimpleToscaProvider().updatePolicyTypes(pfDao, serviceTemplate); assertEquals(policyType0, updatedServiceTemplate.getPolicyTypes().get(policyType0Key)); assertEquals("Updated Description", - updatedServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription()); + updatedServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription()); JpaToscaServiceTemplate gotServiceTemplate = - new SimpleToscaProvider().getPolicyTypes(pfDao, policyType0Key.getName(), policyType0Key.getVersion()); + new SimpleToscaProvider().getPolicyTypes(pfDao, policyType0Key.getName(), policyType0Key.getVersion()); assertEquals(policyType0, gotServiceTemplate.getPolicyTypes().get(policyType0Key)); assertEquals("Updated Description", gotServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription()); JpaToscaServiceTemplate deletedServiceTemplate = - new SimpleToscaProvider().deletePolicyType(pfDao, policyType0Key); + new SimpleToscaProvider().deletePolicyType(pfDao, policyType0Key); assertEquals(policyType0, deletedServiceTemplate.getPolicyTypes().get(policyType0Key)); assertEquals("Updated Description", - deletedServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription()); + deletedServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription()); assertThatThrownBy(() -> new SimpleToscaProvider().deletePolicyType(pfDao, policyType0Key)) - .hasMessage("no policy types found"); + .hasMessage("no policy types found"); } @Test public void testPoliciesGet() throws Exception { ToscaServiceTemplate toscaServiceTemplate = - standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), ToscaServiceTemplate.class); + standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), ToscaServiceTemplate.class); createPolicyTypes(); @@ -350,18 +367,18 @@ public class SimpleToscaProviderTest { assertNotNull(originalServiceTemplate); JpaToscaServiceTemplate createdServiceTemplate = - new SimpleToscaProvider().createPolicies(pfDao, originalServiceTemplate); + new SimpleToscaProvider().createPolicies(pfDao, originalServiceTemplate); assertEquals(originalServiceTemplate.getTopologyTemplate().getPolicies(), - createdServiceTemplate.getTopologyTemplate().getPolicies()); + createdServiceTemplate.getTopologyTemplate().getPolicies()); PfConceptKey policyKey = new PfConceptKey("onap.restart.tca:1.0.0"); JpaToscaServiceTemplate gotServiceTemplate = - new SimpleToscaProvider().getPolicies(pfDao, policyKey.getName(), policyKey.getVersion()); + new SimpleToscaProvider().getPolicies(pfDao, policyKey.getName(), policyKey.getVersion()); assertEquals(0, originalServiceTemplate.getTopologyTemplate().getPolicies().get(policyKey) - .compareTo(gotServiceTemplate.getTopologyTemplate().getPolicies().get(policyKey))); + .compareTo(gotServiceTemplate.getTopologyTemplate().getPolicies().get(policyKey))); JpaToscaServiceTemplate deletedServiceTemplate = new SimpleToscaProvider().deletePolicy(pfDao, policyKey); assertEquals(1, deletedServiceTemplate.getTopologyTemplate().getPolicies().getConceptMap().size()); @@ -370,7 +387,7 @@ public class SimpleToscaProviderTest { @Test public void testPolicyCreate() throws Exception { ToscaServiceTemplate toscaServiceTemplate = - standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), ToscaServiceTemplate.class); + standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), ToscaServiceTemplate.class); createPolicyTypes(); @@ -379,21 +396,21 @@ public class SimpleToscaProviderTest { assertNotNull(originalServiceTemplate); JpaToscaServiceTemplate createdServiceTemplate = - new SimpleToscaProvider().createPolicies(pfDao, originalServiceTemplate); + new SimpleToscaProvider().createPolicies(pfDao, originalServiceTemplate); assertEquals(originalServiceTemplate.getTopologyTemplate().getPolicies(), - createdServiceTemplate.getTopologyTemplate().getPolicies()); + createdServiceTemplate.getTopologyTemplate().getPolicies()); } @Test public void testPolicyCreateTypeAndVersion() throws Exception { ToscaServiceTemplate toscaServiceTemplate = - standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), ToscaServiceTemplate.class); + standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), ToscaServiceTemplate.class); createPolicyTypes(); ToscaPolicy toscaPolicy = - toscaServiceTemplate.getToscaTopologyTemplate().getPoliciesAsMap().values().iterator().next(); + toscaServiceTemplate.getToscaTopologyTemplate().getPoliciesAsMap().values().iterator().next(); JpaToscaServiceTemplate originalServiceTemplate = new JpaToscaServiceTemplate(); @@ -410,7 +427,7 @@ public class SimpleToscaProviderTest { assertThatThrownBy(() -> { originalServiceTemplate.fromAuthorative(toscaServiceTemplate); }).hasMessage("Version not specified, the version of this TOSCA entity must be " - + "specified in the type_version field"); + + "specified in the type_version field"); toscaPolicy.setTypeVersion("hello"); assertThatThrownBy(() -> { @@ -423,7 +440,7 @@ public class SimpleToscaProviderTest { assertThatThrownBy(() -> { new SimpleToscaProvider().createPolicies(pfDao, originalServiceTemplate); }).hasMessageContaining("policy type").hasMessageContaining("IDontExist:99.100.101") - .hasMessageContaining(Validated.NOT_FOUND); + .hasMessageContaining(Validated.NOT_FOUND); toscaPolicy.setType("IDontExist"); originalServiceTemplate.fromAuthorative(toscaServiceTemplate); @@ -439,15 +456,15 @@ public class SimpleToscaProviderTest { originalServiceTemplate.fromAuthorative(toscaServiceTemplate); JpaToscaServiceTemplate createdServiceTemplate = - new SimpleToscaProvider().createPolicies(pfDao, originalServiceTemplate); + new SimpleToscaProvider().createPolicies(pfDao, originalServiceTemplate); assertEquals(originalServiceTemplate.getTopologyTemplate().getPolicies(), - createdServiceTemplate.getTopologyTemplate().getPolicies()); + createdServiceTemplate.getTopologyTemplate().getPolicies()); } @Test public void testPolicyUpdate() throws Exception { ToscaServiceTemplate toscaServiceTemplate = - standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), ToscaServiceTemplate.class); + standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), ToscaServiceTemplate.class); createPolicyTypes(); @@ -456,7 +473,7 @@ public class SimpleToscaProviderTest { assertNotNull(originalServiceTemplate); JpaToscaServiceTemplate updatedServiceTemplate = - new SimpleToscaProvider().updatePolicies(pfDao, originalServiceTemplate); + new SimpleToscaProvider().updatePolicies(pfDao, originalServiceTemplate); assertEquals(originalServiceTemplate, updatedServiceTemplate); } @@ -464,7 +481,7 @@ public class SimpleToscaProviderTest { @Test public void testPoliciesDelete() throws Exception { ToscaServiceTemplate toscaServiceTemplate = - standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), ToscaServiceTemplate.class); + standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), ToscaServiceTemplate.class); createPolicyTypes(); @@ -473,26 +490,26 @@ public class SimpleToscaProviderTest { assertNotNull(originalServiceTemplate); JpaToscaServiceTemplate createdServiceTemplate = - new SimpleToscaProvider().createPolicies(pfDao, originalServiceTemplate); + new SimpleToscaProvider().createPolicies(pfDao, originalServiceTemplate); assertEquals(originalServiceTemplate.getTopologyTemplate(), createdServiceTemplate.getTopologyTemplate()); PfConceptKey policyKey = new PfConceptKey("onap.restart.tca:1.0.0"); assertThatThrownBy(() -> new SimpleToscaProvider().deletePolicy(pfDao, new PfConceptKey("IDontExist:0.0.1"))) - .hasMessage("policy IDontExist:0.0.1 not found"); + .hasMessage("policy IDontExist:0.0.1 not found"); JpaToscaServiceTemplate deletedServiceTemplate = new SimpleToscaProvider().deletePolicy(pfDao, policyKey); assertEquals(0, originalServiceTemplate.getTopologyTemplate().getPolicies().get(policyKey) - .compareTo(deletedServiceTemplate.getTopologyTemplate().getPolicies().get(policyKey))); + .compareTo(deletedServiceTemplate.getTopologyTemplate().getPolicies().get(policyKey))); assertThatThrownBy(() -> { new SimpleToscaProvider().getPolicies(pfDao, policyKey.getName(), policyKey.getVersion()); }).hasMessage("policies for onap.restart.tca:1.0.0 do not exist"); assertThatThrownBy(() -> new SimpleToscaProvider().deletePolicy(pfDao, policyKey)) - .hasMessage("no policies found"); + .hasMessage("no policies found"); new SimpleToscaProvider().createPolicies(pfDao, originalServiceTemplate); } @@ -502,21 +519,21 @@ public class SimpleToscaProviderTest { JpaToscaServiceTemplate testServiceTemplate = new JpaToscaServiceTemplate(); assertThatThrownBy(() -> new SimpleToscaProvider().createPolicies(pfDao, testServiceTemplate)) - .hasMessage("topology template not specified on service template"); + .hasMessage("topology template not specified on service template"); testServiceTemplate.setTopologyTemplate(new JpaToscaTopologyTemplate()); assertThatThrownBy(() -> new SimpleToscaProvider().createPolicies(pfDao, testServiceTemplate)) - .hasMessage("no policies specified on topology template of service template"); + .hasMessage("no policies specified on topology template of service template"); testServiceTemplate.getTopologyTemplate().setPolicies(new JpaToscaPolicies()); assertThatThrownBy(() -> new SimpleToscaProvider().createPolicies(pfDao, testServiceTemplate)) - .hasMessage("list of policies specified on topology template of service template is empty"); + .hasMessage("list of policies specified on topology template of service template is empty"); } @Test public void testGetServiceTemplate() throws PfModelException { assertThatThrownBy(() -> new SimpleToscaProvider().getServiceTemplate(pfDao)) - .hasMessage("service template not found in database"); + .hasMessage("service template not found in database"); } @Test @@ -527,8 +544,8 @@ public class SimpleToscaProviderTest { serviceTemplateFragment.getPolicyTypes().getConceptMap().put(badPt.getKey(), badPt); assertThatThrownBy(() -> new SimpleToscaProvider().appendToServiceTemplate(pfDao, serviceTemplateFragment)) - .hasMessageContaining("key on concept entry").hasMessageContaining("NULL:0.0.0") - .hasMessageContaining(Validated.IS_A_NULL_KEY); + .hasMessageContaining("key on concept entry").hasMessageContaining("NULL:0.0.0") + .hasMessageContaining(Validated.IS_A_NULL_KEY); } @Test @@ -539,8 +556,8 @@ public class SimpleToscaProviderTest { JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate(); serviceTemplate.setPolicyTypes(new JpaToscaPolicyTypes()); - JpaToscaPolicyType p0 = new JpaToscaPolicyType(new PfConceptKey("p0:0.0.1")); - serviceTemplate.getPolicyTypes().getConceptMap().put(p0.getKey(), p0); + JpaToscaPolicyType pt0 = new JpaToscaPolicyType(new PfConceptKey("p0:0.0.1")); + serviceTemplate.getPolicyTypes().getConceptMap().put(pt0.getKey(), pt0); new SimpleToscaProvider().createPolicyTypes(pfDao, serviceTemplate); @@ -550,8 +567,11 @@ public class SimpleToscaProviderTest { serviceTemplate.setDataTypes(new JpaToscaDataTypes()); - JpaToscaDataType p01 = new JpaToscaDataType(new PfConceptKey("dt0:0.0.1")); - serviceTemplate.getDataTypes().getConceptMap().put(p01.getKey(), p01); + JpaToscaDataType dt01 = new JpaToscaDataType(new PfConceptKey("dt0:0.0.1")); + dt01.setConstraints(new ArrayList()); + dt01.setMetadata(new TreeMap()); + dt01.setProperties(new LinkedHashMap()); + serviceTemplate.getDataTypes().getConceptMap().put(dt01.getKey(), dt01); new SimpleToscaProvider().createDataTypes(pfDao, serviceTemplate); @@ -559,32 +579,36 @@ public class SimpleToscaProviderTest { new SimpleToscaProvider().getDataTypes(pfDao, "hello", "0.0.1"); }).hasMessageMatching("data types for hello:0.0.1 do not exist"); - JpaToscaServiceTemplate gotSt = new SimpleToscaProvider().getDataTypes(pfDao, p01.getName(), p01.getVersion()); + JpaToscaServiceTemplate gotSt = + new SimpleToscaProvider().getDataTypes(pfDao, dt01.getName(), dt01.getVersion()); - assertEquals(p01, gotSt.getDataTypes().get(p01.getKey())); - assertEquals(p01, gotSt.getDataTypes().get(p01.getName())); - assertEquals(p01, gotSt.getDataTypes().get(p01.getName(), null)); - assertEquals(p01, gotSt.getDataTypes().get(p01.getName(), p01.getVersion())); + assertEquals(dt01, gotSt.getDataTypes().get(dt01.getKey())); + assertEquals(dt01, gotSt.getDataTypes().get(dt01.getName())); + assertEquals(dt01, gotSt.getDataTypes().get(dt01.getName(), null)); + assertEquals(dt01, gotSt.getDataTypes().get(dt01.getName(), dt01.getVersion())); assertEquals(1, gotSt.getDataTypes().getAll(null).size()); assertEquals(1, gotSt.getDataTypes().getAll(null, null).size()); - assertEquals(1, gotSt.getDataTypes().getAll(p01.getName(), null).size()); - assertEquals(1, gotSt.getDataTypes().getAll(p01.getName(), p01.getVersion()).size()); + assertEquals(1, gotSt.getDataTypes().getAll(dt01.getName(), null).size()); + assertEquals(1, gotSt.getDataTypes().getAll(dt01.getName(), dt01.getVersion()).size()); - JpaToscaDataType p02 = new JpaToscaDataType(new PfConceptKey("dt0:0.0.2")); - serviceTemplate.getDataTypes().getConceptMap().put(p02.getKey(), p02); + JpaToscaDataType dt02 = new JpaToscaDataType(new PfConceptKey("dt0:0.0.2")); + dt02.setConstraints(new ArrayList()); + dt02.setMetadata(new TreeMap()); + dt02.setProperties(new LinkedHashMap()); + serviceTemplate.getDataTypes().getConceptMap().put(dt02.getKey(), dt02); new SimpleToscaProvider().createDataTypes(pfDao, serviceTemplate); - gotSt = new SimpleToscaProvider().getDataTypes(pfDao, p01.getName(), null); + gotSt = new SimpleToscaProvider().getDataTypes(pfDao, dt01.getName(), null); - assertEquals(p01, gotSt.getDataTypes().get(p01.getKey())); - assertEquals(p02, gotSt.getDataTypes().get(p01.getName())); - assertEquals(p02, gotSt.getDataTypes().get(p01.getName(), null)); - assertEquals(p01, gotSt.getDataTypes().get(p01.getName(), p01.getVersion())); - assertEquals(p02, gotSt.getDataTypes().get(p01.getName(), p02.getVersion())); + assertEquals(dt01, gotSt.getDataTypes().get(dt01.getKey())); + assertEquals(dt02, gotSt.getDataTypes().get(dt01.getName())); + assertEquals(dt02, gotSt.getDataTypes().get(dt01.getName(), null)); + assertEquals(dt01, gotSt.getDataTypes().get(dt01.getName(), dt01.getVersion())); + assertEquals(dt02, gotSt.getDataTypes().get(dt01.getName(), dt02.getVersion())); assertEquals(2, gotSt.getDataTypes().getAll(null).size()); assertEquals(2, gotSt.getDataTypes().getAll(null, null).size()); - assertEquals(2, gotSt.getDataTypes().getAll(p01.getName(), null).size()); - assertEquals(1, gotSt.getDataTypes().getAll(p01.getName(), p02.getVersion()).size()); + assertEquals(2, gotSt.getDataTypes().getAll(dt01.getName(), null).size()); + assertEquals(1, gotSt.getDataTypes().getAll(dt01.getName(), dt02.getVersion()).size()); } @Test @@ -607,6 +631,10 @@ public class SimpleToscaProviderTest { serviceTemplate.setPolicyTypes(new JpaToscaPolicyTypes()); JpaToscaPolicyType pt01 = new JpaToscaPolicyType(new PfConceptKey("p0:0.0.1")); + pt01.setMetadata(new TreeMap()); + pt01.setProperties(new LinkedHashMap()); + pt01.setTargets(new ArrayList()); + pt01.setTriggers(new ArrayList()); serviceTemplate.getPolicyTypes().getConceptMap().put(pt01.getKey(), pt01); new SimpleToscaProvider().createPolicyTypes(pfDao, serviceTemplate); @@ -616,7 +644,7 @@ public class SimpleToscaProviderTest { }).hasMessageMatching("policy types for hello:0.0.1 do not exist"); JpaToscaServiceTemplate gotSt = - new SimpleToscaProvider().getPolicyTypes(pfDao, pt01.getName(), pt01.getVersion()); + new SimpleToscaProvider().getPolicyTypes(pfDao, pt01.getName(), pt01.getVersion()); assertEquals(pt01, gotSt.getPolicyTypes().get(pt01.getKey())); assertEquals(pt01, gotSt.getPolicyTypes().get(pt01.getName())); @@ -628,6 +656,10 @@ public class SimpleToscaProviderTest { assertEquals(1, gotSt.getPolicyTypes().getAll(pt01.getName(), pt01.getVersion()).size()); JpaToscaPolicyType pt02 = new JpaToscaPolicyType(new PfConceptKey("p0:0.0.2")); + pt02.setMetadata(new TreeMap()); + pt02.setProperties(new LinkedHashMap()); + pt02.setTargets(new ArrayList()); + pt02.setTriggers(new ArrayList()); serviceTemplate.getPolicyTypes().getConceptMap().put(pt02.getKey(), pt02); new SimpleToscaProvider().createPolicyTypes(pfDao, serviceTemplate); @@ -653,6 +685,9 @@ public class SimpleToscaProviderTest { JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate(); serviceTemplate.setDataTypes(new JpaToscaDataTypes()); JpaToscaDataType dt0 = new JpaToscaDataType(new PfConceptKey("dt0:0.0.1")); + dt0.setConstraints(new ArrayList()); + dt0.setMetadata(new TreeMap()); + dt0.setProperties(new LinkedHashMap()); serviceTemplate.getDataTypes().getConceptMap().put(dt0.getKey(), dt0); new SimpleToscaProvider().createDataTypes(pfDao, serviceTemplate); @@ -664,6 +699,10 @@ public class SimpleToscaProviderTest { serviceTemplate.setPolicyTypes(new JpaToscaPolicyTypes()); JpaToscaPolicyType pt01 = new JpaToscaPolicyType(new PfConceptKey("pt0:0.0.1")); + pt01.setMetadata(new TreeMap()); + pt01.setProperties(new LinkedHashMap()); + pt01.setTargets(new ArrayList()); + pt01.setTriggers(new ArrayList()); serviceTemplate.getPolicyTypes().getConceptMap().put(pt01.getKey(), pt01); serviceTemplate.setTopologyTemplate(new JpaToscaTopologyTemplate()); @@ -671,6 +710,9 @@ public class SimpleToscaProviderTest { JpaToscaPolicy p01 = new JpaToscaPolicy(new PfConceptKey("p0:0.0.1")); p01.setType(pt01.getKey()); + p01.setMetadata(new TreeMap()); + p01.setProperties(new LinkedHashMap()); + p01.setTargets(new ArrayList()); serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().put(p01.getKey(), p01); new SimpleToscaProvider().createPolicies(pfDao, serviceTemplate); @@ -692,6 +734,10 @@ public class SimpleToscaProviderTest { JpaToscaPolicy p02 = new JpaToscaPolicy(new PfConceptKey("p0:0.0.2")); p02.setType(pt01.getKey()); + p02.setType(pt01.getKey()); + p02.setMetadata(new TreeMap()); + p02.setProperties(new LinkedHashMap()); + p02.setTargets(new ArrayList()); serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().put(p02.getKey(), p02); new SimpleToscaProvider().createPolicies(pfDao, serviceTemplate); @@ -860,16 +906,19 @@ public class SimpleToscaProviderTest { new SimpleToscaProvider().deleteServiceTemplate(pfDao); }).hasMessage("service template not found in database"); - JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate(); - PfConceptKey dataType0Key = new PfConceptKey("DataType0", "0.0.1"); JpaToscaDataType dataType0 = new JpaToscaDataType(); dataType0.setKey(dataType0Key); + dataType0.setConstraints(new ArrayList()); + dataType0.setMetadata(new TreeMap()); + dataType0.setProperties(new LinkedHashMap()); + + JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate(); serviceTemplate.setDataTypes(new JpaToscaDataTypes()); serviceTemplate.getDataTypes().getConceptMap().put(dataType0Key, dataType0); JpaToscaServiceTemplate createdServiceTemplate = - new SimpleToscaProvider().createDataTypes(pfDao, serviceTemplate); + new SimpleToscaProvider().createDataTypes(pfDao, serviceTemplate); assertEquals(1, createdServiceTemplate.getDataTypes().getConceptMap().size()); assertEquals(dataType0, createdServiceTemplate.getDataTypes().get(dataType0Key)); @@ -889,11 +938,11 @@ public class SimpleToscaProviderTest { private void createPolicyTypes() throws CoderException, PfModelException { Object yamlObject = - new Yaml().load(ResourceUtils.getResourceAsString("policytypes/onap.policies.monitoring.tcagen2.yaml")); + new Yaml().load(ResourceUtils.getResourceAsString("policytypes/onap.policies.monitoring.tcagen2.yaml")); String yamlAsJsonString = new StandardCoder().encode(yamlObject); ToscaServiceTemplate toscaServiceTemplatePolicyType = - standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class); + standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class); assertNotNull(toscaServiceTemplatePolicyType); new AuthorativeToscaProvider().createPolicyTypes(pfDao, toscaServiceTemplatePolicyType); diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaServiceTemplateProviderTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaServiceTemplateProviderTest.java index 016ed532c..f00fa0fc5 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaServiceTemplateProviderTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaServiceTemplateProviderTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2020-2021 Nordix Foundation. + * Copyright (C) 2020-2021,2023 Nordix Foundation. * Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -25,8 +25,10 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; +import java.util.ArrayList; +import java.util.LinkedHashMap; import java.util.Properties; -import org.eclipse.persistence.config.PersistenceUnitProperties; +import java.util.TreeMap; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -36,11 +38,14 @@ import org.onap.policy.models.dao.DaoParameters; import org.onap.policy.models.dao.PfDao; import org.onap.policy.models.dao.PfDaoFactory; import org.onap.policy.models.dao.impl.DefaultPfDao; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraint; import org.onap.policy.models.tosca.simple.concepts.JpaToscaDataType; import org.onap.policy.models.tosca.simple.concepts.JpaToscaDataTypes; import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyType; import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyTypes; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaProperty; import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaTrigger; /** * Test the {@link SimpleToscaProvider} class. @@ -66,15 +71,15 @@ public class SimpleToscaServiceTemplateProviderTest { daoParameters.setPersistenceUnit("ToscaConceptTest"); Properties jdbcProperties = new Properties(); - jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_USER, "policy"); - jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_PASSWORD, "P01icY"); + jdbcProperties.setProperty("javax.persistence.jdbc.user", "policy"); + jdbcProperties.setProperty("javax.persistence.jdbc.password", "P01icY"); if (System.getProperty("USE-MARIADB") != null) { - jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_DRIVER, "org.mariadb.jdbc.Driver"); - jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_URL, "jdbc:mariadb://localhost:3306/policy"); + jdbcProperties.setProperty("javax.persistence.jdbc.driver", "org.mariadb.jdbc.Driver"); + jdbcProperties.setProperty("javax.persistence.jdbc.url", "jdbc:mariadb://localhost:3306/policy"); } else { - jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_DRIVER, "org.h2.Driver"); - jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_URL, + jdbcProperties.setProperty("javax.persistence.jdbc.driver", "org.h2.Driver"); + jdbcProperties.setProperty("javax.persistence.jdbc.url", "jdbc:h2:mem:SimpleToscaServiceTemplateProviderTest"); } @@ -92,6 +97,7 @@ public class SimpleToscaServiceTemplateProviderTest { @Test public void testCreateUpdateGetDeleteDataType() throws PfModelException { JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate(); + serviceTemplate.setMetadata(new TreeMap()); JpaToscaServiceTemplate dbServiceTemplate = new SimpleToscaServiceTemplateProvider().write(pfDao, serviceTemplate); @@ -106,6 +112,9 @@ public class SimpleToscaServiceTemplateProviderTest { PfConceptKey dataType0Key = new PfConceptKey("DataType0", "0.0.1"); JpaToscaDataType dataType0 = new JpaToscaDataType(); dataType0.setKey(dataType0Key); + dataType0.setConstraints(new ArrayList()); + dataType0.setMetadata(new TreeMap()); + dataType0.setProperties(new LinkedHashMap()); serviceTemplate.setDataTypes(new JpaToscaDataTypes()); serviceTemplate.getDataTypes().getConceptMap().put(dataType0Key, dataType0); @@ -135,6 +144,10 @@ public class SimpleToscaServiceTemplateProviderTest { JpaToscaPolicyType policyType0 = new JpaToscaPolicyType(); policyType0.setKey(policyType0Key); + policyType0.setMetadata(new TreeMap()); + policyType0.setProperties(new LinkedHashMap()); + policyType0.setTargets(new ArrayList()); + policyType0.setTriggers(new ArrayList()); serviceTemplate.setPolicyTypes(new JpaToscaPolicyTypes()); serviceTemplate.getPolicyTypes().getConceptMap().put(policyType0Key, policyType0); diff --git a/models-tosca/src/test/resources/META-INF/persistence.xml b/models-tosca/src/test/resources/META-INF/persistence.xml index 5c65fc59b..922fef286 100644 --- a/models-tosca/src/test/resources/META-INF/persistence.xml +++ b/models-tosca/src/test/resources/META-INF/persistence.xml @@ -1,7 +1,7 @@ + + + -- cgit 1.2.3-korg