- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/test/java/geniusweb/clienttest/JavaClientTest.java
r3 r1 5 5 6 6 import java.io.IOException; 7 import java.util.HashMap;8 7 import java.util.LinkedList; 9 8 import java.util.List; 10 import java.util.Map;11 9 12 10 import org.junit.AfterClass; … … 15 13 import org.python.util.PythonInterpreter; 16 14 17 import com.fasterxml.jackson.core.type.TypeReference;18 import com.fasterxml.jackson.databind.ObjectMapper;19 15 import com.neovisionaries.ws.client.WebSocket; 20 16 import com.neovisionaries.ws.client.WebSocketAdapter; … … 60 56 @Test 61 57 public void clientSmokeTest() throws IOException { 62 WebSocketFactory factory = new WebSocketFactory().setConnectionTimeout(5000); 63 WebSocket ws = factory.createSocket("ws://localhost:8080/profilesserver/websocket/liststream"); 58 WebSocketFactory factory = new WebSocketFactory() 59 .setConnectionTimeout(5000); 60 WebSocket ws = factory.createSocket( 61 "ws://localhost:8080/profilesserver/websocket/liststream"); 64 62 } 65 63 66 64 @Test 67 public void testGetList() throws IOException, InterruptedException, WebSocketException { 65 public void testGetList() 66 throws IOException, InterruptedException, WebSocketException { 68 67 final List<String> received = new LinkedList<>(); 69 68 Thread.sleep(5000); 70 WebSocketFactory factory = new WebSocketFactory().setConnectionTimeout(20000); 71 WebSocket ws = factory.createSocket("ws://localhost:8080/profilesserver/websocket/liststream"); 69 WebSocketFactory factory = new WebSocketFactory() 70 .setConnectionTimeout(20000); 71 WebSocket ws = factory.createSocket( 72 "ws://localhost:8080/profilesserver/websocket/liststream"); 72 73 73 74 ws.addListener(new WebSocketAdapter() { 74 75 @Override 75 public void onTextMessage(WebSocket websocket, String message) throws Exception { 76 public void onTextMessage(WebSocket websocket, String message) 77 throws Exception { 76 78 System.out.println("received message: " + message); 77 79 received.add(message); … … 82 84 83 85 Thread.sleep(2000); 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")); 86 assertEquals(1, received.size()); 87 assertTrue(received.get(0).matches(JSON)); 88 System.out.println(JSON); 98 89 } 99 90 100 91 @Test 101 public void testExample() throws WebSocketException, InterruptedException, IOException { 92 public void testExample() 93 throws WebSocketException, InterruptedException, IOException { 102 94 DownloadProfileExample test = new DownloadProfileExample(); 103 95 test.run(); … … 106 98 107 99 @Test 108 public void testExample2() throws WebSocketException, InterruptedException, IOException { 100 public void testExample2() 101 throws WebSocketException, InterruptedException, IOException { 109 102 DownloadProfileExample2 test = new DownloadProfileExample2(); 110 103 assertEquals(JOBS1PROFILE, test.getReceived()); … … 119 112 120 113 // Create factory and coerce Jython calculator object 121 JythonObjectFactory factory = new JythonObjectFactory(WebSocketAdapter.class, "PythonDownloadProfile", 114 JythonObjectFactory factory = new JythonObjectFactory( 115 WebSocketAdapter.class, "PythonDownloadProfile", 122 116 "PythonDownloadProfile"); 123 117 factory.createObject();
Note:
See TracChangeset
for help on using the changeset viewer.