X-Git-Url: https://gerrit.onap.org/r/gitweb?p=policy%2Fengine.git;a=blobdiff_plain;f=ONAP-PDP-REST%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Fpolicy%2Fpdp%2Frest%2Fapi%2Fservices%2FPDPServicesTest.java;h=5b660bf7d4cac8b643ac4ea2964186389907a3ee;hp=4e8a0fa4afb0fdd3ec6325ed136f8c69941cb747;hb=4179c96ba6fcc5816f3e35130430b2955bc5cbbf;hpb=939cf950022f89aec547d3a6a9f6b9443b7a8a95 diff --git a/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/PDPServicesTest.java b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/PDPServicesTest.java index 4e8a0fa4a..5b660bf7d 100644 --- a/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/PDPServicesTest.java +++ b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/PDPServicesTest.java @@ -4,12 +4,14 @@ * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Modifications Copyright (C) 2019 Samsung + * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -24,17 +26,13 @@ import java.util.HashMap; import java.util.Map; import java.util.UUID; import java.util.Map.Entry; - import javax.json.Json; import javax.json.JsonArrayBuilder; import javax.json.JsonObject; import javax.json.JsonObjectBuilder; - import org.junit.*; import org.junit.runner.RunWith; - import static org.junit.Assert.*; - import org.onap.policy.api.DecisionRequestParameters; import org.onap.policy.api.PolicyDecisionException; import org.onap.policy.pdp.rest.api.models.PDPResponse; @@ -47,148 +45,136 @@ import org.springframework.test.context.web.WebAppConfiguration; @ContextConfiguration(classes = {PDPRestConfig.class}) @WebAppConfiguration public class PDPServicesTest { - /** - * Run the PDPServices() constructor test. - * - * @generatedBy CodePro at 7/20/17 9:26 AM - */ - @Test - public void testPDPServices_1() - throws Exception { - PDPServices result = new PDPServices(); - assertNotNull(result); - // add additional test code here - } - - /** - * Run the Collection generateRequest(String,UUID,boolean,boolean) method test. - * - * @throws Exception - * - * @generatedBy CodePro at 7/20/17 9:26 AM - */ - @Test - public void testGenerateRequest_1() - throws Exception { - DecisionRequestParameters pep = new DecisionRequestParameters(); - Map eventAttributes = new HashMap<>(); - eventAttributes.put("TEST", "test"); - pep.setOnapName("te123"); - pep.setDecisionAttributes(eventAttributes); - PDPServices fixture = new PDPServices(); - - //Failure Tests. - String jsonString = getModel(pep).toString(); - UUID requestID = UUID.randomUUID(); - - Collection result = fixture.generateRequest(jsonString, requestID, false, true); - - // add additional test code here - // An unexpected exception was thrown in user code while executing this test: - // java.lang.NoClassDefFoundError: Could not initialize class org.onap.policy.pdp.rest.api.services.PDPServices - assertNotNull(result); - - } - - private JsonObject getModel(DecisionRequestParameters pep) throws PolicyDecisionException{ + /** + * Run the PDPServices() constructor test. + * + * @generatedBy CodePro at 7/20/17 9:26 AM + */ + @Test + public void testPDPServices_1() throws Exception { + PDPServices result = new PDPServices(); + assertNotNull(result); + // add additional test code here + } + + /** + * Run the Collection generateRequest(String,UUID,boolean,boolean) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 7/20/17 9:26 AM + */ + @Test + public void testGenerateRequest_1() throws Exception { + DecisionRequestParameters pep = new DecisionRequestParameters(); + Map eventAttributes = new HashMap<>(); + eventAttributes.put("TEST", "test"); + pep.setOnapName("te123"); + pep.setDecisionAttributes(eventAttributes); + PDPServices fixture = new PDPServices(); + + // Failure Tests. + String jsonString = getModel(pep).toString(); + UUID requestID = UUID.randomUUID(); + + Collection result = fixture.generateRequest(jsonString, requestID, false, true); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.NoClassDefFoundError: Could not initialize class + // org.onap.policy.pdp.rest.api.services.PDPServices + assertNotNull(result); + + } + + private JsonObject getModel(DecisionRequestParameters pep) throws PolicyDecisionException { JsonArrayBuilder resourceArray = Json.createArrayBuilder(); - + Map decisionAttributes = pep.getDecisionAttributes(); - for (Entry key : decisionAttributes.entrySet()) { + for (Entry key : decisionAttributes.entrySet()) { JsonObjectBuilder resourceBuilder = Json.createObjectBuilder(); if (key.getValue().matches("[0-9]+")) { - - if ((key.getKey().equals("ErrorCode")) || (key.getKey().equals("WorkStep"))) { - - resourceBuilder.add("Value", key.getValue()); - } else { - + if ((key.getKey().equals("ErrorCode")) || (key.getKey().equals("WorkStep"))) { + + resourceBuilder.add("Value", key.getValue()); + + } else { + int val = Integer.parseInt(key.getValue()); resourceBuilder.add("Value", val); - - } - + + } + } else { resourceBuilder.add("Value", key.getValue()); } resourceBuilder.add("AttributeId", key.getKey()); resourceArray.add(resourceBuilder); } - return Json.createObjectBuilder() - .add("Request", Json.createObjectBuilder() - .add("AccessSubject", Json.createObjectBuilder() - .add("Attribute", Json.createObjectBuilder() - .add("Value", pep.getOnapName()) - .add("AttributeId", "ONAPName"))) - .add("Resource", Json.createObjectBuilder() - .add("Attribute", resourceArray)) - .add("Action", Json.createObjectBuilder() - .add("Attribute", Json.createObjectBuilder() - .add("Value", "DECIDE") - .add("AttributeId", "urn:oasis:names:tc:xacml:1.0:action:action-id")))) + return Json.createObjectBuilder().add("Request", Json.createObjectBuilder().add("AccessSubject", + Json.createObjectBuilder().add("Attribute", + Json.createObjectBuilder().add("Value", pep.getOnapName()).add("AttributeId", "ONAPName"))) + .add("Resource", Json.createObjectBuilder().add("Attribute", resourceArray)) + .add("Action", Json.createObjectBuilder().add("Attribute", Json.createObjectBuilder() + .add("Value", "DECIDE").add("AttributeId", "urn:oasis:names:tc:xacml:1.0:action:action-id")))) .build(); } - - /** - * Run the Collection generateRequest(String,UUID,boolean,boolean) method test. - * - * @throws Exception - * - * @generatedBy CodePro at 7/20/17 9:26 AM - */ - @Test(expected = org.onap.policy.api.PolicyException.class) - public void testGenerateRequest_2() - throws Exception { - PDPServices fixture = new PDPServices(); - fixture.generateRequest("", UUID.randomUUID(), true, true); - String jsonString = ""; - UUID requestID = UUID.randomUUID(); - boolean unique = true; - boolean decide = true; - - Collection result = fixture.generateRequest(jsonString, requestID, unique, decide); - - // add additional test code here - assertNotNull(result); - } - - /** - * Perform pre-test initialization. - * - * @throws Exception - * if the initialization fails for some reason - * - * @generatedBy CodePro at 7/20/17 9:26 AM - */ - @Before - public void setUp() - throws Exception { - // add additional set up code here - } - - /** - * Perform post-test clean-up. - * - * @throws Exception - * if the clean-up fails for some reason - * - * @generatedBy CodePro at 7/20/17 9:26 AM - */ - @After - public void tearDown() - throws Exception { - // Add additional tear down code here - } - - /** - * Launch the test. - * - * @param args the command line arguments - * - * @generatedBy CodePro at 7/20/17 9:26 AM - */ - public static void main(String[] args) { - new org.junit.runner.JUnitCore().run(PDPServicesTest.class); - } -} \ No newline at end of file + + /** + * Run the Collection generateRequest(String,UUID,boolean,boolean) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 7/20/17 9:26 AM + */ + @Test(expected = org.onap.policy.api.PolicyException.class) + public void testGenerateRequest_2() throws Exception { + PDPServices fixture = new PDPServices(); + fixture.generateRequest("", UUID.randomUUID(), true, true); + String jsonString = ""; + UUID requestID = UUID.randomUUID(); + boolean unique = true; + boolean decide = true; + + Collection result = fixture.generateRequest(jsonString, requestID, unique, decide); + + // add additional test code here + assertNotNull(result); + } + + /** + * Perform pre-test initialization. + * + * @throws Exception if the initialization fails for some reason + * + * @generatedBy CodePro at 7/20/17 9:26 AM + */ + @Before + public void setUp() throws Exception { + // add additional set up code here + } + + /** + * Perform post-test clean-up. + * + * @throws Exception if the clean-up fails for some reason + * + * @generatedBy CodePro at 7/20/17 9:26 AM + */ + @After + public void tearDown() throws Exception { + // Add additional tear down code here + } + + /** + * Launch the test. + * + * @param args the command line arguments + * + * @generatedBy CodePro at 7/20/17 9:26 AM + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(PDPServicesTest.class); + } +}