Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
DLCM-Backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
DLCM
Community
DLCM-Backend
Commits
0aa79c85
Commit
0aa79c85
authored
5 years ago
by
Jules Paget
Browse files
Options
Downloads
Patches
Plain Diff
Finshed test of siard service and clean code
parent
cd11d2a2
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!275
Draft: JPA Siard tool
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
DLCM-Tools/src/main/java/ch/dlcm/siard/SiardService.java
+6
-2
6 additions, 2 deletions
DLCM-Tools/src/main/java/ch/dlcm/siard/SiardService.java
DLCM-Tools/src/test/java/ch/dlcm/test/tools/SiardTest.java
+35
-24
35 additions, 24 deletions
DLCM-Tools/src/test/java/ch/dlcm/test/tools/SiardTest.java
with
41 additions
and
26 deletions
DLCM-Tools/src/main/java/ch/dlcm/siard/SiardService.java
+
6
−
2
View file @
0aa79c85
...
...
@@ -72,9 +72,13 @@ public class SiardService extends Tools implements CommandLineRunner {
"Alain Mast, Swiss Federal Archives, Berne, Switzerland"
,
"Krystyna Ohnesorge, Swiss Federal Archives, Berne, Switzerland"
})));
@Autowired
private
SiardConfig
siardConfig
;
@Autowired
public
SiardService
(
SiardConfig
siardConfig
)
{
this
.
siardConfig
=
siardConfig
;
}
@Override
public
void
run
(
String
...
args
)
throws
Exception
{
...
...
This diff is collapsed.
Click to expand it.
DLCM-Tools/src/test/java/ch/dlcm/test/tools/SiardTest.java
+
35
−
24
View file @
0aa79c85
package
ch.dlcm.test.tools
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
java.io.File
;
import
java.io.ObjectInputStream.GetField
;
import
java.nio.file.Path
;
import
java.nio.file.Paths
;
import
ch.admin.bar.siard2.*
;
import
ch.dlcm.siard.*
;
import
ch.dlcm.siard.config.SiardConfig
;
import
ch.unige.solidify.util.ZipTool
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.
springframework.boot.test.mock.
mockito.Mock
Bean
;
import
org.mockito.Mock
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
org.springframework.util.ResourceUtils
;
@RunWith
(
SpringRunner
.
class
)
public
class
SiardTest
{
/* TODO change dataBaseManagementSystem and databaseLocation depending on what DBMS you want to test
(cf Siard User usage manual) */
private
String
dataBaseManagementSystem
=
"access"
;
// e.g dbserver.enterag.ch for DB/2
private
Path
databaseLocation
=
Paths
.
get
(
"src"
,
"test"
,
"resources"
).
resolve
(
"databaseTest.accdb"
).
toAbsolutePath
();
// e.g 50000/testdb for DB/2
private
String
databaseUrl
;
private
String
workingDir
;
private
String
user
;
private
String
password
;
private
File
siardFile
;
private
File
expectedSiardFile
;
private
SiardService
siardService
;
@Mock
protected
SiardConfig
siardConfig
;
@Before
public
void
setup
()
{
databaseUrl
=
"dbtest.accdb"
;
workingDir
=
System
.
getProperty
(
"java.io.tmpdir"
);
databaseUrl
=
"jdbc:"
+
dataBaseManagementSystem
+
":"
+
databaseLocation
;
user
=
"user"
;
password
=
"passphrase"
;
siardFile
=
new
File
(
"siardTest.zip"
);
siardFile
=
new
File
(
"newSiardFile.zip"
);
expectedSiardFile
=
Paths
.
get
(
"src"
,
"test"
,
"resources"
).
resolve
(
"siard-file-test.zip"
).
toFile
();
siardService
=
new
SiardService
(
siardConfig
);
}
@MockBean
SiardService
siardService
;
@Test
public
void
siardFromDbTest
()
throws
Exception
{
//TODO an integration test ?
File
result
=
siardService
.
exportDatabase
(
siardFile
,
databaseUrl
,
password
,
user
);
File
expected
=
ResourceUtils
.
getFile
(
this
.
getClass
().
getResource
(
"siard-file-test.zip"
).
getFile
());
assertEquals
(
"database wrongly exported"
,
expected
,
result
);
@After
public
void
purge
()
{
siardFile
.
delete
();
}
@Test
public
void
zipToUploadValidationTest
()
throws
Exception
{
//TODO a unit test ? Must use Backend -> see with other
public
void
siardFromDbTest
()
throws
Exception
{
File
result
=
this
.
siardService
.
exportDatabase
(
siardFile
,
databaseUrl
,
password
,
user
);
ZipTool
resultZipTool
=
new
ZipTool
(
result
.
toURI
());
ZipTool
expectedZipTool
=
new
ZipTool
(
expectedSiardFile
.
toURI
());
assertTrue
(
resultZipTool
.
checkZip
());
assertEquals
(
expectedZipTool
.
getEntryNumber
(),
resultZipTool
.
getEntryNumber
());
// assertEquals("database wrongly exported", expectedZipTool, resultZipTool); // TODO find a new way of comparing zip archives
}
@Test
public
void
unzipSiardArchive
()
throws
Exception
{
//TODO a unit test
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment