-
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.
Config and runner fixes needed to be tested.
- Loading branch information
1 parent
c8c5d21
commit 048054b
Showing
11 changed files
with
479 additions
and
462 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
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
81 changes: 81 additions & 0 deletions
81
src/test/java/org/gridsuite/cgmes/assembling/job/AcquisitionServerTest.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,81 @@ | ||
package org.gridsuite.cgmes.assembling.job; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.mockftpserver.fake.FakeFtpServer; | ||
import org.mockftpserver.fake.UserAccount; | ||
import org.mockftpserver.fake.filesystem.DirectoryEntry; | ||
import org.mockftpserver.fake.filesystem.FileEntry; | ||
import org.mockftpserver.fake.filesystem.FileSystem; | ||
import org.mockftpserver.fake.filesystem.UnixFakeFileSystem; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
import static java.nio.charset.StandardCharsets.UTF_8; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
class AcquisitionServerTest { | ||
@Test | ||
void testFtpAcquisition() throws IOException { | ||
FileSystem fileSystem = new UnixFakeFileSystem(); | ||
fileSystem.add(new DirectoryEntry("/cases")); | ||
fileSystem.add(new FileEntry("/cases/case1.iidm", "fake file content 1")); | ||
fileSystem.add(new FileEntry("/cases/case2.iidm", "fake file content 2")); | ||
|
||
FakeFtpServer fakeFtpServer = new FakeFtpServer(); | ||
fakeFtpServer.addUserAccount(new UserAccount("dummy_ftp", "dummy_ftp", "/")); | ||
fakeFtpServer.setFileSystem(fileSystem); | ||
fakeFtpServer.setServerControlPort(0); | ||
|
||
fakeFtpServer.start(); | ||
|
||
final String acquisitionServerUrl = "ftp://localhost:" + fakeFtpServer.getServerControlPort(); | ||
try (final AcquisitionServer acquisitionServer = new AcquisitionServer(acquisitionServerUrl, "dummy_ftp", "dummy_ftp")) { | ||
acquisitionServer.open(); | ||
Map<String, String> retrievedFiles = acquisitionServer.listFiles("./cases"); | ||
assertEquals(2, retrievedFiles.size()); | ||
|
||
TransferableFile file1 = acquisitionServer.getFile("case1.iidm", acquisitionServerUrl + "/cases/case1.iidm"); | ||
assertEquals("case1.iidm", file1.getName()); | ||
assertEquals("fake file content 1", new String(file1.getData(), UTF_8)); | ||
|
||
TransferableFile file2 = acquisitionServer.getFile("case2.iidm", acquisitionServerUrl + "/cases/case2.iidm"); | ||
assertEquals("case2.iidm", file2.getName()); | ||
assertEquals("fake file content 2", new String(file2.getData(), UTF_8)); | ||
} finally { | ||
fakeFtpServer.stop(); | ||
} | ||
} | ||
|
||
@Test | ||
void testAcceptedFilesConnection() throws Exception { | ||
TestUtils.withSftp(server -> { | ||
server.putFile("cases/20200817T1705Z_1D_RTEFRANCE-FR_SV_002.zip", "fake file content 1", UTF_8); | ||
server.putFile("cases/20200817T1705Z__RTEFRANCE-FR_EQ_002.zip", "fake file content 2", UTF_8); | ||
server.putFile("cases/20200817T1705Z_1D_RTEFRANCE-FR_SSH_002.zip", "fake file content 3", UTF_8); | ||
server.putFile("cases/20200817T1705Z_1D_RTEFRANCE-FR_TP_002.zip", "fake file content 4", UTF_8); | ||
|
||
final Set<String> authorizedSourcingActors = Set.of("RTEFRANCE-FR"); | ||
final Set<String> authorizedBusinessProcesses = Set.of("1D"); | ||
|
||
final String acquisitionServerUrl = "sftp://localhost:" + server.getPort(); | ||
try (final AcquisitionServer acquisitionServer = new AcquisitionServer(acquisitionServerUrl, "dummy", "dummy")) { | ||
acquisitionServer.open(); | ||
Map<String, String> retrievedFiles = acquisitionServer.listFiles("./cases"); | ||
assertEquals(4, retrievedFiles.size()); | ||
|
||
TransferableFile file1 = acquisitionServer.getFile("20200817T1705Z_1D_RTEFRANCE-FR_SV_002.zip", acquisitionServerUrl + "/cases/20200817T1705Z_1D_RTEFRANCE-FR_SV_002.zip"); | ||
assertTrue(CgmesUtils.isValidProfileFileName(file1.getName(), authorizedSourcingActors, authorizedBusinessProcesses)); | ||
assertEquals("20200817T1705Z_1D_RTEFRANCE-FR_SV_002.zip", file1.getName()); | ||
assertEquals("fake file content 1", new String(file1.getData(), UTF_8)); | ||
|
||
TransferableFile file2 = acquisitionServer.getFile("20200817T1705Z__RTEFRANCE-FR_EQ_002.zip", acquisitionServerUrl + "/cases/20200817T1705Z__RTEFRANCE-FR_EQ_002.zip"); | ||
assertTrue(CgmesUtils.isValidProfileFileName(file2.getName(), authorizedSourcingActors, authorizedBusinessProcesses)); | ||
assertEquals("20200817T1705Z__RTEFRANCE-FR_EQ_002.zip", file2.getName()); | ||
assertEquals("fake file content 2", new String(file2.getData(), UTF_8)); | ||
} | ||
}); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/test/java/org/gridsuite/cgmes/assembling/job/CgmesAssemblingLoggerTest.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,41 @@ | ||
package org.gridsuite.cgmes.assembling.job; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.jdbc.JdbcTest; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
|
||
import javax.sql.DataSource; | ||
import java.util.Arrays; | ||
import java.util.Date; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
@JdbcTest | ||
class CgmesAssemblingLoggerTest { | ||
@Autowired private DataSource dataSource; | ||
@MockBean private ProfilesAcquisitionJob runner; //we don't want the runner to run during tests | ||
|
||
@Test | ||
void historyLoggerTest() { | ||
try (final CgmesAssemblingLogger cgmesAssemblingLogger = new CgmesAssemblingLogger(dataSource)) { | ||
assertFalse(cgmesAssemblingLogger.isHandledFile("testFile.iidm", "my_sftp_server")); | ||
cgmesAssemblingLogger.logFileAvailable("testFile.iidm", "uuid", "my_sftp_server", new Date()); | ||
assertEquals("testFile.iidm", cgmesAssemblingLogger.getFileNameByUuid("uuid", "my_sftp_server")); | ||
assertEquals("uuid", cgmesAssemblingLogger.getUuidByFileName("testFile.iidm", "my_sftp_server")); | ||
assertTrue(cgmesAssemblingLogger.isHandledFile("testFile.iidm", "my_sftp_server")); | ||
|
||
cgmesAssemblingLogger.logFileDependencies("uuid", Arrays.asList("uuid1", "uuid2")); | ||
assertEquals(2, cgmesAssemblingLogger.getDependencies("uuid").size(), 2); | ||
} | ||
} | ||
|
||
@Test | ||
void testLogDependencies() { | ||
assertThrows(RuntimeException.class, () -> { | ||
try (final CgmesAssemblingLogger cgmesAssemblingLogger = new CgmesAssemblingLogger(dataSource)) { | ||
cgmesAssemblingLogger.logFileDependencies("uuid", null); | ||
} | ||
}); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/test/java/org/gridsuite/cgmes/assembling/job/CgmesUtilsTest.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,23 @@ | ||
package org.gridsuite.cgmes.assembling.job; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Set; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
|
||
class CgmesUtilsTest { | ||
@Test | ||
void testGetValidProfileFileName() { | ||
final Set<String> authorizedSourcingActors = Set.of("XX"); | ||
final Set<String> authorizedBusinessProcesses = Set.of("1D"); | ||
|
||
assertEquals("SSH", CgmesUtils.getValidProfileFileName("20191106T0930Z_1D_XX_SSH_001.zip", authorizedSourcingActors, authorizedBusinessProcesses)); | ||
assertNull(CgmesUtils.getValidProfileFileName("20191106T0930Z_1D_XX_SSH_1002.zip", authorizedSourcingActors, authorizedBusinessProcesses)); | ||
assertNull(CgmesUtils.getValidProfileFileName("20191106T0930Z_1D_YY_SSH_001.zip", authorizedSourcingActors, authorizedBusinessProcesses)); | ||
assertNull(CgmesUtils.getValidProfileFileName("20191106T0930Z_6D_XX_SSH_001.zip", authorizedSourcingActors, authorizedBusinessProcesses)); | ||
assertNull(CgmesUtils.getValidProfileFileName("20191106T0930Z_1D_XX_SSH_001.xml", authorizedSourcingActors, authorizedBusinessProcesses)); | ||
assertNull(CgmesUtils.getValidProfileFileName("20191106T0930Z_1D_XX_SSH_abc.zip", authorizedSourcingActors, authorizedBusinessProcesses)); | ||
} | ||
} |
Oops, something went wrong.