|
|
@@ -0,0 +1,44 @@
|
|
|
+package nl.quintor.hdboer.aegoncalc.controllers;
|
|
|
+
|
|
|
+import nl.quintor.hdboer.aegoncalc.Application;
|
|
|
+import org.junit.jupiter.api.Assertions;
|
|
|
+import org.junit.jupiter.api.Test;
|
|
|
+import org.springframework.boot.test.context.SpringBootTest;
|
|
|
+import org.springframework.boot.test.web.client.TestRestTemplate;
|
|
|
+import org.springframework.boot.web.server.LocalServerPort;
|
|
|
+import org.springframework.http.HttpStatus;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
+
|
|
|
+@SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
|
|
+class SimpleCalculatorControllerIT {
|
|
|
+
|
|
|
+ @LocalServerPort
|
|
|
+ private int port;
|
|
|
+
|
|
|
+ TestRestTemplate restTemplate = new TestRestTemplate();
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testAdd() {
|
|
|
+ ResponseEntity<Double> response = get("/numbers/1/add/15");
|
|
|
+
|
|
|
+ Assertions.assertAll(
|
|
|
+ () -> Assertions.assertEquals(HttpStatus.OK, response.getStatusCode()),
|
|
|
+ () -> Assertions.assertEquals(16.0, response.getBody())
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testAddLargeNumber() {
|
|
|
+ ResponseEntity<Double> response = get("/numbers/2147483647/add/37");
|
|
|
+
|
|
|
+ Assertions.assertAll(
|
|
|
+ () -> Assertions.assertEquals(HttpStatus.OK, response.getStatusCode()),
|
|
|
+ () -> Assertions.assertEquals(2147483684.0, response.getBody())
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ private ResponseEntity<Double> get(String path) {
|
|
|
+ return restTemplate.getForEntity("http://localhost:" + port + path, Double.class);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|