Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
openbis
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
sispub
openbis
Commits
d7a00ffc
Commit
d7a00ffc
authored
13 years ago
by
kaloyane
Browse files
Options
Downloads
Patches
Plain Diff
LMS-2257: FTP server does not close IHierarchicalContent handles (forgotten test)
SVN: 21505
parent
45b3d627
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/dss/generic/server/ftp/resolver/TemplateBasedDataSetResourceResolverTest.java
+92
-3
92 additions, 3 deletions
...tp/resolver/TemplateBasedDataSetResourceResolverTest.java
with
92 additions
and
3 deletions
datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/dss/generic/server/ftp/resolver/TemplateBasedDataSetResourceResolverTest.java
+
92
−
3
View file @
d7a00ffc
...
@@ -16,6 +16,9 @@
...
@@ -16,6 +16,9 @@
package
ch.systemsx.cisd.openbis.dss.generic.server.ftp.resolver
;
package
ch.systemsx.cisd.openbis.dss.generic.server.ftp.resolver
;
import
java.io.ByteArrayInputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.Method
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Arrays
;
...
@@ -146,8 +149,15 @@ public class TemplateBasedDataSetResourceResolverTest extends AssertJUnit
...
@@ -146,8 +149,15 @@ public class TemplateBasedDataSetResourceResolverTest extends AssertJUnit
IHierarchicalContent
content
=
getHierarchicalContentMock
(
dataSetCode
);
IHierarchicalContent
content
=
getHierarchicalContentMock
(
dataSetCode
);
IHierarchicalContentNode
rootNode
=
getHierarchicalRootNodeMock
(
dataSetCode
);
IHierarchicalContentNode
rootNode
=
getHierarchicalRootNodeMock
(
dataSetCode
);
allowing
(
content
).
getNode
(
StringUtils
.
EMPTY
);
one
(
content
).
getNode
(
StringUtils
.
EMPTY
);
will
(
returnValue
(
rootNode
));
will
(
returnValue
(
rootNode
));
exactly
(
2
).
of
(
rootNode
).
isDirectory
();
will
(
returnValue
(
true
));
one
(
rootNode
).
getFile
();
will
(
throwException
(
new
UnsupportedOperationException
()));
}
}
});
});
...
@@ -186,8 +196,77 @@ public class TemplateBasedDataSetResourceResolverTest extends AssertJUnit
...
@@ -186,8 +196,77 @@ public class TemplateBasedDataSetResourceResolverTest extends AssertJUnit
allowing
(
content
).
getNode
(
subPath
);
allowing
(
content
).
getNode
(
subPath
);
will
(
returnValue
(
mockNode
));
will
(
returnValue
(
mockNode
));
one
(
mockNode
).
isDirectory
();
one
(
mockNode
).
getRelativePath
();
will
(
returnValue
(
subPath
));
exactly
(
2
).
of
(
mockNode
).
isDirectory
();
will
(
returnValue
(
false
));
one
(
mockNode
).
getFileLength
();
will
(
returnValue
(
2L
));
one
(
mockNode
).
getFile
();
will
(
returnValue
(
null
));
}
});
FtpFile
ftpFile
=
resolver
.
resolve
(
path
,
resolverContext
);
assertNotNull
(
ftpFile
);
assertEquals
(
"fileName.txt"
,
ftpFile
.
getName
());
assertTrue
(
ftpFile
.
isFile
());
}
@Test
public
void
testHierarchicalContentClosed
()
throws
IOException
{
FtpServerConfig
config
=
new
FtpServerConfigBuilder
().
withTemplate
(
SIMPLE_TEMPLATE
).
getConfig
();
resolver
=
new
TemplateBasedDataSetResourceResolver
(
config
);
final
String
dataSetCode
=
"dataSetCode"
;
final
String
subPath
=
"fileName.txt"
;
String
path
=
EXP_ID
+
FtpConstants
.
FILE_SEPARATOR
+
dataSetCode
+
FtpConstants
.
FILE_SEPARATOR
+
subPath
;
List
<
ExternalData
>
dataSets
=
Arrays
.
asList
(
createDataSet
(
dataSetCode
,
DS_TYPE1
));
prepareExperimentListExpectations
(
dataSets
);
context
.
checking
(
new
Expectations
()
{
{
IHierarchicalContent
content
=
getHierarchicalContentMock
(
dataSetCode
);
one
(
hierarchicalContentProvider
).
asContent
(
dataSetCode
);
will
(
returnValue
(
content
));
one
(
content
).
close
();
IHierarchicalContentNode
mockNode
=
context
.
mock
(
IHierarchicalContentNode
.
class
);
ByteArrayInputStream
is
=
new
ByteArrayInputStream
(
new
byte
[]
{});
allowing
(
content
).
getNode
(
subPath
);
will
(
returnValue
(
mockNode
));
one
(
mockNode
).
getRelativePath
();
will
(
returnValue
(
subPath
));
exactly
(
2
).
of
(
mockNode
).
isDirectory
();
will
(
returnValue
(
false
));
will
(
returnValue
(
false
));
one
(
mockNode
).
getFileLength
();
will
(
returnValue
(
2L
));
one
(
mockNode
).
getFile
();
will
(
returnValue
(
null
));
one
(
mockNode
).
getInputStream
();
will
(
returnValue
(
is
));
}
}
});
});
...
@@ -196,6 +275,9 @@ public class TemplateBasedDataSetResourceResolverTest extends AssertJUnit
...
@@ -196,6 +275,9 @@ public class TemplateBasedDataSetResourceResolverTest extends AssertJUnit
assertNotNull
(
ftpFile
);
assertNotNull
(
ftpFile
);
assertEquals
(
"fileName.txt"
,
ftpFile
.
getName
());
assertEquals
(
"fileName.txt"
,
ftpFile
.
getName
());
assertTrue
(
ftpFile
.
isFile
());
assertTrue
(
ftpFile
.
isFile
());
InputStream
fileContent
=
ftpFile
.
createInputStream
(
0
);
// this call will also close the IHierarchicalContent
fileContent
.
close
();
}
}
@Test
@Test
...
@@ -269,8 +351,9 @@ public class TemplateBasedDataSetResourceResolverTest extends AssertJUnit
...
@@ -269,8 +351,9 @@ public class TemplateBasedDataSetResourceResolverTest extends AssertJUnit
String
mockName
=
getHierarchicalContentMockName
(
dataSet
.
getCode
());
String
mockName
=
getHierarchicalContentMockName
(
dataSet
.
getCode
());
IHierarchicalContent
content
=
IHierarchicalContent
content
=
context
.
mock
(
IHierarchicalContent
.
class
,
mockName
);
context
.
mock
(
IHierarchicalContent
.
class
,
mockName
);
allowing
(
hierarchicalContentProvider
).
asContent
(
dataSet
.
getCode
());
one
(
hierarchicalContentProvider
).
asContent
(
dataSet
.
getCode
());
will
(
returnValue
(
content
));
will
(
returnValue
(
content
));
one
(
content
).
close
();
String
rootMockName
=
getRootNodeMockName
(
dataSet
.
getCode
());
String
rootMockName
=
getRootNodeMockName
(
dataSet
.
getCode
());
IHierarchicalContentNode
rootNode
=
IHierarchicalContentNode
rootNode
=
...
@@ -338,6 +421,12 @@ public class TemplateBasedDataSetResourceResolverTest extends AssertJUnit
...
@@ -338,6 +421,12 @@ public class TemplateBasedDataSetResourceResolverTest extends AssertJUnit
context
.
mock
(
IHierarchicalContentNode
.
class
,
fileName
);
context
.
mock
(
IHierarchicalContentNode
.
class
,
fileName
);
result
.
add
(
mockNode
);
result
.
add
(
mockNode
);
allowing
(
mockNode
).
getFileLength
();
will
(
returnValue
(
10L
));
allowing
(
mockNode
).
getFile
();
will
(
throwException
(
new
UnsupportedOperationException
()));
allowing
(
mockNode
).
getName
();
allowing
(
mockNode
).
getName
();
will
(
returnValue
(
fileName
));
will
(
returnValue
(
fileName
));
...
...
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