233628406b9239c5ddb31e60307976d03935a042
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / core / SslTrustManagerFactoryTest.java
1 /*
2  * Copyright (c) 2014 Brocade Communications Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.openflowjava.protocol.impl.core;
10
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertTrue;
13
14 import java.security.cert.X509Certificate;
15
16 import javax.net.ssl.TrustManager;
17 import javax.net.ssl.X509TrustManager;
18
19 import org.junit.Before;
20 import org.junit.Test;
21 import org.mockito.MockitoAnnotations;
22
23 /**
24  *
25  * @author jameshall
26  */
27 public class SslTrustManagerFactoryTest {
28
29     /**
30      * Sets up test environment
31      */
32     @Before
33     public void setUp() {
34         MockitoAnnotations.initMocks(this);
35     }
36
37     /**
38      * 
39      */
40     @Test
41     public void testGetTrustManagers() throws Exception {
42         TrustManager[] tmArray  = SslTrustManagerFactory.getTrustManagers() ;
43
44         assertNotNull( tmArray );
45         for ( TrustManager tm : tmArray ) {
46             if ( tm.getClass() == X509TrustManager.class ) {
47                 X509Certificate[] certsArray = ((X509TrustManager)tm).getAcceptedIssuers() ;
48                 assertTrue( certsArray.length > 0 ) ;
49
50                 //                Boolean caught = false;
51                 //                try {
52                 //                    ((X509TrustManager)tm).checkClientTrusted( certsArray, TrustManagerFactory.getDefaultAlgorithm()) ;
53                 //                } catch (CertificateException ce) {
54                 //                    caught = true ;
55                 //                }
56                 //                assertTrue( caught ) ;
57                 //
58                 //                caught = false;
59                 //                try {
60                 //                    ((X509TrustManager)tm).checkServerTrusted( certsArray, TrustManagerFactory.getDefaultAlgorithm()) ;
61                 //                } catch (CertificateException ce) {
62                 //                    caught = true ;
63                 //                }
64                 //                assertTrue( caught ) ;
65                 //            }
66             }
67         }
68     }
69 }
70