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

LMS-663 Simple regression tests for server interfaces added.

SVN: 9306
parent 88016a5b
No related branches found
No related tags found
No related merge requests found
Showing
with 535 additions and 0 deletions
/*
* Copyright 2008 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.generic.shared;
import java.util.List;
import org.springframework.transaction.annotation.Transactional;
import ch.systemsx.cisd.openbis.generic.shared.authorization.annotation.AuthorizationGuard;
import ch.systemsx.cisd.openbis.generic.shared.authorization.annotation.ReturnValueFilter;
import ch.systemsx.cisd.openbis.generic.shared.authorization.annotation.RoleSet;
import ch.systemsx.cisd.openbis.generic.shared.authorization.annotation.RolesAllowed;
import ch.systemsx.cisd.openbis.generic.shared.authorization.predicate.GroupIdentifierPredicate;
import ch.systemsx.cisd.openbis.generic.shared.authorization.validator.GroupValidator;
import ch.systemsx.cisd.openbis.generic.shared.authorization.validator.MatchingEntityValidator;
import ch.systemsx.cisd.openbis.generic.shared.authorization.validator.ProjectValidator;
import ch.systemsx.cisd.openbis.generic.shared.dto.ExperimentPE;
import ch.systemsx.cisd.openbis.generic.shared.dto.ExperimentTypePE;
import ch.systemsx.cisd.openbis.generic.shared.dto.ExternalDataPE;
import ch.systemsx.cisd.openbis.generic.shared.dto.GroupPE;
import ch.systemsx.cisd.openbis.generic.shared.dto.ListSampleCriteriaDTO;
import ch.systemsx.cisd.openbis.generic.shared.dto.PersonPE;
import ch.systemsx.cisd.openbis.generic.shared.dto.ProjectPE;
import ch.systemsx.cisd.openbis.generic.shared.dto.RoleAssignmentPE;
import ch.systemsx.cisd.openbis.generic.shared.dto.RoleCode;
import ch.systemsx.cisd.openbis.generic.shared.dto.SamplePE;
import ch.systemsx.cisd.openbis.generic.shared.dto.SampleTypePE;
import ch.systemsx.cisd.openbis.generic.shared.dto.SearchHit;
import ch.systemsx.cisd.openbis.generic.shared.dto.SearchableEntity;
import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.DatabaseInstanceIdentifier;
import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.GroupIdentifier;
import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.ProjectIdentifier;
import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleIdentifier;
/**
* Definition of the client-server interface.
*
* @author Franz-Josef Elmer
*/
public interface ICommonServer extends IServer
{
/**
* Returns all groups which belong to the specified database instance.
*/
@Transactional(readOnly = true)
@RolesAllowed(RoleSet.OBSERVER)
@ReturnValueFilter(validatorClass = GroupValidator.class)
public List<GroupPE> listGroups(String sessionToken, DatabaseInstanceIdentifier identifier);
/**
* Registers a new group with specified code and optional description and group leader ID.
*/
@Transactional
@RolesAllowed(RoleSet.INSTANCE_ADMIN)
public void registerGroup(String sessionToken, String groupCode, String descriptionOrNull,
String groupLeaderOrNull);
/**
* Returns all persons from current instance.
*/
@Transactional(readOnly = true)
@RolesAllowed(RoleSet.OBSERVER)
public List<PersonPE> listPersons(String sessionToken);
/**
* Returns all projects.
*/
@Transactional(readOnly = true)
@RolesAllowed(RoleSet.OBSERVER)
@ReturnValueFilter(validatorClass = ProjectValidator.class)
public List<ProjectPE> listProjects(String sessionToken);
/**
* Registers a new person.
*/
@Transactional
@RolesAllowed(RoleSet.INSTANCE_ADMIN)
public void registerPerson(String sessionToken, String userID);
/**
* Returns a list of all roles.
*/
@Transactional(readOnly = true)
@RolesAllowed(RoleSet.GROUP_ADMIN)
public List<RoleAssignmentPE> listRoles(String sessionToken);
/**
* Registers a new group role.
*/
@Transactional
@RolesAllowed(RoleSet.GROUP_ADMIN)
public void registerGroupRole(String sessionToken, RoleCode roleCode,
@AuthorizationGuard(guardClass = GroupIdentifierPredicate.class)
GroupIdentifier identifier, String person);
/**
* Registers a new instance role.
*/
@Transactional
@RolesAllowed(RoleSet.INSTANCE_ADMIN)
public void registerInstanceRole(String sessionToken, RoleCode roleCode, String person);
/**
* Deletes role described by given role code, group identifier and user id.
*/
@Transactional
@RolesAllowed(RoleSet.GROUP_ADMIN)
public void deleteGroupRole(String sessionToken, RoleCode roleCode,
@AuthorizationGuard(guardClass = GroupIdentifierPredicate.class)
GroupIdentifier groupIdentifier, String person);
/**
* Deletes role described by given role code and user id.
*/
@Transactional
@RolesAllowed(RoleSet.INSTANCE_ADMIN)
public void deleteInstanceRole(String sessionToken, RoleCode roleCode, String person);
/**
* Lists sample types which are appropriate for listing.
*/
@Transactional(readOnly = true)
@RolesAllowed(RoleSet.OBSERVER)
public List<SampleTypePE> listSampleTypes(String sessionToken);
/**
* Lists samples using given configuration.No properties are loaded.
*/
@Transactional(readOnly = true)
@RolesAllowed(RoleSet.OBSERVER)
public List<SamplePE> listSamples(final String sessionToken,
final ListSampleCriteriaDTO criteria);
/**
* Lists experiments.
*/
@Transactional(readOnly = true)
@RolesAllowed(RoleSet.OBSERVER)
public List<ExperimentPE> listExperiments(final String sessionToken,
ExperimentTypePE experimentType,
@AuthorizationGuard(guardClass = GroupIdentifierPredicate.class)
ProjectIdentifier project);
/**
* For given {@link SampleIdentifier} returns the corresponding list of {@link ExternalDataPE}.
*/
@Transactional(readOnly = true)
@RolesAllowed(RoleSet.OBSERVER)
public List<ExternalDataPE> listExternalData(final String sessionToken,
final SampleIdentifier identifier);
/**
* Performs an <i>Hibernate Search</i> based on given parameters.
*/
@Transactional(readOnly = true)
@RolesAllowed(RoleSet.OBSERVER)
@ReturnValueFilter(validatorClass = MatchingEntityValidator.class)
public List<SearchHit> listMatchingEntities(final String sessionToken,
final SearchableEntity[] searchableEntities, final String queryText);
/**
* List experiment types.
*/
@Transactional(readOnly = true)
@RolesAllowed(RoleSet.OBSERVER)
public List<ExperimentTypePE> listExperimentTypes(String sessionToken);
}
/*
* Copyright 2008 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.generic.shared;
/**
*
*
* @author Franz-Josef Elmer
*/
public interface INormalizer
{
public String normalize(String notNormalizedText);
}
/*
* Copyright 2008 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.generic.shared;
import java.io.File;
import org.testng.AssertJUnit;
import ch.systemsx.cisd.common.filesystem.FileUtilities;
/**
*
*
* @author Franz-Josef Elmer
*/
public class RegressionTestCase extends AssertJUnit
{
private static final File SOURCE_FOLDER = new File("source/java");
private static final File SOURCE_TEST_FOLDER = new File("sourceTest/java");
private static final class DefaultNormalizer implements INormalizer
{
static final INormalizer INSTANCE = new DefaultNormalizer();
public String normalize(String notNormalizedText)
{
return notNormalizedText;
}
}
protected void assertNormalizedSourceFilesAreEqual(Class<?> clazz)
{
assertNormalizedSourceFilesAreEqual(clazz, SOURCE_TEST_FOLDER, SOURCE_FOLDER,
DefaultNormalizer.INSTANCE);
}
protected void assertNormalizedSourceFilesAreEqual(Class<?> clazz, File rootFolderOfExpected,
File rootFolderOfActual)
{
assertNormalizedSourceFilesAreEqual(clazz, rootFolderOfExpected, rootFolderOfActual,
DefaultNormalizer.INSTANCE);
}
protected void assertNormalizedSourceFilesAreEqual(Class<?> clazz, File rootFolderOfExpected,
File rootFolderOfActual, INormalizer normalizer)
{
String fileName = clazz.getName().replace('.', '/') + ".java";
String expectedContent = readContent(normalizer, rootFolderOfExpected, fileName + ".expected");
String actualContent = readContent(normalizer, rootFolderOfActual, fileName);
assertEquals(expectedContent, actualContent);
}
private String readContent(INormalizer normalizer, File rootFolder, String fileName)
{
return normalizer.normalize(FileUtilities.loadToString(new File(rootFolder, fileName)));
}
}
/*
* Copyright 2008 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.generic.shared;
import org.testng.annotations.Test;
/**
*
*
* @author Franz-Josef Elmer
*/
public class ServerInterfaceRegressionTest extends RegressionTestCase
{
@Test
public void testICommonServer()
{
assertNormalizedSourceFilesAreEqual(ICommonServer.class);
}
}
/*
* Copyright 2008 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.plugin.generic.shared;
import java.util.List;
import org.springframework.transaction.annotation.Transactional;
import ch.systemsx.cisd.common.exceptions.UserFailureException;
import ch.systemsx.cisd.openbis.generic.client.web.client.dto.NewSample;
import ch.systemsx.cisd.openbis.generic.client.web.client.dto.SampleType;
import ch.systemsx.cisd.openbis.generic.shared.IServer;
import ch.systemsx.cisd.openbis.generic.shared.authorization.annotation.AuthorizationGuard;
import ch.systemsx.cisd.openbis.generic.shared.authorization.annotation.RoleSet;
import ch.systemsx.cisd.openbis.generic.shared.authorization.annotation.RolesAllowed;
import ch.systemsx.cisd.openbis.generic.shared.authorization.predicate.GroupIdentifierPredicate;
import ch.systemsx.cisd.openbis.generic.shared.authorization.predicate.NewSamplePredicate;
import ch.systemsx.cisd.openbis.generic.shared.dto.AttachmentPE;
import ch.systemsx.cisd.openbis.generic.shared.dto.ExperimentPE;
import ch.systemsx.cisd.openbis.generic.shared.dto.SampleGenerationDTO;
import ch.systemsx.cisd.openbis.generic.shared.dto.SamplePE;
import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.ExperimentIdentifier;
import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleIdentifier;
/**
* Definition of the client-server interface.
*
* @author Franz-Josef Elmer
*/
public interface IGenericServer extends IServer
{
/**
* For given {@link SampleIdentifier} returns the corresponding {@link SamplePE}.
*/
@Transactional(readOnly = true)
@RolesAllowed(RoleSet.OBSERVER)
public SampleGenerationDTO getSampleInfo(final String sessionToken,
final SampleIdentifier identifier);
/**
* Registers a new sample.
*/
@Transactional
@RolesAllowed(RoleSet.USER)
public void registerSample(final String sessionToken,
@AuthorizationGuard(guardClass = NewSamplePredicate.class)
final NewSample newSample);
/**
* For given {@link ExperimentIdentifier} returns the corresponding {@link ExperimentPE}.
*/
@Transactional(readOnly = true)
@RolesAllowed(RoleSet.OBSERVER)
public ExperimentPE getExperimentInfo(String sessionToken, ExperimentIdentifier identifier);
/**
* Returns attachment described by given experiment identifier, filename and version.
*/
@Transactional
@RolesAllowed(RoleSet.OBSERVER)
public AttachmentPE getExperimentFileAttachment(String sessionToken,
@AuthorizationGuard(guardClass = GroupIdentifierPredicate.class)
ExperimentIdentifier experimentIdentifier, String filename, int version)
throws UserFailureException;
/**
* Registers samples in batch.
*/
@Transactional
@RolesAllowed(RoleSet.USER)
public void registerSamples(final String sessionToken, SampleType sampleType,
@AuthorizationGuard(guardClass = NewSamplePredicate.class)
final List<NewSample> newSamples) throws UserFailureException;
}
/*
* Copyright 2008 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.plugin.generic.shared;
import org.testng.annotations.Test;
import ch.systemsx.cisd.openbis.generic.shared.RegressionTestCase;
/**
*
*
* @author Franz-Josef Elmer
*/
public class ServerInterfaceRegressionTest extends RegressionTestCase
{
@Test
public void testIGenericServer()
{
assertNormalizedSourceFilesAreEqual(IGenericServer.class);
}
}
/*
* Copyright 2008 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.plugin.screening.shared;
import org.springframework.transaction.annotation.Transactional;
import ch.systemsx.cisd.common.exceptions.UserFailureException;
import ch.systemsx.cisd.openbis.generic.client.web.client.dto.NewSample;
import ch.systemsx.cisd.openbis.generic.shared.IServer;
import ch.systemsx.cisd.openbis.generic.shared.authorization.annotation.AuthorizationGuard;
import ch.systemsx.cisd.openbis.generic.shared.authorization.annotation.RoleSet;
import ch.systemsx.cisd.openbis.generic.shared.authorization.annotation.RolesAllowed;
import ch.systemsx.cisd.openbis.generic.shared.authorization.predicate.SampleOwnerIdentifierPredicate;
import ch.systemsx.cisd.openbis.generic.shared.authorization.predicate.NewSamplePredicate;
import ch.systemsx.cisd.openbis.generic.shared.dto.SampleGenerationDTO;
import ch.systemsx.cisd.openbis.generic.shared.dto.SamplePE;
import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleIdentifier;
/**
* The <i>screening</i> server.
*
* @author Christian Ribeaud
*/
public interface IScreeningServer extends IServer
{
/**
* For given <var>sampleIdentifier</var> returns the {@link SamplePE} and its children.
*
* @return never <code>null</code>.
* @throws UserFailureException if given <var>sessionToken</var> is invalid or whether sample
* uniquely identified by given <var>sampleIdentifier</var> does not exist.
*/
@Transactional(readOnly = true)
@RolesAllowed(RoleSet.OBSERVER)
SampleGenerationDTO getSampleInfo(final String sessionToken,
@AuthorizationGuard(guardClass = SampleOwnerIdentifierPredicate.class)
final SampleIdentifier sampleIdentifier) throws UserFailureException;
/**
* Registers a new sample.
*/
@Transactional
@RolesAllowed(RoleSet.USER)
public void registerSample(final String sessionToken,
@AuthorizationGuard(guardClass = NewSamplePredicate.class)
final NewSample newSample);
}
/*
* Copyright 2008 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.plugin.screening.shared;
import org.testng.annotations.Test;
import ch.systemsx.cisd.openbis.generic.shared.RegressionTestCase;
/**
*
*
* @author Franz-Josef Elmer
*/
public class ServerInterfaceRegressionTest extends RegressionTestCase
{
@Test
public void testIGenericServer()
{
assertNormalizedSourceFilesAreEqual(IScreeningServer.class);
}
}
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