-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #107 from TAMULib/sync-with-folio
Sync with folio
- Loading branch information
Showing
9 changed files
with
203 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
events/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
service/src/test/java/org/folio/rest/workflow/controller/EventControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package org.folio.rest.workflow.controller; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.junit.jupiter.params.provider.Arguments.arguments; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.FileSystemException; | ||
import java.util.stream.Stream; | ||
import org.apache.commons.io.FileUtils; | ||
import org.folio.rest.workflow.jms.EventProducer; | ||
import org.folio.rest.workflow.model.repo.TriggerRepo; | ||
import org.folio.spring.tenant.properties.TenantProperties; | ||
import org.folio.spring.tenant.resolver.TenantHeaderResolver; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.mock.web.MockMultipartFile; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder; | ||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; | ||
import org.springframework.test.web.servlet.setup.MockMvcBuilders; | ||
|
||
@WebMvcTest(EventController.class) | ||
class EventControllerTest { | ||
|
||
private MockMvc mockMvc; | ||
|
||
@Autowired | ||
private EventController eventController; | ||
|
||
@MockBean | ||
private EventProducer eventProducer; | ||
|
||
@MockBean | ||
private TriggerRepo triggerRepo; | ||
|
||
@MockBean | ||
private TenantProperties tenantProperties; | ||
|
||
@BeforeEach | ||
void beforeEach() { | ||
mockMvc = MockMvcBuilders.standaloneSetup(eventController) | ||
.setCustomArgumentResolvers(new TenantHeaderResolver("X-Okapi-Tenant")) | ||
.build(); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource | ||
void upload(String tenant, String dir, String file, String expectedPath) throws Exception { | ||
String expectedInputFilePath = expectedPath.replaceFirst("[^/]+/[^/]+/", ""); | ||
mockMvc.perform(upload(tenant, dir, file)) | ||
.andExpectAll(status().isOk(), jsonPath("inputFilePath").value(expectedInputFilePath)); | ||
assertThat(readFile(expectedPath)).isEqualTo("This is the file content"); | ||
} | ||
|
||
static Stream<Arguments> upload() { | ||
return Stream.of( | ||
arguments("diku", "d1/d2/d3", "filename.txt", "events/diku/d1/d2/d3/filename.txt"), | ||
arguments("diku", "", "baz.txt", "events/diku/baz.txt"), | ||
arguments("foo", "a/../b", "c/d/../e/f.txt", "events/foo/b/c/e/f.txt")); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource | ||
void uploadRejected(String tenant, String dir, String file) throws Exception { | ||
assertThrows(FileSystemException.class, () -> | ||
mockMvc.perform(upload(tenant, dir, file))); | ||
} | ||
|
||
static Stream<Arguments> uploadRejected() { | ||
return Stream.of( | ||
arguments("diku/../x", "a", "a.txt"), | ||
arguments("diku/../../x", "a", "a.txt"), | ||
arguments("diku", "a/../../x", "a.txt"), | ||
arguments("diku", "../x", "a.txt"), | ||
arguments("diku", "a", "../../x.txt"), | ||
arguments("diku", "a", "../../../x.txt"), | ||
arguments("diku", "a", "../../../../x.txt")); | ||
} | ||
|
||
MockHttpServletRequestBuilder upload(String tenant, String dir, String file) throws Exception { | ||
var sampleFile = new MockMultipartFile( | ||
"file", | ||
file, | ||
MediaType.TEXT_PLAIN_VALUE, | ||
"This is the file content".getBytes()); | ||
|
||
return MockMvcRequestBuilders.multipart("/events").file(sampleFile) | ||
.header("X-Okapi-Tenant", tenant).param("path", dir); | ||
} | ||
|
||
private static String readFile(String path) throws IOException { | ||
return FileUtils.readFileToString(new File(path), StandardCharsets.UTF_8); | ||
} | ||
} |
Oops, something went wrong.