From f0d03b320e772df782a968411f269dc089d1f897 Mon Sep 17 00:00:00 2001 From: Chenfei Gao Date: Fri, 21 Feb 2020 17:07:49 -0500 Subject: Preload default policies Issue-ID: POLICY-2317 Change-Id: I5794e617ea4fb99caf6e7a974a4886e72605979c Signed-off-by: Chenfei Gao --- .../api/main/parameters/TestApiParameterGroup.java | 20 +++++++------- .../policy/api/main/rest/TestApiRestServer.java | 32 ++++++++++------------ .../provider/TestLegacyGuardPolicyProvider.java | 3 +- .../TestLegacyOperationalPolicyProvider.java | 3 +- .../api/main/rest/provider/TestPolicyProvider.java | 3 +- .../main/rest/provider/TestPolicyTypeProvider.java | 3 +- .../parameters/ApiConfigParameters_Https.json | 3 ++ .../ApiConfigParameters_InvalidName.json | 3 +- ...nfigParameters_InvalidRestServerParameters.json | 3 +- .../resources/parameters/MinimumParameters.json | 3 +- .../test/resources/parameters/NoParameters.json | 3 +- 11 files changed, 43 insertions(+), 36 deletions(-) (limited to 'main/src/test') diff --git a/main/src/test/java/org/onap/policy/api/main/parameters/TestApiParameterGroup.java b/main/src/test/java/org/onap/policy/api/main/parameters/TestApiParameterGroup.java index d2209e73..45653883 100644 --- a/main/src/test/java/org/onap/policy/api/main/parameters/TestApiParameterGroup.java +++ b/main/src/test/java/org/onap/policy/api/main/parameters/TestApiParameterGroup.java @@ -48,7 +48,7 @@ public class TestApiParameterGroup { final PolicyModelsProviderParameters databaseProviderParameters = commonTestData.getDatabaseProviderParameters(false); final ApiParameterGroup apiParameters = new ApiParameterGroup(CommonTestData.API_GROUP_NAME, - restServerParameters, databaseProviderParameters, Collections.emptyList()); + restServerParameters, databaseProviderParameters, Collections.emptyList(), Collections.emptyList()); final GroupValidationResult validationResult = apiParameters.validate(); assertTrue(validationResult.isValid()); assertEquals(restServerParameters.getHost(), apiParameters.getRestServerParameters().getHost()); @@ -68,8 +68,8 @@ public class TestApiParameterGroup { final RestServerParameters restServerParameters = commonTestData.getRestServerParameters(false, PORT); final PolicyModelsProviderParameters databaseProviderParameters = commonTestData.getDatabaseProviderParameters(false); - final ApiParameterGroup apiParameters = new ApiParameterGroup(null, - restServerParameters, databaseProviderParameters, Collections.emptyList()); + final ApiParameterGroup apiParameters = new ApiParameterGroup(null, restServerParameters, + databaseProviderParameters, Collections.emptyList(), Collections.emptyList()); final GroupValidationResult validationResult = apiParameters.validate(); assertFalse(validationResult.isValid()); assertEquals(null, apiParameters.getName()); @@ -83,8 +83,8 @@ public class TestApiParameterGroup { final RestServerParameters restServerParameters = commonTestData.getRestServerParameters(false, PORT); final PolicyModelsProviderParameters databaseProviderParameters = commonTestData.getDatabaseProviderParameters(false); - final ApiParameterGroup apiParameters = new ApiParameterGroup("", - restServerParameters, databaseProviderParameters, Collections.emptyList()); + final ApiParameterGroup apiParameters = new ApiParameterGroup("", restServerParameters, + databaseProviderParameters, Collections.emptyList(), Collections.emptyList()); final GroupValidationResult validationResult = apiParameters.validate(); assertFalse(validationResult.isValid()); assertEquals("", apiParameters.getName()); @@ -98,7 +98,7 @@ public class TestApiParameterGroup { final PolicyModelsProviderParameters databaseProviderParameters = commonTestData.getDatabaseProviderParameters(false); final ApiParameterGroup apiParameters = new ApiParameterGroup(CommonTestData.API_GROUP_NAME, - restServerParameters, databaseProviderParameters, Collections.emptyList()); + restServerParameters, databaseProviderParameters, Collections.emptyList(), Collections.emptyList()); final GroupValidationResult validationResult = apiParameters.validate(); assertFalse(validationResult.isValid()); assertTrue(validationResult.getResult() @@ -112,7 +112,7 @@ public class TestApiParameterGroup { final PolicyModelsProviderParameters databaseProviderParameters = commonTestData.getDatabaseProviderParameters(false); final ApiParameterGroup apiParameters = new ApiParameterGroup(CommonTestData.API_GROUP_NAME, - restServerParameters, databaseProviderParameters, Collections.emptyList()); + restServerParameters, databaseProviderParameters, Collections.emptyList(), Collections.emptyList()); final GroupValidationResult validationResult = apiParameters.validate(); assertFalse(validationResult.isValid()); assertTrue(validationResult.getResult() @@ -126,7 +126,7 @@ public class TestApiParameterGroup { final PolicyModelsProviderParameters databaseProviderParameters = commonTestData.getDatabaseProviderParameters(true); final ApiParameterGroup apiParameters = new ApiParameterGroup(CommonTestData.API_GROUP_NAME, - restServerParameters, databaseProviderParameters, Collections.emptyList()); + restServerParameters, databaseProviderParameters, Collections.emptyList(), Collections.emptyList()); final GroupValidationResult validationResult = apiParameters.validate(); assertFalse(validationResult.isValid()); assertTrue(validationResult.getResult() @@ -139,7 +139,7 @@ public class TestApiParameterGroup { final RestServerParameters restServerParameters = commonTestData.getRestServerParameters(false, PORT); final PolicyModelsProviderParameters databaseProviderParameters = null; final ApiParameterGroup apiParameters = new ApiParameterGroup(CommonTestData.API_GROUP_NAME, - restServerParameters, databaseProviderParameters, Collections.emptyList()); + restServerParameters, databaseProviderParameters, Collections.emptyList(), Collections.emptyList()); final GroupValidationResult validationResult = apiParameters.validate(); assertFalse(validationResult.isValid()); assertTrue(validationResult.getResult() @@ -149,7 +149,7 @@ public class TestApiParameterGroup { @Test public void testApiParameterGroup_SetName() { final ApiParameterGroup apiParameters = new ApiParameterGroup(CommonTestData.API_GROUP_NAME, - null, null, Collections.emptyList()); + null, null, Collections.emptyList(), Collections.emptyList()); assertEquals(CommonTestData.API_GROUP_NAME, apiParameters.getName()); apiParameters.setName("SampleName"); assertEquals("SampleName", apiParameters.getName()); diff --git a/main/src/test/java/org/onap/policy/api/main/rest/TestApiRestServer.java b/main/src/test/java/org/onap/policy/api/main/rest/TestApiRestServer.java index 4af601a2..7780ea7d 100644 --- a/main/src/test/java/org/onap/policy/api/main/rest/TestApiRestServer.java +++ b/main/src/test/java/org/onap/policy/api/main/rest/TestApiRestServer.java @@ -110,6 +110,9 @@ public class TestApiRestServer { private static final String POLICYTYPES_DROOLS_VERSION = POLICYTYPES_DROOLS + "/versions/1.0.0"; private static final String POLICYTYPES_DROOLS_VERSION_LATEST = POLICYTYPES_DROOLS + "/versions/latest"; + private static final String POLICYTYPES_NAMING_VERSION = + POLICYTYPES + "/onap.policies.Naming/versions/1.0.0"; + private static final String POLICYTYPES_TCA_POLICIES = "policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app/versions/1.0.0/policies"; private static final String POLICYTYPES_TCA_POLICIES_VCPE = @@ -252,7 +255,8 @@ public class TestApiRestServer { providerParams.setDatabaseUser("policy"); providerParams.setDatabasePassword(Base64.getEncoder().encodeToString("P01icY".getBytes())); providerParams.setPersistenceUnit("ToscaConceptTest"); - apiParamGroup = new ApiParameterGroup("ApiGroup", null, providerParams, Collections.emptyList()); + apiParamGroup = new ApiParameterGroup("ApiGroup", null, providerParams, + Collections.emptyList(), Collections.emptyList()); ParameterService.register(apiParamGroup, true); policyTypeProvider = new PolicyTypeProvider(); @@ -542,6 +546,9 @@ public class TestApiRestServer { rawResponse = readResource(POLICYTYPES_DROOLS_VERSION_LATEST, mediaType); assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus()); + + rawResponse = readResource(POLICYTYPES_NAMING_VERSION, mediaType); + assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus()); } @Test @@ -611,12 +618,9 @@ public class TestApiRestServer { @Test public void testNamingPolicyGet() throws Exception { - Response rawResponse = createResource("policies", "policies/sdnc.policy.naming.input.tosca.yaml"); - assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus()); - rawResponse = readResource("policytypes/" - + "onap.policies.Naming/versions/1.0.0/policies/SDNC_Policy.ONAP_VNF_NAMING_TIMESTAMP/versions/1.0.0", - APP_JSON); + Response rawResponse = readResource("policytypes/onap.policies.Naming/versions/1.0.0/" + + "policies/SDNC_Policy.ONAP_VNF_NAMING_TIMESTAMP/versions/1.0.0", APP_JSON); assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus()); ToscaServiceTemplate namingServiceTemplate = rawResponse.readEntity(ToscaServiceTemplate.class); @@ -624,9 +628,8 @@ public class TestApiRestServer { assertEquals(1, namingServiceTemplate.getPolicyTypesAsMap().size()); assertEquals(3, namingServiceTemplate.getDataTypesAsMap().size()); - rawResponse = readResource("policytypes/" - + "onap.policies.Naming/versions/1.0.0/policies/SDNC_Policy.ONAP_VNF_NAMING_TIMESTAMP/versions/latest", - APP_JSON); + rawResponse = readResource("policytypes/onap.policies.Naming/versions/1.0.0/" + + "policies/SDNC_Policy.ONAP_VNF_NAMING_TIMESTAMP/versions/latest", APP_JSON); assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus()); namingServiceTemplate = rawResponse.readEntity(ToscaServiceTemplate.class); @@ -634,20 +637,13 @@ public class TestApiRestServer { assertEquals(1, namingServiceTemplate.getPolicyTypesAsMap().size()); assertEquals(3, namingServiceTemplate.getDataTypesAsMap().size()); - rawResponse = readResource( - "policytypes/" + "onap.policies.Naming/versions/1.0.0/policies/SDNC_Policy.ONAP_VNF_NAMING_TIMESTAMP", - APP_JSON); + rawResponse = readResource("policytypes/onap.policies.Naming/versions/1.0.0/policies", APP_JSON); assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus()); namingServiceTemplate = rawResponse.readEntity(ToscaServiceTemplate.class); assertEquals(1, namingServiceTemplate.getToscaTopologyTemplate().getPoliciesAsMap().size()); assertEquals(1, namingServiceTemplate.getPolicyTypesAsMap().size()); assertEquals(3, namingServiceTemplate.getDataTypesAsMap().size()); - - rawResponse = deleteResource("policytypes/" - + "onap.policies.Naming/versions/1.0.0/policies/SDNC_Policy.ONAP_VNF_NAMING_TIMESTAMP/versions/1.0.0", - APP_JSON); - assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus()); } @Test @@ -664,7 +660,7 @@ public class TestApiRestServer { Response rawResponse = deleteResource(POLICYTYPES_TCA_POLICIES_VCPE_VERSION1, mediaType); assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus()); ErrorResponse error = rawResponse.readEntity(ErrorResponse.class); - assertEquals("no policies found", error.getErrorMessage()); + assertEquals("policy onap.restart.tca:1.0.0 not found", error.getErrorMessage()); } @Test diff --git a/main/src/test/java/org/onap/policy/api/main/rest/provider/TestLegacyGuardPolicyProvider.java b/main/src/test/java/org/onap/policy/api/main/rest/provider/TestLegacyGuardPolicyProvider.java index 342d17b1..dfe29cfc 100644 --- a/main/src/test/java/org/onap/policy/api/main/rest/provider/TestLegacyGuardPolicyProvider.java +++ b/main/src/test/java/org/onap/policy/api/main/rest/provider/TestLegacyGuardPolicyProvider.java @@ -105,7 +105,8 @@ public class TestLegacyGuardPolicyProvider { providerParams.setDatabaseUser("policy"); providerParams.setDatabasePassword(Base64.getEncoder().encodeToString("P01icY".getBytes())); providerParams.setPersistenceUnit("ToscaConceptTest"); - apiParamGroup = new ApiParameterGroup("ApiGroup", null, providerParams, Collections.emptyList()); + apiParamGroup = new ApiParameterGroup("ApiGroup", null, providerParams, + Collections.emptyList(), Collections.emptyList()); ParameterService.register(apiParamGroup, true); guardPolicyProvider = new LegacyGuardPolicyProvider(); policyTypeProvider = new PolicyTypeProvider(); diff --git a/main/src/test/java/org/onap/policy/api/main/rest/provider/TestLegacyOperationalPolicyProvider.java b/main/src/test/java/org/onap/policy/api/main/rest/provider/TestLegacyOperationalPolicyProvider.java index c0084956..74ad4a9d 100644 --- a/main/src/test/java/org/onap/policy/api/main/rest/provider/TestLegacyOperationalPolicyProvider.java +++ b/main/src/test/java/org/onap/policy/api/main/rest/provider/TestLegacyOperationalPolicyProvider.java @@ -100,7 +100,8 @@ public class TestLegacyOperationalPolicyProvider { providerParams.setDatabaseUser("policy"); providerParams.setDatabasePassword(Base64.getEncoder().encodeToString("P01icY".getBytes())); providerParams.setPersistenceUnit("ToscaConceptTest"); - apiParamGroup = new ApiParameterGroup("ApiGroup", null, providerParams, Collections.emptyList()); + apiParamGroup = new ApiParameterGroup("ApiGroup", null, providerParams, + Collections.emptyList(), Collections.emptyList()); ParameterService.register(apiParamGroup, true); operationalPolicyProvider = new LegacyOperationalPolicyProvider(); policyTypeProvider = new PolicyTypeProvider(); diff --git a/main/src/test/java/org/onap/policy/api/main/rest/provider/TestPolicyProvider.java b/main/src/test/java/org/onap/policy/api/main/rest/provider/TestPolicyProvider.java index d9b01fdb..be9b5838 100644 --- a/main/src/test/java/org/onap/policy/api/main/rest/provider/TestPolicyProvider.java +++ b/main/src/test/java/org/onap/policy/api/main/rest/provider/TestPolicyProvider.java @@ -107,7 +107,8 @@ public class TestPolicyProvider { providerParams.setDatabaseUser("policy"); providerParams.setDatabasePassword(Base64.getEncoder().encodeToString("P01icY".getBytes())); providerParams.setPersistenceUnit("ToscaConceptTest"); - apiParamGroup = new ApiParameterGroup("ApiGroup", null, providerParams, Collections.emptyList()); + apiParamGroup = new ApiParameterGroup("ApiGroup", null, providerParams, + Collections.emptyList(), Collections.emptyList()); ParameterService.register(apiParamGroup, true); policyTypeProvider = new PolicyTypeProvider(); policyProvider = new PolicyProvider(); diff --git a/main/src/test/java/org/onap/policy/api/main/rest/provider/TestPolicyTypeProvider.java b/main/src/test/java/org/onap/policy/api/main/rest/provider/TestPolicyTypeProvider.java index 58576abc..58d4230c 100644 --- a/main/src/test/java/org/onap/policy/api/main/rest/provider/TestPolicyTypeProvider.java +++ b/main/src/test/java/org/onap/policy/api/main/rest/provider/TestPolicyTypeProvider.java @@ -91,7 +91,8 @@ public class TestPolicyTypeProvider { providerParams.setDatabaseUser("policy"); providerParams.setDatabasePassword(Base64.getEncoder().encodeToString("P01icY".getBytes())); providerParams.setPersistenceUnit("ToscaConceptTest"); - apiParamGroup = new ApiParameterGroup("ApiGroup", null, providerParams, Collections.emptyList()); + apiParamGroup = new ApiParameterGroup("ApiGroup", null, providerParams, + Collections.emptyList(), Collections.emptyList()); ParameterService.register(apiParamGroup, true); policyTypeProvider = new PolicyTypeProvider(); policyProvider = new PolicyProvider(); diff --git a/main/src/test/resources/parameters/ApiConfigParameters_Https.json b/main/src/test/resources/parameters/ApiConfigParameters_Https.json index 29745fb8..5f0bc8af 100644 --- a/main/src/test/resources/parameters/ApiConfigParameters_Https.json +++ b/main/src/test/resources/parameters/ApiConfigParameters_Https.json @@ -44,5 +44,8 @@ "policytypes/onap.policies.controlloop.operational.Common.yaml", "policytypes/onap.policies.controlloop.operational.common.Apex.yaml", "policytypes/onap.policies.controlloop.operational.common.Drools.yaml" + ], + "preloadPolicies" : [ + "policies/sdnc.policy.naming.input.tosca.yaml" ] } diff --git a/main/src/test/resources/parameters/ApiConfigParameters_InvalidName.json b/main/src/test/resources/parameters/ApiConfigParameters_InvalidName.json index 1a539cf6..f8a286f9 100644 --- a/main/src/test/resources/parameters/ApiConfigParameters_InvalidName.json +++ b/main/src/test/resources/parameters/ApiConfigParameters_InvalidName.json @@ -14,5 +14,6 @@ "databasePassword": "UDAxaWNZ", "persistenceUnit": "ToscaConceptTest" }, - "preloadPolicyTypes": [] + "preloadPolicyTypes": [], + "preloadPolicies": [] } diff --git a/main/src/test/resources/parameters/ApiConfigParameters_InvalidRestServerParameters.json b/main/src/test/resources/parameters/ApiConfigParameters_InvalidRestServerParameters.json index daf9c749..4e9083ec 100644 --- a/main/src/test/resources/parameters/ApiConfigParameters_InvalidRestServerParameters.json +++ b/main/src/test/resources/parameters/ApiConfigParameters_InvalidRestServerParameters.json @@ -15,5 +15,6 @@ "databasePassword": "UDAxaWNZ", "persistenceUnit": "ToscaConceptTest" }, - "preloadPolicyTypes": [] + "preloadPolicyTypes": [], + "preloadPolicies": [] } diff --git a/main/src/test/resources/parameters/MinimumParameters.json b/main/src/test/resources/parameters/MinimumParameters.json index 4b2db7af..129d9ca3 100644 --- a/main/src/test/resources/parameters/MinimumParameters.json +++ b/main/src/test/resources/parameters/MinimumParameters.json @@ -15,5 +15,6 @@ "databasePassword": "UDAxaWNZ", "persistenceUnit": "ToscaConceptTest" }, - "preloadPolicyTypes": [] + "preloadPolicyTypes": [], + "preloadPolicies": [] } \ No newline at end of file diff --git a/main/src/test/resources/parameters/NoParameters.json b/main/src/test/resources/parameters/NoParameters.json index 091900c9..d71e7bbe 100644 --- a/main/src/test/resources/parameters/NoParameters.json +++ b/main/src/test/resources/parameters/NoParameters.json @@ -14,5 +14,6 @@ "databasePassword": "UDAxaWNZ", "persistenceUnit": "ToscaConceptTest" }, - "preloadPolicyTypes": [] + "preloadPolicyTypes": [], + "preloadPolicies": [] } \ No newline at end of file -- cgit 1.2.3-korg