* ================================================================================
* Copyright (C) 2017-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.
import java.util.List;
import java.util.Properties;
import java.util.Random;
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.EntityTransaction;
-import javax.persistence.Persistence;
+
import javax.servlet.ServletConfig;
import javax.servlet.ServletInputStream;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+
+import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.modules.junit4.PowerMockRunner;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.mock.web.MockServletConfig;
+
import com.att.research.xacml.util.XACMLProperties;
import com.mockrunner.mock.web.MockServletInputStream;
+
import junit.framework.TestCase;
@RunWith(PowerMockRunner.class)
private ServletInputStream mockInput;
private ServletConfig servletConfig;
private XACMLPdpServlet pdpServlet;
- private String persistenceUnit;
private Properties properties;
private String resourceName;
private static final String DEFAULT_DB_DRIVER = "org.h2.Driver";
private StdPDPStatus status;
private StdPDPPolicy foobarPolicy;
+ private static final String ERROR_TEXT = "Exception occurred: ";
+
@Override
@Before
public void setUp() {
foobarPolicy.setName("nothing");
status.addLoadedPolicy(foobarPolicy);
-
properties = new Properties();
properties.put(IntegrityAuditProperties.DB_DRIVER, XACMLPdpServletTest.DEFAULT_DB_DRIVER);
properties.put(IntegrityAuditProperties.DB_URL, "jdbc:h2:file:./sql/xacmlTest");
properties.put(IntegrityAuditProperties.DB_PWD, XACMLPdpServletTest.DEFAULT_DB_PWD);
properties.put(IntegrityAuditProperties.SITE_NAME, "SiteA");
properties.put(IntegrityAuditProperties.NODE_TYPE, "pap");
- persistenceUnit = "testPdpPU";
resourceName = "siteA.pdp1";
System.setProperty("com.sun.management.jmxremote.port", "9999");
- EntityManagerFactory emf = Persistence.createEntityManagerFactory(persistenceUnit, properties);
-
- EntityManager em = emf.createEntityManager();
- // Start a transaction
- EntityTransaction et = em.getTransaction();
-
IntegrityMonitor im = null;
try {
im = IntegrityMonitor.getInstance(resourceName, properties);
- } catch (Exception e2) {
- // TODO Auto-generated catch block
- e2.printStackTrace();
+ } catch (Exception e) {
+ e.printStackTrace();
}
- // cleanDb(persistenceUnit, properties);
httpServletRequest = Mockito.mock(HttpServletRequest.class);
Mockito.when(httpServletRequest.getMethod()).thenReturn("POST");
System.setProperty("xacml.properties", "src/test/resources/xacml.pdp.properties");
System.setProperty("xacml.rest.pdp.config", "src/test/resources/config_testing");
System.setProperty("xacml.rest.pdp.webapps", "src/test/resources/webapps");
- /*
- * System.setProperty("xacml.rootPolicies", "test_PolicyEngine.xml");
- * System.setProperty("xacml.referencedPolicies", "test_PolicyEngine.xml");
- * System.setProperty("test_PolicyEngine.xml.file", "config_testing\\test_PolicyEngine.xml");
- */
+
System.setProperty("xacml.rest.pdp.register", "false");
System.setProperty("com.sun.management.jmxremote.port", "9999");
PowerMockito
.when(IntegrityMonitor.getInstance(Mockito.anyString(), Mockito.any(Properties.class)))
.thenReturn(im);
- } catch (Exception e1) {
- LOGGER.error("Exception Occured" + e1);
+ } catch (Exception e) {
+ LOGGER.error(ERROR_TEXT + e);
}
try {
Mockito.doNothing().when(im).endTransaction();
}
+ @Override
+ @After
+ public void tearDown()
+ {
+ System.clearProperty("xacml.rest.pdp.config");
+ }
+
@Test
public void testInit() {
LOGGER.info("XACMLPdpServletTest - testInit");
assertTrue(true);
} catch (Exception e) {
- LOGGER.error("Exception Occured" + e);
+ LOGGER.error(ERROR_TEXT + e);
fail();
}
XACMLPdpLoader.sendNotification();
assertTrue(true);
} catch (Exception e) {
- LOGGER.error("Exception Occured" + e);
+ LOGGER.error(ERROR_TEXT + e);
fail();
}
XACMLPdpLoader.sendNotification();
assertTrue(true);
} catch (Exception e) {
- LOGGER.error("Exception Occured" + e);
+ LOGGER.error(ERROR_TEXT + e);
fail();
}
regThread.run();
assertTrue(true);
} catch (Exception e) {
- LOGGER.error("Exception Occured" + e);
+ LOGGER.error(ERROR_TEXT + e);
fail();
}
}
Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
assertTrue(true);
} catch (Exception e) {
- System.out.println("Unexpected exception in testDoGetNoTypeError");
- LOGGER.error("Exception Occured" + e);
+ LOGGER.error(ERROR_TEXT + e);
fail();
}
}
Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
assertTrue(true);
} catch (Exception e) {
- System.out.println("Unexpected exception in testDoGetConfigType");
- LOGGER.error("Exception Occured" + e);
+ LOGGER.error(ERROR_TEXT + e);
fail();
}
Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
assertTrue(true);
} catch (Exception e) {
- System.out.println("Unexpected exception in testDoGetTypeHb");
- LOGGER.error("Exception Occured" + e);
+ LOGGER.error(ERROR_TEXT + e);
fail();
}
}
Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
assertTrue(true);
} catch (Exception e) {
- System.out.println("Unexpected exception in testDoGetTypeStatus");
- LOGGER.error("Exception Occured" + e);
+ LOGGER.error(ERROR_TEXT + e);
fail();
}
}
pdpServlet.doPost(httpServletRequest, httpServletResponse);
assertTrue(true);
} catch (Exception e) {
- System.out.println("Unexpected exception in testDoPost");
- LOGGER.error("Exception Occured" + e);
+ LOGGER.error(ERROR_TEXT + e);
fail();
}
}
pdpServlet.doPost(httpServletRequest, httpServletResponse);
assertTrue(true);
} catch (Exception e) {
- System.out.println("Unexpected exception in testDoPostToLong");
- LOGGER.error("Exception Occured" + e);
+ LOGGER.error(ERROR_TEXT + e);
fail();
}
}
pdpServlet.doPost(httpServletRequest, httpServletResponse);
assertTrue(true);
} catch (Exception e) {
- System.out.println("Unexpected exception in testDoPostContentLengthNegative");
- LOGGER.error("Exception Occured" + e);
+ LOGGER.error(ERROR_TEXT + e);
fail();
}
}
pdpServlet.doPost(httpServletRequest, httpServletResponse);
assertTrue(true);
} catch (Exception e) {
- System.out.println("Unexpected exception in testDoPostContentTypeNonValid");
- LOGGER.error("Exception Occured" + e);
+ LOGGER.error(ERROR_TEXT + e);
fail();
}
}
pdpServlet.doPost(httpServletRequest, httpServletResponse);
assertTrue(true);
} catch (Exception e) {
- System.out.println("Unexpected exception in testDoPostContentTypeConfigurationError");
- LOGGER.error("Exception Occured" + e);
+ LOGGER.error(ERROR_TEXT + e);
fail();
}
}
"PUT must contain at least one property");
assertTrue(true);
} catch (Exception e) {
- System.out.println("Unexpected exception in testDoPutCacheEmpty");
- LOGGER.error("Exception Occured" + e);
+ LOGGER.error(ERROR_TEXT + e);
fail();
}
}
pdpServlet.doPut(httpServletRequest, httpServletResponse);
assertTrue(true);
} catch (Exception e) {
- System.out.println("Unexpected exception in testDoPutConfigPolicies");
- LOGGER.error("Exception Occured" + e);
+ LOGGER.error(ERROR_TEXT + e);
fail();
}
}
"Content-Length larger than server will accept.");
assertTrue(true);
} catch (Exception e) {
- System.out.println("Unexpected exception in testDoPutToLong");
- LOGGER.error("Exception Occured" + e);
+ LOGGER.error(ERROR_TEXT + e);
fail();
}
}
"Invalid cache: 'policies' or content-type: 'text/json'");
assertTrue(true);
} catch (Exception e) {
- System.out.println("Unexpected exception in testDoPutInvalidContentType");
- LOGGER.error("Exception Occured" + e);
+ LOGGER.error(ERROR_TEXT + e);
fail();
}
}
pdpServlet.init(servletConfig);
pdpServlet.destroy();
} catch (Exception e) {
- System.out.println("Unexpected exception in testDestroy");
- LOGGER.error("Exception Occured" + e);
+ LOGGER.error(ERROR_TEXT + e);
fail();
}
}
/*-
* ============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.
*/
package org.onap.policy.pdp.rest.api.services;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
import java.io.FileInputStream;
import java.text.SimpleDateFormat;
import java.util.Properties;
import java.util.UUID;
-import org.junit.After;
+import org.junit.AfterClass;
import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.onap.policy.api.AttributeType;
import org.onap.policy.api.PolicyConfigType;
import org.onap.policy.api.PolicyParameters;
public class BRMSParamPolicyServiceTest {
-
+
BRMSParamPolicyService service = null;
-
- @Before
- public void setUp() throws Exception {
+
+ @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);
-
+ }
+
+ @Before
+ public void setUp() throws Exception {
PolicyParameters policyParameters = new PolicyParameters();
policyParameters.setPolicyConfigType(PolicyConfigType.BRMS_PARAM);
policyParameters.setPolicyName("Test.testBRMSPolicy");
policyParameters.setGuard(true);
policyParameters.setRiskLevel("5");
policyParameters.setRiskType("TEST");
-
+
Map<String, String> ruleAttributes = new HashMap<>();
ruleAttributes.put("templateName", "Sample");
- ruleAttributes.put("controller", "default");
- ruleAttributes.put("SamPoll", "300");
+ ruleAttributes.put("controller", "default");
+ ruleAttributes.put("SamPoll", "300");
ruleAttributes.put("value", "abcd");
Map<AttributeType, Map<String, String>> attributes = new HashMap<>();
attributes.put(AttributeType.RULE, ruleAttributes);
policyParameters.setAttributes(attributes);
-
+
String policyName = "testBRMSPolicy";
String policyScope = "Test";
service = new BRMSParamPolicyService(policyName, policyScope, policyParameters, date.toString());
}
- @After
- public void tearDown() throws Exception {
+ @AfterClass
+ public static void tearDownAfterClass() {
PAPServices.setPaps(null);
PAPServices.setJunit(false);
}
/*-
* ============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.
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());
}
- }
}
/*-
* ============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.
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 ConfigPolicyServiceTest {
- @Test
- public void testRaw() throws FileNotFoundException, IOException {
+
+ 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);
-
- String systemKey = "xacml.properties";
+ 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
- String oldProperty = System.getProperty(systemKey);
- System.setProperty(systemKey, "xacml.pdp.properties");
-
+ System.setProperty(SYSTEM_KEY, "xacml.pdp.properties");
+
ConfigPolicyService service = new ConfigPolicyService(testVal, testVal, testParams, testVal);
assertEquals(service.getValidation(), false);
assertEquals(service.getMessage(), "PE300 - Data Issue: No Config Body given.");
-
- // Restore the original system property
- if (oldProperty != null) {
- System.setProperty(systemKey, oldProperty);
- }
- else {
- System.clearProperty(systemKey);
- }
- }
+ }
}
/*-
* ============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.
*/
package org.onap.policy.pdp.rest.api.services;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import java.io.FileInputStream;
import java.text.SimpleDateFormat;
import java.util.Properties;
import java.util.UUID;
-import org.junit.After;
+import org.junit.AfterClass;
import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.onap.policy.api.PolicyConfigType;
import org.onap.policy.api.PolicyException;
OptimizationPolicyService service = null;
- @Before
- public void setUp() throws Exception {
+ @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);
- prop.clear();
-
+ }
+
+ @Before
+ public void setUp() throws Exception {
PolicyParameters policyParameters = new PolicyParameters();
policyParameters.setPolicyConfigType(PolicyConfigType.Optimization);
policyParameters.setPolicyName("Test.testOOFPolicy");
service = new OptimizationPolicyService(policyName, policyScope, policyParameters, date.toString());
}
- @After
- public void tearDown() throws Exception {
+ @AfterClass
+ public static void tearDownAfterClass() {
+ PAPServices.setPaps(null);
+ PAPServices.setJunit(false);
}
@Test
* ================================================================================
* 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.
package org.onap.policy.pdp.rest.api.test;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-
import java.lang.reflect.Method;
-
import org.junit.Test;
import org.onap.policy.api.DictionaryParameters;
import org.onap.policy.pdp.rest.api.services.GetDictionaryService;
public class GetDictionaryServiceTest {
-
+
@Test
public void dictionaryJsonTest() throws Exception{
Method formatDictionary = GetDictionaryService.class.getDeclaredMethod("formatDictionaryJson", String.class);
AAF is supported for externally facing entry points into the Policy subsystem. These are:
* PDP-D supports AAF for its telemetry and healthcheck APIs.
-* PDP-X supports AAF for its external policy APIs. It is currently disabled as some of clients are not AAF-capable, and this is a global setting.
+* PDP-X supports AAF for its external policy APIs. It is currently disabled as some of clients are not AAF-capable, and this is a global setting.
* Console (for Browser Portal redirects) supports AAF when accessed through Portal.
+--------+------+------------+-----+-----+---------------------------------+
| Policy | Role | Remote |HTTPS| AAF | Notes |
+========+======+============+=====+=====+=================================+
-| pdp-d |server| \* |true |true |Healthchek and Telemetry APIs |
+| pdp-d |server| \* |true |true |Healthcheck and Telemetry APIs |
+--------+------+------------+-----+-----+---------------------------------+
| pdp-d |client| aaf |true |true |Two-way TLS |
+--------+------+------------+-----+-----+---------------------------------+