use of edu.harvard.iq.dataverse.DataFile in project dataverse by IQSS.
the class UpdateDatasetThumbnailCommandTest method setUp.
@Before
public void setUp() {
dataset = new Dataset();
testEngine = new TestDataverseEngine(new TestCommandContext() {
@Override
public DataFileServiceBean files() {
return new DataFileServiceBean() {
@Override
public DataFile find(Object object) {
if (object == unfindableFile) {
return null;
} else if (object == thumbnailUnexpectedlyAbsent) {
return new DataFile();
} else {
return null;
}
}
};
}
@Override
public DatasetServiceBean datasets() {
return new DatasetServiceBean() {
@Override
public Dataset setDatasetFileAsThumbnail(Dataset dataset, DataFile datasetFileThumbnailToSwitchTo) {
return dataset;
}
};
}
@Override
public SystemConfig systemConfig() {
return new SystemConfig() {
@Override
public String getDataverseSiteUrl() {
return "https://dataverse.example.edu";
}
};
}
});
}
use of edu.harvard.iq.dataverse.DataFile in project dataverse by IQSS.
the class ExternalToolHandlerTest method testGetToolUrlWithOptionalQueryParameters.
// TODO: It would probably be better to split these into individual tests.
@Test
public void testGetToolUrlWithOptionalQueryParameters() {
ExternalTool.Type type = ExternalTool.Type.EXPLORE;
String toolUrl = "http://example.com";
ExternalTool externalTool = new ExternalTool("displayName", "description", type, toolUrl, "{}");
// One query parameter, not a reserved word, no {fileId} (required) used.
externalTool.setToolParameters(Json.createObjectBuilder().add("queryParameters", Json.createArrayBuilder().add(Json.createObjectBuilder().add("mode", "mode1"))).build().toString());
DataFile nullDataFile = null;
ApiToken nullApiToken = null;
Exception expectedException1 = null;
try {
ExternalToolHandler externalToolHandler1 = new ExternalToolHandler(externalTool, nullDataFile, nullApiToken);
} catch (Exception ex) {
expectedException1 = ex;
}
assertNotNull(expectedException1);
assertEquals("A DataFile is required.", expectedException1.getMessage());
// Two query parameters.
externalTool.setToolParameters(Json.createObjectBuilder().add("queryParameters", Json.createArrayBuilder().add(Json.createObjectBuilder().add("mode", "mode1")).add(Json.createObjectBuilder().add("key2", "value2"))).build().toString());
Exception expectedException2 = null;
try {
ExternalToolHandler externalToolHandler2 = new ExternalToolHandler(externalTool, nullDataFile, nullApiToken);
} catch (Exception ex) {
expectedException2 = ex;
}
assertNotNull(expectedException2);
assertEquals("A DataFile is required.", expectedException2.getMessage());
// Two query parameters, both reserved words, one is {fileId} which is required.
externalTool.setToolParameters(Json.createObjectBuilder().add("queryParameters", Json.createArrayBuilder().add(Json.createObjectBuilder().add("key1", "{fileId}")).add(Json.createObjectBuilder().add("key2", "{apiToken}"))).build().toString());
DataFile dataFile = new DataFile();
dataFile.setId(42l);
ApiToken apiToken = new ApiToken();
apiToken.setTokenString("7196b5ce-f200-4286-8809-03ffdbc255d7");
ExternalToolHandler externalToolHandler3 = new ExternalToolHandler(externalTool, dataFile, apiToken);
String result3 = externalToolHandler3.getQueryParametersForUrl();
System.out.println("result3: " + result3);
assertEquals("?key1=42&key2=7196b5ce-f200-4286-8809-03ffdbc255d7", result3);
// Two query parameters, both reserved words, no apiToken
externalTool.setToolParameters(Json.createObjectBuilder().add("queryParameters", Json.createArrayBuilder().add(Json.createObjectBuilder().add("key1", "{fileId}")).add(Json.createObjectBuilder().add("key2", "{apiToken}"))).build().toString());
ExternalToolHandler externalToolHandler4 = new ExternalToolHandler(externalTool, dataFile, nullApiToken);
String result4 = externalToolHandler4.getQueryParametersForUrl();
System.out.println("result4: " + result4);
assertEquals("?key1=42", result4);
// Two query parameters, attempt to use a reserved word that doesn't exist.
externalTool.setToolParameters(Json.createObjectBuilder().add("queryParameters", Json.createArrayBuilder().add(Json.createObjectBuilder().add("key1", "{junk}")).add(Json.createObjectBuilder().add("key2", "{apiToken}"))).build().toString());
Exception expectedException = null;
try {
ExternalToolHandler externalToolHandler5 = new ExternalToolHandler(externalTool, dataFile, nullApiToken);
String result5 = externalToolHandler5.getQueryParametersForUrl();
System.out.println("result5: " + result5);
} catch (Exception ex) {
System.out.println("Exception caught: " + ex);
expectedException = ex;
}
assertNotNull(expectedException);
assertEquals("Unknown reserved word: {junk}", expectedException.getMessage());
}
use of edu.harvard.iq.dataverse.DataFile 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;
}
use of edu.harvard.iq.dataverse.DataFile in project dataverse by IQSS.
the class MocksFactory method makeDataset.
public static Dataset makeDataset() {
Dataset ds = new Dataset();
ds.setId(nextId());
ds.setIdentifier("sample-ds-" + ds.getId());
ds.setCategoriesByName(Arrays.asList("CatOne", "CatTwo", "CatThree"));
final List<DataFile> files = makeFiles(10);
final List<FileMetadata> metadatas = new ArrayList<>(10);
final List<DataFileCategory> categories = ds.getCategories();
Random rand = new Random();
files.forEach(df -> {
df.getFileMetadata().addCategory(categories.get(rand.nextInt(categories.size())));
metadatas.add(df.getFileMetadata());
});
ds.setFiles(files);
final DatasetVersion initialVersion = ds.getVersions().get(0);
initialVersion.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);
initialVersion.setDatasetFields(fields);
ds.setOwner(makeDataverse());
return ds;
}
use of edu.harvard.iq.dataverse.DataFile in project dataverse by IQSS.
the class StorageIOTest method testGetDvObject.
@Test
public void testGetDvObject() {
assertEquals(null, instance.getDvObject());
instance.setDvObject(new Dataset());
assertEquals(new Dataset(), instance.getDataset());
try {
instance.getDataFile();
fail("This should have thrown");
} catch (ClassCastException ex) {
assertEquals(ex.getMessage(), "edu.harvard.iq.dataverse.Dataset cannot be cast to edu.harvard.iq.dataverse.DataFile");
}
try {
instance.getDataverse();
fail("This should have thrown");
} catch (ClassCastException ex) {
assertEquals(ex.getMessage(), "edu.harvard.iq.dataverse.Dataset cannot be cast to edu.harvard.iq.dataverse.Dataverse");
}
assertEquals(new DataFile(), new FileAccessIO<>(new DataFile()).getDataFile());
assertEquals(new Dataverse(), new FileAccessIO<>(new Dataverse()).getDataverse());
}
Aggregations