Changeset 3 for src


Ignore:
Timestamp:
08/29/19 17:09:33 (5 years ago)
Author:
bart
Message:

Small fixes

Location:
src
Files:
10 added
2 edited

Legend:

Unmodified
Added
Removed
  • src/test/java/geniusweb/clienttest/JavaClientTest.java

    r1 r3  
    55
    66import java.io.IOException;
     7import java.util.HashMap;
    78import java.util.LinkedList;
    89import java.util.List;
     10import java.util.Map;
    911
    1012import org.junit.AfterClass;
     
    1315import org.python.util.PythonInterpreter;
    1416
     17import com.fasterxml.jackson.core.type.TypeReference;
     18import com.fasterxml.jackson.databind.ObjectMapper;
    1519import com.neovisionaries.ws.client.WebSocket;
    1620import com.neovisionaries.ws.client.WebSocketAdapter;
     
    5660        @Test
    5761        public void clientSmokeTest() throws IOException {
    58                 WebSocketFactory factory = new WebSocketFactory()
    59                                 .setConnectionTimeout(5000);
    60                 WebSocket ws = factory.createSocket(
    61                                 "ws://localhost:8080/profilesserver/websocket/liststream");
     62                WebSocketFactory factory = new WebSocketFactory().setConnectionTimeout(5000);
     63                WebSocket ws = factory.createSocket("ws://localhost:8080/profilesserver/websocket/liststream");
    6264        }
    6365
    6466        @Test
    65         public void testGetList()
    66                         throws IOException, InterruptedException, WebSocketException {
     67        public void testGetList() throws IOException, InterruptedException, WebSocketException {
    6768                final List<String> received = new LinkedList<>();
    6869                Thread.sleep(5000);
    69                 WebSocketFactory factory = new WebSocketFactory()
    70                                 .setConnectionTimeout(20000);
    71                 WebSocket ws = factory.createSocket(
    72                                 "ws://localhost:8080/profilesserver/websocket/liststream");
     70                WebSocketFactory factory = new WebSocketFactory().setConnectionTimeout(20000);
     71                WebSocket ws = factory.createSocket("ws://localhost:8080/profilesserver/websocket/liststream");
    7372
    7473                ws.addListener(new WebSocketAdapter() {
    7574                        @Override
    76                         public void onTextMessage(WebSocket websocket, String message)
    77                                         throws Exception {
     75                        public void onTextMessage(WebSocket websocket, String message) throws Exception {
    7876                                System.out.println("received message: " + message);
    7977                                received.add(message);
     
    8482
    8583                Thread.sleep(2000);
    86                 assertEquals(1, received.size());
    87                 assertTrue(received.get(0).matches(JSON));
    88                 System.out.println(JSON);
     84
     85                assertEquals(1, received.size()); // 1 answer received
     86
     87                ObjectMapper mapper = new ObjectMapper();
     88                TypeReference<HashMap<String, Object>> typeRef = new TypeReference<HashMap<String, Object>>() {
     89                };
     90                Map<String, Object> map = mapper.readValue(received.get(0), typeRef);
     91
     92                List<String> domains= new LinkedList<>();
     93                for (String key: map.keySet()) {
     94                        domains.add(key.substring(key.indexOf("get")));
     95                        }
     96                assertTrue(domains.contains("get/jobs"));
     97                assertTrue(domains.contains("get/7issues"));
    8998        }
    9099
    91100        @Test
    92         public void testExample()
    93                         throws WebSocketException, InterruptedException, IOException {
     101        public void testExample() throws WebSocketException, InterruptedException, IOException {
    94102                DownloadProfileExample test = new DownloadProfileExample();
    95103                test.run();
     
    98106
    99107        @Test
    100         public void testExample2()
    101                         throws WebSocketException, InterruptedException, IOException {
     108        public void testExample2() throws WebSocketException, InterruptedException, IOException {
    102109                DownloadProfileExample2 test = new DownloadProfileExample2();
    103110                assertEquals(JOBS1PROFILE, test.getReceived());
     
    112119
    113120                // Create factory and coerce Jython calculator object
    114                 JythonObjectFactory factory = new JythonObjectFactory(
    115                                 WebSocketAdapter.class, "PythonDownloadProfile",
     121                JythonObjectFactory factory = new JythonObjectFactory(WebSocketAdapter.class, "PythonDownloadProfile",
    116122                                "PythonDownloadProfile");
    117123                factory.createObject();
  • src/test/java/geniusweb/profilesserver/AutoUpdatingProfilesFactoryTest.java

    r2 r3  
    119119        @Test
    120120        public void getDomainsTest() {
    121                 assertEquals(2, factory.getDomains().size());
    122                 assertEquals(JOBS, factory.getDomains().get(0));
    123                 assertEquals("7issues", factory.getDomains().get(1));
     121                assertTrue(factory.getDomains().size() > 2);
     122                assertTrue(factory.getDomains().contains(JOBS));
     123                assertTrue(factory.getDomains().contains(JOBS));
     124                assertTrue(factory.getDomains().contains("7issues"));
    124125
    125126        }
Note: See TracChangeset for help on using the changeset viewer.