summaryrefslogtreecommitdiffstats
path: root/ONAP-PAP-REST/src/test/java/org
diff options
context:
space:
mode:
authorrb7147 <rb7147@att.com>2018-02-28 14:23:12 -0500
committerrb7147 <rb7147@att.com>2018-03-01 11:43:47 -0500
commitf0c563df34a999a1702d51cb6cb44fe10155b16b (patch)
tree9abc7df946750250b8f8daff6b88d50597a7ad6a /ONAP-PAP-REST/src/test/java/org
parent331e68e8699a4264022a2a073ebe8ed8a35322db (diff)
Added Junits for Policy PAP-REST
Issue-ID: POLICY-600 Change-Id: Icb67ac587e614f663416b3ea0a03ca6e5b02c621 Signed-off-by: rb7147 <rb7147@att.com>
Diffstat (limited to 'ONAP-PAP-REST/src/test/java/org')
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/test/XACMLPAPTest.java2
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/adapters/SearchDataTest.java56
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/FirewallConfigPolicyTest.java9
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/elk/ElasticSearchPolicyUpdateTest.java97
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/elk/PolicyElasticSearchControllerTest.java81
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/restAuth/AuthenticationServiceTest.java3
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/restAuth/PAPAuthenticationFilterTest.java69
7 files changed, 310 insertions, 7 deletions
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/test/XACMLPAPTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/test/XACMLPAPTest.java
index c44459690..2b84ccaf1 100644
--- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/test/XACMLPAPTest.java
+++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/test/XACMLPAPTest.java
@@ -715,7 +715,7 @@ public class XACMLPAPTest {
setDBDao();
}
- private void setDBDao() throws SQLException {
+ public void setDBDao() throws SQLException {
BasicDataSource dataSource = new BasicDataSource();
dataSource.setDriverClassName("org.h2.Driver");
// In-memory DB for testing
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/adapters/SearchDataTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/adapters/SearchDataTest.java
new file mode 100644
index 000000000..839af2fdc
--- /dev/null
+++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/adapters/SearchDataTest.java
@@ -0,0 +1,56 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP-PAP-REST
+ * ================================================================================
+ * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.policy.pap.xacml.rest.adapters;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+public class SearchDataTest {
+
+
+ @Test
+ public void testSearchData(){
+ String data = "Test";
+ SearchData searchData = new SearchData();
+ searchData.setQuery(data);
+ searchData.setPolicyType(data);
+ searchData.setOnapName(data);
+ searchData.setDescriptiveScope(data);
+ searchData.setClosedLooppolicyType(data);
+ searchData.setD2Service(data);
+ searchData.setVnfType(data);
+ searchData.setPolicyStatus(data);
+ searchData.setVproAction(data);
+ searchData.setServiceType(data);
+ searchData.setBindTextSearch(data);
+ assertEquals(data, searchData.getQuery());
+ assertEquals(data, searchData.getPolicyType());
+ assertEquals(data, searchData.getDescriptiveScope());
+ assertEquals(data, searchData.getClosedLooppolicyType());
+ assertEquals(data, searchData.getOnapName());
+ assertEquals(data, searchData.getD2Service());
+ assertEquals(data, searchData.getVnfType());
+ assertEquals(data, searchData.getPolicyStatus());
+ assertEquals(data, searchData.getVproAction());
+ assertEquals(data, searchData.getServiceType());
+ assertEquals(data, searchData.getBindTextSearch());
+ }
+}
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/FirewallConfigPolicyTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/FirewallConfigPolicyTest.java
index a2c6ddf4e..0dd919a35 100644
--- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/FirewallConfigPolicyTest.java
+++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/FirewallConfigPolicyTest.java
@@ -35,6 +35,7 @@ import org.junit.Test;
import org.mockito.Mockito;
import org.onap.policy.common.logging.flexlogger.FlexLogger;
import org.onap.policy.common.logging.flexlogger.Logger;
+import org.onap.policy.pap.test.XACMLPAPTest;
import org.onap.policy.rest.adapter.PolicyRestAdapter;
import com.att.research.xacml.util.XACMLProperties;
@@ -47,7 +48,7 @@ public class FirewallConfigPolicyTest {
Map<String, String> attributeMap = new HashMap<>();
FirewallConfigPolicy component = null;
FirewallConfigPolicy mockFWConfig = null;
-
+ private XACMLPAPTest papTest;
/**
* @throws java.lang.Exception
@@ -81,6 +82,8 @@ public class FirewallConfigPolicyTest {
component = new FirewallConfigPolicy(policyAdapter);
mockFWConfig = Mockito.mock(FirewallConfigPolicy.class);
+ papTest = new XACMLPAPTest();
+ papTest.setDBDao();
logger.info("setUp: exit");
}
@@ -132,7 +135,7 @@ public class FirewallConfigPolicyTest {
method.setAccessible(true);
String jsonBody= "{\"serviceTypeId\":\"/v0/firewall/pan\",\"configName\":\"TestFwPolicyConfig\",\"deploymentOption\":{\"deployNow\":false},\"securityZoneId\":\"cloudsite:dev1a\",\"serviceGroups\":[{\"name\":\"SSH\",\"description\":\"Sshservice entry in servicelist\",\"type\":\"SERVICE\",\"transportProtocol\":\"tcp\",\"appProtocol\":null,\"ports\":\"22\"}],\"addressGroups\":[{\"name\":\"test\",\"description\":\"Destination\",\"members\":[{\"type\":\"SUBNET\",\"value\":\"127.0.0.1/12\"}]},{\"name\":\"TestServers\",\"description\":\"SourceTestServers for firsttesting\",\"members\":[{\"type\":\"SUBNET\",\"value\":\"127.0.0.1/23\"}]}],\"firewallRuleList\":[{\"position\":\"1\",\"ruleName\":\"FWRuleTestServerToTest\",\"fromZones\":[\"UntrustedZoneTestName\"],\"toZones\":[\"TrustedZoneTestName\"],\"negateSource\":false,\"negateDestination\":false,\"sourceList\":[{\"type\":\"REFERENCE\",\"name\":\"TestServers\"}],\"destinationList\":[{\"type\":\"REFERENCE\",\"name\":\"Test\"}],\"sourceServices\":[],\"destServices\":[{\"type\":\"REFERENCE\",\"name\":\"SSH\"}],\"action\":\"accept\",\"description\":\"FWrule for Test source to Test destination\",\"enabled\":true,\"log\":true}]}";
String prevJsonBody = "{\"serviceTypeId\":\"/v0/firewall/pan\",\"configName\":\"TestFwPolicy1Config\",\"deploymentOption\":{\"deployNow\":false},\"securityZoneId\":\"cloudsite:dev\",\"vendorServiceId\":\"test\",\"vendorSpecificData\":{\"idMap\":[{\"Id\":\"cloudsite:dev1a\",\"vendorId\":\"deviceGroup:dev\"}]},\"serviceGroups\":[{\"name\":\"SSH\",\"description\":\"Ssh service entry in service list\",\"type\":\"SERVICE\",\"transportProtocol\":\"tcp\",\"appProtocol\":null,\"ports\":\"22\"}],\"addressGroups\":[{\"name\":\"Test\",\"description\":\"Destination Test\",\"members\":[{\"type\":\"SUBNET\",\"value\":\"127.0.0.1/12\"}]},{\"name\":\"TestServers\",\"description\":\"Source TestServers for first testing\",\"members\":[{\"type\":\"SUBNET\",\"value\":\"127.0.0.1/23\"}]}],\"firewallRuleList\":[{\"position\":\"1\",\"ruleName\":\"FWRuleTestServerTot\",\"fromZones\":[\"UntrustedZoneTestName\"],\"toZones\":[\"TrustedZoneTName\"],\"negateSource\":false,\"negateDestination\":false,\"sourceList\":[{\"type\":\"REFERENCE\",\"name\":\"TServers\"}],\"destinationList\":[{\"type\":\"REFERENCE\",\"name\":\"Test\"}],\"sourceServices\":[],\"destServices\":[{\"type\":\"REFERENCE\",\"name\":\"SSH\"}],\"action\":\"accept\",\"description\":\"FW rule for HOHO source to CiscoVCE destination\",\"enabled\":true,\"log\":true}]}";
- assertFalse((Boolean) method.invoke(firewallConfigPolicy, jsonBody, prevJsonBody));
+ assertTrue((Boolean) method.invoke(firewallConfigPolicy, jsonBody, prevJsonBody));
}
@Test
@@ -141,7 +144,7 @@ public class FirewallConfigPolicyTest {
Method method = firewallConfigPolicy.getClass().getDeclaredMethod("insertFirewallDicionaryData", String.class);
method.setAccessible(true);
String jsonBody= "{\"serviceTypeId\":\"/v0/firewall/pan\",\"configName\":\"TestFwPolicyConfig\",\"deploymentOption\":{\"deployNow\":false},\"securityZoneId\":\"cloudsite:dev1a\",\"serviceGroups\":[{\"name\":\"SSH\",\"description\":\"Sshservice entry in servicelist\",\"type\":\"SERVICE\",\"transportProtocol\":\"tcp\",\"appProtocol\":null,\"ports\":\"22\"}],\"addressGroups\":[{\"name\":\"test\",\"description\":\"Destination\",\"members\":[{\"type\":\"SUBNET\",\"value\":\"127.0.0.1/12\"}]},{\"name\":\"TestServers\",\"description\":\"SourceTestServers for firsttesting\",\"members\":[{\"type\":\"SUBNET\",\"value\":\"127.0.0.1/23\"}]}],\"firewallRuleList\":[{\"position\":\"1\",\"ruleName\":\"FWRuleTestServerToTest\",\"fromZones\":[\"UntrustedZoneTestName\"],\"toZones\":[\"TrustedZoneTestName\"],\"negateSource\":false,\"negateDestination\":false,\"sourceList\":[{\"type\":\"REFERENCE\",\"name\":\"TestServers\"}],\"destinationList\":[{\"type\":\"REFERENCE\",\"name\":\"Test\"}],\"sourceServices\":[],\"destServices\":[{\"type\":\"REFERENCE\",\"name\":\"SSH\"}],\"action\":\"accept\",\"description\":\"FWrule for Test source to Test destination\",\"enabled\":true,\"log\":true}]}";
- assertFalse((Boolean) method.invoke(firewallConfigPolicy, jsonBody));
+ assertTrue((Boolean) method.invoke(firewallConfigPolicy, jsonBody));
}
} \ No newline at end of file
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/elk/ElasticSearchPolicyUpdateTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/elk/ElasticSearchPolicyUpdateTest.java
new file mode 100644
index 000000000..2b1300cc4
--- /dev/null
+++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/elk/ElasticSearchPolicyUpdateTest.java
@@ -0,0 +1,97 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP-PAP-REST
+ * ================================================================================
+ * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.policy.pap.xacml.rest.elk;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.sql.SQLException;
+import java.util.Date;
+
+import javax.servlet.ServletException;
+
+import org.apache.commons.io.IOUtils;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.common.logging.flexlogger.FlexLogger;
+import org.onap.policy.common.logging.flexlogger.Logger;
+import org.onap.policy.pap.test.XACMLPAPTest;
+import org.onap.policy.pap.xacml.rest.daoimpl.CommonClassDaoImpl;
+import org.onap.policy.pap.xacml.rest.elk.client.ElasticSearchPolicyUpdate;
+import org.onap.policy.rest.jpa.ConfigurationDataEntity;
+import org.onap.policy.rest.jpa.PolicyEntity;
+
+public class ElasticSearchPolicyUpdateTest {
+
+ private static Logger logger = FlexLogger.getLogger(ElasticSearchPolicyUpdateTest.class);
+ private Object policyContent = "";
+ private XACMLPAPTest papTest;
+
+ @Before
+ public void setUp() throws IOException, ServletException, SQLException{
+ // Set the system property temporarily
+ System.setProperty("PROPERTY_FILE", "src/test/resources/policyelk.properties");
+ try {
+ ClassLoader classLoader = getClass().getClassLoader();
+ policyContent = IOUtils.toString(classLoader.getResourceAsStream("Config_SampleTest1206.1.xml"));
+ } catch (Exception e1) {
+ logger.error("Exception Occured"+e1);
+ }
+ papTest = new XACMLPAPTest();
+ papTest.setDBDao();
+ }
+
+ @Test
+ public void testElasticSearchMainFunction() throws SQLException{
+ ConfigurationDataEntity configurationEntity = new ConfigurationDataEntity();
+ configurationEntity.setConfigBody("Sample Test");
+ configurationEntity.setConfigType("OTHER");
+ configurationEntity.setConfigurationName("com.Config_SampleTest1206.1.txt");
+ configurationEntity.setDescription("test");
+ configurationEntity.setModifiedBy("Test");
+ configurationEntity.setModifiedDate(new Date());
+
+
+ PolicyEntity entity = new PolicyEntity();
+ entity.setPolicyName("Config_SampleTest.1.xml");
+ entity.setPolicyData(policyContent.toString());
+ entity.setScope("com");
+ entity.setCreatedBy("Test");
+ entity.setDeleted(false);
+ entity.setDescription("Test");
+ entity.setModifiedBy("Test");
+ entity.setConfigurationData(configurationEntity);
+ entity.preUpdate();
+ CommonClassDaoImpl dao = new CommonClassDaoImpl();
+ dao.save(configurationEntity);
+ dao.save(entity);
+ dao.delete(dao.getEntityItem(PolicyEntity.class, "policyName", "Config_SampleTest.1.xml"));
+ ElasticSearchPolicyUpdate.main(null);
+ StringBuilder policyDataString = new StringBuilder();
+ ElasticSearchPolicyUpdate.constructPolicyData(policyContent, policyDataString);
+ assertTrue(policyDataString.toString().contains("onapName"));
+ }
+
+ @After
+ public void reset(){
+ System.clearProperty("PROPERTY_FILE");
+ }
+}
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/elk/PolicyElasticSearchControllerTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/elk/PolicyElasticSearchControllerTest.java
new file mode 100644
index 000000000..ec86996c1
--- /dev/null
+++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/elk/PolicyElasticSearchControllerTest.java
@@ -0,0 +1,81 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP-PAP-REST
+ * ================================================================================
+ * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.policy.pap.xacml.rest.elk;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.when;
+
+import java.io.BufferedReader;
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.onap.policy.pap.xacml.rest.elk.client.PolicyElasticSearchController;
+
+public class PolicyElasticSearchControllerTest {
+
+ private PolicyElasticSearchController conroller;
+ private HttpServletRequest request = null;
+ private HttpServletResponse response = null;
+
+ @Before
+ public void setup(){
+ conroller = new PolicyElasticSearchController();
+ request = Mockito.mock(HttpServletRequest.class);
+ response = Mockito.mock(HttpServletResponse.class);
+ }
+
+ @Test
+ public void testSearchDictionary(){
+ List<String> jsonString = new ArrayList<>();
+ jsonString.add("{\"type\":\"attribute\",\"data\":{\"xacmlId\":\"Test\"}}");
+ jsonString.add("{\"type\":\"onapName\",\"data\":{\"onapName\":\"Test\"}}");
+ jsonString.add("{\"type\":\"actionPolicy\",\"data\":{\"attributeName\":\"Test\"}}");
+ jsonString.add("{\"type\":\"brmsParam\",\"data\":{\"ruleName\":\"Test\"}}");
+ jsonString.add("{\"type\":\"pepOptions\",\"data\":{\"pepName\":\"Test\"}}");
+ jsonString.add("{\"type\":\"clSite\",\"data\":{\"siteName\":\"Test\"}}");
+ jsonString.add("{\"type\":\"clService\",\"data\":{\"serviceName\":\"Test\"}}");
+ jsonString.add("{\"type\":\"clVarbind\",\"data\":{\"varbindName\":\"Test\"}}");
+ jsonString.add("{\"type\":\"clVnf\",\"data\":{\"vnftype\":\"Test\"}}");
+ jsonString.add("{\"type\":\"clVSCL\",\"data\":{\"vsclaction\":\"Test\"}}");
+ jsonString.add("{\"type\":\"decision\",\"data\":{\"xacmlId\":\"Test\"}}");
+ jsonString.add("{\"type\":\"fwTerm\",\"data\":{\"termName\":\"Test\"}}");
+ jsonString.add("{\"type\":\"msDCAEUUID\",\"data\":{\"name\":\"Test\"}}");
+ jsonString.add("{\"type\":\"msLocation\",\"data\":{\"name\":\"Test\"}}");
+ jsonString.add("{\"type\":\"msModels\",\"data\":{\"modelName\":\"Test\"}}");
+ jsonString.add("{\"type\":\"psGroupPolicy\",\"data\":{\"name\":\"Test\"}}");
+ jsonString.add("{\"type\":\"safeRisk\",\"data\":{\"name\":\"Test\"}}");
+ jsonString.add("{\"type\":\"safePolicyWarning\",\"data\":{\"name\":\"Test\"}}");
+ for(int i = 0; i < jsonString.size(); i++){
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString.get(i)))) {
+ when(request.getReader()).thenReturn(br);
+ conroller.searchDictionary(request, response);
+ } catch (Exception e) {
+ assertEquals(NullPointerException.class, e.getClass());
+ }
+ }
+ }
+}
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/restAuth/AuthenticationServiceTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/restAuth/AuthenticationServiceTest.java
index 9ac434146..180c13f69 100644
--- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/restAuth/AuthenticationServiceTest.java
+++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/restAuth/AuthenticationServiceTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * ONAP-PDP-REST
+ * ONAP-PAP-REST
* ================================================================================
* Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
@@ -17,7 +17,6 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-//foo
package org.onap.policy.pap.xacml.restAuth;
import static org.junit.Assert.assertEquals;
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/restAuth/PAPAuthenticationFilterTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/restAuth/PAPAuthenticationFilterTest.java
index a115c084b..2d72c8a4d 100644
--- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/restAuth/PAPAuthenticationFilterTest.java
+++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/restAuth/PAPAuthenticationFilterTest.java
@@ -17,19 +17,47 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-//foo
package org.onap.policy.pap.xacml.restAuth;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
+
import java.io.IOException;
+
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.junit.After;
+import org.junit.Before;
import org.junit.Test;
+import org.mockito.Mockito;
+
import com.mockrunner.mock.web.MockHttpServletRequest;
import com.mockrunner.mock.web.MockHttpServletResponse;
public class PAPAuthenticationFilterTest {
+
+ private HttpServletRequest request = null;
+ private HttpServletResponse response = null;
+ private String oldProperty;
+ private String systemKey = "xacml.properties";
+ private FilterChain filter;
+ private PAPAuthenticationFilter papFilter;
+
+ @Before
+ public void setUp(){
+ // Set the system property temporarily
+ oldProperty = System.getProperty(systemKey);
+ System.setProperty(systemKey, "xacml.pap.properties");
+
+ request = Mockito.mock(HttpServletRequest.class);
+ response = Mockito.mock(HttpServletResponse.class);
+ filter = Mockito.mock(FilterChain.class);
+ papFilter = new PAPAuthenticationFilter();
+ }
+
@Test
public void testAuth() throws IOException, ServletException {
PAPAuthenticationFilter filter = new PAPAuthenticationFilter();
@@ -51,4 +79,43 @@ public class PAPAuthenticationFilterTest {
fail("Not expecting any exceptions.");
}
}
+
+ @Test
+ public void testDoFilter() {
+ Mockito.when(request.getRequestURI()).thenReturn("/pap/");
+ Mockito.when(request.getHeader("Authorization")).thenReturn("Basic dGVzdHBhcDphbHBoYTEyMw==");
+ callDoFilter();
+ Mockito.when(request.getRequestURI()).thenReturn("/pap/onap/");
+ callDoFilter();
+ }
+
+ public void callDoFilter(){
+ try {
+ papFilter.doFilter(request, response, filter);
+ } catch (Exception e) {
+ assertEquals(NullPointerException.class, e.getClass());
+ }
+ }
+
+ @Test
+ public void testOnPassingInvalidParamters(){
+ Mockito.when(request.getRequestURI()).thenReturn("/pap/");
+ Mockito.when(request.getHeader("Authorization")).thenReturn("Basic dGVzdHBhcDphbHBoYTE789==");
+ try {
+ papFilter.doFilter(request, response, filter);
+ assertEquals(0, response.getStatus());
+ } catch (Exception e) {
+ fail();
+ }
+ }
+
+ @After
+ public void reset(){
+ // Restore the original system property
+ if (oldProperty != null) {
+ System.setProperty(systemKey, oldProperty);
+ } else {
+ System.clearProperty(systemKey);
+ }
+ }
}