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

Test fix

parent 16ff8bff
Branches
No related tags found
No related merge requests found
...@@ -11,6 +11,7 @@ import it.inaf.ia2.transfer.persistence.JobDAO; ...@@ -11,6 +11,7 @@ import it.inaf.ia2.transfer.persistence.JobDAO;
import it.inaf.ia2.transfer.persistence.LocationDAO; import it.inaf.ia2.transfer.persistence.LocationDAO;
import it.inaf.ia2.transfer.persistence.model.FileInfo; import it.inaf.ia2.transfer.persistence.model.FileInfo;
import it.inaf.oats.vospace.exception.QuotaExceededException; import it.inaf.oats.vospace.exception.QuotaExceededException;
import it.inaf.oats.vospace.parent.exchange.ArchiveEntryDescriptor;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
...@@ -38,6 +39,7 @@ import org.kamranzafar.jtar.TarEntry; ...@@ -38,6 +39,7 @@ import org.kamranzafar.jtar.TarEntry;
import org.kamranzafar.jtar.TarInputStream; import org.kamranzafar.jtar.TarInputStream;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.eq;
import org.mockito.Mockito;
import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
...@@ -47,6 +49,7 @@ import org.springframework.boot.test.mock.mockito.MockBean; ...@@ -47,6 +49,7 @@ import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.boot.test.util.TestPropertyValues; import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.ApplicationContextInitializer; import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Primary;
import org.springframework.http.HttpMethod; import org.springframework.http.HttpMethod;
import org.springframework.http.client.ClientHttpResponse; import org.springframework.http.client.ClientHttpResponse;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
...@@ -71,9 +74,6 @@ public class ArchiveServiceTest { ...@@ -71,9 +74,6 @@ public class ArchiveServiceTest {
@MockBean @MockBean
private RestTemplate restTemplate; private RestTemplate restTemplate;
@MockBean
private HttpServletRequest servletRequest;
@MockBean @MockBean
private AuthorizationService authorizationService; private AuthorizationService authorizationService;
...@@ -93,7 +93,6 @@ public class ArchiveServiceTest { ...@@ -93,7 +93,6 @@ public class ArchiveServiceTest {
} }
// TODO: refactor tests // TODO: refactor tests
/*
@Test @Test
public void testTarGeneration() throws Exception { public void testTarGeneration() throws Exception {
...@@ -115,7 +114,6 @@ public class ArchiveServiceTest { ...@@ -115,7 +114,6 @@ public class ArchiveServiceTest {
}); });
} }
@Test @Test
public void testZipGeneration() throws Exception { public void testZipGeneration() throws Exception {
...@@ -137,7 +135,6 @@ public class ArchiveServiceTest { ...@@ -137,7 +135,6 @@ public class ArchiveServiceTest {
}); });
} }
@Test @Test
public void testArchiveQuotaExceeded() throws Exception { public void testArchiveQuotaExceeded() throws Exception {
...@@ -145,7 +142,9 @@ public class ArchiveServiceTest { ...@@ -145,7 +142,9 @@ public class ArchiveServiceTest {
job.setPrincipal(new TokenPrincipal("user2", "token2")); job.setPrincipal(new TokenPrincipal("user2", "token2"));
job.setJobId("job2"); job.setJobId("job2");
job.setType(ArchiveJob.Type.ZIP); 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()); when(servletRequest.getUserPrincipal()).thenReturn(job.getPrincipal());
...@@ -202,7 +201,13 @@ public class ArchiveServiceTest { ...@@ -202,7 +201,13 @@ public class ArchiveServiceTest {
job.setPrincipal(new TokenPrincipal("user1", "token1")); job.setPrincipal(new TokenPrincipal("user1", "token1"));
job.setJobId("abcdef"); job.setJobId("abcdef");
job.setType(type); 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(servletRequest.getUserPrincipal()).thenReturn(job.getPrincipal());
...@@ -293,7 +298,10 @@ public class ArchiveServiceTest { ...@@ -293,7 +298,10 @@ public class ArchiveServiceTest {
Files.write(file.toPath(), "some data".getBytes()); Files.write(file.toPath(), "some data".getBytes());
return file; return file;
} }
*/
private ArchiveEntryDescriptor getArchiveEntryDescriptor(String vosPath) {
return new ArchiveEntryDescriptor(vosPath);
}
/** /**
* @TestPropertySource annotation can't be used in this test because we need * @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