auto import from //branches/cupcake/...@125939
diff --git a/x-net/src/test/java/tests/api/javax/net/AllTests.java b/x-net/src/test/java/tests/api/javax/net/AllTests.java
index fabe97d..90c2a6a 100644
--- a/x-net/src/test/java/tests/api/javax/net/AllTests.java
+++ b/x-net/src/test/java/tests/api/javax/net/AllTests.java
@@ -5,7 +5,7 @@
* 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
+ * 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,
@@ -30,7 +30,7 @@
}
public static Test suite() {
- TestSuite suite = new TestSuite("All tests for package tests.api.javax.net;");
+ TestSuite suite = tests.TestSuiteFactory.createTestSuite("All tests for package tests.api.javax.net;");
// $JUnit-BEGIN$
suite.addTestSuite(ServerSocketFactoryTest.class);
diff --git a/x-net/src/test/java/tests/api/javax/net/ServerSocketFactoryTest.java b/x-net/src/test/java/tests/api/javax/net/ServerSocketFactoryTest.java
index 5a5c201..6044e2d 100644
--- a/x-net/src/test/java/tests/api/javax/net/ServerSocketFactoryTest.java
+++ b/x-net/src/test/java/tests/api/javax/net/ServerSocketFactoryTest.java
@@ -23,20 +23,19 @@
package tests.api.javax.net;
import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestInfo;
import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTarget;
+import dalvik.annotation.TestTargetNew;
import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.SocketException;
-import java.net.UnknownHostException;
-
import javax.net.ServerSocketFactory;
import junit.framework.TestCase;
+import tests.support.Support_PortManager;
+
/**
* Tests for <code>ServerSocketFactory</code> class constructors and methods.
@@ -47,18 +46,17 @@
/**
* @tests javax.net.SocketFactory#SocketFactory()
*/
- @TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "ServerSocketFactory",
- methodArgs = {}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "ServerSocketFactory",
+ args = {}
+ )
public void test_Constructor() {
try {
- new MyServerSocketFactory();
+ MyServerSocketFactory mssf = new MyServerSocketFactory();
+ assertNotNull(mssf);
+ assertTrue(mssf instanceof ServerSocketFactory);
} catch (Exception e) {
fail("Unexpected exception " + e.toString());
}
@@ -67,38 +65,170 @@
/**
* @tests javax.net.ServerSocketFactory#createServerSocket()
*/
- @TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "IOException checking missed",
- targets = {
- @TestTarget(
- methodName = "createServerSocket",
- methodArgs = {}
- )
- })
- public final void test_createServerSocket() {
+ @TestTargetNew(
+ level = TestLevel.SUFFICIENT,
+ notes = "IOException checking missed",
+ method = "createServerSocket",
+ args = {}
+ )
+ public final void test_createServerSocket_01() {
ServerSocketFactory sf = new MyServerSocketFactory();
try {
- sf.createServerSocket();
+ ServerSocket ss = sf.createServerSocket();
+ assertNotNull(ss);
fail("No expected SocketException");
} catch (SocketException e) {
- } catch (IOException e) {
+ } catch (Exception e) {
fail(e.toString());
}
}
+
+ /**
+ * @tests javax.net.ServerSocketFactory#createServerSocket(int port)
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "createServerSocket",
+ args = {int.class}
+ )
+ public final void test_createServerSocket_02() {
+ MyServerSocketFactory sf = new MyServerSocketFactory();
+ int portNumber = Support_PortManager.getNextPort();
+
+ try {
+ ServerSocket ss = sf.createServerSocket(portNumber);
+ assertNotNull(ss);
+ } catch (Exception ex) {
+ fail("Unexpected exception: " + ex);
+ }
+
+ try {
+ sf.createServerSocket(portNumber);
+ fail("IOException wasn't thrown");
+ } catch (IOException ioe) {
+ //expected
+ } catch (Exception ex) {
+ fail(ex + " was thrown instead of IOException");
+ }
+
+ try {
+ sf.createServerSocket(-1);
+ fail("IllegalArgumentException wasn't thrown");
+ } catch (IllegalArgumentException ioe) {
+ //expected
+ } catch (Exception ex) {
+ fail(ex + " was thrown instead of IllegalArgumentException");
+ }
+ }
+
+ /**
+ * @tests javax.net.ServerSocketFactory#createServerSocket(int port, int backlog)
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "createServerSocket",
+ args = {int.class, int.class}
+ )
+ public final void test_createServerSocket_03() {
+ MyServerSocketFactory sf = new MyServerSocketFactory();
+ int portNumber = Support_PortManager.getNextPort();
+
+ try {
+ ServerSocket ss = sf.createServerSocket(portNumber, 0);
+ assertNotNull(ss);
+ } catch (Exception ex) {
+ fail("Unexpected exception: " + ex);
+ }
+
+ try {
+ sf.createServerSocket(portNumber, 0);
+ fail("IOException wasn't thrown");
+ } catch (IOException ioe) {
+ //expected
+ } catch (Exception ex) {
+ fail(ex + " was thrown instead of IOException");
+ }
+
+ portNumber = Support_PortManager.getNextPort();
+ try {
+ sf.createServerSocket(portNumber, -1);
+ fail("IOException wasn't thrown");
+ } catch (IOException ioe) {
+ //expected
+ } catch (Exception ex) {
+ fail(ex + " was thrown instead of IOException");
+ }
+
+ try {
+ sf.createServerSocket(65536, 0);
+ fail("IllegalArgumentException wasn't thrown");
+ } catch (IllegalArgumentException ioe) {
+ //expected
+ } catch (Exception ex) {
+ fail(ex + " was thrown instead of IllegalArgumentException");
+ }
+ }
+
+ /**
+ * @tests javax.net.ServerSocketFactory#createServerSocket(int port, int backlog, InetAddress ifAddress)
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "createServerSocket",
+ args = {int.class, int.class, InetAddress.class}
+ )
+ public final void test_createServerSocket_04() {
+ MyServerSocketFactory sf = new MyServerSocketFactory();
+ int portNumber = Support_PortManager.getNextPort();
+
+ try {
+ ServerSocket ss = sf.createServerSocket(portNumber, 0, InetAddress.getLocalHost());
+ assertNotNull(ss);
+ } catch (Exception ex) {
+ fail("Unexpected exception: " + ex);
+ }
+
+ try {
+ sf.createServerSocket(portNumber, 0, InetAddress.getLocalHost());
+ fail("IOException wasn't thrown");
+ } catch (IOException ioe) {
+ //expected
+ } catch (Exception ex) {
+ fail(ex + " was thrown instead of IOException");
+ }
+
+ portNumber = Support_PortManager.getNextPort();
+ try {
+ sf.createServerSocket(portNumber, -1, InetAddress.getLocalHost());
+ fail("IOException wasn't thrown");
+ } catch (IOException ioe) {
+ //expected
+ } catch (Exception ex) {
+ fail(ex + " was thrown instead of IOException");
+ }
+
+ try {
+ sf.createServerSocket(Integer.MAX_VALUE, 0, InetAddress.getLocalHost());
+ fail("IllegalArgumentException wasn't thrown");
+ } catch (IllegalArgumentException ioe) {
+ //expected
+ } catch (Exception ex) {
+ fail(ex + " was thrown instead of IllegalArgumentException");
+ }
+ }
/**
* @tests javax.net.ServerSocketFactory#getDefault()
*/
- @TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getDefault",
- methodArgs = {}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getDefault",
+ args = {}
+ )
public final void test_getDefault() {
ServerSocketFactory sf = ServerSocketFactory.getDefault();
ServerSocket s;
@@ -126,16 +256,46 @@
super();
}
- public ServerSocket createServerSocket(int port) throws IOException, UnknownHostException {
- throw new IOException();
+ public ServerSocket createServerSocket(int port) throws IOException {
+ ServerSocket ss = null;
+ try {
+ ss = new ServerSocket(port);
+ } catch (java.net.BindException be) {
+ throw new IOException("error occurs");
+ } catch (IllegalArgumentException iae) {
+ throw iae;
+ }
+ return ss;
}
- public ServerSocket createServerSocket(int port, int backlog)
- throws IOException, UnknownHostException {
- throw new IOException();
+ public ServerSocket createServerSocket(int port, int backlog) throws IOException {
+ ServerSocket ss = null;
+ if (backlog < 0) {
+ throw new IOException("negative backlog parameter");
+ }
+ try {
+ ss = new ServerSocket(port, backlog);
+ } catch (java.net.BindException be) {
+ throw new IOException("error occurs");
+ } catch (IllegalArgumentException iae) {
+ throw iae;
+ }
+ return ss;
}
- public ServerSocket createServerSocket(int port, int backlog, InetAddress ifAddress) throws IOException {
- throw new IOException();
+ public ServerSocket createServerSocket(int port, int backlog, InetAddress ifAddress)
+ throws IOException {
+ ServerSocket ss = null;
+ if (backlog < 0) {
+ throw new IOException("negative backlog parameter");
+ }
+ try {
+ ss = new ServerSocket(port, backlog, ifAddress);
+ } catch (java.net.BindException be) {
+ throw new IOException("error occurs");
+ } catch (IllegalArgumentException iae) {
+ throw iae;
+ }
+ return ss;
}
}
diff --git a/x-net/src/test/java/tests/api/javax/net/SocketFactoryTest.java b/x-net/src/test/java/tests/api/javax/net/SocketFactoryTest.java
index e894a46..1d39a0c 100644
--- a/x-net/src/test/java/tests/api/javax/net/SocketFactoryTest.java
+++ b/x-net/src/test/java/tests/api/javax/net/SocketFactoryTest.java
@@ -23,12 +23,12 @@
package tests.api.javax.net;
import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestInfo;
import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTarget;
+import dalvik.annotation.TestTargetNew;
import java.io.IOException;
import java.net.InetAddress;
+import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketException;
import java.net.UnknownHostException;
@@ -37,28 +37,29 @@
import junit.framework.TestCase;
+import tests.support.Support_PortManager;
+
/**
* Tests for <code>SocketFactory</code> class methods.
*/
@TestTargetClass(SocketFactory.class)
public class SocketFactoryTest extends TestCase {
-
+
/**
* @tests javax.net.SocketFactory#SocketFactory()
*/
- @TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "SocketFactory",
- methodArgs = {}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "SocketFactory",
+ args = {}
+ )
public void test_Constructor() {
try {
- new MySocketFactory();
+ MySocketFactory sf = new MySocketFactory();
+ assertNotNull(sf);
+ assertTrue(sf instanceof SocketFactory);
} catch (Exception e) {
fail("Unexpected exception " + e.toString());
}
@@ -67,38 +68,280 @@
/**
* @tests javax.net.SocketFactory#createSocket()
*/
- @TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "Exceptions cases are not tested",
- targets = {
- @TestTarget(
- methodName = "createSocket",
- methodArgs = {}
- )
- })
- public final void test_createSocket() {
- SocketFactory sf = new MySocketFactory();
+ @TestTargetNew(
+ level = TestLevel.SUFFICIENT,
+ notes = "IOException check missed",
+ method = "createSocket",
+ args = {}
+ )
+ public final void test_createSocket_01() {
+ SocketFactory sf = SocketFactory.getDefault();
+
try {
- sf.createSocket();
+ Socket s = sf.createSocket();
+ assertNotNull(s);
+ assertEquals(-1, s.getLocalPort());
+ assertEquals(0, s.getPort());
+ } catch (Exception e) {
+ fail("Unexpected exception: " + e);
+ }
+
+ MySocketFactory msf = new MySocketFactory();
+ try {
+ msf.createSocket();
fail("No expected SocketException");
} catch (SocketException e) {
} catch (IOException e) {
fail(e.toString());
}
}
+
+ /**
+ * @tests javax.net.SocketFactory#createSocket(String host, int port)
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "createSocket",
+ args = {String.class, int.class}
+ )
+ public final void test_createSocket_02() {
+ MySocketFactory sf = new MySocketFactory();
+ int portNumber = Support_PortManager.getNextPort();
+ int sport = startServer("Cons String,I");
+ int[] invalidPorts = {Integer.MIN_VALUE, -1, 65536, Integer.MAX_VALUE};
+
+ try {
+ Socket s = sf.createSocket(InetAddress.getLocalHost().getHostName(), sport);
+ assertNotNull(s);
+ assertTrue("Failed to create socket", s.getPort() == sport);
+ } catch (Exception e) {
+ fail("Unexpected exception: " + e);
+ }
+
+ try {
+ Socket s = sf.createSocket("bla-bla", sport);
+ fail("UnknownHostException wasn't thrown");
+ } catch (UnknownHostException uhe) {
+ //expected
+ } catch (Exception e) {
+ fail(e + " was thrown instead of UnknownHostException");
+ }
+
+ for (int i = 0; i < invalidPorts.length; i++) {
+ try {
+ Socket s = sf.createSocket(InetAddress.getLocalHost().getHostName(), invalidPorts[i]);
+ fail("IllegalArgumentException wasn't thrown for " + invalidPorts[i]);
+ } catch (IllegalArgumentException iae) {
+ //expected
+ } catch (Exception e) {
+ fail(e + " was thrown instead of IllegalArgumentException for " + invalidPorts[i]);
+ }
+ }
+ try {
+ Socket s = sf.createSocket(InetAddress.getLocalHost().getHostName(), portNumber);
+ fail("IOException wasn't thrown");
+ } catch (IOException ioe) {
+ //expected
+ }
+
+ SocketFactory f = SocketFactory.getDefault();
+ try {
+ Socket s = f.createSocket("localhost", 8082);
+ fail("IOException wasn't thrown ...");
+ } catch (IOException e) {
+ }
+ }
+
+ /**
+ * @tests javax.net.SocketFactory#createSocket(InetAddress host, int port)
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "createSocket",
+ args = {InetAddress.class, int.class}
+ )
+ public final void test_createSocket_03() {
+ MySocketFactory sf = new MySocketFactory();
+ int portNumber = Support_PortManager.getNextPort();
+ int sport = startServer("Cons InetAddress,I");
+ int[] invalidPorts = {Integer.MIN_VALUE, -1, 65536, Integer.MAX_VALUE};
+
+ try {
+ Socket s = sf.createSocket(InetAddress.getLocalHost(), sport);
+ assertNotNull(s);
+ assertTrue("Failed to create socket", s.getPort() == sport);
+ } catch (Exception e) {
+ fail("Unexpected exception: " + e);
+ }
+
+ for (int i = 0; i < invalidPorts.length; i++) {
+ try {
+ Socket s = sf.createSocket(InetAddress.getLocalHost(), invalidPorts[i]);
+ fail("IllegalArgumentException wasn't thrown for " + invalidPorts[i]);
+ } catch (IllegalArgumentException iae) {
+ //expected
+ } catch (Exception e) {
+ fail(e + " was thrown instead of IllegalArgumentException for " + invalidPorts[i]);
+ }
+ }
+
+ try {
+ Socket s = sf.createSocket(InetAddress.getLocalHost(), portNumber);
+ fail("IOException wasn't thrown");
+ } catch (IOException ioe) {
+ //expected
+ }
+
+ SocketFactory f = SocketFactory.getDefault();
+ try {
+ Socket s = f.createSocket(InetAddress.getLocalHost(), 8081);
+ fail("IOException wasn't thrown ...");
+ } catch (IOException e) {
+ }
+ }
+
+ /**
+ * @tests javax.net.SocketFactory#createSocket(InetAddress address, int port,
+ * InetAddress localAddress, int localPort)
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "createSocket",
+ args = {InetAddress.class, int.class, InetAddress.class, int.class}
+ )
+ public final void test_createSocket_04() {
+ MySocketFactory sf = new MySocketFactory();
+ int portNumber = Support_PortManager.getNextPort();
+ int sport = startServer("Cons InetAddress,I,InetAddress,I");
+ int[] invalidPorts = {Integer.MIN_VALUE, -1, 65536, Integer.MAX_VALUE};
+
+ try {
+ Socket s = sf.createSocket(InetAddress.getLocalHost(), sport,
+ InetAddress.getLocalHost(), portNumber);
+ assertNotNull(s);
+ assertTrue("1: Failed to create socket", s.getPort() == sport);
+ assertTrue("2: Failed to create socket", s.getLocalPort() == portNumber);
+ } catch (Exception e) {
+ fail("Unexpected exception: " + e);
+ }
+
+ for (int i = 0; i < invalidPorts.length; i++) {
+ try {
+ Socket s = sf.createSocket(InetAddress.getLocalHost(), invalidPorts[i],
+ InetAddress.getLocalHost(), portNumber);
+ fail("IllegalArgumentException wasn't thrown for " + invalidPorts[i]);
+ } catch (IllegalArgumentException iae) {
+ //expected
+ } catch (Exception e) {
+ fail(e + " was thrown instead of IllegalArgumentException for " + invalidPorts[i]);
+ }
+
+ try {
+ Socket s = sf.createSocket(InetAddress.getLocalHost(), sport,
+ InetAddress.getLocalHost(), invalidPorts[i]);
+ fail("IllegalArgumentException wasn't thrown for " + invalidPorts[i]);
+ } catch (IllegalArgumentException iae) {
+ //expected
+ } catch (Exception e) {
+ fail(e + " was thrown instead of IllegalArgumentException for " + invalidPorts[i]);
+ }
+ }
+
+ try {
+ Socket s = sf.createSocket(InetAddress.getLocalHost(), sport,
+ InetAddress.getLocalHost(), portNumber);
+ fail("IOException wasn't thrown");
+ } catch (IOException ioe) {
+ //expected
+ }
+
+ SocketFactory f = SocketFactory.getDefault();
+ try {
+ Socket s = f.createSocket(InetAddress.getLocalHost(), 8081, InetAddress.getLocalHost(), 8082);
+ fail("IOException wasn't thrown ...");
+ } catch (IOException e) {
+ }
+ }
+
+ /**
+ * @tests javax.net.SocketFactory#createSocket(String host, int port,
+ * InetAddress localHost, int localPort)
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "createSocket",
+ args = {String.class, int.class, InetAddress.class, int.class}
+ )
+ public final void test_createSocket_05() {
+ MySocketFactory sf = new MySocketFactory();
+ int portNumber = Support_PortManager.getNextPort();
+ int sport = startServer("Cons String,I,InetAddress,I");
+ int[] invalidPorts = {Integer.MIN_VALUE, -1, 65536, Integer.MAX_VALUE};
+
+ try {
+ Socket s = sf.createSocket(InetAddress.getLocalHost().getHostName(), sport,
+ InetAddress.getLocalHost(), portNumber);
+ assertNotNull(s);
+ assertTrue("1: Failed to create socket", s.getPort() == sport);
+ assertTrue("2: Failed to create socket", s.getLocalPort() == portNumber);
+ } catch (Exception e) {
+ fail("Unexpected exception: " + e);
+ }
+
+ portNumber = Support_PortManager.getNextPort();
+ try {
+ Socket s = sf.createSocket("bla-bla", sport, InetAddress.getLocalHost(), portNumber);
+ fail("UnknownHostException wasn't thrown");
+ } catch (UnknownHostException uhe) {
+ //expected
+ } catch (Exception e) {
+ fail(e + " was thrown instead of UnknownHostException");
+ }
+
+ for (int i = 0; i < invalidPorts.length; i++) {
+ portNumber = Support_PortManager.getNextPort();
+ try {
+ Socket s = sf.createSocket(InetAddress.getLocalHost().getHostName(), invalidPorts[i],
+ InetAddress.getLocalHost(), portNumber);
+ fail("IllegalArgumentException wasn't thrown for " + invalidPorts[i]);
+ } catch (IllegalArgumentException iae) {
+ //expected
+ } catch (Exception e) {
+ fail(e + " was thrown instead of IllegalArgumentException for " + invalidPorts[i]);
+ }
+ try {
+ Socket s = sf.createSocket(InetAddress.getLocalHost().getHostName(), sport,
+ InetAddress.getLocalHost(), invalidPorts[i]);
+ fail("IllegalArgumentException wasn't thrown for " + invalidPorts[i]);
+ } catch (IllegalArgumentException iae) {
+ //expected
+ } catch (Exception e) {
+ fail(e + " was thrown instead of IllegalArgumentException for " + invalidPorts[i]);
+ }
+ }
+
+ SocketFactory f = SocketFactory.getDefault();
+ try {
+ Socket s = f.createSocket("localhost", 8081, InetAddress.getLocalHost(), 8082);
+ fail("IOException wasn't thrown ...");
+ } catch (IOException e) {
+ }
+ }
+
/**
* @tests javax.net.SocketFactory#getDefault()
*/
- @TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getDefault",
- methodArgs = {}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getDefault",
+ args = {}
+ )
public final void test_getDefault() {
SocketFactory sf = SocketFactory.getDefault();
Socket s;
@@ -123,6 +366,17 @@
} catch (IOException e) {
}
}
+
+ protected int startServer(String name) {
+ int portNumber = Support_PortManager.getNextPort();
+ ServerSocket ss = null;
+ try {
+ ss = new ServerSocket(portNumber);
+ } catch (IOException e) {
+ fail(name + ": " + e);
+ }
+ return ss.getLocalPort();
+ }
}
class MySocketFactory extends SocketFactory {
@@ -132,21 +386,45 @@
}
public Socket createSocket(String host, int port) throws IOException, UnknownHostException {
- throw new IOException();
+ Socket s = null;
+ try {
+ s = new Socket(host, port);
+ } catch (java.net.ConnectException ce) {
+ throw new IOException("error occurs");
+ }
+ return s;
}
public Socket createSocket(String host, int port, InetAddress localHost, int localPort)
throws IOException, UnknownHostException {
- throw new IOException();
+ Socket s = null;
+ try {
+ s = new Socket(host, port, localHost, localPort);
+ } catch (java.net.ConnectException ce) {
+ throw new IOException("error occurs");
+ }
+ return s;
}
public Socket createSocket(InetAddress host, int port) throws IOException {
- throw new IOException();
+ Socket s = null;
+ try {
+ s = new Socket(host, port);
+ } catch (java.net.ConnectException ce) {
+ throw new IOException("error occurs");
+ }
+ return s;
}
- public Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort)
- throws IOException {
- throw new IOException();
+ public Socket createSocket(InetAddress address, int port,
+ InetAddress localAddress, int localPort) throws IOException {
+ Socket s = null;
+ try {
+ s = new Socket(address, port, localAddress, localPort);
+ } catch (java.net.ConnectException ce) {
+ throw new IOException("error occurs");
+ }
+ return s;
}
}
diff --git a/x-net/src/test/java/tests/api/javax/net/ssl/AllTests.java b/x-net/src/test/java/tests/api/javax/net/ssl/AllTests.java
index 8846b06..69e75c6 100644
--- a/x-net/src/test/java/tests/api/javax/net/ssl/AllTests.java
+++ b/x-net/src/test/java/tests/api/javax/net/ssl/AllTests.java
@@ -5,7 +5,7 @@
* 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
+ * 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,
@@ -30,14 +30,12 @@
}
public static Test suite() {
- TestSuite suite = new TestSuite("All tests for package tests.api.javax.net.ssl;");
+ TestSuite suite = tests.TestSuiteFactory.createTestSuite("All tests for package tests.api.javax.net.ssl;");
// $JUnit-BEGIN$
suite.addTestSuite(CertPathTrustManagerParametersTest.class);
-// suite.addTestSuite(HandshakeCompletedEventTest.class);
+ suite.addTestSuite(HandshakeCompletedEventTest.class);
suite.addTestSuite(HttpsURLConnectionTest.class);
-// suite.addTestSuite(HttpsURLConnectionTest1.class);
-// suite.addTestSuite(HttpURLConnectionTest.class);
suite.addTestSuite(KeyManagerFactory1Test.class);
suite.addTestSuite(KeyManagerFactory2Test.class);
suite.addTestSuite(KeyManagerFactorySpiTest.class);
@@ -54,6 +52,24 @@
suite.addTestSuite(TrustManagerFactory2Test.class);
suite.addTestSuite(TrustManagerFactorySpiTest.class);
suite.addTestSuite(X509ExtendedKeyManagerTest.class);
+ suite.addTestSuite(SSLSocketTest.class);
+ suite.addTestSuite(SSLServerSocketTest.class);
+ suite.addTestSuite(SSLProtocolExceptionTest.class);
+ suite.addTestSuite(SSLPeerUnverifiedExceptionTest.class);
+ suite.addTestSuite(SSLKeyExceptionTest.class);
+ suite.addTestSuite(SSLHandshakeExceptionTest.class);
+ suite.addTestSuite(SSLExceptionTest.class);
+ suite.addTestSuite(SSLEngineResultStatusTest.class);
+ suite.addTestSuite(SSLEngineResultHandshakeStatusTest.class);
+ suite.addTestSuite(SSLEngineResultTest.class);
+ suite.addTestSuite(KeyStoreBuilderParametersTest.class);
+ suite.addTestSuite(SSLSessionContextTest.class);
+ suite.addTestSuite(X509TrustManagerTest.class);
+ suite.addTestSuite(X509KeyManagerTest.class);
+ suite.addTestSuite(SSLSessionTest.class);
+ suite.addTestSuite(SSLSessionBindingListenerTest.class);
+ suite.addTestSuite(HandshakeCompletedListenerTest.class);
+ suite.addTestSuite(HostnameVerifierTest.class);
// $JUnit-END$
return suite;
diff --git a/x-net/src/test/java/tests/api/javax/net/ssl/CertPathTrustManagerParametersTest.java b/x-net/src/test/java/tests/api/javax/net/ssl/CertPathTrustManagerParametersTest.java
index 25a5df2..45c8d73 100644
--- a/x-net/src/test/java/tests/api/javax/net/ssl/CertPathTrustManagerParametersTest.java
+++ b/x-net/src/test/java/tests/api/javax/net/ssl/CertPathTrustManagerParametersTest.java
@@ -18,9 +18,9 @@
package tests.api.javax.net.ssl;
import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestInfo;
+import dalvik.annotation.TestTargets;
import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTarget;
+import dalvik.annotation.TestTargetNew;
import java.security.cert.CertPathParameters;
import javax.net.ssl.CertPathTrustManagerParameters;
@@ -41,15 +41,12 @@
* Case 1: Try to construct object.
* Case 2: Check NullPointerException.
*/
- @TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "CertPathTrustManagerParameters",
- methodArgs = {CertPathParameters.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "CertPathTrustManagerParameters",
+ args = {java.security.cert.CertPathParameters.class}
+ )
public void test_ConstructorLjava_security_cert_CertPathParameters() {
// case 1: Try to construct object.
try {
@@ -74,15 +71,12 @@
/**
* @tests javax.net.ssl.CertPathTrustManagerParameters#getParameters()
*/
- @TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getParameters",
- methodArgs = {}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getParameters",
+ args = {}
+ )
public void test_getParameters() {
CertPathParameters parameters = new MyCertPathParameters();
CertPathTrustManagerParameters p = new CertPathTrustManagerParameters(
diff --git a/x-net/src/test/java/tests/api/javax/net/ssl/HandshakeCompletedEventTest.java b/x-net/src/test/java/tests/api/javax/net/ssl/HandshakeCompletedEventTest.java
index 6f301da..1b3c9d7 100644
--- a/x-net/src/test/java/tests/api/javax/net/ssl/HandshakeCompletedEventTest.java
+++ b/x-net/src/test/java/tests/api/javax/net/ssl/HandshakeCompletedEventTest.java
@@ -18,23 +18,23 @@
package tests.api.javax.net.ssl;
import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestInfo;
import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTarget;
+import dalvik.annotation.TestTargetNew;
-import java.io.IOException;
-import java.net.ServerSocket;
-import java.security.Principal;
+import java.io.ByteArrayInputStream;
import java.security.cert.Certificate;
import javax.net.ssl.HandshakeCompletedEvent;
import javax.net.ssl.SSLPeerUnverifiedException;
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocket;
-import javax.net.ssl.SSLSocketFactory;
+import javax.security.cert.X509Certificate;
import junit.framework.TestCase;
+import org.apache.harmony.xnet.tests.support.mySSLSession;
+import org.apache.harmony.xnet.tests.support.mySSLSocket;
+
/**
* Tests for <code>HandshakeCompletedEvent</code> class constructors and methods.
@@ -42,259 +42,238 @@
*/
@TestTargetClass(HandshakeCompletedEvent.class)
public class HandshakeCompletedEventTest extends TestCase {
+
+ String certificate = "-----BEGIN CERTIFICATE-----\n"
+ + "MIICZTCCAdICBQL3AAC2MA0GCSqGSIb3DQEBAgUAMF8xCzAJBgNVBAYTAlVTMSAw\n"
+ + "HgYDVQQKExdSU0EgRGF0YSBTZWN1cml0eSwgSW5jLjEuMCwGA1UECxMlU2VjdXJl\n"
+ + "IFNlcnZlciBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTAeFw05NzAyMjAwMDAwMDBa\n"
+ + "Fw05ODAyMjAyMzU5NTlaMIGWMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZv\n"
+ + "cm5pYTESMBAGA1UEBxMJUGFsbyBBbHRvMR8wHQYDVQQKExZTdW4gTWljcm9zeXN0\n"
+ + "ZW1zLCBJbmMuMSEwHwYDVQQLExhUZXN0IGFuZCBFdmFsdWF0aW9uIE9ubHkxGjAY\n"
+ + "BgNVBAMTEWFyZ29uLmVuZy5zdW4uY29tMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCB\n"
+ + "iQKBgQCofmdY+PiUWN01FOzEewf+GaG+lFf132UpzATmYJkA4AEA/juW7jSi+LJk\n"
+ + "wJKi5GO4RyZoyimAL/5yIWDV6l1KlvxyKslr0REhMBaD/3Z3EsLTTEf5gVrQS6sT\n"
+ + "WMoSZAyzB39kFfsB6oUXNtV8+UKKxSxKbxvhQn267PeCz5VX2QIDAQABMA0GCSqG\n"
+ + "SIb3DQEBAgUAA34AXl3at6luiV/7I9MN5CXYoPJYI8Bcdc1hBagJvTMcmlqL2uOZ\n"
+ + "H9T5hNMEL9Tk6aI7yZPXcw/xI2K6pOR/FrMp0UwJmdxX7ljV6ZtUZf7pY492UqwC\n"
+ + "1777XQ9UEZyrKJvF5ntleeO0ayBqLGVKCWzWZX9YsXCpv47FNLZbupE=\n"
+ + "-----END CERTIFICATE-----\n";
- int port;
-
- ServerSocket ss;
-
- SSLSocket soc;
-
- boolean noFreePort = false;
- boolean noSocket = false;
-
- /*
- * @see TestCase#setUp()
- */
- protected void setUp() throws Exception {
- super.setUp();
- SSLSocketFactory sf = (SSLSocketFactory) SSLSocketFactory.getDefault();
- try {
- ss = new ServerSocket(0);
- port = ss.getLocalPort();
- } catch (Exception e) {
- e.printStackTrace();
- noFreePort = true;
- return;
- }
- try {
- soc = (SSLSocket) sf.createSocket("localhost", port);
- } catch (IOException e) {
- noSocket = true;
- }
-
- }
-
- /*
- * @see TestCase#tearDown()
- */
- protected void tearDown() throws Exception {
- super.tearDown();
- if (ss != null) {
- ss.close();
- }
- if (soc != null) {
- soc.close();
- }
- }
-
- @TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "Verification with null/incorrect parameters missed",
- targets = {
- @TestTarget(
- methodName = "HandshakeCompletedEvent",
- methodArgs = {SSLSocket.class, SSLSession.class}
- )
- })
- public final void _test_Constructor() {
- if (noFreePort || noSocket) {
- return;
- }
- SSLSession ses = new MySSLSession();
- HandshakeCompletedEvent event = new HandshakeCompletedEvent(soc, ses);
- if (!ses.equals(event.getSession())) {
- fail("incorrect session");
- }
- if (!soc.equals(event.getSocket())) {
- fail("incorrect socket");
- }
- }
-
- @TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getCipherSuite",
- methodArgs = {}
- )
- })
- public final void _test_getCipherSuite() {
- if (noFreePort || noSocket) {
- return;
- }
- SSLSession ses = new MySSLSession();
-
- HandshakeCompletedEvent event = new HandshakeCompletedEvent(soc, ses);
- String name = event.getCipherSuite();
- String name_ses = ses.getCipherSuite();
- if (name == null && name_ses != null) {
- fail("incorrect null CipherCuite");
- }
- if (!name.equals(name_ses)) {
- fail("incorrect CipherCuite");
- }
- }
/**
- * @tests javax.net.ssl.HandshakeCompletedEvent#getLocalPrincipal()
+ * @tests javax.net.ssl.HandshakeCompletedEvent#HandshakeCompletedEvent(SSLSocket sock, SSLSession s)
*/
- @TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getLocalPrincipal",
- methodArgs = {}
- )
- })
- public void _test_getLocalPrincipal() {
- if (noFreePort || noSocket) return;
- SSLSession ses = new MySSLSession();
- HandshakeCompletedEvent event = new HandshakeCompletedEvent(soc, ses);
- Principal lp = event.getLocalPrincipal();
- Principal ses_lp = ses.getLocalPrincipal();
- assertEquals("Incorrect value of local principal",
- lp, ses_lp);
+ @TestTargetNew(
+ level = TestLevel.SUFFICIENT,
+ notes = "Exceptions for null/incorrect parameters are not provided",
+ method = "HandshakeCompletedEvent",
+ args = {javax.net.ssl.SSLSocket.class, javax.net.ssl.SSLSession.class}
+ )
+ public final void test_Constructor() {
+ mySSLSession session = new mySSLSession("localhost", 1080, null);
+ mySSLSocket socket = new mySSLSocket();
+ try {
+ HandshakeCompletedEvent event = new HandshakeCompletedEvent(socket, session);
+ assertNotNull(event);
+ } catch (Exception e) {
+ fail("Unexpected exception: " + e);
+ }
+ try {
+ HandshakeCompletedEvent event = new HandshakeCompletedEvent(null, null);
+ fail("Any exception wasn't thrown for null parameters");
+ } catch (Exception e) {
+ //expected
+ }
}
- @TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getLocalCertificates",
- methodArgs = {}
- )
- })
- public final void _test_getLocalCertificates() {
- if (noFreePort || noSocket) {
- return;
- }
- SSLSession ses = new MySSLSession();
- HandshakeCompletedEvent event = new HandshakeCompletedEvent(soc, ses);
-
- Certificate[] certs = event.getLocalCertificates();
- Certificate[] ses_certs = ses.getLocalCertificates();
- if (certs == null && ses_certs == null) {
- return;
- }
- if (certs == null || ses_certs == null) {
- fail("incorrect LocalCertificates");
- }
- for (int i = 0; i < certs.length; i++) {
- if (certs[i] != ses_certs[i]) {
- fail("incorrect LocalCertificates");
- }
- }
- }
-
- @TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "Just SSLPeerUnverifiedException case was tested",
- targets = {
- @TestTarget(
- methodName = "getPeerCertificateChain",
- methodArgs = {}
- )
- })
- public final void _test_getPeerCertificateChain() {
- if (noFreePort || noSocket) {
- return;
- }
- SSLSession ses = new MySSLSession();
- HandshakeCompletedEvent event = new HandshakeCompletedEvent(soc, ses);
+ /**
+ * @tests javax.net.ssl.HandshakeCompletedEvent#getCipherSuite()
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getCipherSuite",
+ args = {}
+ )
+ public final void test_getCipherSuite() {
+ mySSLSession session = new mySSLSession("localhost", 1080, null);
+ mySSLSocket socket = new mySSLSocket();
+ HandshakeCompletedEvent event = new HandshakeCompletedEvent(socket, session);
try {
- event.getPeerCertificateChain();
- fail("No excpected SSLPeerUnverifiedException");
- } catch (SSLPeerUnverifiedException e) {
+ String name = event.getCipherSuite();
+ } catch (Exception e) {
+ fail("Unexpected exception: " + e);
}
}
-
- @TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "Just SSLPeerUnverifiedException case was tested",
- targets = {
- @TestTarget(
- methodName = "getPeerCertificates",
- methodArgs = {}
- )
- })
- public final void _test_getPeerCertificates() {
- if (noFreePort || noSocket) {
- return;
- }
- SSLSession ses = new MySSLSession();
- HandshakeCompletedEvent event = new HandshakeCompletedEvent(soc, ses);
+
+ /**
+ * @tests javax.net.ssl.HandshakeCompletedEvent#getLocalCertificates()
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getLocalCertificates",
+ args = {}
+ )
+ public final void test_getLocalCertificates() {
+ mySSLSession session = new mySSLSession("localhost", 1080, null);
+ mySSLSocket socket = new mySSLSocket();
+ HandshakeCompletedEvent event = new HandshakeCompletedEvent(socket, session);
try {
- event.getPeerCertificates();
- fail("No excpected SSLPeerUnverifiedException");
- } catch (SSLPeerUnverifiedException e) {
+ assertNull(event.getLocalCertificates());
+ } catch (Exception e) {
+ fail("Unexpected exception: " + e);
}
}
-
+
/**
- * @tests javax.net.ssl.HandshakeCompletedEvent#getPeerPrincipal()
+ * @tests javax.net.ssl.HandshakeCompletedEvent#getLocalPrincipal()
*/
- @TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "Just SSLPeerUnverifiedException case was tested",
- targets = {
- @TestTarget(
- methodName = "getPeerPrincipal",
- methodArgs = {}
- )
- })
- public void _test_getPeerPrincipal()
- throws SSLPeerUnverifiedException {
- if (noFreePort || noSocket) return;
- SSLSession ses = new MySSLSession();
- HandshakeCompletedEvent event = new HandshakeCompletedEvent(soc, ses);
- Principal pp = event.getPeerPrincipal();
- Principal ses_pp = ses.getPeerPrincipal();
- assertEquals("Incorrect value of peer principal",
- pp, ses_pp);
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getLocalPrincipal",
+ args = {}
+ )
+ public final void test_getLocalPrincipal() {
+ mySSLSession session = new mySSLSession("localhost", 1080, null);
+ mySSLSocket socket = new mySSLSocket();
+ HandshakeCompletedEvent event = new HandshakeCompletedEvent(socket, session);
+ try {
+ assertNull(event.getLocalPrincipal());
+ } catch (Exception e) {
+ fail("Unexpected exception: " + e);
+ }
}
-
+
/**
- * @tests javax.net.ssl.HandshakeCompletedEvent#getSession()
+ * @tests javax.net.ssl.HandshakeCompletedEvent#getPeerCertificateChain()
*/
- @TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getSession",
- methodArgs = {}
- )
- })
- public void _test_getSession() {
- if (noFreePort || noSocket) return;
- SSLSession ses = new MySSLSession();
- HandshakeCompletedEvent event = new HandshakeCompletedEvent(soc, ses);
- SSLSession s = event.getSession();
- assertEquals("Incorrect value of session", s, ses);
- assertNull("Session value is not null",
- new HandshakeCompletedEvent(soc, null).getSession());
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getPeerCertificateChain",
+ args = {}
+ )
+ public final void test_getPeerCertificateChain() {
+ ByteArrayInputStream bis = new ByteArrayInputStream(certificate.getBytes());
+ mySSLSession session = new mySSLSession(null);
+ mySSLSocket socket = new mySSLSocket();
+ HandshakeCompletedEvent event = new HandshakeCompletedEvent(socket, session);
+ try {
+ X509Certificate[] res = event.getPeerCertificateChain();
+ fail("SSLPeerUnverifiedException wasn't thrown");
+ } catch (SSLPeerUnverifiedException spue) {
+ //expected
+ }
+
+ try {
+ X509Certificate xc = X509Certificate.getInstance(bis);
+ X509Certificate[] xcs = {xc};
+ session = new mySSLSession(xcs);
+ event = new HandshakeCompletedEvent(socket, session);
+ } catch (Exception e) {
+ fail(e + " was thrown for configuration");
+ }
+ try {
+ X509Certificate[] res = event.getPeerCertificateChain();
+ assertEquals(res.length, 1);
+ } catch (Exception e) {
+ fail("Unexpected exception: " + e);
+ }
}
-
+
/**
- * @tests javax.net.ssl.HandshakeCompletedEvent#getSocket()
+ * @tests javax.net.ssl.HandshakeCompletedEvent#getPeerCertificates()
*/
- @TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getSocket",
- methodArgs = {}
- )
- })
- public void _test_getSocket() {
- if (noFreePort || noSocket) return;
- SSLSession ses = new MySSLSession();
- HandshakeCompletedEvent event = new HandshakeCompletedEvent(soc, ses);
- SSLSocket socket = event.getSocket();
- assertEquals("Incorrect value of socket", socket, soc);
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getPeerCertificates",
+ args = {}
+ )
+ public final void test_getPeerCertificates() {
+ mySSLSession session = new mySSLSession("localhost", 1080, null);
+ mySSLSocket socket = new mySSLSocket();
+ HandshakeCompletedEvent event = new HandshakeCompletedEvent(socket, session);
+ try {
+ Certificate[] res = event.getPeerCertificates();
+ fail("SSLPeerUnverifiedException wasn't thrown");
+ } catch (SSLPeerUnverifiedException spue) {
+ //expected
+ }
+
+ session = new mySSLSession(null);
+ event = new HandshakeCompletedEvent(socket, session);
+ try {
+ Certificate[] res = event.getPeerCertificates();
+ assertEquals(res.length, 3);
+ } catch (Exception e) {
+ fail("Unexpected exception: " + e);
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.HandshakeCompletedEvent#getPeerPrincipal()
+ */
+ @TestTargetNew(
+ level = TestLevel.SUFFICIENT,
+ notes = "",
+ method = "getPeerPrincipal",
+ args = {}
+ )
+ public final void test_getPeerPrincipal() {
+ mySSLSession session = new mySSLSession("localhost", 1080, null);
+ mySSLSocket socket = new mySSLSocket();
+ HandshakeCompletedEvent event = new HandshakeCompletedEvent(socket, session);
+ try {
+ assertNull(event.getPeerPrincipal());
+ } catch (Exception e) {
+ fail("Unexpected exception: " + e);
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.HandshakeCompletedEvent#getSession()
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getSession",
+ args = {}
+ )
+ public final void test_getSession() {
+ mySSLSession session = new mySSLSession("localhost", 1080, null);
+ mySSLSocket socket = new mySSLSocket();
+ HandshakeCompletedEvent event = new HandshakeCompletedEvent(socket, session);
+ try {
+ SSLSession ss = event.getSession();
+ assertNotNull(ss);
+ assertEquals(session, ss);
+ } catch (Exception e) {
+ fail("Unexpected exception: " + e);
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.HandshakeCompletedEvent#getSocket()
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getSocket",
+ args = {}
+ )
+ public final void test_getSocket() {
+ mySSLSession session = new mySSLSession("localhost", 1080, null);
+ mySSLSocket socket = new mySSLSocket();
+ HandshakeCompletedEvent event = new HandshakeCompletedEvent(socket, session);
+ try {
+ SSLSocket ss = event.getSocket();
+ assertNotNull(ss);
+ assertEquals(socket, ss);
+ } catch (Exception e) {
+ fail("Unexpected exception: " + e);
+ }
}
}
diff --git a/x-net/src/test/java/tests/api/javax/net/ssl/HandshakeCompletedListenerTest.java b/x-net/src/test/java/tests/api/javax/net/ssl/HandshakeCompletedListenerTest.java
new file mode 100644
index 0000000..83d63e3
--- /dev/null
+++ b/x-net/src/test/java/tests/api/javax/net/ssl/HandshakeCompletedListenerTest.java
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+package tests.api.javax.net.ssl;
+
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetNew;
+
+import javax.net.ssl.HandshakeCompletedEvent;
+import javax.net.ssl.HandshakeCompletedListener;
+
+import junit.framework.TestCase;
+
+import org.apache.harmony.xnet.tests.support.mySSLSession;
+import org.apache.harmony.xnet.tests.support.mySSLSocket;
+
+
+/**
+ * Tests for <code>HandshakeCompletedListener</code> class constructors and methods.
+ *
+ */
+@TestTargetClass(HandshakeCompletedListener.class)
+public class HandshakeCompletedListenerTest extends TestCase {
+
+ class myHandshakeCompletedListener implements HandshakeCompletedListener {
+
+ private boolean completeDone;
+
+ myHandshakeCompletedListener() {
+ completeDone = false;
+ }
+
+ public void handshakeCompleted(HandshakeCompletedEvent event) {
+ if (event != null) completeDone = true;
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.HandshakeCompletedListener#handshakeCompleted(HandshakeCompletedEvent event)
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "handshakeCompleted",
+ args = {HandshakeCompletedEvent.class}
+ )
+ public final void test_handshakeCompleted() {
+ mySSLSession session = new mySSLSession("localhost", 1080, null);
+ mySSLSocket socket = new mySSLSocket();
+ HandshakeCompletedEvent event = new HandshakeCompletedEvent(socket, session);
+ myHandshakeCompletedListener hcl = new myHandshakeCompletedListener();
+ try {
+ hcl.handshakeCompleted(event);
+ } catch (Exception e) {
+ fail("Unexpected exception: " + e);
+ }
+ }
+
+}
diff --git a/x-net/src/test/java/tests/api/javax/net/ssl/HostnameVerifierTest.java b/x-net/src/test/java/tests/api/javax/net/ssl/HostnameVerifierTest.java
new file mode 100644
index 0000000..b9a7487
--- /dev/null
+++ b/x-net/src/test/java/tests/api/javax/net/ssl/HostnameVerifierTest.java
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+package tests.api.javax.net.ssl;
+
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetNew;
+
+import javax.net.ssl.SSLSession;
+import javax.net.ssl.HostnameVerifier;
+
+import junit.framework.TestCase;
+
+import org.apache.harmony.xnet.tests.support.mySSLSession;
+
+
+/**
+ * Tests for <code>HostnameVerifier</code> class constructors and methods.
+ *
+ */
+@TestTargetClass(HostnameVerifier.class)
+public class HostnameVerifierTest extends TestCase {
+
+ class myHostnameVerifier implements HostnameVerifier {
+
+ myHostnameVerifier() {
+ }
+
+ public boolean verify(String hostname, SSLSession session) {
+ if (hostname == session.getPeerHost()) {
+ return true;
+ } else return false;
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.HostnameVerifier#verify(String hostname, SSLSession session)
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "verify",
+ args = {String.class, SSLSession.class}
+ )
+ public final void test_verify() {
+ mySSLSession session = new mySSLSession("localhost", 1080, null);
+ myHostnameVerifier hv = new myHostnameVerifier();
+ try {
+ assertFalse(hv.verify("hostname", session));
+ assertTrue(hv.verify("localhost", session));
+ } catch (Exception e) {
+ fail("Unexpected exception: " + e);
+ }
+ }
+}
diff --git a/x-net/src/test/java/tests/api/javax/net/ssl/HttpsURLConnectionTest.java b/x-net/src/test/java/tests/api/javax/net/ssl/HttpsURLConnectionTest.java
index 83953a2..58177d7 100644
--- a/x-net/src/test/java/tests/api/javax/net/ssl/HttpsURLConnectionTest.java
+++ b/x-net/src/test/java/tests/api/javax/net/ssl/HttpsURLConnectionTest.java
@@ -19,12 +19,10 @@
package tests.api.javax.net.ssl;
import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestInfo;
import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTarget;
+import dalvik.annotation.TestTargetNew;
import java.io.ByteArrayInputStream;
-import java.io.IOException;
import java.net.URL;
import java.security.Principal;
import java.security.cert.Certificate;
@@ -34,9 +32,11 @@
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLPeerUnverifiedException;
+import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocketFactory;
import org.apache.harmony.security.tests.support.cert.TestUtils;
+import org.apache.harmony.xnet.tests.support.SSLSocketFactoryImpl;
import junit.framework.TestCase;
@@ -52,40 +52,103 @@
/**
* @tests javax.net.ssl.HttpsURLConnection#HttpsURLConnection(java_net_URL)
*/
- @TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "HttpsURLConnection",
- methodArgs = {URL.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "HttpsURLConnection",
+ args = {java.net.URL.class}
+ )
public final void test_Constructor() {
try {
- new MyHttpsURLConnection(new URL("https://www.fortify.net"));
+ MyHttpsURLConnection huc = new MyHttpsURLConnection(new URL("https://www.fortify.net/"));
+ assertNotNull(huc);
+ assertTrue(huc instanceof HttpsURLConnection);
+ } catch (Exception e) {
+ fail("Unexpected exception: " + e.toString());
+ }
+ try {
+ MyHttpsURLConnection huc = new MyHttpsURLConnection(null);
+ assertNotNull(huc);
} catch (Exception e) {
fail("Unexpected exception " + e.toString());
}
+ }
+
+ /**
+ * @tests javax.net.ssl.HttpsURLConnection#getCipherSuite()
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getCipherSuite",
+ args = {}
+ )
+ public final void test_getCipherSuite() {
try {
- new MyHttpsURLConnection(null);
+ URL url = new URL("https://localhost:55555");
+ HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
+ try {
+ connection.getCipherSuite();
+ fail("IllegalStateException wasn't thrown");
+ } catch (IllegalStateException ise) {
+ //expected
+ }
} catch (Exception e) {
- fail("Unexpected exception " + e.toString());
+ fail("Unexpected exception " + e + " for exception case");
+ }
+
+ try {
+ HttpsURLConnection con = new MyHttpsURLConnection(new URL("https://www.fortify.net/"));
+ assertEquals("CipherSuite", con.getCipherSuite());
+ } catch (Exception e) {
+ fail("Unexpected exception " + e);
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.HttpsURLConnection#getLocalCertificates()
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getLocalCertificates",
+ args = {}
+ )
+ public final void test_getLocalCertificates() {
+ try {
+ URL url = new URL("https://localhost:55555");
+ HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
+ try {
+ connection.getLocalCertificates();
+ fail("IllegalStateException wasn't thrown");
+ } catch (IllegalStateException ise) {
+ //expected
+ }
+ } catch (Exception e) {
+ fail("Unexpected exception " + e + " for exception case");
+ }
+
+ try {
+ HttpsURLConnection con = new MyHttpsURLConnection(new URL("https://www.fortify.net/"), "X.508");
+ assertNull(con.getLocalCertificates());
+ con = new MyHttpsURLConnection(new URL("https://www.fortify.net/"), "X.509");
+ Certificate[] cert = con.getLocalCertificates();
+ assertNotNull(cert);
+ assertEquals(1, cert.length);
+ } catch (Exception e) {
+ fail("Unexpected exception " + e);
}
}
/**
* @tests javax.net.ssl.HttpsURLConnection#getDefaultHostnameVerifier()
*/
- @TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getDefaultHostnameVerifier",
- methodArgs = {}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getDefaultHostnameVerifier",
+ args = {}
+ )
public final void test_getDefaultHostnameVerifier() {
HostnameVerifier verifyer =
HttpsURLConnection.getDefaultHostnameVerifier();
@@ -95,15 +158,12 @@
/**
* @tests javax.net.ssl.HttpsURLConnection#getDefaultSSLSocketFactory()
*/
- @TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getDefaultSSLSocketFactory",
- methodArgs = {}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getDefaultSSLSocketFactory",
+ args = {}
+ )
public final void test_getDefaultSSLSocketFactory() {
SSLSocketFactory sf = HttpsURLConnection.getDefaultSSLSocketFactory();
if (!sf.equals(SSLSocketFactory.getDefault())) {
@@ -114,19 +174,16 @@
/**
* @tests javax.net.ssl.HttpsURLConnection#getHostnameVerifier()
*/
- @TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getHostnameVerifier",
- methodArgs = {}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getHostnameVerifier",
+ args = {}
+ )
public final void test_getHostnameVerifier()
throws Exception {
HttpsURLConnection con = new MyHttpsURLConnection(
- new URL("https://www.fortify.net"));
+ new URL("https://www.fortify.net/"));
HostnameVerifier verifyer = con.getHostnameVerifier();
assertNotNull("Hostname verifyer is null", verifyer);
assertEquals("Incorrect value of hostname verirfyer",
@@ -136,55 +193,125 @@
/**
* @tests javax.net.ssl.HttpsURLConnection#getLocalPrincipal()
*/
- @TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "IllegalStateException checking missed",
- targets = {
- @TestTarget(
- methodName = "getLocalPrincipal",
- methodArgs = {}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getLocalPrincipal",
+ args = {}
+ )
public final void test_getLocalPrincipal() {
- HttpsURLConnection con = new MyHttpsURLConnection(null);
- assertNotNull("Local principal is null", con.getLocalPrincipal());
+ try {
+ URL url = new URL("https://localhost:55555");
+ HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
+ try {
+ connection.getLocalPrincipal();
+ fail("IllegalStateException wasn't thrown");
+ } catch (IllegalStateException ise) {
+ //expected
+ }
+ } catch (Exception e) {
+ fail("Unexpected exception " + e + " for exception case");
+ }
+
+ try {
+ HttpsURLConnection con = new MyHttpsURLConnection(new URL("https://www.fortify.net/"), "X.508");
+ assertNull(con.getLocalPrincipal());
+ con = new MyHttpsURLConnection(new URL("https://www.fortify.net/"), "X.509");
+ assertNotNull("Local principal is null", con.getLocalPrincipal());
+ } catch (Exception e) {
+ fail("Unexpected exception " + e);
+ }
}
/**
* @tests javax.net.ssl.HttpsURLConnection#getPeerPrincipal()
*/
- @TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "IllegalStateException checking missed",
- targets = {
- @TestTarget(
- methodName = "getPeerPrincipal",
- methodArgs = {}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getPeerPrincipal",
+ args = {}
+ )
public final void test_getPeerPrincipal() throws Exception {
- HttpsURLConnection con = new MyHttpsURLConnection(
- new URL("https://www.fortify.net"));
+ try {
+ URL url = new URL("https://localhost:55555");
+ HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
+ try {
+ connection.getPeerPrincipal();
+ fail("IllegalStateException wasn't thrown");
+ } catch (IllegalStateException ise) {
+ //expected
+ }
+ } catch (Exception e) {
+ fail("Unexpected exception " + e + " for exception case");
+ }
+ HttpsURLConnection con = new MyHttpsURLConnection(new URL("https://www.fortify.net/"), "X.508");
try {
Principal p = con.getPeerPrincipal();
- assertNotNull("Principal is null", p);
+ fail("SSLPeerUnverifiedException wasn't thrown");
} catch (SSLPeerUnverifiedException e) {
- fail("Unexpected SSLPeerUnverifiedException " + e.toString());
+ //expected
+ }
+
+ con = new MyHttpsURLConnection(new URL("https://www.fortify.net/"), "X.509");
+ try {
+ Principal p = con.getPeerPrincipal();
+ assertNotNull(p);
+ } catch (Exception e) {
+ fail("Unexpected exception " + e);
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.HttpsURLConnection#getServerCertificates()
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getServerCertificates",
+ args = {}
+ )
+ public final void test_getServerCertificates() throws Exception {
+ try {
+ URL url = new URL("https://localhost:55555");
+ HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
+ try {
+ connection.getServerCertificates();
+ fail("IllegalStateException wasn't thrown");
+ } catch (IllegalStateException ise) {
+ //expected
+ }
+ } catch (Exception e) {
+ fail("Unexpected exception " + e + " for exception case");
+ }
+
+ HttpsURLConnection con = new MyHttpsURLConnection(new URL("https://www.fortify.net/"), "X.508");
+ try {
+ Certificate[] cert = con.getServerCertificates();
+ fail("SSLPeerUnverifiedException wasn't thrown");
+ } catch (SSLPeerUnverifiedException e) {
+ //expected
+ }
+
+ con = new MyHttpsURLConnection(new URL("https://www.fortify.net/"), "X.509");
+ try {
+ Certificate[] cert = con.getServerCertificates();
+ assertNotNull(cert);
+ assertEquals(1, cert.length);
+ } catch (Exception e) {
+ fail("Unexpected exception " + e);
}
}
/**
* @tests javax.net.ssl.HttpsURLConnection#getSSLSocketFactory()
*/
- @TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getSSLSocketFactory",
- methodArgs = {}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getSSLSocketFactory",
+ args = {}
+ )
public final void test_getSSLSocketFactory() {
HttpsURLConnection con = new MyHttpsURLConnection(null);
SSLSocketFactory sf = con.getSSLSocketFactory();
@@ -196,15 +323,12 @@
/**
* @tests javax.net.ssl.HttpsURLConnection#setDefaultHostnameVerifier()
*/
- @TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "Not null parameter checking missed",
- targets = {
- @TestTarget(
- methodName = "setDefaultHostnameVerifier",
- methodArgs = {HostnameVerifier.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "setDefaultHostnameVerifier",
+ args = {javax.net.ssl.HostnameVerifier.class}
+ )
public final void test_setDefaultHostnameVerifier() {
try {
HttpsURLConnection.setDefaultHostnameVerifier(null);
@@ -212,20 +336,23 @@
} catch (IllegalArgumentException e) {
// expected
}
+ try {
+ myHostnameVerifier hnv = new myHostnameVerifier();
+ HttpsURLConnection.setDefaultHostnameVerifier(hnv);
+ } catch (Exception e) {
+ fail("Unexpected exception " + e);
+ }
}
/**
* @tests javax.net.ssl.HttpsURLConnection#setHostnameVerifier()
*/
- @TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "Not null parameter checking missed",
- targets = {
- @TestTarget(
- methodName = "setHostnameVerifier",
- methodArgs = {HostnameVerifier.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "setHostnameVerifier",
+ args = {javax.net.ssl.HostnameVerifier.class}
+ )
public final void test_setHostnameVerifier() {
HttpsURLConnection con = new MyHttpsURLConnection(null);
try {
@@ -233,40 +360,46 @@
fail("No expected IllegalArgumentException");
} catch (IllegalArgumentException e) {
}
+ try {
+ myHostnameVerifier hnv = new myHostnameVerifier();
+ con.setHostnameVerifier(hnv);
+ } catch (Exception e) {
+ fail("Unexpected exception " + e);
+ }
}
/**
* @tests javax.net.ssl.HttpsURLConnection#setDefaultSSLSocketFactory()
*/
- @TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "Not null checking missed",
- targets = {
- @TestTarget(
- methodName = "setDefaultSSLSocketFactory",
- methodArgs = {SSLSocketFactory.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "setDefaultSSLSocketFactory",
+ args = {javax.net.ssl.SSLSocketFactory.class}
+ )
public final void test_setDefaultSSLSocketFactory() {
try {
HttpsURLConnection.setDefaultSSLSocketFactory(null);
fail("No expected IllegalArgumentException");
} catch (IllegalArgumentException e) {
}
+ try {
+ SSLSocketFactoryImpl ssf = new SSLSocketFactoryImpl();
+ HttpsURLConnection.setDefaultSSLSocketFactory(ssf);
+ } catch (Exception e) {
+ fail("Unexpected exception " + e);
+ }
}
/**
* @tests javax.net.ssl.HttpsURLConnection#setSSLSocketFactory()
*/
- @TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "Not null checking missed",
- targets = {
- @TestTarget(
- methodName = "setSSLSocketFactory",
- methodArgs = {SSLSocketFactory.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "setSSLSocketFactory",
+ args = {javax.net.ssl.SSLSocketFactory.class}
+ )
public final void test_setSSLSocketFactory() {
HttpsURLConnection con = new MyHttpsURLConnection(null);
try {
@@ -274,20 +407,33 @@
fail("No expected IllegalArgumentException");
} catch (IllegalArgumentException e) {
}
+ try {
+ SSLSocketFactoryImpl ssf = new SSLSocketFactoryImpl();
+ con.setSSLSocketFactory(ssf);
+ } catch (Exception e) {
+ fail("Unexpected exception " + e);
+ }
}
}
-class MyHttpsURLConnection extends HttpsURLConnection {
-
+class MyHttpsURLConnection extends javax.net.ssl.HttpsURLConnection {
+
+ private String typeDone;
+
public MyHttpsURLConnection(URL url) {
super(url);
}
+
+ public MyHttpsURLConnection(URL url, String type) {
+ super(url);
+ typeDone = type;
+ }
/*
* @see javax.net.ssl.HttpsURLConnection#getCipherSuite()
*/
public String getCipherSuite() {
- return null;
+ return "CipherSuite";
}
/*
@@ -296,7 +442,7 @@
public Certificate[] getLocalCertificates() {
Certificate cert = null;
try {
- CertificateFactory cf = CertificateFactory.getInstance("X.509");
+ CertificateFactory cf = CertificateFactory.getInstance(typeDone);
byte[] barr = TestUtils.getX509Certificate_v1();
ByteArrayInputStream bis = new ByteArrayInputStream(barr);
cert = cf.generateCertificate(bis);
@@ -305,20 +451,19 @@
}
return cert == null ? null : new Certificate[]{cert};
}
-
+
/*
* @see javax.net.ssl.HttpsURLConnection#getServerCertificates()
*/
- public Certificate[] getServerCertificates()
- throws SSLPeerUnverifiedException {
+ public Certificate[] getServerCertificates() throws SSLPeerUnverifiedException {
Certificate cert = null;
try {
- CertificateFactory cf = CertificateFactory.getInstance("X.509");
+ CertificateFactory cf = CertificateFactory.getInstance(typeDone);
byte[] barr = TestUtils.getX509Certificate_v3();
ByteArrayInputStream bis = new ByteArrayInputStream(barr);
cert = cf.generateCertificate(bis);
} catch (CertificateException se) {
- cert = null;
+ throw new SSLPeerUnverifiedException("No server's end-entity certificate");
}
return cert == null ? null : new Certificate[]{cert};
}
@@ -336,11 +481,20 @@
return false;
}
- /*
- * @see java.net.URLConnection#connect()
- */
- public void connect() throws IOException {
+ public void connect() {
}
}
+class myHostnameVerifier implements HostnameVerifier {
+
+ myHostnameVerifier() {
+ }
+
+ public boolean verify(String hostname, SSLSession session) {
+ if (hostname == session.getPeerHost()) {
+ return true;
+ } else return false;
+ }
+}
+
diff --git a/x-net/src/test/java/tests/api/javax/net/ssl/KeyManagerFactory1Test.java b/x-net/src/test/java/tests/api/javax/net/ssl/KeyManagerFactory1Test.java
index 62d1c91..2777a4a 100644
--- a/x-net/src/test/java/tests/api/javax/net/ssl/KeyManagerFactory1Test.java
+++ b/x-net/src/test/java/tests/api/javax/net/ssl/KeyManagerFactory1Test.java
@@ -18,13 +18,11 @@
package tests.api.javax.net.ssl;
import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestInfo;
import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTarget;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.KnownFailure;
-import java.io.FileInputStream;
import java.io.IOException;
-import java.io.InputStream;
import java.security.InvalidAlgorithmParameterException;
import java.security.KeyStore;
import java.security.KeyStoreException;
@@ -35,6 +33,7 @@
import java.security.UnrecoverableKeyException;
import java.security.cert.CertificateException;
+import javax.net.ssl.KeyStoreBuilderParameters;
import javax.net.ssl.ManagerFactoryParameters;
import javax.net.ssl.KeyManager;
import javax.net.ssl.KeyManagerFactory;
@@ -42,6 +41,7 @@
import org.apache.harmony.security.tests.support.SpiEngUtils;
import org.apache.harmony.xnet.tests.support.MyKeyManagerFactorySpi;
+
import junit.framework.TestCase;
/**
@@ -103,15 +103,12 @@
/**
* @tests avax.net.ssl.KeyManagerFactory#getAlgorithm()
*/
- @TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getAlgorithm",
- methodArgs = {}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getAlgorithm",
+ args = {}
+ )
public void test_getAlgorithm()
throws NoSuchAlgorithmException, NoSuchProviderException {
if (!DEFSupported) fail(NotSupportedMsg);
@@ -134,15 +131,12 @@
* Test for <code>getDefaultAlgorithm()</code> method
* Assertion: returns value which is specifoed in security property
*/
- @TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getDefaultAlgorithm",
- methodArgs = {}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getDefaultAlgorithm",
+ args = {}
+ )
public void test_getDefaultAlgorithm() {
if (!DEFSupported) {
fail(NotSupportedMsg);
@@ -172,15 +166,12 @@
* returns security property "ssl.KeyManagerFactory.algorithm";
* returns instance of KeyManagerFactory
*/
- @TestInfo(
- level = TestLevel.PARTIAL_OK,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getInstance",
- methodArgs = {String.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "getInstance",
+ args = {java.lang.String.class}
+ )
public void test_getInstanceLjava_lang_String01() throws NoSuchAlgorithmException {
if (!DEFSupported) {
fail(NotSupportedMsg);
@@ -202,15 +193,12 @@
* throws NullPointerException when algorithm is null;
* throws NoSuchAlgorithmException when algorithm is not correct;
*/
- @TestInfo(
- level = TestLevel.PARTIAL_OK,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getInstance",
- methodArgs = {String.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "getInstance",
+ args = {java.lang.String.class}
+ )
public void test_getInstanceLjava_lang_String02() {
try {
KeyManagerFactory.getInstance(null);
@@ -233,15 +221,12 @@
* method
* Assertion: throws IllegalArgumentException when provider is null or empty
*/
- @TestInfo(
- level = TestLevel.PARTIAL_OK,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getInstance",
- methodArgs = {String.class, String.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "getInstance",
+ args = {java.lang.String.class, java.lang.String.class}
+ )
public void test_getInstanceLjava_lang_StringLjava_lang_String01() throws NoSuchProviderException,
NoSuchAlgorithmException {
if (!DEFSupported) {
@@ -270,15 +255,12 @@
* throws NullPointerException when algorithm is null;
* throws NoSuchAlgorithmException when algorithm is not correct;
*/
- @TestInfo(
- level = TestLevel.PARTIAL_OK,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getInstance",
- methodArgs = {String.class, String.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "getInstance",
+ args = {java.lang.String.class, java.lang.String.class}
+ )
public void test_getInstanceLjava_lang_StringLjava_lang_String02() throws NoSuchProviderException {
if (!DEFSupported) {
fail(NotSupportedMsg);
@@ -307,15 +289,12 @@
* Assertion: throws NoSuchProviderException when provider has
* invalid value
*/
- @TestInfo(
- level = TestLevel.PARTIAL_OK,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getInstance",
- methodArgs = {String.class, String.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "getInstance",
+ args = {java.lang.String.class, java.lang.String.class}
+ )
public void test_getInstanceLjava_lang_StringLjava_lang_String03()
throws NoSuchAlgorithmException {
if (!DEFSupported) {
@@ -340,15 +319,12 @@
* Test for <code>getInstance(String algorithm, String provider)</code>
* method Assertion: returns instance of KeyManagerFactory
*/
- @TestInfo(
- level = TestLevel.PARTIAL_OK,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getInstance",
- methodArgs = {String.class, String.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "getInstance",
+ args = {java.lang.String.class, java.lang.String.class}
+ )
public void test_getInstanceLjava_lang_StringLjava_lang_String04()
throws NoSuchProviderException,
NoSuchAlgorithmException {
@@ -374,15 +350,12 @@
* method
* Assertion: throws IllegalArgumentException when provider is null
*/
- @TestInfo(
- level = TestLevel.PARTIAL_OK,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getInstance",
- methodArgs = {String.class, Provider.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "getInstance",
+ args = {java.lang.String.class, java.security.Provider.class}
+ )
public void test_getInstanceLjava_lang_StringLjava_security_Provider01()
throws NoSuchAlgorithmException {
if (!DEFSupported) {
@@ -406,15 +379,12 @@
* throws NullPointerException when algorithm is null;
* throws NoSuchAlgorithmException when algorithm is not correct;
*/
- @TestInfo(
- level = TestLevel.PARTIAL_OK,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getInstance",
- methodArgs = {String.class, Provider.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "getInstance",
+ args = {java.lang.String.class, java.security.Provider.class}
+ )
public void test_getInstanceLjava_lang_StringLjava_security_Provider02() {
if (!DEFSupported) {
fail(NotSupportedMsg);
@@ -441,15 +411,12 @@
* method
* Assertion: returns instance of KeyManagerFactory
*/
- @TestInfo(
- level = TestLevel.PARTIAL_OK,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getInstance",
- methodArgs = {String.class, Provider.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "getInstance",
+ args = {java.lang.String.class, java.security.Provider.class}
+ )
public void test_getInstanceLjava_lang_StringLjava_security_Provider03()
throws NoSuchAlgorithmException,
IllegalArgumentException {
@@ -471,15 +438,12 @@
* Test for <code>KeyManagerFactory</code> constructor
* Assertion: returns KeyManagerFactory object
*/
- @TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "KeyManagerFactory",
- methodArgs = {KeyManagerFactorySpi.class, Provider.class, String.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "KeyManagerFactory",
+ args = {javax.net.ssl.KeyManagerFactorySpi.class, java.security.Provider.class, java.lang.String.class}
+ )
public void test_Constructor() throws NoSuchAlgorithmException {
if (!DEFSupported) {
fail(NotSupportedMsg);
@@ -517,26 +481,18 @@
* @throws CertificateException
* @throws UnrecoverableKeyException
*/
- @TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getKeyManagers",
- methodArgs = {}
- )
- })
- public void _test_getKeyManagers()
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getKeyManagers",
+ args = {}
+ )
+ public void test_getKeyManagers()
throws Exception {
if (!DEFSupported) fail(NotSupportedMsg);
KeyManagerFactory kmf = KeyManagerFactory.getInstance(defaultAlgorithm);
- KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
- InputStream v1in = new FileInputStream(ClassLoader
- .getSystemClassLoader().getResource("keystore.jks").getFile());
char[] pass = "password".toCharArray();
- keyStore.load(v1in, pass);
- v1in.close();
- kmf.init(keyStore, pass);
+ kmf.init(null, pass);
assertNotNull("Key manager array is null", kmf.getKeyManagers());
assertEquals("Incorrect size of array",
1, kmf.getKeyManagers().length);
@@ -545,15 +501,12 @@
/**
* @tests avax.net.ssl.KeyManagerFactory#getProvider()
*/
- @TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getProvider",
- methodArgs = {}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getProvider",
+ args = {}
+ )
public void test_getProvider()
throws Exception {
if (!DEFSupported) fail(NotSupportedMsg);
@@ -577,15 +530,12 @@
* <code>getKeyManagers()</code>
* Assertion: returns not empty KeyManager array
*/
- @TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "KeyStoreException, NoSuchAlgorithmException, UnrecoverableKeyException checking missed",
- targets = {
- @TestTarget(
- methodName = "init",
- methodArgs = {KeyStore.class, char[].class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.SUFFICIENT,
+ notes = "KeyStoreException, NoSuchAlgorithmException, UnrecoverableKeyException checking missed",
+ method = "init",
+ args = {java.security.KeyStore.class, char[].class}
+ )
public void test_initLjava_security_KeyStore$C()
throws NoSuchAlgorithmException,
KeyStoreException, UnrecoverableKeyException {
@@ -625,6 +575,7 @@
assertTrue("Length of result KeyManager array should not be 0",
(km.length > 0));
}
+
}
/**
@@ -632,17 +583,18 @@
* Assertion:
* throws InvalidAlgorithmParameterException when params is null
*/
- @TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "Exception case was checked only",
- targets = {
- @TestTarget(
- methodName = "init",
- methodArgs = {ManagerFactoryParameters.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "functionality is not implemented in org.apache.harmony.xnet.provider.jsse.engineInit(ManagerFactoryParameters)",
+ method = "init",
+ args = {javax.net.ssl.ManagerFactoryParameters.class}
+ )
+ @KnownFailure("ManagerFactoryParameters object is not supported " +
+ "and InvalidAlgorithmParameterException was thrown." +
+ "RI: functionality is not implemented, just exception.")
public void test_initLjavax_net_ssl_ManagerFactoryParameters()
throws NoSuchAlgorithmException {
+
if (!DEFSupported) {
fail(NotSupportedMsg);
return;
@@ -657,6 +609,19 @@
} catch (InvalidAlgorithmParameterException e) {
}
}
+
+ KeyStore.ProtectionParameter pp = new ProtectionParameterImpl();
+ KeyStore.Builder bld = KeyStore.Builder.newInstance("testType", null, pp);
+ assertNotNull("Null object KeyStore.Builder", bld);
+
+ try {
+ KeyManagerFactory kmf = KeyManagerFactory.getInstance(defaultAlgorithm);
+ KeyStoreBuilderParameters ksp = new KeyStoreBuilderParameters(bld);
+ assertNotNull(ksp.getParameters());
+ kmf.init(ksp);
+ fail("InvalidAlgorithmParameterException must be thrown");
+ } catch (InvalidAlgorithmParameterException e) {
+ }
}
}
@@ -670,3 +635,7 @@
super(spi, prov, alg);
}
}
+
+class ProtectionParameterImpl implements KeyStore.ProtectionParameter {
+ ProtectionParameterImpl(){}
+}
\ No newline at end of file
diff --git a/x-net/src/test/java/tests/api/javax/net/ssl/KeyManagerFactory2Test.java b/x-net/src/test/java/tests/api/javax/net/ssl/KeyManagerFactory2Test.java
index f186923..104b30b 100644
--- a/x-net/src/test/java/tests/api/javax/net/ssl/KeyManagerFactory2Test.java
+++ b/x-net/src/test/java/tests/api/javax/net/ssl/KeyManagerFactory2Test.java
@@ -18,9 +18,9 @@
package tests.api.javax.net.ssl;
import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestInfo;
+import dalvik.annotation.TestTargets;
import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTarget;
+import dalvik.annotation.TestTargetNew;
import java.security.InvalidAlgorithmParameterException;
import java.security.KeyStore;
@@ -130,15 +130,12 @@
* throws NoSuchAlgorithmException when algorithm is not correct;
* returns KeyManagerFactory object
*/
- @TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getInstance",
- methodArgs = {String.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getInstance",
+ args = {java.lang.String.class}
+ )
public void test_getInstanceLjava_lang_String() throws Exception {
try {
KeyManagerFactory.getInstance(null);
@@ -176,15 +173,12 @@
* throws NoSuchProviderException when provider is available;
* returns KeyManagerFactory object
*/
- @TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getInstance",
- methodArgs = {String.class, String.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getInstance",
+ args = {java.lang.String.class, java.lang.String.class}
+ )
public void test_getInstanceLjava_lang_StringLjava_lang_String()
throws Exception
{
@@ -253,15 +247,12 @@
* throws IllegalArgumentException when provider is null;
* returns KeyManagerFactory object
*/
- @TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getInstance",
- methodArgs = {String.class, Provider.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getInstance",
+ args = {java.lang.String.class, java.security.Provider.class}
+ )
public void test_getInstanceLjava_lang_StringLjava_security_Provider()
throws Exception
{
diff --git a/x-net/src/test/java/tests/api/javax/net/ssl/KeyManagerFactorySpiTest.java b/x-net/src/test/java/tests/api/javax/net/ssl/KeyManagerFactorySpiTest.java
index f6a2e96..2319769 100644
--- a/x-net/src/test/java/tests/api/javax/net/ssl/KeyManagerFactorySpiTest.java
+++ b/x-net/src/test/java/tests/api/javax/net/ssl/KeyManagerFactorySpiTest.java
@@ -5,7 +5,7 @@
* 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
+ * 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,
@@ -13,77 +13,168 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package tests.api.javax.net.ssl;
import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestInfo;
import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTarget;
+import dalvik.annotation.TestTargetNew;
import java.security.InvalidAlgorithmParameterException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.UnrecoverableKeyException;
-
import javax.net.ssl.KeyManager;
import javax.net.ssl.KeyManagerFactorySpi;
import javax.net.ssl.ManagerFactoryParameters;
import junit.framework.TestCase;
+import org.apache.harmony.xnet.tests.support.KeyManagerFactorySpiImpl;
+
@TestTargetClass(KeyManagerFactorySpi.class)
public class KeyManagerFactorySpiTest extends TestCase {
- private class MockKeyManagerFactorySpi extends KeyManagerFactorySpi {
- public MockKeyManagerFactorySpi() {
- super();
- }
-
- /**
- * @see javax.net.ssl.KeyManagerFactorySpi#engineGetKeyManagers()
- */
- @Override
- protected KeyManager[] engineGetKeyManagers() {
- // it is a fake
- return null;
- }
-
- /**
- * @see javax.net.ssl.KeyManagerFactorySpi#engineInit(javax.net.ssl.ManagerFactoryParameters)
- */
- @Override
- protected void engineInit(ManagerFactoryParameters arg0) throws InvalidAlgorithmParameterException {
- // it is a fake
- }
-
- /**
- * @see javax.net.ssl.KeyManagerFactorySpi#engineInit(java.security.KeyStore, char[])
- */
- @Override
- protected void engineInit(KeyStore arg0, char[] arg1) throws KeyStoreException, NoSuchAlgorithmException, UnrecoverableKeyException {
- // it is a fake
- }
- }
-
/**
* @tests javax.net.ssl.KeyManagerFactorySpi#KeyManagerFactorySpi()
*/
- @TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "KeyManagerFactorySpi",
- methodArgs = {}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "KeyManagerFactorySpi",
+ args = {}
+ )
public void test_Constructor() {
try {
- new MockKeyManagerFactorySpi();
+ KeyManagerFactorySpiImpl kmf = new KeyManagerFactorySpiImpl();
+ assertTrue(kmf instanceof KeyManagerFactorySpi);
} catch (Exception e) {
fail("Unexpected Exception " + e.toString());
}
}
+
+ /**
+ * @tests javax.net.ssl.KeyManagerFactorySpi#KengineInit(KeyStore ks, char[] password)
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "engineInit",
+ args = {java.security.KeyStore.class, char[].class}
+ )
+ public void test_engineInit_01() {
+ KeyManagerFactorySpiImpl kmf = new KeyManagerFactorySpiImpl();
+ KeyStore ks;
+ char[] psw = "password".toCharArray();
+
+ try {
+ kmf.engineInit(null, null);
+ fail("NoSuchAlgorithmException wasn't thrown");
+ } catch (NoSuchAlgorithmException kse) {
+ //expected
+ } catch (Exception e) {
+ fail(e + " was thrown instead of NoSuchAlgorithmException");
+ }
+
+ try {
+ kmf.engineInit(null, psw);
+ fail("KeyStoreException wasn't thrown");
+ } catch (KeyStoreException uke) {
+ //expected
+ } catch (Exception e) {
+ fail(e + " was thrown instead of KeyStoreException");
+ }
+
+ try {
+ ks = KeyStore.getInstance(KeyStore.getDefaultType());
+ kmf.engineInit(ks, null);
+ fail("UnrecoverableKeyException wasn't thrown");
+ } catch (UnrecoverableKeyException uke) {
+ //expected
+ } catch (Exception e) {
+ fail(e + " was thrown instead of UnrecoverableKeyException");
+ }
+
+ try {
+ KeyStore kst = KeyStore.getInstance(KeyStore.getDefaultType());
+ kst.load(null, null);
+ kmf.engineInit(kst, psw);
+ } catch (Exception e) {
+ fail("Unexpected exception " + e);
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.KeyManagerFactorySpi#KengineInit(ManagerFactoryParameters spec)
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "engineInit",
+ args = {javax.net.ssl.ManagerFactoryParameters.class}
+ )
+ public void test_engineInit_02() {
+ KeyManagerFactorySpiImpl kmf = new KeyManagerFactorySpiImpl();
+
+ try {
+ kmf.engineInit(null);
+ fail("InvalidAlgorithmParameterException wasn't thrown");
+ } catch (InvalidAlgorithmParameterException iape) {
+ //expected
+ } catch (Exception e) {
+ fail(e + " was thrown instead of InvalidAlgorithmParameterException");
+ }
+
+ try {
+ char[] psw = "password".toCharArray();
+ Parameters pr = new Parameters(psw);
+ kmf.engineInit(pr);
+ } catch (Exception e) {
+ fail(e + " unexpected exception was thrown");
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.KeyManagerFactorySpi#engineGetKeyManagers()
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "engineGetKeyManagers",
+ args = {}
+ )
+ public void test_engineGetKeyManagers() {
+ KeyManagerFactorySpiImpl kmf = new KeyManagerFactorySpiImpl();
+
+ try {
+ KeyManager[] km = kmf.engineGetKeyManagers();
+ fail("IllegalStateException wasn't thrown");
+ } catch (IllegalStateException ise) {
+ //expected
+ } catch (Exception e) {
+ fail(e + " was thrown instead of IllegalStateException");
+ }
+
+ try {
+ char[] psw = "password".toCharArray();
+ Parameters pr = new Parameters(psw);
+ kmf.engineInit(pr);
+ KeyManager[] km = kmf.engineGetKeyManagers();
+ assertNull("Object is not NULL", km);
+ } catch (Exception e) {
+ fail(e + " unexpected exception was thrown");
+ }
+ }
+
+ public class Parameters implements ManagerFactoryParameters {
+ private char[] passWD;
+
+ public Parameters (char[] pass) {
+ this.passWD = pass;
+ }
+ public char[] getPassword() {
+ return passWD;
+ }
+ }
+
}
diff --git a/x-net/src/test/java/tests/api/javax/net/ssl/KeyStoreBuilderParametersTest.java b/x-net/src/test/java/tests/api/javax/net/ssl/KeyStoreBuilderParametersTest.java
new file mode 100644
index 0000000..6e1af6b
--- /dev/null
+++ b/x-net/src/test/java/tests/api/javax/net/ssl/KeyStoreBuilderParametersTest.java
@@ -0,0 +1,145 @@
+/*
+ * Copyright (C) 2007 The Android Open Source Project
+ *
+ * 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.
+ */
+package tests.api.javax.net.ssl;
+
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargets;
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetNew;
+
+import javax.net.ssl.KeyManagerFactorySpi;
+import javax.net.ssl.KeyStoreBuilderParameters;
+import java.security.KeyStore;
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+@TestTargetClass(KeyStoreBuilderParameters.class)
+public class KeyStoreBuilderParametersTest extends TestCase {
+
+ /**
+ * @tests javax.net.ssl.KeyStoreBuilderParameters#KeyStoreBuilderParameters(KeyStore.Builder builder)
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "KeyStoreBuilderParameters",
+ args = {java.security.KeyStore.Builder.class}
+ )
+ public void test_Constructor01() {
+ KeyStore.Builder bld = null;
+
+ //Null parameter
+ try {
+ KeyStoreBuilderParameters ksp = new KeyStoreBuilderParameters(bld);
+ assertNotNull(ksp.getParameters());
+ } catch (NullPointerException npe) {
+ fail("NullPointerException should not be thrown");
+ }
+
+ //Not null parameter
+ KeyStore.ProtectionParameter pp = new ProtectionParameterImpl();
+ bld = KeyStore.Builder.newInstance("testType", null, pp);
+ assertNotNull("Null object KeyStore.Builder", bld);
+ try {
+ KeyStoreBuilderParameters ksp = new KeyStoreBuilderParameters(bld);
+ assertNotNull(ksp.getParameters());
+ } catch (Exception e) {
+ fail("Unexpected exception was thrown");
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.KeyStoreBuilderParameters#KeyStoreBuilderParameters(List parameters)
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "KeyStoreBuilderParameters",
+ args = {java.util.List.class}
+ )
+ public void test_Constructor02() {
+
+ //Null parameter
+ List ls = null;
+ try {
+ KeyStoreBuilderParameters ksp = new KeyStoreBuilderParameters(ls);
+ fail("NullPointerException should be thrown");
+ } catch (NullPointerException npe) {
+ //expected
+ }
+
+ //Empty parameter
+ List lsEmpty = new ArrayList();
+ try {
+ KeyStoreBuilderParameters ksp = new KeyStoreBuilderParameters(lsEmpty);
+ fail("IllegalArgumentException should be thrown");
+ } catch (IllegalArgumentException iae) {
+ //expected
+ }
+
+ //Not null parameter
+ List lsFiled = new ArrayList();;
+ lsFiled.add("Parameter1");
+ lsFiled.add("Parameter2");
+ try {
+ KeyStoreBuilderParameters ksp = new KeyStoreBuilderParameters(lsFiled);
+ assertTrue("Not instanceof KeyStoreBuilderParameters object",
+ ksp instanceof KeyStoreBuilderParameters);
+ } catch (Exception e) {
+ fail("Unexpected exception was thrown");
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.KeyStoreBuilderParameters#getParameters()
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getParameters",
+ args = {}
+ )
+ public void test_getParameters() {
+ String[] param = {"Parameter1", "Parameter2", "Parameter3"};
+ List ls = new ArrayList();
+ for (int i = 0; i < param.length; i++) {
+ ls.add(param[i]);
+ }
+ KeyStoreBuilderParameters ksp = new KeyStoreBuilderParameters(ls);
+ try {
+ List res_list = ksp.getParameters();
+ Object[] res = res_list.toArray();
+ if (res.length == param.length) {
+ for (int i = 0; i < res.length; i++) {
+ if (!param[i].equals(res[i])) {
+ fail("Parameters not equal");
+ }
+ }
+ } else {
+ fail("Incorrect number of parameters");
+ }
+ } catch (Exception e) {
+ fail("Unexpected exception was thrown");
+ }
+ }
+
+ class ProtectionParameterImpl implements KeyStore.ProtectionParameter {
+ ProtectionParameterImpl(){}
+ }
+}
+
diff --git a/x-net/src/test/java/tests/api/javax/net/ssl/SSLContext1Test.java b/x-net/src/test/java/tests/api/javax/net/ssl/SSLContext1Test.java
index be3b6d1..1315b69 100644
--- a/x-net/src/test/java/tests/api/javax/net/ssl/SSLContext1Test.java
+++ b/x-net/src/test/java/tests/api/javax/net/ssl/SSLContext1Test.java
@@ -18,9 +18,9 @@
package tests.api.javax.net.ssl;
import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestInfo;
+import dalvik.annotation.TestTargets;
import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTarget;
+import dalvik.annotation.TestTargetNew;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@@ -100,15 +100,12 @@
* Test for <code>SSLContext</code> constructor Assertion: returns
* SSLContext object
*/
- @TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "SSLContext",
- methodArgs = {SSLContextSpi.class, Provider.class, String.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "SSLContext",
+ args = {javax.net.ssl.SSLContextSpi.class, java.security.Provider.class, java.lang.String.class}
+ )
public void test_ConstructorLjavax_net_ssl_SSLContextSpiLjava_security_ProviderLjava_lang_String()
throws NoSuchAlgorithmException,
KeyManagementException {
@@ -155,15 +152,12 @@
* @throws KeyManagementException
* @tests javax.net.ssl.SSLContext#createSSLEngine()
*/
- @TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "UnsupportedOperationException checking missed",
- targets = {
- @TestTarget(
- methodName = "createSSLEngine",
- methodArgs = {}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.SUFFICIENT,
+ notes = "UnsupportedOperationException checking missed",
+ method = "createSSLEngine",
+ args = {}
+ )
public void test_createSSLEngine() throws KeyManagementException {
if (!DEFSupported) fail(NotSupportMsg);
SSLContextSpi spi = new MySSLContextSpi();
@@ -178,15 +172,12 @@
* @throws KeyManagementException
* @tests javax.net.ssl.SSLContext#createSSLEngine(java.lang.String, int)
*/
- @TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "UnsupportedOperationException checking missed",
- targets = {
- @TestTarget(
- methodName = "createSSLEngine",
- methodArgs = {String.class, int.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.SUFFICIENT,
+ notes = "UnsupportedOperationException checking missed",
+ method = "createSSLEngine",
+ args = {java.lang.String.class, int.class}
+ )
public void test_createSSLEngineLjava_lang_StringI()
throws KeyManagementException {
if (!DEFSupported) fail(NotSupportMsg);
@@ -203,15 +194,12 @@
* <code>getServiceSessionContext()</code>
* methods Assertion: returns correspondent object
*/
- @TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getClientSessionContext",
- methodArgs = {}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getClientSessionContext",
+ args = {}
+ )
public void test_getClientSessionContext() throws NoSuchAlgorithmException {
if (!DEFSupported) {
fail(NotSupportMsg);
@@ -231,15 +219,12 @@
* Test for <code>getInstance(String protocol)</code> method Assertion:
* returns SSLContext object
*/
- @TestInfo(
- level = TestLevel.PARTIAL_OK,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getInstance",
- methodArgs = {String.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "getInstance",
+ args = {java.lang.String.class}
+ )
public void test_getInstanceLjava_lang_String01() throws NoSuchAlgorithmException {
if (!DEFSupported) {
fail(NotSupportMsg);
@@ -260,15 +245,12 @@
* throws NullPointerException when protocol is null; throws
* NoSuchAlgorithmException when protocol is not correct;
*/
- @TestInfo(
- level = TestLevel.PARTIAL_OK,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getInstance",
- methodArgs = {String.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "getInstance",
+ args = {java.lang.String.class}
+ )
public void test_getInstanceLjava_lang_String02() {
try {
SSLContext.getInstance(null);
@@ -291,15 +273,12 @@
* method Assertion: throws IllegalArgumentException when provider is null
* or empty
*/
- @TestInfo(
- level = TestLevel.PARTIAL_OK,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getInstance",
- methodArgs = {String.class, String.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "getInstance",
+ args = {java.lang.String.class, java.lang.String.class}
+ )
public void test_getInstanceLjava_lang_StringLjava_lang_String01() throws NoSuchProviderException,
NoSuchAlgorithmException {
if (!DEFSupported) {
@@ -326,15 +305,12 @@
* method Assertion: throws NullPointerException when protocol is null;
* throws NoSuchAlgorithmException when protocol is not correct;
*/
- @TestInfo(
- level = TestLevel.PARTIAL_OK,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getInstance",
- methodArgs = {String.class, String.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "getInstance",
+ args = {java.lang.String.class, java.lang.String.class}
+ )
public void test_getInstanceLjava_lang_StringLjava_lang_String02() throws NoSuchProviderException {
if (!DEFSupported) {
fail(NotSupportMsg);
@@ -361,15 +337,12 @@
* method Assertion: throws NoSuchProviderException when provider has
* invalid value
*/
- @TestInfo(
- level = TestLevel.PARTIAL_OK,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getInstance",
- methodArgs = {String.class, String.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "getInstance",
+ args = {java.lang.String.class, java.lang.String.class}
+ )
public void test_getInstanceLjava_lang_StringLjava_lang_String03() throws NoSuchAlgorithmException {
if (!DEFSupported) {
fail(NotSupportMsg);
@@ -392,15 +365,12 @@
* Test for <code>getInstance(String protocol, String provider)</code>
* method Assertion: returns instance of SSLContext
*/
- @TestInfo(
- level = TestLevel.PARTIAL_OK,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getInstance",
- methodArgs = {String.class, String.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "getInstance",
+ args = {java.lang.String.class, java.lang.String.class}
+ )
public void test_getInstanceLjava_lang_StringLjava_lang_String04() throws NoSuchAlgorithmException,
NoSuchProviderException {
if (!DEFSupported) {
@@ -424,15 +394,12 @@
* Test for <code>getInstance(String protocol, Provider provider)</code>
* method Assertion: throws IllegalArgumentException when provider is null
*/
- @TestInfo(
- level = TestLevel.PARTIAL_OK,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getInstance",
- methodArgs = {String.class, Provider.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "getInstance",
+ args = {java.lang.String.class, java.security.Provider.class}
+ )
public void test_getInstanceLjava_lang_StringLjava_security_Provider01() throws NoSuchAlgorithmException {
if (!DEFSupported) {
fail(NotSupportMsg);
@@ -453,15 +420,12 @@
* method Assertion: throws NullPointerException when protocol is null;
* throws NoSuchAlgorithmException when protocol is not correct;
*/
- @TestInfo(
- level = TestLevel.PARTIAL_OK,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getInstance",
- methodArgs = {String.class, Provider.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "getInstance",
+ args = {java.lang.String.class, java.security.Provider.class}
+ )
public void test_getInstanceLjava_lang_StringLjava_security_Provider02() {
if (!DEFSupported) {
fail(NotSupportMsg);
@@ -486,15 +450,12 @@
* Test for <code>getInstance(String protocol, Provider provider)</code>
* method Assertion: returns instance of SSLContext
*/
- @TestInfo(
- level = TestLevel.PARTIAL_OK,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getInstance",
- methodArgs = {String.class, Provider.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "getInstance",
+ args = {java.lang.String.class, java.security.Provider.class}
+ )
public void test_getInstanceLjava_lang_StringLjava_security_Provider03() throws NoSuchAlgorithmException {
if (!DEFSupported) {
fail(NotSupportMsg);
@@ -518,15 +479,12 @@
* @throws NoSuchProviderException
* @tests javax.net.ssl.SSLContext#getProtocol()
*/
- @TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getProtocol",
- methodArgs = {}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getProtocol",
+ args = {}
+ )
public void test_getProtocol()
throws NoSuchAlgorithmException, NoSuchProviderException {
if (!DEFSupported) fail(NotSupportMsg);
@@ -554,15 +512,12 @@
* @throws NoSuchProviderException
* @tests javax.net.ssl.SSLContext#getProvider()
*/
- @TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getProvider",
- methodArgs = {}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getProvider",
+ args = {}
+ )
public void test_getProvider()
throws NoSuchAlgorithmException, NoSuchProviderException {
if (!DEFSupported) fail(NotSupportMsg);
@@ -582,16 +537,13 @@
/**
* @tests javax.net.ssl.SSLContext#getServletSessionContext()
*/
- @TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getServerSessionContext",
- methodArgs = {}
- )
- })
- public void _test_getServletSessionContext() throws NoSuchAlgorithmException,
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getServerSessionContext",
+ args = {}
+ )
+ public void test_getServerSessionContext() throws NoSuchAlgorithmException,
KeyManagementException, KeyStoreException,
UnrecoverableKeyException {
if (!DEFSupported) fail(NotSupportMsg);
@@ -606,12 +558,14 @@
KeyManagerFactory kmf = KeyManagerFactory.getInstance(kAlg);
kmf.init(null, new char[11]);
TrustManagerFactory tmf = TrustManagerFactory.getInstance(tAlg);
- tmf.init((KeyStore)null);
+ KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
+ tmf.init(ks);
TrustManager[] tms = tmf.getTrustManagers();
for (SSLContext sslCi : sslC) {
sslCi.init(kmf.getKeyManagers(), tms, new SecureRandom());
assertTrue("Server context is incorrectly instantiated",
sslCi.getServerSessionContext() instanceof SSLSessionContext);
+ assertNotNull("Null object returned", sslCi.getServerSessionContext());
}
}
@@ -622,16 +576,13 @@
* methods Assertion: returns correspondent object
*
*/
- @TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getServerSocketFactory",
- methodArgs = {}
- )
- })
- public void _test_getServerSocketFactory() throws NoSuchAlgorithmException,
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getServerSocketFactory",
+ args = {}
+ )
+ public void test_getServerSocketFactory() throws NoSuchAlgorithmException,
KeyManagementException, KeyStoreException,
UnrecoverableKeyException {
if (!DEFSupported) {
@@ -651,7 +602,12 @@
return;
}
KeyManagerFactory kmf = KeyManagerFactory.getInstance(kAlg);
- KeyStore ks = null;
+ KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
+ try {
+ ks.load(null, null);
+ } catch (Exception e) {
+ fail(e + " was thrown for method load(null, null)");
+ }
kmf.init(ks, new char[10]);
KeyManager[] kms = kmf.getKeyManagers();
TrustManagerFactory tmf = TrustManagerFactory.getInstance(tAlg);
@@ -661,22 +617,20 @@
sslC[i].init(kms, tms, new SecureRandom());
assertTrue(sslC[i].getServerSocketFactory() instanceof SSLServerSocketFactory);
assertTrue(sslC[i].getSocketFactory() instanceof SSLSocketFactory);
+ assertNotNull("Null object returned", sslC[i].getServerSocketFactory());
}
}
/**
* @tests javax.net.ssl.SSLContext#getSocketFactory()
*/
- @TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getSocketFactory",
- methodArgs = {}
- )
- })
- public void _test_getSocketFactory() throws NoSuchAlgorithmException,
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getSocketFactory",
+ args = {}
+ )
+ public void test_getSocketFactory() throws NoSuchAlgorithmException,
KeyManagementException, KeyStoreException,
UnrecoverableKeyException {
if (!DEFSupported) fail(NotSupportMsg);
@@ -691,12 +645,14 @@
KeyManagerFactory kmf = KeyManagerFactory.getInstance(kAlg);
kmf.init(null, new char[11]);
TrustManagerFactory tmf = TrustManagerFactory.getInstance(tAlg);
- tmf.init((KeyStore)null);
+ KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
+ tmf.init(ks);
TrustManager[] tms = tmf.getTrustManagers();
for (SSLContext sslCi : sslC) {
sslCi.init(kmf.getKeyManagers(), tms, new SecureRandom());
assertTrue("Socket factory is incorrectly instantiated",
sslCi.getSocketFactory() instanceof SSLSocketFactory);
+ assertNotNull("Null object returned", sslCi.getSocketFactory());
}
}
@@ -709,16 +665,13 @@
* init(javax.net.ssl.KeyManager[], javax.net.ssl.TrustManager[],
* java.security.SecureRandom)
*/
- @TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "KeyManagementException checking missed",
- targets = {
- @TestTarget(
- methodName = "init",
- methodArgs = {KeyManager[].class, TrustManager[].class, SecureRandom.class}
- )
- })
- public void _test_init$Ljavax_net_ssl_KeyManager$Ljavax_net_ssl_TrustManagerLjava_security_SecureRandom()
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "init",
+ args = {javax.net.ssl.KeyManager[].class, javax.net.ssl.TrustManager[].class, java.security.SecureRandom.class}
+ )
+ public void test_init$Ljavax_net_ssl_KeyManager$Ljavax_net_ssl_TrustManagerLjava_security_SecureRandom()
throws Exception {
if (!DEFSupported) fail(NotSupportMsg);
SSLContextSpi spi = new MySSLContextSpi();
@@ -732,27 +685,28 @@
}
try {
- sslContext.init(null, null, new SecureRandom());
-
- KeyManagerFactory kmf = KeyManagerFactory.getInstance(
- KeyManagerFactory.getDefaultAlgorithm());
- KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
- InputStream v1in = new FileInputStream(ClassLoader
- .getSystemClassLoader().getResource("keystore.jks").getFile());
- char[] password = "password".toCharArray();
- ks.load(v1in, password);
- v1in.close();
- kmf.init(ks, password);
- KeyManager[] km = kmf.getKeyManagers();
- sslContext.init(km, null, new SecureRandom());
-
- TrustManagerFactory tmf = TrustManagerFactory.getInstance(
- TrustManagerFactory.getDefaultAlgorithm());
- tmf.init(ks);
- TrustManager[] tm = tmf.getTrustManagers();
- sslContext.init(null, tm, new SecureRandom());
+ sslContext.init(null, null, null);
+ fail("KeyManagementException wasn't thrown");
} catch (KeyManagementException kme) {
- fail("Unexpected KeyManagementException " + kme.toString());
+ //expected
+ }
+
+ try {
+ String tAlg = TrustManagerFactory.getDefaultAlgorithm();
+ String kAlg = KeyManagerFactory.getDefaultAlgorithm();
+ if (tAlg == null)
+ fail("TrustManagerFactory default algorithm is not defined");
+ if (kAlg == null)
+ fail("KeyManagerFactory default algorithm is not defined");
+ KeyManagerFactory kmf = KeyManagerFactory.getInstance(kAlg);
+ kmf.init(null, new char[11]);
+ TrustManagerFactory tmf = TrustManagerFactory.getInstance(tAlg);
+ KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
+ tmf.init(ks);
+ TrustManager[] tms = tmf.getTrustManagers();
+ sslContext.init(kmf.getKeyManagers(), tms, new SecureRandom());
+ } catch (Exception e) {
+ System.out.println("EE = " + e);
}
}
}
diff --git a/x-net/src/test/java/tests/api/javax/net/ssl/SSLContext2Test.java b/x-net/src/test/java/tests/api/javax/net/ssl/SSLContext2Test.java
index 8dd4c25..2ddb1ed 100644
--- a/x-net/src/test/java/tests/api/javax/net/ssl/SSLContext2Test.java
+++ b/x-net/src/test/java/tests/api/javax/net/ssl/SSLContext2Test.java
@@ -18,9 +18,9 @@
package tests.api.javax.net.ssl;
import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestInfo;
+import dalvik.annotation.TestTargets;
import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTarget;
+import dalvik.annotation.TestTargetNew;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
@@ -155,15 +155,12 @@
* throws NoSuchAlgorithmException when protocol is not correct;
* returns SSLContext object
*/
- @TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getInstance",
- methodArgs = {String.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getInstance",
+ args = {java.lang.String.class}
+ )
public void test_getInstanceLjava_lang_String() throws NoSuchAlgorithmException,
KeyManagementException {
try {
@@ -202,15 +199,12 @@
* throws NoSuchProviderException when provider is available;
* returns SSLContext object
*/
- @TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getInstance",
- methodArgs = {String.class, String.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getInstance",
+ args = {java.lang.String.class, java.lang.String.class}
+ )
public void test_getInstanceLjava_lang_StringLjava_lang_String() throws NoSuchAlgorithmException,
NoSuchProviderException, IllegalArgumentException,
KeyManagementException {
@@ -276,15 +270,12 @@
* throws IllegalArgumentException when provider is null;
* returns SSLContext object
*/
- @TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getInstance",
- methodArgs = {String.class, Provider.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getInstance",
+ args = {java.lang.String.class, java.security.Provider.class}
+ )
public void test_getInstanceLjava_lang_StringLjava_security_Provider()
throws NoSuchAlgorithmException,
IllegalArgumentException, KeyManagementException {
diff --git a/x-net/src/test/java/tests/api/javax/net/ssl/SSLContextSpiTest.java b/x-net/src/test/java/tests/api/javax/net/ssl/SSLContextSpiTest.java
index bc08e64..cf3123a 100644
--- a/x-net/src/test/java/tests/api/javax/net/ssl/SSLContextSpiTest.java
+++ b/x-net/src/test/java/tests/api/javax/net/ssl/SSLContextSpiTest.java
@@ -5,7 +5,7 @@
* 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
+ * 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,
@@ -13,115 +13,311 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package tests.api.javax.net.ssl;
import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestInfo;
+import dalvik.annotation.TestTargets;
import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTarget;
+import dalvik.annotation.TestTargetNew;
-import java.security.KeyManagementException;
-import java.security.SecureRandom;
-
-import javax.net.ssl.KeyManager;
+import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContextSpi;
import javax.net.ssl.SSLEngine;
import javax.net.ssl.SSLServerSocketFactory;
import javax.net.ssl.SSLSessionContext;
import javax.net.ssl.SSLSocketFactory;
+import javax.net.ssl.KeyManager;
import javax.net.ssl.TrustManager;
+import javax.net.ssl.TrustManagerFactory;
+import java.security.KeyManagementException;
+
+import java.security.KeyStore;
+import java.security.SecureRandom;
+import java.security.Security;
import junit.framework.TestCase;
+import org.apache.harmony.xnet.tests.support.SSLContextSpiImpl;
+
@TestTargetClass(SSLContextSpi.class)
public class SSLContextSpiTest extends TestCase {
-
- private class MockSSLContextSpi extends SSLContextSpi {
- public MockSSLContextSpi() {
- super();
- }
-
- /**
- * @see javax.net.ssl.SSLContextSpi#engineCreateSSLEngine()
- */
- @Override
- protected SSLEngine engineCreateSSLEngine() {
- // it is a fake
- return null;
- }
-
- /**
- * @see javax.net.ssl.SSLContextSpi#engineCreateSSLEngine(java.lang.String, int)
- */
- @Override
- protected SSLEngine engineCreateSSLEngine(String host, int port) {
- // it is a fake
- return null;
- }
-
- /**
- * @see javax.net.ssl.SSLContextSpi#engineGetClientSessionContext()
- */
- @Override
- protected SSLSessionContext engineGetClientSessionContext() {
- // it is a fake
- return null;
- }
-
- /**
- * @see javax.net.ssl.SSLContextSpi#engineGetServerSessionContext()
- */
- @Override
- protected SSLSessionContext engineGetServerSessionContext() {
- // it is a fake
- return null;
- }
-
- /**
- * @see javax.net.ssl.SSLContextSpi#engineGetServerSocketFactory()
- */
- @Override
- protected SSLServerSocketFactory engineGetServerSocketFactory() {
- // it is a fake
- return null;
- }
-
- /**
- * @see javax.net.ssl.SSLContextSpi#engineGetSocketFactory()
- */
- @Override
- protected SSLSocketFactory engineGetSocketFactory() {
- // it is a fake
- return null;
- }
-
- /**
- * @see javax.net.ssl.SSLContextSpi#engineInit(javax.net.ssl.KeyManager[], javax.net.ssl.TrustManager[], java.security.SecureRandom)
- */
- @Override
- protected void engineInit(KeyManager[] km, TrustManager[] tm, SecureRandom sr) throws KeyManagementException {
- // it is a fake
- }
- }
/**
* @tests javax.net.ssl.SSLContextSpi#SSLContextSpi()
*/
- @TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "SSLContextSpi",
- methodArgs = {}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "SSLContextSpi",
+ args = {}
+ )
public void test_Constructor() {
try {
- new MockSSLContextSpi();
+ SSLContextSpiImpl ssl = new SSLContextSpiImpl();
+ assertTrue(ssl instanceof SSLContextSpi);
} catch (Exception e) {
fail("Unexpected exception " + e.toString());
}
}
+
+ /**
+ * @tests javax.net.ssl.SSLContextSpi#engineCreateSSLEngine()
+ * Verify exception when SSLContextSpi object wasn't initialiazed.
+ */
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "engineCreateSSLEngine",
+ args = {}
+ )
+ public void test_engineCreateSSLEngine_01() {
+ SSLContextSpiImpl ssl = new SSLContextSpiImpl();
+ try {
+ SSLEngine sleng = ssl.engineCreateSSLEngine();
+ fail("RuntimeException wasn't thrown");
+ } catch (RuntimeException re) {
+ String str = re.getMessage();
+ if (!str.equals("Not initialiazed"))
+ fail("Incorrect exception message: " + str);
+ } catch (Exception e) {
+ fail("Incorrect exception " + e + " was thrown");
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLContextSpi#engineCreateSSLEngine(String host, int port)
+ * Verify exception when SSLContextSpi object wasn't initialiazed.
+ */
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "engineCreateSSLEngine",
+ args = {java.lang.String.class, int.class}
+ )
+ public void test_engineCreateSSLEngine_02() {
+ int[] invalid_port = {Integer.MIN_VALUE, -65535, -1, 65536, Integer.MAX_VALUE};
+ SSLContextSpiImpl ssl = new SSLContextSpiImpl();
+ try {
+ SSLEngine sleng = ssl.engineCreateSSLEngine("localhost", 1080);
+ fail("RuntimeException wasn't thrown");
+ } catch (RuntimeException re) {
+ String str = re.getMessage();
+ if (!str.equals("Not initialiazed"))
+ fail("Incorrect exception message: " + str);
+ } catch (Exception e) {
+ fail("Incorrect exception " + e + " was thrown");
+ }
+
+ for (int i = 0; i < invalid_port.length; i++) {
+ try {
+ SSLEngine sleng = ssl.engineCreateSSLEngine("localhost", invalid_port[i]);
+ fail("IllegalArgumentException wasn't thrown");
+ } catch (IllegalArgumentException iae) {
+ //expected
+ }
+ }
+ }
+
+ /**
+ * @tests SSLContextSpi#engineGetClientSessionContext()
+ * @tests SSLContextSpi#engineGetServerSessionContext()
+ * @tests SSLContextSpi#engineGetServerSocketFactory()
+ * @tests SSLContextSpi#engineGetSocketFactory()
+ * Verify exception when SSLContextSpi object wasn't initialiazed.
+ */
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "engineGetClientSessionContext",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "engineGetServerSessionContext",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "engineGetServerSocketFactory",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "engineGetSocketFactory",
+ args = {}
+ )
+ })
+ public void test_commonTest_01() {
+ SSLContextSpiImpl ssl = new SSLContextSpiImpl();
+
+ try {
+ SSLSessionContext slsc = ssl.engineGetClientSessionContext();
+ fail("RuntimeException wasn't thrown");
+ } catch (RuntimeException re) {
+ String str = re.getMessage();
+ if (!str.equals("Not initialiazed"))
+ fail("Incorrect exception message: " + str);
+ } catch (Exception e) {
+ fail("Incorrect exception " + e + " was thrown");
+ }
+
+ try {
+ SSLSessionContext slsc = ssl.engineGetServerSessionContext();
+ fail("RuntimeException wasn't thrown");
+ } catch (RuntimeException re) {
+ String str = re.getMessage();
+ if (!str.equals("Not initialiazed"))
+ fail("Incorrect exception message: " + str);
+ } catch (Exception e) {
+ fail("Incorrect exception " + e + " was thrown");
+ }
+
+ try {
+ SSLServerSocketFactory sssf = ssl.engineGetServerSocketFactory();
+ fail("RuntimeException wasn't thrown");
+ } catch (RuntimeException re) {
+ String str = re.getMessage();
+ if (!str.equals("Not initialiazed"))
+ fail("Incorrect exception message: " + str);
+ } catch (Exception e) {
+ fail("Incorrect exception " + e + " was thrown");
+ }
+
+ try {
+ SSLSocketFactory ssf = ssl.engineGetSocketFactory();
+ fail("RuntimeException wasn't thrown");
+ } catch (RuntimeException re) {
+ String str = re.getMessage();
+ if (!str.equals("Not initialiazed"))
+ fail("Incorrect exception message: " + str);
+ } catch (Exception e) {
+ fail("Incorrect exception " + e + " was thrown");
+ }
+ }
+
+ /**
+ * @tests SSLContextSpi#engineInit(KeyManager[] km, TrustManager[] tm, SecureRandom sr)
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "engineInit",
+ args = {javax.net.ssl.KeyManager[].class, javax.net.ssl.TrustManager[].class, java.security.SecureRandom.class}
+ )
+ public void test_engineInit() {
+ SSLContextSpiImpl ssl = new SSLContextSpiImpl();
+ String defaultAlgorithm = Security.getProperty("ssl.KeyManagerFactory.algorithm");
+ try {
+ KeyManagerFactory kmf = KeyManagerFactory.getInstance(defaultAlgorithm);
+ char[] pass = "password".toCharArray();
+ kmf.init(null, pass);
+ KeyManager[] km = kmf.getKeyManagers();
+ defaultAlgorithm = Security.getProperty("ssl.TrustManagerFactory.algorithm");
+ TrustManagerFactory trustMF = TrustManagerFactory.getInstance(defaultAlgorithm);
+ KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
+ ks.load(null, null);
+ trustMF.init(ks);
+ TrustManager[] tm = trustMF.getTrustManagers();
+ SecureRandom sr = SecureRandom.getInstance("SHA1PRNG");
+ try {
+ ssl.engineInit(km, tm, sr);
+ } catch (KeyManagementException kme) {
+ fail(kme + " was throw for engineInit method");
+ }
+ try {
+ ssl.engineInit(km, tm, null);
+ fail("KeyManagementException wasn't thrown");
+ } catch (KeyManagementException kme) {
+ //expected
+ }
+ } catch (Exception ex) {
+ fail(ex + " unexpected exception");
+ }
+ }
+
+ /**
+ * @tests SSLContextSpi#engineCreateSSLEngine()
+ * @tests SSLContextSpi#engineCreateSSLEngine(String host, int port)
+ * @tests SSLContextSpi#engineGetClientSessionContext()
+ * @tests SSLContextSpi#engineGetServerSessionContext()
+ * @tests SSLContextSpi#engineGetServerSocketFactory()
+ * @tests SSLContextSpi#engineGetSocketFactory()
+ */
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "engineCreateSSLEngine",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "engineCreateSSLEngine",
+ args = {java.lang.String.class, int.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "engineGetClientSessionContext",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "engineGetServerSessionContext",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "engineGetServerSocketFactory",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "engineGetSocketFactory",
+ args = {}
+ )
+ })
+ public void test_commonTest_02() {
+ SSLContextSpiImpl ssl = new SSLContextSpiImpl();
+ String defaultAlgorithm = Security.getProperty("ssl.KeyManagerFactory.algorithm");
+ try {
+ KeyManagerFactory kmf = KeyManagerFactory.getInstance(defaultAlgorithm);
+ char[] pass = "password".toCharArray();
+ kmf.init(null, pass);
+ KeyManager[] km = kmf.getKeyManagers();
+ defaultAlgorithm = Security.getProperty("ssl.TrustManagerFactory.algorithm");
+ TrustManagerFactory trustMF = TrustManagerFactory.getInstance(defaultAlgorithm);
+ KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
+ ks.load(null, null);
+ trustMF.init(ks);
+ TrustManager[] tm = trustMF.getTrustManagers();
+ SecureRandom sr = SecureRandom.getInstance("SHA1PRNG");
+ ssl.engineInit(km, tm, sr);
+ } catch (Exception ex) {
+ fail(ex + " unexpected exception");
+ }
+
+ try {
+ assertNotNull("Subtest_01: Object is NULL", ssl.engineCreateSSLEngine());
+ SSLEngine sleng = ssl.engineCreateSSLEngine("localhost", 1080);
+ assertNotNull("Subtest_02: Object is NULL", sleng);
+ assertEquals(sleng.getPeerPort(), 1080);
+ assertEquals(sleng.getPeerHost(), "localhost");
+ assertNull("Subtest_03: Object not NULL", ssl.engineGetClientSessionContext());
+ assertNull("Subtest_04: Object not NULL", ssl.engineGetServerSessionContext());
+ assertNull("Subtest_05: Object not NULL", ssl.engineGetServerSocketFactory());
+ assertNull("Subtest_06: Object not NULL", ssl.engineGetSocketFactory());
+ } catch (Exception e) {
+ fail("Unexpected exception " + e);
+ }
+ }
+
}
diff --git a/x-net/src/test/java/tests/api/javax/net/ssl/SSLEngineResultHandshakeStatusTest.java b/x-net/src/test/java/tests/api/javax/net/ssl/SSLEngineResultHandshakeStatusTest.java
new file mode 100644
index 0000000..22af271
--- /dev/null
+++ b/x-net/src/test/java/tests/api/javax/net/ssl/SSLEngineResultHandshakeStatusTest.java
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+package tests.api.javax.net.ssl;
+
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetNew;
+
+import javax.net.ssl.SSLEngineResult;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests for SSLEngineResult.Status class
+ *
+ */
+@TestTargetClass(SSLEngineResult.HandshakeStatus.class)
+public class SSLEngineResultHandshakeStatusTest extends TestCase {
+
+ /**
+ * Test for <code> SSLEngineResult.HandshakeStatus.values() </code>
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "values",
+ args = {}
+ )
+ public void test_SSLEngineResultHandshakeStatus_values() {
+ String[] str = {"NOT_HANDSHAKING", "FINISHED", "NEED_TASK", "NEED_WRAP", "NEED_UNWRAP"};
+ SSLEngineResult.HandshakeStatus[] enS = SSLEngineResult.HandshakeStatus.values();
+ if (enS.length == str.length) {
+ for (int i = 0; i < enS.length; i++) {
+ //System.out.println("enS[" + i + "] = " + enS[i]);
+ assertEquals("Incorrect Status", enS[i].toString(), str[i]);
+ }
+ } else {
+ fail("Incorrect number of enum constant was returned");
+ }
+ }
+
+ /**
+ * Test for <code> SSLEngineResult.HandshakeStatus.valueOf(String name) </code>
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "valueOf",
+ args = {String.class}
+ )
+ public void test_SSLEngineResultStatus_valueOf() {
+ String[] str = {"FINISHED", "NEED_TASK", "NEED_UNWRAP", "NEED_WRAP", "NOT_HANDSHAKING"};
+ String[] str_invalid = {"", "FINISHED1", "NEED_task", "NEED_UN",
+ "NEED_WRAP_WRAP", "not_HANDSHAKING", "Bad string for verification valueOf method"};
+ SSLEngineResult.HandshakeStatus enS;
+
+ //Correct parameter
+ for (int i = 0; i < str.length; i++) {
+ try {
+ enS = SSLEngineResult.HandshakeStatus.valueOf(str[i]);
+ assertEquals("Incorrect Status", enS.toString(), str[i]);
+ } catch (Exception e) {
+ fail("Unexpected exception " + e + " was thrown for " + str[i]);
+ }
+ }
+
+ //Incorrect parameter
+ for (int i = 0; i < str_invalid.length; i++) {
+ try {
+ enS = SSLEngineResult.HandshakeStatus.valueOf(str_invalid[i]);
+ fail("IllegalArgumentException should be thrown for " + str_invalid[i]);
+ } catch (IllegalArgumentException iae) {
+ //expected
+ }
+ }
+
+ //Null parameter
+ try {
+ enS = SSLEngineResult.HandshakeStatus.valueOf(null);
+ fail("NullPointerException/IllegalArgumentException should be thrown for NULL parameter");
+ } catch (NullPointerException npe) {
+ //expected
+ } catch (IllegalArgumentException iae) {
+ }
+ }
+}
\ No newline at end of file
diff --git a/x-net/src/test/java/tests/api/javax/net/ssl/SSLEngineResultStatusTest.java b/x-net/src/test/java/tests/api/javax/net/ssl/SSLEngineResultStatusTest.java
new file mode 100644
index 0000000..652b384
--- /dev/null
+++ b/x-net/src/test/java/tests/api/javax/net/ssl/SSLEngineResultStatusTest.java
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+package tests.api.javax.net.ssl;
+
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetNew;
+
+import javax.net.ssl.SSLEngineResult;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests for SSLEngineResult.Status class
+ *
+ */
+@TestTargetClass(SSLEngineResult.Status.class)
+public class SSLEngineResultStatusTest extends TestCase {
+
+ /**
+ * Test for <code> SSLEngineResult.Status.values() </code>
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "values",
+ args = {}
+ )
+ public void test_SSLEngineResultStatus_values() {
+ boolean flag = false;
+ String[] str = {"BUFFER_OVERFLOW", "BUFFER_UNDERFLOW", "CLOSED", "OK"};
+ SSLEngineResult.Status[] enS = SSLEngineResult.Status.values();
+ if (enS.length == str.length) {
+ for (int i = 0; i < enS.length; i++) {
+ flag = false;
+ for (int j = 0; j < str.length; j++) {
+ if (enS[i].toString() == str[j]) {
+ flag = true;
+ break;
+ }
+ }
+ }
+ assertTrue("Incorrect Status", flag);
+ } else {
+ fail("Incorrect number of enum constant was returned");
+ }
+ }
+
+ /**
+ * Test for <code> SSLEngineResult.Status.valueOf(String name) </code>
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "valueOf",
+ args = {String.class}
+ )
+ public void test_SSLEngineResultStatus_valueOf() {
+ String[] str = {"BUFFER_OVERFLOW", "BUFFER_UNDERFLOW", "CLOSED", "OK"};
+ String[] str_invalid = {"", "OK1", "BUFFER_overflow", "BUFFER_UND",
+ "CLOSED_CLOSED", "Bad string for verification valueOf method"};
+ SSLEngineResult.Status enS;
+
+ //Correct parameter
+ for (int i = 0; i < str.length; i++) {
+ try {
+ enS = SSLEngineResult.Status.valueOf(str[i]);
+ assertEquals("Incorrect Status", enS.toString(), str[i]);
+ } catch (Exception e) {
+ fail("Unexpected exception " + e + " was thrown for " + str[i]);
+ }
+ }
+
+ //Incorrect parameter
+ for (int i = 0; i < str_invalid.length; i++) {
+ try {
+ enS = SSLEngineResult.Status.valueOf(str_invalid[i]);
+ fail("IllegalArgumentException should be thrown for " + str_invalid[i]);
+ } catch (IllegalArgumentException iae) {
+ //expected
+ }
+ }
+
+ //Null parameter
+ try {
+ enS = SSLEngineResult.Status.valueOf(null);
+ fail("NullPointerException/IllegalArgumentException should be thrown for NULL parameter");
+ } catch (NullPointerException npe) {
+ //expected
+ } catch (IllegalArgumentException iae) {
+ }
+ }
+}
\ No newline at end of file
diff --git a/x-net/src/test/java/tests/api/javax/net/ssl/SSLEngineResultTest.java b/x-net/src/test/java/tests/api/javax/net/ssl/SSLEngineResultTest.java
index dbffed6..4878df8 100644
--- a/x-net/src/test/java/tests/api/javax/net/ssl/SSLEngineResultTest.java
+++ b/x-net/src/test/java/tests/api/javax/net/ssl/SSLEngineResultTest.java
@@ -18,9 +18,9 @@
package tests.api.javax.net.ssl;
import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestInfo;
+import dalvik.annotation.TestTargets;
import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTarget;
+import dalvik.annotation.TestTargetNew;
import javax.net.ssl.SSLEngineResult;
import junit.framework.TestCase;
@@ -50,15 +50,12 @@
* is null
*
*/
- @TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "Exception cases were tested only",
- targets = {
- @TestTarget(
- methodName = "SSLEngineResult",
- methodArgs = {SSLEngineResult.Status.class, SSLEngineResult.HandshakeStatus.class, int.class, int.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "SSLEngineResult",
+ args = {javax.net.ssl.SSLEngineResult.Status.class, javax.net.ssl.SSLEngineResult.HandshakeStatus.class, int.class, int.class}
+ )
public void test_ConstructorLjavax_net_ssl_SSLEngineResult_StatusLjavax_net_ssl_SSLEngineResult_HandshakeStatusII() {
int[] neg = { -1, -10, -1000, Integer.MIN_VALUE,
@@ -91,20 +88,27 @@
} catch (IllegalArgumentException e) {
}
}
+
+ try {
+ SSLEngineResult res = new SSLEngineResult(SSLEngineResult.Status.BUFFER_OVERFLOW,
+ SSLEngineResult.HandshakeStatus.FINISHED, 1, 2);
+ assertNotNull("Null object", res);
+ assertEquals(1, res.bytesConsumed());
+ assertEquals(2, res.bytesProduced());
+ } catch (Exception e) {
+ fail("Unexpected exception: " + e);
+ }
}
/**
* Test for <code>bytesConsumed()</code> method
*/
- @TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "bytesConsumed",
- methodArgs = {}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "bytesConsumed",
+ args = {}
+ )
public void test_bytesConsumed() {
int[] pos = { 0, 1, 1000, Integer.MAX_VALUE, (Integer.MAX_VALUE - 1) };
SSLEngineResult.Status [] enS =
@@ -128,15 +132,12 @@
/**
* Test for <code>bytesProduced()</code> method
*/
- @TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "bytesProduced",
- methodArgs = {}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "bytesProduced",
+ args = {}
+ )
public void test_bytesProduced() {
int[] pos = { 0, 1, 1000, Integer.MAX_VALUE, (Integer.MAX_VALUE - 1) };
SSLEngineResult.Status [] enS =
@@ -160,15 +161,12 @@
/**
* Test for <code>getHandshakeStatus()</code> method
*/
- @TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getHandshakeStatus",
- methodArgs = {}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getHandshakeStatus",
+ args = {}
+ )
public void test_getHandshakeStatus() {
int[] pos = { 0, 1, 1000, Integer.MAX_VALUE, (Integer.MAX_VALUE - 1) };
SSLEngineResult.Status [] enS =
@@ -192,15 +190,12 @@
/**
* Test for <code>getStatus()</code> method
*/
- @TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getStatus",
- methodArgs = {}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getStatus",
+ args = {}
+ )
public void test_getStatus() {
int[] pos = { 0, 1, 1000, Integer.MAX_VALUE, (Integer.MAX_VALUE - 1) };
SSLEngineResult.Status [] enS =
@@ -224,15 +219,12 @@
/**
* Test for <code>toString()</code> method
*/
- @TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "toString",
- methodArgs = {}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "toString",
+ args = {}
+ )
public void test_toString() {
int[] pos = { 0, 1, 1000, Integer.MAX_VALUE, (Integer.MAX_VALUE - 1) };
SSLEngineResult.Status [] enS =
@@ -253,135 +245,6 @@
}
}
- /**
- * Test for <code>SSLEngineResult.Status.values()</code> method
- */
- @TestInfo(
- level = TestLevel.TODO,
- purpose = "Status class includes values() method.",
- targets = {
- @TestTarget(
- methodName = "values",
- methodArgs = {}
- )
- })
- public void test_SSLEngineResult_Status01() {
- SSLEngineResult.Status [] enS = SSLEngineResult.Status.values();
- assertTrue("Incorrect array of Status objects", enS.length > 0);
- assertTrue("OK object does not define", findEl(enS,
- SSLEngineResult.Status.OK));
- assertTrue("CLOSED object does not define", findEl(enS,
- SSLEngineResult.Status.CLOSED));
- assertTrue("BUFFER_OVERFLOW object does not define", findEl(enS,
- SSLEngineResult.Status.BUFFER_OVERFLOW));
- assertTrue("BUFFER_UNDERFLOW object does not define", findEl(enS,
- SSLEngineResult.Status.BUFFER_UNDERFLOW));
- }
-
- /**
- * Test for <code>SSLEngineResult.Status.valueOf(String name)</code> method
- * Assertion:
- * throws IllegalArgumentException when there is no constan with specified
- * name
- */
- @TestInfo(
- level = TestLevel.TODO,
- purpose = "Status class includes valueOf method. Null parameter checking missed.",
- targets = {
- @TestTarget(
- methodName = "valueOf",
- methodArgs = {String.class}
- )
- })
- public void test_SSLEngineResult_Status02() {
- String [] invalid = {"", "OK1", "BUFFER_overflow", "BUFFER_UND",
- "CLOSED_CLOSED", "Bad string for verification valueOf method"
- };
- assertEquals(SSLEngineResult.Status.valueOf("BUFFER_OVERFLOW"),
- SSLEngineResult.Status.BUFFER_OVERFLOW);
- assertEquals(SSLEngineResult.Status.valueOf("BUFFER_UNDERFLOW"),
- SSLEngineResult.Status.BUFFER_UNDERFLOW);
- assertEquals(SSLEngineResult.Status.valueOf("CLOSED"),
- SSLEngineResult.Status.CLOSED);
- assertEquals(SSLEngineResult.Status.valueOf("OK"),
- SSLEngineResult.Status.OK);
- for (int i = 0; i < invalid.length; i++) {
- try {
- SSLEngineResult.Status.valueOf(invalid[i]);
- fail("IllegalArgumentException must be thrown for name: " + invalid[i]);
- } catch (IllegalArgumentException e) {
- }
- }
- }
-
- /**
- * Test for <code>SSLEngineResult.HandshakeStatus.values()</code> method
- */
- @TestInfo(
- level = TestLevel.TODO,
- purpose = "HandshakeStatus class includes values method.",
- targets = {
- @TestTarget(
- methodName = "values",
- methodArgs = {}
- )
- })
- public void test_SSLEngineResult_HandshakeStatus01() {
- SSLEngineResult.HandshakeStatus [] enHS = SSLEngineResult.HandshakeStatus
- .values();
- assertTrue("Incorrect array of HandshakeStatus objects",
- enHS.length > 0);
- assertTrue("FINISHED object does not define", findEl(enHS,
- SSLEngineResult.HandshakeStatus.FINISHED));
- assertTrue("NEED_UNWRAP object does not define", findEl(enHS,
- SSLEngineResult.HandshakeStatus.NEED_UNWRAP));
- assertTrue("NEED_WRAP object does not define", findEl(enHS,
- SSLEngineResult.HandshakeStatus.NEED_WRAP));
- assertTrue("NEED_TASK object does not define", findEl(enHS,
- SSLEngineResult.HandshakeStatus.NEED_TASK));
- assertTrue("NOT_HANDSHAKING object does not define", findEl(enHS,
- SSLEngineResult.HandshakeStatus.NOT_HANDSHAKING));
- }
-
- /**
- * Test for <code>SSLEngineResult.HandshakeStatus.valueOf(String name)</code> method
- * Assertion:
- * throws IllegalArgumentException when there is no constan with specified
- * name
- */
-
- @TestInfo(
- level = TestLevel.TODO,
- purpose = "HandshakeStatus class includes valueOf method. Null parameter checking missed.",
- targets = {
- @TestTarget(
- methodName = "valueOf",
- methodArgs = {String.class}
- )
- })
- public void test_SSLEngineResult_HandshakeStatus02() {
- String [] invalid = {"", "FINISHED1", "NEED_task", "NEED_UN",
- "NEED_WRAP_WRAP", "not_HANDSHAKING", "Bad string for verification valueOf method"
- };
- assertEquals(SSLEngineResult.HandshakeStatus.valueOf("NOT_HANDSHAKING"),
- SSLEngineResult.HandshakeStatus.NOT_HANDSHAKING);
- assertEquals(SSLEngineResult.HandshakeStatus.valueOf("NEED_WRAP"),
- SSLEngineResult.HandshakeStatus.NEED_WRAP);
- assertEquals(SSLEngineResult.HandshakeStatus.valueOf("NEED_UNWRAP"),
- SSLEngineResult.HandshakeStatus.NEED_UNWRAP);
- assertEquals(SSLEngineResult.HandshakeStatus.valueOf("FINISHED"),
- SSLEngineResult.HandshakeStatus.FINISHED);
- assertEquals(SSLEngineResult.HandshakeStatus.valueOf("NEED_TASK"),
- SSLEngineResult.HandshakeStatus.NEED_TASK);
- for (int i = 0; i < invalid.length; i++) {
- try {
- SSLEngineResult.HandshakeStatus.valueOf(invalid[i]);
- fail("IllegalArgumentException must be thrown for name: " + invalid[i]);
- } catch (IllegalArgumentException e) {
- }
- }
- }
-
private boolean findEl(Object[] arr, Object el) {
boolean ok = false;
for (int i = 0; i < arr.length; i++) {
diff --git a/x-net/src/test/java/tests/api/javax/net/ssl/SSLEngineTest.java b/x-net/src/test/java/tests/api/javax/net/ssl/SSLEngineTest.java
index 8368391..94e384d 100644
--- a/x-net/src/test/java/tests/api/javax/net/ssl/SSLEngineTest.java
+++ b/x-net/src/test/java/tests/api/javax/net/ssl/SSLEngineTest.java
@@ -18,9 +18,10 @@
package tests.api.javax.net.ssl;
import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestInfo;
+import dalvik.annotation.TestTargets;
import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTarget;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.AndroidOnly;
import java.nio.ByteBuffer;
@@ -28,11 +29,11 @@
import javax.net.ssl.SSLException;
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLEngineResult;
+import java.nio.ReadOnlyBufferException;
import junit.framework.TestCase;
-
/**
* Tests for SSLEngine class
*
@@ -48,15 +49,12 @@
* Test for <code>SSLEngine()</code> constructor Assertion: creates
* SSLEngine object with null host and -1 port
*/
- @TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "SSLEngine",
- methodArgs = {}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "SSLEngine",
+ args = {}
+ )
public void test_Constructor() {
SSLEngine e = new mySSLEngine();
assertNull(e.getPeerHost());
@@ -69,15 +67,12 @@
/**
* Test for <code>SSLEngine(String host, int port)</code> constructor
*/
- @TestInfo(
- level = TestLevel.PARTIAL_OK,
- purpose = "Verification with incorrect parameters missed",
- targets = {
- @TestTarget(
- methodName = "SSLEngine",
- methodArgs = {String.class, int.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "Verification with incorrect parameters missed",
+ method = "SSLEngine",
+ args = {java.lang.String.class, int.class}
+ )
public void test_ConstructorLjava_lang_StringI01() throws SSLException {
int port = 1010;
SSLEngine e = new mySSLEngine(null, port);
@@ -92,15 +87,12 @@
/**
* Test for <code>SSLEngine(String host, int port)</code> constructor
*/
- @TestInfo(
- level = TestLevel.PARTIAL_OK,
- purpose = "Verification with incorrect parameters missed",
- targets = {
- @TestTarget(
- methodName = "SSLEngine",
- methodArgs = {String.class, int.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "Verification with incorrect parameters missed",
+ method = "SSLEngine",
+ args = {java.lang.String.class, int.class}
+ )
public void test_ConstructorLjava_lang_StringI02() {
String host = "new host";
int port = 8080;
@@ -117,34 +109,28 @@
/**
* Test for <code>getPeerHost()</code> method
*/
- @TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "Verification of real host name missed",
- targets = {
- @TestTarget(
- methodName = "getPeerHost",
- methodArgs = {}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getPeerHost",
+ args = {}
+ )
public void test_getPeerHost() {
SSLEngine e = new mySSLEngine();
assertNull(e.getPeerHost());
e = new mySSLEngine("www.fortify.net", 80);
- assertEquals("Incorrect host name", "www.fortify.net", e.getPeerHost());
+ assertEquals("Incorrect host name", "www.fortify.net", e.getPeerHost());
}
/**
* Test for <code>getPeerPort()</code> method
*/
- @TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "Verification of real port number missed",
- targets = {
- @TestTarget(
- methodName = "getPeerPort",
- methodArgs = {}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getPeerPort",
+ args = {}
+ )
public void test_getPeerPort() {
SSLEngine e = new mySSLEngine();
assertEquals("Incorrect default value of peer port",
@@ -154,366 +140,1454 @@
}
/**
- * Test for <code>wrap(ByteBuffer src, ByteBuffer dst)</code> method
- * Assertions:
- * throws IllegalArgumentException when src or dst is null
- * throws ReadOnlyBufferException when dst is ReadOnly byte buffer
- *
- * Check that implementation behavior follows RI:
- * jdk 1.5 does not throw IllegalArgumentException when parameters are null
- * and does not throw ReadOnlyBufferException if dst is read only byte buffer
+ * @tests javax.net.ssl.SSLEngine#getSupportedProtocols()
*/
- @TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "IllegalStateException checking missed",
- targets = {
- @TestTarget(
- methodName = "wrap",
- methodArgs = {ByteBuffer.class, ByteBuffer.class}
- )
- })
- public void test_wrapLjava_nio_ByteBufferLjava_nio_ByteBuffer01() throws SSLException {
- String host = "new host";
- int port = 8080;
- ByteBuffer bbN = null;
- ByteBuffer bb = ByteBuffer.allocate(10);
- SSLEngine e = new mySSLEngine(host, port);
-
- e.wrap(bbN, bb);
- e.wrap(bb, bbN);
-
- ByteBuffer roBb = bb.asReadOnlyBuffer();
- assertTrue("Not read only byte buffer", roBb.isReadOnly());
- e.wrap(bb, roBb);
-
- }
-
- /**
- * Test for <code>wrap(ByteBuffer src, ByteBuffer dst)</code> method
- *
- * Assertion: encodes a buffer data into network data.
- *
- */
- @TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "IllegalStateException checking missed",
- targets = {
- @TestTarget(
- methodName = "wrap",
- methodArgs = {ByteBuffer.class, ByteBuffer.class}
- )
- })
- public void test_wrapLjava_nio_ByteBufferLjava_nio_ByteBuffer02() throws SSLException {
- String host = "new host";
- int port = 8080;
- ByteBuffer bb = ByteBuffer.allocate(10);
- SSLEngine e = new mySSLEngine(host, port);
-
- SSLEngineResult res = e.wrap(bb, ByteBuffer.allocate(10));
- assertEquals(10, res.bytesConsumed());
- assertEquals(20, res.bytesProduced());
- }
-
- /**
- * Test for <code>wrap(ByteBuffer[] srcs, ByteBuffer dst)</code> method
- *
- * Assertions: throws IllegalArgumentException when srcs or dst is null or
- * srcs contains null byte buffer; throws ReadOnlyBufferException when dst
- * is read only byte buffer
- *
- * Check that implementation behavior follows RI:
- * jdk 1.5 does not throw IllegalArgumentException when dst is null or
- * if srcs contains null elements It does not throw ReadOnlyBufferException
- * for read only dst
- */
- @TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "IllegalStateException checking missed",
- targets = {
- @TestTarget(
- methodName = "wrap",
- methodArgs = {ByteBuffer[].class, ByteBuffer.class}
- )
- })
- public void test_wrap$Ljava_nio_ByteBufferLjava_nio_ByteBuffer01() throws SSLException {
- String host = "new host";
- int port = 8080;
- ByteBuffer[] bbNA = null;
- ByteBuffer[] bbA = { null, ByteBuffer.allocate(10), null };
-
- ByteBuffer bb = ByteBuffer.allocate(10);
- ByteBuffer bbN = null;
- SSLEngine e = new mySSLEngine(host, port);
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getSupportedProtocols",
+ args = {}
+ )
+ public void test_getSupportedProtocols() {
+ mySSLEngine sse = new mySSLEngine();
try {
- e.wrap(bbNA, bb);
- fail("IllegalArgumentException must be thrown for null srcs byte buffer array");
- } catch (IllegalArgumentException ex) {
+ String[] res = sse.getSupportedProtocols();
+ assertNotNull(res);
+ assertEquals(res.length, 0);
+ } catch (Exception ex) {
+ fail("Unexpected exception " + ex);
}
-
- e.wrap(bbA, bb);
- e.wrap(bbA, bbN);
-
- ByteBuffer roBb = bb.asReadOnlyBuffer();
- bbA[0] = ByteBuffer.allocate(100);
- bbA[2] = ByteBuffer.allocate(20);
- assertTrue("Not read only byte buffer", roBb.isReadOnly());
-
- e.wrap(bbA, roBb);
-
- }
-
- /**
- * Test for <code>wrap(ByteBuffer[] srcs, ByteBuffer dst)</code> method
- *
- * Assertion: encodes datas from buffers into network data.
- */
- @TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "IllegalStateException checking missed",
- targets = {
- @TestTarget(
- methodName = "wrap",
- methodArgs = {ByteBuffer[].class, ByteBuffer.class}
- )
- })
- public void test_wrap$Ljava_nio_ByteBufferLjava_nio_ByteBuffer02() throws SSLException {
- String host = "new host";
- int port = 8080;
-
- ByteBuffer bb = ByteBuffer.allocate(10);
- ByteBuffer[] bbA = { ByteBuffer.allocate(5), ByteBuffer.allocate(10), ByteBuffer.allocate(5) };
-
- SSLEngine e = new mySSLEngine(host, port);
-
- SSLEngineResult res = e.wrap(bbA, bb);
- assertEquals(10, res.bytesConsumed());
- assertEquals(20, res.bytesProduced());
}
/**
- * Test for <code>wrap(ByteBuffer src, ByteBuffer dst)</code> and
- * <code>wrap(ByteBuffer[] srcs, ByteBuffer dst)</code> methods
- *
- * Assertion: these methods throw SSLException
+ * @tests javax.net.ssl.SSLEngine#setEnabledProtocols(String[] protocols)
+ * @tests javax.net.ssl.SSLEngine#getEnabledProtocols()
*/
- @TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "IllegalStateException checking missed",
- targets = {
- @TestTarget(
- methodName = "wrap",
- methodArgs = {ByteBuffer.class, ByteBuffer.class}
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getEnabledProtocols",
+ args = {}
),
- @TestTarget(
- methodName = "wrap",
- methodArgs = {ByteBuffer[].class, ByteBuffer.class}
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "setEnabledProtocols",
+ args = {String[].class}
)
-
})
- public void test_wrap() throws SSLException {
- String host = "new host";
- int port = 8080;
+ public void test_EnabledProtocols() {
+ mySSLEngine sse = new mySSLEngine();
+ String[] pr = {"Protocil_01", "Protocol_02"};
+ try {
+ sse.setEnabledProtocols(pr);
+ String[] res = sse.getEnabledProtocols();
+ assertNotNull("Null array was returned", res);
+ assertEquals("Incorrect array length", res.length, pr.length);
+ assertEquals("Incorrect array was returned", res, pr);
+ } catch (Exception ex) {
+ fail("Unexpected exception " + ex);
+ }
+ try {
+ sse.setEnabledProtocols(null);
+ fail("IllegalArgumentException wasn't thrown");
+ } catch (IllegalArgumentException iae) {
+ //expected
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLEngine#getSupportedCipherSuites()
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getSupportedCipherSuites",
+ args = {}
+ )
+ public void test_getSupportedCipherSuites() {
+ mySSLEngine sse = new mySSLEngine();
+ try {
+ String[] res = sse.getSupportedCipherSuites();
+ assertNotNull(res);
+ assertEquals(res.length, 0);
+ } catch (Exception ex) {
+ fail("Unexpected exception " + ex);
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLEngine#setEnabledCipherSuites(String[] suites)
+ * @tests javax.net.ssl.SSLEngine#getEnabledCipherSuites()
+ */
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "setEnabledCipherSuites",
+ args = {String[].class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getEnabledCipherSuites",
+ args = {}
+ )
+ })
+ public void test_EnabledCipherSuites() {
+ mySSLEngine sse = new mySSLEngine();
+ String[] st = {"Suite_01", "Suite_02"};
+ try {
+ sse.setEnabledCipherSuites(st);
+ String[] res = sse.getEnabledCipherSuites();
+ assertNotNull("Null array was returned", res);
+ assertEquals("Incorrect array length", res.length, st.length);
+ assertEquals("Incorrect array was returned", res, st);
+ } catch (Exception ex) {
+ fail("Unexpected exception " + ex);
+ }
+ try {
+ sse.setEnabledCipherSuites(null);
+ fail("IllegalArgumentException wasn't thrown");
+ } catch (IllegalArgumentException iae) {
+ //expected
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLEngine#setEnableSessionCreation(boolean flag)
+ * @tests javax.net.ssl.SSLEngine#getEnableSessionCreation()
+ */
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "setEnableSessionCreation",
+ args = {boolean.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getEnableSessionCreation",
+ args = {}
+ )
+ })
+ public void test_EnableSessionCreation() {
+ mySSLEngine sse = new mySSLEngine();
+ try {
+ assertTrue(sse.getEnableSessionCreation());
+ sse.setEnableSessionCreation(false);
+ assertFalse(sse.getEnableSessionCreation());
+ sse.setEnableSessionCreation(true);
+ assertTrue(sse.getEnableSessionCreation());
+ } catch (Exception ex) {
+ fail("Unexpected exception " + ex);
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLEngine#setNeedClientAuth(boolean need)
+ * @tests javax.net.ssl.SSLEngine#getNeedClientAuth()
+ */
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "setNeedClientAuth",
+ args = {boolean.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getNeedClientAuth",
+ args = {}
+ )
+ })
+ public void test_NeedClientAuth() {
+ mySSLEngine sse = new mySSLEngine();
+ try {
+ sse.setNeedClientAuth(false);
+ assertFalse(sse.getNeedClientAuth());
+ sse.setNeedClientAuth(true);
+ assertTrue(sse.getNeedClientAuth());
+ } catch (Exception ex) {
+ fail("Unexpected exception " + ex);
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLEngine#setWantClientAuth(boolean want)
+ * @tests javax.net.ssl.SSLEngine#getWantClientAuth()
+ */
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "setWantClientAuth",
+ args = {boolean.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getWantClientAuth",
+ args = {}
+ )
+ })
+ public void test_WantClientAuth() {
+ mySSLEngine sse = new mySSLEngine();
+ try {
+ sse.setWantClientAuth(false);
+ assertFalse(sse.getWantClientAuth());
+ sse.setWantClientAuth(true);
+ assertTrue(sse.getWantClientAuth());
+ } catch (Exception ex) {
+ fail("Unexpected exception " + ex);
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLEngine#beginHandshake()
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "beginHandshake",
+ args = {}
+ )
+ public void test_beginHandshake() {
+ mySSLEngine sse = new mySSLEngine();
+ try {
+ sse.beginHandshake();
+ fail("SSLException wasn't thrown");
+ } catch (SSLException se) {
+ //expected
+ }
+ sse = new mySSLEngine("new host", 1080);
+ try {
+ sse.beginHandshake();
+ fail("IllegalStateException wasn't thrown");
+ } catch (IllegalStateException ise) {
+ //expected
+ } catch (Exception e) {
+ fail(e + " was thrown instead of IllegalStateException");
+ }
+ try {
+ sse.setUseClientMode(true);
+ System.out.println("<--- Client mode was set");
+ sse.beginHandshake();
+ } catch (Exception ex) {
+ fail("Unexpected exception " + ex);
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLEngine#setUseClientMode(boolean mode)
+ * @tests javax.net.ssl.SSLEngine#getUseClientMode()
+ */
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "setUseClientMode",
+ args = {boolean.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getUseClientMode",
+ args = {}
+ )
+ })
+ public void test_UseClientMode() {
+ mySSLEngine sse = new mySSLEngine();
+ try {
+ sse.setUseClientMode(false);
+ assertFalse(sse.getUseClientMode());
+ sse.setUseClientMode(true);
+ assertTrue(sse.getUseClientMode());
+ } catch (Exception ex) {
+ fail("Unexpected exception " + ex);
+ }
+
+ try {
+ sse = new mySSLEngine("new host", 1080);
+ sse.setUseClientMode(true);
+ sse.beginHandshake();
+ try {
+ sse.setUseClientMode(false);
+ fail("IllegalArgumentException was not thrown");
+ } catch (IllegalArgumentException iae) {
+ //expected
+ }
+ } catch (Exception ex) {
+ fail("Unexpected exception " + ex);
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLEngine#getSession()
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getSession",
+ args = {}
+ )
+ public void test_getSession() {
+ mySSLEngine sse = new mySSLEngine();
+ try {
+ assertNull(sse.getSession());
+ } catch (Exception ex) {
+ fail("Unexpected exception " + ex);
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLEngine#getHandshakeStatus()
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getHandshakeStatus",
+ args = {}
+ )
+ public void test_getHandshakeStatus() {
+ mySSLEngine sse = new mySSLEngine();
+ try {
+ assertEquals(sse.getHandshakeStatus().toString(), "FINISHED");
+ } catch (Exception ex) {
+ fail("Unexpected exception " + ex);
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLEngine#getDelegatedTask()
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getDelegatedTask",
+ args = {}
+ )
+ public void test_getDelegatedTask() {
+ mySSLEngine sse = new mySSLEngine();
+ try {
+ assertNull(sse.getDelegatedTask());
+ } catch (Exception ex) {
+ fail("Unexpected exception " + ex);
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLEngine#unwrap(ByteBuffer src, ByteBuffer[] dsts,
+ * int offset, int length)
+ * Exception case: SSLException should be thrown.
+ */
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "unwrap",
+ args = {ByteBuffer.class, ByteBuffer[].class, int.class, int.class}
+ )
+ public void test_unwrap_01() {
ByteBuffer bbs = ByteBuffer.allocate(100);
ByteBuffer bbd = ByteBuffer.allocate(10);
- SSLEngine e = new mySSLEngine1(host, port);
- try {
- e.wrap(bbs, bbd);
- fail("SSLException must be thrown");
- } catch (SSLException ex) {
- }
- SSLEngineResult res = e.wrap(bbd, bbs);
- assertEquals(10, res.bytesConsumed());
- assertEquals(20, res.bytesProduced());
-
- try {
- e.wrap(new ByteBuffer[] { bbs }, bbd);
- fail("SSLException must be thrown");
- } catch (SSLException ex) {
- }
- res = e.wrap(new ByteBuffer[] { bbd }, bbs);
- assertEquals(10, res.bytesConsumed());
- assertEquals(20, res.bytesProduced());
- }
-
- /**
- * Test for <code>unwrap(ByteBuffer src, ByteBuffer dst)</code> method
- *
- * Assertions:
- * throws IllegalArgumentException when src or dst is null
- * throws ReadOnlyBufferException when dst is read only byte buffer
- *
- * Check that implementation behavior follows RI:
- * jdk 1.5 does not throw IllegalArgumentException when parameters are null
- * and does not throw ReadOnlyBufferException if dst is read only byte buffer
- */
- @TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "IllegalStateException checking missed",
- targets = {
- @TestTarget(
- methodName = "unwrap",
- methodArgs = {ByteBuffer.class, ByteBuffer.class}
- )
- })
- public void test_unwrapLjava_nio_ByteBufferLjava_nio_ByteBuffer01() throws SSLException {
- String host = "new host";
- int port = 8080;
- ByteBuffer bbN = null;
- ByteBuffer bb = ByteBuffer.allocate(10);
- SSLEngine e = new mySSLEngine(host, port);
-
- e.unwrap(bbN, bb);
- e.unwrap(bb, bbN);
-
- ByteBuffer roBb = bb.asReadOnlyBuffer();
- assertTrue("Not read only byte buffer", roBb.isReadOnly());
-
- e.unwrap(bb, roBb);
- }
-
- /**
- * Test for <code>unwrap(ByteBuffersrc, ByteBuffer dst)</code> and
- * <code>unwrap(ByteBuffer src, ByteBuffer[] dsts)</code> methods
- *
- * Assertion: these methods throw SSLException
- */
- @TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "IllegalStateException checking missed",
- targets = {
- @TestTarget(
- methodName = "unwrap",
- methodArgs = {ByteBuffer.class, ByteBuffer.class}
- ),
- @TestTarget(
- methodName = "unwrap",
- methodArgs = {ByteBuffer.class, ByteBuffer[].class}
- )
-
- })
- public void test_unwrapLjava_nio_ByteBufferLjava_nio_ByteBuffer02() throws SSLException {
- ByteBuffer bbs = ByteBuffer.allocate(100);
- ByteBuffer bbd = ByteBuffer.allocate(10);
- SSLEngine e = new mySSLEngine1();
- try {
- e.unwrap(bbs, bbd);
- fail("SSLException must be thrown");
- } catch (SSLException ex) {
- }
- SSLEngineResult res = e.unwrap(bbd, bbs);
- assertEquals(1, res.bytesConsumed());
- assertEquals(2, res.bytesProduced());
-
- try {
- e.unwrap(bbs, new ByteBuffer[] { bbd });
- fail("SSLException must be thrown");
- } catch (SSLException ex) {
- }
- res = e.unwrap(bbd, new ByteBuffer[] { bbs });
- assertEquals(1, res.bytesConsumed());
- assertEquals(2, res.bytesProduced());
- }
-
- /**
- * Test for <code>unwrap(ByteBuffer src, ByteBuffer dst)</code> method
- *
- * Assertion: decodes network data into a data buffer.
- */
- @TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "IllegalStateException checking missed",
- targets = {
- @TestTarget(
- methodName = "unwrap",
- methodArgs = {ByteBuffer.class, ByteBuffer.class}
- )
- })
- public void test_unwrapLjava_nio_ByteBufferLjava_nio_ByteBuffer03() throws SSLException {
- String host = "new host";
- int port = 8080;
- ByteBuffer bb = ByteBuffer.allocate(10);
- SSLEngine e = new mySSLEngine(host, port);
- SSLEngineResult res = e.unwrap(bb, ByteBuffer.allocate(10));
+ SSLEngine sse = new mySSLEngine1();
+ sse.setUseClientMode(true);
- assertEquals(1, res.bytesConsumed());
- assertEquals(2, res.bytesProduced());
+ try {
+ sse.unwrap(bbs, new ByteBuffer[] { bbd }, 0, 10);
+ fail("SSLException wasn't thrown");
+ } catch (SSLException ex) {
+ //expected
+ }
}
/**
- * Test for <code>unwrap(ByteBuffer src, ByteBuffer[] dsts)</code> method
- *
- * Assertions: throws IllegalArgumentException if parameters are null or
- * when dsts contains null elements throws ReadOnlyBufferException when dsts
- * contains read only elements
- *
- * Check that implementation behavior follows RI:
- * jdk 1.5 does not throw IllegalArgumentException when src is null or
- * if dsts contains null elements It does not throw ReadOnlyBufferException
- * when dsts contains read only elements
+ * @tests javax.net.ssl.SSLEngine#unwrap(ByteBuffer src, ByteBuffer[] dsts,
+ * int offset, int length)
+ * Exception case: IndexOutOfBoundsException should be thrown.
*/
- @TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "IllegalStateException checking missed",
- targets = {
- @TestTarget(
- methodName = "unwrap",
- methodArgs = {ByteBuffer.class, ByteBuffer[].class}
- )
- })
- public void test_unwrapLjava_nio_ByteBuffer$Ljava_nio_ByteBuffer01() throws SSLException {
- String host = "new host";
- int port = 8080;
- ByteBuffer[] bbNA = null;
- ByteBuffer[] bbA = { null, ByteBuffer.allocate(10), null };
-
- ByteBuffer bb = ByteBuffer.allocate(10);
- ByteBuffer bbN = null;
- SSLEngine e = new mySSLEngine(host, port);
- try {
- e.unwrap(bb, bbNA);
- fail("IllegalArgumentException must be thrown for null dsts byte buffer array");
- } catch (IllegalArgumentException ex) {
- }
-
- e.unwrap(bb, bbA);
- e.unwrap(bbN, bbA);
-
- ByteBuffer bb1 = ByteBuffer.allocate(100);
- ByteBuffer roBb = bb1.asReadOnlyBuffer();
- bbA[0] = bb1;
- bbA[2] = roBb;
- assertTrue("Not read only byte buffer", bbA[2].isReadOnly());
-
- e.unwrap(bb, bbA);
-
- }
-
- /**
- * Test for <code>unwrap(ByteBuffer src, ByteBuffer[] dsts)</code> method
- *
- * Assertion:
- * decode network data into data buffers.
- */
- @TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "IllegalStateException checking missed",
- targets = {
- @TestTarget(
- methodName = "unwrap",
- methodArgs = {ByteBuffer.class, ByteBuffer[].class}
- )
- })
- public void test_unwrapLjava_nio_ByteBuffer$Ljava_nio_ByteBuffer02() throws SSLException {
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "unwrap",
+ args = {ByteBuffer.class, ByteBuffer[].class, int.class, int.class}
+ )
+ public void test_unwrap_02() throws SSLException {
String host = "new host";
int port = 8080;
ByteBuffer[] bbA = { ByteBuffer.allocate(100), ByteBuffer.allocate(10), ByteBuffer.allocate(100) };
ByteBuffer bb = ByteBuffer.allocate(10);
- SSLEngine e = new mySSLEngine(host, port);
+ SSLEngine sse = new mySSLEngine1(host, port);
+ sse.setUseClientMode(true);
+
+ try {
+ SSLEngineResult res = sse.unwrap(bb, bbA, -1, 3);
+ fail("IndexOutOfBoundsException wasn't thrown");
+ } catch (IndexOutOfBoundsException iobe) {
+ //expected
+ }
+ try {
+ SSLEngineResult res = sse.unwrap(bb, bbA, 0, -3);
+ fail("IndexOutOfBoundsException wasn't thrown");
+ } catch (IndexOutOfBoundsException iobe) {
+ //expected
+ }
+ try {
+ SSLEngineResult res = sse.unwrap(bb, bbA, bbA.length + 1, bbA.length);
+ fail("IndexOutOfBoundsException wasn't thrown");
+ } catch (IndexOutOfBoundsException iobe) {
+ //expected
+ }
+ try {
+ SSLEngineResult res = sse.unwrap(bb, bbA, 0, bbA.length + 1);
+ fail("IndexOutOfBoundsException wasn't thrown");
+ } catch (IndexOutOfBoundsException iobe) {
+ //expected
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLEngine#unwrap(ByteBuffer src, ByteBuffer[] dsts,
+ * int offset, int length)
+ * Exception case: ReadOnlyBufferException should be thrown.
+ */
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "unwrap",
+ args = {ByteBuffer.class, ByteBuffer[].class, int.class, int.class}
+ )
+ public void test_unwrap_03() {
+ String host = "new host";
+ int port = 8080;
+ ByteBuffer bbR = ByteBuffer.allocate(100).asReadOnlyBuffer();
+ ByteBuffer[] bbA = { bbR, ByteBuffer.allocate(10), ByteBuffer.allocate(100) };
- SSLEngineResult res = e.unwrap(bb, bbA);
- assertEquals(1, res.bytesConsumed());
- assertEquals(2, res.bytesProduced());
+ ByteBuffer bb = ByteBuffer.allocate(10);
+ SSLEngine sse = new mySSLEngine1(host, port);
+ sse.setUseClientMode(true);
+
+ try {
+ SSLEngineResult res = sse.unwrap(bb, bbA, 0, bbA.length);
+ fail("ReadOnlyBufferException wasn't thrown");
+ } catch (ReadOnlyBufferException iobe) {
+ //expected
+ } catch (Exception e) {
+ fail(e + " was thrown instead of ReadOnlyBufferException");
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLEngine#unwrap(ByteBuffer src, ByteBuffer[] dsts,
+ * int offset, int length)
+ * Exception case: IllegalArgumentException should be thrown.
+ */
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "IllegalArgumentException should be thrown",
+ method = "unwrap",
+ args = {ByteBuffer.class, ByteBuffer[].class, int.class, int.class}
+ )
+ @AndroidOnly("NullPointerException was thrown instead of IllegalArgumentException for null parameter.")
+ public void test_unwrap_04() {
+ String host = "new host";
+ int port = 8080;
+ ByteBuffer[] bbA = {ByteBuffer.allocate(100), ByteBuffer.allocate(10), ByteBuffer.allocate(100)};
+ ByteBuffer[] bbAN = {ByteBuffer.allocate(100), null, ByteBuffer.allocate(100)};
+ ByteBuffer[] bbN = null;
+ ByteBuffer bb = ByteBuffer.allocate(10);
+ ByteBuffer bN = null;
+ SSLEngine sse = new mySSLEngine1(host, port);
+ sse.setUseClientMode(true);
+
+ try {
+ SSLEngineResult res = sse.unwrap(bN, bbA, 0, 3);
+ fail("IllegalArgumentException wasn't thrown");
+ } catch (IllegalArgumentException iobe) {
+ //expected
+ } catch (NullPointerException npe) {
+ } catch (Exception e) {
+ fail(e + " was thrown instead of IllegalArgumentException");
+ }
+ try {
+ SSLEngineResult res = sse.unwrap(bb, bbAN, 0, 3);
+ fail("IllegalArgumentException wasn't thrown");
+ } catch (IllegalArgumentException iobe) {
+ //expected
+ } catch (NullPointerException npe) {
+ } catch (Exception e) {
+ fail(e + " was thrown instead of IllegalArgumentException");
+ }
+ try {
+ SSLEngineResult res = sse.unwrap(bb, bbN, 0, 0);
+ fail("IllegalArgumentException wasn't thrown");
+ } catch (IllegalArgumentException iobe) {
+ //expected
+ } catch (NullPointerException npe) {
+ } catch (Exception e) {
+ fail(e + " was thrown instead of IllegalArgumentException");
+ }
+ try {
+ SSLEngineResult res = sse.unwrap(bN, bbN, 0, 0);
+ fail("IllegalArgumentException wasn't thrown");
+ } catch (IllegalArgumentException iobe) {
+ //expected
+ } catch (NullPointerException npe) {
+ } catch (Exception e) {
+ fail(e + " was thrown instead of IllegalArgumentException");
+ }
+
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLEngine#unwrap(ByteBuffer src, ByteBuffer[] dsts,
+ * int offset, int length)
+ * Exception case: IllegalStateException should be thrown.
+ */
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "unwrap",
+ args = {ByteBuffer.class, ByteBuffer[].class, int.class, int.class}
+ )
+ public void test_unwrap_05() {
+ String host = "new host";
+ int port = 8080;
+ ByteBuffer[] bbA = { ByteBuffer.allocate(100), ByteBuffer.allocate(10), ByteBuffer.allocate(100) };
+
+ ByteBuffer bb = ByteBuffer.allocate(10);
+ SSLEngine sse = new mySSLEngine1(host, port);
+
+ try {
+ SSLEngineResult res = sse.unwrap(bb, bbA, 0, bbA.length);
+ fail("IllegalStateException wasn't thrown");
+ } catch (IllegalStateException iobe) {
+ //expected
+ } catch (Exception e) {
+ fail(e + " was thrown instead of IllegalStateException");
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLEngine#unwrap(ByteBuffer src, ByteBuffer[] dsts,
+ * int offset, int length)
+ */
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "unwrap",
+ args = {ByteBuffer.class, ByteBuffer[].class, int.class, int.class}
+ )
+ public void test_unwrap_06() {
+ String host = "new host";
+ int port = 8080;
+ ByteBuffer[] bbA = { ByteBuffer.allocate(100), ByteBuffer.allocate(10), ByteBuffer.allocate(100) };
+
+ ByteBuffer bb = ByteBuffer.allocate(10);
+ SSLEngine sse = new mySSLEngine1(host, port);
+ sse.setUseClientMode(true);
+
+ try {
+ SSLEngineResult res = sse.unwrap(bb, bbA, 0, bbA.length);
+ assertEquals(1, res.bytesConsumed());
+ assertEquals(2, res.bytesProduced());
+ } catch (Exception ex) {
+ fail("Unexpected exception: " + ex);
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLEngine#wrap(ByteBuffer[] srcs, int offset,
+ * int length, ByteBuffer dst)
+ * Exception case: SSLException should be thrown.
+ */
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "wrap",
+ args = {ByteBuffer[].class, int.class, int.class, ByteBuffer.class}
+ )
+ public void test_wrap_01() {
+ ByteBuffer bbs = ByteBuffer.allocate(100);
+ ByteBuffer bbd = ByteBuffer.allocate(10);
+ SSLEngine sse = new mySSLEngine1();
+ sse.setUseClientMode(true);
+
+ try {
+ sse.wrap(new ByteBuffer[] { bbs }, 0, 100, bbd);
+ fail("SSLException wasn't thrown");
+ } catch (SSLException ex) {
+ //expected
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLEngine#wrap(ByteBuffer[] srcs, int offset,
+ * int length, ByteBuffer dst)
+ * Exception case: IndexOutOfBoundsException should be thrown.
+ */
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "wrap",
+ args = {ByteBuffer[].class, int.class, int.class, ByteBuffer.class}
+ )
+ public void test_wrap_02() throws SSLException {
+ String host = "new host";
+ int port = 8080;
+ ByteBuffer bb = ByteBuffer.allocate(10);
+ ByteBuffer[] bbA = {ByteBuffer.allocate(5), ByteBuffer.allocate(10), ByteBuffer.allocate(5)};
+ SSLEngine sse = new mySSLEngine1(host, port);
+ sse.setUseClientMode(true);
+
+ try {
+ SSLEngineResult res = sse.wrap(bbA, -1, 3, bb);
+ fail("IndexOutOfBoundsException wasn't thrown");
+ } catch (IndexOutOfBoundsException iobe) {
+ //expected
+ }
+ try {
+ SSLEngineResult res = sse.wrap(bbA, 0, -3, bb);
+ fail("IndexOutOfBoundsException wasn't thrown");
+ } catch (IndexOutOfBoundsException iobe) {
+ //expected
+ }
+ try {
+ SSLEngineResult res = sse.wrap(bbA, bbA.length + 1, bbA.length, bb);
+ fail("IndexOutOfBoundsException wasn't thrown");
+ } catch (IndexOutOfBoundsException iobe) {
+ //expected
+ }
+ try {
+ SSLEngineResult res = sse.wrap(bbA, 0, bbA.length + 1, bb);
+ fail("IndexOutOfBoundsException wasn't thrown");
+ } catch (IndexOutOfBoundsException iobe) {
+ //expected
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLEngine#wrap(ByteBuffer[] srcs, int offset,
+ * int length, ByteBuffer dst)
+ * Exception case: ReadOnlyBufferException should be thrown.
+ */
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "wrap",
+ args = {ByteBuffer[].class, int.class, int.class, ByteBuffer.class}
+ )
+ public void test_wrap_03() throws SSLException {
+ String host = "new host";
+ int port = 8080;
+ ByteBuffer bb = ByteBuffer.allocate(10).asReadOnlyBuffer();
+ ByteBuffer[] bbA = {ByteBuffer.allocate(5), ByteBuffer.allocate(10), ByteBuffer.allocate(5)};
+ SSLEngine sse = new mySSLEngine1(host, port);
+ sse.setUseClientMode(true);
+
+ try {
+ SSLEngineResult res = sse.wrap(bbA, 0, bbA.length, bb);
+ fail("ReadOnlyBufferException wasn't thrown");
+ } catch (ReadOnlyBufferException iobe) {
+ //expected
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLEngine#wrap(ByteBuffer[] srcs, int offset,
+ * int length, ByteBuffer dst)
+ * Exception case: IllegalArgumentException should be thrown.
+ */
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "IllegalArgumentException must be thrown",
+ method = "wrap",
+ args = {ByteBuffer[].class, int.class, int.class, ByteBuffer.class}
+ )
+ @AndroidOnly("NullPointerException was thrown instead of IllegalArgumentException for null parameter.")
+ public void test_wrap_04() {
+ String host = "new host";
+ int port = 8080;
+ ByteBuffer[] bbA = {ByteBuffer.allocate(100), ByteBuffer.allocate(10), ByteBuffer.allocate(100)};
+ ByteBuffer[] bbAN = {ByteBuffer.allocate(100), null, ByteBuffer.allocate(100)};
+ ByteBuffer[] bbN = null;
+ ByteBuffer bb = ByteBuffer.allocate(10);
+ ByteBuffer bN = null;
+ SSLEngine e = new mySSLEngine1(host, port);
+ e.setUseClientMode(true);
+
+ try {
+ e.wrap(bbA, 0, 3, bN);
+ fail("IllegalArgumentException must be thrown for null srcs byte buffer array");
+ } catch (NullPointerException npe) {
+ } catch (IllegalArgumentException ex) {
+ } catch (Exception ex) {
+ fail(ex + " was thrown instead of IllegalArgumentException");
+ }
+
+ try {
+ e.wrap(bbN, 0, 0, bN);
+ fail("IllegalArgumentException wasn't thrown");
+ } catch (IllegalArgumentException ex) {
+ } catch (NullPointerException npe) {
+ } catch (Exception ex) {
+ fail(ex + " was thrown instead of IllegalArgumentException");
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLEngine#wrap(ByteBuffer[] srcs, int offset,
+ * int length, ByteBuffer dst)
+ * Exception case: IllegalStateException should be thrown.
+ */
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "wrap",
+ args = {ByteBuffer[].class, int.class, int.class, ByteBuffer.class}
+ )
+ public void test_wrap_05() throws SSLException {
+ String host = "new host";
+ int port = 8080;
+ ByteBuffer bb = ByteBuffer.allocate(10);
+ ByteBuffer[] bbA = {ByteBuffer.allocate(5), ByteBuffer.allocate(10), ByteBuffer.allocate(5)};
+ SSLEngine sse = new mySSLEngine1(host, port);
+
+ try {
+ SSLEngineResult res = sse.wrap(bbA, 0, bbA.length, bb);
+ fail("IllegalStateException wasn't thrown");
+ } catch (IllegalStateException iobe) {
+ //expected
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLEngine#wrap(ByteBuffer[] srcs, int offset,
+ * int length, ByteBuffer dst)
+ */
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "wrap",
+ args = {ByteBuffer[].class, int.class, int.class, ByteBuffer.class}
+ )
+ public void test_wrap_06() {
+ String host = "new host";
+ int port = 8080;
+ ByteBuffer bb = ByteBuffer.allocate(10);
+ ByteBuffer[] bbA = {ByteBuffer.allocate(5), ByteBuffer.allocate(10), ByteBuffer.allocate(5)};
+ SSLEngine sse = new mySSLEngine1(host, port);
+ sse.setUseClientMode(true);
+
+ try {
+ SSLEngineResult res = sse.wrap(bbA, 0, bbA.length, bb);
+ } catch (Exception ex) {
+ fail("Unexpected exception: " + ex);
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLEngine#closeOutbound()
+ * @tests javax.net.ssl.SSLEngine#isOutboundDone()
+ */
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "closeOutbound",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "isOutboundDone",
+ args = {}
+ )
+ })
+ public void test_closeOutbound() {
+ SSLEngine sse = new mySSLEngine();
+
+ try {
+ assertFalse(sse.isOutboundDone());
+ sse.closeOutbound();
+ assertTrue(sse.isOutboundDone());
+ } catch (Exception ex) {
+ fail("Unexpected exception: " + ex);
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLEngine#closeInbound()
+ * @tests javax.net.ssl.SSLEngine#isInboundDone()
+ */
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.SUFFICIENT,
+ notes = "",
+ method = "closeInbound",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "isInboundDone",
+ args = {}
+ )
+ })
+ public void test_closeInbound() {
+ SSLEngine sse = new mySSLEngine();
+
+ try {
+ assertFalse(sse.isInboundDone());
+ sse.closeInbound();
+ assertTrue(sse.isInboundDone());
+ } catch (Exception ex) {
+ fail("Unexpected exception: " + ex);
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLEngine#unwrap(ByteBuffer src, ByteBuffer dst)
+ * SSLException should be thrown.
+ */
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "unwrap",
+ args = {ByteBuffer.class, ByteBuffer.class}
+ )
+ public void test_unwrap_ByteBuffer_ByteBuffer_01() {
+ ByteBuffer bbs = ByteBuffer.allocate(100);
+ ByteBuffer bbd = ByteBuffer.allocate(10);
+ SSLEngine sse = new mySSLEngine1();
+ sse.setUseClientMode(true);
+
+ try {
+ sse.unwrap(bbs, bbd);
+ fail("SSLException wasn't thrown");
+ } catch (SSLException ex) {
+ //expected
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLEngine#unwrap(ByteBuffer src, ByteBuffer dst)
+ * ReadOnlyBufferException should be thrown.
+ */
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "unwrap",
+ args = {ByteBuffer.class, ByteBuffer.class}
+ )
+ public void test_unwrap_ByteBuffer_ByteBuffer_02() {
+ String host = "new host";
+ int port = 8080;
+ ByteBuffer bbs = ByteBuffer.allocate(10);
+ ByteBuffer bbd = ByteBuffer.allocate(100).asReadOnlyBuffer();
+ SSLEngine sse = new mySSLEngine1(host, port);
+ sse.setUseClientMode(true);
+
+ try {
+ SSLEngineResult res = sse.unwrap(bbs, bbd);
+ fail("ReadOnlyBufferException wasn't thrown");
+ } catch (ReadOnlyBufferException iobe) {
+ //expected
+ } catch (Exception e) {
+ fail(e + " was thrown instead of ReadOnlyBufferException");
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLEngine#unwrap(ByteBuffer src, ByteBuffer dst)
+ * IllegalArgumentException should be thrown.
+ */
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "unwrap",
+ args = {ByteBuffer.class, ByteBuffer.class}
+ )
+ @AndroidOnly("NullPointerException was thrown instead of IllegalArgumentException for null parameter.")
+ public void test_unwrap_ByteBuffer_ByteBuffer_03() {
+ String host = "new host";
+ int port = 8080;
+ ByteBuffer bbsN = null;
+ ByteBuffer bbdN = null;
+ ByteBuffer bbs = ByteBuffer.allocate(10);
+ ByteBuffer bbd = ByteBuffer.allocate(100);
+ SSLEngine sse = new mySSLEngine1(host, port);
+ sse.setUseClientMode(true);
+
+ try {
+ SSLEngineResult res = sse.unwrap(bbsN, bbd);
+ fail("IllegalArgumentException wasn't thrown");
+ } catch (IllegalArgumentException iae) {
+ //expected
+ } catch (NullPointerException npe) {
+ } catch (Exception e) {
+ fail(e + " was thrown instead of IllegalArgumentException");
+ }
+
+ try {
+ SSLEngineResult res = sse.unwrap(bbs, bbdN);
+ fail("IllegalArgumentException wasn't thrown");
+ } catch (IllegalArgumentException iae) {
+ //expected
+ } catch (NullPointerException npe) {
+ } catch (Exception e) {
+ fail(e + " was thrown instead of IllegalArgumentException");
+ }
+
+ try {
+ SSLEngineResult res = sse.unwrap(bbsN, bbdN);
+ fail("IllegalArgumentException wasn't thrown");
+ } catch (IllegalArgumentException iae) {
+ //expected
+ } catch (NullPointerException npe) {
+ } catch (Exception e) {
+ fail(e + " was thrown instead of IllegalArgumentException");
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLEngine#unwrap(ByteBuffer src, ByteBuffer dst)
+ * IllegalStateException should be thrown.
+ */
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "unwrap",
+ args = {ByteBuffer.class, ByteBuffer.class}
+ )
+ public void test_unwrap_ByteBuffer_ByteBuffer_04() {
+ String host = "new host";
+ int port = 8080;
+ ByteBuffer bbs = ByteBuffer.allocate(10);
+ ByteBuffer bbd = ByteBuffer.allocate(100);
+ SSLEngine sse = new mySSLEngine1(host, port);
+
+ try {
+ SSLEngineResult res = sse.unwrap(bbs, bbd);
+ fail("IllegalStateException wasn't thrown");
+ } catch (IllegalStateException iobe) {
+ //expected
+ } catch (Exception e) {
+ fail(e + " was thrown instead of IllegalStateException");
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLEngine#unwrap(ByteBuffer src, ByteBuffer dst)
+ */
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "unwrap",
+ args = {ByteBuffer.class, ByteBuffer.class}
+ )
+ public void test_unwrap_ByteBuffer_ByteBuffer_05() {
+ String host = "new host";
+ int port = 8080;
+ ByteBuffer bbs = ByteBuffer.allocate(10);
+ ByteBuffer bbd = ByteBuffer.allocate(100);
+ SSLEngine sse = new mySSLEngine1(host, port);
+ sse.setUseClientMode(true);
+
+ try {
+ SSLEngineResult res = sse.unwrap(bbs, bbd);
+ assertEquals(1, res.bytesConsumed());
+ assertEquals(2, res.bytesProduced());
+ } catch (Exception e) {
+ fail("Unexpected exception: " + e);
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLEngine#unwrap(ByteBuffer src, ByteBuffer[] dsts)
+ * SSLException should be thrown.
+ */
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "unwrap",
+ args = {ByteBuffer.class, ByteBuffer[].class}
+ )
+ public void test_unwrap_ByteBuffer$ByteBuffer_01() {
+ ByteBuffer bbs = ByteBuffer.allocate(100);
+ ByteBuffer bbd = ByteBuffer.allocate(10);
+ SSLEngine sse = new mySSLEngine1();
+ sse.setUseClientMode(true);
+
+ try {
+ sse.unwrap(bbs, new ByteBuffer[] { bbd });
+ fail("SSLException wasn't thrown");
+ } catch (SSLException ex) {
+ //expected
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLEngine#unwrap(ByteBuffer src, ByteBuffer[] dsts)
+ * ReadOnlyBufferException should be thrown.
+ */
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "unwrap",
+ args = {ByteBuffer.class, ByteBuffer[].class}
+ )
+ public void test_unwrap_ByteBuffer$ByteBuffer_02() {
+ String host = "new host";
+ int port = 8080;
+ ByteBuffer bbs = ByteBuffer.allocate(10);
+ ByteBuffer bbR = ByteBuffer.allocate(100).asReadOnlyBuffer();
+ ByteBuffer[] bbA = { bbR, ByteBuffer.allocate(10), ByteBuffer.allocate(100) };
+ SSLEngine sse = new mySSLEngine1(host, port);
+ sse.setUseClientMode(true);
+
+ try {
+ SSLEngineResult res = sse.unwrap(bbs, bbA);
+ fail("ReadOnlyBufferException wasn't thrown");
+ } catch (ReadOnlyBufferException iobe) {
+ //expected
+ } catch (Exception e) {
+ fail(e + " was thrown instead of ReadOnlyBufferException");
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLEngine#unwrap(ByteBuffer src, ByteBuffer[] dsts)
+ * IllegalArgumentException should be thrown.
+ */
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "unwrap",
+ args = {ByteBuffer.class, ByteBuffer[].class}
+ )
+ @AndroidOnly("NullPointerException was thrown instead of IllegalArgumentException for null parameter.")
+ public void test_unwrap_ByteBuffer$ByteBuffer_03() {
+ String host = "new host";
+ int port = 8080;
+ ByteBuffer[] bbA = { ByteBuffer.allocate(100), ByteBuffer.allocate(10), ByteBuffer.allocate(100) };
+ ByteBuffer[] bbN = { ByteBuffer.allocate(100), null, ByteBuffer.allocate(100) };
+ ByteBuffer[] bbAN = null;
+ ByteBuffer bb = ByteBuffer.allocate(10);
+ ByteBuffer bN = null;
+ SSLEngine sse = new mySSLEngine1(host, port);
+ sse.setUseClientMode(true);
+
+ try {
+ SSLEngineResult res = sse.unwrap(bN, bbA);
+ fail("IllegalArgumentException wasn't thrown");
+ } catch (IllegalArgumentException iobe) {
+ //expected
+ } catch (NullPointerException npe) {
+ } catch (Exception e) {
+ fail(e + " was thrown instead of IllegalArgumentException");
+ }
+
+ try {
+ SSLEngineResult res = sse.unwrap(bb, bbAN);
+ fail("IllegalArgumentException wasn't thrown");
+ } catch (IllegalArgumentException iobe) {
+ //expected
+ } catch (NullPointerException npe) {
+ } catch (Exception e) {
+ fail(e + " was thrown instead of IllegalArgumentException");
+ }
+
+ try {
+ SSLEngineResult res = sse.unwrap(bb, bbN);
+ fail("IllegalArgumentException wasn't thrown");
+ } catch (IllegalArgumentException iobe) {
+ //expected
+ } catch (NullPointerException npe) {
+ } catch (Exception e) {
+ fail(e + " was thrown instead of IllegalArgumentException");
+ }
+
+ try {
+ SSLEngineResult res = sse.unwrap(bN, bbAN);
+ fail("IllegalArgumentException wasn't thrown");
+ } catch (IllegalArgumentException iobe) {
+ //expected
+ } catch (NullPointerException npe) {
+ } catch (Exception e) {
+ fail(e + " was thrown instead of IllegalArgumentException");
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLEngine#unwrap(ByteBuffer src, ByteBuffer[] dsts)
+ * IllegalStateException should be thrown.
+ */
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "unwrap",
+ args = {ByteBuffer.class, ByteBuffer[].class}
+ )
+ public void test_unwrap_ByteBuffer$ByteBuffer_04() {
+ String host = "new host";
+ int port = 8080;
+ ByteBuffer bbs = ByteBuffer.allocate(10);
+ ByteBuffer[] bbd = {ByteBuffer.allocate(100), ByteBuffer.allocate(10), ByteBuffer.allocate(100) };
+ SSLEngine sse = new mySSLEngine1(host, port);
+
+ try {
+ SSLEngineResult res = sse.unwrap(bbs, bbd);
+ fail("IllegalStateException wasn't thrown");
+ } catch (IllegalStateException iobe) {
+ //expected
+ } catch (Exception e) {
+ fail(e + " was thrown instead of IllegalStateException");
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLEngine#unwrap(ByteBuffer src, ByteBuffer[] dsts)
+ */
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "unwrap",
+ args = {ByteBuffer.class, ByteBuffer[].class}
+ )
+ public void test_unwrap_ByteBuffer$ByteBuffer_05() {
+ String host = "new host";
+ int port = 8080;
+ ByteBuffer bbs = ByteBuffer.allocate(10);
+ ByteBuffer[] bbd = {ByteBuffer.allocate(100), ByteBuffer.allocate(10), ByteBuffer.allocate(100) };
+ SSLEngine sse = new mySSLEngine1(host, port);
+ sse.setUseClientMode(true);
+
+ try {
+ SSLEngineResult res = sse.unwrap(bbs, bbd);
+ assertEquals(1, res.bytesConsumed());
+ assertEquals(2, res.bytesProduced());
+ } catch (Exception ex) {
+ fail("Unexpected exception: " + ex);
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLEngine#wrap(ByteBuffer src, ByteBuffer dst)
+ * SSLException should be thrown.
+ */
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "wrap",
+ args = {ByteBuffer.class, ByteBuffer.class}
+ )
+ public void test_wrap_ByteBuffer_ByteBuffer_01() {
+ ByteBuffer bbs = ByteBuffer.allocate(100);
+ ByteBuffer bbd = ByteBuffer.allocate(10);
+ SSLEngine sse = new mySSLEngine1();
+ sse.setUseClientMode(true);
+
+ try {
+ sse.wrap(bbs, bbd);
+ fail("SSLException wasn't thrown");
+ } catch (SSLException ex) {
+ //expected
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLEngine#wrap(ByteBuffer src, ByteBuffer dst)
+ * ReadOnlyBufferException should be thrown.
+ */
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "wrap",
+ args = {ByteBuffer.class, ByteBuffer.class}
+ )
+ public void test_wrap_ByteBuffer_ByteBuffer_02() {
+ String host = "new host";
+ int port = 8080;
+ ByteBuffer bbs = ByteBuffer.allocate(10);
+ ByteBuffer bbd = ByteBuffer.allocate(100).asReadOnlyBuffer();
+ SSLEngine sse = new mySSLEngine1(host, port);
+ sse.setUseClientMode(true);
+
+ try {
+ SSLEngineResult res = sse.wrap(bbs, bbd);
+ fail("ReadOnlyBufferException wasn't thrown");
+ } catch (ReadOnlyBufferException iobe) {
+ //expected
+ } catch (Exception e) {
+ fail(e + " was thrown instead of ReadOnlyBufferException");
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLEngine#wrap(ByteBuffer src, ByteBuffer dst)
+ * IllegalArgumentException should be thrown.
+ */
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "wrap",
+ args = {ByteBuffer.class, ByteBuffer.class}
+ )
+ @AndroidOnly("NullPointerException was thrown instead of IllegalArgumentException for null parameter.")
+ public void test_wrap_ByteBuffer_ByteBuffer_03() {
+ String host = "new host";
+ int port = 8080;
+ ByteBuffer bbsN = null;
+ ByteBuffer bbdN = null;
+ ByteBuffer bbs = ByteBuffer.allocate(10);
+ ByteBuffer bbd = ByteBuffer.allocate(100);
+ SSLEngine sse = new mySSLEngine1(host, port);
+ sse.setUseClientMode(true);
+
+ try {
+ SSLEngineResult res = sse.wrap(bbsN, bbd);
+ fail("IllegalArgumentException wasn't thrown");
+ } catch (IllegalArgumentException iae) {
+ //expected
+ } catch (NullPointerException npe) {
+ } catch (Exception e) {
+ fail(e + " was thrown instead of IllegalArgumentException");
+ }
+
+ try {
+ SSLEngineResult res = sse.wrap(bbs, bbdN);
+ fail("IllegalArgumentException wasn't thrown");
+ } catch (IllegalArgumentException iae) {
+ //expected
+ } catch (NullPointerException npe) {
+ } catch (Exception e) {
+ fail(e + " was thrown instead of IllegalArgumentException");
+ }
+
+ try {
+ SSLEngineResult res = sse.wrap(bbsN, bbdN);
+ fail("IllegalArgumentException wasn't thrown");
+ } catch (IllegalArgumentException iae) {
+ //expected
+ } catch (NullPointerException npe) {
+ } catch (Exception e) {
+ fail(e + " was thrown instead of IllegalArgumentException");
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLEngine#wrap(ByteBuffer src, ByteBuffer dst)
+ * IllegalStateException should be thrown.
+ */
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "wrap",
+ args = {ByteBuffer.class, ByteBuffer.class}
+ )
+ public void test_wrap_ByteBuffer_ByteBuffer_04() {
+ String host = "new host";
+ int port = 8080;
+ ByteBuffer bbs = ByteBuffer.allocate(10);
+ ByteBuffer bbd = ByteBuffer.allocate(10);
+ SSLEngine sse = new mySSLEngine1(host, port);
+
+ try {
+ SSLEngineResult res = sse.wrap(bbs, bbd);
+ fail("IllegalStateException wasn't thrown");
+ } catch (IllegalStateException iobe) {
+ //expected
+ } catch (Exception e) {
+ fail(e + " was thrown instead of IllegalStateException");
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLEngine#wrap(ByteBuffer src, ByteBuffer dst)
+ */
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "wrap",
+ args = {ByteBuffer.class, ByteBuffer.class}
+ )
+ public void test_wrap_ByteBuffer_ByteBuffer_05() {
+ String host = "new host";
+ int port = 8080;
+ ByteBuffer bb = ByteBuffer.allocate(10);
+ SSLEngine sse = new mySSLEngine1(host, port);
+ sse.setUseClientMode(true);
+
+ try {
+ SSLEngineResult res = sse.wrap(bb, ByteBuffer.allocate(10));
+ assertEquals(10, res.bytesConsumed());
+ assertEquals(20, res.bytesProduced());
+ } catch (Exception e) {
+ fail("Unexpected exception: " + e);
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLEngine#wrap(ByteBuffer[] srcs, ByteBuffer dst)
+ * SSLException should be thrown.
+ */
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "wrap",
+ args = {ByteBuffer[].class, ByteBuffer.class}
+ )
+ public void test_wrap_ByteBuffer$ByteBuffer_01() {
+ ByteBuffer bbs = ByteBuffer.allocate(100);
+ ByteBuffer bbd = ByteBuffer.allocate(10);
+ SSLEngine sse = new mySSLEngine1();
+ sse.setUseClientMode(true);
+
+ try {
+ sse.wrap(new ByteBuffer[] { bbs }, bbd);
+ fail("SSLException wasn't thrown");
+ } catch (SSLException ex) {
+ //expected
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLEngine#wrap(ByteBuffer[] srcs, ByteBuffer dst)
+ * ReadOnlyBufferException should be thrown.
+ */
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "wrap",
+ args = {ByteBuffer[].class, ByteBuffer.class}
+ )
+ public void test_wrap_ByteBuffer$ByteBuffer_02() {
+ String host = "new host";
+ int port = 8080;
+ ByteBuffer bb = ByteBuffer.allocate(10).asReadOnlyBuffer();
+ ByteBuffer[] bbA = {ByteBuffer.allocate(5), ByteBuffer.allocate(10), ByteBuffer.allocate(5)};
+ SSLEngine sse = new mySSLEngine1(host, port);
+ sse.setUseClientMode(true);
+
+ try {
+ SSLEngineResult res = sse.wrap(bbA, bb);
+ fail("ReadOnlyBufferException wasn't thrown");
+ } catch (ReadOnlyBufferException iobe) {
+ //expected
+ } catch (Exception e) {
+ fail(e + " was thrown instead of ReadOnlyBufferException");
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLEngine#wrap(ByteBuffer[] srcs, ByteBuffer dst)
+ * IllegalArgumentException should be thrown.
+ */
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "wrap",
+ args = {ByteBuffer[].class, ByteBuffer.class}
+ )
+ @AndroidOnly("NullPointerException was thrown instead of IllegalArgumentException for null parameter.")
+ public void test_wrap_ByteBuffer$ByteBuffer_03() {
+ String host = "new host";
+ int port = 8080;
+ ByteBuffer[] bbA = {ByteBuffer.allocate(100), ByteBuffer.allocate(10), ByteBuffer.allocate(100)};
+ ByteBuffer[] bbN = {ByteBuffer.allocate(100), null, ByteBuffer.allocate(100)};
+ ByteBuffer[] bbAN = null;
+ ByteBuffer bb = ByteBuffer.allocate(10);
+ ByteBuffer bN = null;
+ SSLEngine sse = new mySSLEngine1(host, port);
+ sse.setUseClientMode(true);
+
+ try {
+ SSLEngineResult res = sse.wrap(bbA, bN);
+ fail("IllegalArgumentException wasn't thrown");
+ } catch (IllegalArgumentException iobe) {
+ //expected
+ } catch (NullPointerException npe) {
+ } catch (Exception e) {
+ fail(e + " was thrown instead of IllegalArgumentException");
+ }
+
+ try {
+ SSLEngineResult res = sse.wrap(bbAN, bb);
+ fail("IllegalArgumentException wasn't thrown");
+ } catch (IllegalArgumentException iobe) {
+ //expected
+ } catch (NullPointerException npe) {
+ } catch (Exception e) {
+ fail(e + " was thrown instead of IllegalArgumentException");
+ }
+
+ try {
+ SSLEngineResult res = sse.wrap(bbAN, bN);
+ fail("IllegalArgumentException wasn't thrown");
+ } catch (IllegalArgumentException iobe) {
+ //expected
+ } catch (NullPointerException npe) {
+ } catch (Exception e) {
+ fail(e + " was thrown instead of IllegalArgumentException");
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLEngine#wrap(ByteBuffer[] srcs, ByteBuffer dst)
+ * IllegalStateException should be thrown.
+ */
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "wrap",
+ args = {ByteBuffer[].class, ByteBuffer.class}
+ )
+ public void test_wrap_ByteBuffer$ByteBuffer_04() {
+ String host = "new host";
+ int port = 8080;
+ ByteBuffer bb = ByteBuffer.allocate(10);
+ ByteBuffer[] bbA = { ByteBuffer.allocate(5), ByteBuffer.allocate(10), ByteBuffer.allocate(5) };
+ SSLEngine sse = new mySSLEngine1(host, port);
+
+ try {
+ SSLEngineResult res = sse.wrap(bbA, bb);
+ fail("IllegalStateException wasn't thrown");
+ } catch (IllegalStateException iobe) {
+ //expected
+ } catch (Exception e) {
+ fail(e + " was thrown instead of IllegalStateException");
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLEngine#wrap(ByteBuffer[] srcs, ByteBuffer dst)
+ */
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "wrap",
+ args = {ByteBuffer[].class, ByteBuffer.class}
+ )
+ public void test_wrap_ByteBuffer$ByteBuffer_05() {
+ String host = "new host";
+ int port = 8080;
+ ByteBuffer bb = ByteBuffer.allocate(10);
+ ByteBuffer[] bbA = { ByteBuffer.allocate(5), ByteBuffer.allocate(10), ByteBuffer.allocate(5) };
+ SSLEngine sse = new mySSLEngine1(host, port);
+ sse.setUseClientMode(true);
+
+ try {
+ SSLEngineResult res = sse.wrap(bbA, bb);
+ assertEquals(10, res.bytesConsumed());
+ assertEquals(20, res.bytesProduced());
+ } catch (Exception ex) {
+ fail("Unexpected exception: " + ex);
+ }
}
}
@@ -527,13 +1601,18 @@
private boolean needClientAuth;
- private boolean enableSessionCreation;
+ private boolean enableSessionCreation = true;
private boolean wantClientAuth;
private String[] enabledProtocols;
private String[] enabledCipherSuites;
+
+ public int mode = -1;
+ private boolean init = false;
+ private boolean inboundDone = false;
+ private boolean outboundDone = false;
public mySSLEngine() {
super();
@@ -548,12 +1627,18 @@
if ((host == null) || (host.length() == 0)) {
throw new SSLException("");
}
+ if (mode == -1) {
+ throw new IllegalStateException();
+ }
+ init = true;
}
public void closeInbound() throws SSLException {
+ inboundDone = true;
}
public void closeOutbound() {
+ outboundDone = true;
}
public Runnable getDelegatedTask() {
@@ -601,18 +1686,24 @@
}
public boolean isInboundDone() {
- return false;
+ return inboundDone;
}
public boolean isOutboundDone() {
- return false;
+ return outboundDone;
}
public void setEnabledCipherSuites(String[] suites) {
+ if (suites == null) {
+ throw new IllegalArgumentException();
+ }
enabledCipherSuites = suites;
}
public void setEnabledProtocols(String[] protocols) {
+ if (protocols == null) {
+ throw new IllegalArgumentException();
+ }
enabledProtocols = protocols;
}
@@ -625,7 +1716,15 @@
}
public void setUseClientMode(boolean mode) {
+ if (init) {
+ throw new IllegalArgumentException();
+ }
useClientMode = mode;
+ if (useClientMode) {
+ this.mode = 1;
+ } else {
+ this.mode = 0;
+ }
}
public void setWantClientAuth(boolean want) {
@@ -646,14 +1745,14 @@
}
class mySSLEngine1 extends mySSLEngine {
-
+
public mySSLEngine1() {
}
public mySSLEngine1(String host, int port) {
super(host, port);
}
-
+
public SSLEngineResult unwrap(ByteBuffer src, ByteBuffer dst)
throws SSLException {
if (src.limit() > dst.limit()) {
@@ -685,5 +1784,59 @@
}
return super.wrap(src, dst);
}
-
+
+ public SSLEngineResult unwrap(ByteBuffer src, ByteBuffer[] dsts,
+ int offset, int length) throws SSLException {
+ if (super.mode == -1) {
+ throw new IllegalStateException("client/server mode has not yet been set");
+ }
+ if (src.limit() > dsts[0].limit()) {
+ throw new SSLException("incorrect limits");
+ }
+ if (offset < 0 || length < 0) {
+ throw new IndexOutOfBoundsException("negative parameter");
+ }
+ if (offset > length || length > dsts.length - offset) {
+ throw new IndexOutOfBoundsException("negative parameter");
+ }
+ if (src.equals(null) || dsts.equals(null)) {
+ throw new IllegalArgumentException("null parameter");
+ }
+ for (int i = 0; i < dsts.length; i++) {
+ if (dsts[i].isReadOnly()) {
+ throw new ReadOnlyBufferException();
+ } else if (dsts[i].equals(null)) {
+ throw new IllegalArgumentException("null parameter");
+ }
+ }
+ return super.unwrap(src, dsts, offset, length);
+ }
+
+ public SSLEngineResult wrap(ByteBuffer[] srcs, int offset, int length, ByteBuffer dst)
+ throws SSLException {
+ if (super.mode == -1) {
+ throw new IllegalStateException("client/server mode has not yet been set");
+ }
+ if (srcs[0].limit() > dst.limit()) {
+ throw new SSLException("incorrect limits");
+ }
+ if (offset < 0 || length < 0) {
+ throw new IndexOutOfBoundsException("negative parameter");
+ }
+ if (offset > length || length > srcs.length - offset) {
+ throw new IndexOutOfBoundsException("negative parameter");
+ }
+ if (srcs.equals(null) || dst.equals(null)) {
+ throw new IllegalArgumentException("null parameter");
+ }
+ for (int i = 0; i < srcs.length; i++) {
+ if (srcs[i].equals(null)) {
+ throw new IllegalArgumentException("null parameter");
+ }
+ }
+ if (dst.isReadOnly()) {
+ throw new ReadOnlyBufferException();
+ }
+ return super.wrap(srcs, offset, length, dst);
+ }
}
\ No newline at end of file
diff --git a/x-net/src/test/java/tests/api/javax/net/ssl/SSLExceptionTest.java b/x-net/src/test/java/tests/api/javax/net/ssl/SSLExceptionTest.java
new file mode 100644
index 0000000..fe0d056
--- /dev/null
+++ b/x-net/src/test/java/tests/api/javax/net/ssl/SSLExceptionTest.java
@@ -0,0 +1,223 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+package tests.api.javax.net.ssl;
+
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargets;
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetNew;
+
+import javax.net.ssl.SSLException;
+
+import junit.framework.TestCase;
+@TestTargetClass(SSLException.class)
+/**
+ * Tests for <code>SSLException</code> class constructors and methods.
+ *
+ */
+public class SSLExceptionTest extends TestCase {
+
+ public static void main(String[] args) {
+ }
+
+ /**
+ * Constructor for SSLExceptionTests.
+ *
+ * @param arg0
+ */
+ public SSLExceptionTest(String arg0) {
+ super(arg0);
+ }
+
+ private static String[] msgs = {
+ "",
+ "Check new message",
+ "Check new message Check new message Check new message Check new message Check new message" };
+
+ private static Throwable tCause = new Throwable("Throwable for exception");
+
+ /**
+ * Test for <code>SSLException(String)</code> constructor Assertion:
+ * constructs SSLException with detail message msg. Parameter
+ * <code>msg</code> is not null.
+ */
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "SSLException",
+ args = {java.lang.String.class}
+ )
+ public void testSSLException01() {
+ SSLException sE;
+ for (int i = 0; i < msgs.length; i++) {
+ sE = new SSLException(msgs[i]);
+ assertEquals("getMessage() must return: ".concat(msgs[i]), sE.getMessage(), msgs[i]);
+ assertNull("getCause() must return null", sE.getCause());
+ }
+ }
+
+ /**
+ * Test for <code>SSLException(String)</code> constructor Assertion:
+ * constructs SSLException when <code>msg</code> is null
+ */
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "SSLException",
+ args = {java.lang.String.class}
+ )
+ public void testSSLException02() {
+ String msg = null;
+ SSLException sE = new SSLException(msg);
+ assertNull("getMessage() must return null.", sE.getMessage());
+ assertNull("getCause() must return null", sE.getCause());
+ }
+
+ /**
+ * Test for <code>SSLException(Throwable)</code> constructor
+ * Assertion: constructs SSLException when <code>cause</code> is null
+ */
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "SSLException",
+ args = {java.lang.Throwable.class}
+ )
+ public void testSSLException03() {
+ Throwable cause = null;
+ SSLException sE = new SSLException(cause);
+ assertNull("getMessage() must return null.", sE.getMessage());
+ assertNull("getCause() must return null", sE.getCause());
+ }
+
+ /**
+ * Test for <code>SSLException(Throwable)</code> constructor
+ * Assertion: constructs SSLException when <code>cause</code> is not
+ * null
+ */
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "SSLException",
+ args = {java.lang.Throwable.class}
+ )
+ public void testSSLException04() {
+ SSLException sE = new SSLException(tCause);
+ if (sE.getMessage() != null) {
+ String toS = tCause.toString();
+ String getM = sE.getMessage();
+ assertTrue("getMessage() should contain ".concat(toS), (getM
+ .indexOf(toS) != -1));
+ }
+ assertNotNull("getCause() must not return null", sE.getCause());
+ assertEquals("getCause() must return ".concat(tCause.toString()), sE.getCause(), tCause);
+ }
+
+ /**
+ * Test for <code>SSLException(String, Throwable)</code> constructor
+ * Assertion: constructs SSLException when <code>cause</code> is null
+ * <code>msg</code> is null
+ */
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "SSLException",
+ args = {java.lang.String.class, java.lang.Throwable.class}
+ )
+ public void testSSLException05() {
+ SSLException sE = new SSLException(null, null);
+ assertNull("getMessage() must return null", sE.getMessage());
+ assertNull("getCause() must return null", sE.getCause());
+ }
+
+ /**
+ * Test for <code>SSLException(String, Throwable)</code> constructor
+ * Assertion: constructs SSLException when <code>cause</code> is null
+ * <code>msg</code> is not null
+ */
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "SSLException",
+ args = {java.lang.String.class, java.lang.Throwable.class}
+ )
+ public void testSSLException06() {
+ SSLException sE;
+ for (int i = 0; i < msgs.length; i++) {
+ sE = new SSLException(msgs[i], null);
+ assertEquals("getMessage() must return: ".concat(msgs[i]), sE
+ .getMessage(), msgs[i]);
+ assertNull("getCause() must return null", sE.getCause());
+ }
+ }
+
+ /**
+ * Test for <code>SSLException(String, Throwable)</code> constructor
+ * Assertion: constructs SSLException when <code>cause</code> is not
+ * null <code>msg</code> is null
+ */
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "SSLException",
+ args = {java.lang.String.class, java.lang.Throwable.class}
+ )
+ public void testSSLException07() {
+ SSLException sE = new SSLException(null, tCause);
+ if (sE.getMessage() != null) {
+ String toS = tCause.toString();
+ String getM = sE.getMessage();
+ assertTrue("getMessage() must should ".concat(toS), (getM
+ .indexOf(toS) != -1));
+ }
+ assertNotNull("getCause() must not return null", sE.getCause());
+ assertEquals("getCause() must return ".concat(tCause.toString()), sE
+ .getCause(), tCause);
+ }
+
+ /**
+ * Test for <code>SSLException(String, Throwable)</code> constructor
+ * Assertion: constructs SSLException when <code>cause</code> is not
+ * null <code>msg</code> is not null
+ */
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "SSLException",
+ args = {java.lang.String.class, java.lang.Throwable.class}
+ )
+ public void testSSLException08() {
+ SSLException sE;
+ for (int i = 0; i < msgs.length; i++) {
+ sE = new SSLException(msgs[i], tCause);
+ String getM = sE.getMessage();
+ String toS = tCause.toString();
+ if (msgs[i].length() > 0) {
+ assertTrue("getMessage() must contain ".concat(msgs[i]), getM
+ .indexOf(msgs[i]) != -1);
+ if (!getM.equals(msgs[i])) {
+ assertTrue("getMessage() should contain ".concat(toS), getM
+ .indexOf(toS) != -1);
+ }
+ }
+ assertNotNull("getCause() must not return null", sE.getCause());
+ assertEquals("getCause() must return ".concat(tCause.toString()),
+ sE.getCause(), tCause);
+ }
+ }
+}
\ No newline at end of file
diff --git a/x-net/src/test/java/tests/api/javax/net/ssl/SSLHandshakeExceptionTest.java b/x-net/src/test/java/tests/api/javax/net/ssl/SSLHandshakeExceptionTest.java
new file mode 100644
index 0000000..ffc0105
--- /dev/null
+++ b/x-net/src/test/java/tests/api/javax/net/ssl/SSLHandshakeExceptionTest.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2007 The Android Open Source Project
+ *
+ * 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.
+ */
+package tests.api.javax.net.ssl;
+
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargets;
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetNew;
+
+import javax.net.ssl.SSLHandshakeException;
+
+import junit.framework.TestCase;
+
+@TestTargetClass(SSLHandshakeException.class)
+public class SSLHandshakeExceptionTest extends TestCase {
+
+ public static void main(String[] args) {
+ }
+
+ /**
+ * Constructor for SSLHandshakeExceptionTest.
+ *
+ * @param arg0
+ */
+ public SSLHandshakeExceptionTest(String arg0) {
+ super(arg0);
+ }
+
+ private static String[] msgs = {
+ "",
+ "Check new message",
+ "Check new message Check new message Check new message Check new message Check new message" };
+
+
+ /**
+ * Test for <code>SSLHandshakeException(String)</code> constructor Assertion:
+ * constructs SSLHandshakeException with detail message msg. Parameter
+ * <code>msg</code> is not null.
+ */
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "SSLHandshakeException",
+ args = {java.lang.String.class}
+ )
+ public void test_Constructor01() {
+ SSLHandshakeException sslE;
+ for (int i = 0; i < msgs.length; i++) {
+ sslE = new SSLHandshakeException(msgs[i]);
+ assertEquals("getMessage() must return: ".concat(msgs[i]), sslE.getMessage(), msgs[i]);
+ assertNull("getCause() must return null", sslE.getCause());
+ }
+ }
+
+ /**
+ * Test for <code>SSLHandshakeException(String)</code> constructor Assertion:
+ * constructs SSLHandshakeException with detail message msg. Parameter
+ * <code>msg</code> is null.
+ */
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "SSLHandshakeException",
+ args = {java.lang.String.class}
+ )
+ public void test_Constructor02() {
+ String msg = null;
+ SSLHandshakeException sslE = new SSLHandshakeException(msg);
+ assertNull("getMessage() must return null.", sslE.getMessage());
+ assertNull("getCause() must return null", sslE.getCause());
+ }
+}
\ No newline at end of file
diff --git a/x-net/src/test/java/tests/api/javax/net/ssl/SSLKeyExceptionTest.java b/x-net/src/test/java/tests/api/javax/net/ssl/SSLKeyExceptionTest.java
new file mode 100644
index 0000000..a890dbd
--- /dev/null
+++ b/x-net/src/test/java/tests/api/javax/net/ssl/SSLKeyExceptionTest.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2007 The Android Open Source Project
+ *
+ * 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.
+ */
+package tests.api.javax.net.ssl;
+
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargets;
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetNew;
+
+import javax.net.ssl.SSLKeyException;
+
+import junit.framework.TestCase;
+
+@TestTargetClass(SSLKeyException.class)
+public class SSLKeyExceptionTest extends TestCase {
+
+ public static void main(String[] args) {
+ }
+
+ /**
+ * Constructor for SSLKeyExceptionTest.
+ *
+ * @param arg0
+ */
+ public SSLKeyExceptionTest(String arg0) {
+ super(arg0);
+ }
+
+ private static String[] msgs = {
+ "",
+ "Check new message",
+ "Check new message Check new message Check new message Check new message Check new message" };
+
+
+ /**
+ * Test for <code>SSLKeyException(String)</code> constructor Assertion:
+ * constructs SSLKeyException with detail message msg. Parameter
+ * <code>msg</code> is not null.
+ */
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "SSLKeyException",
+ args = {java.lang.String.class}
+ )
+ public void test_Constructor01() {
+ SSLKeyException skE;
+ for (int i = 0; i < msgs.length; i++) {
+ skE = new SSLKeyException(msgs[i]);
+ assertEquals("getMessage() must return: ".concat(msgs[i]), skE.getMessage(), msgs[i]);
+ assertNull("getCause() must return null", skE.getCause());
+ }
+ }
+
+ /**
+ * Test for <code>SSLPeerUnverifiedException(String)</code> constructor Assertion:
+ * constructs SSLPeerUnverifiedException with detail message msg. Parameter
+ * <code>msg</code> is null.
+ */
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "SSLKeyException",
+ args = {java.lang.String.class}
+ )
+ public void test_Constructor02() {
+ String msg = null;
+ SSLKeyException skE = new SSLKeyException(msg);
+ assertNull("getMessage() must return null.", skE.getMessage());
+ assertNull("getCause() must return null", skE.getCause());
+ }
+}
\ No newline at end of file
diff --git a/x-net/src/test/java/tests/api/javax/net/ssl/SSLPeerUnverifiedExceptionTest.java b/x-net/src/test/java/tests/api/javax/net/ssl/SSLPeerUnverifiedExceptionTest.java
new file mode 100644
index 0000000..7fdd0b7
--- /dev/null
+++ b/x-net/src/test/java/tests/api/javax/net/ssl/SSLPeerUnverifiedExceptionTest.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2007 The Android Open Source Project
+ *
+ * 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.
+ */
+package tests.api.javax.net.ssl;
+
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargets;
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetNew;
+
+import javax.net.ssl.SSLPeerUnverifiedException;
+
+import junit.framework.TestCase;
+
+@TestTargetClass(SSLPeerUnverifiedException.class)
+public class SSLPeerUnverifiedExceptionTest extends TestCase {
+
+ public static void main(String[] args) {
+ }
+
+ /**
+ * Constructor for SSLPeerUnverifiedExceptionTest.
+ *
+ * @param arg0
+ */
+ public SSLPeerUnverifiedExceptionTest(String arg0) {
+ super(arg0);
+ }
+
+ private static String[] msgs = {
+ "",
+ "Check new message",
+ "Check new message Check new message Check new message Check new message Check new message" };
+
+
+ /**
+ * Test for <code>SSLPeerUnverifiedException(String)</code> constructor Assertion:
+ * constructs SSLPeerUnverifiedException with detail message msg. Parameter
+ * <code>msg</code> is not null.
+ */
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "SSLPeerUnverifiedException",
+ args = {java.lang.String.class}
+ )
+ public void test_Constructor01() {
+ SSLPeerUnverifiedException sslE;
+ for (int i = 0; i < msgs.length; i++) {
+ sslE = new SSLPeerUnverifiedException(msgs[i]);
+ assertEquals("getMessage() must return: ".concat(msgs[i]), sslE.getMessage(), msgs[i]);
+ assertNull("getCause() must return null", sslE.getCause());
+ }
+ }
+
+ /**
+ * Test for <code>SSLPeerUnverifiedException(String)</code> constructor Assertion:
+ * constructs SSLPeerUnverifiedException with detail message msg. Parameter
+ * <code>msg</code> is null.
+ */
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "SSLPeerUnverifiedException",
+ args = {java.lang.String.class}
+ )
+ public void test_Constructor02() {
+ String msg = null;
+ SSLPeerUnverifiedException sslE = new SSLPeerUnverifiedException(msg);
+ assertNull("getMessage() must return null.", sslE.getMessage());
+ assertNull("getCause() must return null", sslE.getCause());
+ }
+}
diff --git a/x-net/src/test/java/tests/api/javax/net/ssl/SSLPermissionTest.java b/x-net/src/test/java/tests/api/javax/net/ssl/SSLPermissionTest.java
index 79eca96..4da9553 100644
--- a/x-net/src/test/java/tests/api/javax/net/ssl/SSLPermissionTest.java
+++ b/x-net/src/test/java/tests/api/javax/net/ssl/SSLPermissionTest.java
@@ -18,9 +18,8 @@
package tests.api.javax.net.ssl;
import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestInfo;
import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTarget;
+import dalvik.annotation.TestTargetNew;
import javax.net.ssl.SSLPermission;
import junit.framework.TestCase;
@@ -36,19 +35,21 @@
/*
* Class under test for void SSLPermission(String)
*/
- @TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "Null parameter checking missed",
- targets = {
- @TestTarget(
- methodName = "SSLPermission",
- methodArgs = {String.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "SSLPermission",
+ args = {String.class}
+ )
public void test_ConstructorLjava_lang_String() {
try {
SSLPermission p = new SSLPermission("name");
assertEquals("Incorrect permission name", "name", p.getName());
+ try {
+ p = new SSLPermission(null);
+ } catch (NullPointerException npe) {
+ //expected
+ }
} catch (Exception e) {
fail("Unexpected exception " + e.toString());
}
@@ -57,21 +58,33 @@
/*
* Class under test for void SSLPermission(String, String)
*/
- @TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "Null parameters checking missed",
- targets = {
- @TestTarget(
- methodName = "SSLPermission",
- methodArgs = {String.class, String.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "SSLPermission",
+ args = {String.class, String.class}
+ )
public void test_ConstructorLjava_lang_StringLjava_lang_String() {
try {
SSLPermission p = new SSLPermission("name", "value");
assertEquals("Incorrect permission name", "name", p.getName());
assertEquals("Incorrect default permission actions",
"", p.getActions());
+ try {
+ p = new SSLPermission(null, "value");
+ } catch (NullPointerException npe) {
+ //expected
+ }
+ try {
+ p = new SSLPermission("name", null);
+ } catch (NullPointerException npe) {
+ //expected
+ }
+ try {
+ p = new SSLPermission(null, null);
+ } catch (NullPointerException npe) {
+ //expected
+ }
} catch (Exception e) {
fail("Unexpected exception " + e.toString());
}
diff --git a/x-net/src/test/java/tests/api/javax/net/ssl/SSLProtocolExceptionTest.java b/x-net/src/test/java/tests/api/javax/net/ssl/SSLProtocolExceptionTest.java
new file mode 100644
index 0000000..e73a525
--- /dev/null
+++ b/x-net/src/test/java/tests/api/javax/net/ssl/SSLProtocolExceptionTest.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2007 The Android Open Source Project
+ *
+ * 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.
+ */
+package tests.api.javax.net.ssl;
+
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargets;
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetNew;
+
+import javax.net.ssl.SSLProtocolException;
+
+import junit.framework.TestCase;
+
+@TestTargetClass(SSLProtocolException.class)
+public class SSLProtocolExceptionTest extends TestCase {
+
+ public static void main(String[] args) {
+ }
+
+ /**
+ * Constructor for SSLProtocolExceptionTest.
+ *
+ * @param arg0
+ */
+ public SSLProtocolExceptionTest(String arg0) {
+ super(arg0);
+ }
+
+ private static String[] msgs = {
+ "",
+ "Check new message",
+ "Check new message Check new message Check new message Check new message Check new message" };
+
+
+ /**
+ * Test for <code>SSLProtocolException(String)</code> constructor Assertion:
+ * constructs SSLProtocolException with detail message msg. Parameter
+ * <code>msg</code> is not null.
+ */
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "SSLProtocolException",
+ args = {java.lang.String.class}
+ )
+ public void test_Constructor01() {
+ SSLProtocolException sslE;
+ for (int i = 0; i < msgs.length; i++) {
+ sslE = new SSLProtocolException(msgs[i]);
+ assertEquals("getMessage() must return: ".concat(msgs[i]), sslE.getMessage(), msgs[i]);
+ assertNull("getCause() must return null", sslE.getCause());
+ }
+ }
+
+ /**
+ * Test for <code>SSLProtocolException(String)</code> constructor Assertion:
+ * constructs SSLProtocolException with detail message msg. Parameter
+ * <code>msg</code> is null.
+ */
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "SSLProtocolException",
+ args = {java.lang.String.class}
+ )
+ public void test_Constructor02() {
+ String msg = null;
+ SSLProtocolException sslE = new SSLProtocolException(msg);
+ assertNull("getMessage() must return null.", sslE.getMessage());
+ assertNull("getCause() must return null", sslE.getCause());
+ }
+}
\ No newline at end of file
diff --git a/x-net/src/test/java/tests/api/javax/net/ssl/SSLServerSocketFactoryTest.java b/x-net/src/test/java/tests/api/javax/net/ssl/SSLServerSocketFactoryTest.java
index e823410..a702d56 100644
--- a/x-net/src/test/java/tests/api/javax/net/ssl/SSLServerSocketFactoryTest.java
+++ b/x-net/src/test/java/tests/api/javax/net/ssl/SSLServerSocketFactoryTest.java
@@ -5,7 +5,7 @@
* 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
+ * 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,
@@ -13,13 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package tests.api.javax.net.ssl;
import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestInfo;
+import dalvik.annotation.TestTargets;
import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTarget;
+import dalvik.annotation.TestTargetNew;
import java.io.IOException;
import java.net.InetAddress;
@@ -86,18 +85,16 @@
/**
* @tests javax.net.ssl.SSLServerSocketFactory#SSLServerSocketFactory()
*/
- @TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "SSLServerSocketFactory",
- methodArgs = {}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "SSLServerSocketFactory",
+ args = {}
+ )
public void test_Constructor() {
try {
- new MockSSLServerSocketFactory();
+ MockSSLServerSocketFactory ssf = new MockSSLServerSocketFactory();
+ assertTrue(ssf instanceof SSLServerSocketFactory);
} catch (Exception e) {
fail("Unexpected exception " + e.toString());
}
@@ -106,17 +103,50 @@
/**
* @tests javax.net.ssl.SSLServerSocketFactory#getDefault()
*/
- @TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getDefault",
- methodArgs = {}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getDefault",
+ args = {}
+ )
public void test_getDefault() {
assertNotNull("Incorrect default socket factory",
SSLServerSocketFactory.getDefault());
}
+
+ /**
+ * @tests javax.net.ssl.SSLServerSocketFactory#getDefaultCipherSuites()
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getDefaultCipherSuites",
+ args = {}
+ )
+ public void test_getDefaultCipherSuites() {
+ MockSSLServerSocketFactory ssf = new MockSSLServerSocketFactory();
+ try {
+ assertNull(ssf.getDefaultCipherSuites());
+ } catch (Exception e) {
+ fail("Unexpected exception " + e);
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLServerSocketFactory#getSupportedCipherSuites()
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getSupportedCipherSuites",
+ args = {}
+ )
+ public void test_getSupportedCipherSuites() {
+ MockSSLServerSocketFactory ssf = new MockSSLServerSocketFactory();
+ try {
+ assertNull(ssf.getSupportedCipherSuites());
+ } catch (Exception e) {
+ fail("Unexpected exception " + e);
+ }
+ }
}
diff --git a/x-net/src/test/java/tests/api/javax/net/ssl/SSLServerSocketTest.java b/x-net/src/test/java/tests/api/javax/net/ssl/SSLServerSocketTest.java
new file mode 100644
index 0000000..4007d92
--- /dev/null
+++ b/x-net/src/test/java/tests/api/javax/net/ssl/SSLServerSocketTest.java
@@ -0,0 +1,570 @@
+/*
+ * Copyright (C) 2007 The Android Open Source Project
+ *
+ * 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.
+ */
+package tests.api.javax.net.ssl;
+
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargets;
+
+import javax.net.ssl.*;
+
+import java.net.*;
+import java.io.*;
+import java.lang.String;
+
+import junit.framework.TestCase;
+
+import tests.support.Support_PortManager;
+
+@TestTargetClass(SSLServerSocket.class)
+public class SSLServerSocketTest extends TestCase {
+
+ /**
+ * Additional class for SSLServerSocket constructor verification
+ */
+ class mySSLServerSocket extends SSLServerSocket {
+
+ private boolean sslFlag = true;
+ private boolean sslNeed = false;
+ private boolean sslWant = false;
+ private boolean sslMode = true;
+ private String[] supportProtocol = null;
+ private String[] supportSuites = null;
+
+ public mySSLServerSocket(String[] protocols, String[] suites) throws IOException {
+ super();
+ supportProtocol = protocols;
+ supportSuites = suites;
+ }
+ public mySSLServerSocket() throws IOException{
+ super();
+ }
+ public mySSLServerSocket(int port) throws IOException{
+ super(port);
+ }
+ public mySSLServerSocket(int port, int backlog) throws IOException{
+ super(port, backlog);
+ }
+ public mySSLServerSocket(int port, int backlog, InetAddress address) throws IOException{
+ super(port, backlog, address);
+ }
+
+ public String[] getSupportedCipherSuites() {
+ if (supportSuites == null) {
+ throw new NullPointerException();
+ }
+ if (supportSuites.length == 0) {
+ return null;
+ } else return supportSuites;
+ }
+ public void setEnabledCipherSuites(String[] suites) {
+ if (suites == null) {
+ throw new IllegalArgumentException("null parameter");
+ }
+ if (!suites.equals(supportSuites)) {
+ throw new IllegalArgumentException("incorrect suite");
+ }
+ }
+ public String[] getEnabledCipherSuites() {
+ return supportSuites;
+ }
+
+ public String[] getSupportedProtocols() {
+ if (supportProtocol == null) {
+ throw new NullPointerException();
+ }
+ if (supportProtocol.length == 0) {
+ return null;
+ } else return supportProtocol;
+ }
+ public String[] getEnabledProtocols() {
+ return supportProtocol;
+ }
+ public void setEnabledProtocols(String[] protocols) {
+ if (protocols == null) {
+ throw new IllegalArgumentException("null protocol");
+ }
+ if (!protocols.equals(supportProtocol)) {
+ throw new IllegalArgumentException("incorrect protocol");
+ }
+ }
+
+ public void setEnableSessionCreation(boolean flag) {
+ sslFlag = flag;
+ }
+ public boolean getEnableSessionCreation() {
+ return sslFlag;
+ }
+
+ public void setNeedClientAuth(boolean need) {
+ sslNeed = need;
+ }
+ public boolean getNeedClientAuth() {
+ return sslNeed;
+ }
+
+ public boolean getUseClientMode() {
+ return sslMode;
+ }
+ public void setUseClientMode(boolean mode) {
+ sslMode = mode;
+ }
+
+ public boolean getWantClientAuth() {
+ return sslWant;
+ }
+ public void setWantClientAuth(boolean mode) {
+ sslWant = mode;
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLServerSocket#SSLServerSocket()
+ */
+ @TestTargetNew(
+ level = TestLevel.SUFFICIENT,
+ notes = "IOException wasn't implemented",
+ method = "SSLServerSocket",
+ args = {}
+ )
+ public void testConstructor_01() {
+ try {
+ mySSLServerSocket ssl = new mySSLServerSocket();
+ assertNotNull(ssl);
+ assertTrue(ssl instanceof SSLServerSocket);
+ } catch (Exception ex) {
+ fail("Unexpected exception was thrown " + ex);
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLServerSocket#SSLServerSocket(int port)
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "SSLServerSocket",
+ args = {int.class}
+ )
+ public void testConstructor_02() {
+ mySSLServerSocket ssl;
+ int portNumber = Support_PortManager.getNextPort();
+ int[] port_invalid = {-1, 65536, Integer.MIN_VALUE, Integer.MAX_VALUE};
+
+ try {
+ ssl = new mySSLServerSocket(portNumber);
+ assertNotNull(ssl);
+ assertEquals(portNumber, ssl.getLocalPort());
+ } catch (Exception ex) {
+ fail("Unexpected exception was thrown " + ex);
+ }
+
+ for (int i = 0; i < port_invalid.length; i++) {
+ try {
+ ssl = new mySSLServerSocket(port_invalid[i]);
+ fail("IllegalArgumentException should be thrown");
+ } catch (IllegalArgumentException iae) {
+ //expected
+ } catch (Exception e) {
+ fail(e + " was thrown instead of IllegalArgumentException");
+ }
+ }
+
+ try {
+ ssl = new mySSLServerSocket(portNumber);
+ new mySSLServerSocket(portNumber);
+ } catch (IOException ioe) {
+ } catch (Exception ex) {
+ fail("Unexpected exception was thrown " + ex);
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLServerSocket#SSLServerSocket(int port, int backlog)
+ */
+ @TestTargetNew(
+ level = TestLevel.SUFFICIENT,
+ notes = "Invalid values for backlog weren't checked",
+ method = "SSLServerSocket",
+ args = {int.class, int.class}
+ )
+ public void testConstructor_03() {
+ mySSLServerSocket ssl;
+ int portNumber = Support_PortManager.getNextPort();
+ int[] port_invalid = {-1, Integer.MIN_VALUE, Integer.MAX_VALUE};
+
+ try {
+ ssl = new mySSLServerSocket(portNumber, 1);
+ assertNotNull(ssl);
+ assertEquals(portNumber, ssl.getLocalPort());
+ } catch (Exception ex) {
+ fail("Unexpected exception was thrown");
+ }
+
+ for (int i = 0; i < port_invalid.length; i++) {
+ try {
+ ssl = new mySSLServerSocket(port_invalid[i], 1);
+ fail("IllegalArgumentException should be thrown");
+ } catch (IllegalArgumentException iae) {
+ } catch (Exception e) {
+ fail(e + " was thrown instead of IllegalArgumentException");
+ }
+ }
+
+ portNumber = Support_PortManager.getNextPort();
+ try {
+ ssl = new mySSLServerSocket(portNumber, 1);
+ new mySSLServerSocket(portNumber, 1);
+ fail("IOException should be thrown");
+ } catch (IOException ioe) {
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLServerSocket#SSLServerSocket(int port, int backlog, InetAddress address)
+ */
+ @TestTargetNew(
+ level = TestLevel.SUFFICIENT,
+ notes = "Invalid values for backlog weren\'t checked",
+ method = "SSLServerSocket",
+ args = {int.class, int.class, InetAddress.class}
+ )
+ public void testConstructor_04() {
+ mySSLServerSocket ssl;
+ InetAddress ia = null;
+ int portNumber = Support_PortManager.getNextPort();
+ int[] port_invalid = {-1, 65536, Integer.MIN_VALUE, Integer.MAX_VALUE};
+
+ try {
+ ssl = new mySSLServerSocket(portNumber, 0, ia);
+ assertNotNull(ssl);
+ assertEquals(portNumber, ssl.getLocalPort());
+ } catch (Exception ex) {
+ fail("Unexpected exception was thrown");
+ }
+
+ portNumber = Support_PortManager.getNextPort();
+ try {
+ ssl = new mySSLServerSocket(portNumber, 0, InetAddress.getLocalHost());
+ assertNotNull(ssl);
+ assertEquals(portNumber, ssl.getLocalPort());
+ } catch (Exception ex) {
+ fail("Unexpected exception was thrown");
+ }
+
+ for (int i = 0; i < port_invalid.length; i++) {
+ try {
+ ssl = new mySSLServerSocket(port_invalid[i], 1, InetAddress.getLocalHost());
+ fail("IllegalArgumentException should be thrown");
+ } catch (IllegalArgumentException iae) {
+ } catch (Exception e) {
+ fail(e + " was thrown instead of IllegalArgumentException");
+ }
+ }
+
+ portNumber = Support_PortManager.getNextPort();
+ try {
+ ssl = new mySSLServerSocket(portNumber, 0, InetAddress.getLocalHost());
+ new mySSLServerSocket(portNumber, 0, InetAddress.getLocalHost());
+ fail("IOException should be thrown for");
+ } catch (IOException ioe) {
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLServerSocket#getSupportedCipherSuites()
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getSupportedCipherSuites",
+ args = {}
+ )
+ public void test_getSupportedCipherSuites() {
+ String[] pr = {"Suite_1", "Suite_2", "Suite_3"};
+ try {
+ mySSLServerSocket sss = new mySSLServerSocket();
+ try {
+ sss.getSupportedCipherSuites();
+ } catch (NullPointerException npe) {
+ //expected
+ }
+ sss = new mySSLServerSocket(null, pr);
+ try {
+ sss.getSupportedCipherSuites();
+ } catch (NullPointerException npe) {
+ //expected
+ }
+ sss = new mySSLServerSocket(new String[0], new String[0]);
+ assertNull("Not NULL result", sss.getSupportedCipherSuites());
+ sss = new mySSLServerSocket(null, pr);
+ String[] res = sss.getSupportedCipherSuites();
+ assertNotNull("NULL result", res);
+ if (!res.equals(pr)) {
+ fail("Returned result was incorrect");
+ }
+ } catch (Exception e) {
+ fail("Unexpected exception " + e);
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLServerSocket#getEnabledCipherSuites()
+ * @tests javax.net.ssl.SSLServerSocket#setEnabledCipherSuites(String[] suites)
+ */
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getEnabledCipherSuites",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "setEnabledCipherSuites",
+ args = {String[].class}
+ )
+ })
+ public void test_EnabledCipherSuites() {
+ String[] pr1 = {"Suite_1", "Suite_2", "Suite_3"};
+ String[] pr2 = {"Suite_1", "Suite_2"};
+ try {
+ mySSLServerSocket sss = new mySSLServerSocket(null, pr1);
+ try {
+ sss.setEnabledCipherSuites(null);
+ } catch (IllegalArgumentException iae) {
+ //expected
+ }
+ try {
+ sss.setEnabledCipherSuites(pr2);
+ } catch (IllegalArgumentException iae) {
+ //expected
+ }
+ sss.setEnabledCipherSuites(pr1);
+ String[] res = sss.getEnabledCipherSuites();
+ assertNotNull("NULL result", res);
+ if (!res.equals(pr1)) {
+ fail("Returned result was incorrect");
+ }
+ } catch (Exception e) {
+ fail("Unexpected exception " + e);
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLServerSocket#getSupportedProtocols()
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getSupportedProtocols",
+ args = {}
+ )
+ public void test_getSupportedProtocols() {
+ String[] pr = {"Protocol_1", "Protocol_2", "Protocol_3"};
+ try {
+ mySSLServerSocket sss = new mySSLServerSocket();
+ try {
+ sss.getSupportedProtocols();
+ } catch (NullPointerException npe) {
+ //expected
+ }
+ sss = new mySSLServerSocket(null, null);
+ try {
+ sss.getSupportedProtocols();
+ } catch (NullPointerException npe) {
+ //expected
+ }
+ sss = new mySSLServerSocket(new String[0], null);
+ assertNull("Not NULL result", sss.getSupportedProtocols());
+ sss = new mySSLServerSocket(pr, null);
+ String[] res = sss.getSupportedProtocols();
+ assertNotNull("NULL result", res);
+ if (!res.equals(pr)) {
+ fail("Returned result was incorrect");
+ }
+ } catch (Exception e) {
+ fail("Unexpected exception " + e);
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLServerSocket#getEnabledProtocols()
+ * @tests javax.net.ssl.SSLServerSocket#setEnabledProtocols(String[] protocols)
+ */
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "setEnabledProtocols",
+ args = {String[].class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getEnabledProtocols",
+ args = {}
+ )
+ })
+ public void test_EnabledProtocols() {
+ String[] pr1 = {"Protocol_1", "Protocol_2", "Protocol_3"};
+ String[] pr2 = {"Protocol_1", "Protocol_2"};
+ try {
+ mySSLServerSocket sss = new mySSLServerSocket(pr1, null);
+ try {
+ sss.setEnabledProtocols(null);
+ } catch (IllegalArgumentException iae) {
+ //expected
+ }
+ try {
+ sss.setEnabledProtocols(pr2);
+ } catch (IllegalArgumentException iae) {
+ //expected
+ }
+ sss.setEnabledProtocols(pr1);
+ String[] res = sss.getEnabledProtocols();
+ assertNotNull("NULL result", res);
+ if (!res.equals(pr1)) {
+ fail("Returned result was incorrect");
+ }
+ } catch (Exception e) {
+ fail("Unexpected exception " + e);
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLServerSocket#setEnableSessionCreation(boolean flag)
+ * @tests javax.net.ssl.SSLServerSocket#getEnableSessionCreation()
+ */
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getEnableSessionCreation",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "setEnableSessionCreation",
+ args = {boolean.class}
+ )
+ })
+ public void test_EnableSessionCreation() {
+ try {
+ mySSLServerSocket sss = new mySSLServerSocket();
+ assertTrue(sss.getEnableSessionCreation());
+ sss.setEnableSessionCreation(false);
+ assertFalse(sss.getEnableSessionCreation());
+ sss.setEnableSessionCreation(true);
+ assertTrue(sss.getEnableSessionCreation());
+ } catch (Exception e) {
+ fail("Unexpected exception " + e);
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLServerSocket#setNeedClientAuth(boolean need)
+ * @tests javax.net.ssl.SSLServerSocket#getNeedClientAuthCreation()
+ */
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "setNeedClientAuth",
+ args = {boolean.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getNeedClientAuth",
+ args = {}
+ )
+ })
+ public void test_NeedClientAuth() {
+ try {
+ mySSLServerSocket sss = new mySSLServerSocket();
+ sss.setNeedClientAuth(true);
+ assertTrue(sss.getNeedClientAuth());
+ sss.setNeedClientAuth(false);
+ assertFalse(sss.getNeedClientAuth());
+ } catch (Exception e) {
+ fail("Unexpected exception " + e);
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLServerSocket#getUseClientMode()
+ * @tests javax.net.ssl.SSLServerSocket#setUseClientMode(boolean mode)
+ */
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getUseClientMode",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "setUseClientMode",
+ args = {boolean.class}
+ )
+ })
+ public void test_UseClientMode() {
+ try {
+ mySSLServerSocket sss = new mySSLServerSocket();
+ sss.setUseClientMode(false);
+ assertFalse(sss.getUseClientMode());
+ sss.setUseClientMode(true);
+ assertTrue(sss.getUseClientMode());
+ } catch (Exception e) {
+ fail("Unexpected exception " + e);
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLServerSocket#setWantClientAuth(boolean want)
+ * @tests javax.net.ssl.SSLServerSocket#getWantClientAuthCreation()
+ */
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getWantClientAuth",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "setWantClientAuth",
+ args = {boolean.class}
+ )
+ })
+ public void test_WantClientAuth() {
+ try {
+ mySSLServerSocket sss = new mySSLServerSocket();
+ sss.setWantClientAuth(true);
+ assertTrue(sss.getWantClientAuth());
+ sss.setWantClientAuth(false);
+ assertFalse(sss.getWantClientAuth());
+ } catch (Exception e) {
+ fail("Unexpected exception " + e);
+ }
+ }
+}
diff --git a/x-net/src/test/java/tests/api/javax/net/ssl/SSLSessionBindingEventTest.java b/x-net/src/test/java/tests/api/javax/net/ssl/SSLSessionBindingEventTest.java
index 9dc64cc..f95c941 100644
--- a/x-net/src/test/java/tests/api/javax/net/ssl/SSLSessionBindingEventTest.java
+++ b/x-net/src/test/java/tests/api/javax/net/ssl/SSLSessionBindingEventTest.java
@@ -18,9 +18,9 @@
package tests.api.javax.net.ssl;
import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestInfo;
+import dalvik.annotation.TestTargets;
import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTarget;
+import dalvik.annotation.TestTargetNew;
import java.security.Principal;
import java.security.cert.Certificate;
@@ -40,38 +40,50 @@
@TestTargetClass(SSLSessionBindingEvent.class)
public class SSLSessionBindingEventTest extends TestCase {
- @TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "Null parameters checking missed",
- targets = {
- @TestTarget(
- methodName = "SSLSessionBindingEvent",
- methodArgs = {SSLSession.class, String.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "SSLSessionBindingEvent",
+ args = {javax.net.ssl.SSLSession.class, java.lang.String.class}
+ )
public final void test_ConstructorLjavax_net_ssl_SSLSessionLjava_lang_String() {
SSLSession ses = new MySSLSession();
- SSLSessionBindingEvent event = new SSLSessionBindingEvent(ses, "test");
- if (!"test".equals(event.getName())) {
- fail("incorrect name");
+
+ try {
+ SSLSessionBindingEvent event = new SSLSessionBindingEvent(ses, "test");
+ if (!"test".equals(event.getName())) {
+ fail("incorrect name");
+ }
+ if (!event.getSession().equals(ses)) {
+ fail("incorrect session");
+ }
+ } catch (Exception e) {
+ fail("Unexpected exception " + e);
}
- if (!event.getSession().equals(ses)) {
- fail("incorrect session");
+
+ try {
+ SSLSessionBindingEvent event = new SSLSessionBindingEvent(null, "test");
+ fail("IllegalArgumentException expected");
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+
+ try {
+ SSLSessionBindingEvent event = new SSLSessionBindingEvent(ses, null);
+ } catch (IllegalArgumentException e) {
+ fail("Unexpected IllegalArgumentException: " + e);
}
}
/**
* @tests javax.net.ssl.SSLSessionBindingEvent#getName()
*/
- @TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getName",
- methodArgs = {}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getName",
+ args = {}
+ )
public void test_getName() {
SSLSession ses = new MySSLSession();
SSLSessionBindingEvent event = new SSLSessionBindingEvent(ses, "test");
@@ -83,15 +95,12 @@
/**
* @tests javax.net.ssl.SSLSessionBindingEvent#getSession()
*/
- @TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getSession",
- methodArgs = {}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getSession",
+ args = {}
+ )
public void test_getSession() {
SSLSession ses = new MySSLSession();
SSLSessionBindingEvent event = new SSLSessionBindingEvent(ses, "test");
diff --git a/x-net/src/test/java/tests/api/javax/net/ssl/SSLSessionBindingListenerTest.java b/x-net/src/test/java/tests/api/javax/net/ssl/SSLSessionBindingListenerTest.java
new file mode 100644
index 0000000..c640bd5
--- /dev/null
+++ b/x-net/src/test/java/tests/api/javax/net/ssl/SSLSessionBindingListenerTest.java
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+package tests.api.javax.net.ssl;
+
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetNew;
+
+import javax.net.ssl.SSLSessionBindingEvent;
+import javax.net.ssl.SSLSessionBindingListener;
+
+import org.apache.harmony.xnet.tests.support.mySSLSession;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests for SSLSessionBindingListener class
+ *
+ */
+@TestTargetClass(SSLSessionBindingListener.class)
+public class SSLSessionBindingListenerTest extends TestCase {
+
+ public class mySSLSessionBindingListener implements SSLSessionBindingListener {
+
+ private boolean boundDone = false;
+ private boolean unboundDone = false;
+
+ mySSLSessionBindingListener() {
+ }
+
+ public void valueBound(SSLSessionBindingEvent event) {
+ if (event != null) boundDone = true;
+ }
+ public void valueUnbound(SSLSessionBindingEvent event) {
+ if (event != null) unboundDone = true;
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLSessionBindingListener#valueBound(SSLSessionBindingEvent event)
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "valueBound",
+ args = {SSLSessionBindingEvent.class}
+ )
+ public void test_valueBound() {
+ mySSLSession ss = new mySSLSession("localhost", 1080, null);
+ mySSLSessionBindingListener sbl = new mySSLSessionBindingListener();
+ SSLSessionBindingEvent event = new SSLSessionBindingEvent(ss, "Name_01");
+ try {
+ sbl.valueBound(event);
+ } catch (Exception e) {
+ fail("Unexpected exception: " + e);
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLSessionBindingListener#valueUnbound(SSLSessionBindingEvent event)
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "valueUnbound",
+ args = {SSLSessionBindingEvent.class}
+ )
+ public void test_valueUnbound() {
+ mySSLSession ss = new mySSLSession("localhost", 1080, null);
+ mySSLSessionBindingListener sbl = new mySSLSessionBindingListener();
+ SSLSessionBindingEvent event = new SSLSessionBindingEvent(ss, "Name_01");
+ try {
+ sbl.valueUnbound(event);
+ } catch (Exception e) {
+ fail("Unexpected exception: " + e);
+ }
+ }
+
+}
diff --git a/x-net/src/test/java/tests/api/javax/net/ssl/SSLSessionContextTest.java b/x-net/src/test/java/tests/api/javax/net/ssl/SSLSessionContextTest.java
new file mode 100644
index 0000000..293f5b1
--- /dev/null
+++ b/x-net/src/test/java/tests/api/javax/net/ssl/SSLSessionContextTest.java
@@ -0,0 +1,132 @@
+package tests.api.javax.net.ssl;
+
+import dalvik.annotation.TestTargets;
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargetClass;
+
+import junit.framework.TestCase;
+
+import javax.net.ssl.SSLSessionContext;
+import org.apache.harmony.xnet.tests.support.SSLSessionContextImpl;
+
+/**
+ * Tests for <code>SSLSessionContext</code> class constructors and methods.
+ */
+@TestTargetClass(SSLSessionContext.class)
+public class SSLSessionContextTest extends TestCase {
+
+ /**
+ * @tests javax.net.ssl.SSLSessionContex#getSessionCacheSize()
+ * @tests javax.net.ssl.SSLSessionContex#setSessionCacheSize(int size)
+ */
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getSessionCacheSize",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "setSessionCacheSize",
+ args = {int.class}
+ )
+ })
+ public final void test_sessionCacheSize() {
+ SSLSessionContextImpl sc = new SSLSessionContextImpl();
+ try {
+ assertEquals("0 wasn't returned", 0, sc.getSessionCacheSize());
+ sc.setSessionCacheSize(10);
+ assertEquals("10 wasn't returned", 10, sc.getSessionCacheSize());
+ sc.setSessionCacheSize(5);
+ assertEquals("5 wasn't returned", 5, sc.getSessionCacheSize());
+ } catch (Exception e) {
+ fail("Unexpected exception");
+ }
+
+ try {
+ sc.setSessionCacheSize(-1);
+ fail("IllegalArgumentException wasn't thrown");
+ } catch (IllegalArgumentException iae) {
+ //expected
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLSessionContex#getSessionTimeout()
+ * @tests javax.net.ssl.SSLSessionContex#setSessionTimeout(int seconds)
+ */
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getSessionTimeout",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "setSessionTimeout",
+ args = {int.class}
+ )
+ })
+ public final void test_sessionTimeout() {
+ SSLSessionContextImpl sc = new SSLSessionContextImpl();
+ try {
+ assertEquals("0 wasn't returned", 0, sc.getSessionTimeout());
+ sc.setSessionTimeout(100);
+ assertEquals("100 wasn't returned", 100, sc.getSessionTimeout());
+ sc.setSessionTimeout(5000);
+ assertEquals("5000 wasn't returned", 5000, sc.getSessionTimeout());
+ } catch (Exception e) {
+ fail("Unexpected exception");
+ }
+
+ try {
+ sc.setSessionTimeout(-1);
+ fail("IllegalArgumentException wasn't thrown");
+ } catch (IllegalArgumentException iae) {
+ //expected
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLSessionContex#getSession(byte[] sessionId)
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getSession",
+ args = {byte[].class}
+ )
+ public final void test_getSession() {
+ SSLSessionContextImpl sc = new SSLSessionContextImpl();
+ try {
+ assertNull(sc.getSession(null));
+ assertNull(sc.getSession(new byte[5]));
+ } catch (Exception e) {
+ fail("Unexpected exception");
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLSessionContex#getIds()
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getIds",
+ args = {}
+ )
+ public final void test_getIds() {
+ SSLSessionContextImpl sc = new SSLSessionContextImpl();
+ try {
+ assertNull(sc.getIds());
+ } catch (Exception e) {
+ fail("Unexpected exception");
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/x-net/src/test/java/tests/api/javax/net/ssl/SSLSessionTest.java b/x-net/src/test/java/tests/api/javax/net/ssl/SSLSessionTest.java
new file mode 100644
index 0000000..123998d
--- /dev/null
+++ b/x-net/src/test/java/tests/api/javax/net/ssl/SSLSessionTest.java
@@ -0,0 +1,482 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+package tests.api.javax.net.ssl;
+
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargets;
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetNew;
+
+import javax.net.ssl.SSLSession;
+import javax.net.ssl.SSLPeerUnverifiedException;
+import javax.net.ssl.SSLSessionBindingListener;
+import javax.net.ssl.SSLSessionBindingEvent;
+
+import java.io.ByteArrayInputStream;
+import java.security.cert.Certificate;
+import javax.security.cert.X509Certificate;
+
+import junit.framework.TestCase;
+
+import org.apache.harmony.xnet.tests.support.mySSLSession;
+
+/**
+ * Tests for SSLSession class
+ *
+ */
+@TestTargetClass(SSLSession.class)
+public class SSLSessionTest extends TestCase {
+
+ String certificate = "-----BEGIN CERTIFICATE-----\n"
+ + "MIICZTCCAdICBQL3AAC2MA0GCSqGSIb3DQEBAgUAMF8xCzAJBgNVBAYTAlVTMSAw\n"
+ + "HgYDVQQKExdSU0EgRGF0YSBTZWN1cml0eSwgSW5jLjEuMCwGA1UECxMlU2VjdXJl\n"
+ + "IFNlcnZlciBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTAeFw05NzAyMjAwMDAwMDBa\n"
+ + "Fw05ODAyMjAyMzU5NTlaMIGWMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZv\n"
+ + "cm5pYTESMBAGA1UEBxMJUGFsbyBBbHRvMR8wHQYDVQQKExZTdW4gTWljcm9zeXN0\n"
+ + "ZW1zLCBJbmMuMSEwHwYDVQQLExhUZXN0IGFuZCBFdmFsdWF0aW9uIE9ubHkxGjAY\n"
+ + "BgNVBAMTEWFyZ29uLmVuZy5zdW4uY29tMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCB\n"
+ + "iQKBgQCofmdY+PiUWN01FOzEewf+GaG+lFf132UpzATmYJkA4AEA/juW7jSi+LJk\n"
+ + "wJKi5GO4RyZoyimAL/5yIWDV6l1KlvxyKslr0REhMBaD/3Z3EsLTTEf5gVrQS6sT\n"
+ + "WMoSZAyzB39kFfsB6oUXNtV8+UKKxSxKbxvhQn267PeCz5VX2QIDAQABMA0GCSqG\n"
+ + "SIb3DQEBAgUAA34AXl3at6luiV/7I9MN5CXYoPJYI8Bcdc1hBagJvTMcmlqL2uOZ\n"
+ + "H9T5hNMEL9Tk6aI7yZPXcw/xI2K6pOR/FrMp0UwJmdxX7ljV6ZtUZf7pY492UqwC\n"
+ + "1777XQ9UEZyrKJvF5ntleeO0ayBqLGVKCWzWZX9YsXCpv47FNLZbupE=\n"
+ + "-----END CERTIFICATE-----\n";
+
+
+ /**
+ * @tests javax.net.ssl.SSLSession#getPeerHost()
+ * @tests javax.net.ssl.SSLSession#getPeerPort()
+ */
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getPeerHost",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getPeerPort",
+ args = {}
+ )
+ })
+ public void test_getPeerHost() {
+ mySSLSession s = new mySSLSession("localhost", 1080, null);
+ try {
+ assertEquals(s.getPeerHost(), "localhost");
+ assertEquals(s.getPeerPort(), 1080);
+ } catch (Exception ex) {
+ fail("Unexpected exception " + ex);
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLSession#invalidate()
+ * @tests javax.net.ssl.SSLSession#isValid()
+ */
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "invalidate",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "isValid",
+ args = {}
+ )
+ })
+ public void test_invalidate() {
+ mySSLSession s = new mySSLSession("localhost", 1080, null);
+ try {
+ assertFalse(s.isValid());
+ s.invalidate();
+ assertTrue(s.isValid());
+ } catch (Exception ex) {
+ fail("Unexpected exception " + ex);
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLSession#getPeerPrincipal()
+ */
+ @TestTargetNew(
+ level = TestLevel.SUFFICIENT,
+ notes = "Exception wasn't implemented in the interface's class",
+ method = "getPeerPrincipal",
+ args = {}
+ )
+ public void test_getPeerPrincipal() {
+ mySSLSession s = new mySSLSession("localhost", 1080, null);
+ try {
+ assertNull(s.getPeerPrincipal());
+ } catch (Exception ex) {
+ fail("Unexpected exception " + ex);
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLSession#getApplicationBufferSize()
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getApplicationBufferSize",
+ args = {}
+ )
+ public void test_getApplicationBufferSize() {
+ mySSLSession s = new mySSLSession("localhost", 1080, null);
+ try {
+ assertEquals(s.getApplicationBufferSize(), 1234567);
+ } catch (Exception ex) {
+ fail("Unexpected exception " + ex);
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLSession#getCipherSuite()
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getCipherSuite",
+ args = {}
+ )
+ public void test_getCipherSuite() {
+ mySSLSession s = new mySSLSession("localhost", 1080, null);
+ try {
+ assertEquals(s.getCipherSuite(), "SuiteName");
+ } catch (Exception ex) {
+ fail("Unexpected exception " + ex);
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLSession#getCreationTime()
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getCreationTime",
+ args = {}
+ )
+ public void test_getCreationTime() {
+ mySSLSession s = new mySSLSession("localhost", 1080, null);
+ try {
+ assertEquals(s.getCreationTime(), 1000l);
+ } catch (Exception ex) {
+ fail("Unexpected exception " + ex);
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLSession#getId()
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getId",
+ args = {}
+ )
+ public void test_getId() {
+ byte[] data = {5, 10, 15};
+ mySSLSession s = new mySSLSession("localhost", 1080, data);
+ try {
+ assertEquals(s.getId(), data);
+ } catch (Exception ex) {
+ fail("Unexpected exception " + ex);
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLSession#getLastAccessedTime()
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getLastAccessedTime",
+ args = {}
+ )
+ public void test_getLastAccessedTime() {
+ mySSLSession s = new mySSLSession("localhost", 1080, null);
+ try {
+ assertEquals(s.getLastAccessedTime(), 2000l);
+ } catch (Exception ex) {
+ fail("Unexpected exception " + ex);
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLSession#getLocalCertificates()
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getLocalCertificates",
+ args = {}
+ )
+ public void test_getLocalCertificates() {
+ mySSLSession s = new mySSLSession("localhost", 1080, null);
+ try {
+ assertNull(s.getLocalCertificates());
+ } catch (Exception ex) {
+ fail("Unexpected exception " + ex);
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLSession#getLocalPrincipal()
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getLocalPrincipal",
+ args = {}
+ )
+ public void test_getLocalPrincipal() {
+ mySSLSession s = new mySSLSession("localhost", 1080, null);
+ try {
+ assertNull(s.getLocalPrincipal());
+ } catch (Exception ex) {
+ fail("Unexpected exception " + ex);
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLSession#getPacketBufferSize()
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getPacketBufferSize",
+ args = {}
+ )
+ public void test_getPacketBufferSize() {
+ mySSLSession s = new mySSLSession("localhost", 1080, null);
+ try {
+ assertEquals(s.getPacketBufferSize(), 12345);
+ } catch (Exception ex) {
+ fail("Unexpected exception " + ex);
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLSession#getPeerCertificates()
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getPeerCertificates",
+ args = {}
+ )
+ public void test_getPeerCertificates() {
+ mySSLSession s = new mySSLSession("localhost", 1080, null);
+ try {
+ Certificate[] res = s.getPeerCertificates();
+ fail("SSLPeerUnverifiedException wasn't thrown");
+ } catch (SSLPeerUnverifiedException pue) {
+ //expected
+ }
+ s = new mySSLSession(null);
+ try {
+ Certificate[] res = s.getPeerCertificates();
+ assertEquals(res.length, 3);
+ } catch (Exception e) {
+ fail("Unexpected exception: " + e);
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLSession#getPeerCertificateChain()
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getPeerCertificateChain",
+ args = {}
+ )
+ public void test_getPeerCertificateChain() {
+ ByteArrayInputStream bis = new ByteArrayInputStream(certificate.getBytes());
+ mySSLSession s = new mySSLSession("localhost", 1080, null);
+ try {
+ X509Certificate[] resN = s.getPeerCertificateChain();
+ fail("SSLPeerUnverifiedException wasn't thrown");
+ } catch (SSLPeerUnverifiedException pue) {
+ //expected
+ }
+ try {
+ X509Certificate xc = X509Certificate.getInstance(bis);
+ X509Certificate[] xcs = {xc};
+ s = new mySSLSession(xcs);
+ } catch (Exception e) {
+ fail(e + " was thrown for configuration");
+ }
+ try {
+ X509Certificate[] res = s.getPeerCertificateChain();
+ assertEquals(res.length, 1);
+ } catch (Exception e) {
+ fail("Unexpected exception: " + e);
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLSession#getProtocol()
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getProtocol",
+ args = {}
+ )
+ public void test_getProtocol() {
+ mySSLSession s = new mySSLSession("localhost", 1080, null);
+ try {
+ assertEquals(s.getProtocol(), "ProtocolName");
+ } catch (Exception e) {
+ fail("Unexpected exception: " + e);
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLSession#getSessionContext()
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getSessionContext",
+ args = {}
+ )
+ public void test_getSessionContext() {
+ mySSLSession s = new mySSLSession("localhost", 1080, null);
+ try {
+ assertNull(s.getSessionContext());
+ } catch (Exception e) {
+ fail("Unexpected exception: " + e);
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLSession#putValue(String name, Object value)
+ * @tests javax.net.ssl.SSLSession#removeValue(String name)
+ * @tests javax.net.ssl.SSLSession#getValueNames()
+ */
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "putValue",
+ args = {String.class, Object.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "removeValue",
+ args = {String.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getValueNames",
+ args = {}
+ )
+ })
+ public void test_putValue() {
+ mySSLSession s = new mySSLSession("localhost", 1080, null);
+ mySSLSessionBindingListener sbl = new mySSLSessionBindingListener();
+ try {
+ assertNotNull(s.getValueNames());
+ assertEquals(s.getValueNames().length, 0);
+ s.putValue("Name_01", sbl);
+ s.putValue("Name_02", sbl);
+ s.putValue("Name_03", sbl);
+ assertEquals(s.getValueNames().length, 3);
+ s.removeValue("Name_01");
+ assertEquals(s.getValueNames().length, 2);
+ } catch (Exception e) {
+ fail("Unexpected exception: " + e);
+ }
+
+ try {
+ s.putValue(null, null);
+ fail("IllegalArgumentException wasn't thrown");
+ } catch (IllegalArgumentException iae) {
+ //expected
+ }
+ try {
+ s.putValue("ABC", null);
+ fail("IllegalArgumentException wasn't thrown");
+ } catch (IllegalArgumentException iae) {
+ //expected
+ }
+ try {
+ s.putValue(null, sbl);
+ fail("IllegalArgumentException wasn't thrown");
+ } catch (IllegalArgumentException iae) {
+ //expected
+ }
+
+ try {
+ s.removeValue(null);
+ fail("IllegalArgumentException wasn't thrown");
+ } catch (IllegalArgumentException iae) {
+ //expected
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLSession#getValue(String name)
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getValue",
+ args = {String.class}
+ )
+ public void test_getValue() {
+ mySSLSession s = new mySSLSession("localhost", 1080, null);
+ mySSLSessionBindingListener sbl = new mySSLSessionBindingListener();
+
+ try {
+ s.getValue(null);
+ fail("IllegalArgumentException wasn't thrown");
+ } catch (IllegalArgumentException iae) {
+ //expected
+ }
+
+ try {
+ s.putValue("Name", sbl);
+ Object obj = s.getValue("Name");
+ assertTrue(obj instanceof SSLSessionBindingListener);
+ } catch (Exception e) {
+ fail("Unexpected exception: " + e);
+ }
+ }
+
+ public class mySSLSessionBindingListener implements SSLSessionBindingListener {
+ mySSLSessionBindingListener() {
+ }
+ public void valueBound(SSLSessionBindingEvent event) {}
+ public void valueUnbound(SSLSessionBindingEvent event) {}
+ }
+
+
+}
diff --git a/x-net/src/test/java/tests/api/javax/net/ssl/SSLSocketFactoryTest.java b/x-net/src/test/java/tests/api/javax/net/ssl/SSLSocketFactoryTest.java
index d9846a8..18b507e 100644
--- a/x-net/src/test/java/tests/api/javax/net/ssl/SSLSocketFactoryTest.java
+++ b/x-net/src/test/java/tests/api/javax/net/ssl/SSLSocketFactoryTest.java
@@ -5,7 +5,7 @@
* 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
+ * 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,
@@ -13,16 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package tests.api.javax.net.ssl;
import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestInfo;
import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTarget;
+import dalvik.annotation.TestTargetNew;
import java.io.IOException;
-import java.net.InetAddress;
+import java.net.ServerSocket;
import java.net.Socket;
import java.net.UnknownHostException;
@@ -30,93 +28,37 @@
import junit.framework.TestCase;
+import org.apache.harmony.xnet.tests.support.SSLSocketFactoryImpl;
+
+import tests.support.Support_PortManager;
+
@TestTargetClass(SSLSocketFactory.class)
public class SSLSocketFactoryTest extends TestCase {
-
- private class MockSSLSocketFactory extends SSLSocketFactory {
- public MockSSLSocketFactory() {
- super();
- }
-
- /**
- * @see javax.net.ssl.SSLSocketFactory#createSocket(java.net.Socket, java.lang.String, int, boolean)
- */
- @Override
- public Socket createSocket(Socket s, String host, int port, boolean autoClose) throws IOException {
- // it is a fake
- return null;
- }
-
- /**
- * @see javax.net.ssl.SSLSocketFactory#getDefaultCipherSuites()
- */
- @Override
- public String[] getDefaultCipherSuites() {
- // it is a fake
- return null;
- }
-
- /**
- * @see javax.net.ssl.SSLSocketFactory#getSupportedCipherSuites()
- */
- @Override
- public String[] getSupportedCipherSuites() {
- // it is a fake
- return null;
- }
-
- /**
- * @see javax.net.SocketFactory#createSocket(java.lang.String, int)
- */
- @Override
- public Socket createSocket(String arg0, int arg1) throws IOException, UnknownHostException {
- // it is a fake
- return null;
- }
-
- /**
- * @see javax.net.SocketFactory#createSocket(java.net.InetAddress, int)
- */
- @Override
- public Socket createSocket(InetAddress arg0, int arg1) throws IOException {
- // it is a fake
- return null;
- }
-
- /**
- * @see javax.net.SocketFactory#createSocket(java.lang.String, int, java.net.InetAddress, int)
- */
- @Override
- public Socket createSocket(String arg0, int arg1, InetAddress arg2, int arg3) throws IOException, UnknownHostException {
- // it is a fake
- return null;
- }
-
- /**
- * @see javax.net.SocketFactory#createSocket(java.net.InetAddress, int, java.net.InetAddress, int)
- */
- @Override
- public Socket createSocket(InetAddress arg0, int arg1, InetAddress arg2, int arg3) throws IOException {
- // it is a fake
- return null;
- }
- }
+ protected int startServer(String name) {
+ int portNumber = Support_PortManager.getNextPort();
+ ServerSocket ss = null;
+ try {
+ ss = new ServerSocket(portNumber);
+ } catch (IOException e) {
+ fail(name + ": " + e);
+ }
+ return ss.getLocalPort();
+ }
+
/**
* @tests javax.net.ssl.SSLSocketFactory#SSLSocketFactory()
*/
- @TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "SSLSocketFactory",
- methodArgs = {}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "SSLSocketFactory",
+ args = {}
+ )
public void test_Constructor() {
try {
- new MockSSLSocketFactory();
+ SSLSocketFactoryImpl sf = new SSLSocketFactoryImpl();
+ assertTrue(sf instanceof SSLSocketFactory);
} catch (Exception e) {
fail("Unexpected exception " + e.toString());
}
@@ -125,17 +67,103 @@
/**
* @tests javax.net.ssl.SSLSocketFactory#getDefault()
*/
- @TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getDefault",
- methodArgs = {}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getDefault",
+ args = {}
+ )
public void test_getDefault() {
assertNotNull("Incorrect default socket factory",
SSLSocketFactory.getDefault());
}
+
+ /**
+ * @tests javax.net.ssl.SSLSocketFactory#createSocket(Socket s, String host, int port, boolean autoClose)
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "createSocket",
+ args = {java.net.Socket.class, java.lang.String.class, int.class, boolean.class}
+ )
+ public void test_createSocket() {
+ SSLSocketFactoryImpl sf = new SSLSocketFactoryImpl();
+ int sport = startServer("test_createSocket()");
+ int[] invalid = {Integer.MIN_VALUE, -1, 65536, Integer.MAX_VALUE};
+ String[] str = {null, ""};
+ try {
+ Socket s = sf.createSocket(new Socket(), "localhost", sport, false);
+ assertFalse(s.isClosed());
+ } catch (Exception ex) {
+ fail("Unexpected exception " + ex);
+ }
+ try {
+ Socket s = sf.createSocket(new Socket(), "localhost", sport, true);
+ assertTrue(s.isClosed());
+ } catch (Exception ex) {
+ fail("Unexpected exception " + ex);
+ }
+ try {
+ Socket s = sf.createSocket(null, "localhost", sport, true);
+ fail("IOException wasn't thrown");
+ } catch (IOException ioe) {
+ //expected
+ }
+ for (int i = 0; i < invalid.length; i++) {
+ try {
+ Socket s = sf.createSocket(new Socket(), "localhost", invalid[i], false);
+ fail("IOException wasn't thrown");
+ } catch (IOException ioe) {
+ //expected
+ }
+ }
+ for (int i = 0; i < str.length; i++) {
+ try {
+ Socket s = sf.createSocket(new Socket(), str[i], sport, false);
+ fail("UnknownHostException wasn't thrown");
+ } catch (UnknownHostException uhe) {
+ //expected
+ } catch (Exception e) {
+ fail(e + " was thrown instead of UnknownHostException");
+ }
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLSocketFactory#getDefaultCipherSuites()
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getDefaultCipherSuites",
+ args = {}
+ )
+ public void test_getDefaultCipherSuites() {
+ try {
+ SSLSocketFactoryImpl sf = new SSLSocketFactoryImpl();
+ assertNull(sf.getDefaultCipherSuites());
+ } catch (Exception e) {
+ fail("Unexpected exception " + e.toString());
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLSocketFactory#getSupportedCipherSuites()
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getSupportedCipherSuites",
+ args = {}
+ )
+ public void test_getSupportedCipherSuites() {
+ try {
+ SSLSocketFactoryImpl sf = new SSLSocketFactoryImpl();
+ assertNull(sf.getSupportedCipherSuites());
+ } catch (Exception e) {
+ fail("Unexpected exception " + e.toString());
+ }
+ }
+
}
diff --git a/x-net/src/test/java/tests/api/javax/net/ssl/SSLSocketTest.java b/x-net/src/test/java/tests/api/javax/net/ssl/SSLSocketTest.java
new file mode 100644
index 0000000..31b19fd
--- /dev/null
+++ b/x-net/src/test/java/tests/api/javax/net/ssl/SSLSocketTest.java
@@ -0,0 +1,707 @@
+/*
+ * Copyright (C) 2007 The Android Open Source Project
+ *
+ * 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.
+ */
+package tests.api.javax.net.ssl;
+
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargets;
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetNew;
+
+import javax.net.ssl.*;
+import java.net.*;
+import java.lang.String;
+import java.lang.IllegalStateException;
+import java.io.IOException;
+
+
+import junit.framework.TestCase;
+import org.apache.harmony.xnet.tests.support.mySSLSocket;
+
+import tests.support.Support_PortManager;
+
+@TestTargetClass(SSLSocket.class)
+public class SSLSocketTest extends TestCase {
+
+ public class HandshakeCL implements HandshakeCompletedListener {
+ HandshakeCL() {
+ super();
+ }
+ public void handshakeCompleted(HandshakeCompletedEvent event) {
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLSocket#SSLSocket()
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "SSLSocket",
+ args = {}
+ )
+ public void testConstructor_01() {
+ try {
+ mySSLSocket ssl = new mySSLSocket();
+ assertNotNull(ssl);
+ assertTrue(ssl instanceof SSLSocket);
+ } catch (Exception e) {
+ fail("Unexpected exception " + e);
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLSocket#SSLSocket(InetAddress address, int port)
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "SSLSocket",
+ args = {java.net.InetAddress.class, int.class}
+ )
+ public void testConstructor_02() {
+ mySSLSocket ssl;
+ int sport = startServer("Cons InetAddress,I");
+ int[] invalidPort = {-1, Integer.MIN_VALUE, 65536, Integer.MAX_VALUE};
+
+ try {
+ ssl = new mySSLSocket(InetAddress.getLocalHost(), sport);
+ assertNotNull(ssl);
+ assertEquals(sport, ssl.getPort());
+ } catch (Exception e) {
+ fail("Unexpected exception: " + e);
+ }
+
+ try {
+ ssl = new mySSLSocket(InetAddress.getLocalHost(), 8081);
+ fail("IOException wasn't thrown ...");
+ } catch (IOException e) {
+ //expected
+ }
+
+ for (int i = 0; i < invalidPort.length; i++) {
+ try {
+ ssl = new mySSLSocket(InetAddress.getLocalHost(), invalidPort[i]);
+ fail("IllegalArgumentException wasn't thrown for " + invalidPort[i]);
+ } catch (IllegalArgumentException iae) {
+ } catch (Exception e) {
+ fail(e + " was thrown instead of IllegalArgumentException for " + invalidPort[i]);
+ }
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLSocket#SSLSocket(InetAddress address, int port,
+ * InetAddress clientAddress, int clientPort)
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "SSLSocket",
+ args = {java.net.InetAddress.class, int.class, java.net.InetAddress.class, int.class}
+ )
+ public void testConstructor_03() {
+ mySSLSocket ssl;
+ int sport = startServer("Cons InetAddress,I,InetAddress,I");
+ int portNumber = Support_PortManager.getNextPort();
+ int[] invalidPort = {-1, Integer.MIN_VALUE, 65536, Integer.MAX_VALUE};
+
+ try {
+ ssl = new mySSLSocket(InetAddress.getLocalHost(), sport,
+ InetAddress.getLocalHost(), portNumber);
+ assertNotNull(ssl);
+ assertEquals(sport, ssl.getPort());
+ assertEquals(portNumber, ssl.getLocalPort());
+ } catch (Exception e) {
+ fail("Unexpected exception: " + e);
+ }
+
+ try {
+ ssl = new mySSLSocket(InetAddress.getLocalHost(), 8081, InetAddress.getLocalHost(), 8082);
+ fail("IOException wasn't thrown ...");
+ } catch (IOException e) {
+ //expected
+ }
+
+ for (int i = 0; i < invalidPort.length; i++) {
+ try {
+ ssl = new mySSLSocket(InetAddress.getLocalHost(), invalidPort[i],
+ InetAddress.getLocalHost(), portNumber);
+ fail("IllegalArgumentException wasn't thrown for " + invalidPort[i]);
+ } catch (IllegalArgumentException iae) {
+ } catch (Exception e) {
+ fail(e + " was thrown instead of IllegalArgumentException for " + invalidPort[i]);
+ }
+ try {
+ ssl = new mySSLSocket(InetAddress.getLocalHost(), sport,
+ InetAddress.getLocalHost(), invalidPort[i]);
+ fail("IllegalArgumentException wasn't thrown for " + invalidPort[i]);
+ } catch (IllegalArgumentException iae) {
+ } catch (Exception e) {
+ fail(e + " was thrown instead of IllegalArgumentException for " + invalidPort[i]);
+ }
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLSocket#SSLSocket(String host, int port)
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "SSLSocket",
+ args = {java.lang.String.class, int.class}
+ )
+ public void testConstructor_04() {
+ mySSLSocket ssl;
+ int sport = startServer("Cons String,I");
+ int[] invalidPort = {-1, Integer.MIN_VALUE, 65536, Integer.MAX_VALUE};
+
+ try {
+ ssl = new mySSLSocket(InetAddress.getLocalHost().getHostName(), sport);
+ assertNotNull(ssl);
+ assertEquals(sport, ssl.getPort());
+ } catch (Exception e) {
+ fail("Unexpected exception: " + e);
+ }
+
+ try {
+ ssl = new mySSLSocket("localhost", 8082);
+ fail("IOException wasn't thrown ...");
+ } catch (IOException e) {
+ //expected
+ }
+
+ for (int i = 0; i < invalidPort.length; i++) {
+ try {
+ ssl = new mySSLSocket(InetAddress.getLocalHost().getHostName(), invalidPort[i]);
+ fail("IllegalArgumentException wasn't thrown for " + invalidPort[i]);
+ } catch (IllegalArgumentException iae) {
+ } catch (Exception e) {
+ fail(e + " was thrown instead of IllegalArgumentException for " + invalidPort[i]);
+ }
+ }
+
+ try {
+ ssl = new mySSLSocket("bla-bla", sport);
+ fail("UnknownHostException wasn't thrown");
+ } catch (UnknownHostException uhp) {
+ } catch (Exception e) {
+ fail(e + " was thrown instead of UnknownHostException");
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLSocket#SSLSocket(String host, int port, InetAddress clientAddress,
+ * int clientPort)
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "SSLSocket",
+ args = {java.lang.String.class, int.class, java.net.InetAddress.class, int.class}
+ )
+ public void testConstructor_05() {
+ mySSLSocket ssl;
+ int sport = startServer("Cons String,I,InetAddress,I");
+ int portNumber = Support_PortManager.getNextPort();
+ int[] invalidPort = {-1, Integer.MIN_VALUE, 65536, Integer.MAX_VALUE};
+
+ try {
+ ssl = new mySSLSocket(InetAddress.getLocalHost().getHostName(), sport,
+ InetAddress.getLocalHost(), portNumber);
+ assertNotNull(ssl);
+ assertEquals(sport, ssl.getPort());
+ assertEquals(portNumber, ssl.getLocalPort());
+ } catch (Exception e) {
+ fail("Unexpected exception: " + e);
+ }
+
+ try {
+ ssl = new mySSLSocket("localhost", 8081, InetAddress.getLocalHost(), 8082);
+ fail("IOException wasn't thrown ...");
+ } catch (IOException e) {
+ //expected
+ }
+
+ for (int i = 0; i < invalidPort.length; i++) {
+ portNumber = Support_PortManager.getNextPort();
+ try {
+ ssl = new mySSLSocket(InetAddress.getLocalHost().getHostName(), invalidPort[i],
+ InetAddress.getLocalHost(), portNumber);
+ fail("IllegalArgumentException wasn't thrown for " + invalidPort[i]);
+ } catch (IllegalArgumentException iae) {
+ } catch (Exception e) {
+ fail(e + " was thrown instead of IllegalArgumentException for " + invalidPort[i]);
+ }
+ try {
+ ssl = new mySSLSocket(InetAddress.getLocalHost().getHostName(), sport,
+ InetAddress.getLocalHost(), invalidPort[i]);
+ fail("IllegalArgumentException wasn't thrown for " + invalidPort[i]);
+ } catch (IllegalArgumentException iae) {
+ } catch (Exception e) {
+ fail(e + " was thrown instead of IllegalArgumentException for " + invalidPort[i]);
+ }
+ }
+
+ portNumber = Support_PortManager.getNextPort();
+ try {
+ ssl = new mySSLSocket("bla-bla", sport, InetAddress.getLocalHost(), portNumber);
+ fail("UnknownHostException wasn't thrown");
+ } catch (UnknownHostException uhp) {
+ } catch (Exception e) {
+ fail(e + " was thrown instead of UnknownHostException");
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLSocket#addHandshakeCompletedListener(HandshakeCompletedListener listener)
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "addHandshakeCompletedListener",
+ args = {javax.net.ssl.HandshakeCompletedListener.class}
+ )
+ public void test_addHandshakeCompletedListener() {
+ mySSLSocket ssl = new mySSLSocket();
+ HandshakeCompletedListener ls = new HandshakeCL();
+ try {
+ ssl.addHandshakeCompletedListener(null);
+ fail("IllegalArgumentException wasn't thrown");
+ } catch (IllegalArgumentException iae) {
+ //expected
+ }
+ try {
+ ssl.addHandshakeCompletedListener(ls);
+ } catch (Exception e) {
+ fail("Unexpected exception " + e);
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLSocket#removeHandshakeCompletedListener(HandshakeCompletedListener listener)
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "removeHandshakeCompletedListener",
+ args = {javax.net.ssl.HandshakeCompletedListener.class}
+ )
+ public void test_removeHandshakeCompletedListener() {
+ mySSLSocket ssl = new mySSLSocket();
+ HandshakeCompletedListener ls = new HandshakeCL();
+ try {
+ ssl.removeHandshakeCompletedListener(null);
+ fail("IllegalArgumentException wasn't thrown");
+ } catch (IllegalArgumentException iae) {
+ //expected
+ }
+ try {
+ ssl.removeHandshakeCompletedListener(ls);
+ } catch (Exception e) {
+ fail("Unexpected exception " + e);
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLSocket#setEnableSessionCreation(boolean flag)
+ * @tests javax.net.ssl.SSLSocket#getEnableSessionCreation()
+ */
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getEnableSessionCreation",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "setEnableSessionCreation",
+ args = {boolean.class}
+ )
+ })
+ public void test_EnableSessionCreation() {
+ mySSLSocket ssl = new mySSLSocket();
+ try {
+ assertTrue(ssl.getEnableSessionCreation());
+ ssl.setEnableSessionCreation(false);
+ assertFalse(ssl.getEnableSessionCreation());
+ ssl.setEnableSessionCreation(true);
+ assertTrue(ssl.getEnableSessionCreation());
+ } catch (Exception e) {
+ fail("Unexpected exception " + e);
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLSocket#setNeedClientAuth(boolean need)
+ * @tests javax.net.ssl.SSLSocket#getNeedClientAuthCreation()
+ */
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "setNeedClientAuth",
+ args = {boolean.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getNeedClientAuth",
+ args = {}
+ )
+ })
+ public void test_NeedClientAuth() {
+ mySSLSocket ssl = new mySSLSocket(1);
+ try {
+ try {
+ ssl.setNeedClientAuth(true);
+ fail("IllegalStateException wasn't thrown");
+ } catch (IllegalStateException ise) {
+ //expected
+ }
+
+ try {
+ ssl.getNeedClientAuth();
+ fail("IllegalStateException wasn't thrown");
+ } catch (IllegalStateException ise) {
+ //expected
+ }
+ ssl = new mySSLSocket(0);
+ ssl.setNeedClientAuth(true);
+ assertTrue(ssl.getNeedClientAuth());
+ ssl.setNeedClientAuth(false);
+ assertFalse(ssl.getNeedClientAuth());
+ } catch (Exception e) {
+ fail("Unexpected exception " + e);
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLSocket#setWantClientAuth(boolean want)
+ * @tests javax.net.ssl.SSLSocket#getWantClientAuthCreation()
+ */
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "setWantClientAuth",
+ args = {boolean.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getWantClientAuth",
+ args = {}
+ )
+ })
+ public void test_WantClientAuth() {
+ mySSLSocket ssl = new mySSLSocket(1);
+ try {
+ try {
+ ssl.setWantClientAuth(true);
+ fail("IllegalStateException wasn't thrown");
+ } catch (IllegalStateException ise) {
+ //expected
+ }
+
+ try {
+ ssl.getWantClientAuth();
+ fail("IllegalStateException wasn't thrown");
+ } catch (IllegalStateException ise) {
+ //expected
+ }
+ ssl = new mySSLSocket(0);
+ ssl.setWantClientAuth(true);
+ assertTrue(ssl.getWantClientAuth());
+ ssl.setWantClientAuth(false);
+ assertFalse(ssl.getWantClientAuth());
+ } catch (Exception e) {
+ fail("Unexpected exception " + e);
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLSocket#getSupportedProtocols()
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getSupportedProtocols",
+ args = {}
+ )
+ public void test_getSupportedProtocols() {
+ String[] pr = {"Protocol_1", "Protocol_2", "Protocol_3"};
+ mySSLSocket ssl = new mySSLSocket();
+ try {
+ try {
+ ssl.getSupportedProtocols();
+ } catch (NullPointerException npe) {
+ //expected
+ }
+ ssl = new mySSLSocket(null, null);
+ try {
+ ssl.getSupportedProtocols();
+ } catch (NullPointerException npe) {
+ //expected
+ }
+ ssl = new mySSLSocket(new String[0], null);
+ assertNull("Not NULL result", ssl.getSupportedProtocols());
+ ssl = new mySSLSocket(pr, null);
+ String[] res = ssl.getSupportedProtocols();
+ assertNotNull("NULL result", res);
+ if (!res.equals(pr)) {
+ fail("Returned result was incorrect");
+ }
+ } catch (Exception e) {
+ fail("Unexpected exception " + e);
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLSocket#getEnabledProtocols()
+ * @tests javax.net.ssl.SSLSocket#setEnabledProtocols(String[] protocols)
+ */
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "setEnabledProtocols",
+ args = {java.lang.String[].class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getEnabledProtocols",
+ args = {}
+ )
+ })
+ public void test_EnabledProtocols() {
+ String[] pr1 = {"Protocol_1", "Protocol_2", "Protocol_3"};
+ String[] pr2 = {"Protocol_1", "Protocol_2"};
+ mySSLSocket ssl = new mySSLSocket(pr1, null);
+ try {
+ try {
+ ssl.setEnabledProtocols(null);
+ } catch (IllegalArgumentException iae) {
+ //expected
+ }
+ try {
+ ssl.setEnabledProtocols(pr2);
+ } catch (IllegalArgumentException iae) {
+ //expected
+ }
+ ssl.setEnabledProtocols(pr1);
+ String[] res = ssl.getEnabledProtocols();
+ assertNotNull("NULL result", res);
+ if (!res.equals(pr1)) {
+ fail("Returned result was incorrect");
+ }
+ } catch (Exception e) {
+ fail("Unexpected exception " + e);
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLSocket#getSession()
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getSession",
+ args = {}
+ )
+ public void test_getSession() {
+ mySSLSocket ssl = new mySSLSocket();
+ try {
+ assertNull(ssl.getSession());
+ } catch (Exception e) {
+ fail("Unexpected exception " + e);
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLSocket#getSupportedCipherSuites()
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getSupportedCipherSuites",
+ args = {}
+ )
+ public void test_getSupportedCipherSuites() {
+ String[] pr = {"Suite_1", "Suite_2", "Suite_3"};
+ mySSLSocket ssl = new mySSLSocket();
+ try {
+ try {
+ ssl.getSupportedCipherSuites();
+ } catch (NullPointerException npe) {
+ //expected
+ }
+ ssl = new mySSLSocket(null, null);
+ try {
+ ssl.getSupportedCipherSuites();
+ } catch (NullPointerException npe) {
+ //expected
+ }
+ ssl = new mySSLSocket(new String[0], new String[0]);
+ assertNull("Not NULL result", ssl.getSupportedCipherSuites());
+ ssl = new mySSLSocket(null, pr);
+ String[] res = ssl.getSupportedCipherSuites();
+ assertNotNull("NULL result", res);
+ if (!res.equals(pr)) {
+ fail("Returned result was incorrect");
+ }
+ } catch (Exception e) {
+ fail("Unexpected exception " + e);
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLSocket#getEnabledCipherSuites()
+ * @tests javax.net.ssl.SSLSocket#setEnabledCipherSuites(String[] suites)
+ */
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getEnabledCipherSuites",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "setEnabledCipherSuites",
+ args = {java.lang.String[].class}
+ )
+ })
+ public void test_EnabledCipherSuites() {
+ String[] pr1 = {"Suite_1", "Suite_2", "Suite_3"};
+ String[] pr2 = {"Suite_1", "Suite_2"};
+ mySSLSocket ssl = new mySSLSocket(null, pr1);
+ try {
+ try {
+ ssl.setEnabledCipherSuites(null);
+ } catch (IllegalArgumentException iae) {
+ //expected
+ }
+ try {
+ ssl.setEnabledCipherSuites(pr2);
+ } catch (IllegalArgumentException iae) {
+ //expected
+ }
+ ssl.setEnabledCipherSuites(pr1);
+ String[] res = ssl.getEnabledCipherSuites();
+ assertNotNull("NULL result", res);
+ if (!res.equals(pr1)) {
+ fail("Returned result was incorrect");
+ }
+ } catch (Exception e) {
+ fail("Unexpected exception " + e);
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLSocket#getUseClientMode()
+ * @tests javax.net.ssl.SSLSocket#setUseClientMode(boolean mode)
+ */
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getUseClientMode",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "setUseClientMode",
+ args = {boolean.class}
+ )
+ })
+ public void test_UseClientMode() {
+ String[] pr = {"Protocol_1", "Protocol_3"};
+ mySSLSocket ssl = new mySSLSocket(0, pr, null);
+ try {
+ assertFalse(ssl.getUseClientMode());
+ ssl.setUseClientMode(true);
+ assertTrue(ssl.getUseClientMode());
+ } catch (Exception e) {
+ fail("Unexpected exception " + e);
+ }
+ ssl = new mySSLSocket(1, pr, null);
+ try {
+ assertTrue(ssl.getUseClientMode());
+ ssl.setUseClientMode(false);
+ assertFalse(ssl.getUseClientMode());
+ } catch (Exception e) {
+ fail("Unexpected exception " + e);
+ }
+ try {
+ ssl.startHandshake();
+ ssl.setUseClientMode(false);
+ fail("IllegalArgumentException wasn't thrown");
+ } catch (IllegalArgumentException iae) {
+ //expected
+ } catch (IOException ioe) {
+ fail(ioe + " was thrown for method startHandshake()");
+ } catch (Exception e) {
+ fail(e + " was thrown instead of IllegalArgumentException");
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.SSLSocket#startHandshake()
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "startHandshake",
+ args = {}
+ )
+ public void test_startHandshake() {
+ String[] pr = {"Protocol_1", "Protocol_3"};
+ String[] pr1 = {"Protocol_1", "Protocol_3", "Protocol_2"};
+ mySSLSocket ssl = new mySSLSocket(pr, null);
+ try {
+ ssl.startHandshake();
+ } catch (Exception e) {
+ fail("Unexpected exception " + e);
+ }
+ ssl = new mySSLSocket(pr1, null);
+ try {
+ ssl.startHandshake();
+ fail("IOException wasn't thrown");
+ } catch (IOException ioe) {
+ //expected
+ } catch (Exception e) {
+ fail(e + " was thrown instead of IOException");
+ }
+ }
+
+ protected int startServer(String name) {
+ int portNumber = Support_PortManager.getNextPort();
+ ServerSocket ss = null;
+ try {
+ ss = new ServerSocket(portNumber);
+ } catch (IOException e) {
+ fail(name + ": " + e);
+ }
+ return ss.getLocalPort();
+ }
+}
+
diff --git a/x-net/src/test/java/tests/api/javax/net/ssl/TrustManagerFactory1Test.java b/x-net/src/test/java/tests/api/javax/net/ssl/TrustManagerFactory1Test.java
index 2dd2523..001b02f 100644
--- a/x-net/src/test/java/tests/api/javax/net/ssl/TrustManagerFactory1Test.java
+++ b/x-net/src/test/java/tests/api/javax/net/ssl/TrustManagerFactory1Test.java
@@ -18,9 +18,9 @@
package tests.api.javax.net.ssl;
import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestInfo;
import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTarget;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.KnownFailure;
import java.io.IOException;
import java.security.InvalidAlgorithmParameterException;
@@ -29,6 +29,7 @@
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.Provider;
+import java.security.PublicKey;
import java.security.Security;
import java.security.cert.CertificateException;
@@ -38,9 +39,19 @@
import javax.net.ssl.TrustManagerFactorySpi;
import org.apache.harmony.security.tests.support.SpiEngUtils;
+import org.apache.harmony.security.tests.support.TestKeyPair;
import org.apache.harmony.xnet.tests.support.MyTrustManagerFactorySpi;
import junit.framework.TestCase;
+//
+import java.security.cert.TrustAnchor;
+import java.security.cert.X509CertSelector;
+import java.security.cert.PKIXBuilderParameters;
+import javax.net.ssl.CertPathTrustManagerParameters;
+
+import java.util.HashSet;
+import java.util.Set;
+
/**
* Tests for <code>TrustManagerFactory</code> class constructors and methods.
*
@@ -103,15 +114,12 @@
* constructor
* Assertion: created new TrustManagerFactory object
*/
- @TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "TrustManagerFactory",
- methodArgs = {TrustManagerFactorySpi.class, Provider.class, String.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "TrustManagerFactory",
+ args = {javax.net.ssl.TrustManagerFactorySpi.class, java.security.Provider.class, java.lang.String.class}
+ )
public void test_ConstructorLjavax_net_ssl_TrustManagerFactorySpiLjava_security_ProviderLjava_lang_String()
throws NoSuchAlgorithmException {
if (!DEFSupported) {
@@ -144,15 +152,12 @@
* @throws NoSuchAlgorithmException
* @throws NoSuchProviderException
*/
- @TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getAlgorithm",
- methodArgs = {}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getAlgorithm",
+ args = {}
+ )
public void test_getAlgorithm()
throws NoSuchAlgorithmException, NoSuchProviderException {
if (!DEFSupported) fail(NotSupportedMsg);
@@ -175,15 +180,12 @@
* Test for <code>getDefaultAlgorithm()</code> method
* Assertion: returns value which is specifoed in security property
*/
- @TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getDefaultAlgorithm",
- methodArgs = {}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getDefaultAlgorithm",
+ args = {}
+ )
public void test_getDefaultAlgorithm() {
if (!DEFSupported) {
fail(NotSupportedMsg);
@@ -212,15 +214,12 @@
* Assertions: returns security property "ssl.TrustManagerFactory.algorithm";
* returns instance of TrustManagerFactory
*/
- @TestInfo(
- level = TestLevel.PARTIAL_OK,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getInstance",
- methodArgs = {String.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "getInstance",
+ args = {java.lang.String.class}
+ )
public void test_getInstanceLjava_lang_String01() throws NoSuchAlgorithmException {
if (!DEFSupported) {
fail(NotSupportedMsg);
@@ -242,15 +241,12 @@
* throws NullPointerException when algorithm is null;
* throws NoSuchAlgorithmException when algorithm is not correct;
*/
- @TestInfo(
- level = TestLevel.PARTIAL_OK,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getInstance",
- methodArgs = {String.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "getInstance",
+ args = {java.lang.String.class}
+ )
public void test_getInstanceLjava_lang_String02() {
try {
TrustManagerFactory.getInstance(null);
@@ -274,15 +270,12 @@
* Assertion: throws IllegalArgumentException when provider is null
* or empty
*/
- @TestInfo(
- level = TestLevel.PARTIAL_OK,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getInstance",
- methodArgs = {String.class, String.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "getInstance",
+ args = {java.lang.String.class, java.lang.String.class}
+ )
public void test_getInstanceLjava_lang_StringLjava_lang_String01() throws NoSuchProviderException,
NoSuchAlgorithmException {
if (!DEFSupported) {
@@ -311,15 +304,12 @@
* throws NullPointerException when algorithm is null;
* throws NoSuchAlgorithmException when algorithm is not correct;
*/
- @TestInfo(
- level = TestLevel.PARTIAL_OK,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getInstance",
- methodArgs = {String.class, String.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "getInstance",
+ args = {java.lang.String.class, java.lang.String.class}
+ )
public void test_getInstanceLjava_lang_StringLjava_lang_String02() throws NoSuchProviderException {
if (!DEFSupported) {
fail(NotSupportedMsg);
@@ -348,15 +338,12 @@
* Assertion: throws NoSuchProviderException when provider has
* invalid value
*/
- @TestInfo(
- level = TestLevel.PARTIAL_OK,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getInstance",
- methodArgs = {String.class, String.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "getInstance",
+ args = {java.lang.String.class, java.lang.String.class}
+ )
public void test_getInstanceLjava_lang_StringLjava_lang_String03() throws NoSuchAlgorithmException {
if (!DEFSupported) {
fail(NotSupportedMsg);
@@ -381,15 +368,12 @@
* method
* Assertion: returns instance of TrustManagerFactory
*/
- @TestInfo(
- level = TestLevel.PARTIAL_OK,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getInstance",
- methodArgs = {String.class, String.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "getInstance",
+ args = {java.lang.String.class, java.lang.String.class}
+ )
public void test_getInstanceLjava_lang_StringLjava_lang_String04() throws NoSuchAlgorithmException,
NoSuchProviderException {
if (!DEFSupported) {
@@ -414,15 +398,12 @@
* method
* Assertion: throws IllegalArgumentException when provider is null
*/
- @TestInfo(
- level = TestLevel.PARTIAL_OK,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getInstance",
- methodArgs = {String.class, Provider.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "getInstance",
+ args = {java.lang.String.class, java.security.Provider.class}
+ )
public void test_getInstanceLjava_lang_StringLjava_security_Provider01() throws NoSuchAlgorithmException {
if (!DEFSupported) {
fail(NotSupportedMsg);
@@ -445,15 +426,12 @@
* throws NullPointerException when algorithm is null;
* throws NoSuchAlgorithmException when algorithm is not correct;
*/
- @TestInfo(
- level = TestLevel.PARTIAL_OK,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getInstance",
- methodArgs = {String.class, Provider.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "getInstance",
+ args = {java.lang.String.class, java.security.Provider.class}
+ )
public void test_getInstanceLjava_lang_StringLjava_security_Provider02() {
if (!DEFSupported) {
fail(NotSupportedMsg);
@@ -481,15 +459,12 @@
* method
* Assertion: returns instance of TrustManagerFactory
*/
- @TestInfo(
- level = TestLevel.PARTIAL_OK,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getInstance",
- methodArgs = {String.class, Provider.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "getInstance",
+ args = {java.lang.String.class, java.security.Provider.class}
+ )
public void test_getInstanceLjava_lang_StringLjava_security_Provider03() throws NoSuchAlgorithmException {
if (!DEFSupported) {
fail(NotSupportedMsg);
@@ -513,15 +488,12 @@
* @throws NoSuchAlgorithmException
* @throws NoSuchProviderException
*/
- @TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getProvider",
- methodArgs = {}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getProvider",
+ args = {}
+ )
public void test_getProvider()
throws NoSuchAlgorithmException, NoSuchProviderException {
if (!DEFSupported) fail(NotSupportedMsg);
@@ -547,66 +519,81 @@
* @throws CertificateException
* @throws NoSuchAlgorithmException
*/
- @TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getTrustManagers",
- methodArgs = {}
- )
- })
- public void _test_getTrustManagers()
- throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException {
- KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
- ks.load(null, null);
- TrustManager[] tm;
- TrustManagerFactory[] trustMF = createTMFac();
- assertNotNull("TrustManagerFactory objects were not created", trustMF);
- for (int i = 0; i < trustMF.length; i++) {
- try {
- trustMF[i].init((KeyStore)null);
- } catch (KeyStoreException e) {
- fail("Unexpected exception " + e.toString());
- }
- trustMF[i].init(ks);
- tm = trustMF[i].getTrustManagers();
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getTrustManagers",
+ args = {}
+ )
+ public void test_getTrustManagers() {
+ try {
+ TrustManagerFactory trustMF = TrustManagerFactory.getInstance(defaultAlgorithm);
+ KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
+ ks.load(null, null);
+ trustMF.init(ks);
+ TrustManager[] tm = trustMF.getTrustManagers();
assertNotNull("Result has not be null", tm);
assertTrue("Length of result TrustManager array should not be 0",
(tm.length > 0));
+ } catch (Exception ex) {
+ fail("Unexpected exception " + ex.toString());
}
}
/**
* Test for <code>init(KeyStore keyStore)</code>
- * Assertion: returns not empty TrustManager array
+ * Assertion: call method with null parameter
*/
- @TestInfo(
- level = TestLevel.TODO,
- purpose = "Method init wasn't invoked in this test",
- targets = {
- @TestTarget(
- methodName = "init",
- methodArgs = {KeyStore.class}
- )
- })
- public void test_initLjava_security_KeyStore() throws NoSuchAlgorithmException,
- KeyStoreException {
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "init",
+ args = {java.security.KeyStore.class}
+ )
+ @KnownFailure("The RI doesn't throw any exception for null parameter.")
+ public void test_initLjava_security_KeyStore_01() {
if (!DEFSupported) {
fail(NotSupportedMsg);
return;
}
- KeyStore ks;
+
KeyStore ksNull = null;
+ TrustManagerFactory[] trustMF = createTMFac();
+ assertNotNull("TrustManagerFactory objects were not created", trustMF);
+ // null parameter
try {
- ks = KeyStore.getInstance(KeyStore.getDefaultType());
- ks.load(null, null);
- } catch (KeyStoreException e) {
- fail(e.toString() + "default KeyStore type is not supported");
+ trustMF[0].init(ksNull);
+ } catch (Exception ex) {
+ fail(ex + " unexpected exception was thrown for null parameter");
+ }
+ }
+
+ /**
+ * Test for <code>init(KeyStore keyStore)</code>
+ * Assertion: call method with not null parameter
+ */
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "init",
+ args = {java.security.KeyStore.class}
+ )
+ public void test_initLjava_security_KeyStore_02() throws KeyStoreException {
+ if (!DEFSupported) {
+ fail(NotSupportedMsg);
return;
- } catch (Exception e) {
- fail("Unexpected: " + e.toString());
- return;
+ }
+
+ KeyStore ks;
+ ks = KeyStore.getInstance(KeyStore.getDefaultType());
+ TrustManagerFactory[] trustMF = createTMFac();
+ assertNotNull("TrustManagerFactory objects were not created", trustMF);
+
+ // not null parameter
+ try {
+ trustMF[0].init(ks);
+ } catch (Exception ex) {
+ fail(ex + " unexpected exception was thrown for not null parameter");
}
}
@@ -615,24 +602,20 @@
* Assertion:
* throws InvalidAlgorithmParameterException when params is null
*/
- @TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "InvalidAlgorithmParameterException case was tested only",
- targets = {
- @TestTarget(
- methodName = "init",
- methodArgs = {ManagerFactoryParameters.class}
- )
- })
- public void test_initLjavax_net_ssl_ManagerFactoryParameters()
- throws NoSuchAlgorithmException,
- KeyStoreException, InvalidAlgorithmParameterException {
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "init",
+ args = {javax.net.ssl.ManagerFactoryParameters.class}
+ )
+ @KnownFailure("ManagerFactoryParameters object is not supported " +
+ "and InvalidAlgorithmParameterException was thrown.")
+ public void test_initLjavax_net_ssl_ManagerFactoryParameters() {
if (!DEFSupported) {
fail(NotSupportedMsg);
return;
}
ManagerFactoryParameters par = null;
- ManagerFactoryParameters par1 = new myManagerFactoryParam();
TrustManagerFactory[] trustMF = createTMFac();
assertNotNull("TrustManagerFactory objects were not created", trustMF);
for (int i = 0; i < trustMF.length; i++) {
@@ -641,14 +624,80 @@
fail("InvalidAlgorithmParameterException must be thrown");
} catch (InvalidAlgorithmParameterException e) {
}
+ }
+
+ //
+ String keyAlg = "DSA";
+ String validCaNameRfc2253 = "CN=Test CA," +
+ "OU=Testing Division," +
+ "O=Test It All," +
+ "L=Test Town," +
+ "ST=Testifornia," +
+ "C=Testland";
+
+ try {
+ KeyStore kStore = KeyStore.getInstance(KeyStore.getDefaultType());
+ kStore.load(null, null);
+ PublicKey pk = new TestKeyPair(keyAlg).getPublic();
+ TrustAnchor ta = new TrustAnchor(validCaNameRfc2253, pk, getFullEncoding());
+ Set<TrustAnchor> trustAnchors = new HashSet<TrustAnchor>();
+ trustAnchors.add(ta);
+ X509CertSelector xcs = new X509CertSelector();
+ PKIXBuilderParameters pkixBP = new PKIXBuilderParameters(trustAnchors, xcs);
+ CertPathTrustManagerParameters cptmp = new CertPathTrustManagerParameters(pkixBP);
+ TrustManagerFactory tmf = TrustManagerFactory.getInstance(defaultAlgorithm);
try {
- trustMF[i].init(par1);
- fail("InvalidAlgorithmParameterException must be thrown");
- } catch (InvalidAlgorithmParameterException e) {
+ tmf.init(cptmp);
+ } catch (Exception ex) {
+ fail(ex + " was thrown for init(ManagerFactoryParameters spec)");
}
- }
+ } catch (Exception e) {
+ fail("Unexpected exception for configuration: " + e);
+ }
+
}
+ private static final byte[] getFullEncoding() {
+ // DO NOT MODIFY!
+ return new byte[] {
+ (byte)0x30,(byte)0x81,(byte)0x8c,(byte)0xa0,
+ (byte)0x44,(byte)0x30,(byte)0x16,(byte)0x86,
+ (byte)0x0e,(byte)0x66,(byte)0x69,(byte)0x6c,
+ (byte)0x65,(byte)0x3a,(byte)0x2f,(byte)0x2f,
+ (byte)0x66,(byte)0x6f,(byte)0x6f,(byte)0x2e,
+ (byte)0x63,(byte)0x6f,(byte)0x6d,(byte)0x80,
+ (byte)0x01,(byte)0x00,(byte)0x81,(byte)0x01,
+ (byte)0x01,(byte)0x30,(byte)0x16,(byte)0x86,
+ (byte)0x0e,(byte)0x66,(byte)0x69,(byte)0x6c,
+ (byte)0x65,(byte)0x3a,(byte)0x2f,(byte)0x2f,
+ (byte)0x62,(byte)0x61,(byte)0x72,(byte)0x2e,
+ (byte)0x63,(byte)0x6f,(byte)0x6d,(byte)0x80,
+ (byte)0x01,(byte)0x00,(byte)0x81,(byte)0x01,
+ (byte)0x01,(byte)0x30,(byte)0x12,(byte)0x86,
+ (byte)0x0a,(byte)0x66,(byte)0x69,(byte)0x6c,
+ (byte)0x65,(byte)0x3a,(byte)0x2f,(byte)0x2f,
+ (byte)0x6d,(byte)0x75,(byte)0x75,(byte)0x80,
+ (byte)0x01,(byte)0x00,(byte)0x81,(byte)0x01,
+ (byte)0x01,(byte)0xa1,(byte)0x44,(byte)0x30,
+ (byte)0x16,(byte)0x86,(byte)0x0e,(byte)0x68,
+ (byte)0x74,(byte)0x74,(byte)0x70,(byte)0x3a,
+ (byte)0x2f,(byte)0x2f,(byte)0x66,(byte)0x6f,
+ (byte)0x6f,(byte)0x2e,(byte)0x63,(byte)0x6f,
+ (byte)0x6d,(byte)0x80,(byte)0x01,(byte)0x00,
+ (byte)0x81,(byte)0x01,(byte)0x01,(byte)0x30,
+ (byte)0x16,(byte)0x86,(byte)0x0e,(byte)0x68,
+ (byte)0x74,(byte)0x74,(byte)0x70,(byte)0x3a,
+ (byte)0x2f,(byte)0x2f,(byte)0x62,(byte)0x61,
+ (byte)0x72,(byte)0x2e,(byte)0x63,(byte)0x6f,
+ (byte)0x6d,(byte)0x80,(byte)0x01,(byte)0x00,
+ (byte)0x81,(byte)0x01,(byte)0x01,(byte)0x30,
+ (byte)0x12,(byte)0x86,(byte)0x0a,(byte)0x68,
+ (byte)0x74,(byte)0x74,(byte)0x70,(byte)0x3a,
+ (byte)0x2f,(byte)0x2f,(byte)0x6d,(byte)0x75,
+ (byte)0x75,(byte)0x80,(byte)0x01,(byte)0x00,
+ (byte)0x81,(byte)0x01,(byte)0x01
+ };
+ }
}
/**
@@ -662,6 +711,3 @@
}
}
-class myManagerFactoryParam implements ManagerFactoryParameters {
-
-}
\ No newline at end of file
diff --git a/x-net/src/test/java/tests/api/javax/net/ssl/TrustManagerFactory2Test.java b/x-net/src/test/java/tests/api/javax/net/ssl/TrustManagerFactory2Test.java
index bba0b77..e16a62f 100644
--- a/x-net/src/test/java/tests/api/javax/net/ssl/TrustManagerFactory2Test.java
+++ b/x-net/src/test/java/tests/api/javax/net/ssl/TrustManagerFactory2Test.java
@@ -18,9 +18,9 @@
package tests.api.javax.net.ssl;
import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestInfo;
+import dalvik.annotation.TestTargets;
import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTarget;
+import dalvik.annotation.TestTargetNew;
import java.security.InvalidAlgorithmParameterException;
import java.security.KeyStore;
@@ -120,15 +120,12 @@
* throws NoSuchAlgorithmException when algorithm is not correct;
* returns TrustManagerFactory object
*/
- @TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getInstance",
- methodArgs = {String.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getInstance",
+ args = {java.lang.String.class}
+ )
public void test_getInstanceLjava_lang_String() throws Exception {
try {
TrustManagerFactory.getInstance(null);
@@ -166,15 +163,12 @@
* throws NoSuchProviderException when provider is available;
* returns TrustManagerFactory object
*/
- @TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getInstance",
- methodArgs = {String.class, String.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getInstance",
+ args = {java.lang.String.class, java.lang.String.class}
+ )
public void test_getInstanceLjava_lang_StringLjava_lang_String() throws Exception {
try {
TrustManagerFactory.getInstance(null, mProv.getName());
@@ -241,15 +235,12 @@
* throws IllegalArgumentException when provider is null;
* returns TrustManagerFactory object
*/
- @TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getInstance",
- methodArgs = {String.class, Provider.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getInstance",
+ args = {java.lang.String.class, java.security.Provider.class}
+ )
public void testLjava_lang_StringLjava_security_Provider() throws Exception {
try {
TrustManagerFactory.getInstance(null, mProv);
diff --git a/x-net/src/test/java/tests/api/javax/net/ssl/TrustManagerFactorySpiTest.java b/x-net/src/test/java/tests/api/javax/net/ssl/TrustManagerFactorySpiTest.java
index 360cae7..fcaf8c16 100644
--- a/x-net/src/test/java/tests/api/javax/net/ssl/TrustManagerFactorySpiTest.java
+++ b/x-net/src/test/java/tests/api/javax/net/ssl/TrustManagerFactorySpiTest.java
@@ -5,7 +5,7 @@
* 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
+ * 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,
@@ -13,13 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package tests.api.javax.net.ssl;
import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestInfo;
+import dalvik.annotation.TestTargets;
import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTarget;
+import dalvik.annotation.TestTargetNew;
import java.security.InvalidAlgorithmParameterException;
import java.security.KeyStore;
@@ -30,56 +29,110 @@
import javax.net.ssl.TrustManagerFactorySpi;
import junit.framework.TestCase;
+import org.apache.harmony.xnet.tests.support.TrustManagerFactorySpiImpl;
+import org.apache.harmony.xnet.tests.support.MyTrustManagerFactorySpi.Parameters;
@TestTargetClass(TrustManagerFactorySpi.class)
public class TrustManagerFactorySpiTest extends TestCase {
- private class MockTrustManagerFactorySpi extends TrustManagerFactorySpi {
- public MockTrustManagerFactorySpi() {
- super();
- }
-
- /**
- * @see javax.net.ssl.TrustManagerFactorySpi#engineGetTrustManagers()
- */
- @Override
- protected TrustManager[] engineGetTrustManagers() {
- // it is a fake
- return null;
- }
-
- /**
- * @see javax.net.ssl.TrustManagerFactorySpi#engineInit(java.security.KeyStore)
- */
- @Override
- protected void engineInit(KeyStore ks) throws KeyStoreException {
- // it is a fake
- }
-
- /**
- * @see javax.net.ssl.TrustManagerFactorySpi#engineInit(javax.net.ssl.ManagerFactoryParameters)
- */
- @Override
- protected void engineInit(ManagerFactoryParameters spec) throws InvalidAlgorithmParameterException {
- // it is a fake
+ /**
+ * @tests javax.net.ssl.TrustManagerFactorySpi#TrustManagerFactorySpi()
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "TrustManagerFactorySpi",
+ args = {}
+ )
+ public void test_Constructor() {
+ try {
+ TrustManagerFactorySpiImpl tmf = new TrustManagerFactorySpiImpl();
+ assertTrue(tmf instanceof TrustManagerFactorySpi);
+ } catch (Exception e) {
+ fail("Unexpected exception " + e.toString());
}
}
/**
- * @tests javax.net.ssl.TrustManagerFactorySpi#TrustManagerFactorySpi()
+ * @tests javax.net.ssl.TrustManagerFactorySpi#engineInit(KeyStore ks)
*/
- @TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "TrustManagerFactorySpi",
- methodArgs = {}
- )
- })
- public void test_Constructor() {
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "engineInit",
+ args = {java.security.KeyStore.class}
+ )
+ public void test_engineInit_01() {
+ TrustManagerFactorySpiImpl tmf = new TrustManagerFactorySpiImpl();
try {
- new MockTrustManagerFactorySpi();
+ KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
+ ks.load(null, null);
+ tmf.engineInit(ks);
+ } catch (Exception e) {
+ fail("Unexpected exception " + e.toString());
+ }
+ try {
+ KeyStore ks = null;
+ tmf.engineInit(ks);
+ fail("KeyStoreException wasn't thrown");
+ } catch (KeyStoreException kse) {
+ //expected
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.TrustManagerFactorySpi#engineInit(ManagerFactoryParameters spec)
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "engineInit",
+ args = {javax.net.ssl.ManagerFactoryParameters.class}
+ )
+ public void test_engineInit_02() {
+ TrustManagerFactorySpiImpl tmf = new TrustManagerFactorySpiImpl();
+ try {
+ KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
+ ks.load(null, null);
+ Parameters pr = new Parameters(ks);
+ tmf.engineInit(pr);
+ } catch (Exception e) {
+ fail("Unexpected exception " + e.toString());
+ }
+ try {
+ ManagerFactoryParameters mfp = null;
+ tmf.engineInit(mfp);
+ fail("InvalidAlgorithmParameterException wasn't thrown");
+ } catch (InvalidAlgorithmParameterException kse) {
+ //expected
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.TrustManagerFactorySpi#engineGetTrustManagers()
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "engineGetTrustManagers",
+ args = {}
+ )
+ public void test_engineGetTrustManagers() {
+ TrustManagerFactorySpiImpl tmf = new TrustManagerFactorySpiImpl();
+ try {
+ TrustManager[] tm = tmf.engineGetTrustManagers();
+ fail("IllegalStateException wasn't thrown");
+ } catch (IllegalStateException ise) {
+ //expected
+ } catch (Exception e) {
+ fail(e + " was thrown instead of IllegalStateException");
+ }
+ try {
+ KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
+ ks.load(null, null);
+ tmf.engineInit(ks);
+ TrustManager[] tm = tmf.engineGetTrustManagers();
+ assertNull("Object is not NULL", tm);
} catch (Exception e) {
fail("Unexpected exception " + e.toString());
}
diff --git a/x-net/src/test/java/tests/api/javax/net/ssl/X509ExtendedKeyManagerTest.java b/x-net/src/test/java/tests/api/javax/net/ssl/X509ExtendedKeyManagerTest.java
index 6748d5f..5f711b1 100644
--- a/x-net/src/test/java/tests/api/javax/net/ssl/X509ExtendedKeyManagerTest.java
+++ b/x-net/src/test/java/tests/api/javax/net/ssl/X509ExtendedKeyManagerTest.java
@@ -18,9 +18,9 @@
package tests.api.javax.net.ssl;
import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestInfo;
+import dalvik.annotation.TestTargets;
import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTarget;
+import dalvik.annotation.TestTargetNew;
import java.net.Socket;
import java.security.Principal;
@@ -37,6 +37,7 @@
*/
@TestTargetClass(X509ExtendedKeyManager.class)
public class X509ExtendedKeyManagerTest extends TestCase {
+
private class MockX509ExtendedKeyManager extends X509ExtendedKeyManager {
public MockX509ExtendedKeyManager() {
super();
@@ -94,15 +95,12 @@
/**
* @tests javax.net.ssl.X509ExtendedKeyManager#X509ExtendedKeyManager()
*/
- @TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "X509ExtendedKeyManager",
- methodArgs = {}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "X509ExtendedKeyManager",
+ args = {}
+ )
public final void test_Constructor() {
try {
new MockX509ExtendedKeyManager();
@@ -116,15 +114,12 @@
* #chooseEngineClientAlias(java.lang.String[],
* java.security.Principal[], javax.net.ssl.SSLEngine)
*/
- @TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "Verification with not null parameters missed",
- targets = {
- @TestTarget(
- methodName = "chooseEngineClientAlias",
- methodArgs = {String[].class, Principal[].class, javax.net.ssl.SSLEngine.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "chooseEngineClientAlias",
+ args = {java.lang.String[].class, java.security.Principal[].class, javax.net.ssl.SSLEngine.class}
+ )
public final void test_chooseEngineClientAlias() {
X509ExtendedKeyManager km = new MyX509ExtendedKeyManager();
if (km.chooseEngineClientAlias(null, null, null) != null) {
@@ -137,15 +132,12 @@
* #chooseEngineServerAlias(java.lang.String,
* java.security.Principal[], javax.net.ssl.SSLEngine)
*/
- @TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "Verification with not null parameters missed",
- targets = {
- @TestTarget(
- methodName = "chooseEngineServerAlias",
- methodArgs = {String.class, Principal[].class, javax.net.ssl.SSLEngine.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "chooseEngineServerAlias",
+ args = {java.lang.String.class, java.security.Principal[].class, javax.net.ssl.SSLEngine.class}
+ )
public final void test_chooseEngineServerAlias() {
X509ExtendedKeyManager km = new MyX509ExtendedKeyManager();
if (km.chooseEngineServerAlias(null, null, null) != null) {
diff --git a/x-net/src/test/java/tests/api/javax/net/ssl/X509KeyManagerTest.java b/x-net/src/test/java/tests/api/javax/net/ssl/X509KeyManagerTest.java
new file mode 100644
index 0000000..f9ffd96
--- /dev/null
+++ b/x-net/src/test/java/tests/api/javax/net/ssl/X509KeyManagerTest.java
@@ -0,0 +1,167 @@
+package tests.api.javax.net.ssl;
+
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargets;
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetNew;
+
+import javax.net.ssl.X509KeyManager;
+import java.security.cert.X509Certificate;
+import java.security.Principal;
+import java.security.PrivateKey;
+import java.net.Socket;
+
+import junit.framework.TestCase;
+
+import org.apache.harmony.xnet.tests.support.X509KeyManagerImpl;
+
+/**
+ * Tests for <code>X509KeyManager</code> class constructors and methods.
+ */
+@TestTargetClass(X509KeyManager.class)
+public class X509KeyManagerTest extends TestCase {
+
+ /**
+ * @tests X509KeyManager#getClientAliases(String keyType, Principal[] issuers)
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getClientAliases",
+ args = {java.lang.String.class, java.security.Principal[].class}
+ )
+ public void test_getClientAliases() {
+ try {
+ X509KeyManagerImpl xkm = new X509KeyManagerImpl("CLIENT");
+ assertNull(xkm.getClientAliases(null, null));
+ assertNull(xkm.getClientAliases("", null));
+ String[] resArray = xkm.getClientAliases("CLIENT", null);
+ assertTrue("Incorrect result", compareC(resArray));
+ } catch (Exception e) {
+ fail("Unexpected exception " + e);
+ }
+ }
+
+ /**
+ * @tests X509KeyManager#chooseClientAlias(String[] keyType, Principal[] issuers, Socket socket)
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "chooseClientAlias",
+ args = {java.lang.String[].class, java.security.Principal[].class, java.net.Socket.class}
+ )
+ public void test_chooseClientAlias() {
+ try {
+ String[] ar = {"CLIENT"};
+ X509KeyManagerImpl xkm = new X509KeyManagerImpl("CLIENT");
+ assertNull(xkm.chooseClientAlias(null, null, new Socket()));
+ assertNull(xkm.chooseClientAlias(new String[0], null, new Socket()));
+ String res = xkm.chooseClientAlias(ar, null, new Socket());
+ assertEquals(res, "clientalias_03");
+ res = xkm.chooseClientAlias(ar, null, null);
+ assertEquals(res, "clientalias_02");
+ } catch (Exception e) {
+ fail("Unexpected exception " + e);
+ }
+ }
+
+ /**
+ * @tests X509KeyManager#getServerAliases(String keyType, Principal[] issuers)
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getServerAliases",
+ args = {java.lang.String.class, java.security.Principal[].class}
+ )
+ public void test_getServerAliases() {
+ try {
+ X509KeyManagerImpl xkm = new X509KeyManagerImpl("SERVER");
+ assertNull(xkm.getServerAliases(null, null));
+ assertNull(xkm.getServerAliases("", null));
+ String[] resArray = xkm.getServerAliases("SERVER", null);
+ assertEquals("Incorrect length", resArray.length, 1);
+ assertEquals("Incorrect aliase", resArray[0], "serveralias_00");
+ } catch (Exception e) {
+ fail("Unexpected exception " + e);
+ }
+ }
+
+ /**
+ * @tests X509KeyManager#chooseServerAlias(String keyType, Principal[] issuers, Socket socket)
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "chooseServerAlias",
+ args = {java.lang.String.class, java.security.Principal[].class, java.net.Socket.class}
+ )
+ public void test_chooseServerAlias() {
+ try {
+ X509KeyManagerImpl xkm = new X509KeyManagerImpl("SERVER");
+ assertNull(xkm.chooseServerAlias(null, null, new Socket()));
+ assertNull(xkm.chooseServerAlias("", null, new Socket()));
+ assertNull(xkm.chooseServerAlias("SERVER", null, null));
+ String res = xkm.chooseServerAlias("SERVER", null, new Socket());
+ assertEquals(res, "serveralias_00");
+ } catch (Exception e) {
+ fail("Unexpected exception " + e);
+ }
+ }
+
+ /**
+ * @tests X509KeyManager#getCertificateChain(String alias)
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getCertificateChain",
+ args = {java.lang.String.class}
+ )
+ public void test_getCertificateChain() {
+ try {
+ X509KeyManagerImpl xkm = new X509KeyManagerImpl("SERVER");
+ assertNull("Not NULL for NULL parameter", xkm.getCertificateChain(null));
+ assertNull("Not NULL for empty parameter",xkm.getCertificateChain(""));
+ assertNull("Not NULL for clientAlias_01 parameter", xkm.getCertificateChain("clientAlias_01"));
+ assertNull("Not NULL for serverAlias_00 parameter", xkm.getCertificateChain("serverAlias_00"));
+ } catch (Exception e) {
+ fail("Unexpected exception " + e);
+ }
+ }
+
+ /**
+ * @tests X509KeyManager#getPrivateKey(String alias)
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getPrivateKey",
+ args = {java.lang.String.class}
+ )
+ public void test_getPrivateKey() {
+ try {
+ X509KeyManagerImpl xkm = new X509KeyManagerImpl("CLIENT");
+ assertNull("Not NULL for NULL parameter", xkm.getPrivateKey(null));
+ assertNull("Not NULL for serverAlias_00 parameter", xkm.getPrivateKey("serverAlias_00"));
+ assertNull("Not NULL for clientAlias_02 parameter", xkm.getPrivateKey("clientAlias_02"));
+ } catch (Exception e) {
+ fail("Unexpected exception " + e);
+ }
+ }
+
+
+ private boolean compareC(String[] ar) {
+ if (ar.length != 3) {
+ return false;
+ }
+ for (int i = 0; i < ar.length; i++) {
+ if (ar[i] != "clientalias_01" && ar[i] != "clientalias_02" && ar[i] != "clientalias_03") {
+ return false;
+ }
+ }
+ return true;
+ }
+}
+
diff --git a/x-net/src/test/java/tests/api/javax/net/ssl/X509TrustManagerTest.java b/x-net/src/test/java/tests/api/javax/net/ssl/X509TrustManagerTest.java
new file mode 100644
index 0000000..d5e4001
--- /dev/null
+++ b/x-net/src/test/java/tests/api/javax/net/ssl/X509TrustManagerTest.java
@@ -0,0 +1,258 @@
+package tests.api.javax.net.ssl;
+
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargets;
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetNew;
+
+import java.io.ByteArrayInputStream;
+import java.security.cert.CertificateFactory;
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
+import javax.net.ssl.X509TrustManager;
+
+import junit.framework.TestCase;
+
+import org.apache.harmony.security.tests.support.cert.TestUtils;
+import org.apache.harmony.xnet.tests.support.X509TrustManagerImpl;
+
+/**
+ * Tests for <code>X509TrustManager</code> class constructors and methods.
+ */
+@TestTargetClass(X509TrustManager.class)
+public class X509TrustManagerTest extends TestCase {
+
+ private X509Certificate[] setX509Certificate() {
+ try {
+ CertificateFactory certFact = CertificateFactory.getInstance("X.509");
+ X509Certificate pemCert = (X509Certificate) certFact
+ .generateCertificate(new ByteArrayInputStream(TestUtils
+ .getX509Certificate_v3()));
+ X509Certificate[] xcert = {pemCert};
+ return xcert;
+ } catch (Exception ex) {
+ fail("Unexpected exception " + ex);
+ }
+ return null;
+ }
+
+ private X509Certificate[] setInvalid() {
+ try {
+ CertificateFactory certFact = CertificateFactory.getInstance("X.509");
+ X509Certificate pemCert = (X509Certificate) certFact
+ .generateCertificate(new ByteArrayInputStream(TestUtils
+ .getX509Certificate_v1()));
+ X509Certificate[] xcert = {pemCert};
+ return xcert;
+ } catch (Exception ex) {
+ fail("Unexpected exception " + ex);
+ }
+ return null;
+ }
+
+ /**
+ * @tests javax.net.ssl.X509TrustManager#checkClientTrusted(X509Certificate[] chain, String authType)
+ */
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "checkClientTrusted",
+ args = {java.security.cert.X509Certificate[].class, java.lang.String.class}
+ )
+ public void test_checkClientTrusted_01() {
+ X509TrustManagerImpl xtm = new X509TrustManagerImpl();
+ X509Certificate[] xcert = null;
+
+ try {
+ xtm.checkClientTrusted(xcert, "SSL");
+ fail("IllegalArgumentException wasn't thrown");
+ } catch (IllegalArgumentException iae) {
+ //expected
+ } catch (Exception e) {
+ fail(e + " was thrown instead of IllegalArgumentException");
+ }
+
+ xcert = new X509Certificate[0];
+ try {
+ xtm.checkClientTrusted(xcert, "SSL");
+ fail("IllegalArgumentException wasn't thrown");
+ } catch (IllegalArgumentException iae) {
+ //expected
+ } catch (Exception e) {
+ fail(e + " was thrown instead of IllegalArgumentException");
+ }
+
+ xcert = setX509Certificate();
+ try {
+ xtm.checkClientTrusted(xcert, null);
+ fail("IllegalArgumentException wasn't thrown");
+ } catch (IllegalArgumentException iae) {
+ //expected
+ } catch (Exception e) {
+ fail(e + " was thrown instead of IllegalArgumentException");
+ }
+
+ try {
+ xtm.checkClientTrusted(xcert, "");
+ fail("IllegalArgumentException wasn't thrown");
+ } catch (IllegalArgumentException iae) {
+ //expected
+ } catch (Exception e) {
+ fail(e + " was thrown instead of IllegalArgumentException");
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.X509TrustManager#checkClientTrusted(X509Certificate[] chain, String authType)
+ */
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "checkClientTrusted",
+ args = {java.security.cert.X509Certificate[].class, java.lang.String.class}
+ )
+ public void test_checkClientTrusted_02() {
+ X509TrustManagerImpl xtm = new X509TrustManagerImpl();
+ X509Certificate[] xcert = setInvalid();
+
+ try {
+ xtm.checkClientTrusted(xcert, "SSL");
+ fail("CertificateException wasn't thrown");
+ } catch (CertificateException ce) {
+ //expected
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.X509TrustManager#checkClientTrusted(X509Certificate[] chain, String authType)
+ */
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "checkClientTrusted",
+ args = {java.security.cert.X509Certificate[].class, java.lang.String.class}
+ )
+ public void test_checkClientTrusted_03() {
+ X509TrustManagerImpl xtm = new X509TrustManagerImpl();
+ X509Certificate[] xcert = setX509Certificate();
+
+ try {
+ xtm.checkClientTrusted(xcert, "SSL");
+ } catch (Exception ex) {
+ fail("Unexpected exception " + ex);
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.X509TrustManager#checkServerTrusted(X509Certificate[] chain, String authType)
+ */
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "checkServerTrusted",
+ args = {java.security.cert.X509Certificate[].class, java.lang.String.class}
+ )
+ public void test_checkServerTrusted_01() {
+ X509TrustManagerImpl xtm = new X509TrustManagerImpl();
+ X509Certificate[] xcert = null;
+
+ try {
+ xtm.checkServerTrusted(xcert, "SSL");
+ fail("IllegalArgumentException wasn't thrown");
+ } catch (IllegalArgumentException iae) {
+ //expected
+ } catch (Exception e) {
+ fail(e + " was thrown instead of IllegalArgumentException");
+ }
+
+ xcert = new X509Certificate[0];
+ try {
+ xtm.checkServerTrusted(xcert, "SSL");
+ fail("IllegalArgumentException wasn't thrown");
+ } catch (IllegalArgumentException iae) {
+ //expected
+ } catch (Exception e) {
+ fail(e + " was thrown instead of IllegalArgumentException");
+ }
+
+ xcert = setX509Certificate();
+ try {
+ xtm.checkServerTrusted(xcert, null);
+ fail("IllegalArgumentException wasn't thrown");
+ } catch (IllegalArgumentException iae) {
+ //expected
+ } catch (Exception e) {
+ fail(e + " was thrown instead of IllegalArgumentException");
+ }
+
+ try {
+ xtm.checkServerTrusted(xcert, "");
+ fail("IllegalArgumentException wasn't thrown");
+ } catch (IllegalArgumentException iae) {
+ //expected
+ } catch (Exception e) {
+ fail(e + " was thrown instead of IllegalArgumentException");
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.X509TrustManager#checkServerTrusted(X509Certificate[] chain, String authType)
+ */
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "checkServerTrusted",
+ args = {java.security.cert.X509Certificate[].class, java.lang.String.class}
+ )
+ public void test_checkServerTrusted_02() {
+ X509TrustManagerImpl xtm = new X509TrustManagerImpl();
+ X509Certificate[] xcert = setInvalid();
+
+ try {
+ xtm.checkServerTrusted(xcert, "SSL");
+ fail("CertificateException wasn't thrown");
+ } catch (CertificateException ce) {
+ //expected
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.X509TrustManager#checkServerTrusted(X509Certificate[] chain, String authType)
+ */
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "checkServerTrusted",
+ args = {java.security.cert.X509Certificate[].class, java.lang.String.class}
+ )
+ public void test_checkServerTrusted_03() {
+ X509TrustManagerImpl xtm = new X509TrustManagerImpl();
+ X509Certificate[] xcert = setX509Certificate();
+
+ try {
+ xtm.checkServerTrusted(xcert, "SSL");
+ } catch (Exception ex) {
+ fail("Unexpected exception " + ex);
+ }
+ }
+
+ /**
+ * @tests javax.net.ssl.X509TrustManager#getAcceptedIssuers()
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getAcceptedIssuers",
+ args = {}
+ )
+ public void test_getAcceptedIssuers() {
+ X509TrustManagerImpl xtm = new X509TrustManagerImpl();
+
+ try {
+ assertNotNull(xtm.getAcceptedIssuers());
+ } catch (Exception ex) {
+ fail("Unexpected exception " + ex);
+ }
+ }
+
+}
diff --git a/x-net/src/test/java/tests/xnet/AllTests.java b/x-net/src/test/java/tests/xnet/AllTests.java
index be4999f..53b11dc 100644
--- a/x-net/src/test/java/tests/xnet/AllTests.java
+++ b/x-net/src/test/java/tests/xnet/AllTests.java
@@ -29,7 +29,7 @@
}
public static Test suite() {
- TestSuite suite = new TestSuite(
+ TestSuite suite = tests.TestSuiteFactory.createTestSuite(
"All javax.net and javax.net.ssl test suites");
// $JUnit-BEGIN$
suite.addTest(tests.api.javax.net.AllTests.suite());