Skip to content

Commit

Permalink
Merge pull request #29 from taciano-perez/fix-duplicate-dep
Browse files Browse the repository at this point in the history
fixed issue with ApiUtils
  • Loading branch information
taciano-perez authored Feb 13, 2021
2 parents c914061 + 0cb9a94 commit e00236b
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Object> submit(@RequestParam("file") MultipartFile file,
@RequestParam("title") String title,
Expand All @@ -48,7 +45,7 @@ public ResponseEntity<Object> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -53,9 +49,6 @@ class UploadFileApiTest {
@MockBean
private GoogleId idValidator;

@MockBean
private ApiUtils apiUtils;

@Test
void testUploadSmallFile() throws Exception {
// given
Expand All @@ -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
Expand All @@ -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) {
Expand Down

0 comments on commit e00236b

Please sign in to comment.