All Downloads are FREE. Search and download functionalities are using the official Maven repository.

test.junit.fedora.server.resourceIndex.ResourceIndexModMiscIntegrationTest Maven / Gradle / Ivy

Go to download

The Fedora Client is a Java Library that allows API access to a Fedora Repository. The client is typically one part of a full Fedora installation.

The newest version!
package fedora.server.resourceIndex;

import java.util.HashSet;
import java.util.Set;

import org.jrdf.graph.Triple;

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

import fedora.server.storage.types.DigitalObject;

/**
 * Miscellaneous tests of modifying existing objects in the RI.
 *
 * Note: All tests run at RI level 1 unless otherwise noted.
 *
 * @author [email protected]
 */
public class ResourceIndexModMiscIntegrationTest
        extends ResourceIndexIntegrationTest {

    /**
     * Modify an object's label with the RI at level 0.
     */
    @Test
    public void testModObjOnceLabelLv0()
            throws Exception {
        Set objects = getTestObjects(1, 0);

        // add at level 1
        initRI(1);
        addAll(objects, true);
        Set origTriples = getExpectedTriples(1, objects);

        // mod at level 0
        DigitalObject original = (DigitalObject) objects.toArray()[0];
        DigitalObject modified = deepCopy(original);
        modified.setLabel("new label");
        initRI(0);
        modify(original, modified, true);

        assertTrue("Did not get expected orig triples after modify at level 0",
                   sameTriples(origTriples, getActualTriples(), true));
    }

    /**
     * Modify an object's label once.
     */
    @Test
    public void testModObjOnceLabel()
            throws Exception {
        DigitalObject original = getTestObject("test:1", "test1");

        DigitalObject modified = deepCopy(original);
        modified.setLabel("new label");

        doModifyTest(1, original, modified);
    }

    /**
     * Modify an object's label multiple times.
     */
    @Test
    public void testModObjMultiLabel()
            throws Exception {

        // prep by initting at lv 1 and adding original object
        initRI(1);
        DigitalObject previous = getTestObject("test:1", "test1");
        Set origSet = new HashSet();
        origSet.add(previous);
        addAll(origSet, true);

        // modify the label multiple times
        for (int i = 1; i <= 5; i++) {
            DigitalObject modified = deepCopy(previous);
            modified.setLabel("new label " + i);
            doModifyTest(-1, previous, modified);
            previous = modified;
        }

    }

    /**
     * Modify an object's label multiple times while flushing the buffer
     * many times from a separate thread.
     */
    @Test
    public void testModObjMultiLabelAsyncFlush()
            throws Exception {

        // prep by initting at lv 1 and adding original object
        initRI(1);
        DigitalObject original = getTestObject("test:1", "test1");
        DigitalObject previous = original;
        Set origSet = new HashSet();
        origSet.add(previous);
        addAll(origSet, true);

        // hold on to the original triples so we can compare later
        Set origTriples = getExpectedTriples(1, origSet);

        // modify the label multiple times while flushing
        startFlushing(0);
        try {
            for (int i = 0; i <= 5; i++) {
                DigitalObject modified = deepCopy(previous);
                modified.setLabel("new label " + i);
                modify(previous, modified, false);
                previous = modified;
            }
            // last change puts obj back into original state
            modify(previous, original, false);
        } finally {
            // this stops async flushing and flushes one last time
            finishFlushing();
        }

        assertTrue("Did not get expected orig triples after multi mod of "
                + "one object with async buffer flushing",
                sameTriples(origTriples, getActualTriples(), true));
    }

    // Supports legacy test runners
    public static junit.framework.Test suite() {
        return new junit.framework.JUnit4TestAdapter(
                ResourceIndexModMiscIntegrationTest.class);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy