X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=models-tosca%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Fpolicy%2Fmodels%2Ftosca%2Fauthorative%2Fprovider%2FAuthorativeToscaProviderPolicyTest.java;h=8b79374bc66ed40920e2317b0600c5dc99866a21;hb=88bcb550c2efd5e43ad3d256fe075a6bf7e90538;hp=6c87d7681df6b9cbc84c615a965963c02758dc5d;hpb=92bd3a4d89a3f7740094e0c5dac278722fc3f27c;p=policy%2Fmodels.git 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 6c87d7681..8b79374bc 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderPolicyTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderPolicyTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. + * Copyright (C) 2019-2020 Nordix Foundation. * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -60,7 +60,7 @@ public class AuthorativeToscaProviderPolicyTest { private static final String VCPE_JSON = "policies/vCPE.policy.monitoring.input.tosca.json"; private static final String POLICY_AND_VERSION = "onap.restart.tca:1.0.0"; private static final String POLICY1 = "onap.restart.tca"; - private static final String DAO_IS_NULL = "dao is marked @NonNull but is null"; + private static final String DAO_IS_NULL = "^dao is marked .*on.*ull but is null$"; private static final String VERSION_100 = "1.0.0"; private PfDao pfDao; private StandardCoder standardCoder; @@ -73,7 +73,7 @@ public class AuthorativeToscaProviderPolicyTest { @Before public void setupDao() throws Exception { final DaoParameters daoParameters = new DaoParameters(); - daoParameters.setPluginClass(DefaultPfDao.class.getCanonicalName()); + daoParameters.setPluginClass(DefaultPfDao.class.getName()); daoParameters.setPersistenceUnit("ToscaConceptTest"); @@ -108,17 +108,16 @@ public class AuthorativeToscaProviderPolicyTest { public void testPoliciesGet() throws Exception { assertThatThrownBy(() -> { new AuthorativeToscaProvider().getPolicies(null, null, null); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new AuthorativeToscaProvider().getPolicyList(null, null, null); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); createPolicyTypes(); - ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode( - ResourceUtils.getResourceAsString(VCPE_JSON), - ToscaServiceTemplate.class); + ToscaServiceTemplate toscaServiceTemplate = + standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_JSON), ToscaServiceTemplate.class); assertNotNull(toscaServiceTemplate); ToscaServiceTemplate createdServiceTemplate = @@ -141,8 +140,7 @@ public class AuthorativeToscaProviderPolicyTest { assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicy)); assertTrue(beforePolicy.getType().equals(gotPolicy.getType())); - List gotPolicyList = - new AuthorativeToscaProvider().getPolicyList(pfDao, POLICY1, VERSION_100); + List gotPolicyList = new AuthorativeToscaProvider().getPolicyList(pfDao, POLICY1, VERSION_100); assertEquals(1, gotPolicyList.size()); assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicyList.get(0))); @@ -158,41 +156,39 @@ public class AuthorativeToscaProviderPolicyTest { assertEquals(1, gotPolicyList.size()); assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicyList.get(0))); - gotPolicyList = new AuthorativeToscaProvider().getPolicyList(pfDao, "Nonexistant", VERSION_100); - assertEquals(0, gotPolicyList.size()); + assertTrue(new AuthorativeToscaProvider().getPolicyList(pfDao, "Nonexistant", VERSION_100).isEmpty()); } @Test public void testPoliciesGetFiltered() throws Exception { assertThatThrownBy(() -> { new AuthorativeToscaProvider().getFilteredPolicies(null, null); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new AuthorativeToscaProvider().getFilteredPolicies(null, ToscaPolicyFilter.builder().build()); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new AuthorativeToscaProvider().getFilteredPolicies(pfDao, null); - }).hasMessage("filter is marked @NonNull but is null"); + }).hasMessageMatching("^filter is marked .*on.*ull but is null$"); assertThatThrownBy(() -> { new AuthorativeToscaProvider().getFilteredPolicyList(null, null); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new AuthorativeToscaProvider().getFilteredPolicyList(null, ToscaPolicyFilter.builder().build()); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new AuthorativeToscaProvider().getFilteredPolicyList(pfDao, null); - }).hasMessage("filter is marked @NonNull but is null"); + }).hasMessageMatching("^filter is marked .*on.*ull but is null$"); createPolicyTypes(); - ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode( - ResourceUtils.getResourceAsString(VCPE_JSON), - ToscaServiceTemplate.class); + ToscaServiceTemplate toscaServiceTemplate = + standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_JSON), ToscaServiceTemplate.class); assertNotNull(toscaServiceTemplate); ToscaServiceTemplate createdServiceTemplate = @@ -229,8 +225,7 @@ public class AuthorativeToscaProviderPolicyTest { assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicy)); assertTrue(beforePolicy.getType().equals(gotPolicy.getType())); - List gotPolicyList = - new AuthorativeToscaProvider().getPolicyList(pfDao, POLICY1, VERSION_100); + List gotPolicyList = new AuthorativeToscaProvider().getPolicyList(pfDao, POLICY1, VERSION_100); assertEquals(1, gotPolicyList.size()); assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicyList.get(0))); @@ -254,21 +249,20 @@ public class AuthorativeToscaProviderPolicyTest { public void testPolicyCreate() throws Exception { assertThatThrownBy(() -> { new AuthorativeToscaProvider().createPolicies(null, null); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new AuthorativeToscaProvider().createPolicies(null, new ToscaServiceTemplate()); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new AuthorativeToscaProvider().createPolicies(pfDao, null); - }).hasMessage("serviceTemplate is marked @NonNull but is null"); + }).hasMessageMatching("^serviceTemplate is marked .*on.*ull but is null$"); createPolicyTypes(); - ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode( - ResourceUtils.getResourceAsString(VCPE_JSON), - ToscaServiceTemplate.class); + ToscaServiceTemplate toscaServiceTemplate = + standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_JSON), ToscaServiceTemplate.class); assertNotNull(toscaServiceTemplate); ToscaServiceTemplate createdServiceTemplate = @@ -288,25 +282,24 @@ public class AuthorativeToscaProviderPolicyTest { public void testPolicyUpdate() throws Exception { assertThatThrownBy(() -> { new AuthorativeToscaProvider().createPolicies(null, null); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new AuthorativeToscaProvider().updatePolicies(null, null); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new AuthorativeToscaProvider().updatePolicies(null, new ToscaServiceTemplate()); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new AuthorativeToscaProvider().updatePolicies(pfDao, null); - }).hasMessage("serviceTemplate is marked @NonNull but is null"); + }).hasMessageMatching("^serviceTemplate is marked .*on.*ull but is null$"); createPolicyTypes(); - ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode( - ResourceUtils.getResourceAsString(VCPE_JSON), - ToscaServiceTemplate.class); + ToscaServiceTemplate toscaServiceTemplate = + standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_JSON), ToscaServiceTemplate.class); assertNotNull(toscaServiceTemplate); ToscaServiceTemplate createdServiceTemplate = @@ -334,37 +327,36 @@ public class AuthorativeToscaProviderPolicyTest { public void testPoliciesDelete() throws Exception { assertThatThrownBy(() -> { new AuthorativeToscaProvider().deletePolicy(null, null, null); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new AuthorativeToscaProvider().deletePolicy(null, null, VERSION); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new AuthorativeToscaProvider().deletePolicy(null, "name", null); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new AuthorativeToscaProvider().deletePolicy(null, "name", VERSION); - }).hasMessage(DAO_IS_NULL); + }).hasMessageMatching(DAO_IS_NULL); assertThatThrownBy(() -> { new AuthorativeToscaProvider().deletePolicy(pfDao, null, null); - }).hasMessage("name is marked @NonNull but is null"); + }).hasMessageMatching("^name is marked .*on.*ull but is null$"); assertThatThrownBy(() -> { new AuthorativeToscaProvider().deletePolicy(pfDao, null, VERSION); - }).hasMessage("name is marked @NonNull but is null"); + }).hasMessageMatching("^name is marked .*on.*ull but is null$"); assertThatThrownBy(() -> { new AuthorativeToscaProvider().deletePolicy(pfDao, "name", null); - }).hasMessage("version is marked @NonNull but is null"); + }).hasMessageMatching("^version is marked .*on.*ull but is null$"); createPolicyTypes(); - ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode( - ResourceUtils.getResourceAsString(VCPE_JSON), - ToscaServiceTemplate.class); + ToscaServiceTemplate toscaServiceTemplate = + standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_JSON), ToscaServiceTemplate.class); assertNotNull(toscaServiceTemplate); ToscaServiceTemplate createdServiceTemplate = @@ -387,10 +379,11 @@ public class AuthorativeToscaProviderPolicyTest { assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, createdPolicy)); assertTrue(beforePolicy.getType().equals(deletedPolicy.getType())); - ToscaServiceTemplate gotServiceTemplate = - new AuthorativeToscaProvider().getPolicies(pfDao, policyKey.getName(), policyKey.getVersion()); - - assertTrue(gotServiceTemplate.getToscaTopologyTemplate().getPolicies().isEmpty()); + // @formatter:off + assertThatThrownBy( + () -> new AuthorativeToscaProvider().getPolicies(pfDao, policyKey.getName(), policyKey.getVersion())) + .hasMessageMatching("policies for onap.restart.tca:1.0.0 do not exist"); + // @formatter:on } @Test @@ -399,7 +392,7 @@ public class AuthorativeToscaProviderPolicyTest { assertThatThrownBy(() -> { new AuthorativeToscaProvider().deletePolicy(pfDao, "name", null); - }).hasMessage("version is marked @NonNull but is null"); + }).hasMessageMatching("^version is marked .*on.*ull but is null$"); assertThatThrownBy(() -> { new AuthorativeToscaProvider().createPolicies(pfDao, testServiceTemplate);