Updated directory structure

This commit is contained in:
2020-07-07 23:00:19 +02:00
parent ce00bd39ee
commit ef60abc4f9
26 changed files with 44 additions and 61 deletions

View File

@ -0,0 +1,62 @@
package de.twomartens.oparlservice;
import de.twomartens.oparlservice.entity.Greeting;
import de.twomartens.oparlservice.interceptors.RequestTypeInterceptor;
import de.twomartens.oparlservice.interceptors.TraceIdInterceptor;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import org.springframework.web.client.RestTemplate;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
@SpringJUnitConfig
@SpringBootTest(webEnvironment = RANDOM_PORT)
class OParlServiceRestTests {
@Autowired
private RestTemplate restTemplate;
@LocalServerPort
int randomServerPort;
@Autowired
private RequestTypeInterceptor requestTypeInterceptor;
@Autowired
private TraceIdInterceptor traceIdInterceptor;
@BeforeEach
void setup() {
traceIdInterceptor.createNewTraceId();
requestTypeInterceptor.markAsIntegrationTest();
}
@Test
void testRestService() {
ResponseEntity<Greeting> result = restTemplate.getForEntity(getEndpoint(), Greeting.class);
assertThat(result.getStatusCode().is2xxSuccessful()).isTrue();
assertThat(result.getBody()).isNotNull();
assertThat(result.getBody().getMessage()).isEqualTo("Hello RestCheck!");
}
/*
* This method is so complicated because it uses the local-grpc-server configuration for grpc to create
* a correct link for the rest endpoints in the cloud
*/
private String getEndpoint() {
String hostNameForGrpcServer = "127.0.0.1";
int port = randomServerPort;
String protocol = "http";
return String.format("%s://%s:%d/greeting?name=RestCheck",
protocol,
hostNameForGrpcServer,
port);
}
}