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