|
1 | 1 | package org.lognet.springboot.grpc; |
2 | 2 |
|
3 | | -import com.google.common.util.concurrent.ListenableFuture; |
4 | | -import io.grpc.ManagedChannel; |
5 | | -import io.grpc.ManagedChannelBuilder; |
6 | | -import io.grpc.examples.GreeterGrpc; |
7 | | -import io.grpc.examples.GreeterOuterClass; |
8 | | -import io.netty.handler.codec.http.HttpMethod; |
| 3 | +import static org.junit.Assert.assertEquals; |
| 4 | + |
9 | 5 | import org.junit.After; |
10 | 6 | import org.junit.Before; |
11 | 7 | import org.junit.Test; |
12 | 8 | import org.junit.runner.RunWith; |
13 | 9 | import org.lognet.springboot.grpc.demo.GreeterApp; |
14 | | -import org.springframework.boot.test.IntegrationTest; |
15 | 10 | import org.springframework.boot.test.SpringApplicationConfiguration; |
16 | 11 | import org.springframework.boot.test.TestRestTemplate; |
17 | 12 | import org.springframework.boot.test.WebIntegrationTest; |
18 | | -import org.springframework.http.HttpEntity; |
19 | 13 | import org.springframework.http.HttpStatus; |
20 | 14 | import org.springframework.http.ResponseEntity; |
21 | | -import org.springframework.test.annotation.DirtiesContext; |
22 | 15 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
23 | 16 |
|
24 | 17 | import java.util.concurrent.ExecutionException; |
25 | 18 |
|
26 | | -import static org.junit.Assert.assertEquals; |
| 19 | +import io.grpc.ManagedChannel; |
| 20 | +import io.grpc.ManagedChannelBuilder; |
| 21 | +import io.grpc.examples.GreeterGrpc; |
| 22 | +import io.grpc.examples.GreeterOuterClass; |
27 | 23 |
|
28 | 24 | /** |
29 | 25 | * Created by alexf on 28-Jan-16. |
|
33 | 29 | @WebIntegrationTest |
34 | 30 |
|
35 | 31 | public class GreeterAppTest { |
| 32 | + |
36 | 33 | private ManagedChannel channel; |
| 34 | + |
37 | 35 | @Before |
38 | | - public void setup(){ |
| 36 | + public void setup() { |
39 | 37 | channel = ManagedChannelBuilder.forAddress("localhost", 6565) |
40 | | - .usePlaintext(true) |
41 | | - .build(); |
| 38 | + .usePlaintext(true) |
| 39 | + .build(); |
42 | 40 |
|
43 | 41 | } |
| 42 | + |
44 | 43 | @After |
45 | | - public void tearDown(){ |
| 44 | + public void tearDown() { |
46 | 45 | channel.shutdown(); |
47 | 46 | } |
48 | 47 |
|
49 | 48 | @Test |
50 | | - public void simpleGreeting () throws ExecutionException, InterruptedException { |
| 49 | + public void simpleGreeting() throws ExecutionException, InterruptedException { |
51 | 50 |
|
52 | 51 | final GreeterGrpc.GreeterFutureStub greeterFutureStub = GreeterGrpc.newFutureStub(channel); |
53 | | - final GreeterOuterClass.HelloRequest helloRequest = GreeterOuterClass.HelloRequest.newBuilder().setName("John").build(); |
| 52 | + final GreeterOuterClass.HelloRequest |
| 53 | + helloRequest = |
| 54 | + GreeterOuterClass.HelloRequest.newBuilder().setName("John").build(); |
54 | 55 | final String replay = greeterFutureStub.sayHello(helloRequest).get().getMessage(); |
55 | 56 | System.out.println(replay); |
56 | 57 | } |
57 | 58 |
|
58 | 59 | @Test |
59 | | - public void actuatorTest () throws ExecutionException, InterruptedException { |
| 60 | + public void actuatorTest() throws ExecutionException, InterruptedException { |
60 | 61 | final TestRestTemplate template = new TestRestTemplate(); |
61 | 62 |
|
62 | | - ResponseEntity<String> response = template.getForEntity("http://localhost:8080/env",String.class); |
| 63 | + ResponseEntity<String> response = template.getForEntity("http://localhost:8080/env", String.class); |
63 | 64 | assertEquals(HttpStatus.OK, response.getStatusCode()); |
64 | 65 | } |
65 | 66 |
|
|
0 commit comments