Author: veithen
Date: Sat Jan 14 15:22:41 2017
New Revision: 1778779
URL: http://svn.apache.org/viewvc?rev=1778779&view=rev
Log:
Transform JettyServer into a JUnit rule.
Modified:
axis/axis2/java/rampart/trunk/modules/rampart-integration/src/main/java/org/apache/axis2/integration/JettyServer.java
axis/axis2/java/rampart/trunk/modules/rampart-integration/src/main/java/org/apache/rahas/TestClient.java
axis/axis2/java/rampart/trunk/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAML2TokenCertForHoKTest.java
axis/axis2/java/rampart/trunk/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAML2TokenTest.java
axis/axis2/java/rampart/trunk/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAML2TokenUTForBearerTest.java
axis/axis2/java/rampart/trunk/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenAttributeTest.java
axis/axis2/java/rampart/trunk/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenCertForHoKTest.java
axis/axis2/java/rampart/trunk/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenCertForHoKV1205Test.java
axis/axis2/java/rampart/trunk/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenTest.java
axis/axis2/java/rampart/trunk/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenUTForBearerTest.java
axis/axis2/java/rampart/trunk/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenUTForBearerV1205Test.java
axis/axis2/java/rampart/trunk/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenUTForHoKTest.java
axis/axis2/java/rampart/trunk/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenUTForHoKV1205Test.java
axis/axis2/java/rampart/trunk/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenV1205Test.java
axis/axis2/java/rampart/trunk/modules/rampart-integration/src/test/java/org/apache/rampart/RampartTest.java
Modified:
axis/axis2/java/rampart/trunk/modules/rampart-integration/src/main/java/org/apache/axis2/integration/JettyServer.java
URL:
http://svn.apache.org/viewvc/axis/axis2/java/rampart/trunk/modules/rampart-integration/src/main/java/org/apache/axis2/integration/JettyServer.java?rev=1778779&r1=1778778&r2=1778779&view=diff
==============================================================================
---
axis/axis2/java/rampart/trunk/modules/rampart-integration/src/main/java/org/apache/axis2/integration/JettyServer.java
(original)
+++
axis/axis2/java/rampart/trunk/modules/rampart-integration/src/main/java/org/apache/axis2/integration/JettyServer.java
Sat Jan 14 15:22:41 2017
@@ -24,6 +24,7 @@ import org.eclipse.jetty.server.ssl.SslS
import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.eclipse.jetty.webapp.WebAppContext;
+import org.junit.rules.ExternalResource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.axis2.testutils.PortAllocator;
@@ -32,7 +33,7 @@ import org.apache.axis2.transport.http.A
/**
* Support for running an embedded Jetty server
*/
-public class JettyServer {
+public class JettyServer extends ExternalResource {
/**
* Keystore to configure for Jetty's ssl context factory: {@value}
@@ -71,57 +72,41 @@ public class JettyServer {
private static final Logger logger =
LoggerFactory.getLogger(JettyServer.class);
- private static Server server;
-
- private JettyServer() {
-
- }
-
- /**
- * Starts the embedded Jetty server using dynamic port allocation with
both http and https connectors enabled.
- *
- * @param repository The path to the Axis2 repository to use. Must not be
null or empty.
- *
- * @throws Exception
- */
- public static synchronized void start(String repository) throws Exception {
- start(repository, true, true);
- }
-
- /**
- * Starts the embedded Jetty server using dynamic port allocation.
- *
- * @param repository The path to the Axis2 repository to use. Must not be
null or empty.
- * @param enableHttp Specifies whether to enable http connector.
- * @param enableHttps Specifies whether to enable https connector.
- *
- * @throws Exception
- */
- public static synchronized void start(String repository, boolean
enableHttp, boolean enableHttps) throws Exception {
- int httpPort = enableHttp ? PortAllocator.allocatePort() : -1;
- int httpsPort = enableHttps ? PortAllocator.allocatePort() : -1;
-
- start(repository, httpPort, httpsPort);
- }
-
- /**
- * Starts the embedded Jetty server.
- *
- * @param repository The path to the Axis2 repository to use. Must not be
null or empty.
- * @param httpPort The http port to use. Set to <code>-1</code> to disable
http connector.
- * @param httpsPort The https port to use. Set to <code>-1</code> to
disable https connector.
- *
- * @throws Exception
+ private final String repository;
+ private final int httpPort;
+ private final int httpsPort;
+ private Server server;
+
+ /**
+ * Constructor.
+ *
+ * @param repository
+ * The path to the Axis2 repository to use. Must not be null or
empty.
+ * @param httpPort
+ * The http port to use. Set to <code>-1</code> to disable http
connector. Set to
+ * <code>0</code> to enable dynamic port allocation.
+ * @param httpsPort
+ * The https port to use. Set to <code>-1</code> to disable
https connector. Set to
+ * <code>0</code> to enable dynamic port allocation.
* @throws IllegalArgumentException If both ports are set to
<code>-1</code>
*/
- public static synchronized void start(String repository, int httpPort, int
httpsPort) throws Exception {
+ public JettyServer(String repository, int httpPort, int httpsPort) {
if (repository == null || repository.trim().length() == 0) {
throw new IllegalArgumentException("Axis2 repository must not be
null or empty");
}
- else if (httpPort == -1 && httpsPort == -1) {
+ if (httpPort == -1 && httpsPort == -1) {
throw new IllegalArgumentException("At least one port must be
specified.");
}
+ this.repository = repository;
+ this.httpPort = httpPort;
+ this.httpsPort = httpsPort;
+ }
+ @Override
+ protected void before() throws Throwable {
+ int httpPort = this.httpPort == 0 ? PortAllocator.allocatePort() :
this.httpPort;
+ int httpsPort = this.httpsPort == 0 ? PortAllocator.allocatePort() :
this.httpsPort;
+
server = new Server();
SelectChannelConnector connector = null;
@@ -196,15 +181,15 @@ public class JettyServer {
}
}
- /**
- * Stops the embedded Jetty server.
- *
- * @throws Exception
- */
- public static synchronized void stop() throws Exception {
+ @Override
+ protected void after() {
if (server != null) {
logger.info("Stop called");
- server.stop();
+ try {
+ server.stop();
+ } catch (Exception ex) {
+ logger.error("Failed to stop Jetty server", ex);
+ }
server = null;
}
}
@@ -213,7 +198,7 @@ public class JettyServer {
* @return Jetty's http connector port.
* @throws IllegalStateException If Jetty is not running or the http
connector cannot be found.
*/
- public static synchronized int getHttpPort() throws IllegalStateException {
+ public int getHttpPort() throws IllegalStateException {
assertStarted();
Connector[] connectors = server.getConnectors();
@@ -236,7 +221,7 @@ public class JettyServer {
* @return Jetty's ssl connector port.
* @throws IllegalStateException If Jetty is not running or the ssl
connector cannot be found.
*/
- public static synchronized int getHttpsPort() throws IllegalStateException
{
+ public int getHttpsPort() throws IllegalStateException {
assertStarted();
Connector[] connectors = server.getConnectors();
@@ -254,7 +239,7 @@ public class JettyServer {
throw new IllegalStateException("Could not find Jetty https
connector");
}
- private static void assertStarted() throws IllegalStateException {
+ private void assertStarted() throws IllegalStateException {
if (server == null) {
throw new IllegalStateException("Jetty server is not initialized");
}
Modified:
axis/axis2/java/rampart/trunk/modules/rampart-integration/src/main/java/org/apache/rahas/TestClient.java
URL:
http://svn.apache.org/viewvc/axis/axis2/java/rampart/trunk/modules/rampart-integration/src/main/java/org/apache/rahas/TestClient.java?rev=1778779&r1=1778778&r2=1778779&view=diff
==============================================================================
---
axis/axis2/java/rampart/trunk/modules/rampart-integration/src/main/java/org/apache/rahas/TestClient.java
(original)
+++
axis/axis2/java/rampart/trunk/modules/rampart-integration/src/main/java/org/apache/rahas/TestClient.java
Sat Jan 14 15:22:41 2017
@@ -34,27 +34,19 @@ import org.apache.axis2.integration.Jett
import org.apache.neethi.Policy;
import org.apache.neethi.PolicyEngine;
import org.apache.rampart.RampartMessageData;
+import org.junit.Rule;
+import org.junit.Test;
-import junit.framework.TestCase;
-
-public abstract class TestClient extends TestCase {
+public abstract class TestClient {
protected int port = 5555;
- public TestClient(String name) {
- super(name);
- }
-
- protected void setUp() throws Exception {
- JettyServer.start(Constants.TESTING_PATH + getServiceRepo(), port, -1);
- }
-
- protected void tearDown() throws Exception {
- JettyServer.stop();
- }
+ @Rule
+ public final JettyServer server = new JettyServer(Constants.TESTING_PATH +
getServiceRepo(), port, -1);
/**
*/
+ @Test
public void testRequest() throws Exception {
// Get the repository location from the args
String repo = Constants.TESTING_PATH + "rahas_client_repo";
Modified:
axis/axis2/java/rampart/trunk/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAML2TokenCertForHoKTest.java
URL:
http://svn.apache.org/viewvc/axis/axis2/java/rampart/trunk/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAML2TokenCertForHoKTest.java?rev=1778779&r1=1778778&r2=1778779&view=diff
==============================================================================
---
axis/axis2/java/rampart/trunk/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAML2TokenCertForHoKTest.java
(original)
+++
axis/axis2/java/rampart/trunk/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAML2TokenCertForHoKTest.java
Sat Jan 14 15:22:41 2017
@@ -22,13 +22,11 @@ import org.apache.axiom.om.OMAbstractFac
import org.apache.neethi.Policy;
import org.apache.ws.secpolicy.SP11Constants;
+import static org.junit.Assert.assertNotNull;
+
import javax.xml.namespace.QName;
public class RahasSAML2TokenCertForHoKTest extends TestClient{
- public RahasSAML2TokenCertForHoKTest(String name) {
- super(name);
- }
-
public String getServiceRepo() {
return "rahas_service_repo_1";
}
Modified:
axis/axis2/java/rampart/trunk/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAML2TokenTest.java
URL:
http://svn.apache.org/viewvc/axis/axis2/java/rampart/trunk/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAML2TokenTest.java?rev=1778779&r1=1778778&r2=1778779&view=diff
==============================================================================
---
axis/axis2/java/rampart/trunk/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAML2TokenTest.java
(original)
+++
axis/axis2/java/rampart/trunk/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAML2TokenTest.java
Sat Jan 14 15:22:41 2017
@@ -22,15 +22,11 @@ import org.apache.axiom.om.OMAbstractFac
import org.apache.neethi.Policy;
import org.apache.ws.secpolicy.SP11Constants;
+import static org.junit.Assert.assertNotNull;
+
import javax.xml.namespace.QName;
-public class RahasSAML2TokenTest extends TestClient{
- /**
- * @param name
- */
- public RahasSAML2TokenTest(String name) {
- super(name);
- }
+public class RahasSAML2TokenTest extends TestClient{
public String getServiceRepo() {
return "rahas_service_repo_1";
}
Modified:
axis/axis2/java/rampart/trunk/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAML2TokenUTForBearerTest.java
URL:
http://svn.apache.org/viewvc/axis/axis2/java/rampart/trunk/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAML2TokenUTForBearerTest.java?rev=1778779&r1=1778778&r2=1778779&view=diff
==============================================================================
---
axis/axis2/java/rampart/trunk/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAML2TokenUTForBearerTest.java
(original)
+++
axis/axis2/java/rampart/trunk/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAML2TokenUTForBearerTest.java
Sat Jan 14 15:22:41 2017
@@ -33,6 +33,10 @@ import org.w3c.dom.Element;
import javax.xml.namespace.QName;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
import java.io.ByteArrayInputStream;
import java.util.List;
@@ -41,11 +45,6 @@ import java.util.List;
* @author Ruchith Fernando ([email protected])
*/
public class RahasSAML2TokenUTForBearerTest extends TestClient {
-
- public RahasSAML2TokenUTForBearerTest(String name) {
- super(name);
- }
-
public OMElement getRequest() {
try {
OMElement rstElem =
TrustUtil.createRequestSecurityTokenElement(RahasConstants.VERSION_05_02);
Modified:
axis/axis2/java/rampart/trunk/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenAttributeTest.java
URL:
http://svn.apache.org/viewvc/axis/axis2/java/rampart/trunk/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenAttributeTest.java?rev=1778779&r1=1778778&r2=1778779&view=diff
==============================================================================
---
axis/axis2/java/rampart/trunk/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenAttributeTest.java
(original)
+++
axis/axis2/java/rampart/trunk/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenAttributeTest.java
Sat Jan 14 15:22:41 2017
@@ -1,5 +1,7 @@
package org.apache.rahas;
+import static org.junit.Assert.assertNotNull;
+
import javax.xml.namespace.QName;
import org.apache.axiom.om.OMAbstractFactory;
@@ -9,11 +11,6 @@ import org.apache.neethi.Policy;
import org.apache.ws.secpolicy.SP11Constants;
public class RahasSAMLTokenAttributeTest extends TestClient{
-
- public RahasSAMLTokenAttributeTest(String name) {
- super(name);
- }
-
public OMElement getRequest() {
try {
OMElement rstElem =
TrustUtil.createRequestSecurityTokenElement(RahasConstants.VERSION_05_02);
Modified:
axis/axis2/java/rampart/trunk/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenCertForHoKTest.java
URL:
http://svn.apache.org/viewvc/axis/axis2/java/rampart/trunk/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenCertForHoKTest.java?rev=1778779&r1=1778778&r2=1778779&view=diff
==============================================================================
---
axis/axis2/java/rampart/trunk/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenCertForHoKTest.java
(original)
+++
axis/axis2/java/rampart/trunk/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenCertForHoKTest.java
Sat Jan 14 15:22:41 2017
@@ -22,15 +22,11 @@ import org.apache.axiom.om.OMFactory;
import org.apache.neethi.Policy;
import org.apache.ws.secpolicy.SP11Constants;
-import javax.xml.namespace.QName;
+import static org.junit.Assert.assertNotNull;
+import javax.xml.namespace.QName;
public class RahasSAMLTokenCertForHoKTest extends TestClient {
-
- public RahasSAMLTokenCertForHoKTest(String name) {
- super(name);
- }
-
public String getServiceRepo() {
return "rahas_service_repo_1";
}
Modified:
axis/axis2/java/rampart/trunk/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenCertForHoKV1205Test.java
URL:
http://svn.apache.org/viewvc/axis/axis2/java/rampart/trunk/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenCertForHoKV1205Test.java?rev=1778779&r1=1778778&r2=1778779&view=diff
==============================================================================
---
axis/axis2/java/rampart/trunk/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenCertForHoKV1205Test.java
(original)
+++
axis/axis2/java/rampart/trunk/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenCertForHoKV1205Test.java
Sat Jan 14 15:22:41 2017
@@ -22,15 +22,11 @@ import org.apache.axiom.om.OMFactory;
import org.apache.neethi.Policy;
import org.apache.ws.secpolicy.SP12Constants;
+import static org.junit.Assert.assertNotNull;
+
import javax.xml.namespace.QName;
public class RahasSAMLTokenCertForHoKV1205Test extends TestClient {
-
-
- public RahasSAMLTokenCertForHoKV1205Test(String name) {
- super(name);
- }
-
public OMElement getRequest() {
try {
OMElement rstElem =
Modified:
axis/axis2/java/rampart/trunk/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenTest.java
URL:
http://svn.apache.org/viewvc/axis/axis2/java/rampart/trunk/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenTest.java?rev=1778779&r1=1778778&r2=1778779&view=diff
==============================================================================
---
axis/axis2/java/rampart/trunk/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenTest.java
(original)
+++
axis/axis2/java/rampart/trunk/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenTest.java
Sat Jan 14 15:22:41 2017
@@ -22,18 +22,11 @@ import org.apache.axiom.om.OMFactory;
import org.apache.neethi.Policy;
import org.apache.ws.secpolicy.SP11Constants;
+import static org.junit.Assert.assertNotNull;
+
import javax.xml.namespace.QName;
public class RahasSAMLTokenTest extends TestClient {
-
-
- /**
- * @param name
- */
- public RahasSAMLTokenTest(String name) {
- super(name);
- }
-
public String getServiceRepo() {
return "rahas_service_repo_1";
}
Modified:
axis/axis2/java/rampart/trunk/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenUTForBearerTest.java
URL:
http://svn.apache.org/viewvc/axis/axis2/java/rampart/trunk/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenUTForBearerTest.java?rev=1778779&r1=1778778&r2=1778779&view=diff
==============================================================================
---
axis/axis2/java/rampart/trunk/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenUTForBearerTest.java
(original)
+++
axis/axis2/java/rampart/trunk/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenUTForBearerTest.java
Sat Jan 14 15:22:41 2017
@@ -34,6 +34,10 @@ import org.w3c.dom.Element;
import javax.xml.namespace.QName;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
import java.io.ByteArrayInputStream;
import java.util.List;
@@ -42,11 +46,6 @@ import java.util.List;
* @author Ruchith Fernando ([email protected])
*/
public class RahasSAMLTokenUTForBearerTest extends TestClient {
-
- public RahasSAMLTokenUTForBearerTest(String name) {
- super(name);
- }
-
public OMElement getRequest() {
try {
OMElement rstElem =
TrustUtil.createRequestSecurityTokenElement(RahasConstants.VERSION_05_02);
Modified:
axis/axis2/java/rampart/trunk/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenUTForBearerV1205Test.java
URL:
http://svn.apache.org/viewvc/axis/axis2/java/rampart/trunk/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenUTForBearerV1205Test.java?rev=1778779&r1=1778778&r2=1778779&view=diff
==============================================================================
---
axis/axis2/java/rampart/trunk/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenUTForBearerV1205Test.java
(original)
+++
axis/axis2/java/rampart/trunk/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenUTForBearerV1205Test.java
Sat Jan 14 15:22:41 2017
@@ -22,17 +22,11 @@ import org.apache.axiom.om.OMFactory;
import org.apache.neethi.Policy;
import org.apache.ws.secpolicy.SP12Constants;
+import static org.junit.Assert.assertNotNull;
+
import javax.xml.namespace.QName;
public class RahasSAMLTokenUTForBearerV1205Test extends TestClient {
-
- /**
- * @param name
- */
- public RahasSAMLTokenUTForBearerV1205Test(String name) {
- super(name);
- }
-
public OMElement getRequest() {
try {
OMElement rstElem =
TrustUtil.createRequestSecurityTokenElement(RahasConstants.VERSION_05_12);
Modified:
axis/axis2/java/rampart/trunk/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenUTForHoKTest.java
URL:
http://svn.apache.org/viewvc/axis/axis2/java/rampart/trunk/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenUTForHoKTest.java?rev=1778779&r1=1778778&r2=1778779&view=diff
==============================================================================
---
axis/axis2/java/rampart/trunk/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenUTForHoKTest.java
(original)
+++
axis/axis2/java/rampart/trunk/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenUTForHoKTest.java
Sat Jan 14 15:22:41 2017
@@ -22,14 +22,11 @@ import org.apache.axiom.om.OMFactory;
import org.apache.neethi.Policy;
import org.apache.ws.secpolicy.SP11Constants;
+import static org.junit.Assert.assertNotNull;
+
import javax.xml.namespace.QName;
public class RahasSAMLTokenUTForHoKTest extends TestClient {
-
- public RahasSAMLTokenUTForHoKTest(String name) {
- super(name);
- }
-
public OMElement getRequest() {
try {
OMElement rstElem =
TrustUtil.createRequestSecurityTokenElement(RahasConstants.VERSION_05_02);
Modified:
axis/axis2/java/rampart/trunk/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenUTForHoKV1205Test.java
URL:
http://svn.apache.org/viewvc/axis/axis2/java/rampart/trunk/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenUTForHoKV1205Test.java?rev=1778779&r1=1778778&r2=1778779&view=diff
==============================================================================
---
axis/axis2/java/rampart/trunk/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenUTForHoKV1205Test.java
(original)
+++
axis/axis2/java/rampart/trunk/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenUTForHoKV1205Test.java
Sat Jan 14 15:22:41 2017
@@ -16,6 +16,8 @@
package org.apache.rahas;
+import static org.junit.Assert.assertNotNull;
+
import javax.xml.namespace.QName;
import org.apache.axiom.om.OMAbstractFactory;
@@ -30,13 +32,6 @@ public class RahasSAMLTokenUTForHoKV1205
byte[] clientEntr;
- /**
- * @param name
- */
- public RahasSAMLTokenUTForHoKV1205Test(String name) {
- super(name);
- }
-
public OMElement getRequest() {
try {
OMElement rstElem =
TrustUtil.createRequestSecurityTokenElement(RahasConstants.VERSION_05_12);
Modified:
axis/axis2/java/rampart/trunk/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenV1205Test.java
URL:
http://svn.apache.org/viewvc/axis/axis2/java/rampart/trunk/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenV1205Test.java?rev=1778779&r1=1778778&r2=1778779&view=diff
==============================================================================
---
axis/axis2/java/rampart/trunk/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenV1205Test.java
(original)
+++
axis/axis2/java/rampart/trunk/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenV1205Test.java
Sat Jan 14 15:22:41 2017
@@ -22,20 +22,14 @@ import org.apache.axiom.om.OMFactory;
import org.apache.neethi.Policy;
import org.apache.ws.secpolicy.SP12Constants;
+import static org.junit.Assert.assertNotNull;
+
import javax.xml.namespace.QName;
/**
* RahasSAMLTokenTest with the WS-SX namespaces
*/
public class RahasSAMLTokenV1205Test extends TestClient {
-
- /**
- * @param name
- */
- public RahasSAMLTokenV1205Test(String name) {
- super(name);
- }
-
public OMElement getRequest() {
try {
OMElement rstElem =
TrustUtil.createRequestSecurityTokenElement(RahasConstants.VERSION_05_12);
Modified:
axis/axis2/java/rampart/trunk/modules/rampart-integration/src/test/java/org/apache/rampart/RampartTest.java
URL:
http://svn.apache.org/viewvc/axis/axis2/java/rampart/trunk/modules/rampart-integration/src/test/java/org/apache/rampart/RampartTest.java?rev=1778779&r1=1778778&r2=1778779&view=diff
==============================================================================
---
axis/axis2/java/rampart/trunk/modules/rampart-integration/src/test/java/org/apache/rampart/RampartTest.java
(original)
+++
axis/axis2/java/rampart/trunk/modules/rampart-integration/src/test/java/org/apache/rampart/RampartTest.java
Sat Jan 14 15:22:41 2017
@@ -16,12 +16,11 @@
package org.apache.rampart;
-import static org.apache.axis2.integration.JettyServer.getHttpPort;
-import static org.apache.axis2.integration.JettyServer.getHttpsPort;
import static org.apache.axis2.integration.JettyServer.CLIENT_KEYSTORE;
import static org.apache.axis2.integration.JettyServer.KEYSTORE_PASSWORD;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
-import junit.framework.TestCase;
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
@@ -39,14 +38,22 @@ import org.apache.axis2.context.ServiceC
import org.apache.axis2.integration.JettyServer;
import org.apache.neethi.Policy;
import org.apache.neethi.PolicyEngine;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
-public class RampartTest extends TestCase {
+public class RampartTest {
private static ResourceBundle resources;
+
+ @Rule
+ public final JettyServer server = new JettyServer(Constants.TESTING_PATH +
"rampart_service_repo", 0, 0);
+
private String trustStore;
private String trustStorePassword;
private String trustStoreType;
@@ -59,11 +66,8 @@ public class RampartTest extends TestCas
}
}
- public RampartTest(String name) {
- super(name);
- }
-
- protected void setUp() throws Exception {
+ @Before
+ public void setUp() throws Exception {
trustStore = System.getProperty("javax.net.ssl.trustStore");
System.setProperty("javax.net.ssl.trustStore", CLIENT_KEYSTORE);
@@ -72,36 +76,30 @@ public class RampartTest extends TestCas
trustStoreType = System.getProperty("javax.net.ssl.trustStoreType");
System.setProperty("javax.net.ssl.trustStoreType", "JKS");
-
- JettyServer.start(Constants.TESTING_PATH + "rampart_service_repo");
}
- protected void tearDown() throws Exception {
- try {
- JettyServer.stop();
+ @After
+ public void tearDown() throws Exception {
+ if (trustStore != null) {
+ System.setProperty("javax.net.ssl.trustStore", trustStore);
}
- finally {
- if (trustStore != null) {
- System.setProperty("javax.net.ssl.trustStore", trustStore);
- }
- else {
- System.clearProperty("javax.net.ssl.trustStore");
- }
-
- if (trustStorePassword != null) {
- System.setProperty("javax.net.ssl.trustStorePassword",
trustStorePassword);
- }
- else {
- System.clearProperty("javax.net.ssl.trustStorePassword");
- }
-
- if (trustStoreType != null) {
- System.setProperty("javax.net.ssl.trustStoreType",
trustStoreType);
- }
- else {
- System.clearProperty("javax.net.ssl.trustStoreType");
- }
+ else {
+ System.clearProperty("javax.net.ssl.trustStore");
+ }
+
+ if (trustStorePassword != null) {
+ System.setProperty("javax.net.ssl.trustStorePassword",
trustStorePassword);
+ }
+ else {
+ System.clearProperty("javax.net.ssl.trustStorePassword");
+ }
+
+ if (trustStoreType != null) {
+ System.setProperty("javax.net.ssl.trustStoreType", trustStoreType);
+ }
+ else {
+ System.clearProperty("javax.net.ssl.trustStoreType");
}
}
@@ -121,6 +119,7 @@ public class RampartTest extends TestCas
}
+ @Test
public void testWithPolicy() {
try {
@@ -149,7 +148,7 @@ public class RampartTest extends TestCas
if( i == 13 ) {
options.setTo(new EndpointReference("https://localhost:" +
- getHttpsPort() +
+ server.getHttpsPort() +
"/axis2/services/SecureService" + i));
//Username token created with user/pass from options
options.setUserName("alice");
@@ -157,7 +156,7 @@ public class RampartTest extends TestCas
}
else {
options.setTo(new EndpointReference("http://localhost:" +
- getHttpPort() +
+ server.getHttpPort() +
"/axis2/services/SecureService" + i));
}
@@ -225,7 +224,7 @@ public class RampartTest extends TestCas
if (i == 13) {
options.setTo(new EndpointReference("https://localhost:" +
- getHttpsPort() +
+ server.getHttpsPort() +
"/axis2/services/SecureService" + i));
//Username token created with user/pass from options
options.setUserName("alice");
@@ -233,7 +232,7 @@ public class RampartTest extends TestCas
}
else {
options.setTo(new EndpointReference("http://localhost:" +
- getHttpPort() +
+ server.getHttpPort() +
"/axis2/services/SecureService" + i));
}
System.out.println("Testing WS-Sec: negative scenario " + i);
@@ -259,10 +258,10 @@ public class RampartTest extends TestCas
Options options = new Options();
if (i == 3 || i == 6) {
- options.setTo(new EndpointReference("https://localhost:" +
getHttpsPort() + "/axis2/services/SecureServiceSC" + i));
+ options.setTo(new EndpointReference("https://localhost:" +
server.getHttpsPort() + "/axis2/services/SecureServiceSC" + i));
}
else {
- options.setTo(new EndpointReference("http://localhost:" +
getHttpPort() + "/axis2/services/SecureServiceSC" + i));
+ options.setTo(new EndpointReference("http://localhost:" +
server.getHttpPort() + "/axis2/services/SecureServiceSC" + i));
}
System.out.println("Testing WS-SecConv: custom scenario " + i);