|
|
|
|
@ -21,8 +21,7 @@ class HubConnectionTest {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void checkHubConnectionState() throws Exception {
|
|
|
|
|
Transport mockTransport = new MockTransport();
|
|
|
|
|
HubConnection hubConnection = new HubConnection("http://example.com", mockTransport, new NullLogger(), true, new TestHttpClient());
|
|
|
|
|
HubConnection hubConnection = TestUtils.createHubConnection("http://example.com");
|
|
|
|
|
hubConnection.start();
|
|
|
|
|
assertEquals(HubConnectionState.CONNECTED, hubConnection.getConnectionState());
|
|
|
|
|
|
|
|
|
|
@ -48,7 +47,7 @@ class HubConnectionTest {
|
|
|
|
|
@Test
|
|
|
|
|
public void hubConnectionClosesAfterCloseMessage() throws Exception {
|
|
|
|
|
MockTransport mockTransport = new MockTransport();
|
|
|
|
|
HubConnection hubConnection = new HubConnection("http://example.com", mockTransport, new NullLogger(), true, new TestHttpClient());
|
|
|
|
|
HubConnection hubConnection = TestUtils.createHubConnection("http://example.com", mockTransport);
|
|
|
|
|
|
|
|
|
|
hubConnection.start();
|
|
|
|
|
mockTransport.receiveMessage("{}" + RECORD_SEPARATOR);
|
|
|
|
|
@ -63,7 +62,7 @@ class HubConnectionTest {
|
|
|
|
|
@Test
|
|
|
|
|
public void hubConnectionReceiveHandshakeResponseWithError() throws Exception {
|
|
|
|
|
MockTransport mockTransport = new MockTransport();
|
|
|
|
|
HubConnection hubConnection = new HubConnection("http://example.com", mockTransport, new NullLogger(), true, new TestHttpClient());
|
|
|
|
|
HubConnection hubConnection = TestUtils.createHubConnection("http://example.com", mockTransport);
|
|
|
|
|
|
|
|
|
|
hubConnection.start();
|
|
|
|
|
Throwable exception = assertThrows(HubException.class, () -> mockTransport.receiveMessage("{\"error\":\"Requested protocol 'messagepack' is not available.\"}" + RECORD_SEPARATOR));
|
|
|
|
|
@ -74,7 +73,7 @@ class HubConnectionTest {
|
|
|
|
|
public void registeringMultipleHandlersAndBothGetTriggered() throws Exception {
|
|
|
|
|
AtomicReference<Double> value = new AtomicReference<>(0.0);
|
|
|
|
|
MockTransport mockTransport = new MockTransport();
|
|
|
|
|
HubConnection hubConnection = new HubConnection("http://example.com", mockTransport, new NullLogger(), true, new TestHttpClient());
|
|
|
|
|
HubConnection hubConnection = TestUtils.createHubConnection("http://example.com", mockTransport);
|
|
|
|
|
Action action = () -> value.getAndUpdate((val) -> val + 1);
|
|
|
|
|
|
|
|
|
|
hubConnection.on("inc", action);
|
|
|
|
|
@ -100,7 +99,7 @@ class HubConnectionTest {
|
|
|
|
|
public void removeHandlerByName() throws Exception {
|
|
|
|
|
AtomicReference<Double> value = new AtomicReference<>(0.0);
|
|
|
|
|
MockTransport mockTransport = new MockTransport();
|
|
|
|
|
HubConnection hubConnection = new HubConnection("http://example.com", mockTransport, new NullLogger(), true, new TestHttpClient());
|
|
|
|
|
HubConnection hubConnection = TestUtils.createHubConnection("http://example.com", mockTransport);
|
|
|
|
|
Action action = () -> value.getAndUpdate((val) -> val + 1);
|
|
|
|
|
|
|
|
|
|
hubConnection.on("inc", action);
|
|
|
|
|
@ -127,7 +126,7 @@ class HubConnectionTest {
|
|
|
|
|
public void addAndRemoveHandlerImmediately() throws Exception {
|
|
|
|
|
AtomicReference<Double> value = new AtomicReference<>(0.0);
|
|
|
|
|
MockTransport mockTransport = new MockTransport();
|
|
|
|
|
HubConnection hubConnection = new HubConnection("http://example.com", mockTransport, new NullLogger(), true, new TestHttpClient());
|
|
|
|
|
HubConnection hubConnection = TestUtils.createHubConnection("http://example.com", mockTransport);
|
|
|
|
|
Action action = () -> value.getAndUpdate((val) -> val + 1);
|
|
|
|
|
|
|
|
|
|
hubConnection.on("inc", action);
|
|
|
|
|
@ -152,7 +151,7 @@ class HubConnectionTest {
|
|
|
|
|
public void removingMultipleHandlersWithOneCallToRemove() throws Exception {
|
|
|
|
|
AtomicReference<Double> value = new AtomicReference<>(0.0);
|
|
|
|
|
MockTransport mockTransport = new MockTransport();
|
|
|
|
|
HubConnection hubConnection = new HubConnection("http://example.com", mockTransport, new NullLogger(), true, new TestHttpClient());
|
|
|
|
|
HubConnection hubConnection = TestUtils.createHubConnection("http://example.com", mockTransport);
|
|
|
|
|
Action action = () -> value.getAndUpdate((val) -> val + 1);
|
|
|
|
|
Action secondAction = () -> value.getAndUpdate((val) -> val + 2);
|
|
|
|
|
|
|
|
|
|
@ -184,7 +183,7 @@ class HubConnectionTest {
|
|
|
|
|
public void removeHandlerWithUnsubscribe() throws Exception {
|
|
|
|
|
AtomicReference<Double> value = new AtomicReference<>(0.0);
|
|
|
|
|
MockTransport mockTransport = new MockTransport();
|
|
|
|
|
HubConnection hubConnection = new HubConnection("http://example.com", mockTransport, new NullLogger(), true, new TestHttpClient());
|
|
|
|
|
HubConnection hubConnection = TestUtils.createHubConnection("http://example.com", mockTransport);
|
|
|
|
|
Action action = () -> value.getAndUpdate((val) -> val + 1);
|
|
|
|
|
|
|
|
|
|
Subscription subscription = hubConnection.on("inc", action);
|
|
|
|
|
@ -217,7 +216,7 @@ class HubConnectionTest {
|
|
|
|
|
public void unsubscribeTwice() throws Exception {
|
|
|
|
|
AtomicReference<Double> value = new AtomicReference<>(0.0);
|
|
|
|
|
MockTransport mockTransport = new MockTransport();
|
|
|
|
|
HubConnection hubConnection = new HubConnection("http://example.com", mockTransport, new NullLogger(),true, new TestHttpClient());
|
|
|
|
|
HubConnection hubConnection = TestUtils.createHubConnection("http://example.com", mockTransport);
|
|
|
|
|
Action action = () -> value.getAndUpdate((val) -> val + 1);
|
|
|
|
|
|
|
|
|
|
Subscription subscription = hubConnection.on("inc", action);
|
|
|
|
|
@ -251,7 +250,7 @@ class HubConnectionTest {
|
|
|
|
|
public void removeSingleHandlerWithUnsubscribe() throws Exception {
|
|
|
|
|
AtomicReference<Double> value = new AtomicReference<>(0.0);
|
|
|
|
|
MockTransport mockTransport = new MockTransport();
|
|
|
|
|
HubConnection hubConnection = new HubConnection("http://example.com", mockTransport, new NullLogger(), true, new TestHttpClient());
|
|
|
|
|
HubConnection hubConnection = TestUtils.createHubConnection("http://example.com", mockTransport);
|
|
|
|
|
Action action = () -> value.getAndUpdate((val) -> val + 1);
|
|
|
|
|
Action secondAction = () -> value.getAndUpdate((val) -> val + 2);
|
|
|
|
|
|
|
|
|
|
@ -281,7 +280,7 @@ class HubConnectionTest {
|
|
|
|
|
public void addAndRemoveHandlerImmediatelyWithSubscribe() throws Exception {
|
|
|
|
|
AtomicReference<Double> value = new AtomicReference<>(0.0);
|
|
|
|
|
MockTransport mockTransport = new MockTransport();
|
|
|
|
|
HubConnection hubConnection = new HubConnection("http://example.com", mockTransport, new NullLogger(), true, new TestHttpClient());
|
|
|
|
|
HubConnection hubConnection = TestUtils.createHubConnection("http://example.com", mockTransport);
|
|
|
|
|
Action action = () -> value.getAndUpdate((val) -> val + 1);
|
|
|
|
|
|
|
|
|
|
Subscription sub = hubConnection.on("inc", action);
|
|
|
|
|
@ -306,7 +305,7 @@ class HubConnectionTest {
|
|
|
|
|
public void registeringMultipleHandlersThatTakeParamsAndBothGetTriggered() throws Exception {
|
|
|
|
|
AtomicReference<Double> value = new AtomicReference<>(0.0);
|
|
|
|
|
MockTransport mockTransport = new MockTransport();
|
|
|
|
|
HubConnection hubConnection = new HubConnection("http://example.com", mockTransport, new NullLogger(), true, new TestHttpClient());
|
|
|
|
|
HubConnection hubConnection = TestUtils.createHubConnection("http://example.com", mockTransport);
|
|
|
|
|
|
|
|
|
|
Action1<Double> action = (number) -> value.getAndUpdate((val) -> val + number);
|
|
|
|
|
|
|
|
|
|
@ -325,7 +324,7 @@ class HubConnectionTest {
|
|
|
|
|
@Test
|
|
|
|
|
public void invokeWaitsForCompletionMessage() throws Exception {
|
|
|
|
|
MockTransport mockTransport = new MockTransport();
|
|
|
|
|
HubConnection hubConnection = new HubConnection("http://example.com", mockTransport, new NullLogger(), true, new TestHttpClient());
|
|
|
|
|
HubConnection hubConnection = TestUtils.createHubConnection("http://example.com", mockTransport);
|
|
|
|
|
|
|
|
|
|
hubConnection.start();
|
|
|
|
|
mockTransport.receiveMessage("{}" + RECORD_SEPARATOR);
|
|
|
|
|
@ -342,7 +341,7 @@ class HubConnectionTest {
|
|
|
|
|
@Test
|
|
|
|
|
public void multipleInvokesWaitForOwnCompletionMessage() throws Exception {
|
|
|
|
|
MockTransport mockTransport = new MockTransport();
|
|
|
|
|
HubConnection hubConnection = new HubConnection("http://example.com", mockTransport, new NullLogger(), true, new TestHttpClient());
|
|
|
|
|
HubConnection hubConnection = TestUtils.createHubConnection("http://example.com", mockTransport);
|
|
|
|
|
|
|
|
|
|
hubConnection.start();
|
|
|
|
|
mockTransport.receiveMessage("{}" + RECORD_SEPARATOR);
|
|
|
|
|
@ -365,7 +364,7 @@ class HubConnectionTest {
|
|
|
|
|
@Test
|
|
|
|
|
public void invokeWorksForPrimitiveTypes() throws Exception {
|
|
|
|
|
MockTransport mockTransport = new MockTransport();
|
|
|
|
|
HubConnection hubConnection = new HubConnection("http://example.com", mockTransport, new NullLogger(), true, new TestHttpClient());
|
|
|
|
|
HubConnection hubConnection = TestUtils.createHubConnection("http://example.com", mockTransport);
|
|
|
|
|
|
|
|
|
|
hubConnection.start();
|
|
|
|
|
mockTransport.receiveMessage("{}" + RECORD_SEPARATOR);
|
|
|
|
|
@ -383,7 +382,7 @@ class HubConnectionTest {
|
|
|
|
|
@Test
|
|
|
|
|
public void completionMessageCanHaveError() throws Exception {
|
|
|
|
|
MockTransport mockTransport = new MockTransport();
|
|
|
|
|
HubConnection hubConnection = new HubConnection("http://example.com", mockTransport, new NullLogger(), true, new TestHttpClient());
|
|
|
|
|
HubConnection hubConnection = TestUtils.createHubConnection("http://example.com", mockTransport);
|
|
|
|
|
|
|
|
|
|
hubConnection.start();
|
|
|
|
|
mockTransport.receiveMessage("{}" + RECORD_SEPARATOR);
|
|
|
|
|
@ -407,7 +406,7 @@ class HubConnectionTest {
|
|
|
|
|
@Test
|
|
|
|
|
public void stopCancelsActiveInvokes() throws Exception {
|
|
|
|
|
MockTransport mockTransport = new MockTransport();
|
|
|
|
|
HubConnection hubConnection = new HubConnection("http://example.com", mockTransport, new NullLogger(), true, new TestHttpClient());
|
|
|
|
|
HubConnection hubConnection = TestUtils.createHubConnection("http://example.com", mockTransport);
|
|
|
|
|
|
|
|
|
|
hubConnection.start();
|
|
|
|
|
mockTransport.receiveMessage("{}" + RECORD_SEPARATOR);
|
|
|
|
|
@ -432,7 +431,7 @@ class HubConnectionTest {
|
|
|
|
|
public void sendWithNoParamsTriggersOnHandler() throws Exception {
|
|
|
|
|
AtomicReference<Integer> value = new AtomicReference<>(0);
|
|
|
|
|
MockTransport mockTransport = new MockTransport();
|
|
|
|
|
HubConnection hubConnection = new HubConnection("http://example.com", mockTransport, new NullLogger(), true, new TestHttpClient());
|
|
|
|
|
HubConnection hubConnection = TestUtils.createHubConnection("http://example.com", mockTransport);
|
|
|
|
|
|
|
|
|
|
hubConnection.on("inc", () ->{
|
|
|
|
|
assertEquals(Integer.valueOf(0), value.get());
|
|
|
|
|
@ -451,7 +450,7 @@ class HubConnectionTest {
|
|
|
|
|
public void sendWithParamTriggersOnHandler() throws Exception {
|
|
|
|
|
AtomicReference<String> value = new AtomicReference<>();
|
|
|
|
|
MockTransport mockTransport = new MockTransport();
|
|
|
|
|
HubConnection hubConnection = new HubConnection("http://example.com", mockTransport, new NullLogger(), true, new TestHttpClient());
|
|
|
|
|
HubConnection hubConnection = TestUtils.createHubConnection("http://example.com", mockTransport);
|
|
|
|
|
|
|
|
|
|
hubConnection.on("inc", (param) ->{
|
|
|
|
|
assertNull(value.get());
|
|
|
|
|
@ -473,7 +472,7 @@ class HubConnectionTest {
|
|
|
|
|
AtomicReference<Double> value2 = new AtomicReference<>();
|
|
|
|
|
|
|
|
|
|
MockTransport mockTransport = new MockTransport();
|
|
|
|
|
HubConnection hubConnection = new HubConnection("http://example.com", mockTransport, new NullLogger(), true, new TestHttpClient());
|
|
|
|
|
HubConnection hubConnection = TestUtils.createHubConnection("http://example.com", mockTransport);
|
|
|
|
|
|
|
|
|
|
hubConnection.on("inc", (param1, param2) ->{
|
|
|
|
|
assertNull(value1.get());
|
|
|
|
|
@ -500,7 +499,7 @@ class HubConnectionTest {
|
|
|
|
|
AtomicReference<String> value3 = new AtomicReference<>();
|
|
|
|
|
|
|
|
|
|
MockTransport mockTransport = new MockTransport();
|
|
|
|
|
HubConnection hubConnection = new HubConnection("http://example.com", mockTransport, new NullLogger(), true, new TestHttpClient());
|
|
|
|
|
HubConnection hubConnection = TestUtils.createHubConnection("http://example.com", mockTransport);
|
|
|
|
|
|
|
|
|
|
hubConnection.on("inc", (param1, param2, param3) ->{
|
|
|
|
|
assertNull(value1.get());
|
|
|
|
|
@ -531,7 +530,7 @@ class HubConnectionTest {
|
|
|
|
|
AtomicReference<String> value4 = new AtomicReference<>();
|
|
|
|
|
|
|
|
|
|
MockTransport mockTransport = new MockTransport();
|
|
|
|
|
HubConnection hubConnection = new HubConnection("http://example.com", mockTransport, new NullLogger(), true, new TestHttpClient());
|
|
|
|
|
HubConnection hubConnection = TestUtils.createHubConnection("http://example.com", mockTransport);
|
|
|
|
|
|
|
|
|
|
hubConnection.on("inc", (param1, param2, param3, param4) ->{
|
|
|
|
|
assertNull(value1.get());
|
|
|
|
|
@ -565,7 +564,7 @@ class HubConnectionTest {
|
|
|
|
|
AtomicReference<Double> value5 = new AtomicReference<>();
|
|
|
|
|
|
|
|
|
|
MockTransport mockTransport = new MockTransport();
|
|
|
|
|
HubConnection hubConnection = new HubConnection("http://example.com", mockTransport, new NullLogger(), true, new TestHttpClient());
|
|
|
|
|
HubConnection hubConnection = TestUtils.createHubConnection("http://example.com", mockTransport);
|
|
|
|
|
|
|
|
|
|
hubConnection.on("inc", (param1, param2, param3, param4, param5) ->{
|
|
|
|
|
assertNull(value1.get());
|
|
|
|
|
@ -603,7 +602,7 @@ class HubConnectionTest {
|
|
|
|
|
AtomicReference<String> value6 = new AtomicReference<>();
|
|
|
|
|
|
|
|
|
|
MockTransport mockTransport = new MockTransport();
|
|
|
|
|
HubConnection hubConnection = new HubConnection("http://example.com", mockTransport, new NullLogger(), true, new TestHttpClient());
|
|
|
|
|
HubConnection hubConnection = TestUtils.createHubConnection("http://example.com", mockTransport);
|
|
|
|
|
|
|
|
|
|
hubConnection.on("inc", (param1, param2, param3, param4, param5, param6) -> {
|
|
|
|
|
assertNull(value1.get());
|
|
|
|
|
@ -645,7 +644,7 @@ class HubConnectionTest {
|
|
|
|
|
AtomicReference<String> value7 = new AtomicReference<>();
|
|
|
|
|
|
|
|
|
|
MockTransport mockTransport = new MockTransport();
|
|
|
|
|
HubConnection hubConnection = new HubConnection("http://example.com", mockTransport, new NullLogger(), true, new TestHttpClient());
|
|
|
|
|
HubConnection hubConnection = TestUtils.createHubConnection("http://example.com", mockTransport);
|
|
|
|
|
|
|
|
|
|
hubConnection.on("inc", (param1, param2, param3, param4, param5, param6, param7) -> {
|
|
|
|
|
assertNull(value1.get());
|
|
|
|
|
@ -691,7 +690,7 @@ class HubConnectionTest {
|
|
|
|
|
AtomicReference<String> value8 = new AtomicReference<>();
|
|
|
|
|
|
|
|
|
|
MockTransport mockTransport = new MockTransport();
|
|
|
|
|
HubConnection hubConnection = new HubConnection("http://example.com", mockTransport, new NullLogger(), true, new TestHttpClient());
|
|
|
|
|
HubConnection hubConnection = TestUtils.createHubConnection("http://example.com", mockTransport);
|
|
|
|
|
|
|
|
|
|
hubConnection.on("inc", (param1, param2, param3, param4, param5, param6, param7, param8) -> {
|
|
|
|
|
assertNull(value1.get());
|
|
|
|
|
@ -738,7 +737,7 @@ class HubConnectionTest {
|
|
|
|
|
AtomicReference<Custom> value1 = new AtomicReference<>();
|
|
|
|
|
|
|
|
|
|
MockTransport mockTransport = new MockTransport();
|
|
|
|
|
HubConnection hubConnection = new HubConnection("http://example.com", mockTransport, new NullLogger(), true, new TestHttpClient());
|
|
|
|
|
HubConnection hubConnection = TestUtils.createHubConnection("http://example.com", mockTransport);
|
|
|
|
|
|
|
|
|
|
hubConnection.on("inc", (param1) -> {
|
|
|
|
|
assertNull(value1.get());
|
|
|
|
|
@ -763,7 +762,7 @@ class HubConnectionTest {
|
|
|
|
|
public void receiveHandshakeResponseAndMessage() throws Exception {
|
|
|
|
|
AtomicReference<Double> value = new AtomicReference<Double>(0.0);
|
|
|
|
|
MockTransport mockTransport = new MockTransport();
|
|
|
|
|
HubConnection hubConnection = new HubConnection("http://example.com", mockTransport, new NullLogger(), true, new TestHttpClient());
|
|
|
|
|
HubConnection hubConnection = TestUtils.createHubConnection("http://example.com", mockTransport);
|
|
|
|
|
|
|
|
|
|
hubConnection.on("inc", () ->{
|
|
|
|
|
assertEquals(Double.valueOf(0), value.get());
|
|
|
|
|
@ -784,8 +783,7 @@ class HubConnectionTest {
|
|
|
|
|
@Test
|
|
|
|
|
public void onClosedCallbackRunsWhenStopIsCalled() throws Exception {
|
|
|
|
|
AtomicReference<String> value1 = new AtomicReference<>();
|
|
|
|
|
Transport mockTransport = new MockTransport();
|
|
|
|
|
HubConnection hubConnection = new HubConnection("http://example.com", mockTransport, new NullLogger(), true, new TestHttpClient());
|
|
|
|
|
HubConnection hubConnection = TestUtils.createHubConnection("http://example.com");
|
|
|
|
|
hubConnection.start();
|
|
|
|
|
hubConnection.onClosed((ex) -> {
|
|
|
|
|
assertNull(value1.get());
|
|
|
|
|
@ -801,8 +799,7 @@ class HubConnectionTest {
|
|
|
|
|
public void multipleOnClosedCallbacksRunWhenStopIsCalled() throws Exception {
|
|
|
|
|
AtomicReference<String> value1 = new AtomicReference<>();
|
|
|
|
|
AtomicReference<String> value2 = new AtomicReference<>();
|
|
|
|
|
Transport mockTransport = new MockTransport();
|
|
|
|
|
HubConnection hubConnection = new HubConnection("http://example.com", mockTransport, new NullLogger(), true, new TestHttpClient());
|
|
|
|
|
HubConnection hubConnection = TestUtils.createHubConnection("http://example.com");
|
|
|
|
|
hubConnection.start();
|
|
|
|
|
|
|
|
|
|
hubConnection.onClosed((ex) -> {
|
|
|
|
|
@ -827,7 +824,7 @@ class HubConnectionTest {
|
|
|
|
|
@Test
|
|
|
|
|
public void hubConnectionClosesAndRunsOnClosedCallbackAfterCloseMessageWithError() throws Exception {
|
|
|
|
|
MockTransport mockTransport = new MockTransport();
|
|
|
|
|
HubConnection hubConnection = new HubConnection("http://example.com", mockTransport, new NullLogger(), true, new TestHttpClient());
|
|
|
|
|
HubConnection hubConnection = TestUtils.createHubConnection("http://example.com", mockTransport);
|
|
|
|
|
hubConnection.onClosed((ex) -> {
|
|
|
|
|
assertEquals(ex.getMessage(), "There was an error");
|
|
|
|
|
});
|
|
|
|
|
@ -843,8 +840,7 @@ class HubConnectionTest {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void callingStartOnStartedHubConnectionNoOps() throws Exception {
|
|
|
|
|
Transport mockTransport = new MockTransport();
|
|
|
|
|
HubConnection hubConnection = new HubConnection("http://example.com", mockTransport, new NullLogger(), true, new TestHttpClient());
|
|
|
|
|
HubConnection hubConnection = TestUtils.createHubConnection("http://example.com");
|
|
|
|
|
hubConnection.start();
|
|
|
|
|
assertEquals(HubConnectionState.CONNECTED, hubConnection.getConnectionState());
|
|
|
|
|
|
|
|
|
|
@ -857,8 +853,7 @@ class HubConnectionTest {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void cannotSendBeforeStart() throws Exception {
|
|
|
|
|
Transport mockTransport = new MockTransport();
|
|
|
|
|
HubConnection hubConnection = new HubConnection("http://example.com", mockTransport, new NullLogger(), true, new TestHttpClient());
|
|
|
|
|
HubConnection hubConnection = TestUtils.createHubConnection("http://example.com");
|
|
|
|
|
assertEquals(HubConnectionState.DISCONNECTED, hubConnection.getConnectionState());
|
|
|
|
|
|
|
|
|
|
Throwable exception = assertThrows(HubException.class, () -> hubConnection.send("inc"));
|
|
|
|
|
@ -868,7 +863,7 @@ class HubConnectionTest {
|
|
|
|
|
@Test
|
|
|
|
|
public void errorWhenReceivingInvokeWithIncorrectArgumentLength() throws Exception {
|
|
|
|
|
MockTransport mockTransport = new MockTransport();
|
|
|
|
|
HubConnection hubConnection = new HubConnection("http://example.com", mockTransport, new NullLogger(), true, new TestHttpClient());
|
|
|
|
|
HubConnection hubConnection = TestUtils.createHubConnection("http://example.com", mockTransport);
|
|
|
|
|
hubConnection.on("Send", (s) -> {
|
|
|
|
|
assertTrue(false);
|
|
|
|
|
}, String.class);
|
|
|
|
|
@ -886,9 +881,10 @@ class HubConnectionTest {
|
|
|
|
|
TestHttpClient client = new TestHttpClient()
|
|
|
|
|
.on("POST", (req) -> CompletableFuture.completedFuture(new HttpResponse(404, "", "")));
|
|
|
|
|
|
|
|
|
|
HttpConnectionOptions options = new HttpConnectionOptions();
|
|
|
|
|
options.setHttpClient(client);
|
|
|
|
|
HubConnection hubConnection = new HubConnectionBuilder()
|
|
|
|
|
.withUrl("http://example.com")
|
|
|
|
|
.configureHttpClient(client)
|
|
|
|
|
.withUrl("http://example.com", options)
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
@ -905,8 +901,11 @@ class HubConnectionTest {
|
|
|
|
|
TestHttpClient client = new TestHttpClient().on("POST", "http://example.com/negotiate",
|
|
|
|
|
(req) -> CompletableFuture.completedFuture(new HttpResponse(200, "", "{\"url\":\"http://example.com\"}")));
|
|
|
|
|
|
|
|
|
|
HubConnection hubConnection = new HubConnectionBuilder().withUrl("http://example.com")
|
|
|
|
|
.configureHttpClient(client).build();
|
|
|
|
|
HttpConnectionOptions options = new HttpConnectionOptions();
|
|
|
|
|
options.setHttpClient(client);
|
|
|
|
|
HubConnection hubConnection = new HubConnectionBuilder()
|
|
|
|
|
.withUrl("http://example.com", options)
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
ExecutionException exception = assertThrows(ExecutionException.class, () -> hubConnection.start().get(1000, TimeUnit.MILLISECONDS));
|
|
|
|
|
assertEquals("Negotiate redirection limit exceeded.", exception.getCause().getMessage());
|
|
|
|
|
@ -922,8 +921,10 @@ class HubConnectionTest {
|
|
|
|
|
MockTransport transport = new MockTransport();
|
|
|
|
|
HttpConnectionOptions options = new HttpConnectionOptions();
|
|
|
|
|
options.setTransport(transport);
|
|
|
|
|
HubConnection hubConnection = new HubConnectionBuilder().withUrl("http://example.com", options)
|
|
|
|
|
.configureHttpClient(client).build();
|
|
|
|
|
options.setHttpClient(client);
|
|
|
|
|
HubConnection hubConnection = new HubConnectionBuilder()
|
|
|
|
|
.withUrl("http://example.com", options)
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
hubConnection.start().get(1000, TimeUnit.MILLISECONDS);
|
|
|
|
|
|
|
|
|
|
@ -940,8 +941,10 @@ class HubConnectionTest {
|
|
|
|
|
MockTransport transport = new MockTransport();
|
|
|
|
|
HttpConnectionOptions options = new HttpConnectionOptions();
|
|
|
|
|
options.setTransport(transport);
|
|
|
|
|
HubConnection hubConnection = new HubConnectionBuilder().withUrl("http://example.com", options)
|
|
|
|
|
.configureHttpClient(client).build();
|
|
|
|
|
options.setHttpClient(client);
|
|
|
|
|
HubConnection hubConnection = new HubConnectionBuilder()
|
|
|
|
|
.withUrl("http://example.com", options)
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
ExecutionException exception = assertThrows(ExecutionException.class, () -> hubConnection.start().get(1000, TimeUnit.MILLISECONDS));
|
|
|
|
|
assertEquals("Test error.", exception.getCause().getMessage());
|
|
|
|
|
@ -958,18 +961,75 @@ class HubConnectionTest {
|
|
|
|
|
MockTransport transport = new MockTransport();
|
|
|
|
|
HttpConnectionOptions options = new HttpConnectionOptions();
|
|
|
|
|
options.setTransport(transport);
|
|
|
|
|
HubConnection hubConnection = new HubConnectionBuilder().withUrl("http://example.com", options)
|
|
|
|
|
.configureHttpClient(client).build();
|
|
|
|
|
options.setHttpClient(client);
|
|
|
|
|
HubConnection hubConnection = new HubConnectionBuilder()
|
|
|
|
|
.withUrl("http://example.com", options)
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
hubConnection.start().get(1000, TimeUnit.MILLISECONDS);
|
|
|
|
|
assertEquals(HubConnectionState.CONNECTED, hubConnection.getConnectionState());
|
|
|
|
|
hubConnection.stop();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void accessTokenProviderIsUsedForNegotiate()
|
|
|
|
|
throws InterruptedException, ExecutionException, TimeoutException, Exception {
|
|
|
|
|
AtomicReference<String> token = new AtomicReference<>();
|
|
|
|
|
TestHttpClient client = new TestHttpClient()
|
|
|
|
|
.on("POST", "http://example.com/negotiate",
|
|
|
|
|
(req) -> {
|
|
|
|
|
token.set(req.getHeaders().get("Authorization"));
|
|
|
|
|
return CompletableFuture
|
|
|
|
|
.completedFuture(new HttpResponse(200, "", "{\"connectionId\":\"bVOiRPG8-6YiJ6d7ZcTOVQ\",\""
|
|
|
|
|
+ "availableTransports\":[{\"transport\":\"WebSockets\",\"transferFormats\":[\"Text\",\"Binary\"]}]}"));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
MockTransport transport = new MockTransport();
|
|
|
|
|
HttpConnectionOptions options = new HttpConnectionOptions();
|
|
|
|
|
options.setTransport(transport);
|
|
|
|
|
options.setHttpClient(client);
|
|
|
|
|
options.setAccessTokenProvider(() -> CompletableFuture.completedFuture("secretToken"));
|
|
|
|
|
HubConnection hubConnection = new HubConnectionBuilder().withUrl("http://example.com", options).build();
|
|
|
|
|
|
|
|
|
|
hubConnection.start().get(1000, TimeUnit.MILLISECONDS);
|
|
|
|
|
assertEquals(HubConnectionState.CONNECTED, hubConnection.getConnectionState());
|
|
|
|
|
hubConnection.stop();
|
|
|
|
|
assertEquals("Bearer secretToken", token.get());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void accessTokenProviderIsOverriddenFromRedirectNegotiate()
|
|
|
|
|
throws InterruptedException, ExecutionException, TimeoutException, Exception {
|
|
|
|
|
AtomicReference<String> token = new AtomicReference<>();
|
|
|
|
|
TestHttpClient client = new TestHttpClient()
|
|
|
|
|
.on("POST", "http://example.com/negotiate", (req) -> CompletableFuture.completedFuture(new HttpResponse(200, "", "{\"url\":\"http://testexample.com/\",\"accessToken\":\"newToken\"}")))
|
|
|
|
|
.on("POST", "http://testexample.com/negotiate", (req) -> {
|
|
|
|
|
token.set(req.getHeaders().get("Authorization"));
|
|
|
|
|
return CompletableFuture
|
|
|
|
|
.completedFuture(new HttpResponse(200, "", "{\"connectionId\":\"bVOiRPG8-6YiJ6d7ZcTOVQ\",\""
|
|
|
|
|
+ "availableTransports\":[{\"transport\":\"WebSockets\",\"transferFormats\":[\"Text\",\"Binary\"]}]}"));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
MockTransport transport = new MockTransport();
|
|
|
|
|
HttpConnectionOptions options = new HttpConnectionOptions();
|
|
|
|
|
options.setTransport(transport);
|
|
|
|
|
options.setHttpClient(client);
|
|
|
|
|
options.setAccessTokenProvider(() -> CompletableFuture.completedFuture("secretToken"));
|
|
|
|
|
HubConnection hubConnection = new HubConnectionBuilder().withUrl("http://example.com", options).build();
|
|
|
|
|
|
|
|
|
|
hubConnection.start().get(1000, TimeUnit.MILLISECONDS);
|
|
|
|
|
assertEquals(HubConnectionState.CONNECTED, hubConnection.getConnectionState());
|
|
|
|
|
hubConnection.stop();
|
|
|
|
|
assertEquals("Bearer newToken", token.get());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void hubConnectionCanBeStartedAfterBeingStopped() throws Exception {
|
|
|
|
|
MockTransport mockTransport = new MockTransport();
|
|
|
|
|
HubConnection hubConnection = new HubConnection("http://example.com", mockTransport, new NullLogger(), true, new TestHttpClient());
|
|
|
|
|
MockTransport transport = new MockTransport();
|
|
|
|
|
HttpConnectionOptions options = new HttpConnectionOptions();
|
|
|
|
|
options.setTransport(transport);
|
|
|
|
|
options.setSkipNegotiate(true);
|
|
|
|
|
HubConnection hubConnection = new HubConnectionBuilder().withUrl("http://example.com", options).build();
|
|
|
|
|
|
|
|
|
|
hubConnection.start().get(1000, TimeUnit.MILLISECONDS);
|
|
|
|
|
assertEquals(HubConnectionState.CONNECTED, hubConnection.getConnectionState());
|
|
|
|
|
@ -990,7 +1050,10 @@ class HubConnectionTest {
|
|
|
|
|
.on("POST", "http://testexample.com/negotiate", (req) -> CompletableFuture
|
|
|
|
|
.completedFuture(new HttpResponse(200, "", "{\"connectionId\":\"bVOiRPG8-6YiJ6d7ZcTOVQ\",\""
|
|
|
|
|
+ "availableTransports\":[{\"transport\":\"WebSockets\",\"transferFormats\":[\"Text\",\"Binary\"]}]}")));
|
|
|
|
|
HubConnection hubConnection = new HubConnection("http://example.com", mockTransport, new NullLogger(), false, client);
|
|
|
|
|
HttpConnectionOptions options = new HttpConnectionOptions();
|
|
|
|
|
options.setTransport(mockTransport);
|
|
|
|
|
options.setHttpClient(client);
|
|
|
|
|
HubConnection hubConnection = new HubConnectionBuilder().withUrl("http://example.com", options).build();
|
|
|
|
|
|
|
|
|
|
hubConnection.start().get(1000, TimeUnit.MILLISECONDS);
|
|
|
|
|
assertEquals(HubConnectionState.CONNECTED, hubConnection.getConnectionState());
|
|
|
|
|
|