forked from esig/dss
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DSS-1431 : TSLRepository#clearRepository() fails if the cache directo…
…ry doesn't exist
- Loading branch information
1 parent
076cd47
commit 6646425
Showing
5 changed files
with
85 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
dss-tsl-validation/src/test/java/eu/europa/esig/dss/tsl/service/TSLRepositoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package eu.europa.esig.dss.tsl.service; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import java.io.File; | ||
import java.io.FileNotFoundException; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
|
||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.TemporaryFolder; | ||
|
||
public class TSLRepositoryTest { | ||
|
||
@Rule | ||
public TemporaryFolder folder = new TemporaryFolder(); | ||
|
||
@Test | ||
public void clear() throws IOException { | ||
File testFolder = folder.newFolder("test"); | ||
createFile(testFolder, "test1.xml"); | ||
|
||
assertEquals(1, testFolder.listFiles().length); | ||
|
||
TSLRepository repo = new TSLRepository(); | ||
repo.setCacheDirectoryPath(testFolder.getAbsolutePath()); | ||
repo.clearRepository(); | ||
assertEquals(0, testFolder.listFiles().length); | ||
assertTrue(testFolder.exists()); | ||
} | ||
|
||
@Test(expected = FileNotFoundException.class) | ||
public void clearFolderNotExist() throws IOException { | ||
TSLRepository repo = new TSLRepository(); | ||
repo.setCacheDirectoryPath("wrong"); | ||
repo.clearRepository(); | ||
} | ||
|
||
private void createFile(File folder, String name) throws IOException { | ||
File file = new File(folder, name); | ||
try (FileOutputStream fos = new FileOutputStream(file)) { | ||
fos.write(0); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters