From 0cb9a94aff96117d903eff8e35c505b0b9965616 Mon Sep 17 00:00:00 2001 From: Taciano Dreckmann Perez Date: Sat, 13 Feb 2021 14:58:46 +0100 Subject: [PATCH] fixed issue with ApiUtils --- .../java/com/o3/storyinspector/api/UploadFileApi.java | 5 +---- .../java/com/o3/storyinspector/api/util/ApiUtils.java | 4 +--- .../com/o3/storyinspector/api/UploadFileApiTest.java | 9 --------- 3 files changed, 2 insertions(+), 16 deletions(-) diff --git a/api/src/main/java/com/o3/storyinspector/api/UploadFileApi.java b/api/src/main/java/com/o3/storyinspector/api/UploadFileApi.java index 58bb236..d7370d2 100644 --- a/api/src/main/java/com/o3/storyinspector/api/UploadFileApi.java +++ b/api/src/main/java/com/o3/storyinspector/api/UploadFileApi.java @@ -27,9 +27,6 @@ public class UploadFileApi { @Autowired private GoogleId idValidator; - @Autowired - private ApiUtils apiUtils; - @RequestMapping(value = "/book", method = RequestMethod.POST, consumes = {"multipart/form-data"}) public ResponseEntity submit(@RequestParam("file") MultipartFile file, @RequestParam("title") String title, @@ -48,7 +45,7 @@ public ResponseEntity submit(@RequestParam("file") MultipartFile file, final Long bookId = BookDAO.saveBook(db, userInfo.getId(), userInfo.getEmail(), title, author, content, null, null, null); logger.trace(String.format("BOOK ID - %s", bookId)); - apiUtils.callAsyncApiWithParameter(ApiUtils.API_PROCESS_BOOK_ENDPOINT, "ID", bookId.toString()); + ApiUtils.callAsyncApiWithParameter(ApiUtils.API_PROCESS_BOOK_ENDPOINT, "ID", bookId.toString()); return ResponseEntity.ok().build(); } else { logger.error("Could not upload book, error authenticating user. Title: " + title + ", author:" + author + ", token: " + idToken); diff --git a/api/src/main/java/com/o3/storyinspector/api/util/ApiUtils.java b/api/src/main/java/com/o3/storyinspector/api/util/ApiUtils.java index ef3eb9d..2ab9fa4 100644 --- a/api/src/main/java/com/o3/storyinspector/api/util/ApiUtils.java +++ b/api/src/main/java/com/o3/storyinspector/api/util/ApiUtils.java @@ -7,7 +7,6 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.scheduling.annotation.Async; -import org.springframework.stereotype.Component; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.web.client.RestTemplate; @@ -22,7 +21,6 @@ /** * Class with utility functions to handle API endpoints. */ -@Component("apiUtils") public class ApiUtils { final static Logger logger = LoggerFactory.getLogger(ApiUtils.class); @@ -34,7 +32,7 @@ public class ApiUtils { public static final String API_PROCESS_BOOK_ENDPOINT = API_ROOT + "/process-book"; @Async - public void callAsyncApiWithParameter(final String endpointPath, final String paramName, final String paramValue) { + public static void callAsyncApiWithParameter(final String endpointPath, final String paramName, final String paramValue) { final String endpoint = getBaseUrl() + endpointPath; logger.trace("Calling async endpoint " + endpoint + " with parameter " + paramName + "=" + paramValue); final HttpHeaders headers = new HttpHeaders(); diff --git a/api/src/test/java/com/o3/storyinspector/api/UploadFileApiTest.java b/api/src/test/java/com/o3/storyinspector/api/UploadFileApiTest.java index 0c34c14..894b8cf 100644 --- a/api/src/test/java/com/o3/storyinspector/api/UploadFileApiTest.java +++ b/api/src/test/java/com/o3/storyinspector/api/UploadFileApiTest.java @@ -2,7 +2,6 @@ import com.o3.storyinspector.api.user.GoogleId; import com.o3.storyinspector.api.user.UserInfo; -import com.o3.storyinspector.api.util.ApiUtils; import org.apache.commons.lang3.ArrayUtils; import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; @@ -19,10 +18,7 @@ import java.util.Random; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.multipart; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -53,9 +49,6 @@ class UploadFileApiTest { @MockBean private GoogleId idValidator; - @MockBean - private ApiUtils apiUtils; - @Test void testUploadSmallFile() throws Exception { // given @@ -72,7 +65,6 @@ void testUploadSmallFile() throws Exception { .contentType(MediaType.MULTIPART_FORM_DATA_VALUE + "; boundary=" + BOUNDARY)) // then .andExpect(status().isOk()); - verify(apiUtils, times(1)).callAsyncApiWithParameter(eq(ApiUtils.API_PROCESS_BOOK_ENDPOINT), eq("ID"), any()); } @Test @@ -92,7 +84,6 @@ void testUploadLargeFile() throws Exception { .contentType(MediaType.MULTIPART_FORM_DATA_VALUE + "; boundary=" + BOUNDARY)) // then .andExpect(status().isOk()); - verify(apiUtils, times(1)).callAsyncApiWithParameter(eq(ApiUtils.API_PROCESS_BOOK_ENDPOINT), eq("ID"), any()); } private static byte[] createFileContent(final byte[] data, final String boundary, final String contentType, final String fileName) {