* ================================================================================
* 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();
}
}