use of edu.harvard.iq.dataverse.DatasetVersion in project dataverse by IQSS.
the class ReturnDatasetToAuthorCommandTest method setUp.
@Before
public void setUp() {
dataset = new Dataset();
HttpServletRequest aHttpServletRequest = null;
dataverseRequest = new DataverseRequest(MocksFactory.makeAuthenticatedUser("First", "Last"), aHttpServletRequest);
testEngine = new TestDataverseEngine(new TestCommandContext() {
@Override
public AuthenticationServiceBean authentication() {
return new AuthenticationServiceBean() {
@Override
public AuthenticatedUser getAuthenticatedUser(String id) {
return MocksFactory.makeAuthenticatedUser("First", "Last");
}
};
}
@Override
public IndexServiceBean index() {
return new IndexServiceBean() {
@Override
public Future<String> indexDataset(Dataset dataset, boolean doNormalSolrDocCleanUp) {
return null;
}
};
}
@Override
public EntityManager em() {
return new NoOpTestEntityManager();
}
@Override
public DatasetServiceBean datasets() {
return new DatasetServiceBean() {
{
em = new NoOpTestEntityManager();
}
@Override
public DatasetVersionUser getDatasetVersionUser(DatasetVersion version, User user) {
return null;
}
@Override
public WorkflowComment addWorkflowComment(WorkflowComment comment) {
return comment;
}
@Override
public void removeDatasetLocks(Long datasetId, DatasetLock.Reason aReason) {
}
};
}
@Override
public DataverseRoleServiceBean roles() {
return new DataverseRoleServiceBean() {
@Override
public DataverseRole findBuiltinRoleByAlias(String alias) {
return new DataverseRole();
}
@Override
public RoleAssignment save(RoleAssignment assignment) {
// no-op
return assignment;
}
};
}
@Override
public PermissionServiceBean permissions() {
return new PermissionServiceBean() {
@Override
public List<AuthenticatedUser> getUsersWithPermissionOn(Permission permission, DvObject dvo) {
// We only need permissions for notifications, which we are testing in InReviewWorkflowIT.
return Collections.emptyList();
}
};
}
});
}
use of edu.harvard.iq.dataverse.DatasetVersion in project dataverse by IQSS.
the class DDIExporterTest method testExportDataset.
@Test
public void testExportDataset() throws Exception {
System.out.println("exportDataset");
// FIXME: switch ddi/dataset-finch1.json
// File datasetVersionJson = new File("src/test/java/edu/harvard/iq/dataverse/export/ddi/dataset-finch1.json");
File datasetVersionJson = new File("src/test/resources/json/dataset-finch1.json");
String datasetVersionAsJson = new String(Files.readAllBytes(Paths.get(datasetVersionJson.getAbsolutePath())));
JsonReader jsonReader = Json.createReader(new StringReader(datasetVersionAsJson));
JsonObject json = jsonReader.readObject();
JsonParser jsonParser = new JsonParser(datasetFieldTypeSvc, null, null);
DatasetVersion version = jsonParser.parseDatasetVersion(json.getJsonObject("datasetVersion"));
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
DDIExporter instance = new DDIExporter();
boolean nullPointerFixed = false;
if (nullPointerFixed) {
instance.exportDataset(version, json, byteArrayOutputStream);
}
System.out.println("out: " + XmlPrinter.prettyPrintXml(byteArrayOutputStream.toString()));
}
use of edu.harvard.iq.dataverse.DatasetVersion in project dataverse by IQSS.
the class DDIExporterTest method testExportDatasetContactEmailAbsent.
@Test
public void testExportDatasetContactEmailAbsent() throws Exception {
File datasetVersionJson = new File("src/test/java/edu/harvard/iq/dataverse/export/ddi/datasetContactEmailAbsent.json");
String datasetVersionAsJson = new String(Files.readAllBytes(Paths.get(datasetVersionJson.getAbsolutePath())));
JsonReader jsonReader = Json.createReader(new StringReader(datasetVersionAsJson));
JsonObject json = jsonReader.readObject();
// JsonParser jsonParser = new JsonParser(datasetFieldTypeSvc, null, settingsSvc);
JsonParser jsonParser = new JsonParser(datasetFieldTypeSvc, null, null);
DatasetVersion version = jsonParser.parseDatasetVersion(json.getJsonObject("datasetVersion"));
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
DDIExporter instance = new DDIExporter();
instance.exportDataset(version, json, byteArrayOutputStream);
System.out.println(XmlPrinter.prettyPrintXml(byteArrayOutputStream.toString()));
assertFalse(byteArrayOutputStream.toString().contains("finch@mailinator.com"));
}
use of edu.harvard.iq.dataverse.DatasetVersion in project dataverse by IQSS.
the class DDIExporterTest method testExportDatasetContactEmailPresent.
@Test
public void testExportDatasetContactEmailPresent() throws Exception {
File datasetVersionJson = new File("src/test/java/edu/harvard/iq/dataverse/export/ddi/datasetContactEmailPresent.json");
String datasetVersionAsJson = new String(Files.readAllBytes(Paths.get(datasetVersionJson.getAbsolutePath())));
JsonReader jsonReader = Json.createReader(new StringReader(datasetVersionAsJson));
JsonObject json = jsonReader.readObject();
JsonParser jsonParser = new JsonParser(datasetFieldTypeSvc, null, null);
DatasetVersion version = jsonParser.parseDatasetVersion(json.getJsonObject("datasetVersion"));
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
DDIExporter instance = new DDIExporter();
instance.exportDataset(version, json, byteArrayOutputStream);
System.out.println(XmlPrinter.prettyPrintXml(byteArrayOutputStream.toString()));
assertTrue(byteArrayOutputStream.toString().contains("finch@mailinator.com"));
}
use of edu.harvard.iq.dataverse.DatasetVersion in project dataverse by IQSS.
the class MocksFactory method makeDatasetVersion.
public static DatasetVersion makeDatasetVersion(List<DataFileCategory> categories) {
final DatasetVersion retVal = new DatasetVersion();
final List<DataFile> files = makeFiles(10);
final List<FileMetadata> metadatas = new ArrayList<>(10);
Random rand = new Random();
files.forEach(df -> {
df.getFileMetadata().addCategory(categories.get(rand.nextInt(categories.size())));
metadatas.add(df.getFileMetadata());
});
retVal.setFileMetadatas(metadatas);
List<DatasetField> fields = new ArrayList<>();
DatasetField field = new DatasetField();
field.setId(nextId());
field.setSingleValue("Sample Field Value");
field.setDatasetFieldType(makeDatasetFieldType());
fields.add(field);
retVal.setDatasetFields(fields);
return retVal;
}
Aggregations