Skip to content
Snippets Groups Projects
Commit 071f849d authored by Nicola Fulvio Calabria's avatar Nicola Fulvio Calabria
Browse files

Test fix

parent 16ff8bff
No related branches found
No related tags found
No related merge requests found
......@@ -11,6 +11,7 @@ import it.inaf.ia2.transfer.persistence.JobDAO;
import it.inaf.ia2.transfer.persistence.LocationDAO;
import it.inaf.ia2.transfer.persistence.model.FileInfo;
import it.inaf.oats.vospace.exception.QuotaExceededException;
import it.inaf.oats.vospace.parent.exchange.ArchiveEntryDescriptor;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
......@@ -38,6 +39,7 @@ import org.kamranzafar.jtar.TarEntry;
import org.kamranzafar.jtar.TarInputStream;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import org.mockito.Mockito;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
......@@ -47,6 +49,7 @@ import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Primary;
import org.springframework.http.HttpMethod;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.test.context.ContextConfiguration;
......@@ -70,9 +73,6 @@ public class ArchiveServiceTest {
@MockBean
private RestTemplate restTemplate;
@MockBean
private HttpServletRequest servletRequest;
@MockBean
private AuthorizationService authorizationService;
......@@ -93,7 +93,6 @@ public class ArchiveServiceTest {
}
// TODO: refactor tests
/*
@Test
public void testTarGeneration() throws Exception {
......@@ -115,7 +114,6 @@ public class ArchiveServiceTest {
});
}
@Test
public void testZipGeneration() throws Exception {
......@@ -137,7 +135,6 @@ public class ArchiveServiceTest {
});
}
@Test
public void testArchiveQuotaExceeded() throws Exception {
......@@ -145,8 +142,10 @@ public class ArchiveServiceTest {
job.setPrincipal(new TokenPrincipal("user2", "token2"));
job.setJobId("job2");
job.setType(ArchiveJob.Type.ZIP);
job.setVosPaths(Arrays.asList("/ignore"));
job.setEntryDescriptors(List.of(this.getArchiveEntryDescriptor("/ignore")));
HttpServletRequest servletRequest = Mockito.mock(HttpServletRequest.class);
when(servletRequest.getUserPrincipal()).thenReturn(job.getPrincipal());
File user2Dir = tmpDir.toPath().resolve("user2").toFile();
......@@ -165,7 +164,7 @@ public class ArchiveServiceTest {
archiveService.createArchive(job, servletRequest);
});
}
private static abstract class TestArchiveHandler<I extends InputStream, E> {
private final I is;
......@@ -202,8 +201,14 @@ public class ArchiveServiceTest {
job.setPrincipal(new TokenPrincipal("user1", "token1"));
job.setJobId("abcdef");
job.setType(type);
job.setVosPaths(Arrays.asList(parent + "/dir1", parent + "/dir2", parent + "/file6"));
job.setEntryDescriptors(List.of(
this.getArchiveEntryDescriptor(parent + "/dir1"),
this.getArchiveEntryDescriptor(parent + "/dir2"),
this.getArchiveEntryDescriptor(parent + "/file6")
));
HttpServletRequest servletRequest = Mockito.mock(HttpServletRequest.class);
when(servletRequest.getUserPrincipal()).thenReturn(job.getPrincipal());
when(authorizationService.isDownloadable(any(), any())).thenReturn(true);
......@@ -251,7 +256,7 @@ public class ArchiveServiceTest {
TestArchiveHandler<I, E> testArchiveHandler = testArchiveGetter.apply(new FileInputStream(result));
try ( InputStream is = testArchiveHandler.getInputStream()) {
try (InputStream is = testArchiveHandler.getInputStream()) {
E entry;
while ((entry = testArchiveHandler.getNextEntry()) != null) {
assertFalse(i >= expectedSequence.size(), "Found more entries than in expected sequence");
......@@ -288,12 +293,15 @@ public class ArchiveServiceTest {
private File createFile(File parent, String path) throws Exception {
File file = parent.toPath().resolve(path).toFile();
file.getParentFile().mkdirs();
file.getParentFile().mkdirs();
file.createNewFile();
Files.write(file.toPath(), "some data".getBytes());
return file;
}
*/
private ArchiveEntryDescriptor getArchiveEntryDescriptor(String vosPath) {
return new ArchiveEntryDescriptor(vosPath);
}
/**
* @TestPropertySource annotation can't be used in this test because we need
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment