Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
StoragePlugin4Rosetta
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Harbor Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Digital Preservation
StoragePlugin4Rosetta
Commits
a56aa48b
Commit
a56aa48b
authored
2 years ago
by
Andreas Romeyke
Browse files
Options
Downloads
Patches
Plain Diff
- added some tests
parent
b14ed74d
No related branches found
No related tags found
No related merge requests found
Pipeline
#3396
passed
2 years ago
Stage: build
Stage: test
Stage: packaging
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
java/org/slub/rosetta/dps/repository/plugin/storage/nfs/TestSLUBStoragePlugin.java
+100
-6
100 additions, 6 deletions
.../repository/plugin/storage/nfs/TestSLUBStoragePlugin.java
with
100 additions
and
6 deletions
java/org/slub/rosetta/dps/repository/plugin/storage/nfs/TestSLUBStoragePlugin.java
+
100
−
6
View file @
a56aa48b
package
org.slub.rosetta.dps.repository.plugin.storage.nfs
;
import
com.exlibris.core.sdk.storage.containers.StoredEntityMetaData
;
import
com.exlibris.digitool.common.dnx.DnxDocument
;
import
com.exlibris.digitool.common.dnx.DnxDocumentFactory
;
import
com.exlibris.digitool.common.storage.Fixity
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.junit.runners.JUnit4
;
import
java.io.ByteArrayInputStream
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
import
java.nio.charset.StandardCharsets
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
/**
* Tests for {@link org.slub.rosetta.dps.repository.plugin.storage.nfs.SLUBStoragePlugin}.
...
...
@@ -15,22 +31,98 @@ import static org.junit.Assert.assertEquals;
* @author andreas.romeyke@slub-dresden.de (Andreas Romeyke)
*/
@RunWith
(
JUnit4
.
class
)
public
class
TestSLUBStoragePlugin
{
@Test
public
void
getStreamDirectory
()
{
SLUBStoragePlugin
mock
=
new
SLUBStoragePlugin
();
private
static
SLUBStoragePlugin
mock
;
private
static
Path
testroot
;
@Before
public
void
setUp
()
throws
IOException
{
testroot
=
Files
.
createTempDirectory
(
"testslubstorage"
);
Files
.
createFile
(
Path
.
of
(
testroot
.
toAbsolutePath
().
toString
()
+
"/foo"
));
mock
=
new
SLUBStoragePlugin
();
HashMap
<
String
,
String
>
map
=
new
HashMap
<
String
,
String
>
();
map
.
put
(
"DIR_ROOT"
,
"./"
);
map
.
put
(
"DIR_ROOT"
,
testroot
.
toAbsolutePath
().
toString
()
);
map
.
put
(
"BLOCK_SIZE"
,
"8192"
);
map
.
put
(
"FILES_HANDLING_METHOD"
,
"move"
);
mock
.
setParameters
(
map
);
mock
.
init
(
map
);
// TODO:
}
// @Test
// public void getDirRoot() {
//SLUBStoragePlugin mock = new SLUBStoragePlugin();
//assertEquals(mock.getDirRoot());
// }
@Test
public
void
getStreamDirectory
()
{
File
calced_path
=
mock
.
getStreamDirectory
(
"foo"
,
"bar"
);
//System.out.println("getStreamDirectory:"+ calced_path.getName()+ "\n");
assertEquals
(
"getStreamDirectory test"
,
"bar"
,
calced_path
.
getName
());
}
@Test
public
void
checkFixity
()
{
List
<
Fixity
>
fixities
=
new
ArrayList
<>();
try
{
var
result
=
mock
.
checkFixity
(
fixities
,
"/tmp/foo"
);
assertTrue
(
"checkFixity"
,
result
);
}
catch
(
Exception
e
)
{
assertEquals
(
"checkFixity"
,
"foo"
,
e
);
}
}
@Test
public
void
getFullFilePath
()
{
assertEquals
(
"getFullFilePath"
,
testroot
.
toAbsolutePath
().
toString
()+
"/2022"
,
mock
.
getFullFilePath
(
"/2022"
));
}
@Test
public
void
retrieveEntity
()
{
try
{
InputStream
is
=
mock
.
retrieveEntity
(
"/foo"
);
assertTrue
(
"retrieveEntity"
,
true
);
}
catch
(
Exception
e
)
{
assertEquals
(
"retrieveEntity"
,
""
,
e
);
}
}
@Test
public
void
retrieveEntitybyRange
()
{
try
{
byte
[]
bytes
=
mock
.
retrieveEntityByRange
(
"/foo"
,
0
,
0
);
assertTrue
(
"retrieveEntitybyRange"
,
true
);
}
catch
(
java
.
io
.
EOFException
e
)
{
assertEquals
(
"retrieveEntitybyRange"
,
null
,
e
.
getMessage
());
}
catch
(
Exception
e
)
{
assertEquals
(
"retrieveEntitybyRange"
,
""
,
e
.
getMessage
());
}
}
@Test
public
void
storeEntity
()
throws
IOException
{
byte
[]
bytes
=
"teststring"
.
getBytes
(
StandardCharsets
.
UTF_8
);
InputStream
is
=
new
ByteArrayInputStream
(
bytes
);
StoredEntityMetaData
sem
=
new
StoredEntityMetaData
();
sem
.
setCurrentFilePath
(
"/bar"
);
sem
.
setIePid
(
null
);
File
file
=
new
File
(
"resources/iemets.xml"
);
InputStream
ioStream
=
new
FileInputStream
(
file
);
InputStreamReader
isr
=
new
InputStreamReader
(
ioStream
);
char
[]
charArray
=
new
char
[(
int
)
file
.
length
()];
isr
.
read
(
charArray
);
String
iemets
=
new
String
(
charArray
);
try
{
DnxDocument
dnx
=
DnxDocumentFactory
.
getInstance
().
createDnxDocument
(
false
);
dnx
.
setDocumentXml
(
iemets
);
sem
.
setIeDnx
(
dnx
);
sem
.
setEntityType
(
StoredEntityMetaData
.
EntityType
.
IE
);
mock
.
storeEntity
(
is
,
sem
);
}
catch
(
NoClassDefFoundError
e
)
{
/* FIXME: Test irgendwie den org/springframework/context/ApplicationContext verpassen... */
assertEquals
(
"storeEntity"
,
"org/springframework/context/ApplicationContext"
,
e
.
getMessage
());
}
catch
(
Exception
e
)
{
assertEquals
(
"storeEntity"
,
""
,
e
.
getMessage
());
}
}
/*
@Test
public void getStreamRelativePath() throws Exception {
...
...
@@ -59,4 +151,6 @@ public class TestSLUBStoragePlugin {
mock.getStreamRelativePath( storedEntityMetaData);
}
*/
}
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