diff options
author | kaihlavi <l.kaihlavirt@partner.samsung.com> | 2019-02-05 16:04:04 +0200 |
---|---|---|
committer | kaihlavi <l.kaihlavirt@partner.samsung.com> | 2019-02-12 11:06:01 +0200 |
commit | 939cf950022f89aec547d3a6a9f6b9443b7a8a95 (patch) | |
tree | 185a1d601530a9068a6c9d25622f12458803ffc4 /ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/BRMSRawPolicyServiceTest.java | |
parent | df36ba3e64a49419a64e580283b21fce79591b71 (diff) |
Improve ONAP-PDP-REST JUnit test case independency
Handle cleanup of changed system properties and other test-related
static parameters to prevent unexpected behaviour of other test cases
that are dependent of the same properties and parameters when order
of the execution changes
Add Samsung modification copyrights for changed files
Fix some loggings and a minor typo in documentation
Change-Id: Ib6920d6300da79bfc426e4f348b503e3fd6a31ee
Issue-ID: POLICY-1501
Signed-off-by: kaihlavi <l.kaihlavirt@partner.samsung.com>
Diffstat (limited to 'ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/BRMSRawPolicyServiceTest.java')
-rw-r--r-- | ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/BRMSRawPolicyServiceTest.java | 80 |
1 files changed, 49 insertions, 31 deletions
diff --git a/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/BRMSRawPolicyServiceTest.java b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/BRMSRawPolicyServiceTest.java index b9e9403d4..8781b827e 100644 --- a/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/BRMSRawPolicyServiceTest.java +++ b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/BRMSRawPolicyServiceTest.java @@ -1,15 +1,17 @@ /*- * ============LICENSE_START======================================================= - * ONAP-PAP-REST + * ONAP-PDP-REST * ================================================================================ * Copyright (C) 2018 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. @@ -20,43 +22,59 @@ package org.onap.policy.pdp.rest.api.services; import static org.junit.Assert.assertEquals; + import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.util.Arrays; import java.util.List; import java.util.Properties; + +import org.junit.AfterClass; +import org.junit.BeforeClass; import org.junit.Test; import org.onap.policy.api.PolicyParameters; public class BRMSRawPolicyServiceTest { - @Test - public void testRaw() throws FileNotFoundException, IOException { - Properties prop = new Properties(); - prop.load(new FileInputStream("src/test/resources/pass.xacml.pdp.properties")); - String succeeded = prop.getProperty("xacml.rest.pap.url"); - List<String> paps = Arrays.asList(succeeded.split(",")); - PAPServices.setPaps(paps); - PAPServices.setJunit(true); - prop.clear(); - - String systemKey = "xacml.properties"; - String testVal = "testVal"; - PolicyParameters testParams = new PolicyParameters(); - - // Set the system property temporarily - String oldProperty = System.getProperty(systemKey); - System.setProperty(systemKey, "xacml.pdp.properties"); - - BRMSRawPolicyService service = new BRMSRawPolicyService(testVal, testVal, testParams, testVal); - assertEquals(false, service.getValidation()); - assertEquals("PE300 - Data Issue: No Rule Body given", service.getMessage()); - - // Restore the original system property - if (oldProperty != null) { - System.setProperty(systemKey, oldProperty); - } else { - System.clearProperty(systemKey); + + private static final String SYSTEM_KEY = "xacml.properties"; + private static String oldProperty; + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + Properties prop = new Properties(); + prop.load(new FileInputStream("src/test/resources/pass.xacml.pdp.properties")); + String succeeded = prop.getProperty("xacml.rest.pap.url"); + List<String> paps = Arrays.asList(succeeded.split(",")); + PAPServices.setPaps(paps); + PAPServices.setJunit(true); + oldProperty = System.getProperty(SYSTEM_KEY); + } + + @AfterClass + public static void tearDownAfterClass() { + PAPServices.setPaps(null); + PAPServices.setJunit(false); + // Restore the original system property + if (oldProperty != null) { + System.setProperty(SYSTEM_KEY, oldProperty); + } else { + System.clearProperty(SYSTEM_KEY); + } + } + + @Test + public void testRaw() throws FileNotFoundException, IOException { + + String testVal = "testVal"; + PolicyParameters testParams = new PolicyParameters(); + + // Set the system property temporarily + System.setProperty(SYSTEM_KEY, "xacml.pdp.properties"); + + BRMSRawPolicyService service = + new BRMSRawPolicyService(testVal, testVal, testParams, testVal); + assertEquals(false, service.getValidation()); + assertEquals("PE300 - Data Issue: No Rule Body given", service.getMessage()); } - } } |