Skip to content
Snippets Groups Projects
Commit dad2eae3 authored by felmer's avatar felmer
Browse files

LMS-1910 head-less system tests for attachment uploading

SVN: 19049
parent bcb0aa79
No related branches found
No related tags found
No related merge requests found
/*
* Copyright 2010 ETH Zuerich, CISD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.systemsx.cisd.openbis.systemtest;
import static org.testng.AssertJUnit.assertEquals;
import java.util.List;
import org.testng.annotations.Test;
import ch.systemsx.cisd.openbis.generic.client.web.client.dto.DefaultResultSetConfig;
import ch.systemsx.cisd.openbis.generic.client.web.client.dto.ResultSet;
import ch.systemsx.cisd.openbis.generic.client.web.client.dto.SessionContext;
import ch.systemsx.cisd.openbis.generic.shared.basic.TechId;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Attachment;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.AttachmentHolderKind;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.AttachmentVersions;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.AttachmentWithContent;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewAttachment;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Project;
/**
*
*
* @author Franz-Josef Elmer
*/
@Test(groups = "system test")
public class AttachmentUploadTest extends SystemTestCase
{
private static final String FILE_CONTENT = "hello world";
private static final String FILE_NAME = "hello.txt";
@Test
public void testUploadProjectAttachment()
{
SessionContext sessionContext = logIntoCommonClientService();
ResultSet<Project> projects =
commonClientService.listProjects(new DefaultResultSetConfig<String, Project>());
Project project = projects.getList().extractOriginalObjects().get(0);
TechId projectID = TechId.create(project);
uploadFile(FILE_NAME, FILE_CONTENT);
commonClientService.addAttachment(projectID, SESSION_KEY, AttachmentHolderKind.PROJECT,
new NewAttachment(FILE_NAME, "my file", "example file"));
AttachmentWithContent attachmentWithContent =
genericServer.getProjectFileAttachment(sessionContext.getSessionID(), projectID,
FILE_NAME, 1);
checkUploadedAttachment(projectID, AttachmentHolderKind.PROJECT, attachmentWithContent);
}
@Test
public void testUploadExperimentAttachment()
{
SessionContext sessionContext = logIntoCommonClientService();
TechId experimentID = new TechId(2);
uploadFile(FILE_NAME, FILE_CONTENT);
commonClientService.addAttachment(experimentID, SESSION_KEY, AttachmentHolderKind.EXPERIMENT,
new NewAttachment(FILE_NAME, "my file", "example file"));
AttachmentWithContent attachmentWithContent =
genericServer.getExperimentFileAttachment(sessionContext.getSessionID(), experimentID,
FILE_NAME, 1);
checkUploadedAttachment(experimentID, AttachmentHolderKind.EXPERIMENT, attachmentWithContent);
}
@Test
public void testUploadSampleAttachment()
{
SessionContext sessionContext = logIntoCommonClientService();
TechId sampleID = new TechId(1);
uploadFile(FILE_NAME, FILE_CONTENT);
commonClientService.addAttachment(sampleID, SESSION_KEY, AttachmentHolderKind.SAMPLE,
new NewAttachment(FILE_NAME, "my file", "example file"));
AttachmentWithContent attachmentWithContent =
genericServer.getSampleFileAttachment(sessionContext.getSessionID(), sampleID,
FILE_NAME, 1);
checkUploadedAttachment(sampleID, AttachmentHolderKind.SAMPLE, attachmentWithContent);
}
private void checkUploadedAttachment(TechId holderID, AttachmentHolderKind holderKind,
AttachmentWithContent attachmentWithContent)
{
ResultSet<AttachmentVersions> attachmentVersions =
commonClientService.listAttachmentVersions(holderID, holderKind,
new DefaultResultSetConfig<String, AttachmentVersions>());
List<Attachment> attachments =
attachmentVersions.getList().get(0).getOriginalObject().getVersions();
Attachment attachment = attachments.get(0);
assertEquals(FILE_NAME, attachment.getFileName());
assertEquals("my file", attachment.getTitle());
assertEquals("example file", attachment.getDescription());
assertEquals(1, attachment.getVersion());
assertEquals(FILE_CONTENT, new String(attachmentWithContent.getContent()));
}
}
...@@ -26,9 +26,7 @@ import java.util.HashSet; ...@@ -26,9 +26,7 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import javax.servlet.http.HttpSession;
import org.springframework.mock.web.MockMultipartFile;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import ch.systemsx.cisd.openbis.generic.client.web.client.dto.DisplayedOrSelectedIdHolderCriteria; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.DisplayedOrSelectedIdHolderCriteria;
...@@ -36,7 +34,6 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.dto.GridRowModels; ...@@ -36,7 +34,6 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.dto.GridRowModels;
import ch.systemsx.cisd.openbis.generic.client.web.client.dto.ListMaterialDisplayCriteria; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.ListMaterialDisplayCriteria;
import ch.systemsx.cisd.openbis.generic.client.web.client.dto.ResultSet; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.ResultSet;
import ch.systemsx.cisd.openbis.generic.client.web.client.exception.UserFailureException; import ch.systemsx.cisd.openbis.generic.client.web.client.exception.UserFailureException;
import ch.systemsx.cisd.openbis.generic.client.web.server.UploadedFilesBean;
import ch.systemsx.cisd.openbis.generic.shared.basic.GridRowModel; import ch.systemsx.cisd.openbis.generic.shared.basic.GridRowModel;
import ch.systemsx.cisd.openbis.generic.shared.basic.IEntityInformationHolderWithPermId; import ch.systemsx.cisd.openbis.generic.shared.basic.IEntityInformationHolderWithPermId;
import ch.systemsx.cisd.openbis.generic.shared.basic.TechId; import ch.systemsx.cisd.openbis.generic.shared.basic.TechId;
...@@ -54,7 +51,6 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.MaterialType; ...@@ -54,7 +51,6 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.MaterialType;
public class BatchMaterialRegistrationAndUpdate extends SystemTestCase public class BatchMaterialRegistrationAndUpdate extends SystemTestCase
{ {
private static final String MATERIAL_TYPE = "CONTROL"; private static final String MATERIAL_TYPE = "CONTROL";
private static final String SESSION_KEY = "session-key";
private static final Set<String> CODES = new HashSet<String>(Arrays.asList("C1", "C2")); private static final Set<String> CODES = new HashSet<String>(Arrays.asList("C1", "C2"));
@Test @Test
...@@ -175,7 +171,7 @@ public class BatchMaterialRegistrationAndUpdate extends SystemTestCase ...@@ -175,7 +171,7 @@ public class BatchMaterialRegistrationAndUpdate extends SystemTestCase
private List<BatchRegistrationResult> registerMaterials(String materialBatchData) private List<BatchRegistrationResult> registerMaterials(String materialBatchData)
{ {
uploadFile(materialBatchData); uploadFile("my-file", materialBatchData);
MaterialType materialType = new MaterialType(); MaterialType materialType = new MaterialType();
materialType.setCode(MATERIAL_TYPE); materialType.setCode(MATERIAL_TYPE);
return genericClientService.registerMaterials(materialType, SESSION_KEY); return genericClientService.registerMaterials(materialType, SESSION_KEY);
...@@ -183,17 +179,9 @@ public class BatchMaterialRegistrationAndUpdate extends SystemTestCase ...@@ -183,17 +179,9 @@ public class BatchMaterialRegistrationAndUpdate extends SystemTestCase
private List<BatchRegistrationResult> updateMaterials(String materialBatchData, boolean ignoreUnregistered) private List<BatchRegistrationResult> updateMaterials(String materialBatchData, boolean ignoreUnregistered)
{ {
uploadFile(materialBatchData); uploadFile("my-file", materialBatchData);
MaterialType materialType = new MaterialType(); MaterialType materialType = new MaterialType();
materialType.setCode(MATERIAL_TYPE); materialType.setCode(MATERIAL_TYPE);
return genericClientService.updateMaterials(materialType, SESSION_KEY, ignoreUnregistered); return genericClientService.updateMaterials(materialType, SESSION_KEY, ignoreUnregistered);
} }
private void uploadFile(String fileContent)
{
UploadedFilesBean bean = new UploadedFilesBean();
bean.addMultipartFile(new MockMultipartFile("my-file", fileContent.getBytes()));
HttpSession session = request.getSession();
session.setAttribute(SESSION_KEY, bean);
}
} }
...@@ -16,8 +16,11 @@ ...@@ -16,8 +16,11 @@
package ch.systemsx.cisd.openbis.systemtest; package ch.systemsx.cisd.openbis.systemtest;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests; import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.AssertJUnit; import org.testng.AssertJUnit;
...@@ -26,10 +29,12 @@ import org.testng.annotations.BeforeSuite; ...@@ -26,10 +29,12 @@ import org.testng.annotations.BeforeSuite;
import ch.systemsx.cisd.common.servlet.SpringRequestContextProvider; import ch.systemsx.cisd.common.servlet.SpringRequestContextProvider;
import ch.systemsx.cisd.openbis.generic.client.web.client.ICommonClientService; import ch.systemsx.cisd.openbis.generic.client.web.client.ICommonClientService;
import ch.systemsx.cisd.openbis.generic.client.web.client.dto.SessionContext; import ch.systemsx.cisd.openbis.generic.client.web.client.dto.SessionContext;
import ch.systemsx.cisd.openbis.generic.client.web.server.UploadedFilesBean;
import ch.systemsx.cisd.openbis.generic.server.ICommonServerForInternalUse; import ch.systemsx.cisd.openbis.generic.server.ICommonServerForInternalUse;
import ch.systemsx.cisd.openbis.generic.server.util.TestInitializer; import ch.systemsx.cisd.openbis.generic.server.util.TestInitializer;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DisplaySettings; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DisplaySettings;
import ch.systemsx.cisd.openbis.plugin.generic.client.web.client.IGenericClientService; import ch.systemsx.cisd.openbis.plugin.generic.client.web.client.IGenericClientService;
import ch.systemsx.cisd.openbis.plugin.generic.shared.IGenericServer;
/** /**
* @author Franz-Josef Elmer * @author Franz-Josef Elmer
...@@ -37,8 +42,12 @@ import ch.systemsx.cisd.openbis.plugin.generic.client.web.client.IGenericClientS ...@@ -37,8 +42,12 @@ import ch.systemsx.cisd.openbis.plugin.generic.client.web.client.IGenericClientS
@ContextConfiguration(locations = "classpath:applicationContext.xml") @ContextConfiguration(locations = "classpath:applicationContext.xml")
public abstract class SystemTestCase extends AbstractTestNGSpringContextTests public abstract class SystemTestCase extends AbstractTestNGSpringContextTests
{ {
protected static final String SESSION_KEY = "session-key";
protected ICommonServerForInternalUse commonServer; protected ICommonServerForInternalUse commonServer;
protected IGenericServer genericServer;
protected ICommonClientService commonClientService; protected ICommonClientService commonClientService;
protected IGenericClientService genericClientService; protected IGenericClientService genericClientService;
...@@ -73,6 +82,18 @@ public abstract class SystemTestCase extends AbstractTestNGSpringContextTests ...@@ -73,6 +82,18 @@ public abstract class SystemTestCase extends AbstractTestNGSpringContextTests
this.commonServer = commonServer; this.commonServer = commonServer;
} }
/**
* Sets <code>genericServer</code>.
* <p>
* Will be automatically dependency injected by type.
* </p>
*/
@Autowired
public final void setGenericServer(final IGenericServer genericServer)
{
this.genericServer = genericServer;
}
/** /**
* Sets <code>commonClientService</code>. * Sets <code>commonClientService</code>.
* <p> * <p>
...@@ -120,4 +141,12 @@ public abstract class SystemTestCase extends AbstractTestNGSpringContextTests ...@@ -120,4 +141,12 @@ public abstract class SystemTestCase extends AbstractTestNGSpringContextTests
} }
} }
protected void uploadFile(String fileName, String fileContent)
{
UploadedFilesBean bean = new UploadedFilesBean();
bean.addMultipartFile(new MockMultipartFile(fileName, fileName, null, fileContent.getBytes()));
HttpSession session = request.getSession();
session.setAttribute(SESSION_KEY, bean);
}
} }
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