Test for DownloaderImpl
This commit is contained in:
@@ -52,6 +52,16 @@
|
|||||||
</exclusion>
|
</exclusion>
|
||||||
</exclusions>
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-test-autoconfigure</artifactId>
|
||||||
|
<version>${spring-boot.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import javax.sql.DataSource;
|
|||||||
@Configuration
|
@Configuration
|
||||||
@EnableJpaRepositories("me.bearns.fias.repository")
|
@EnableJpaRepositories("me.bearns.fias.repository")
|
||||||
@EnableTransactionManagement
|
@EnableTransactionManagement
|
||||||
@PropertySource("application.properties")
|
@PropertySource(value = "application.properties", ignoreResourceNotFound = true)
|
||||||
class ApplicationConfig {
|
class ApplicationConfig {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
|||||||
@@ -0,0 +1,57 @@
|
|||||||
|
package me.bearns.fias;
|
||||||
|
|
||||||
|
|
||||||
|
import me.bearns.fias.service.Downloader;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
@RunWith(SpringRunner.class)
|
||||||
|
@SpringBootTest
|
||||||
|
public class DownloaderTest {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private Downloader service;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDownload() {
|
||||||
|
List<String> list = Arrays.asList(
|
||||||
|
"http://fias-file.nalog.ru/DownloadUpdates?file=fias_delta_xml.zip&version=20200811",
|
||||||
|
"http://fias-file.nalog.ru/DownloadUpdates?file=fias_delta_xml.zip&version=20200807",
|
||||||
|
"http://fias-file.nalog.ru/DownloadUpdates?file=fias_delta_xml.zip&version=20200804",
|
||||||
|
"http://fias-file.nalog.ru/DownloadUpdates?file=fias_delta_xml.zip&version=20200807" //repeat
|
||||||
|
);
|
||||||
|
|
||||||
|
assert service != null;
|
||||||
|
|
||||||
|
//start download
|
||||||
|
final Stream<CompletableFuture<File>> futureStream = list.parallelStream().map(service::download);
|
||||||
|
|
||||||
|
Stream<File> fileStream = futureStream.map(fileCompletableFuture -> {
|
||||||
|
try {
|
||||||
|
return fileCompletableFuture.get();
|
||||||
|
} catch (Exception e) {
|
||||||
|
return null; //on error
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
assert fileStream.allMatch(Objects::nonNull);
|
||||||
|
|
||||||
|
assert fileStream.count() == 3;
|
||||||
|
|
||||||
|
assert fileStream.allMatch(File::exists);
|
||||||
|
|
||||||
|
assert fileStream.allMatch(file -> file.length() > 0);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user