Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OKBJavaConnector/AdministrationService/src/administrationservice/Main.java @ 6085

Last change on this file since 6085 was 6085, checked in by mholper, 13 years ago

added AddPlatformstest #1441

File size: 4.3 KB
Line 
1/*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5
6package administrationservice;
7
8import com.heuristiclab.services.administration.AdministrationService;
9import com.heuristiclab.services.administration.Algorithm;
10import com.heuristiclab.services.administration.ArrayOfAlgorithm;
11import com.heuristiclab.services.administration.ArrayOfPlatform;
12import com.heuristiclab.services.administration.IAdministrationService;
13import com.heuristiclab.services.administration.ObjectFactory;
14import com.heuristiclab.services.administration.Platform;
15import java.net.MalformedURLException;
16import java.net.URL;
17import java.security.KeyManagementException;
18import java.security.NoSuchAlgorithmException;
19import java.util.logging.Level;
20import java.util.logging.Logger;
21import javax.net.ssl.HttpsURLConnection;
22import javax.net.ssl.SSLContext;
23import javax.net.ssl.TrustManager;
24import javax.net.ssl.X509TrustManager;
25import javax.xml.bind.JAXBElement;
26
27/**
28 *
29 * @author MartinH
30 */
31public class Main {
32
33
34      static {
35    // Create a trust manager that does not validate certificate chains
36    TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
37      public java.security.cert.X509Certificate[] getAcceptedIssuers() {
38        return new java.security.cert.X509Certificate[] {};
39      }
40
41      public void checkClientTrusted(
42          java.security.cert.X509Certificate[] certs, String authType) {
43      }
44
45      public void checkServerTrusted(
46          java.security.cert.X509Certificate[] certs, String authType) {
47      }
48    } };
49
50    SSLContext sc;
51    try {
52      sc = SSLContext.getInstance("SSL");
53      sc.init(null, trustAllCerts, new java.security.SecureRandom());
54      HttpsURLConnection
55          .setDefaultSSLSocketFactory(sc.getSocketFactory());
56    } catch (NoSuchAlgorithmException e) {
57      throw new RuntimeException(e);
58    } catch (KeyManagementException e) {
59      throw new RuntimeException(e);
60    }
61
62  }
63
64  public void GetAlgorithmsTest(IAdministrationService port) {
65
66    ArrayOfAlgorithm algos = port.getAlgorithms();
67
68
69    for (Algorithm algo : algos.getAlgorithm()) {
70      System.out.println("algo ClassId:=" + algo.getAlgorithmClassId());
71      System.out.println("algo Id:=" + algo.getId());
72      System.out.println("algo PlattformId:=" + algo.getPlatformId());
73      System.out.println("algo Class:=" + algo.getClass());
74      System.out.println("algo Description:="
75          + algo.getDescription().getValue());
76      System.out.println("algo Name:=" + algo.getName().getValue());
77    }
78    //assertTrue("No Algorithms found!", algos.getAlgorithm().size() > 0);
79  }
80
81  public void GetPlatformsTest(IAdministrationService port) {
82
83    ArrayOfPlatform algos = port.getPlatforms();
84
85
86    for (Platform platform : algos.getPlatform()) {
87      System.out.println("platform Id:=" + platform.getId());
88      System.out.println("platform Class:=" + platform.getClass());
89      System.out.println("platform Description:="
90          + platform.getDescription().getValue());
91      System.out.println("platform Name:=" + platform.getName().getValue());
92    }
93    //assertTrue("No Platforms found!", algos.getPlatform().size() > 0);
94  }
95
96  public void AddPlatformsTest(IAdministrationService port) {
97                Long retval = 0L;
98                ObjectFactory fac = new ObjectFactory();
99                Platform p = fac.createPlatform();
100                p.setName(fac.createNamedOKBItemName("ECJ"));
101                p.setDescription(fac.createNamedOKBItemDescription("A Java-based Evolutionary Computation Research System"));
102
103
104                try {
105                    retval = port.addPlatform(p);
106                } catch (Exception e) {
107                    e.printStackTrace();
108                }
109
110                System.out.println("adding of Platform "+(retval>0?"sucessful":"failed"));
111  }
112
113
114    /**
115     * @param args the command line arguments
116     */
117    public static void main(String[] args) {
118        try {
119            Main test = new Main();
120            AdministrationService srv = new AdministrationService(new URL("https://services.heuristiclab.com/OKB.SPR.Java-3.3/AdministrationService.svc?wsdl"));
121            IAdministrationService port = srv.getAdministrationService();
122            test.GetAlgorithmsTest(port);
123            test.AddPlatformsTest(port);
124            test.GetPlatformsTest(port);
125        } catch (MalformedURLException ex) {
126            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
127        }
128    }
129
130}
Note: See TracBrowser for help on using the repository browser.