114 lines
4.8 KiB
Java
114 lines
4.8 KiB
Java
package org.gcube.application.geoportal.service.engine.mongo;
|
|
|
|
import org.bson.Document;
|
|
import org.gcube.application.cms.plugins.faults.EventException;
|
|
import org.gcube.application.cms.plugins.faults.StepException;
|
|
import org.gcube.application.cms.tests.TokenSetter;
|
|
import org.gcube.application.cms.tests.model.concessioni.TestConcessioniModel;
|
|
import org.gcube.application.geoportal.common.faults.StorageException;
|
|
import org.gcube.application.geoportal.common.model.document.Lock;
|
|
import org.gcube.application.geoportal.common.model.document.Project;
|
|
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
|
|
import org.gcube.application.geoportal.common.model.rest.RegisterFileSetRequest;
|
|
import org.gcube.application.geoportal.common.model.useCaseDescriptor.Field;
|
|
import org.gcube.application.geoportal.common.utils.FileSets;
|
|
import org.gcube.application.geoportal.common.utils.StorageUtils;
|
|
import org.gcube.application.geoportal.common.utils.tests.GCubeTest;
|
|
import org.gcube.application.geoportal.service.BasicServiceTestUnit;
|
|
import org.gcube.application.geoportal.service.model.internal.faults.*;
|
|
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
|
import org.geotoolkit.referencing.operation.provider.PolarStereographic;
|
|
import org.junit.Before;
|
|
import org.junit.Test;
|
|
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
|
|
import static junit.framework.TestCase.*;
|
|
import static org.junit.Assume.assumeTrue;
|
|
|
|
public class LockTests extends BasicServiceTestUnit {
|
|
|
|
String profileID = "profiledConcessioni";
|
|
ProfiledMongoManager manager= null;
|
|
|
|
@Before
|
|
public void inits() throws RegistrationException, ConfigurationException {
|
|
assumeTrue(GCubeTest.isTestInfrastructureEnabled());
|
|
TokenSetter.set(GCubeTest.getContext());
|
|
manager = new ProfiledMongoManager(profileID);
|
|
}
|
|
|
|
@Test
|
|
public void testLocking() throws StepException, EventException, IOException, ProjectLockedException, ProjectNotFoundException, InvalidLockException {
|
|
assumeTrue(GCubeTest.isTestInfrastructureEnabled());
|
|
Project p = manager.registerNew(new Document("dummyField","dummyValue"));
|
|
// lock
|
|
p= manager.lock(p.getId(),"Testing");
|
|
|
|
assertNotNull(p.getLock());
|
|
assertNotNull(p.getLock().getId());
|
|
assertNotNull(p.getLock().getInfo());
|
|
assertTrue(p.getLock().getOperation().equals("Testing"));
|
|
|
|
try{
|
|
Lock l =p.getLock();
|
|
System.out.println("Lock is "+l);
|
|
p = manager.lock(p.getId(),"Should Fail");
|
|
fail("Expected Lock exception. New Lock is "+p.getLock());
|
|
}catch(ProjectLockedException e){
|
|
// expected lock exception
|
|
System.out.println("Successfully blocked invalid lock operation");
|
|
}
|
|
|
|
try{
|
|
Lock l =p.getLock();
|
|
System.out.println("Lock is "+l);
|
|
manager.update(p.getId(),new Document("should","fail"));
|
|
fail("Expected Lock exception. New Lock is "+p.getLock());
|
|
}catch (ProjectLockedException e){
|
|
// expected lock exception
|
|
System.out.println("Successfully blocked invalid edit operation");
|
|
}
|
|
|
|
manager.unlockAndUpdate(p);
|
|
|
|
manager.update(p.getId(),new Document("should","fail"));
|
|
}
|
|
|
|
@Test
|
|
public void testUnlock() throws StepException, EventException, IOException, ProjectNotFoundException, ProjectLockedException, InvalidLockException, DeletionException, ConfigurationException, StorageHubException, StorageException {
|
|
assumeTrue(GCubeTest.isTestInfrastructureEnabled());
|
|
MongoManagerI<Project> managerInterface = manager;
|
|
// create
|
|
Project p = managerInterface.registerNew(new Document("dummyField","dummyValue"));
|
|
checkIsLockCleaned(p.getId());
|
|
|
|
// edit
|
|
p=managerInterface.update(p.getId(),new Document("some","field"));
|
|
checkIsLockCleaned(p.getId());
|
|
|
|
// register fileset
|
|
FileSets.RequestBuilder builder = FileSets.build(
|
|
"$.relazioneScavo","fileset","relazioneScavo."+ Field.CHILDREN+"[?(@.fileset)]");
|
|
StorageUtils s= new StorageUtils();
|
|
builder.add(
|
|
s.putOntoStorage(new File(TestConcessioniModel.getBaseFolder(),"pos.shp"),"pos.shp"));
|
|
|
|
p= managerInterface.registerFileSet(p.getId(),builder.getTheRequest());
|
|
checkIsLockCleaned(p.getId());
|
|
|
|
// delete fileset
|
|
p=managerInterface.deleteFileSet(p.getId(),"$.relazioneScavo.fileset",false);
|
|
checkIsLockCleaned(p.getId());
|
|
|
|
// perform step
|
|
p=managerInterface.performStep(p.getId(),"SUBMIT DRAFT",new Document());
|
|
checkIsLockCleaned(p.getId());
|
|
}
|
|
|
|
private void checkIsLockCleaned(String id) throws ProjectNotFoundException {
|
|
assertNull(manager.getByID(id).getLock());
|
|
}
|
|
}
|