1 | package com.heuristiclab.services.administration; |
---|
2 | |
---|
3 | import java.security.KeyManagementException; |
---|
4 | import java.security.NoSuchAlgorithmException; |
---|
5 | import javax.net.ssl.HttpsURLConnection; |
---|
6 | import javax.net.ssl.SSLContext; |
---|
7 | import javax.net.ssl.X509TrustManager; |
---|
8 | import javax.net.ssl.TrustManager; |
---|
9 | import java.util.Map; |
---|
10 | import org.junit.After; |
---|
11 | import org.junit.AfterClass; |
---|
12 | import org.junit.Before; |
---|
13 | import org.junit.BeforeClass; |
---|
14 | import org.junit.Test; |
---|
15 | import static org.junit.Assert.*; |
---|
16 | |
---|
17 | /** |
---|
18 | * |
---|
19 | * @author MartinH |
---|
20 | */ |
---|
21 | public class AdministrationServiceTest { |
---|
22 | |
---|
23 | static { |
---|
24 | // Create a trust manager that does not validate certificate chains |
---|
25 | TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() { |
---|
26 | |
---|
27 | public java.security.cert.X509Certificate[] getAcceptedIssuers() { |
---|
28 | return new java.security.cert.X509Certificate[]{}; |
---|
29 | } |
---|
30 | |
---|
31 | public void checkClientTrusted( |
---|
32 | java.security.cert.X509Certificate[] certs, String authType) { |
---|
33 | } |
---|
34 | |
---|
35 | public void checkServerTrusted( |
---|
36 | java.security.cert.X509Certificate[] certs, String authType) { |
---|
37 | } |
---|
38 | }}; |
---|
39 | |
---|
40 | SSLContext sc; |
---|
41 | try { |
---|
42 | sc = SSLContext.getInstance("SSL"); |
---|
43 | sc.init(null, trustAllCerts, new java.security.SecureRandom()); |
---|
44 | HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); |
---|
45 | } catch (NoSuchAlgorithmException e) { |
---|
46 | throw new RuntimeException(e); |
---|
47 | } catch (KeyManagementException e) { |
---|
48 | throw new RuntimeException(e); |
---|
49 | } |
---|
50 | |
---|
51 | } |
---|
52 | |
---|
53 | public AdministrationServiceTest() { |
---|
54 | } |
---|
55 | AdministrationService srv = null; |
---|
56 | IAdministrationService port = null; |
---|
57 | |
---|
58 | /** |
---|
59 | * @throws java.lang.Exception |
---|
60 | */ |
---|
61 | @BeforeClass |
---|
62 | public static void setUpBeforeClass() throws Exception { |
---|
63 | } |
---|
64 | |
---|
65 | /** |
---|
66 | * @throws java.lang.Exception |
---|
67 | */ |
---|
68 | @AfterClass |
---|
69 | public static void tearDownAfterClass() throws Exception { |
---|
70 | } |
---|
71 | |
---|
72 | /** |
---|
73 | * @throws java.lang.Exception |
---|
74 | */ |
---|
75 | @Before |
---|
76 | public void setUp() throws Exception { |
---|
77 | this.srv = new AdministrationService(); |
---|
78 | this.port = srv.getAdministrationService(); // .getWSHttpBindingIAdministrationService1(); |
---|
79 | |
---|
80 | /*Map<String, Object> requestContext = ((BindingProvider) port).getRequestContext(); |
---|
81 | requestContext.put(BindingProvider.USERNAME_PROPERTY, "okbtester"); |
---|
82 | requestContext.put(BindingProvider.PASSWORD_PROPERTY, "okbtester");*/ |
---|
83 | } |
---|
84 | |
---|
85 | /** |
---|
86 | * @throws java.lang.Exception |
---|
87 | */ |
---|
88 | @After |
---|
89 | public void tearDown() throws Exception { |
---|
90 | } |
---|
91 | |
---|
92 | // TODO: fix -->Problem deleting existing Algorithm |
---|
93 | @Test |
---|
94 | public void AddAlgorithmTest() throws Exception { |
---|
95 | |
---|
96 | ObjectFactory fac = new ObjectFactory(); |
---|
97 | Long retval = 0L; |
---|
98 | |
---|
99 | // delete existing Algo and Class first |
---|
100 | if (port.getAlgorithmClass(1000L) != null) { |
---|
101 | port.deleteAlgorithmClass(1000L); |
---|
102 | } |
---|
103 | if (port.getAlgorithm(1000L) != null) { |
---|
104 | port.deleteAlgorithm(1000L); |
---|
105 | } |
---|
106 | |
---|
107 | // add AlgorithmClassId first |
---|
108 | AddAlgorithmClassTest(); |
---|
109 | Algorithm a = fac.createAlgorithm(); |
---|
110 | |
---|
111 | a.setAlgorithmClassId(1000L); |
---|
112 | a.setDescription(fac.createNamedOKBItemDescription("a new Algo")); |
---|
113 | a.setId(1000L); |
---|
114 | a.setName(fac.createNamedOKBItemName("Algorithm Name 6")); |
---|
115 | a.setPlatformId(1L); |
---|
116 | try { |
---|
117 | retval = port.addAlgorithm(a); |
---|
118 | } catch (Exception e) { |
---|
119 | e.printStackTrace(); |
---|
120 | // throw new OKBWebServiceFailedException(e.getMessage()); |
---|
121 | } |
---|
122 | assertTrue("Algortihm wasn't added", retval > 0); |
---|
123 | } |
---|
124 | |
---|
125 | @Test |
---|
126 | public void AddAlgorithmClassTest() throws Exception { |
---|
127 | |
---|
128 | ObjectFactory fac = new ObjectFactory(); |
---|
129 | Long retval = 0L; |
---|
130 | |
---|
131 | // delete existing Algo first (if exists) |
---|
132 | if (port.getAlgorithmClass(1000L) != null) { |
---|
133 | port.deleteAlgorithmClass(1000L); |
---|
134 | } |
---|
135 | |
---|
136 | AlgorithmClass a = fac.createAlgorithmClass(); |
---|
137 | a.setId(1000L); |
---|
138 | a.setName(fac.createNamedOKBItemName("a new AlgoClass")); |
---|
139 | |
---|
140 | try { |
---|
141 | retval = port.addAlgorithmClass(a); |
---|
142 | } catch (Exception e) { |
---|
143 | e.printStackTrace(); |
---|
144 | // throw new OKBWebServiceFailedException(e.getMessage()); |
---|
145 | } |
---|
146 | assertTrue("AlgortihmClass wasn't added", retval > 0); |
---|
147 | } |
---|
148 | |
---|
149 | @Test |
---|
150 | public void GetAlgorithmsTest() { |
---|
151 | |
---|
152 | ArrayOfAlgorithm algos = port.getAlgorithms(); |
---|
153 | |
---|
154 | for (Algorithm algo : algos.getAlgorithm()) { |
---|
155 | System.out.println("algo ClassId:=" + algo.getAlgorithmClassId()); |
---|
156 | System.out.println("algo Id:=" + algo.getId()); |
---|
157 | System.out.println("algo PlattformId:=" + algo.getPlatformId()); |
---|
158 | System.out.println("algo Class:=" + algo.getClass()); |
---|
159 | System.out.println("algo Description:=" |
---|
160 | + algo.getDescription().getValue()); |
---|
161 | System.out.println("algo Name:=" + algo.getName().getValue()); |
---|
162 | } |
---|
163 | assertTrue("No Algorithms found!", algos.getAlgorithm().size() > 0); |
---|
164 | } |
---|
165 | } |
---|