Skip to content
Snippets Groups Projects
Commit d7a00ffc authored by kaloyane's avatar kaloyane
Browse files

LMS-2257: FTP server does not close IHierarchicalContent handles (forgotten test)

SVN: 21505
parent 45b3d627
No related branches found
No related tags found
No related merge requests found
...@@ -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));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment