Test for DownloaderImpl

apache_commons_compress
Terekhin Alexander 5 years ago
parent f2937772b4
commit 2df96026bb
  1. 10
      pom.xml
  2. 2
      src/main/java/me/bearns/fias/config/ApplicationConfig.java
  3. 57
      src/test/java/me/bearns/fias/DownloaderTest.java

@ -52,6 +52,16 @@
</exclusion>
</exclusions>
</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>
<build>

@ -20,7 +20,7 @@ import javax.sql.DataSource;
@Configuration
@EnableJpaRepositories("me.bearns.fias.repository")
@EnableTransactionManagement
@PropertySource("application.properties")
@PropertySource(value = "application.properties", ignoreResourceNotFound = true)
class ApplicationConfig {
@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);
}
}
Loading…
Cancel
Save