Branch yann #6

Merged
YanNThO merged 47 commits from Branch_Yann into main 2021-02-01 18:36:46 +01:00
4 changed files with 44 additions and 25 deletions
Showing only changes of commit 3915b18aba - Show all commits

View file

@ -6,16 +6,19 @@
<content url="file://$MODULE_DIR$"> <content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" /> <sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-resource" />
<excludeFolder url="file://$MODULE_DIR$/target" /> <excludeFolder url="file://$MODULE_DIR$/target" />
</content> </content>
<orderEntry type="inheritedJdk" /> <orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-engine:5.7.0" level="project" /> <orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-engine:5.7.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.apiguardian:apiguardian-api:1.1.0" level="project" /> <orderEntry type="library" name="Maven: org.apiguardian:apiguardian-api:1.1.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-engine:1.7.0" level="project" /> <orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-engine:1.7.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-api:5.7.0" level="project" /> <orderEntry type="library" name="Maven: org.junit.jupiter:junit-jupiter-api:5.7.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.opentest4j:opentest4j:1.2.0" level="project" /> <orderEntry type="library" name="Maven: org.opentest4j:opentest4j:1.2.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-commons:1.7.0" level="project" /> <orderEntry type="library" name="Maven: org.junit.platform:junit-platform-commons:1.7.0" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.25" level="project" /> <orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.25" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-simple:1.7.25" level="project" /> <orderEntry type="library" name="Maven: org.slf4j:slf4j-simple:1.7.25" level="project" />
</component> </component>

View file

@ -67,6 +67,12 @@
<artifactId>slf4j-simple</artifactId> <artifactId>slf4j-simple</artifactId>
<version>1.7.25</version> <version>1.7.25</version>
</dependency> </dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.7.0</version>
<scope>compile</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>

View file

@ -7,12 +7,14 @@ import java.net.MalformedURLException;
public class ImportData { public class ImportData {
protected String url; protected String url;
protected String repDes;
/** /**
* Le constructeur de ImportData * Le constructeur de ImportData
*/ */
ImportData(){ ImportData(){
this.url = "https://www.fdj.fr/jeux-de-tirage/loto/statistiques"; this.url = "https://www.fdj.fr/jeux-de-tirage/loto/statistiques";
this.repDes = "src/test/resources/";
} }
/** /**
@ -23,6 +25,10 @@ public class ImportData {
this.url=url; this.url=url;
} }
public void getUrl() {
}
private boolean UrlExist() { private boolean UrlExist() {
try { try {
URL site = new URL(url); URL site = new URL(url);
@ -37,16 +43,6 @@ public class ImportData {
} }
} }
private boolean ZipNotExist(String filename) {
File directory = new File("src/main/java/resources/");
File[] files = directory.listFiles();
for (File f : files) {
if (f.getName().equals(filename))
return false;
}
return true;
}
public void DownloadCsvZip() { public void DownloadCsvZip() {
if (UrlExist()) { if (UrlExist()) {
BufferedReader in = null; BufferedReader in = null;
@ -63,19 +59,16 @@ public class ImportData {
if (test.equals(urlZipLink.substring(50, 55))) { if (test.equals(urlZipLink.substring(50, 55))) {
nameZip = urlZipLink.substring(50,65); nameZip = urlZipLink.substring(50,65);
urlZipLink = urlZipLink.substring(13,65); urlZipLink = urlZipLink.substring(13,65);
if (ZipNotExist(nameZip)) { try (BufferedInputStream bis = new BufferedInputStream(new URL(urlZipLink).openStream());
try (BufferedInputStream bis = new BufferedInputStream(new URL(urlZipLink).openStream()); FileOutputStream fos = new FileOutputStream(repDes + nameZip)) {
FileOutputStream fos = new FileOutputStream("src/main/java/resources/" + nameZip)) { byte data[] = new byte[1024];
byte data[] = new byte[1024]; int byteContent;
int byteContent; while ((byteContent = bis.read(data, 0, 1024)) != -1) {
while ((byteContent = bis.read(data, 0, 1024)) != -1) { fos.write(data, 0, byteContent);
fos.write(data, 0, byteContent);
}
} catch (IOException e) {
e.printStackTrace(System.out);
} }
} catch (IOException e) {
e.printStackTrace(System.out);
} }
} }
} }
} }

View file

@ -0,0 +1,17 @@
package fr.myny.data;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class ImportDataTest {
@Test
void downloadCsvZip() {
ImportData csv = new ImportData();
csv.DownloadCsvZip();
}
}