diff options
Diffstat (limited to 'models-tosca/src/test/java/org/onap')
6 files changed, 413 insertions, 582 deletions
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderGenericTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderGenericTest.java index d12e741c1..a6e84bbea 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderGenericTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderGenericTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2020-2021, 2023-2024 Nordix Foundation. + * Copyright (C) 2020-2021, 2023-2025 Nordix Foundation. * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2024 Nordix Foundation * ================================================================================ @@ -62,8 +62,6 @@ class AuthorativeToscaProviderGenericTest { /** * Read the policy type definition. - * - * @throws Exception on errors */ @BeforeAll public static void readPolicyDefinition() { @@ -88,14 +86,9 @@ class AuthorativeToscaProviderGenericTest { Properties jdbcProperties = new Properties(); jdbcProperties.setProperty("jakarta.persistence.jdbc.user", "policy"); jdbcProperties.setProperty("jakarta.persistence.jdbc.password", "P01icY"); - if (System.getProperty("USE-MARIADB") != null) { - jdbcProperties.setProperty("jakarta.persistence.jdbc.driver", "org.mariadb.jdbc.Driver"); - jdbcProperties.setProperty("jakarta.persistence.jdbc.url", "jdbc:mariadb://localhost:3306/policy"); - } else { - jdbcProperties.setProperty("jakarta.persistence.jdbc.driver", "org.h2.Driver"); - jdbcProperties.setProperty("jakarta.persistence.jdbc.url", - "jdbc:h2:mem:AuthorativeToscaProviderGenericTest"); - } + jdbcProperties.setProperty("jakarta.persistence.jdbc.driver", "org.h2.Driver"); + jdbcProperties.setProperty("jakarta.persistence.jdbc.url", + "jdbc:h2:mem:AuthorativeToscaProviderGenericTest"); daoParameters.setJdbcProperties(jdbcProperties); pfDao = new PfDaoFactory().createPfDao(daoParameters); @@ -117,9 +110,8 @@ class AuthorativeToscaProviderGenericTest { @Test void testCreateGetDelete() throws Exception { - assertThatThrownBy(() -> { - new AuthorativeToscaProvider().getServiceTemplateList(null, null, null); - }).hasMessageMatching(DAO_IS_NULL); + assertThatThrownBy(() -> new AuthorativeToscaProvider().getServiceTemplateList(null, null, null)) + .hasMessageMatching(DAO_IS_NULL); ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class); @@ -131,32 +123,32 @@ class AuthorativeToscaProviderGenericTest { ToscaPolicyType beforePolicyType = toscaServiceTemplate.getPolicyTypes().get(policyTypeKey.getName()); ToscaPolicyType createdPolicyType = createdServiceTemplate.getPolicyTypes().get(policyTypeKey.getName()); - assertEquals(true, beforePolicyType.getName().equals(createdPolicyType.getName())); + assertEquals(beforePolicyType.getName(), createdPolicyType.getName()); assertEquals(0, ObjectUtils.compare(beforePolicyType.getDescription(), createdPolicyType.getDescription())); List<ToscaServiceTemplate> gotServiceTemplateList = new AuthorativeToscaProvider().getServiceTemplateList(pfDao, null, null); ToscaPolicyType gotPolicyType = gotServiceTemplateList.get(0).getPolicyTypes().get(policyTypeKey.getName()); - assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName())); + assertEquals(beforePolicyType.getName(), gotPolicyType.getName()); assertEquals(0, ObjectUtils.compare(beforePolicyType.getDescription(), createdPolicyType.getDescription())); List<ToscaPolicyType> gotPolicyTypeList = new AuthorativeToscaProvider().getPolicyTypeList(pfDao, POLICY_NO_VERSION, VERSION_001); assertEquals(2, gotPolicyTypeList.size()); - assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName())); + assertEquals(beforePolicyType.getName(), gotPolicyType.getName()); gotPolicyTypeList = new AuthorativeToscaProvider().getPolicyTypeList(pfDao, POLICY_NO_VERSION, null); assertEquals(2, gotPolicyTypeList.size()); - assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName())); + assertEquals(beforePolicyType.getName(), gotPolicyType.getName()); gotPolicyTypeList = new AuthorativeToscaProvider().getPolicyTypeList(pfDao, null, null); assertEquals(2, gotPolicyTypeList.size()); - assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName())); + assertEquals(beforePolicyType.getName(), gotPolicyType.getName()); gotPolicyTypeList = new AuthorativeToscaProvider().getPolicyTypeList(pfDao, null, VERSION_001); assertEquals(2, gotPolicyTypeList.size()); - assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName())); + assertEquals(beforePolicyType.getName(), gotPolicyType.getName()); assertThatThrownBy(() -> new AuthorativeToscaProvider().getPolicyTypeList(new DefaultPfDao(), POLICY_NO_VERSION, VERSION_001)).hasMessageContaining("Policy Framework DAO has not been initialized"); 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 95cee32ce..80221a3d9 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-2024 Nordix Foundation. + * Copyright (C) 2022-2025 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -68,6 +68,7 @@ class AuthorativeToscaProviderNodeTemplateTest { /** * Read policy metadataSet input json. + * * @throws Exception Coder exception */ @BeforeEach @@ -97,14 +98,9 @@ class AuthorativeToscaProviderNodeTemplateTest { Properties jdbcProperties = new Properties(); jdbcProperties.setProperty("jakarta.persistence.jdbc.user", "policy"); jdbcProperties.setProperty("jakarta.persistence.jdbc.password", "P01icY"); - if (System.getProperty("USE-MARIADB") != null) { - jdbcProperties.setProperty("jakarta.persistence.jdbc.driver", "org.mariadb.jdbc.Driver"); - jdbcProperties.setProperty("jakarta.persistence.jdbc.url", "jdbc:mariadb://localhost:3306/policy"); - } else { - jdbcProperties.setProperty("jakarta.persistence.jdbc.driver", "org.h2.Driver"); - jdbcProperties.setProperty("jakarta.persistence.jdbc.url", - "jdbc:h2:mem:AuthorativeToscaProviderNodeTemplatesTest"); - } + jdbcProperties.setProperty("jakarta.persistence.jdbc.driver", "org.h2.Driver"); + jdbcProperties.setProperty("jakarta.persistence.jdbc.url", + "jdbc:h2:mem:AuthorativeToscaProviderNodeTemplatesTest"); daoParameters.setJdbcProperties(jdbcProperties); pfDao = new PfDaoFactory().createPfDao(daoParameters); @@ -119,9 +115,8 @@ class AuthorativeToscaProviderNodeTemplateTest { @Test void testPolicyMetadataSetsGet() throws Exception { - assertThatThrownBy(() -> { - authorativeToscaProvider.getNodeTemplateMetadataSet(null, null, null); - }).hasMessageMatching(DAO_IS_NULL); + assertThatThrownBy(() -> authorativeToscaProvider.getNodeTemplateMetadataSet(null, null, null)) + .hasMessageMatching(DAO_IS_NULL); assertNotNull(toscaServiceTemplate); authorativeToscaProvider.createToscaNodeTemplates(pfDao, toscaServiceTemplate); @@ -145,9 +140,8 @@ class AuthorativeToscaProviderNodeTemplateTest { @Test void testToscaNodeTemplatesGet() throws Exception { - assertThatThrownBy(() -> { - authorativeToscaProvider.getToscaNodeTemplate(null, null, null); - }).hasMessageMatching(DAO_IS_NULL); + assertThatThrownBy(() -> authorativeToscaProvider.getToscaNodeTemplate(null, null, null)) + .hasMessageMatching(DAO_IS_NULL); assertNotNull(toscaServiceTemplate); authorativeToscaProvider.createToscaNodeTemplates(pfDao, toscaServiceTemplate); @@ -170,17 +164,14 @@ class AuthorativeToscaProviderNodeTemplateTest { @Test void testToscaNodeTemplatesCreate() throws Exception { - assertThatThrownBy(() -> { - authorativeToscaProvider.createToscaNodeTemplates(null, null); - }).hasMessageMatching(DAO_IS_NULL); + assertThatThrownBy(() -> authorativeToscaProvider.createToscaNodeTemplates(null, null)) + .hasMessageMatching(DAO_IS_NULL); - assertThatThrownBy(() -> { - authorativeToscaProvider.createToscaNodeTemplates(null, new ToscaServiceTemplate()); - }).hasMessageMatching(DAO_IS_NULL); + assertThatThrownBy(() -> authorativeToscaProvider.createToscaNodeTemplates(null, new ToscaServiceTemplate())) + .hasMessageMatching(DAO_IS_NULL); - assertThatThrownBy(() -> { - authorativeToscaProvider.createToscaNodeTemplates(pfDao, null); - }).hasMessageMatching("^toscaServiceTemplate is marked .*on.*ull but is null$"); + assertThatThrownBy(() -> authorativeToscaProvider.createToscaNodeTemplates(pfDao, null)) + .hasMessageMatching("^toscaServiceTemplate is marked .*on.*ull but is null$"); ToscaServiceTemplate createdNodeTemplates = authorativeToscaProvider.createToscaNodeTemplates(pfDao, toscaServiceTemplate); @@ -194,25 +185,21 @@ class AuthorativeToscaProviderNodeTemplateTest { //Create node template with invalid node type createToscaNodeTemplate.getToscaTopologyTemplate().getNodeTemplates().get("apexMetadata_adaptive") .setType("invalid.type"); - assertThatThrownBy(() -> { - authorativeToscaProvider.createToscaNodeTemplates(pfDao, createToscaNodeTemplate); - }).hasMessageMatching("^NODE_TYPE .* for toscaNodeTemplate .* does not exist$"); + assertThatThrownBy(() -> authorativeToscaProvider.createToscaNodeTemplates(pfDao, createToscaNodeTemplate)) + .hasMessageMatching("^NODE_TYPE .* for toscaNodeTemplate .* does not exist$"); } @Test void testToscaNodeTemplateUpdate() throws Exception { - assertThatThrownBy(() -> { - authorativeToscaProvider.updateToscaNodeTemplates(null, null); - }).hasMessageMatching(DAO_IS_NULL); + assertThatThrownBy(() -> authorativeToscaProvider.updateToscaNodeTemplates(null, null)) + .hasMessageMatching(DAO_IS_NULL); - assertThatThrownBy(() -> { - authorativeToscaProvider.updateToscaNodeTemplates(null, new ToscaServiceTemplate()); - }).hasMessageMatching(DAO_IS_NULL); + assertThatThrownBy(() -> authorativeToscaProvider.updateToscaNodeTemplates(null, new ToscaServiceTemplate())) + .hasMessageMatching(DAO_IS_NULL); - assertThatThrownBy(() -> { - authorativeToscaProvider.updateToscaNodeTemplates(pfDao, null); - }).hasMessageMatching("^serviceTemplate is marked non-null but is null$"); + assertThatThrownBy(() -> authorativeToscaProvider.updateToscaNodeTemplates(pfDao, null)) + .hasMessageMatching("^serviceTemplate is marked non-null but is null$"); authorativeToscaProvider.createToscaNodeTemplates(pfDao, toscaServiceTemplate); ToscaServiceTemplate updatedTemplate = @@ -224,33 +211,27 @@ class AuthorativeToscaProviderNodeTemplateTest { //Update nodeTemplate with invalid node type updatedToscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates().get("apexMetadata_grpc") .setTypeVersion("0.0.0"); - assertThatThrownBy(() -> { - authorativeToscaProvider.updateToscaNodeTemplates(pfDao, updatedToscaServiceTemplate); - }).hasMessageMatching("^NODE_TYPE .* for toscaNodeTemplate .* does not exist$"); + assertThatThrownBy(() -> authorativeToscaProvider.updateToscaNodeTemplates(pfDao, updatedToscaServiceTemplate)) + .hasMessageMatching("^NODE_TYPE .* for toscaNodeTemplate .* does not exist$"); } @Test void testToscaNodeTemplateDelete() throws Exception { - assertThatThrownBy(() -> { - authorativeToscaProvider.deleteToscaNodeTemplate(null, null, null); - }).hasMessageMatching(DAO_IS_NULL); + assertThatThrownBy(() -> authorativeToscaProvider.deleteToscaNodeTemplate(null, null, null)) + .hasMessageMatching(DAO_IS_NULL); - assertThatThrownBy(() -> { - authorativeToscaProvider.deleteToscaNodeTemplate(null, null, "0.0.1"); - }).hasMessageMatching(DAO_IS_NULL); + assertThatThrownBy(() -> authorativeToscaProvider.deleteToscaNodeTemplate(null, null, "0.0.1")) + .hasMessageMatching(DAO_IS_NULL); - assertThatThrownBy(() -> { - authorativeToscaProvider.deleteToscaNodeTemplate(pfDao, null, null); - }).hasMessageMatching("^name is marked .*on.*ull but is null$"); + assertThatThrownBy(() -> authorativeToscaProvider.deleteToscaNodeTemplate(pfDao, null, null)) + .hasMessageMatching("^name is marked .*on.*ull but is null$"); - assertThatThrownBy(() -> { - authorativeToscaProvider.deleteToscaNodeTemplate(pfDao, "name", null); - }).hasMessageMatching("^version is marked .*on.*ull but is null$"); + assertThatThrownBy(() -> authorativeToscaProvider.deleteToscaNodeTemplate(pfDao, "name", null)) + .hasMessageMatching("^version is marked .*on.*ull but is null$"); authorativeToscaProvider.createToscaNodeTemplates(pfDao, toscaServiceTemplate); - assertThatThrownBy(() -> { - authorativeToscaProvider.deleteToscaNodeTemplate(pfDao, "dummyname", "1.0.1"); - }).hasMessage("node template dummyname:1.0.1 not found"); + assertThatThrownBy(() -> authorativeToscaProvider.deleteToscaNodeTemplate(pfDao, "dummyname", "1.0.1")) + .hasMessage("node template dummyname:1.0.1 not found"); ToscaServiceTemplate responseTemplate = @@ -282,11 +263,10 @@ class AuthorativeToscaProviderNodeTemplateTest { authorativeToscaProvider.createToscaNodeTemplates(pfDao, toscaServiceTemplate); //delete node templates referenced in existing policy - assertThatThrownBy(() -> { - authorativeToscaProvider - .deleteToscaNodeTemplate(pfDao, "apexMetadata_decisionMaker", "1.0.0"); - }).hasMessageEndingWith("Node template is in use, it is referenced in Tosca Policy " - + "operational.apex.decisionMaker version 1.0.0"); + assertThatThrownBy(() -> authorativeToscaProvider + .deleteToscaNodeTemplate(pfDao, "apexMetadata_decisionMaker", "1.0.0")) + .hasMessageEndingWith("Node template is in use, it is referenced in Tosca Policy " + + "operational.apex.decisionMaker version 1.0.0"); //delete unreferenced node template authorativeToscaProvider.deleteToscaNodeTemplate(pfDao, "apexMetadata_adaptive", "2.3.1"); 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 e80d6248c..a2675781f 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 @@ -79,14 +79,9 @@ class AuthorativeToscaProviderPolicyTest { Properties jdbcProperties = new Properties(); jdbcProperties.setProperty("jakarta.persistence.jdbc.user", "policy"); jdbcProperties.setProperty("jakarta.persistence.jdbc.password", "P01icY"); - if (System.getProperty("USE-MARIADB") != null) { - jdbcProperties.setProperty("jakarta.persistence.jdbc.driver", "org.mariadb.jdbc.Driver"); - jdbcProperties.setProperty("jakarta.persistence.jdbc.url", "jdbc:mariadb://localhost:3306/policy"); - } else { - jdbcProperties.setProperty("jakarta.persistence.jdbc.driver", "org.h2.Driver"); - jdbcProperties.setProperty("jakarta.persistence.jdbc.url", - "jdbc:h2:mem:AuthorativeToscaProviderPolicyTest"); - } + jdbcProperties.setProperty("jakarta.persistence.jdbc.driver", "org.h2.Driver"); + jdbcProperties.setProperty("jakarta.persistence.jdbc.url", + "jdbc:h2:mem:AuthorativeToscaProviderPolicyTest"); daoParameters.setJdbcProperties(jdbcProperties); pfDao = new PfDaoFactory().createPfDao(daoParameters); @@ -108,37 +103,35 @@ class AuthorativeToscaProviderPolicyTest { @Test void testPoliciesGet() throws Exception { - assertThatThrownBy(() -> { - new AuthorativeToscaProvider().getPolicies(null, null, null); - }).hasMessageMatching(DAO_IS_NULL); + assertThatThrownBy(() -> new AuthorativeToscaProvider().getPolicies(null, null, null)) + .hasMessageMatching(DAO_IS_NULL); - assertThatThrownBy(() -> { - new AuthorativeToscaProvider().getPolicyList(null, null, null); - }).hasMessageMatching(DAO_IS_NULL); + assertThatThrownBy(() -> new AuthorativeToscaProvider().getPolicyList(null, null, null)) + .hasMessageMatching(DAO_IS_NULL); createPolicyTypes(); ToscaServiceTemplate toscaServiceTemplate = - standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_JSON), ToscaServiceTemplate.class); + standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_JSON), ToscaServiceTemplate.class); assertNotNull(toscaServiceTemplate); ToscaServiceTemplate createdServiceTemplate = - new AuthorativeToscaProvider().createPolicies(pfDao, toscaServiceTemplate); + new AuthorativeToscaProvider().createPolicies(pfDao, toscaServiceTemplate); PfConceptKey policyKey = new PfConceptKey(POLICY_AND_VERSION); ToscaPolicy beforePolicy = - toscaServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName()); + toscaServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName()); ToscaPolicy createdPolicy = - createdServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName()); + createdServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName()); assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, createdPolicy)); assertEquals(beforePolicy.getType(), createdPolicy.getType()); ToscaServiceTemplate gotServiceTemplate = - new AuthorativeToscaProvider().getPolicies(pfDao, policyKey.getName(), policyKey.getVersion()); + new AuthorativeToscaProvider().getPolicies(pfDao, policyKey.getName(), policyKey.getVersion()); ToscaPolicy gotPolicy = - gotServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName()); + gotServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName()); assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicy)); assertEquals(beforePolicy.getType(), gotPolicy.getType()); @@ -163,67 +156,59 @@ class AuthorativeToscaProviderPolicyTest { @Test void testPoliciesGetFiltered() throws Exception { - assertThatThrownBy(() -> { - new AuthorativeToscaProvider().getFilteredPolicies(null, null); - }).hasMessageMatching(DAO_IS_NULL); + assertThatThrownBy(() -> new AuthorativeToscaProvider().getFilteredPolicies(null, null)) + .hasMessageMatching(DAO_IS_NULL); - assertThatThrownBy(() -> { - new AuthorativeToscaProvider().getFilteredPolicies(null, - ToscaTypedEntityFilter.<ToscaPolicy>builder().build()); - }).hasMessageMatching(DAO_IS_NULL); + assertThatThrownBy(() -> new AuthorativeToscaProvider().getFilteredPolicies(null, + ToscaTypedEntityFilter.<ToscaPolicy>builder().build())).hasMessageMatching(DAO_IS_NULL); - assertThatThrownBy(() -> { - new AuthorativeToscaProvider().getFilteredPolicies(pfDao, null); - }).hasMessageMatching("^filter is marked .*on.*ull but is null$"); + assertThatThrownBy(() -> new AuthorativeToscaProvider().getFilteredPolicies(pfDao, null)) + .hasMessageMatching("^filter is marked .*on.*ull but is null$"); - assertThatThrownBy(() -> { - new AuthorativeToscaProvider().getFilteredPolicyList(null, null); - }).hasMessageMatching(DAO_IS_NULL); + assertThatThrownBy(() -> new AuthorativeToscaProvider().getFilteredPolicyList(null, null)) + .hasMessageMatching(DAO_IS_NULL); - assertThatThrownBy(() -> { - new AuthorativeToscaProvider().getFilteredPolicyList(null, - ToscaTypedEntityFilter.<ToscaPolicy>builder().build()); - }).hasMessageMatching(DAO_IS_NULL); + assertThatThrownBy(() -> new AuthorativeToscaProvider().getFilteredPolicyList(null, + ToscaTypedEntityFilter.<ToscaPolicy>builder().build())).hasMessageMatching(DAO_IS_NULL); - assertThatThrownBy(() -> { - new AuthorativeToscaProvider().getFilteredPolicyList(pfDao, null); - }).hasMessageMatching("^filter is marked .*on.*ull but is null$"); + assertThatThrownBy(() -> new AuthorativeToscaProvider().getFilteredPolicyList(pfDao, null)) + .hasMessageMatching("^filter is marked .*on.*ull but is null$"); createPolicyTypes(); ToscaServiceTemplate toscaServiceTemplate = - standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_JSON), ToscaServiceTemplate.class); + standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_JSON), ToscaServiceTemplate.class); assertNotNull(toscaServiceTemplate); ToscaServiceTemplate createdServiceTemplate = - new AuthorativeToscaProvider().createPolicies(pfDao, toscaServiceTemplate); + new AuthorativeToscaProvider().createPolicies(pfDao, toscaServiceTemplate); PfConceptKey policyKey = new PfConceptKey(POLICY_AND_VERSION); ToscaPolicy beforePolicy = - toscaServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName()); + toscaServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName()); ToscaPolicy createdPolicy = - createdServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName()); + createdServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName()); assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, createdPolicy)); assertEquals(beforePolicy.getType(), createdPolicy.getType()); ToscaServiceTemplate gotServiceTemplate = new AuthorativeToscaProvider().getFilteredPolicies(pfDao, - ToscaTypedEntityFilter.<ToscaPolicy>builder().build()); + ToscaTypedEntityFilter.<ToscaPolicy>builder().build()); ToscaPolicy gotPolicy = - gotServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName()); + gotServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName()); assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicy)); assertEquals(beforePolicy.getType(), gotPolicy.getType()); gotServiceTemplate = new AuthorativeToscaProvider().getFilteredPolicies(pfDao, - ToscaTypedEntityFilter.<ToscaPolicy>builder().name(policyKey.getName()).build()); + ToscaTypedEntityFilter.<ToscaPolicy>builder().name(policyKey.getName()).build()); gotPolicy = gotServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName()); assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicy)); assertEquals(beforePolicy.getType(), gotPolicy.getType()); gotServiceTemplate = new AuthorativeToscaProvider().getFilteredPolicies(pfDao, - ToscaTypedEntityFilter.<ToscaPolicy>builder().name(policyKey.getName()).version(VERSION_100).build()); + ToscaTypedEntityFilter.<ToscaPolicy>builder().name(policyKey.getName()).version(VERSION_100).build()); gotPolicy = gotServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName()); assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicy)); @@ -234,152 +219,138 @@ class AuthorativeToscaProviderPolicyTest { assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicyList.get(0))); gotPolicyList = new AuthorativeToscaProvider().getFilteredPolicyList(pfDao, - ToscaTypedEntityFilter.<ToscaPolicy>builder().build()); + ToscaTypedEntityFilter.<ToscaPolicy>builder().build()); assertEquals(1, gotPolicyList.size()); assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicyList.get(0))); gotPolicyList = new AuthorativeToscaProvider().getFilteredPolicyList(pfDao, - ToscaTypedEntityFilter.<ToscaPolicy>builder().name(policyKey.getName()).build()); + ToscaTypedEntityFilter.<ToscaPolicy>builder().name(policyKey.getName()).build()); assertEquals(1, gotPolicyList.size()); assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicyList.get(0))); gotPolicyList = new AuthorativeToscaProvider().getFilteredPolicyList(pfDao, - ToscaTypedEntityFilter.<ToscaPolicy>builder().name(policyKey.getName()).version(VERSION_100).build()); + ToscaTypedEntityFilter.<ToscaPolicy>builder().name(policyKey.getName()).version(VERSION_100).build()); assertEquals(1, gotPolicyList.size()); assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicyList.get(0))); } @Test void testPolicyCreate() throws Exception { - assertThatThrownBy(() -> { - new AuthorativeToscaProvider().createPolicies(null, null); - }).hasMessageMatching(DAO_IS_NULL); + assertThatThrownBy(() -> new AuthorativeToscaProvider().createPolicies(null, null)) + .hasMessageMatching(DAO_IS_NULL); - assertThatThrownBy(() -> { - new AuthorativeToscaProvider().createPolicies(null, new ToscaServiceTemplate()); - }).hasMessageMatching(DAO_IS_NULL); + assertThatThrownBy(() -> new AuthorativeToscaProvider().createPolicies(null, new ToscaServiceTemplate())) + .hasMessageMatching(DAO_IS_NULL); - assertThatThrownBy(() -> { - new AuthorativeToscaProvider().createPolicies(pfDao, null); - }).hasMessageMatching("^serviceTemplate is marked .*on.*ull but is null$"); + assertThatThrownBy(() -> new AuthorativeToscaProvider().createPolicies(pfDao, null)) + .hasMessageMatching("^serviceTemplate is marked .*on.*ull but is null$"); createPolicyTypes(); ToscaServiceTemplate toscaServiceTemplate = - standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_JSON), ToscaServiceTemplate.class); + standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_JSON), ToscaServiceTemplate.class); assertNotNull(toscaServiceTemplate); ToscaServiceTemplate createdServiceTemplate = - new AuthorativeToscaProvider().createPolicies(pfDao, toscaServiceTemplate); + new AuthorativeToscaProvider().createPolicies(pfDao, toscaServiceTemplate); PfConceptKey policyKey = new PfConceptKey(POLICY_AND_VERSION); ToscaPolicy beforePolicy = - toscaServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName()); + toscaServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName()); ToscaPolicy createdPolicy = - createdServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName()); + createdServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName()); assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, createdPolicy)); assertEquals(beforePolicy.getType(), createdPolicy.getType()); } @Test void testPolicyUpdate() throws Exception { - assertThatThrownBy(() -> { - new AuthorativeToscaProvider().createPolicies(null, null); - }).hasMessageMatching(DAO_IS_NULL); + assertThatThrownBy(() -> new AuthorativeToscaProvider().createPolicies(null, null)) + .hasMessageMatching(DAO_IS_NULL); - assertThatThrownBy(() -> { - new AuthorativeToscaProvider().updatePolicies(null, null); - }).hasMessageMatching(DAO_IS_NULL); + assertThatThrownBy(() -> new AuthorativeToscaProvider().updatePolicies(null, null)) + .hasMessageMatching(DAO_IS_NULL); - assertThatThrownBy(() -> { - new AuthorativeToscaProvider().updatePolicies(null, new ToscaServiceTemplate()); - }).hasMessageMatching(DAO_IS_NULL); + assertThatThrownBy(() -> new AuthorativeToscaProvider().updatePolicies(null, new ToscaServiceTemplate())) + .hasMessageMatching(DAO_IS_NULL); - assertThatThrownBy(() -> { - new AuthorativeToscaProvider().updatePolicies(pfDao, null); - }).hasMessageMatching("^serviceTemplate is marked .*on.*ull but is null$"); + assertThatThrownBy(() -> new AuthorativeToscaProvider().updatePolicies(pfDao, null)) + .hasMessageMatching("^serviceTemplate is marked .*on.*ull but is null$"); createPolicyTypes(); ToscaServiceTemplate toscaServiceTemplate = - standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_JSON), ToscaServiceTemplate.class); + standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_JSON), ToscaServiceTemplate.class); assertNotNull(toscaServiceTemplate); ToscaServiceTemplate createdServiceTemplate = - new AuthorativeToscaProvider().createPolicies(pfDao, toscaServiceTemplate); + new AuthorativeToscaProvider().createPolicies(pfDao, toscaServiceTemplate); PfConceptKey policyKey = new PfConceptKey(POLICY_AND_VERSION); ToscaPolicy beforePolicy = - toscaServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName()); + toscaServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName()); ToscaPolicy createdPolicy = - createdServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName()); + createdServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName()); assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, createdPolicy)); assertEquals(beforePolicy.getType(), createdPolicy.getType()); ToscaServiceTemplate updatedServiceTemplate = - new AuthorativeToscaProvider().updatePolicies(pfDao, toscaServiceTemplate); + new AuthorativeToscaProvider().updatePolicies(pfDao, toscaServiceTemplate); ToscaPolicy updatedPolicy = - updatedServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName()); + updatedServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName()); assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, updatedPolicy)); assertEquals(beforePolicy.getType(), updatedPolicy.getType()); } @Test void testPoliciesDelete() throws Exception { - assertThatThrownBy(() -> { - new AuthorativeToscaProvider().deletePolicy(null, null, null); - }).hasMessageMatching(DAO_IS_NULL); + assertThatThrownBy(() -> new AuthorativeToscaProvider().deletePolicy(null, null, null)) + .hasMessageMatching(DAO_IS_NULL); - assertThatThrownBy(() -> { - new AuthorativeToscaProvider().deletePolicy(null, null, VERSION); - }).hasMessageMatching(DAO_IS_NULL); + assertThatThrownBy(() -> new AuthorativeToscaProvider().deletePolicy(null, null, VERSION)) + .hasMessageMatching(DAO_IS_NULL); - assertThatThrownBy(() -> { - new AuthorativeToscaProvider().deletePolicy(null, "name", null); - }).hasMessageMatching(DAO_IS_NULL); + assertThatThrownBy(() -> new AuthorativeToscaProvider().deletePolicy(null, "name", null)) + .hasMessageMatching(DAO_IS_NULL); - assertThatThrownBy(() -> { - new AuthorativeToscaProvider().deletePolicy(null, "name", VERSION); - }).hasMessageMatching(DAO_IS_NULL); + assertThatThrownBy(() -> new AuthorativeToscaProvider().deletePolicy(null, "name", VERSION)) + .hasMessageMatching(DAO_IS_NULL); - assertThatThrownBy(() -> { - new AuthorativeToscaProvider().deletePolicy(pfDao, null, null); - }).hasMessageMatching("^name is marked .*on.*ull but is null$"); + assertThatThrownBy(() -> new AuthorativeToscaProvider().deletePolicy(pfDao, null, null)) + .hasMessageMatching("^name is marked .*on.*ull but is null$"); - assertThatThrownBy(() -> { - new AuthorativeToscaProvider().deletePolicy(pfDao, null, VERSION); - }).hasMessageMatching("^name is marked .*on.*ull but is null$"); + assertThatThrownBy(() -> new AuthorativeToscaProvider().deletePolicy(pfDao, null, VERSION)) + .hasMessageMatching("^name is marked .*on.*ull but is null$"); - assertThatThrownBy(() -> { - new AuthorativeToscaProvider().deletePolicy(pfDao, "name", null); - }).hasMessageMatching("^version is marked .*on.*ull but is null$"); + assertThatThrownBy(() -> new AuthorativeToscaProvider().deletePolicy(pfDao, "name", null)) + .hasMessageMatching("^version is marked .*on.*ull but is null$"); createPolicyTypes(); ToscaServiceTemplate toscaServiceTemplate = - standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_JSON), ToscaServiceTemplate.class); + standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_JSON), ToscaServiceTemplate.class); assertNotNull(toscaServiceTemplate); ToscaServiceTemplate createdServiceTemplate = - new AuthorativeToscaProvider().createPolicies(pfDao, toscaServiceTemplate); + new AuthorativeToscaProvider().createPolicies(pfDao, toscaServiceTemplate); PfConceptKey policyKey = new PfConceptKey(POLICY_AND_VERSION); ToscaPolicy beforePolicy = - toscaServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName()); + toscaServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName()); ToscaPolicy createdPolicy = - createdServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName()); + createdServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName()); assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, createdPolicy)); assertEquals(beforePolicy.getType(), createdPolicy.getType()); ToscaServiceTemplate deletedServiceTemplate = - new AuthorativeToscaProvider().deletePolicy(pfDao, policyKey.getName(), policyKey.getVersion()); + new AuthorativeToscaProvider().deletePolicy(pfDao, policyKey.getName(), policyKey.getVersion()); ToscaPolicy deletedPolicy = - deletedServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName()); + deletedServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName()); assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, createdPolicy)); assertEquals(beforePolicy.getType(), deletedPolicy.getType()); @@ -394,33 +365,29 @@ class AuthorativeToscaProviderPolicyTest { void testAssertPoliciesExist() { ToscaServiceTemplate testServiceTemplate = new ToscaServiceTemplate(); - assertThatThrownBy(() -> { - new AuthorativeToscaProvider().deletePolicy(pfDao, "name", null); - }).hasMessageMatching("^version is marked .*on.*ull but is null$"); + assertThatThrownBy(() -> new AuthorativeToscaProvider().deletePolicy(pfDao, "name", null)) + .hasMessageMatching("^version is marked .*on.*ull but is null$"); - assertThatThrownBy(() -> { - new AuthorativeToscaProvider().createPolicies(pfDao, testServiceTemplate); - }).hasMessage("topology template not specified on service template"); + assertThatThrownBy(() -> new AuthorativeToscaProvider().createPolicies(pfDao, testServiceTemplate)) + .hasMessage("topology template not specified on service template"); testServiceTemplate.setToscaTopologyTemplate(new ToscaTopologyTemplate()); - assertThatThrownBy(() -> { - new AuthorativeToscaProvider().createPolicies(pfDao, testServiceTemplate); - }).hasMessage("no policies specified on topology template of service template"); + assertThatThrownBy(() -> new AuthorativeToscaProvider().createPolicies(pfDao, testServiceTemplate)) + .hasMessage("no policies specified on topology template of service template"); testServiceTemplate.getToscaTopologyTemplate().setPolicies(new ArrayList<>()); - assertThatThrownBy(() -> { - new AuthorativeToscaProvider().createPolicies(pfDao, testServiceTemplate); - }).hasMessage("An incoming list of concepts must have at least one entry"); + assertThatThrownBy(() -> new AuthorativeToscaProvider().createPolicies(pfDao, testServiceTemplate)) + .hasMessage("An incoming list of concepts must have at least one entry"); } @Test void testEntityMaps() throws CoderException, PfModelException { - Object yamlObject = - new Yaml().load(ResourceUtils.getResourceAsString("policytypes/onap.policies.monitoring.tcagen2.yaml")); + Object yamlObject = 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); @@ -429,19 +396,19 @@ class AuthorativeToscaProviderPolicyTest { assertEquals(2, toscaServiceTemplatePolicyType.getPolicyTypesAsMap().size()); ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode( - ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"), - ToscaServiceTemplate.class); + ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"), + ToscaServiceTemplate.class); assertNotNull(toscaServiceTemplate); ToscaServiceTemplate createdServiceTemplate = - new AuthorativeToscaProvider().createPolicies(pfDao, toscaServiceTemplate); + new AuthorativeToscaProvider().createPolicies(pfDao, toscaServiceTemplate); PfConceptKey policyKey = new PfConceptKey("onap.restart.tca:1.0.0"); ToscaPolicy beforePolicy = - toscaServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName()); + toscaServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName()); ToscaPolicy createdPolicy = - createdServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName()); + createdServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName()); assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, createdPolicy)); assertEquals(beforePolicy.getType(), createdPolicy.getType()); @@ -451,9 +418,8 @@ class AuthorativeToscaProviderPolicyTest { Map<String, ToscaPolicy> policyMapItem = createdServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0); createdServiceTemplate.getToscaTopologyTemplate().getPolicies().add(policyMapItem); - assertThatThrownBy(() -> { - createdServiceTemplate.getToscaTopologyTemplate().getPoliciesAsMap(); - }).hasMessageContaining("list of map of entities contains more than one entity with key"); + assertThatThrownBy(() -> createdServiceTemplate.getToscaTopologyTemplate().getPoliciesAsMap()) + .hasMessageContaining("list of map of entities contains more than one entity with key"); ToscaDataType duplDataType = toscaServiceTemplatePolicyType.getDataTypes().values().iterator().next(); @@ -465,11 +431,11 @@ class AuthorativeToscaProviderPolicyTest { 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/authorative/provider/AuthorativeToscaProviderPolicyTypeTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderPolicyTypeTest.java index a993b303b..9ae7842a6 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, 2023-2024 Nordix Foundation. + * Copyright (C) 2019-2021, 2023-2025 Nordix Foundation. * Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -65,7 +65,6 @@ class AuthorativeToscaProviderPolicyTypeTest { /** * Read the policy type definition. * - * @throws Exception on errors */ @BeforeAll public static void readPolicyDefinition() { @@ -90,14 +89,9 @@ class AuthorativeToscaProviderPolicyTypeTest { Properties jdbcProperties = new Properties(); jdbcProperties.setProperty("jakarta.persistence.jdbc.user", "policy"); jdbcProperties.setProperty("jakarta.persistence.jdbc.password", "P01icY"); - if (System.getProperty("USE-MARIADB") != null) { - jdbcProperties.setProperty("jakarta.persistence.jdbc.driver", "org.mariadb.jdbc.Driver"); - jdbcProperties.setProperty("jakarta.persistence.jdbc.url", "jdbc:mariadb://localhost:3306/policy"); - } else { - jdbcProperties.setProperty("jakarta.persistence.jdbc.driver", "org.h2.Driver"); - jdbcProperties.setProperty("jakarta.persistence.jdbc.url", - "jdbc:h2:mem:AuthorativeToscaProviderPolicyTypeTest"); - } + jdbcProperties.setProperty("jakarta.persistence.jdbc.driver", "org.h2.Driver"); + jdbcProperties.setProperty("jakarta.persistence.jdbc.url", + "jdbc:h2:mem:AuthorativeToscaProviderPolicyTypeTest"); daoParameters.setJdbcProperties(jdbcProperties); pfDao = new PfDaoFactory().createPfDao(daoParameters); @@ -119,13 +113,11 @@ class AuthorativeToscaProviderPolicyTypeTest { @Test void testPolicyTypesGet() throws Exception { - assertThatThrownBy(() -> { - new AuthorativeToscaProvider().getPolicyTypes(null, null, null); - }).hasMessageMatching(DAO_IS_NULL); + assertThatThrownBy(() -> new AuthorativeToscaProvider().getPolicyTypes(null, null, null)) + .hasMessageMatching(DAO_IS_NULL); - assertThatThrownBy(() -> { - new AuthorativeToscaProvider().getPolicyList(null, null, null); - }).hasMessageMatching(DAO_IS_NULL); + assertThatThrownBy(() -> new AuthorativeToscaProvider().getPolicyList(null, null, null)) + .hasMessageMatching(DAO_IS_NULL); ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class); @@ -137,32 +129,32 @@ class AuthorativeToscaProviderPolicyTypeTest { ToscaPolicyType beforePolicyType = toscaServiceTemplate.getPolicyTypes().get(policyTypeKey.getName()); ToscaPolicyType createdPolicyType = createdServiceTemplate.getPolicyTypes().get(policyTypeKey.getName()); - assertEquals(true, beforePolicyType.getName().equals(createdPolicyType.getName())); + assertEquals(beforePolicyType.getName(), createdPolicyType.getName()); assertEquals(0, ObjectUtils.compare(beforePolicyType.getDescription(), createdPolicyType.getDescription())); ToscaServiceTemplate gotServiceTemplate = new AuthorativeToscaProvider().getPolicyTypes(pfDao, policyTypeKey.getName(), policyTypeKey.getVersion()); ToscaPolicyType gotPolicyType = gotServiceTemplate.getPolicyTypes().get(policyTypeKey.getName()); - assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName())); + assertEquals(beforePolicyType.getName(), gotPolicyType.getName()); assertEquals(0, ObjectUtils.compare(beforePolicyType.getDescription(), createdPolicyType.getDescription())); List<ToscaPolicyType> gotPolicyTypeList = new AuthorativeToscaProvider().getPolicyTypeList(pfDao, POLICY_NO_VERSION, VERSION_001); assertEquals(2, gotPolicyTypeList.size()); - assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName())); + assertEquals(beforePolicyType.getName(), gotPolicyType.getName()); gotPolicyTypeList = new AuthorativeToscaProvider().getPolicyTypeList(pfDao, POLICY_NO_VERSION, null); assertEquals(2, gotPolicyTypeList.size()); - assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName())); + assertEquals(beforePolicyType.getName(), gotPolicyType.getName()); gotPolicyTypeList = new AuthorativeToscaProvider().getPolicyTypeList(pfDao, null, null); assertEquals(2, gotPolicyTypeList.size()); - assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName())); + assertEquals(beforePolicyType.getName(), gotPolicyType.getName()); gotPolicyTypeList = new AuthorativeToscaProvider().getPolicyTypeList(pfDao, null, VERSION_001); assertEquals(2, gotPolicyTypeList.size()); - assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName())); + assertEquals(beforePolicyType.getName(), gotPolicyType.getName()); assertThatThrownBy(() -> new AuthorativeToscaProvider().getPolicyTypeList(new DefaultPfDao(), POLICY_NO_VERSION, VERSION_001)).hasMessageContaining("Policy Framework DAO has not been initialized"); @@ -172,31 +164,24 @@ class AuthorativeToscaProviderPolicyTypeTest { @Test void testPolicyTypesGetFiltered() throws Exception { - assertThatThrownBy(() -> { - new AuthorativeToscaProvider().getFilteredPolicyTypes(null, null); - }).hasMessageMatching(DAO_IS_NULL); + assertThatThrownBy(() -> new AuthorativeToscaProvider().getFilteredPolicyTypes(null, null)) + .hasMessageMatching(DAO_IS_NULL); - assertThatThrownBy(() -> { - new AuthorativeToscaProvider().getFilteredPolicyTypes(null, - ToscaEntityFilter.<ToscaPolicyType>builder().build()); - }).hasMessageMatching(DAO_IS_NULL); + assertThatThrownBy(() -> new AuthorativeToscaProvider().getFilteredPolicyTypes(null, + ToscaEntityFilter.<ToscaPolicyType>builder().build())).hasMessageMatching(DAO_IS_NULL); - assertThatThrownBy(() -> { - new AuthorativeToscaProvider().getFilteredPolicyTypes(pfDao, null); - }).hasMessageMatching("^filter is marked .*on.*ull but is null$"); + assertThatThrownBy(() -> new AuthorativeToscaProvider().getFilteredPolicyTypes(pfDao, null)) + .hasMessageMatching("^filter is marked .*on.*ull but is null$"); - assertThatThrownBy(() -> { - new AuthorativeToscaProvider().getFilteredPolicyTypeList(null, null); - }).hasMessageMatching(DAO_IS_NULL); + assertThatThrownBy(() -> new AuthorativeToscaProvider().getFilteredPolicyTypeList(null, null)) + .hasMessageMatching(DAO_IS_NULL); - assertThatThrownBy(() -> { - new AuthorativeToscaProvider().getFilteredPolicyTypeList(null, - ToscaEntityFilter.<ToscaPolicyType>builder().build()); - }).hasMessageMatching(DAO_IS_NULL); + assertThatThrownBy(() -> new AuthorativeToscaProvider().getFilteredPolicyTypeList(null, + ToscaEntityFilter.<ToscaPolicyType>builder().build())) + .hasMessageMatching(DAO_IS_NULL); - assertThatThrownBy(() -> { - new AuthorativeToscaProvider().getFilteredPolicyTypeList(pfDao, null); - }).hasMessageMatching("^filter is marked .*on.*ull but is null$"); + assertThatThrownBy(() -> new AuthorativeToscaProvider().getFilteredPolicyTypeList(pfDao, null)) + .hasMessageMatching("^filter is marked .*on.*ull but is null$"); assertThatThrownBy(() -> new AuthorativeToscaProvider().getFilteredPolicyTypeList(new DefaultPfDao(), ToscaEntityFilter.<ToscaPolicyType>builder().name("i.dont.Exist").build())) @@ -215,7 +200,7 @@ class AuthorativeToscaProviderPolicyTypeTest { ToscaPolicyType beforePolicyType = toscaServiceTemplate.getPolicyTypes().get(policyTypeKey.getName()); ToscaPolicyType createdPolicyType = createdServiceTemplate.getPolicyTypes().get(policyTypeKey.getName()); - assertEquals(true, beforePolicyType.getName().equals(createdPolicyType.getName())); + assertEquals(beforePolicyType.getName(), createdPolicyType.getName()); assertEquals(0, ObjectUtils.compare(beforePolicyType.getDescription(), createdPolicyType.getDescription())); ToscaServiceTemplate gotServiceTemplate = new AuthorativeToscaProvider().getFilteredPolicyTypes(pfDao, @@ -239,27 +224,27 @@ class AuthorativeToscaProviderPolicyTypeTest { List<ToscaPolicyType> gotPolicyTypeList = new AuthorativeToscaProvider().getPolicyTypeList(pfDao, POLICY_NO_VERSION, VERSION_001); assertEquals(2, gotPolicyTypeList.size()); - assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName())); + assertEquals(beforePolicyType.getName(), gotPolicyType.getName()); gotPolicyTypeList = new AuthorativeToscaProvider().getFilteredPolicyTypeList(pfDao, ToscaEntityFilter.<ToscaPolicyType>builder().build()); assertEquals(2, gotPolicyTypeList.size()); - assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName())); + assertEquals(beforePolicyType.getName(), gotPolicyType.getName()); gotPolicyTypeList = new AuthorativeToscaProvider().getFilteredPolicyTypeList(pfDao, ToscaEntityFilter.<ToscaPolicyType>builder().name(policyTypeKey.getName()).build()); assertEquals(1, gotPolicyTypeList.size()); - assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName())); + assertEquals(beforePolicyType.getName(), gotPolicyType.getName()); gotPolicyTypeList = new AuthorativeToscaProvider().getFilteredPolicyTypeList(pfDao, ToscaEntityFilter .<ToscaPolicyType>builder().name(policyTypeKey.getName()).version(VERSION_001).build()); assertEquals(1, gotPolicyTypeList.size()); - assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName())); + assertEquals(beforePolicyType.getName(), gotPolicyType.getName()); gotPolicyTypeList = new AuthorativeToscaProvider().getFilteredPolicyTypeList(pfDao, ToscaEntityFilter.<ToscaPolicyType>builder().version("1.0.0").build()); assertEquals(1, gotPolicyTypeList.size()); - assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName())); + assertEquals(beforePolicyType.getName(), gotPolicyType.getName()); } private void checkEqualsNameDescription(ToscaPolicyType beforePolicyType, ToscaPolicyType gotPolicyType) { @@ -269,27 +254,22 @@ class AuthorativeToscaProviderPolicyTypeTest { @Test void testPolicyTypesCreate() throws Exception { - assertThatThrownBy(() -> { - new AuthorativeToscaProvider().createPolicyTypes(null, null); - }).hasMessageMatching(DAO_IS_NULL); + assertThatThrownBy(() -> new AuthorativeToscaProvider().createPolicyTypes(null, null)) + .hasMessageMatching(DAO_IS_NULL); - assertThatThrownBy(() -> { - new AuthorativeToscaProvider().createPolicyTypes(null, new ToscaServiceTemplate()); - }).hasMessageMatching(DAO_IS_NULL); + assertThatThrownBy(() -> new AuthorativeToscaProvider().createPolicyTypes(null, new ToscaServiceTemplate())) + .hasMessageMatching(DAO_IS_NULL); - assertThatThrownBy(() -> { - new AuthorativeToscaProvider().createPolicyTypes(pfDao, null); - }).hasMessageMatching("^serviceTemplate is marked .*on.*ull but is null$"); + assertThatThrownBy(() -> new AuthorativeToscaProvider().createPolicyTypes(pfDao, null)) + .hasMessageMatching("^serviceTemplate is marked .*on.*ull but is null$"); ToscaServiceTemplate testToscaServiceTemplate = new ToscaServiceTemplate(); - assertThatThrownBy(() -> { - new AuthorativeToscaProvider().createPolicyTypes(pfDao, testToscaServiceTemplate); - }).hasMessage(MISSING_POLICY_TYPES); + assertThatThrownBy(() -> new AuthorativeToscaProvider().createPolicyTypes(pfDao, testToscaServiceTemplate)) + .hasMessage(MISSING_POLICY_TYPES); testToscaServiceTemplate.setPolicyTypes(new LinkedHashMap<>()); - assertThatThrownBy(() -> { - new AuthorativeToscaProvider().createPolicyTypes(pfDao, testToscaServiceTemplate); - }).hasMessage("An incoming list of concepts must have at least one entry"); + 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); @@ -301,27 +281,23 @@ class AuthorativeToscaProviderPolicyTypeTest { ToscaPolicyType beforePolicyType = toscaServiceTemplate.getPolicyTypes().get(policyTypeKey.getName()); ToscaPolicyType createdPolicyType = createdServiceTemplate.getPolicyTypes().get(policyTypeKey.getName()); - assertEquals(true, beforePolicyType.getName().equals(createdPolicyType.getName())); + assertEquals(beforePolicyType.getName(), createdPolicyType.getName()); assertEquals(0, ObjectUtils.compare(beforePolicyType.getDescription(), createdPolicyType.getDescription())); } @Test void testPolicyTypesUpdate() throws Exception { - assertThatThrownBy(() -> { - new AuthorativeToscaProvider().createPolicyTypes(null, null); - }).hasMessageMatching(DAO_IS_NULL); + assertThatThrownBy(() -> new AuthorativeToscaProvider().createPolicyTypes(null, null)) + .hasMessageMatching(DAO_IS_NULL); - assertThatThrownBy(() -> { - new AuthorativeToscaProvider().updatePolicyTypes(null, null); - }).hasMessageMatching(DAO_IS_NULL); + assertThatThrownBy(() -> new AuthorativeToscaProvider().updatePolicyTypes(null, null)) + .hasMessageMatching(DAO_IS_NULL); - assertThatThrownBy(() -> { - new AuthorativeToscaProvider().updatePolicyTypes(null, new ToscaServiceTemplate()); - }).hasMessageMatching(DAO_IS_NULL); + assertThatThrownBy(() -> new AuthorativeToscaProvider().updatePolicyTypes(null, new ToscaServiceTemplate())) + .hasMessageMatching(DAO_IS_NULL); - assertThatThrownBy(() -> { - new AuthorativeToscaProvider().updatePolicyTypes(pfDao, null); - }).hasMessageMatching("^serviceTemplate is marked .*on.*ull but is null$"); + assertThatThrownBy(() -> new AuthorativeToscaProvider().updatePolicyTypes(pfDao, null)) + .hasMessageMatching("^serviceTemplate is marked .*on.*ull but is null$"); ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class); @@ -333,46 +309,39 @@ class AuthorativeToscaProviderPolicyTypeTest { ToscaPolicyType beforePolicyType = toscaServiceTemplate.getPolicyTypes().get(policyTypeKey.getName()); ToscaPolicyType createdPolicyType = createdServiceTemplate.getPolicyTypes().get(policyTypeKey.getName()); - assertEquals(true, beforePolicyType.getName().equals(createdPolicyType.getName())); + assertEquals(beforePolicyType.getName(), createdPolicyType.getName()); assertEquals(0, ObjectUtils.compare(beforePolicyType.getDescription(), createdPolicyType.getDescription())); ToscaServiceTemplate updatedServiceTemplate = new AuthorativeToscaProvider().updatePolicyTypes(pfDao, toscaServiceTemplate); ToscaPolicyType updatedPolicy = updatedServiceTemplate.getPolicyTypes().get(policyTypeKey.getName()); - assertEquals(true, beforePolicyType.getName().equals(updatedPolicy.getName())); + assertEquals(beforePolicyType.getName(), updatedPolicy.getName()); assertEquals(0, ObjectUtils.compare(beforePolicyType.getDescription(), updatedPolicy.getDescription())); } @Test void testPolicyTypesDelete() throws Exception { - assertThatThrownBy(() -> { - new AuthorativeToscaProvider().deletePolicyType(null, null, null); - }).hasMessageMatching(DAO_IS_NULL); + assertThatThrownBy(() -> new AuthorativeToscaProvider().deletePolicyType(null, null, null)) + .hasMessageMatching(DAO_IS_NULL); - assertThatThrownBy(() -> { - new AuthorativeToscaProvider().deletePolicyType(null, null, VERSION); - }).hasMessageMatching(DAO_IS_NULL); + assertThatThrownBy(() -> new AuthorativeToscaProvider().deletePolicyType(null, null, VERSION)) + .hasMessageMatching(DAO_IS_NULL); - assertThatThrownBy(() -> { - new AuthorativeToscaProvider().deletePolicyType(null, "name", null); - }).hasMessageMatching(DAO_IS_NULL); + assertThatThrownBy(() -> new AuthorativeToscaProvider().deletePolicyType(null, "name", null)) + .hasMessageMatching(DAO_IS_NULL); - assertThatThrownBy(() -> { - new AuthorativeToscaProvider().deletePolicyType(null, "name", VERSION); - }).hasMessageMatching(DAO_IS_NULL); + assertThatThrownBy(() -> new AuthorativeToscaProvider().deletePolicyType(null, "name", VERSION)) + .hasMessageMatching(DAO_IS_NULL); - assertThatThrownBy(() -> { - new AuthorativeToscaProvider().deletePolicyType(pfDao, null, null); - }).hasMessageMatching("^name is marked .*on.*ull but is null$"); + assertThatThrownBy(() -> new AuthorativeToscaProvider().deletePolicyType(pfDao, null, null)) + .hasMessageMatching("^name is marked .*on.*ull but is null$"); - assertThatThrownBy(() -> { - new AuthorativeToscaProvider().deletePolicyType(pfDao, null, VERSION); - }).hasMessageMatching("^name is marked .*on.*ull but is null$"); + assertThatThrownBy(() -> new AuthorativeToscaProvider().deletePolicyType(pfDao, null, VERSION)) + .hasMessageMatching("^name is marked .*on.*ull but is null$"); - assertThatThrownBy(() -> { - new AuthorativeToscaProvider().deletePolicyType(pfDao, "name", null); - }).hasMessageMatching("^version is marked .*on.*ull but is null$"); + assertThatThrownBy(() -> new AuthorativeToscaProvider().deletePolicyType(pfDao, "name", null)) + .hasMessageMatching("^version is marked .*on.*ull but is null$"); ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class); @@ -384,42 +353,38 @@ class AuthorativeToscaProviderPolicyTypeTest { ToscaPolicyType beforePolicyType = toscaServiceTemplate.getPolicyTypes().get(policyTypeKey.getName()); ToscaPolicyType createdPolicyType = createdServiceTemplate.getPolicyTypes().get(policyTypeKey.getName()); - assertEquals(true, beforePolicyType.getName().equals(createdPolicyType.getName())); + assertEquals(beforePolicyType.getName(), createdPolicyType.getName()); assertEquals(0, ObjectUtils.compare(beforePolicyType.getDescription(), createdPolicyType.getDescription())); ToscaServiceTemplate deletedServiceTemplate = new AuthorativeToscaProvider().deletePolicyType(pfDao, policyTypeKey.getName(), policyTypeKey.getVersion()); ToscaPolicyType deletedPolicy = deletedServiceTemplate.getPolicyTypes().get(policyTypeKey.getName()); - assertEquals(true, beforePolicyType.getName().equals(deletedPolicy.getName())); + assertEquals(beforePolicyType.getName(), deletedPolicy.getName()); assertEquals(0, ObjectUtils.compare(beforePolicyType.getDescription(), deletedPolicy.getDescription())); - assertThatThrownBy(() -> { - new AuthorativeToscaProvider().getPolicyTypes(pfDao, policyTypeKey.getName(), policyTypeKey.getVersion()); - }).hasMessage("policy types for onap.policies.NoVersion:0.0.1 do not exist"); + assertThatThrownBy(() -> new AuthorativeToscaProvider() + .getPolicyTypes(pfDao, policyTypeKey.getName(), policyTypeKey.getVersion())) + .hasMessage("policy types for onap.policies.NoVersion:0.0.1 do not exist"); } @Test void testAssertPoliciesExist() { ToscaServiceTemplate testServiceTemplate = new ToscaServiceTemplate(); - assertThatThrownBy(() -> { - new AuthorativeToscaProvider().deletePolicyType(pfDao, "name", null); - }).hasMessageMatching("^version is marked .*on.*ull but is null$"); + assertThatThrownBy(() -> new AuthorativeToscaProvider().deletePolicyType(pfDao, "name", null)) + .hasMessageMatching("^version is marked .*on.*ull but is null$"); - assertThatThrownBy(() -> { - new AuthorativeToscaProvider().createPolicyTypes(pfDao, testServiceTemplate); - }).hasMessage(MISSING_POLICY_TYPES); + assertThatThrownBy(() -> new AuthorativeToscaProvider().createPolicyTypes(pfDao, testServiceTemplate)) + .hasMessage(MISSING_POLICY_TYPES); testServiceTemplate.setToscaTopologyTemplate(new ToscaTopologyTemplate()); - assertThatThrownBy(() -> { - new AuthorativeToscaProvider().createPolicyTypes(pfDao, testServiceTemplate); - }).hasMessage(MISSING_POLICY_TYPES); + assertThatThrownBy(() -> new AuthorativeToscaProvider().createPolicyTypes(pfDao, testServiceTemplate)) + .hasMessage(MISSING_POLICY_TYPES); testServiceTemplate.setPolicyTypes(new LinkedHashMap<>()); - assertThatThrownBy(() -> { - new AuthorativeToscaProvider().createPolicyTypes(pfDao, testServiceTemplate); - }).hasMessage("An incoming list of concepts must have at least one entry"); + assertThatThrownBy(() -> new AuthorativeToscaProvider().createPolicyTypes(pfDao, testServiceTemplate)) + .hasMessage("An incoming list of concepts must have at least one entry"); } @Test 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 b26b3976f..57df333ae 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 @@ -47,7 +47,6 @@ 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; @@ -57,7 +56,6 @@ 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; /** @@ -90,13 +88,8 @@ class SimpleToscaProviderTest { jdbcProperties.setProperty("jakarta.persistence.jdbc.user", "policy"); jdbcProperties.setProperty("jakarta.persistence.jdbc.password", "P01icY"); - if (System.getProperty("USE-MARIADB") != null) { - jdbcProperties.setProperty("jakarta.persistence.jdbc.driver", "org.mariadb.jdbc.Driver"); - jdbcProperties.setProperty("jakarta.persistence.jdbc.url", "jdbc:mariadb://localhost:3306/policy"); - } else { - jdbcProperties.setProperty("jakarta.persistence.jdbc.driver", "org.h2.Driver"); - jdbcProperties.setProperty("jakarta.persistence.jdbc.url", "jdbc:h2:mem:SimpleToscaProviderTest"); - } + jdbcProperties.setProperty("jakarta.persistence.jdbc.driver", "org.h2.Driver"); + jdbcProperties.setProperty("jakarta.persistence.jdbc.url", "jdbc:h2:mem:SimpleToscaProviderTest"); daoParameters.setJdbcProperties(jdbcProperties); @@ -122,9 +115,9 @@ class SimpleToscaProviderTest { PfConceptKey dataType0Key = new PfConceptKey("DataType0", "0.0.1"); JpaToscaDataType dataType0 = new JpaToscaDataType(); dataType0.setKey(dataType0Key); - dataType0.setConstraints(new ArrayList<JpaToscaConstraint>()); - dataType0.setMetadata(new TreeMap<String, String>()); - dataType0.setProperties(new LinkedHashMap<String, JpaToscaProperty>()); + dataType0.setConstraints(new ArrayList<>()); + dataType0.setMetadata(new TreeMap<>()); + dataType0.setProperties(new LinkedHashMap<>()); JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate(); serviceTemplate.setDataTypes(new JpaToscaDataTypes()); @@ -135,7 +128,7 @@ class SimpleToscaProviderTest { assertEquals(1, createdServiceTemplate.getDataTypes().getConceptMap().size()); assertEquals(dataType0, createdServiceTemplate.getDataTypes().get(dataType0Key)); - assertEquals(null, createdServiceTemplate.getDataTypes().get(dataType0Key).getDescription()); + assertNull(createdServiceTemplate.getDataTypes().get(dataType0Key).getDescription()); dataType0.setDescription("Updated Description"); @@ -190,9 +183,9 @@ class SimpleToscaProviderTest { .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<JpaToscaConstraint>()); - dataType0v2.setMetadata(new TreeMap<String, String>()); - dataType0v2.setProperties(new LinkedHashMap<String, JpaToscaProperty>()); + dataType0v2.setConstraints(new ArrayList<>()); + dataType0v2.setMetadata(new TreeMap<>()); + dataType0v2.setProperties(new LinkedHashMap<>()); updatedServiceTemplate.getDataTypes().getConceptMap().put(dataType0v2.getKey(), dataType0v2); new SimpleToscaProvider().createDataTypes(pfDao, updatedServiceTemplate); @@ -229,10 +222,10 @@ class SimpleToscaProviderTest { PfConceptKey policyType0Key = new PfConceptKey("PolicyType0", "0.0.1"); JpaToscaPolicyType policyType0 = new JpaToscaPolicyType(); policyType0.setKey(policyType0Key); - policyType0.setMetadata(new TreeMap<String, String>()); - policyType0.setProperties(new LinkedHashMap<String, JpaToscaProperty>()); - policyType0.setTargets(new ArrayList<PfConceptKey>()); - policyType0.setTriggers(new ArrayList<JpaToscaTrigger>()); + 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); @@ -241,7 +234,7 @@ class SimpleToscaProviderTest { assertEquals(1, createdServiceTemplate.getPolicyTypes().getConceptMap().size()); assertEquals(policyType0, createdServiceTemplate.getPolicyTypes().get(policyType0Key)); - assertEquals(null, createdServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription()); + assertNull(createdServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription()); policyType0.setDescription("Updated Description"); @@ -258,9 +251,9 @@ class SimpleToscaProviderTest { assertEquals(policyType0, gotServiceTemplate.getPolicyTypes().get(policyType0Key)); assertEquals("Updated Description", gotServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription()); - assertThatThrownBy(() -> { - new SimpleToscaProvider().deletePolicyType(pfDao, new PfConceptKey("IDontExist:0.0.1")); - }).hasMessage("policy type IDontExist:0.0.1 not found"); + assertThatThrownBy( + () -> new SimpleToscaProvider().deletePolicyType(pfDao, new PfConceptKey("IDontExist:0.0.1"))) + .hasMessage("policy type IDontExist:0.0.1 not found"); JpaToscaPolicyType pt1 = new JpaToscaPolicyType(new PfConceptKey("pt1:0.0.2")); pt1.setDerivedFrom(policyType0Key); @@ -314,10 +307,10 @@ class SimpleToscaProviderTest { PfConceptKey policyType0Key = new PfConceptKey("PolicyType0", "0.0.1"); JpaToscaPolicyType policyType0 = new JpaToscaPolicyType(); policyType0.setKey(policyType0Key); - policyType0.setMetadata(new TreeMap<String, String>()); - policyType0.setProperties(new LinkedHashMap<String, JpaToscaProperty>()); - policyType0.setTargets(new ArrayList<PfConceptKey>()); - policyType0.setTriggers(new ArrayList<JpaToscaTrigger>()); + policyType0.setMetadata(new TreeMap<>()); + policyType0.setProperties(new LinkedHashMap<>()); + policyType0.setTargets(new ArrayList<>()); + policyType0.setTriggers(new ArrayList<>()); JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate(); serviceTemplate.setPolicyTypes(new JpaToscaPolicyTypes()); @@ -327,7 +320,7 @@ class SimpleToscaProviderTest { new SimpleToscaProvider().createPolicyTypes(pfDao, serviceTemplate); assertEquals(policyType0, createdServiceTemplate.getPolicyTypes().get(policyType0Key)); - assertEquals(null, createdServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription()); + assertNull(createdServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription()); policyType0.setDescription("Updated Description"); @@ -419,27 +412,23 @@ class SimpleToscaProviderTest { toscaPolicy.setType(null); toscaPolicy.setTypeVersion(null); - assertThatThrownBy(() -> { - originalServiceTemplate.fromAuthorative(toscaServiceTemplate); - }).hasMessage("Type not specified, the type of this TOSCA entity must be specified in the type field"); + assertThatThrownBy(() -> originalServiceTemplate.fromAuthorative(toscaServiceTemplate)) + .hasMessage("Type not specified, the type of this TOSCA entity must be specified in the type field"); toscaPolicy.setType("IDontExist"); - assertThatThrownBy(() -> { - originalServiceTemplate.fromAuthorative(toscaServiceTemplate); - }).hasMessage("Version not specified, the version of this TOSCA entity must be " - + "specified in the type_version field"); + assertThatThrownBy(() -> originalServiceTemplate.fromAuthorative(toscaServiceTemplate)) + .hasMessage("Version not specified, the version of this TOSCA entity must be " + + "specified in the type_version field"); toscaPolicy.setTypeVersion("hello"); - assertThatThrownBy(() -> { - originalServiceTemplate.fromAuthorative(toscaServiceTemplate); - }).hasMessageContaining("value \"hello\", does not match regular expression"); + assertThatThrownBy(() -> originalServiceTemplate.fromAuthorative(toscaServiceTemplate)) + .hasMessageContaining("value \"hello\", does not match regular expression"); toscaPolicy.setTypeVersion("99.100.101"); originalServiceTemplate.fromAuthorative(toscaServiceTemplate); - assertThatThrownBy(() -> { - new SimpleToscaProvider().createPolicies(pfDao, originalServiceTemplate); - }).hasMessageContaining("policy type").hasMessageContaining("IDontExist:99.100.101") + assertThatThrownBy(() -> new SimpleToscaProvider().createPolicies(pfDao, originalServiceTemplate)) + .hasMessageContaining("policy type").hasMessageContaining("IDontExist:99.100.101") .hasMessageContaining(Validated.NOT_FOUND); toscaPolicy.setType("IDontExist"); @@ -447,9 +436,8 @@ class SimpleToscaProviderTest { toscaPolicy.setType(null); - assertThatThrownBy(() -> { - originalServiceTemplate.fromAuthorative(toscaServiceTemplate); - }).hasMessage("Type not specified, the type of this TOSCA entity must be specified in the type field"); + assertThatThrownBy(() -> originalServiceTemplate.fromAuthorative(toscaServiceTemplate)) + .hasMessage("Type not specified, the type of this TOSCA entity must be specified in the type field"); toscaPolicy.setType(originalPolicyType); toscaPolicy.setTypeVersion(originalPolicyTypeVersion); @@ -504,9 +492,9 @@ class SimpleToscaProviderTest { assertEquals(0, originalServiceTemplate.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().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"); @@ -550,9 +538,8 @@ class SimpleToscaProviderTest { @Test void testGetDataTypesCornerCases() throws PfModelException { - assertThatThrownBy(() -> { - new SimpleToscaProvider().getDataTypes(pfDao, "hello", "0.0.1"); - }).hasMessageMatching("service template not found in database"); + assertThatThrownBy(() -> new SimpleToscaProvider().getDataTypes(pfDao, "hello", "0.0.1")) + .hasMessageMatching("service template not found in database"); JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate(); serviceTemplate.setPolicyTypes(new JpaToscaPolicyTypes()); @@ -561,23 +548,21 @@ class SimpleToscaProviderTest { new SimpleToscaProvider().createPolicyTypes(pfDao, serviceTemplate); - assertThatThrownBy(() -> { - new SimpleToscaProvider().getDataTypes(pfDao, "hello", "0.0.1"); - }).hasMessageMatching("data types for hello:0.0.1 do not exist"); + assertThatThrownBy(() -> new SimpleToscaProvider().getDataTypes(pfDao, "hello", "0.0.1")) + .hasMessageMatching("data types for hello:0.0.1 do not exist"); serviceTemplate.setDataTypes(new JpaToscaDataTypes()); JpaToscaDataType dt01 = new JpaToscaDataType(new PfConceptKey("dt0:0.0.1")); - dt01.setConstraints(new ArrayList<JpaToscaConstraint>()); - dt01.setMetadata(new TreeMap<String, String>()); - dt01.setProperties(new LinkedHashMap<String, JpaToscaProperty>()); + dt01.setConstraints(new ArrayList<>()); + dt01.setMetadata(new TreeMap<>()); + dt01.setProperties(new LinkedHashMap<>()); serviceTemplate.getDataTypes().getConceptMap().put(dt01.getKey(), dt01); new SimpleToscaProvider().createDataTypes(pfDao, serviceTemplate); - assertThatThrownBy(() -> { - new SimpleToscaProvider().getDataTypes(pfDao, "hello", "0.0.1"); - }).hasMessageMatching("data types for hello:0.0.1 do not exist"); + assertThatThrownBy(() -> 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, dt01.getName(), dt01.getVersion()); @@ -592,9 +577,9 @@ class SimpleToscaProviderTest { assertEquals(1, gotSt.getDataTypes().getAll(dt01.getName(), dt01.getVersion()).size()); JpaToscaDataType dt02 = new JpaToscaDataType(new PfConceptKey("dt0:0.0.2")); - dt02.setConstraints(new ArrayList<JpaToscaConstraint>()); - dt02.setMetadata(new TreeMap<String, String>()); - dt02.setProperties(new LinkedHashMap<String, JpaToscaProperty>()); + dt02.setConstraints(new ArrayList<>()); + dt02.setMetadata(new TreeMap<>()); + dt02.setProperties(new LinkedHashMap<>()); serviceTemplate.getDataTypes().getConceptMap().put(dt02.getKey(), dt02); new SimpleToscaProvider().createDataTypes(pfDao, serviceTemplate); @@ -613,9 +598,8 @@ class SimpleToscaProviderTest { @Test void testGetPolicyTypesCornerCases() throws PfModelException { - assertThatThrownBy(() -> { - new SimpleToscaProvider().getPolicyTypes(pfDao, "hello", "0.0.1"); - }).hasMessageMatching("service template not found in database"); + assertThatThrownBy(() -> new SimpleToscaProvider().getPolicyTypes(pfDao, "hello", "0.0.1")) + .hasMessageMatching("service template not found in database"); JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate(); serviceTemplate.setDataTypes(new JpaToscaDataTypes()); @@ -624,24 +608,22 @@ class SimpleToscaProviderTest { new SimpleToscaProvider().createDataTypes(pfDao, serviceTemplate); - assertThatThrownBy(() -> { - new SimpleToscaProvider().getPolicyTypes(pfDao, "hello", "0.0.1"); - }).hasMessageMatching("policy types for hello:0.0.1 do not exist"); + assertThatThrownBy(() -> new SimpleToscaProvider().getPolicyTypes(pfDao, "hello", "0.0.1")) + .hasMessageMatching("policy types for hello:0.0.1 do not exist"); serviceTemplate.setPolicyTypes(new JpaToscaPolicyTypes()); JpaToscaPolicyType pt01 = new JpaToscaPolicyType(new PfConceptKey("p0:0.0.1")); - pt01.setMetadata(new TreeMap<String, String>()); - pt01.setProperties(new LinkedHashMap<String, JpaToscaProperty>()); - pt01.setTargets(new ArrayList<PfConceptKey>()); - pt01.setTriggers(new ArrayList<JpaToscaTrigger>()); + 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); - assertThatThrownBy(() -> { - new SimpleToscaProvider().getPolicyTypes(pfDao, "hello", "0.0.1"); - }).hasMessageMatching("policy types for hello:0.0.1 do not exist"); + assertThatThrownBy(() -> new SimpleToscaProvider().getPolicyTypes(pfDao, "hello", "0.0.1")) + .hasMessageMatching("policy types for hello:0.0.1 do not exist"); JpaToscaServiceTemplate gotSt = new SimpleToscaProvider().getPolicyTypes(pfDao, pt01.getName(), pt01.getVersion()); @@ -656,10 +638,10 @@ 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<String, String>()); - pt02.setProperties(new LinkedHashMap<String, JpaToscaProperty>()); - pt02.setTargets(new ArrayList<PfConceptKey>()); - pt02.setTriggers(new ArrayList<JpaToscaTrigger>()); + 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); @@ -678,31 +660,29 @@ class SimpleToscaProviderTest { @Test void testGetPoliciesCornerCases() throws PfModelException { - assertThatThrownBy(() -> { - new SimpleToscaProvider().getPolicies(pfDao, "hello", "0.0.1"); - }).hasMessageMatching("service template not found in database"); + assertThatThrownBy(() -> new SimpleToscaProvider().getPolicies(pfDao, "hello", "0.0.1")) + .hasMessageMatching("service template not found in database"); JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate(); serviceTemplate.setDataTypes(new JpaToscaDataTypes()); JpaToscaDataType dt0 = new JpaToscaDataType(new PfConceptKey("dt0:0.0.1")); - dt0.setConstraints(new ArrayList<JpaToscaConstraint>()); - dt0.setMetadata(new TreeMap<String, String>()); - dt0.setProperties(new LinkedHashMap<String, JpaToscaProperty>()); + dt0.setConstraints(new ArrayList<>()); + dt0.setMetadata(new TreeMap<>()); + dt0.setProperties(new LinkedHashMap<>()); serviceTemplate.getDataTypes().getConceptMap().put(dt0.getKey(), dt0); new SimpleToscaProvider().createDataTypes(pfDao, serviceTemplate); - assertThatThrownBy(() -> { - new SimpleToscaProvider().getPolicies(pfDao, "hello", "0.0.1"); - }).hasMessageMatching("policies for hello:0.0.1 do not exist"); + assertThatThrownBy(() -> new SimpleToscaProvider().getPolicies(pfDao, "hello", "0.0.1")) + .hasMessageMatching("policies for hello:0.0.1 do not exist"); serviceTemplate.setPolicyTypes(new JpaToscaPolicyTypes()); JpaToscaPolicyType pt01 = new JpaToscaPolicyType(new PfConceptKey("pt0:0.0.1")); - pt01.setMetadata(new TreeMap<String, String>()); - pt01.setProperties(new LinkedHashMap<String, JpaToscaProperty>()); - pt01.setTargets(new ArrayList<PfConceptKey>()); - pt01.setTriggers(new ArrayList<JpaToscaTrigger>()); + 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()); @@ -710,16 +690,15 @@ class SimpleToscaProviderTest { JpaToscaPolicy p01 = new JpaToscaPolicy(new PfConceptKey("p0:0.0.1")); p01.setType(pt01.getKey()); - p01.setMetadata(new TreeMap<String, String>()); - p01.setProperties(new LinkedHashMap<String, String>()); - p01.setTargets(new ArrayList<PfConceptKey>()); + 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); - assertThatThrownBy(() -> { - new SimpleToscaProvider().getPolicies(pfDao, "hello", "0.0.1"); - }).hasMessageMatching("policies for hello:0.0.1 do not exist"); + assertThatThrownBy(() -> new SimpleToscaProvider().getPolicies(pfDao, "hello", "0.0.1")) + .hasMessageMatching("policies for hello:0.0.1 do not exist"); JpaToscaServiceTemplate gotSt = new SimpleToscaProvider().getPolicies(pfDao, p01.getName(), p01.getVersion()); @@ -735,9 +714,9 @@ class SimpleToscaProviderTest { JpaToscaPolicy p02 = new JpaToscaPolicy(new PfConceptKey("p0:0.0.2")); p02.setType(pt01.getKey()); p02.setType(pt01.getKey()); - p02.setMetadata(new TreeMap<String, String>()); - p02.setProperties(new LinkedHashMap<String, String>()); - p02.setTargets(new ArrayList<PfConceptKey>()); + 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); @@ -756,162 +735,126 @@ class SimpleToscaProviderTest { @Test void testNonNullsDataType() { - assertThatThrownBy(() -> { - new SimpleToscaProvider().getServiceTemplate(null); - }).hasMessageMatching(DAO_IS_NULL); + assertThatThrownBy(() -> new SimpleToscaProvider().getServiceTemplate(null)) + .hasMessageMatching(DAO_IS_NULL); - assertThatThrownBy(() -> { - new SimpleToscaProvider().appendToServiceTemplate(null, null); - }).hasMessageMatching(DAO_IS_NULL); + assertThatThrownBy(() -> new SimpleToscaProvider().appendToServiceTemplate(null, null)) + .hasMessageMatching(DAO_IS_NULL); - assertThatThrownBy(() -> { - new SimpleToscaProvider().appendToServiceTemplate(null, new JpaToscaServiceTemplate()); - }).hasMessageMatching(DAO_IS_NULL); + assertThatThrownBy(() -> new SimpleToscaProvider().appendToServiceTemplate(null, new JpaToscaServiceTemplate())) + .hasMessageMatching(DAO_IS_NULL); - assertThatThrownBy(() -> { - new SimpleToscaProvider().appendToServiceTemplate(pfDao, null); - }).hasMessageMatching("^incomingServiceTemplateFragment is marked .*on.*ull but is null$"); + assertThatThrownBy(() -> new SimpleToscaProvider().appendToServiceTemplate(pfDao, null)) + .hasMessageMatching("^incomingServiceTemplateFragment is marked .*on.*ull but is null$"); - assertThatThrownBy(() -> { - new SimpleToscaProvider().getDataTypes(null, null, null); - }).hasMessageMatching(DAO_IS_NULL); + assertThatThrownBy(() -> new SimpleToscaProvider().getDataTypes(null, null, null)) + .hasMessageMatching(DAO_IS_NULL); - assertThatThrownBy(() -> { - new SimpleToscaProvider().createDataTypes(null, null); - }).hasMessageMatching(DAO_IS_NULL); + assertThatThrownBy(() -> new SimpleToscaProvider().createDataTypes(null, null)) + .hasMessageMatching(DAO_IS_NULL); - assertThatThrownBy(() -> { - new SimpleToscaProvider().createDataTypes(null, new JpaToscaServiceTemplate()); - }).hasMessageMatching(DAO_IS_NULL); + assertThatThrownBy(() -> new SimpleToscaProvider().createDataTypes(null, new JpaToscaServiceTemplate())) + .hasMessageMatching(DAO_IS_NULL); - assertThatThrownBy(() -> { - new SimpleToscaProvider().createDataTypes(pfDao, null); - }).hasMessageMatching(INCOMING_TEMPLATE_IS_NULL); + assertThatThrownBy(() -> new SimpleToscaProvider().createDataTypes(pfDao, null)) + .hasMessageMatching(INCOMING_TEMPLATE_IS_NULL); - assertThatThrownBy(() -> { - new SimpleToscaProvider().updateDataTypes(null, null); - }).hasMessageMatching(DAO_IS_NULL); + assertThatThrownBy(() -> new SimpleToscaProvider().updateDataTypes(null, null)) + .hasMessageMatching(DAO_IS_NULL); - assertThatThrownBy(() -> { - new SimpleToscaProvider().updateDataTypes(null, new JpaToscaServiceTemplate()); - }).hasMessageMatching(DAO_IS_NULL); + assertThatThrownBy(() -> new SimpleToscaProvider().updateDataTypes(null, new JpaToscaServiceTemplate())) + .hasMessageMatching(DAO_IS_NULL); - assertThatThrownBy(() -> { - new SimpleToscaProvider().updateDataTypes(pfDao, null); - }).hasMessageMatching(TEMPLATE_IS_NULL); + assertThatThrownBy(() -> new SimpleToscaProvider().updateDataTypes(pfDao, null)) + .hasMessageMatching(TEMPLATE_IS_NULL); - assertThatThrownBy(() -> { - new SimpleToscaProvider().deleteDataType(null, null); - }).hasMessageMatching(DAO_IS_NULL); + assertThatThrownBy(() -> new SimpleToscaProvider().deleteDataType(null, null)) + .hasMessageMatching(DAO_IS_NULL); - assertThatThrownBy(() -> { - new SimpleToscaProvider().deleteDataType(null, new PfConceptKey()); - }).hasMessageMatching(DAO_IS_NULL); + assertThatThrownBy(() -> new SimpleToscaProvider().deleteDataType(null, new PfConceptKey())) + .hasMessageMatching(DAO_IS_NULL); - assertThatThrownBy(() -> { - new SimpleToscaProvider().deleteDataType(pfDao, null); - }).hasMessageMatching("^dataTypeKey is marked .*on.*ull but is null$"); + assertThatThrownBy(() -> new SimpleToscaProvider().deleteDataType(pfDao, null)) + .hasMessageMatching("^dataTypeKey is marked .*on.*ull but is null$"); } @Test void testNotNullsPolicyTypes() { - assertThatThrownBy(() -> { - new SimpleToscaProvider().getPolicyTypes(null, null, null); - }).hasMessageMatching(DAO_IS_NULL); + assertThatThrownBy(() -> new SimpleToscaProvider().getPolicyTypes(null, null, null)) + .hasMessageMatching(DAO_IS_NULL); - assertThatThrownBy(() -> { - new SimpleToscaProvider().createPolicyTypes(null, null); - }).hasMessageMatching(DAO_IS_NULL); + assertThatThrownBy(() -> new SimpleToscaProvider().createPolicyTypes(null, null)) + .hasMessageMatching(DAO_IS_NULL); - assertThatThrownBy(() -> { - new SimpleToscaProvider().createPolicyTypes(null, new JpaToscaServiceTemplate()); - }).hasMessageMatching(DAO_IS_NULL); + assertThatThrownBy(() -> new SimpleToscaProvider().createPolicyTypes(null, new JpaToscaServiceTemplate())) + .hasMessageMatching(DAO_IS_NULL); - assertThatThrownBy(() -> { - new SimpleToscaProvider().createPolicyTypes(pfDao, null); - }).hasMessageMatching(INCOMING_TEMPLATE_IS_NULL); + assertThatThrownBy(() -> new SimpleToscaProvider().createPolicyTypes(pfDao, null)) + .hasMessageMatching(INCOMING_TEMPLATE_IS_NULL); - assertThatThrownBy(() -> { - new SimpleToscaProvider().updatePolicyTypes(null, null); - }).hasMessageMatching(DAO_IS_NULL); + assertThatThrownBy(() -> new SimpleToscaProvider().updatePolicyTypes(null, null)) + .hasMessageMatching(DAO_IS_NULL); - assertThatThrownBy(() -> { - new SimpleToscaProvider().updatePolicyTypes(null, new JpaToscaServiceTemplate()); - }).hasMessageMatching(DAO_IS_NULL); + assertThatThrownBy(() -> new SimpleToscaProvider().updatePolicyTypes(null, new JpaToscaServiceTemplate())) + .hasMessageMatching(DAO_IS_NULL); - assertThatThrownBy(() -> { - new SimpleToscaProvider().updatePolicyTypes(pfDao, null); - }).hasMessageMatching(TEMPLATE_IS_NULL); + assertThatThrownBy(() -> new SimpleToscaProvider().updatePolicyTypes(pfDao, null)) + .hasMessageMatching(TEMPLATE_IS_NULL); - assertThatThrownBy(() -> { - new SimpleToscaProvider().deletePolicyType(null, null); - }).hasMessageMatching(DAO_IS_NULL); + assertThatThrownBy(() -> new SimpleToscaProvider().deletePolicyType(null, null)) + .hasMessageMatching(DAO_IS_NULL); - assertThatThrownBy(() -> { - new SimpleToscaProvider().deletePolicyType(null, new PfConceptKey()); - }).hasMessageMatching(DAO_IS_NULL); + assertThatThrownBy(() -> new SimpleToscaProvider().deletePolicyType(null, new PfConceptKey())) + .hasMessageMatching(DAO_IS_NULL); - assertThatThrownBy(() -> { - new SimpleToscaProvider().deletePolicyType(pfDao, null); - }).hasMessageMatching("^policyTypeKey is marked .*on.*ull but is null$"); + assertThatThrownBy(() -> new SimpleToscaProvider().deletePolicyType(pfDao, null)) + .hasMessageMatching("^policyTypeKey is marked .*on.*ull but is null$"); - assertThatThrownBy(() -> { - new SimpleToscaProvider().getPolicies(null, null, null); - }).hasMessageMatching(DAO_IS_NULL); + assertThatThrownBy(() -> new SimpleToscaProvider().getPolicies(null, null, null)) + .hasMessageMatching(DAO_IS_NULL); - assertThatThrownBy(() -> { - new SimpleToscaProvider().createPolicies(null, null); - }).hasMessageMatching(DAO_IS_NULL); + assertThatThrownBy(() -> new SimpleToscaProvider().createPolicies(null, null)) + .hasMessageMatching(DAO_IS_NULL); - assertThatThrownBy(() -> { - new SimpleToscaProvider().createPolicies(null, new JpaToscaServiceTemplate()); - }).hasMessageMatching(DAO_IS_NULL); + assertThatThrownBy(() -> new SimpleToscaProvider().createPolicies(null, new JpaToscaServiceTemplate())) + .hasMessageMatching(DAO_IS_NULL); - assertThatThrownBy(() -> { - new SimpleToscaProvider().createPolicies(pfDao, null); - }).hasMessageMatching(INCOMING_TEMPLATE_IS_NULL); + assertThatThrownBy(() -> new SimpleToscaProvider().createPolicies(pfDao, null)) + .hasMessageMatching(INCOMING_TEMPLATE_IS_NULL); - assertThatThrownBy(() -> { - new SimpleToscaProvider().updatePolicies(null, null); - }).hasMessageMatching(DAO_IS_NULL); + assertThatThrownBy(() -> new SimpleToscaProvider().updatePolicies(null, null)) + .hasMessageMatching(DAO_IS_NULL); - assertThatThrownBy(() -> { - new SimpleToscaProvider().updatePolicies(null, new JpaToscaServiceTemplate()); - }).hasMessageMatching(DAO_IS_NULL); + assertThatThrownBy(() -> new SimpleToscaProvider().updatePolicies(null, new JpaToscaServiceTemplate())) + .hasMessageMatching(DAO_IS_NULL); - assertThatThrownBy(() -> { - new SimpleToscaProvider().updatePolicies(pfDao, null); - }).hasMessageMatching(TEMPLATE_IS_NULL); + assertThatThrownBy(() -> new SimpleToscaProvider().updatePolicies(pfDao, null)) + .hasMessageMatching(TEMPLATE_IS_NULL); - assertThatThrownBy(() -> { - new SimpleToscaProvider().deletePolicy(null, null); - }).hasMessageMatching(DAO_IS_NULL); + assertThatThrownBy(() -> new SimpleToscaProvider().deletePolicy(null, null)) + .hasMessageMatching(DAO_IS_NULL); - assertThatThrownBy(() -> { - new SimpleToscaProvider().deletePolicy(null, new PfConceptKey()); - }).hasMessageMatching(DAO_IS_NULL); + assertThatThrownBy(() -> new SimpleToscaProvider().deletePolicy(null, new PfConceptKey())) + .hasMessageMatching(DAO_IS_NULL); - assertThatThrownBy(() -> { - new SimpleToscaProvider().deletePolicy(pfDao, null); - }).hasMessageMatching("^policyKey is marked .*on.*ull but is null$"); + assertThatThrownBy(() -> new SimpleToscaProvider().deletePolicy(pfDao, null)) + .hasMessageMatching("^policyKey is marked .*on.*ull but is null$"); } @Test void testDeleteServiceTemplate() throws PfModelException { - assertThatThrownBy(() -> { - new SimpleToscaProvider().deleteServiceTemplate(null); - }).hasMessageMatching("^dao is marked .*on.*ull but is null$"); + assertThatThrownBy(() -> new SimpleToscaProvider().deleteServiceTemplate(null)) + .hasMessageMatching("^dao is marked .*on.*ull but is null$"); - assertThatThrownBy(() -> { - new SimpleToscaProvider().deleteServiceTemplate(pfDao); - }).hasMessage("service template not found in database"); + assertThatThrownBy(() -> new SimpleToscaProvider().deleteServiceTemplate(pfDao)) + .hasMessage("service template not found in database"); PfConceptKey dataType0Key = new PfConceptKey("DataType0", "0.0.1"); JpaToscaDataType dataType0 = new JpaToscaDataType(); dataType0.setKey(dataType0Key); - dataType0.setConstraints(new ArrayList<JpaToscaConstraint>()); - dataType0.setMetadata(new TreeMap<String, String>()); - dataType0.setProperties(new LinkedHashMap<String, JpaToscaProperty>()); + dataType0.setConstraints(new ArrayList<>()); + dataType0.setMetadata(new TreeMap<>()); + dataType0.setProperties(new LinkedHashMap<>()); JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate(); serviceTemplate.setDataTypes(new JpaToscaDataTypes()); @@ -922,7 +865,7 @@ class SimpleToscaProviderTest { assertEquals(1, createdServiceTemplate.getDataTypes().getConceptMap().size()); assertEquals(dataType0, createdServiceTemplate.getDataTypes().get(dataType0Key)); - assertEquals(null, createdServiceTemplate.getDataTypes().get(dataType0Key).getDescription()); + assertNull(createdServiceTemplate.getDataTypes().get(dataType0Key).getDescription()); JpaToscaServiceTemplate deletedServiceTemplate = new SimpleToscaProvider().deleteServiceTemplate(pfDao); @@ -931,9 +874,8 @@ class SimpleToscaProviderTest { @Test void testNullParameters() { - assertThatThrownBy(() -> { - new SimpleToscaProvider().getCascadedDataTypes(null, null, null); - }).hasMessageMatching("^dbServiceTemplate is marked .*on.*ull but is null$"); + assertThatThrownBy(() -> new SimpleToscaProvider().getCascadedDataTypes(null, null, null)) + .hasMessageMatching("^dbServiceTemplate is marked .*on.*ull but is null$"); } private void createPolicyTypes() throws CoderException, PfModelException { 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 205d3baa8..c4e9f51d5 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, 2023-2024 Nordix Foundation. + * Copyright (C) 2020-2021, 2023-2025 Nordix Foundation. * Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -38,14 +38,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.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. @@ -73,15 +70,9 @@ class SimpleToscaServiceTemplateProviderTest { Properties jdbcProperties = new Properties(); jdbcProperties.setProperty("jakarta.persistence.jdbc.user", "policy"); jdbcProperties.setProperty("jakarta.persistence.jdbc.password", "P01icY"); - - if (System.getProperty("USE-MARIADB") != null) { - jdbcProperties.setProperty("jakarta.persistence.jdbc.driver", "org.mariadb.jdbc.Driver"); - jdbcProperties.setProperty("jakarta.persistence.jdbc.url", "jdbc:mariadb://localhost:3306/policy"); - } else { - jdbcProperties.setProperty("jakarta.persistence.jdbc.driver", "org.h2.Driver"); - jdbcProperties.setProperty("jakarta.persistence.jdbc.url", - "jdbc:h2:mem:SimpleToscaServiceTemplateProviderTest"); - } + jdbcProperties.setProperty("jakarta.persistence.jdbc.driver", "org.h2.Driver"); + jdbcProperties.setProperty("jakarta.persistence.jdbc.url", + "jdbc:h2:mem:SimpleToscaServiceTemplateProviderTest"); daoParameters.setJdbcProperties(jdbcProperties); @@ -97,7 +88,7 @@ class SimpleToscaServiceTemplateProviderTest { @Test void testCreateUpdateGetDeleteDataType() throws PfModelException { JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate(); - serviceTemplate.setMetadata(new TreeMap<String, String>()); + serviceTemplate.setMetadata(new TreeMap<>()); JpaToscaServiceTemplate dbServiceTemplate = new SimpleToscaServiceTemplateProvider().write(pfDao, serviceTemplate); @@ -112,9 +103,9 @@ class SimpleToscaServiceTemplateProviderTest { PfConceptKey dataType0Key = new PfConceptKey("DataType0", "0.0.1"); JpaToscaDataType dataType0 = new JpaToscaDataType(); dataType0.setKey(dataType0Key); - dataType0.setConstraints(new ArrayList<JpaToscaConstraint>()); - dataType0.setMetadata(new TreeMap<String, String>()); - dataType0.setProperties(new LinkedHashMap<String, JpaToscaProperty>()); + dataType0.setConstraints(new ArrayList<>()); + dataType0.setMetadata(new TreeMap<>()); + dataType0.setProperties(new LinkedHashMap<>()); serviceTemplate.setDataTypes(new JpaToscaDataTypes()); serviceTemplate.getDataTypes().getConceptMap().put(dataType0Key, dataType0); @@ -144,10 +135,10 @@ class SimpleToscaServiceTemplateProviderTest { JpaToscaPolicyType policyType0 = new JpaToscaPolicyType(); policyType0.setKey(policyType0Key); - policyType0.setMetadata(new TreeMap<String, String>()); - policyType0.setProperties(new LinkedHashMap<String, JpaToscaProperty>()); - policyType0.setTargets(new ArrayList<PfConceptKey>()); - policyType0.setTriggers(new ArrayList<JpaToscaTrigger>()); + 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); @@ -167,24 +158,19 @@ class SimpleToscaServiceTemplateProviderTest { @Test void testNonNulls() { - assertThatThrownBy(() -> { - new SimpleToscaServiceTemplateProvider().write(null, null); - }).hasMessageMatching(DAO_IS_NULL); + assertThatThrownBy(() -> new SimpleToscaServiceTemplateProvider().write(null, null)) + .hasMessageMatching(DAO_IS_NULL); - assertThatThrownBy(() -> { - new SimpleToscaServiceTemplateProvider().write(pfDao, null); - }).hasMessageMatching(TEMPLATE_IS_NULL); + assertThatThrownBy(() -> new SimpleToscaServiceTemplateProvider().write(pfDao, null)) + .hasMessageMatching(TEMPLATE_IS_NULL); - assertThatThrownBy(() -> { - new SimpleToscaServiceTemplateProvider().write(null, new JpaToscaServiceTemplate()); - }).hasMessageMatching(DAO_IS_NULL); + assertThatThrownBy(() -> new SimpleToscaServiceTemplateProvider().write(null, new JpaToscaServiceTemplate())) + .hasMessageMatching(DAO_IS_NULL); - assertThatThrownBy(() -> { - new SimpleToscaServiceTemplateProvider().read(null); - }).hasMessageMatching(DAO_IS_NULL); + assertThatThrownBy(() -> new SimpleToscaServiceTemplateProvider().read(null)) + .hasMessageMatching(DAO_IS_NULL); - assertThatThrownBy(() -> { - new SimpleToscaServiceTemplateProvider().delete(null); - }).hasMessageMatching(DAO_IS_NULL); + assertThatThrownBy(() -> new SimpleToscaServiceTemplateProvider().delete(null)) + .hasMessageMatching(DAO_IS_NULL); } } |