diff options
author | aditya.puthuparambil <aditya.puthuparambil@est.tech> | 2020-06-15 12:13:49 +0100 |
---|---|---|
committer | aditya.puthuparambil <aditya.puthuparambil@est.tech> | 2020-06-15 12:33:22 +0100 |
commit | 07e4b4fa99ccab385e8e295c8caedf96b5cb0620 (patch) | |
tree | eda0a4790302e4387521ecb0c82524ec4de23100 /main/src/test/java/org/onap | |
parent | d5fa90efb8a49875924a88094d1369b15e979b89 (diff) |
Removing duplicate yamls and jsons
Issue-ID: POLICY-2052
Signed-off-by: aditya.puthuparambil <aditya.puthuparambil@est.tech>
Change-Id: Ib4125baa1415cdc7f8a34fabc21fa322bc9b82a1
Diffstat (limited to 'main/src/test/java/org/onap')
-rw-r--r-- | main/src/test/java/org/onap/policy/api/main/rest/TestApiRestServer.java | 118 |
1 files changed, 48 insertions, 70 deletions
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 d5ea4d95..c3c81f6b 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 @@ -80,6 +80,7 @@ import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy; * @author Chenfei Gao (cgao@research.att.com) */ public class TestApiRestServer { + private static final String ALIVE = "alive"; private static final String SELF = NetworkUtil.getHostname(); private static final String NAME = "Policy API"; @@ -118,8 +119,6 @@ public class TestApiRestServer { "policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app/versions/1.0.0/policies/onap.restart.tca"; private static final String POLICYTYPES_TCA_POLICIES_VCPE_VERSION1 = "policytypes/" + "onap.policies.monitoring.cdap.tca.hi.lo.app/versions/1.0.0/policies/onap.restart.tca/versions/1.0.0"; - private static final String POLICYTYPES_TCA_POLICIES_VCPE_VERSION2 = "policytypes/" - + "onap.policies.monitoring.cdap.tca.hi.lo.app/versions/1.0.0/policies/onap.restart.tca/versions/2.0.0"; private static final String POLICYTYPES_TCA_POLICIES_VCPE_LATEST = "policytypes/" + "onap.policies.monitoring.cdap.tca.hi.lo.app/versions/1.0.0/policies/onap.restart.tca/versions/latest"; @@ -140,30 +139,29 @@ public class TestApiRestServer { private static final String OPS_POLICIES_VFIREWALL_LATEST = "policytypes/onap.policies.controlloop.Operational/versions/1.0.0/policies/" + OP_POLICY_NAME_VFW + "/versions/latest"; - private static final String OPS_POLICIES_VCPE_VERSION = "policytypes/" - + "onap.policies.controlloop.Operational/versions/1.0.0/policies/" + OP_POLICY_NAME_VCPE + "/versions/1"; - private static final String OPS_POLICIES_VDNS_VERSION = "policytypes/" - + "onap.policies.controlloop.Operational/versions/1.0.0/policies/" + OP_POLICY_NAME_VDNS + "/versions/1"; - private static final String OPS_POLICIES_VFIREWALL_VERSION = "policytypes/" - + "onap.policies.controlloop.Operational/versions/1.0.0/policies/" + OP_POLICY_NAME_VFW + "/versions/1"; - private static final String OPS_POLICIES_VCPE_VERSION_NOEX = "policytypes/" - + "onap.policies.controlloop.Operational/versions/1.0.0/policies/" + OP_POLICY_NAME_VCPE + "/versions/99"; + private static final String OPS_POLICIES_VCPE_VERSION = + "policytypes/" + "onap.policies.controlloop.Operational/versions/1.0.0/policies/" + OP_POLICY_NAME_VCPE + + "/versions/1"; + private static final String OPS_POLICIES_VDNS_VERSION = + "policytypes/" + "onap.policies.controlloop.Operational/versions/1.0.0/policies/" + OP_POLICY_NAME_VDNS + + "/versions/1"; + private static final String OPS_POLICIES_VFIREWALL_VERSION = + "policytypes/" + "onap.policies.controlloop.Operational/versions/1.0.0/policies/" + OP_POLICY_NAME_VFW + + "/versions/1"; + private static final String OPS_POLICIES_VCPE_VERSION_NOEX = + "policytypes/" + "onap.policies.controlloop.Operational/versions/1.0.0/policies/" + OP_POLICY_NAME_VCPE + + "/versions/99"; private static final String POLICIES = "policies"; private static final String KEYSTORE = System.getProperty("user.dir") + "/src/test/resources/ssl/policy-keystore"; // @formatter:off - private static final String[] TOSCA_POLICY_RESOURCE_NAMES = { - "policies/vCPE.policy.monitoring.input.tosca.json", - "policies/vCPE.policy.monitoring.input.tosca.v2.yaml", - "policies/vDNS.policy.monitoring.input.tosca.json", - "policies/vDNS.policy.monitoring.input.tosca.v2.yaml" - }; + private static final String[] TOSCA_POLICY_RESOURCE_NAMES = {"policies/vCPE.policy.monitoring.input.tosca.json", + "policies/vCPE.policy.monitoring.input.tosca.yaml", "policies/vDNS.policy.monitoring.input.tosca.json", + "policies/vDNS.policy.monitoring.input.tosca.v2.yaml"}; private static final String[] TOSCA_POLICIES_RESOURCE_NAMES = { - "policies/vCPE.policies.optimization.input.tosca.json", - "policies/vCPE.policies.optimization.input.tosca.v2.yaml" - }; + "policies/vCPE.policies.optimization.input.tosca.json", "policies/vCPE.policies.optimization.input.tosca.yaml"}; private static final String TOSCA_POLICYTYPE_OP_RESOURCE = "policytypes/onap.policies.controlloop.operational.Common.yaml"; @@ -174,9 +172,7 @@ public class TestApiRestServer { private static final String[] TOSCA_POLICYTYPE_RESOURCE_NAMES = { "policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app.yaml", "policytypes/onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server.yaml", - "policytypes/onap.policies.Optimization.yaml", - LEGACY_POLICYTYPE_OP_RESOURCE, - TOSCA_POLICYTYPE_OP_RESOURCE, + "policytypes/onap.policies.Optimization.yaml", LEGACY_POLICYTYPE_OP_RESOURCE, TOSCA_POLICYTYPE_OP_RESOURCE, "policytypes/onap.policies.controlloop.operational.common.Drools.yaml", "policytypes/onap.policies.controlloop.guard.Common.yaml", "policytypes/onap.policies.controlloop.guard.common.Blacklist.yaml", @@ -191,8 +187,7 @@ public class TestApiRestServer { "policytypes/onap.policies.optimization.service.QueryPolicy.yaml", "policytypes/onap.policies.optimization.service.SubscriberPolicy.yaml", "policytypes/onap.policies.optimization.resource.Vim_fit.yaml", - "policytypes/onap.policies.optimization.resource.VnfPolicy.yaml" - }; + "policytypes/onap.policies.optimization.resource.VnfPolicy.yaml"}; private static final String TOSCA_POLICY_OP_DROOLS_VCPE_RESOURSE_JSON = "policies/vCPE.policy.operational.input.tosca.json"; @@ -201,10 +196,8 @@ public class TestApiRestServer { "policies/vCPE.policy.operational.input.tosca.yaml"; private static final String[] LEGACY_OPERATIONAL_POLICY_RESOURCE_NAMES = { - "policies/vCPE.policy.operational.legacy.input.json", - "policies/vDNS.policy.operational.legacy.input.json", - "policies/vFirewall.policy.operational.legacy.input.json" - }; + "policies/vCPE.policy.operational.legacy.input.json", "policies/vDNS.policy.operational.legacy.input.json", + "policies/vFirewall.policy.operational.legacy.input.json"}; private static PolicyModelsProviderParameters providerParams; private static ApiParameterGroup apiParamGroup; @@ -224,7 +217,7 @@ public class TestApiRestServer { * Initializes parameters and set up test environment. * * @throws PfModelException the PfModel parsing exception - * @throws IOException on I/O exceptions + * @throws IOException on I/O exceptions */ @BeforeClass public static void setupParameters() throws PfModelException, IOException { @@ -235,8 +228,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(), Collections.emptyList()); + apiParamGroup = new ApiParameterGroup("ApiGroup", null, providerParams, Collections.emptyList(), + Collections.emptyList()); ParameterService.register(apiParamGroup, true); policyTypeProvider = new PolicyTypeProvider(); @@ -316,14 +309,14 @@ public class TestApiRestServer { new File("src/test/resources/policies/BadTestPolicy.yaml").deleteOnExit(); // Send a policy with no policy type trigger an error - String toscaPolicy = - ResourceUtils.getResourceAsString(TOSCA_POLICY_RESOURCE_NAMES[TOSCA_POLICIES_RESOURCE_NAMES.length - 1]); + String toscaPolicy = ResourceUtils + .getResourceAsString(TOSCA_POLICY_RESOURCE_NAMES[TOSCA_POLICIES_RESOURCE_NAMES.length - 1]); toscaPolicy = toscaPolicy.replaceAll("onap.policies.monitoring.cdap.tca.hi.lo.app", "IDontExist"); TextFileUtils.putStringAsTextFile(toscaPolicy, "src/test/resources/policies/BadTestPolicy.yaml"); - Response rawResponse2 = - createResource(POLICYTYPES_TCA_POLICIES, "src/test/resources/policies/BadTestPolicy.yaml"); + Response rawResponse2 = createResource(POLICYTYPES_TCA_POLICIES, + "src/test/resources/policies/BadTestPolicy.yaml"); assertEquals(Response.Status.NOT_ACCEPTABLE.getStatusCode(), rawResponse2.getStatus()); ErrorResponse errorResponse = rawResponse2.readEntity(ErrorResponse.class); assertThat(errorResponse.getErrorMessage()) @@ -340,8 +333,8 @@ public class TestApiRestServer { new File("src/test/resources/policies/BadTestPolicy.yaml").deleteOnExit(); // Send a policy with no policy type trigger an error - String toscaPolicy = - ResourceUtils.getResourceAsString(TOSCA_POLICY_RESOURCE_NAMES[TOSCA_POLICIES_RESOURCE_NAMES.length - 1]); + String toscaPolicy = ResourceUtils + .getResourceAsString(TOSCA_POLICY_RESOURCE_NAMES[TOSCA_POLICIES_RESOURCE_NAMES.length - 1]); toscaPolicy = toscaPolicy.replaceAll("onap.policies.monitoring.cdap.tca.hi.lo.app", "IDontExist"); TextFileUtils.putStringAsTextFile(toscaPolicy, "src/test/resources/policies/BadTestPolicy.yaml"); @@ -407,16 +400,16 @@ public class TestApiRestServer { assertEquals(OP_POLICY_NAME_VCPE, toscaVcpeSt.getToscaTopologyTemplate().getPolicies().get(0).get(OP_POLICY_NAME_VCPE).getName()); - Map<String, Object> props = - toscaVcpeSt.getToscaTopologyTemplate().getPolicies().get(0).get(OP_POLICY_NAME_VCPE).getProperties(); + Map<String, Object> props = toscaVcpeSt.getToscaTopologyTemplate().getPolicies().get(0).get(OP_POLICY_NAME_VCPE) + .getProperties(); assertNotNull(props); List<Object> operations = (List<Object>) props.get("operations"); assertEquals(1, operations.size()); assertEquals(props.get("trigger"), ((Map<String, Object>) operations.get(0)).get("id")); - Map<String, Object> operation = - (Map<String, Object>) ((Map<String, Object>) operations.get(0)).get("operation"); + Map<String, Object> operation = (Map<String, Object>) ((Map<String, Object>) operations.get(0)) + .get("operation"); assertEquals("APPC", operation.get("actor")); assertEquals("Restart", operation.get("operation")); @@ -567,17 +560,12 @@ public class TestApiRestServer { rawResponse = readResource(POLICYTYPES_TCA_POLICIES_VCPE_VERSION1, mediaType); assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus()); - rawResponse = readResource(POLICYTYPES_TCA_POLICIES_VCPE_VERSION2, mediaType); - assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus()); - rawResponse = readResource(POLICYTYPES_TCA_POLICIES_VCPE_LATEST, mediaType); assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus()); rawResponse = deleteResource(POLICYTYPES_TCA_POLICIES_VCPE_VERSION1, mediaType); assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus()); - rawResponse = deleteResource(POLICYTYPES_TCA_POLICIES_VCPE_VERSION2, mediaType); - assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus()); } @Test @@ -605,8 +593,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?mode=referenced", APP_JSON); + rawResponse = readResource("policytypes/onap.policies.Naming/versions/1.0.0/policies?mode=referenced", + APP_JSON); assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus()); namingServiceTemplate = rawResponse.readEntity(ToscaServiceTemplate.class); @@ -689,14 +677,6 @@ public class TestApiRestServer { ErrorResponse errorResponse = rawResponse.readEntity(ErrorResponse.class); assertEquals("policies for onap.restart.tca:1.0.0 do not exist", errorResponse.getErrorMessage()); - rawResponse = deleteResource(POLICYTYPES_TCA_POLICIES_VCPE_VERSION2, mediaType); - assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus()); - - rawResponse = readResource(POLICYTYPES_TCA_POLICIES_VCPE_VERSION2, mediaType); - assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus()); - errorResponse = rawResponse.readEntity(ErrorResponse.class); - assertEquals("policies for onap.restart.tca:2.0.0 do not exist", errorResponse.getErrorMessage()); - rawResponse = readResource(POLICYTYPES_TCA_POLICIES_VCPE, mediaType); assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus()); errorResponse = rawResponse.readEntity(ErrorResponse.class); @@ -846,10 +826,8 @@ public class TestApiRestServer { Response rawResponse = readResource(OPS_POLICIES_VCPE_DEPLOYED, mediaType); assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus()); ErrorResponse errorResponse = rawResponse.readEntity(ErrorResponse.class); - assertEquals( - "could not find policy with ID " + OP_POLICY_NAME_VCPE + " and type " - + "onap.policies.controlloop.Operational:1.0.0 deployed in any pdp group", - errorResponse.getErrorMessage()); + assertEquals("could not find policy with ID " + OP_POLICY_NAME_VCPE + " and type " + + "onap.policies.controlloop.Operational:1.0.0 deployed in any pdp group", errorResponse.getErrorMessage()); } @Test @@ -865,12 +843,12 @@ public class TestApiRestServer { String mediaType = APP_JSON; // default media type ToscaServiceTemplate rawServiceTemplate = new ToscaServiceTemplate(); if (resourceName.endsWith(".json")) { - rawServiceTemplate = - standardCoder.decode(ResourceUtils.getResourceAsString(resourceName), ToscaServiceTemplate.class); + rawServiceTemplate = standardCoder + .decode(ResourceUtils.getResourceAsString(resourceName), ToscaServiceTemplate.class); } else if (resourceName.endsWith(".yaml") || resourceName.endsWith(".yml")) { mediaType = APP_YAML; - rawServiceTemplate = - standardYamlCoder.decode(ResourceUtils.getResourceAsString(resourceName), ToscaServiceTemplate.class); + rawServiceTemplate = standardYamlCoder + .decode(ResourceUtils.getResourceAsString(resourceName), ToscaServiceTemplate.class); } final Invocation.Builder invocationBuilder; @@ -886,12 +864,12 @@ public class TestApiRestServer { String mediaType = APP_JSON; // default media type LegacyOperationalPolicy rawOpsPolicy = new LegacyOperationalPolicy(); if (resourceName.endsWith(".json")) { - rawOpsPolicy = - standardCoder.decode(ResourceUtils.getResourceAsString(resourceName), LegacyOperationalPolicy.class); + rawOpsPolicy = standardCoder + .decode(ResourceUtils.getResourceAsString(resourceName), LegacyOperationalPolicy.class); } else if (resourceName.endsWith(".yaml") || resourceName.endsWith(".yml")) { mediaType = APP_YAML; - rawOpsPolicy = standardYamlCoder.decode(ResourceUtils.getResourceAsString(resourceName), - LegacyOperationalPolicy.class); + rawOpsPolicy = standardYamlCoder + .decode(ResourceUtils.getResourceAsString(resourceName), LegacyOperationalPolicy.class); } final Invocation.Builder invocationBuilder; @@ -927,8 +905,8 @@ public class TestApiRestServer { final SSLContext sc = SSLContext.getInstance("TLSv1.2"); sc.init(null, noopTrustManager, new SecureRandom()); - final ClientBuilder clientBuilder = - ClientBuilder.newBuilder().sslContext(sc).hostnameVerifier((host, session) -> true); + final ClientBuilder clientBuilder = ClientBuilder.newBuilder().sslContext(sc) + .hostnameVerifier((host, session) -> true); final Client client = clientBuilder.build(); final HttpAuthenticationFeature feature = HttpAuthenticationFeature.basic("healthcheck", "zb!XztG34"); client.register(feature); |