16
16
17
17
package org .springframework .integration .graphql .outbound ;
18
18
19
- import graphql .ExecutionResult ;
20
- import graphql .ExecutionResultImpl ;
21
- import org .junit .jupiter .api .BeforeEach ;
19
+ import static org .assertj .core .api .Assertions .assertThat ;
20
+
21
+ import java .time .Duration ;
22
+ import java .util .Collections ;
23
+ import java .util .Map ;
24
+
22
25
import org .junit .jupiter .api .Test ;
26
+
23
27
import org .springframework .beans .factory .annotation .Autowired ;
24
- import org .springframework .context .annotation .AnnotationConfigApplicationContext ;
25
28
import org .springframework .context .annotation .Bean ;
26
29
import org .springframework .context .annotation .Configuration ;
27
30
import org .springframework .core .io .ClassPathResource ;
28
31
import org .springframework .graphql .GraphQlService ;
29
32
import org .springframework .graphql .RequestInput ;
30
33
import org .springframework .graphql .data .method .annotation .QueryMapping ;
31
34
import org .springframework .graphql .data .method .annotation .support .AnnotatedControllerConfigurer ;
32
- import org .springframework .graphql .execution .*;
35
+ import org .springframework .graphql .execution .BatchLoaderRegistry ;
36
+ import org .springframework .graphql .execution .DefaultBatchLoaderRegistry ;
37
+ import org .springframework .graphql .execution .ExecutionGraphQlService ;
38
+ import org .springframework .graphql .execution .GraphQlSource ;
33
39
import org .springframework .integration .channel .FluxMessageChannel ;
34
40
import org .springframework .integration .channel .QueueChannel ;
35
41
import org .springframework .integration .config .EnableIntegration ;
39
45
import org .springframework .messaging .Message ;
40
46
import org .springframework .messaging .MessageHandlingException ;
41
47
import org .springframework .messaging .PollableChannel ;
42
- import org .springframework .messaging .support .GenericMessage ;
48
+ import org .springframework .messaging .support .ErrorMessage ;
43
49
import org .springframework .messaging .support .MessageBuilder ;
44
50
import org .springframework .stereotype .Controller ;
45
51
import org .springframework .test .annotation .DirtiesContext ;
46
- import org .springframework .test .context .TestPropertySource ;
47
52
import org .springframework .test .context .junit .jupiter .SpringJUnitConfig ;
48
- import reactor .core .Disposable ;
53
+
54
+ import graphql .ExecutionResult ;
55
+ import graphql .ExecutionResultImpl ;
49
56
import reactor .core .publisher .Flux ;
50
57
import reactor .core .publisher .Mono ;
51
58
import reactor .test .StepVerifier ;
52
59
53
- import java .time .Duration ;
54
- import java .util .Map ;
55
-
56
- import static java .util .Collections .emptyMap ;
57
- import static org .assertj .core .api .Assertions .assertThat ;
58
- import static org .junit .jupiter .api .Assertions .assertThrows ;
59
-
60
60
/**
61
61
*
62
62
* @author Daniel Frey
@@ -72,33 +72,30 @@ public class GraphqlQueryMessageHandlerTests {
72
72
@ Autowired
73
73
private FluxMessageChannel resultChannel ;
74
74
75
+ @ Autowired
76
+ private PollableChannel errorChannel ;
77
+
75
78
@ Test
76
79
void testHandleMessageForQuery () {
77
80
78
- ExecutionResult expected = new ExecutionResultImpl (
79
- Map .of ( "testQuery" , Map .of ( "id" , "test-data" ) ),
80
- null , null
81
- );
82
81
StepVerifier verifier = StepVerifier .create (
83
- // Flux.from(
84
- this .resultChannel
85
- // )
86
- // .map(Message::getPayload)
87
- // .cast(ExecutionResult.class)
82
+ Flux .from (this .resultChannel )
83
+ .map (Message ::getPayload )
84
+ .cast (ExecutionResult .class )
88
85
)
89
- .consumeNextWith ( result -> {
86
+ .consumeNextWith (result -> {
90
87
assertThat (result ).isInstanceOf (ExecutionResultImpl .class );
91
- // Map<String, Object> data = ((ExecutionResult) result) .getData();
92
- // Map<String, Object> testQuery = (Map<String, Object>) data.get("testQuery");
93
- // assertThat(testQuery.get("id")).isEqualTo("test-data");
88
+ Map <String , Object > data = result .getData ();
89
+ Map <String , Object > testQuery = (Map <String , Object >) data .get ("testQuery" );
90
+ assertThat (testQuery .get ("id" )).isEqualTo ("test-data" );
94
91
}
95
92
)
96
93
.thenCancel ()
97
94
.verifyLater ();
98
95
99
96
this .inputChannel .send (
100
97
MessageBuilder
101
- .withPayload (new RequestInput ("{ testQuery { id } }" , null , emptyMap ()))
98
+ .withPayload (new RequestInput ("{ testQuery { id } }" , null , Collections . emptyMap ()))
102
99
.build ()
103
100
);
104
101
@@ -108,8 +105,20 @@ void testHandleMessageForQuery() {
108
105
@ Test
109
106
void testHandleMessageForQueryWithInvalidPayload () {
110
107
111
- Message <?> testMessage = new GenericMessage <>("{ testQuery { id } }" );
112
- assertThrows ( IllegalArgumentException .class , () -> this .inputChannel .send (testMessage ));
108
+ this .inputChannel .send (
109
+ MessageBuilder
110
+ .withPayload ("{ testQuery { id } }" )
111
+ .build ()
112
+ );
113
+
114
+ Message <?> errorMessage = errorChannel .receive (10_000 );
115
+ assertThat (errorMessage ).isNotNull ()
116
+ .isInstanceOf (ErrorMessage .class )
117
+ .extracting (Message ::getPayload )
118
+ .isInstanceOf (MessageHandlingException .class )
119
+ .satisfies ((ex ) -> assertThat ((Exception ) ex )
120
+ .hasMessageContaining (
121
+ "Message payload needs to be 'org.springframework.graphql.RequestInput'" ));
113
122
114
123
}
115
124
@@ -125,9 +134,6 @@ public Mono<QueryResult> testQuery() {
125
134
126
135
@ Configuration
127
136
@ EnableIntegration
128
- @ TestPropertySource (properties = {
129
- "logging.level.org.springframework.integration=TRACE"
130
- })
131
137
static class TestConfig {
132
138
133
139
@ Bean
0 commit comments