Search in sources :

Example 76 with Dataverse

use of edu.harvard.iq.dataverse.Dataverse in project dataverse by IQSS.

the class JsonParserTest method testParseThemeDataverse.

@Test
public void testParseThemeDataverse() throws JsonParseException {
    JsonObject dvJson;
    try (InputStream jsonFile = ClassLoader.getSystemResourceAsStream("json/dataverse-theme.json")) {
        InputStreamReader reader = new InputStreamReader(jsonFile, "UTF-8");
        dvJson = Json.createReader(reader).readObject();
        Dataverse actual = sut.parseDataverse(dvJson);
        assertEquals("testDv", actual.getName());
        assertEquals("testAlias", actual.getAlias());
        assertEquals("Test-Driven University", actual.getAffiliation());
        assertEquals("test Description.", actual.getDescription());
        assertEquals("UNCATEGORIZED", actual.getDataverseType().toString());
        assertEquals("gray", actual.getDataverseTheme().getBackgroundColor());
        assertEquals("red", actual.getDataverseTheme().getLinkColor());
        assertEquals("http://www.cnn.com", actual.getDataverseTheme().getLinkUrl());
        assertEquals("lion", actual.getDataverseTheme().getLogo());
        assertEquals(Alignment.CENTER, actual.getDataverseTheme().getLogoAlignment());
        assertEquals(2, actual.getDataverseContacts().size());
        assertEquals("test@example.com,test@example.org", actual.getContactEmails());
        assertEquals(0, actual.getDataverseContacts().get(0).getDisplayOrder());
        assertEquals(1, actual.getDataverseContacts().get(1).getDisplayOrder());
        assertTrue(actual.isPermissionRoot());
    } catch (IOException ioe) {
        throw new JsonParseException("Couldn't read test file", ioe);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) JsonObject(javax.json.JsonObject) IOException(java.io.IOException) Dataverse(edu.harvard.iq.dataverse.Dataverse) Test(org.junit.Test)

Example 77 with Dataverse

use of edu.harvard.iq.dataverse.Dataverse in project dataverse by IQSS.

the class JsonParserTest method testParseNoAliasDataverse.

/**
 * Test that a dataverse JSON object without alias fails to parse.
 * @throws JsonParseException if all goes well - this is expected.
 * @throws IOException when test file IO goes wrong - this is bad.
 */
@Test(expected = JsonParseException.class)
public void testParseNoAliasDataverse() throws JsonParseException, IOException {
    JsonObject dvJson;
    try (InputStream jsonFile = ClassLoader.getSystemResourceAsStream("json/no-alias-dataverse.json")) {
        dvJson = Json.createReader(jsonFile).readObject();
        Dataverse actual = sut.parseDataverse(dvJson);
    }
}
Also used : InputStream(java.io.InputStream) JsonObject(javax.json.JsonObject) Dataverse(edu.harvard.iq.dataverse.Dataverse) Test(org.junit.Test)

Example 78 with Dataverse

use of edu.harvard.iq.dataverse.Dataverse in project dataverse by IQSS.

the class JsonParserTest method testParseCompleteDataverse.

/**
 * Test that a complete dataverse JSON object is correctly parsed. This
 * checks that required and optional properties are parsed into the correct
 * dataverse properties.
 * @throws JsonParseException when this test is broken.
 */
@Test
public void testParseCompleteDataverse() throws JsonParseException {
    JsonObject dvJson;
    try (FileReader reader = new FileReader("doc/sphinx-guides/source/_static/api/dataverse-complete.json")) {
        dvJson = Json.createReader(reader).readObject();
        Dataverse actual = sut.parseDataverse(dvJson);
        assertEquals("Scientific Research", actual.getName());
        assertEquals("science", actual.getAlias());
        assertEquals("Scientific Research University", actual.getAffiliation());
        assertEquals("We do all the science.", actual.getDescription());
        assertEquals("LABORATORY", actual.getDataverseType().toString());
        assertEquals(2, actual.getDataverseContacts().size());
        assertEquals("pi@example.edu,student@example.edu", actual.getContactEmails());
        assertEquals(0, actual.getDataverseContacts().get(0).getDisplayOrder());
        assertEquals(1, actual.getDataverseContacts().get(1).getDisplayOrder());
        /**
         * The JSON does not specify "permissionRoot" because it's a no-op
         * so we don't want to document it in the API Guide. It's a no-op
         * because as of fb7e65f (4.0) all dataverses have permissionRoot
         * hard coded to true.
         */
        assertFalse(actual.isPermissionRoot());
    } catch (IOException ioe) {
        throw new JsonParseException("Couldn't read test file", ioe);
    }
}
Also used : JsonObject(javax.json.JsonObject) FileReader(java.io.FileReader) IOException(java.io.IOException) Dataverse(edu.harvard.iq.dataverse.Dataverse) Test(org.junit.Test)

Example 79 with Dataverse

use of edu.harvard.iq.dataverse.Dataverse in project dataverse by IQSS.

the class JsonParserTest method testParseMinimalDataverse.

/**
 * Test that a minimally complete dataverse JSON object is correctly parsed.
 * This checks for required properties and default values for optional
 * values.
 * @throws JsonParseException when this test is broken.
 */
@Test
public void testParseMinimalDataverse() throws JsonParseException {
    JsonObject dvJson;
    try (InputStream jsonFile = ClassLoader.getSystemResourceAsStream("json/minimal-dataverse.json")) {
        InputStreamReader reader = new InputStreamReader(jsonFile, "UTF-8");
        dvJson = Json.createReader(reader).readObject();
        Dataverse actual = sut.parseDataverse(dvJson);
        assertEquals("testDv", actual.getName());
        assertEquals("testAlias", actual.getAlias());
        assertEquals("UNCATEGORIZED", actual.getDataverseType().toString());
        assertTrue(actual.getDataverseContacts().isEmpty());
        assertEquals("", actual.getContactEmails());
        assertFalse(actual.isPermissionRoot());
        assertFalse(actual.isFacetRoot());
    } catch (IOException ioe) {
        throw new JsonParseException("Couldn't read test file", ioe);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) JsonObject(javax.json.JsonObject) IOException(java.io.IOException) Dataverse(edu.harvard.iq.dataverse.Dataverse) Test(org.junit.Test)

Example 80 with Dataverse

use of edu.harvard.iq.dataverse.Dataverse in project dataverse by IQSS.

the class MoveDatasetCommandTest method setUp.

@Before
public void setUp() {
    auth = makeAuthenticatedUser("Super", "User");
    auth.setSuperuser(true);
    nobody = makeAuthenticatedUser("Nick", "Nobody");
    nobody.setSuperuser(false);
    root = new Dataverse();
    root.setName("root");
    root.setId(1l);
    root.setPublicationDate(new Timestamp(new Date().getTime()));
    childA = new Dataverse();
    childA.setName("childA");
    childA.setId(2l);
    childA.setPublicationDate(new Timestamp(new Date().getTime()));
    childB = new Dataverse();
    childB.setName("childB");
    childB.setId(3l);
    childB.setPublicationDate(new Timestamp(new Date().getTime()));
    grandchildAA = new Dataverse();
    grandchildAA.setName("grandchildAA");
    grandchildAA.setId(4l);
    grandchildAA.setPublicationDate(new Timestamp(new Date().getTime()));
    childDraft = new Dataverse();
    childDraft.setName("childDraft");
    childDraft.setId(5l);
    grandchildBB = new Dataverse();
    grandchildBB.setName("grandchildBB");
    grandchildBB.setId(6l);
    grandchildBB.setPublicationDate(new Timestamp(new Date().getTime()));
    moved = new Dataset();
    moved.setOwner(root);
    moved.setPublicationDate(new Timestamp(new Date().getTime()));
    moved.setId(1l);
    movedResponses = new Dataset();
    movedResponses.setOwner(root);
    movedResponses.setPublicationDate(new Timestamp(new Date().getTime()));
    movedResponses.setId(2l);
    childA.setOwner(root);
    childB.setOwner(root);
    grandchildAA.setOwner(childA);
    grandchildBB.setOwner(childA);
    childDraft.setOwner(childA);
    gbA = new Guestbook();
    gbA.setId(1l);
    gbB = new Guestbook();
    gbB.setId(2l);
    gbC = new Guestbook();
    gbC.setId(3l);
    moved.setGuestbook(gbA);
    movedResponses.setGuestbook(gbA);
    GuestbookResponse gbResp = new GuestbookResponse();
    gbResp.setGuestbook(gbA);
    gbResp.setDataset(movedResponses);
    List<Guestbook> includeA = new ArrayList();
    includeA.add(gbA);
    includeA.add(gbB);
    grandchildAA.setGuestbooks(includeA);
    List<Guestbook> notIncludeA = new ArrayList();
    notIncludeA.add(gbC);
    notIncludeA.add(gbB);
    childB.setGuestbooks(notIncludeA);
    List<Guestbook> none = new ArrayList();
    root.setGuestbooks(none);
    grandchildBB.setGuestbooks(none);
    grandchildBB.setGuestbookRoot(false);
    childA.setGuestbooks(includeA);
    testEngine = new TestDataverseEngine(new TestCommandContext() {

        @Override
        public DataverseServiceBean dataverses() {
            return new DataverseServiceBean() {

                @Override
                public Dataverse save(Dataverse dataverse) {
                    // no-op. The superclass accesses databases which we don't have.
                    return dataverse;
                }
            };
        }

        @Override
        public GuestbookServiceBean guestbooks() {
            return new GuestbookServiceBean() {

                @Override
                public Long findCountResponsesForGivenDataset(Long guestbookId, Long datasetId) {
                    // We're going to fake a response for a dataset with responses
                    if (datasetId == 1) {
                        return new Long(0);
                    } else {
                        return new Long(1);
                    }
                }
            };
        }

        @Override
        public IndexServiceBean index() {
            return new IndexServiceBean() {

                @Override
                public Future<String> indexDataset(Dataset dataset, boolean doNormalSolrDocCleanUp) {
                    return null;
                }
            };
        }

        @Override
        public EntityManager em() {
            return new MockEntityManager() {
            };
        }
    });
}
Also used : TestCommandContext(edu.harvard.iq.dataverse.engine.TestCommandContext) GuestbookServiceBean(edu.harvard.iq.dataverse.GuestbookServiceBean) GuestbookResponse(edu.harvard.iq.dataverse.GuestbookResponse) Dataset(edu.harvard.iq.dataverse.Dataset) Guestbook(edu.harvard.iq.dataverse.Guestbook) ArrayList(java.util.ArrayList) Dataverse(edu.harvard.iq.dataverse.Dataverse) Timestamp(java.sql.Timestamp) DataverseServiceBean(edu.harvard.iq.dataverse.DataverseServiceBean) Date(java.util.Date) TestDataverseEngine(edu.harvard.iq.dataverse.engine.TestDataverseEngine) IndexServiceBean(edu.harvard.iq.dataverse.search.IndexServiceBean) Before(org.junit.Before)

Aggregations

Dataverse (edu.harvard.iq.dataverse.Dataverse)94 Dataset (edu.harvard.iq.dataverse.Dataset)34 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)31 Test (org.junit.Test)27 DataverseRequest (edu.harvard.iq.dataverse.engine.command.DataverseRequest)22 DataFile (edu.harvard.iq.dataverse.DataFile)18 IOException (java.io.IOException)18 Path (javax.ws.rs.Path)16 JsonObject (javax.json.JsonObject)15 CommandException (edu.harvard.iq.dataverse.engine.command.exception.CommandException)11 ArrayList (java.util.ArrayList)11 EJBException (javax.ejb.EJBException)11 JsonObjectBuilder (javax.json.JsonObjectBuilder)11 InputStream (java.io.InputStream)10 Date (java.util.Date)10 JsonArrayBuilder (javax.json.JsonArrayBuilder)10 POST (javax.ws.rs.POST)10 DataverseRole (edu.harvard.iq.dataverse.authorization.DataverseRole)9 User (edu.harvard.iq.dataverse.authorization.users.User)9 SwordError (org.swordapp.server.SwordError)9