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);
}
}
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);
}
}
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);
}
}
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);
}
}
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() {
};
}
});
}
Aggregations