Page tree
Skip to end of metadata
Go to start of metadata

We like tests. We use JUnit and Mockito. Tests over HTTP use Grizzly.

Ensuring that the quality of the code base is maintained (as it is extended, refactored, or otherwise modified) can be addressed through the extensive coverage of functionality by unit or integration testing.  One approach often undertaken within the domain of software development is that of test driven development, in which the appropriate testing suites outlining the behavior of some method are structured concurrently or before the method itself is actually implemented.  Adhering to this methodology is by no means mandatory, but it does often assist in ensuring that the code base is quality assured to a higher degree.

Writing tests

Unit Tests

Each module has unit tests in the src/test/java/org/fcrepo/ directory and integration tests in the src/test/java/org/fcrepo/integration/ directory.

The unit tests often use mock objects to create surrogates for the Modeshape and webapp machinery that much of the Fedora code interacts with.  Some good examples of mock object usage are in the fcrepo-http-api module (e.g., FedoraNodesTest.java) and in the fcrepo-jms-indexer-core module (e.g. IndexerGroupTest.java). By convention, unit test classes are named as: <FunctionalClass>Test.java

Examples

Not found

Could not read the file fcrepo-kernel/src/test/java/org/fcrepo/kernel/observer/FedoraEventTest.java

fcrepo-http-api/src/test/java/org/fcrepo/http/api/FedoraNodesTest.java
/*
 * Licensed to DuraSpace under one or more contributor license agreements.
 * See the NOTICE file distributed with this work for additional information
 * regarding copyright ownership.
 *
 * DuraSpace licenses this file to you 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 org.fcrepo.http.api;

import static javax.ws.rs.core.Response.Status.PRECONDITION_FAILED;
import static org.fcrepo.http.commons.test.util.TestHelpers.getUriInfoImpl;
import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.isA;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.springframework.test.util.ReflectionTestUtils.setField;

import java.net.URISyntaxException;
import java.util.function.Supplier;

import javax.jcr.ItemExistsException;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.Value;
import javax.jcr.ValueFactory;
import javax.jcr.Workspace;
import javax.jcr.nodetype.NodeType;
import javax.jcr.version.VersionManager;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.ClientErrorException;
import javax.ws.rs.ServerErrorException;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Request;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder;
import javax.ws.rs.core.UriInfo;
import javax.ws.rs.core.SecurityContext;

import org.fcrepo.http.commons.api.rdf.HttpResourceConverter;
import org.fcrepo.http.commons.session.HttpSession;
import org.fcrepo.kernel.api.FedoraSession;
import org.fcrepo.kernel.api.exception.RepositoryRuntimeException;
import org.fcrepo.kernel.api.models.FedoraResource;
import org.fcrepo.kernel.api.services.NodeService;
import org.fcrepo.kernel.api.services.ContainerService;
import org.fcrepo.kernel.api.services.VersionService;
import org.fcrepo.kernel.modeshape.FedoraSessionImpl;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

import org.apache.jena.rdf.model.Model;
import org.apache.jena.sparql.util.Context;


/**
 * <p>FedoraNodesTest class.</p>
 *
 * @author awoods
 */
@RunWith(MockitoJUnitRunner.class)
public class FedoraNodesTest {

    FedoraNodes testObj;

    FedoraSession testSession;

    HttpSession testHttpSession;

    @Mock
    private ContainerService mockObjects;

    @Mock
    private NodeService mockNodes;

    @Mock
    private VersionService mockVersions;

    @Mock
    private Node mockNode;

    @Mock
    private NodeType mockNodeType;

    @Mock
    private Request mockRequest;

    @Mock
    private FedoraResource mockResource;

    @Mock
    Session mockSession;

    @Mock
    private FedoraResource mockContainer;

    @Mock
    private Model mockModel;

    @Mock
    private Context mockContext;

    @Mock
    private HttpServletResponse mockResponse;

    @Mock
    private Supplier<String> mockPidMinter;

    private UriInfo mockUriInfo;

    @Mock
    private Value mockValue;

    @Mock
    private ValueFactory mockValueFactory;

    @Mock
    private SecurityContext mockSecurityContext;

    private String path = "/some/path";

    @Before
    public void setUp() throws Exception {
        testObj = new FedoraNodes(path);
        testSession = new FedoraSessionImpl(mockSession);
        testHttpSession = new HttpSession(testSession);

        setField(testObj, "request", mockRequest);
        setField(testObj, "servletResponse", mockResponse);
        setField(testObj, "uriInfo", mockUriInfo);
        setField(testObj, "nodeService", mockNodes);
        setField(testObj, "versionService", mockVersions);
        this.mockUriInfo = getUriInfoImpl();
        setField(testObj, "pidMinter", mockPidMinter);
        setField(testObj, "containerService", mockObjects);
        setField(testObj, "session", testHttpSession);
        setField(testObj, "securityContext", mockSecurityContext);
        final Workspace mockWorkspace = mock(Workspace.class);
        when(mockWorkspace.getName()).thenReturn("default");
        when(mockSession.getWorkspace()).thenReturn(mockWorkspace);
        final VersionManager mockVM = mock(VersionManager.class);
        when(mockWorkspace.getVersionManager()).thenReturn(mockVM);
        when(mockNode.getPath()).thenReturn(path);
        when(mockContainer.getPath()).thenReturn(path);
        when(mockContainer.getEtagValue()).thenReturn("XYZ");
        when(mockNodeType.getName()).thenReturn("nt:folder");
        when(mockNode.getPrimaryNodeType()).thenReturn(mockNodeType);
        when(mockSession.getNode(path)).thenReturn(mockNode);

        setField(testObj, "idTranslator", new HttpResourceConverter(testHttpSession,
                    UriBuilder.fromUri("http://localhost/fcrepo/{path: .*}")));
    }

    @Test
    public void testCopyObject() throws RepositoryException, URISyntaxException {

        final ValueFactory mockVF = mock(ValueFactory.class);
        when(mockSession.getValueFactory()).thenReturn(mockVF);
        when(mockNodes.exists(testSession, path)).thenReturn(true);
        when(mockContainer.getPath()).thenReturn(path);

        testObj.copyObject("http://localhost/fcrepo/bar");
        verify(mockNodes).copyObject(testSession, path, "/bar");
    }

    @Test(expected = ClientErrorException.class)
    public void testCopyMissingObject() throws RepositoryException, URISyntaxException {

        final ValueFactory mockVF = mock(ValueFactory.class);
        when(mockSession.getValueFactory()).thenReturn(mockVF);
        when(mockNodes.exists(testSession, path)).thenReturn(false);

        testObj.copyObject("http://localhost/fcrepo/bar");
    }

    @Test(expected = ServerErrorException.class)
    public void testCopyObjectWithBadDestination() throws RepositoryException, URISyntaxException {
        final ValueFactory mockVF = mock(ValueFactory.class);
        when(mockSession.getValueFactory()).thenReturn(mockVF);
        when(mockNodes.exists(testSession, path)).thenReturn(true);

        testObj.copyObject("http://somewhere/else/baz");

    }

    @Test(expected = WebApplicationException.class)
    public void testCopyObjectToExistingDestination() throws RepositoryException, URISyntaxException {
        final ValueFactory mockVF = mock(ValueFactory.class);
        when(mockSession.getValueFactory()).thenReturn(mockVF);
        when(mockNodes.exists(testSession, path)).thenReturn(true);
        doThrow(new RepositoryRuntimeException(new ItemExistsException()))
                .when(mockNodes).copyObject(testSession, path, "/baz");

        final Response response = testObj.copyObject("http://localhost/fcrepo/baz");

        assertEquals(PRECONDITION_FAILED.getStatusCode(), response.getStatus());
    }

    @Test
    public void testMoveObject() throws RepositoryException, URISyntaxException {
        final ValueFactory mockVF = mock(ValueFactory.class);
        when(mockNodes.find(isA(FedoraSession.class), isA(String.class)))
            .thenReturn(mockContainer);
        when(mockContainer.getEtagValue()).thenReturn("");
        when(mockContainer.getPath()).thenReturn(path);

        when(mockSession.getValueFactory()).thenReturn(mockVF);
        when(mockNodes.exists(testSession, path)).thenReturn(true);

        testObj.moveObject("http://localhost/fcrepo/bar");
        verify(mockNodes).moveObject(testSession, path, "/bar");
    }

    @Test(expected = ClientErrorException.class)
    public void testMoveMissingObject() throws RepositoryException, URISyntaxException {
        final ValueFactory mockVF = mock(ValueFactory.class);
        when(mockSession.getValueFactory()).thenReturn(mockVF);
        when(mockNodes.exists(testSession, path)).thenReturn(false);
        when(mockNodes.find(isA(FedoraSession.class), isA(String.class)))
            .thenReturn(mockContainer);
        when(mockContainer.getEtagValue()).thenReturn("");

        testObj.moveObject("http://localhost/fcrepo/bar");
    }

    @Test(expected = WebApplicationException.class)
    public void testMoveObjectToExistingDestination() throws RepositoryException, URISyntaxException {
        final ValueFactory mockVF = mock(ValueFactory.class);
        when(mockSession.getValueFactory()).thenReturn(mockVF);
        when(mockNodes.exists(testSession, path)).thenReturn(true);
        when(mockNodes.find(isA(FedoraSession.class), isA(String.class)))
            .thenReturn(mockContainer);
        when(mockContainer.getEtagValue()).thenReturn("");
        doThrow(new RepositoryRuntimeException(new ItemExistsException()))
                .when(mockNodes).moveObject(testSession, path, "/baz");

        final Response response = testObj.moveObject("http://localhost/fcrepo/baz");

        assertEquals(PRECONDITION_FAILED.getStatusCode(), response.getStatus());
    }

    @Test(expected = ServerErrorException.class)
    public void testMoveObjectWithBadDestination() throws RepositoryException, URISyntaxException {
        final ValueFactory mockVF = mock(ValueFactory.class);
        when(mockSession.getValueFactory()).thenReturn(mockVF);
        when(mockNodes.find(isA(FedoraSession.class), isA(String.class)))
            .thenReturn(mockContainer);
        when(mockNodes.exists(testSession, path)).thenReturn(true);
        when(mockContainer.getEtagValue()).thenReturn("");

        testObj.moveObject("http://somewhere/else/baz");
    }

}

 

Integration Tests

Integration tests use embedded Modeshape, servlet engine, etc. to run real requests against the code.  The web-based tests typically use HttpClient to make requests.  Non-web tests, use injection to have the repository and service objects made accessible to the tests (the embedded repository and injection are configured in the src/test/resources directory).  Some good examples are in the fcrepo-http-api module (e.g. FedoraNodesIT.java) and fcrepo-kernel module (e.g., FedoraResourceImplIT.java). By convention, integration test classes are named as: <FunctionalClass>IT.java

Examples

fcrepo-http-api/src/test/java/org/fcrepo/integration/http/api/FedoraNodesIT.java
/*
 * Licensed to DuraSpace under one or more contributor license agreements.
 * See the NOTICE file distributed with this work for additional information
 * regarding copyright ownership.
 *
 * DuraSpace licenses this file to you 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 org.fcrepo.integration.http.api;

import static javax.ws.rs.core.HttpHeaders.LINK;
import static javax.ws.rs.core.Response.Status.CONFLICT;
import static javax.ws.rs.core.Response.Status.CREATED;
import static javax.ws.rs.core.Response.Status.GONE;
import static javax.ws.rs.core.Response.Status.OK;
import static javax.ws.rs.core.Response.Status.PRECONDITION_FAILED;
import static org.apache.http.annotation.ThreadingBehavior.UNSAFE;
import static org.junit.Assert.assertEquals;
import java.io.IOException;
import java.net.URI;

import javax.ws.rs.core.Link;

import org.apache.http.annotation.Contract;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpRequestBase;
import org.junit.Test;

/**
 * <p>FedoraNodesIT class.</p>
 *
 * @author awoods
 * @author ajs6f
 */
public class FedoraNodesIT extends AbstractResourceIT {

    @Test
    public void testCopy() throws IOException {
        final String subject = serverAddress + getRandomUniqueId();
        final String location = getLocation(postObjMethod());
        final HttpCopy request = new HttpCopy(location);
        request.addHeader("Destination", subject);
        executeAndClose(request);
        assertEquals(OK.getStatusCode(), getStatus(new HttpGet(subject)));
        assertEquals(OK.getStatusCode(), getStatus(new HttpGet(location)));
    }

    @Test
    public void testCopyDestExists() throws IOException {
        final HttpCopy request = new HttpCopy(getLocation(postObjMethod()));
        request.addHeader("Destination", getLocation(postObjMethod()));
        assertEquals(PRECONDITION_FAILED.getStatusCode(), getStatus(request));
    }

    @Test
    public void testCopyInvalidDest() throws IOException {
        final String location1 = getLocation(postObjMethod());
        final HttpCopy request = new HttpCopy(location1);
        request.addHeader("Destination", serverAddress + "non/existent/path");
        assertEquals(CONFLICT.getStatusCode(), getStatus(request));
    }

    @Test
    public void testMoveAndTombstoneFromRoot() throws IOException {
        final String subject = serverAddress + getRandomUniqueId();
        final String location = serverAddress + getRandomUniqueId();
        createObjectAndClose(location.substring(serverAddress.length()));
        final HttpMove request = new HttpMove(location);
        request.addHeader("Destination", subject);
        executeAndClose(request);

        final HttpGet httpGet = new HttpGet(subject);
        assertEquals(OK.getStatusCode(), getStatus(httpGet));
        try (final CloseableHttpResponse originalResult = execute(new HttpGet(location))) {
            assertEquals(GONE.getStatusCode(), getStatus(originalResult));
            final Link tombstone = Link.valueOf(originalResult.getFirstHeader(LINK).getValue());
            assertEquals("hasTombstone", tombstone.getRel());
        }
    }

    @Test
    public void testMoveAndTombstone() throws IOException {
        final String id = getRandomUniqueId();
        final String location = getLocation(postObjMethod());

        final HttpMove request = new HttpMove(location);
        request.addHeader("Destination", serverAddress + id);
        executeAndClose(request);

        assertEquals(OK.getStatusCode(), getStatus(new HttpGet(serverAddress + id)));
        try (final CloseableHttpResponse originalResult = execute(new HttpGet(location))) {
            assertEquals(GONE.getStatusCode(), getStatus(originalResult));
            final Link tombstone = Link.valueOf(originalResult.getFirstHeader(LINK).getValue());
            assertEquals("hasTombstone", tombstone.getRel());
        }
    }

    @Test
    public void testMoveDestExists() throws IOException {
        final HttpMove request = new HttpMove(getLocation(postObjMethod()));
        request.addHeader("Destination", getLocation(postObjMethod()));
        assertEquals(PRECONDITION_FAILED.getStatusCode(), getStatus(request));
    }

    @Test
    public void testMoveInvalidDest() throws IOException {
        final HttpMove request = new HttpMove(getLocation(postObjMethod()));
        request.addHeader("Destination", serverAddress + "non/existent/destination");
        assertEquals(CONFLICT.getStatusCode(), getStatus(request));
    }

    @Test
    public void testMoveWithBadEtag() throws IOException {
        final HttpMove request = new HttpMove(getLocation(postObjMethod()));
        request.addHeader("Destination", serverAddress + getRandomUniqueId());
        request.addHeader("If-Match", "\"doesnt-match\"");
        assertEquals(PRECONDITION_FAILED.getStatusCode(), getStatus(request));
    }

    @Test
    public void testMoveBinary() throws IOException {
        final String id = getRandomUniqueId();
        final String oldLocation = getLocation(putDSMethod(id, "oldName", "test content"));
        final String newLocation = getLocation(postObjMethod()) + "/newName";

        final HttpMove request = new HttpMove(oldLocation);
        request.addHeader("Destination", newLocation);
        assertEquals(CREATED.getStatusCode(), getStatus(request));

        assertEquals(OK.getStatusCode(), getStatus(new HttpGet(newLocation)));
        assertEquals(GONE.getStatusCode(), getStatus(new HttpGet(oldLocation)));
    }

    @Test
    public void testRenameBinary() throws IOException {
        final String id = getRandomUniqueId();
        final String oldLocation = getLocation(putDSMethod(id, "oldName", "test content"));
        final String newLocation = oldLocation + "2";

        final HttpMove request = new HttpMove(oldLocation);
        request.addHeader("Destination", newLocation);
        assertEquals(CREATED.getStatusCode(), getStatus(request));

        assertEquals(OK.getStatusCode(), getStatus(new HttpGet(newLocation)));
        assertEquals(GONE.getStatusCode(), getStatus(new HttpGet(oldLocation)));
    }

    @Test
    public void testRenameContainer() throws IOException {
        final String oldLocation = getLocation(postObjMethod());
        final String newLocation = oldLocation + "2";

        final HttpMove request = new HttpMove(oldLocation);
        request.addHeader("Destination", newLocation);
        assertEquals(CREATED.getStatusCode(), getStatus(request));

        assertEquals(OK.getStatusCode(), getStatus(new HttpGet(newLocation)));
        assertEquals(GONE.getStatusCode(), getStatus(new HttpGet(oldLocation)));
    }

    @Contract(threading = UNSAFE) // HttpRequestBase is @NotThreadSafe
    private class HttpCopy extends HttpRequestBase {

        /**
         * @throws IllegalArgumentException if the uri is invalid.
         */
        public HttpCopy(final String uri) {
            super();
            setURI(URI.create(uri));
        }

        @Override
        public String getMethod() {
            return "COPY";
        }
    }

    @Contract(threading = UNSAFE) // HttpRequestBase is @NotThreadSafe
    private class HttpMove extends HttpRequestBase {

        /**
         * @throws IllegalArgumentException if the uri is invalid.
         */
        public HttpMove(final String uri) {
            super();
            setURI(URI.create(uri));
        }

        @Override
        public String getMethod() {
            return "MOVE";
        }
    }

}

fcrepo-auth-common/src/test/java/org/fcrepo/auth/integration/FedoraResponseCodesIT.java
/*
 * Licensed to DuraSpace under one or more contributor license agreements.
 * See the NOTICE file distributed with this work for additional information
 * regarding copyright ownership.
 *
 * DuraSpace licenses this file to you 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 org.fcrepo.auth.integration;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.util.EntityUtils;
import org.junit.Test;


/**
 * <p>FedoraResponseCodesIT class.</p>
 *
 * @author gregjan
 */
public class FedoraResponseCodesIT extends AbstractResourceIT {

    @Test
    public void testAllowedAddDatastream() throws Exception {
        final String pid = getRandomUniquePid() + "Permit";
        final HttpPut objMethod = putObjMethod(pid);
        assertEquals(201, getStatus(objMethod));

        final HttpPost method = postDSMethod(pid, "zxcpermit", "foo");
        final HttpResponse response = client.execute(method);
        final String location = response.getFirstHeader("Location").getValue();
        assertEquals(201, response.getStatusLine().getStatusCode());
        assertEquals("Got wrong URI in Location header for datastream creation!", serverAddress + pid +
                "/zxcpermit/jcr:content", location);
    }

    @Test
    public void testDeniedAddDatastream() throws Exception {
        final String pid = getRandomUniquePid() + "Permit";
        final HttpPut objMethod = putObjMethod(pid);

        assertEquals(201, getStatus(objMethod));

        final HttpPut obj2Method = putObjMethod(pid + "/FedoraDatastreamsTest2Deny");
        assertEquals(201, getStatus(obj2Method));

        final HttpPost method = postDSMethod(pid + "/FedoraDatastreamsTest2Deny", "zxc", "foo");
        final HttpResponse response = client.execute(method);
        assertEquals(403, response.getStatusLine().getStatusCode());
    }

    @Test
    public void testAllowedAddDeepDatastream() throws Exception {
        final String pid = getRandomUniquePid() + "Permit";
        final HttpPut method =
                putDSMethod(pid + "/does_permit/not_permit/exist_permit/yet_permit", "zxc_permit", "foo");

        final HttpResponse response = client.execute(method);
        final String location =
                response.getFirstHeader("Location").getValue();
        assertEquals(201, response.getStatusLine().getStatusCode());
        assertEquals("Got wrong URI in Location header for datastream creation!", serverAddress + pid +
                "/does_permit/not_permit/exist_permit/yet_permit/zxc_permit/jcr:content", location);
    }

    @Test
    public void testDeniedAddDeepDatastream() throws Exception {
        final String pid = getRandomUniquePid() + "Permit";
        final HttpPut method =
                putDSMethod(
                        pid + "/does_permit/not_permit/exist_permit/yet_permit/allowed_child",
                        "zxc", "foo");
        final HttpResponse response = client.execute(method);
        assertEquals(403, response.getStatusLine().getStatusCode());
    }

    @Test
    public void testAllowedPutDatastream() throws Exception {
        final String pid = getRandomUniquePid() + "Permit";
        final HttpPut objMethod = putObjMethod(pid);
        assertEquals(201, getStatus(objMethod));
        final HttpPut method = putDSMethod(pid, "zxc_permit", "foo");
        final HttpResponse response = client.execute(method);
        assertEquals(201, response.getStatusLine().getStatusCode());
    }

    @Test
    public void testDeniedPutDatastream() throws Exception {
        final String pid = getRandomUniquePid() + "Permit";

        final HttpPut objMethod = putObjMethod(pid + "/allowed_child");
        assertEquals(201, getStatus(objMethod));

        final HttpPut method = putDSMethod(pid + "/allowed_child", "zxc", "foo");
        final HttpResponse response = client.execute(method);
        assertEquals(403, response.getStatusLine().getStatusCode());
    }

    // @Test
    public void testGetDatastreamContent() throws Exception {
        final String pid = getRandomUniquePid() + "Permit";
        // TODO requires Grizzly client authN, see:
        // https://java.net/projects/jersey/sources/svn/content/trunk/jersey/samples/https-clientserver-grizzly/src
        // /main/java/com/sun/jersey/samples/https_grizzly/Server.java?rev=5853
        // https://java.net/projects/jersey/sources/svn/content/trunk/jersey/samples/https-clientserver-grizzly/src
        // /main/java/com/sun/jersey/samples/https_grizzly/auth/SecurityFilter.java?rev=5853

        final HttpPut objMethod =
            putObjMethod(pid);

        assertEquals(201, getStatus(objMethod));

        final HttpPost createDSMethod = postDSMethod(pid, "ds1", "marbles for everyone");
        assertEquals(201, getStatus(createDSMethod));

        final HttpGet method_test_get = new HttpGet(serverAddress + pid + "/ds1/jcr:content");
        assertEquals(200, getStatus(method_test_get));

        final HttpResponse response = client.execute(method_test_get);

        logger.debug("Returned from HTTP GET, now checking content...");
        assertTrue("Got the wrong content back!", "marbles for everyone"
                .equals(EntityUtils.toString(response.getEntity())));

        assertEquals("urn:sha1:ba6cb22191300aebcfcfb83de9635d6b224677df",
                response.getFirstHeader("ETag").getValue().replace("\"", ""));

        logger.debug("Content was correct.");
    }
}

 

Remember to follow the Code Style Guide when writing your test classes. This is especially true if writing a test class is your first foray into contributing to Fedora.

Running the tests

$ mvn test verify

 

See the fcrepo4 README file for more detailed instructions concerning Maven settings, etc., to build from source.

  • No labels