Loading src/test/java/it/inaf/ia2/transfer/controller/ArchiveFileControllerTest.java +16 −13 Original line number Diff line number Diff line Loading @@ -9,9 +9,11 @@ import com.fasterxml.jackson.databind.ObjectMapper; import it.inaf.ia2.transfer.auth.TokenPrincipal; import it.inaf.ia2.transfer.service.ArchiveJob; import it.inaf.ia2.transfer.service.ArchiveService; import it.inaf.oats.vospace.parent.exchange.ArchiveEntryDescriptor; import java.io.File; import java.nio.file.Files; import java.util.Arrays; import java.util.List; import static org.junit.jupiter.api.Assertions.assertEquals; import org.junit.jupiter.api.Test; import static org.mockito.ArgumentMatchers.any; Loading Loading @@ -44,15 +46,14 @@ public class ArchiveFileControllerTest { @Autowired private MockMvc mockMvc; // TODO: refactor tests /* @Test public void testCreateTarArchive() throws Exception { ArchiveRequest request = new ArchiveRequest(); request.setJobId("123"); request.setType("TAR"); request.setPaths(Arrays.asList("/path/to/file1", "/path/to/file2")); request.setEntryDescriptors(List.of(this.getArchiveEntryDescriptor("/path/to/file1"), this.getArchiveEntryDescriptor("/path/to/file2"))); mockMvc.perform(post("/archive") .principal(fakePrincipal("user1")) Loading @@ -65,10 +66,10 @@ public class ArchiveFileControllerTest { assertEquals("123", job.getJobId()); assertEquals(ArchiveJob.Type.TAR, job.getType()); assertEquals("user1", job.getPrincipal().getName()); assertEquals(2, job.getVosPaths().size()); assertEquals(2, job.getEntryDescriptors().size()); return true; }), any()); }*/ } @Test public void testGetArchive() throws Exception { Loading @@ -90,14 +91,13 @@ public class ArchiveFileControllerTest { } } /* @Test //@Test public void testAnonymousCantCreateArchive() throws Exception { ArchiveRequest request = new ArchiveRequest(); request.setJobId("123"); request.setType("ZIP"); request.setPaths(Arrays.asList("/ignore")); request.setEntryDescriptors(List.of(this.getArchiveEntryDescriptor("/ignore"))); mockMvc.perform(post("/archive") .principal(fakePrincipal("anonymous")) Loading @@ -105,9 +105,8 @@ public class ArchiveFileControllerTest { .content(MAPPER.writeValueAsString(request))) .andDo(print()) .andExpect(status().isForbidden()); }*/ } @Test public void testAnonymousCantGetArchive() throws Exception { mockMvc.perform(get("/archive/123.zip") Loading @@ -121,4 +120,8 @@ public class ArchiveFileControllerTest { when(principal.getName()).thenReturn(name); return principal; } private ArchiveEntryDescriptor getArchiveEntryDescriptor(String vosPath) { return new ArchiveEntryDescriptor(vosPath); } } Loading
src/test/java/it/inaf/ia2/transfer/controller/ArchiveFileControllerTest.java +16 −13 Original line number Diff line number Diff line Loading @@ -9,9 +9,11 @@ import com.fasterxml.jackson.databind.ObjectMapper; import it.inaf.ia2.transfer.auth.TokenPrincipal; import it.inaf.ia2.transfer.service.ArchiveJob; import it.inaf.ia2.transfer.service.ArchiveService; import it.inaf.oats.vospace.parent.exchange.ArchiveEntryDescriptor; import java.io.File; import java.nio.file.Files; import java.util.Arrays; import java.util.List; import static org.junit.jupiter.api.Assertions.assertEquals; import org.junit.jupiter.api.Test; import static org.mockito.ArgumentMatchers.any; Loading Loading @@ -44,15 +46,14 @@ public class ArchiveFileControllerTest { @Autowired private MockMvc mockMvc; // TODO: refactor tests /* @Test public void testCreateTarArchive() throws Exception { ArchiveRequest request = new ArchiveRequest(); request.setJobId("123"); request.setType("TAR"); request.setPaths(Arrays.asList("/path/to/file1", "/path/to/file2")); request.setEntryDescriptors(List.of(this.getArchiveEntryDescriptor("/path/to/file1"), this.getArchiveEntryDescriptor("/path/to/file2"))); mockMvc.perform(post("/archive") .principal(fakePrincipal("user1")) Loading @@ -65,10 +66,10 @@ public class ArchiveFileControllerTest { assertEquals("123", job.getJobId()); assertEquals(ArchiveJob.Type.TAR, job.getType()); assertEquals("user1", job.getPrincipal().getName()); assertEquals(2, job.getVosPaths().size()); assertEquals(2, job.getEntryDescriptors().size()); return true; }), any()); }*/ } @Test public void testGetArchive() throws Exception { Loading @@ -90,14 +91,13 @@ public class ArchiveFileControllerTest { } } /* @Test //@Test public void testAnonymousCantCreateArchive() throws Exception { ArchiveRequest request = new ArchiveRequest(); request.setJobId("123"); request.setType("ZIP"); request.setPaths(Arrays.asList("/ignore")); request.setEntryDescriptors(List.of(this.getArchiveEntryDescriptor("/ignore"))); mockMvc.perform(post("/archive") .principal(fakePrincipal("anonymous")) Loading @@ -105,9 +105,8 @@ public class ArchiveFileControllerTest { .content(MAPPER.writeValueAsString(request))) .andDo(print()) .andExpect(status().isForbidden()); }*/ } @Test public void testAnonymousCantGetArchive() throws Exception { mockMvc.perform(get("/archive/123.zip") Loading @@ -121,4 +120,8 @@ public class ArchiveFileControllerTest { when(principal.getName()).thenReturn(name); return principal; } private ArchiveEntryDescriptor getArchiveEntryDescriptor(String vosPath) { return new ArchiveEntryDescriptor(vosPath); } }