Search in sources :

Example 1 with DataverseRequest

use of edu.harvard.iq.dataverse.engine.command.DataverseRequest in project dataverse by IQSS.

the class IpGroupTest method testContains.

/**
 * Test of contains method, of class IpGroup.
 */
@Test
public void testContains() {
    IpGroup sut = new IpGroup();
    sut.setId(MocksFactory.nextId());
    sut.setDescription("A's description");
    sut.setDisplayName("A");
    sut.setPersistedGroupAlias("&ip/a");
    final IpAddressRange allIPv4 = IpAddressRange.make(IpAddress.valueOf("0.0.0.0"), IpAddress.valueOf("255.255.255.255"));
    final IpAddressRange allIPv6 = IpAddressRange.make(IpAddress.valueOf("0:0:0:0:0:0:0:0"), IpAddress.valueOf("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"));
    sut.add(allIPv4);
    sut.add(allIPv6);
    assertTrue(sut.contains(new DataverseRequest(GuestUser.get(), IpAddress.valueOf("1.2.3.4"))));
    assertTrue(sut.contains(new DataverseRequest(GuestUser.get(), IpAddress.valueOf("11::fff"))));
    sut.remove(allIPv4);
    assertFalse(sut.contains(new DataverseRequest(GuestUser.get(), IpAddress.valueOf("1.2.3.4"))));
    sut.remove(allIPv6);
    assertFalse(sut.contains(new DataverseRequest(GuestUser.get(), IpAddress.valueOf("11::fff"))));
    sut.add(IpAddressRange.make(IpAddress.valueOf("0.0.0.0"), IpAddress.valueOf("168.0.0.0")));
    assertFalse(sut.contains(new DataverseRequest(GuestUser.get(), IpAddress.valueOf("169.0.0.0"))));
    assertTrue(sut.contains(new DataverseRequest(GuestUser.get(), IpAddress.valueOf("167.0.0.0"))));
}
Also used : DataverseRequest(edu.harvard.iq.dataverse.engine.command.DataverseRequest) IpAddressRange(edu.harvard.iq.dataverse.authorization.groups.impl.ipaddress.ip.IpAddressRange) Test(org.junit.Test)

Example 2 with DataverseRequest

use of edu.harvard.iq.dataverse.engine.command.DataverseRequest in project dataverse by IQSS.

the class MoveDatasetCommandTest method testValidMove.

/**
 * Moving ChildB to ChildA
 * @throws Exception - should not throw an exception
 */
@Test
public void testValidMove() throws Exception {
    DataverseRequest aRequest = new DataverseRequest(auth, httpRequest);
    testEngine.submit(new MoveDatasetCommand(aRequest, moved, childA, null));
    assertEquals(childA, moved.getOwner());
}
Also used : DataverseRequest(edu.harvard.iq.dataverse.engine.command.DataverseRequest) Test(org.junit.Test)

Example 3 with DataverseRequest

use of edu.harvard.iq.dataverse.engine.command.DataverseRequest in project dataverse by IQSS.

the class MoveDatasetCommandTest method testNotSuperUser.

/**
 * Moving DS Without Being Super User
 * Fails due to Permission Exception
 * @throws java.lang.Exception
 */
@Test(expected = PermissionException.class)
public void testNotSuperUser() throws Exception {
    DataverseRequest aRequest = new DataverseRequest(nobody, httpRequest);
    testEngine.submit(new MoveDatasetCommand(aRequest, moved, root, null));
    fail();
}
Also used : DataverseRequest(edu.harvard.iq.dataverse.engine.command.DataverseRequest) Test(org.junit.Test)

Example 4 with DataverseRequest

use of edu.harvard.iq.dataverse.engine.command.DataverseRequest in project dataverse by IQSS.

the class MoveDatasetCommandTest method testInvalidMove.

/**
 * Moving DS to its owning DV
 * @throws IllegalCommandException
 */
@Test(expected = IllegalCommandException.class)
public void testInvalidMove() throws Exception {
    DataverseRequest aRequest = new DataverseRequest(auth, httpRequest);
    testEngine.submit(new MoveDatasetCommand(aRequest, moved, root, false));
    fail();
}
Also used : DataverseRequest(edu.harvard.iq.dataverse.engine.command.DataverseRequest) Test(org.junit.Test)

Example 5 with DataverseRequest

use of edu.harvard.iq.dataverse.engine.command.DataverseRequest in project dataverse by IQSS.

the class RequestRsyncScriptCommandTest method testHappyPath.

@Test
public void testHappyPath() throws Exception {
    dataset = new Dataset();
    dataset.setIdentifier("42");
    HttpServletRequest aHttpServletRequest = null;
    DataverseRequest dataverseRequest = new DataverseRequest(MocksFactory.makeAuthenticatedUser("First", "Last"), aHttpServletRequest);
    ScriptRequestResponse scriptRequestResponse = testEngine.submit(new RequestRsyncScriptCommand(dataverseRequest, dataset));
    assertEquals("theScript", scriptRequestResponse.getScript());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) DataverseRequest(edu.harvard.iq.dataverse.engine.command.DataverseRequest) ScriptRequestResponse(edu.harvard.iq.dataverse.datacapturemodule.ScriptRequestResponse) Dataset(edu.harvard.iq.dataverse.Dataset) Test(org.junit.Test)

Aggregations

DataverseRequest (edu.harvard.iq.dataverse.engine.command.DataverseRequest)57 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)22 Dataverse (edu.harvard.iq.dataverse.Dataverse)21 Test (org.junit.Test)18 Dataset (edu.harvard.iq.dataverse.Dataset)15 Path (javax.ws.rs.Path)14 CommandException (edu.harvard.iq.dataverse.engine.command.exception.CommandException)13 SwordError (org.swordapp.server.SwordError)10 DatasetVersion (edu.harvard.iq.dataverse.DatasetVersion)7 HttpServletRequest (javax.servlet.http.HttpServletRequest)7 DataverseRole (edu.harvard.iq.dataverse.authorization.DataverseRole)6 IOException (java.io.IOException)6 POST (javax.ws.rs.POST)6 DataFile (edu.harvard.iq.dataverse.DataFile)5 User (edu.harvard.iq.dataverse.authorization.users.User)5 HarvestingClient (edu.harvard.iq.dataverse.harvest.client.HarvestingClient)5 JsonObject (javax.json.JsonObject)5 JsonObjectBuilder (javax.json.JsonObjectBuilder)5 DepositReceipt (org.swordapp.server.DepositReceipt)5 RoleAssignment (edu.harvard.iq.dataverse.RoleAssignment)4