Skip to content

Commit e9680ce

Browse files
committed
Enhanced polymorph tests with one more usecase
1 parent de21447 commit e9680ce

File tree

12 files changed

+128
-0
lines changed

12 files changed

+128
-0
lines changed

services-gateway/src/test/java/io/scalecube/services/gateway/http/HttpGatewayTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import io.scalecube.services.gateway.SomeException;
2424
import io.scalecube.services.gateway.client.http.HttpGatewayClientTransport;
2525
import io.scalecube.services.gateway.sut.typed.Circle;
26+
import io.scalecube.services.gateway.sut.typed.Rectangle;
27+
import io.scalecube.services.gateway.sut.typed.Square;
2628
import io.scalecube.services.gateway.sut.typed.StartOfDayEvent;
2729
import io.scalecube.services.routing.StaticAddressRouter;
2830
import io.scalecube.services.transport.rsocket.RSocketServiceTransport;
@@ -231,6 +233,20 @@ public void shouldReturnPolymorph() {
231233
.verify();
232234
}
233235

236+
@Test
237+
public void shouldReturnListPolymorph() {
238+
StepVerifier.create(typedGreetingService.helloListPolymorph())
239+
.assertNext(
240+
shapes -> {
241+
assertEquals(1.0, ((Circle) shapes.get(0)).radius());
242+
assertEquals(1.0, ((Rectangle) shapes.get(1)).height());
243+
assertEquals(1.0, ((Rectangle) shapes.get(1)).width());
244+
assertEquals(1.0, ((Square) shapes.get(2)).side());
245+
})
246+
.thenCancel()
247+
.verify();
248+
}
249+
234250
@Test
235251
public void shouldReturnMultitype() {
236252
StepVerifier.create(typedGreetingService.helloMultitype())

services-gateway/src/test/java/io/scalecube/services/gateway/http/HttpLocalGatewayTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import io.scalecube.services.gateway.SomeException;
2323
import io.scalecube.services.gateway.client.http.HttpGatewayClientTransport;
2424
import io.scalecube.services.gateway.sut.typed.Circle;
25+
import io.scalecube.services.gateway.sut.typed.Rectangle;
26+
import io.scalecube.services.gateway.sut.typed.Square;
2527
import io.scalecube.services.gateway.sut.typed.StartOfDayEvent;
2628
import io.scalecube.services.routing.StaticAddressRouter;
2729
import java.time.Duration;
@@ -205,6 +207,20 @@ public void shouldReturnPolymorph() {
205207
.verify();
206208
}
207209

210+
@Test
211+
public void shouldReturnListPolymorph() {
212+
StepVerifier.create(typedGreetingService.helloListPolymorph())
213+
.assertNext(
214+
shapes -> {
215+
assertEquals(1.0, ((Circle) shapes.get(0)).radius());
216+
assertEquals(1.0, ((Rectangle) shapes.get(1)).height());
217+
assertEquals(1.0, ((Rectangle) shapes.get(1)).width());
218+
assertEquals(1.0, ((Square) shapes.get(2)).side());
219+
})
220+
.thenCancel()
221+
.verify();
222+
}
223+
208224
@Test
209225
public void shouldReturnMultitype() {
210226
StepVerifier.create(typedGreetingService.helloMultitype())

services-gateway/src/test/java/io/scalecube/services/gateway/http/TypedGreetingService.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import io.scalecube.services.annotations.Service;
44
import io.scalecube.services.annotations.ServiceMethod;
55
import io.scalecube.services.gateway.sut.typed.Shape;
6+
import java.util.List;
67
import reactor.core.publisher.Mono;
78

89
@Service(TypedGreetingService.SERVICE_NAME)
@@ -13,6 +14,9 @@ public interface TypedGreetingService {
1314
@ServiceMethod
1415
Mono<Shape> helloPolymorph();
1516

17+
@ServiceMethod
18+
Mono<List<Shape>> helloListPolymorph();
19+
1620
@ServiceMethod
1721
Mono<Object> helloMultitype();
1822

services-gateway/src/test/java/io/scalecube/services/gateway/http/TypedGreetingServiceImpl.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package io.scalecube.services.gateway.http;
22

33
import io.scalecube.services.gateway.sut.typed.Circle;
4+
import io.scalecube.services.gateway.sut.typed.Rectangle;
45
import io.scalecube.services.gateway.sut.typed.Shape;
6+
import io.scalecube.services.gateway.sut.typed.Square;
57
import io.scalecube.services.gateway.sut.typed.StartOfDayEvent;
68
import java.time.Clock;
79
import java.time.LocalDateTime;
10+
import java.util.List;
811
import reactor.core.publisher.Mono;
912

1013
public class TypedGreetingServiceImpl implements TypedGreetingService {
@@ -14,6 +17,11 @@ public Mono<Shape> helloPolymorph() {
1417
return Mono.just(new Circle(1.0));
1518
}
1619

20+
@Override
21+
public Mono<List<Shape>> helloListPolymorph() {
22+
return Mono.just(List.of(new Circle(1.0), new Rectangle(1.0, 1.0), new Square(1.0)));
23+
}
24+
1725
@Override
1826
public Mono<Object> helloMultitype() {
1927
return Mono.just(new StartOfDayEvent(1, 1, 1, LocalDateTime.now(Clock.systemUTC())));

services-gateway/src/test/java/io/scalecube/services/gateway/websocket/TypedGreetingService.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
import io.scalecube.services.annotations.Service;
44
import io.scalecube.services.annotations.ServiceMethod;
55
import io.scalecube.services.gateway.sut.typed.Shape;
6+
import java.util.List;
67
import reactor.core.publisher.Flux;
8+
import reactor.core.publisher.Mono;
79

810
@Service(TypedGreetingService.SERVICE_NAME)
911
public interface TypedGreetingService {
@@ -13,6 +15,9 @@ public interface TypedGreetingService {
1315
@ServiceMethod
1416
Flux<Shape> helloPolymorph();
1517

18+
@ServiceMethod
19+
Mono<List<Shape>> helloListPolymorph();
20+
1621
@ServiceMethod
1722
Flux<Object> helloMultitype();
1823

services-gateway/src/test/java/io/scalecube/services/gateway/websocket/TypedGreetingServiceImpl.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
import java.math.BigDecimal;
1111
import java.time.Clock;
1212
import java.time.LocalDateTime;
13+
import java.util.List;
1314
import reactor.core.publisher.Flux;
15+
import reactor.core.publisher.Mono;
1416

1517
public class TypedGreetingServiceImpl implements TypedGreetingService {
1618

@@ -19,6 +21,11 @@ public Flux<Shape> helloPolymorph() {
1921
return Flux.just(new Circle(1.0), new Rectangle(1.0, 1.0), new Square(1.0));
2022
}
2123

24+
@Override
25+
public Mono<List<Shape>> helloListPolymorph() {
26+
return Mono.just(List.of(new Circle(1.0), new Rectangle(1.0, 1.0), new Square(1.0)));
27+
}
28+
2229
@Override
2330
public Flux<Object> helloMultitype() {
2431
return Flux.just(

services-gateway/src/test/java/io/scalecube/services/gateway/websocket/WebsocketGatewayTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,20 @@ public void shouldReturnPolymorph() {
275275
.verify();
276276
}
277277

278+
@Test
279+
public void shouldReturnListPolymorph() {
280+
StepVerifier.create(typedGreetingService.helloListPolymorph())
281+
.assertNext(
282+
shapes -> {
283+
assertEquals(1.0, ((Circle) shapes.get(0)).radius());
284+
assertEquals(1.0, ((Rectangle) shapes.get(1)).height());
285+
assertEquals(1.0, ((Rectangle) shapes.get(1)).width());
286+
assertEquals(1.0, ((Square) shapes.get(2)).side());
287+
})
288+
.thenCancel()
289+
.verify();
290+
}
291+
278292
@Test
279293
public void shouldReturnMultitype() {
280294
StepVerifier.create(typedGreetingService.helloMultitype())

services-gateway/src/test/java/io/scalecube/services/gateway/websocket/WebsocketLocalGatewayTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,20 @@ public void shouldReturnPolymorph() {
247247
.verify();
248248
}
249249

250+
@Test
251+
public void shouldReturnListPolymorph() {
252+
StepVerifier.create(typedGreetingService.helloListPolymorph())
253+
.assertNext(
254+
shapes -> {
255+
assertEquals(1.0, ((Circle) shapes.get(0)).radius());
256+
assertEquals(1.0, ((Rectangle) shapes.get(1)).height());
257+
assertEquals(1.0, ((Rectangle) shapes.get(1)).width());
258+
assertEquals(1.0, ((Square) shapes.get(2)).side());
259+
})
260+
.thenCancel()
261+
.verify();
262+
}
263+
250264
@Test
251265
public void shouldReturnMultitype() {
252266
StepVerifier.create(typedGreetingService.helloMultitype())

services/src/test/java/io/scalecube/services/ServiceLocalTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,22 @@ public void test_polymorph() {
438438
.verify();
439439
}
440440

441+
@Test
442+
public void test_list_polymorph() {
443+
final var greetingService = api(TypedGreetingService.class);
444+
445+
StepVerifier.create(greetingService.helloListPolymorph())
446+
.assertNext(
447+
shapes -> {
448+
assertEquals(1.0, ((Circle) shapes.get(0)).radius());
449+
assertEquals(1.0, ((Rectangle) shapes.get(1)).height());
450+
assertEquals(1.0, ((Rectangle) shapes.get(1)).width());
451+
assertEquals(1.0, ((Square) shapes.get(2)).side());
452+
})
453+
.thenCancel()
454+
.verify();
455+
}
456+
441457
@Test
442458
public void test_multitype() {
443459
final var greetingService = api(TypedGreetingService.class);

services/src/test/java/io/scalecube/services/ServiceRemoteTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,22 @@ public void test_polymorph() {
610610
.verify();
611611
}
612612

613+
@Test
614+
public void test_list_polymorph() {
615+
final var greetingService = api(TypedGreetingService.class);
616+
617+
StepVerifier.create(greetingService.helloListPolymorph())
618+
.assertNext(
619+
shapes -> {
620+
assertEquals(1.0, ((Circle) shapes.get(0)).radius());
621+
assertEquals(1.0, ((Rectangle) shapes.get(1)).height());
622+
assertEquals(1.0, ((Rectangle) shapes.get(1)).width());
623+
assertEquals(1.0, ((Square) shapes.get(2)).side());
624+
})
625+
.thenCancel()
626+
.verify();
627+
}
628+
613629
@Test
614630
public void test_multitype() {
615631
final var greetingService = api(TypedGreetingService.class);

0 commit comments

Comments
 (0)