Skip to content

Commit 83950b5

Browse files
committed
Use @AutoConfigureInProcessTransport
1 parent ccc55d2 commit 83950b5

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright 2025-current the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.grpc.sample;
17+
18+
import static org.assertj.core.api.Assertions.assertThat;
19+
20+
import org.junit.jupiter.api.Test;
21+
import org.springframework.beans.factory.annotation.Autowired;
22+
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
23+
import org.springframework.boot.grpc.test.autoconfigure.AutoConfigureInProcessTransport;
24+
import org.springframework.boot.test.context.TestConfiguration;
25+
import org.springframework.context.annotation.Import;
26+
import org.springframework.grpc.sample.GrpcServerSideTests.TestConfig;
27+
import org.springframework.grpc.sample.proto.HelloReply;
28+
import org.springframework.grpc.sample.proto.HelloRequest;
29+
import org.springframework.grpc.sample.proto.SimpleGrpc.SimpleBlockingStub;
30+
import org.springframework.test.context.TestPropertySource;
31+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
32+
33+
@TestPropertySource(properties = { "spring.grpc.client.default-channel.address=localhost:9090" })
34+
@SpringJUnitConfig(TestConfig.class)
35+
@AutoConfigureInProcessTransport
36+
public class GrpcServerSideTests {
37+
38+
@Autowired
39+
private SimpleBlockingStub stub;
40+
41+
@Test
42+
void contextLoads() {
43+
HelloRequest request = HelloRequest.newBuilder().setName("Test").build();
44+
HelloReply reply = this.stub.sayHello(request);
45+
assertThat(reply.getMessage()).contains(("Test"));
46+
}
47+
48+
@TestConfiguration
49+
@Import({ GrpcServerService.class })
50+
@EnableAutoConfiguration
51+
static class TestConfig {
52+
53+
}
54+
55+
}

0 commit comments

Comments
 (0)