From e4a04e625c05ee5b3aa9ecd1a019b7937bb2d0ee Mon Sep 17 00:00:00 2001 From: Julien Hagestedt Date: Mon, 8 Jun 2020 15:44:56 +0200 Subject: [PATCH] feat: api (#68) --- pom.xml | 25 +++++++++ .../testresult/TestResultController.java | 12 ++-- .../testresult/model/TestResultList.java | 55 +++++++++++++++++++ .../testresult/TestResultControllerTest.java | 17 +++--- 4 files changed, 95 insertions(+), 14 deletions(-) create mode 100644 src/main/java/app/coronawarn/testresult/model/TestResultList.java diff --git a/pom.xml b/pom.xml index 2c6fdde..262fb9b 100644 --- a/pom.xml +++ b/pom.xml @@ -198,6 +198,18 @@ org.springframework.boot spring-boot-maven-plugin + + pre-integration-test + + start + + + + post-integration-test + + stop + + repackage @@ -206,6 +218,19 @@ + + org.springdoc + springdoc-openapi-maven-plugin + 1.0 + + + integration-test + + generate + + + + org.apache.maven.plugins maven-checkstyle-plugin diff --git a/src/main/java/app/coronawarn/testresult/TestResultController.java b/src/main/java/app/coronawarn/testresult/TestResultController.java index d397729..fbddb80 100644 --- a/src/main/java/app/coronawarn/testresult/TestResultController.java +++ b/src/main/java/app/coronawarn/testresult/TestResultController.java @@ -22,12 +22,12 @@ package app.coronawarn.testresult; import app.coronawarn.testresult.model.TestResult; +import app.coronawarn.testresult.model.TestResultList; import app.coronawarn.testresult.model.TestResultRequest; import app.coronawarn.testresult.model.TestResultResponse; import io.swagger.v3.oas.annotations.Operation; -import java.util.List; import javax.validation.Valid; -import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.http.MediaType; @@ -71,7 +71,7 @@ public ResponseEntity result( /** * Insert or update the test results. * - * @param request the test result collection request + * @param list the test result list request * @return the response */ @Operation( @@ -83,10 +83,10 @@ public ResponseEntity result( produces = MediaType.APPLICATION_JSON_VALUE ) public ResponseEntity results( - @RequestBody @NotEmpty List<@Valid TestResult> request + @RequestBody @NotNull @Valid TestResultList list ) { - log.info("Received {} test results to insert or update from lab.", request.size()); - request.forEach(testResultService::createOrUpdate); + log.info("Received {} test results to insert or update from lab.", list.getTestResults().size()); + list.getTestResults().forEach(testResultService::createOrUpdate); return ResponseEntity.noContent().build(); } } diff --git a/src/main/java/app/coronawarn/testresult/model/TestResultList.java b/src/main/java/app/coronawarn/testresult/model/TestResultList.java new file mode 100644 index 0000000..fba20be --- /dev/null +++ b/src/main/java/app/coronawarn/testresult/model/TestResultList.java @@ -0,0 +1,55 @@ +/* + * Corona-Warn-App / cwa-testresult-server + * + * (C) 2020, T-Systems International GmbH + * + * Deutsche Telekom AG and all other contributors / + * copyright owners license this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this + * file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package app.coronawarn.testresult.model; + +import io.swagger.v3.oas.annotations.media.Schema; +import java.util.List; +import javax.validation.Valid; +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.ToString; + +/** + * Model of the test result list. + */ +@Schema( + description = "The test result list model." +) +@Getter +@ToString +@EqualsAndHashCode +public class TestResultList { + + /** + * The test result entries. + */ + @NotNull + @NotEmpty + private List<@Valid TestResult> testResults; + + public TestResultList setTestResults(List testResults) { + this.testResults = testResults; + return this; + } +} diff --git a/src/test/java/app/coronawarn/testresult/TestResultControllerTest.java b/src/test/java/app/coronawarn/testresult/TestResultControllerTest.java index 07b5f6c..f33d263 100644 --- a/src/test/java/app/coronawarn/testresult/TestResultControllerTest.java +++ b/src/test/java/app/coronawarn/testresult/TestResultControllerTest.java @@ -22,6 +22,7 @@ package app.coronawarn.testresult; import app.coronawarn.testresult.model.TestResult; +import app.coronawarn.testresult.model.TestResultList; import app.coronawarn.testresult.model.TestResultRequest; import com.fasterxml.jackson.databind.ObjectMapper; import java.util.Collections; @@ -81,9 +82,9 @@ public void insertInvalidResultShouldReturnBadRequest() throws Exception { // data String id = "a".repeat(64); // create - List invalid = Collections.singletonList( + TestResultList invalid = new TestResultList().setTestResults(Collections.singletonList( new TestResult().setId(id) - ); + )); mockMvc.perform(MockMvcRequestBuilders .post("/api/v1/lab/results") .accept(MediaType.APPLICATION_JSON_VALUE) @@ -92,9 +93,9 @@ public void insertInvalidResultShouldReturnBadRequest() throws Exception { .andDo(MockMvcResultHandlers.print()) .andExpect(MockMvcResultMatchers.status().isBadRequest()); // create - invalid = Collections.singletonList( + invalid = new TestResultList().setTestResults(Collections.singletonList( new TestResult().setId(id).setResult(4) - ); + )); mockMvc.perform(MockMvcRequestBuilders .post("/api/v1/lab/results") .accept(MediaType.APPLICATION_JSON_VALUE) @@ -110,9 +111,9 @@ public void insertValidShouldReturnNoContent() throws Exception { String id = "b".repeat(64); Integer result = 1; // create - List valid = Collections.singletonList( + TestResultList valid = new TestResultList().setTestResults(Collections.singletonList( new TestResult().setId(id).setResult(result) - ); + )); mockMvc.perform(MockMvcRequestBuilders .post("/api/v1/lab/results") .accept(MediaType.APPLICATION_JSON_VALUE) @@ -128,9 +129,9 @@ public void insertValidAndGetShouldReturnOk() throws Exception { String id = "c".repeat(64); Integer result = 1; // create - List valid = Collections.singletonList( + TestResultList valid = new TestResultList().setTestResults(Collections.singletonList( new TestResult().setId(id).setResult(result) - ); + )); mockMvc.perform(MockMvcRequestBuilders .post("/api/v1/lab/results") .accept(MediaType.APPLICATION_JSON_VALUE)