use of org.talend.dataprep.api.user.UserData in project data-prep by Talend.
the class DataSetAPITest method should_list_filtered_datasets_properly.
@Test
public void should_list_filtered_datasets_properly() throws Exception {
// create data sets
final String dataSetId1 = testClient.createDataset("dataset/dataset.csv", "dataset1");
final String dataSetId2 = testClient.createDataset("dataset/dataset.csv", "dataset2");
final String dataSetId3 = testClient.createDataset("dataset/dataset.csv", "dataset3");
testClient.createDataset("dataset/dataset.csv", "dataset4");
// Make dataset1 more recent
final DataSetMetadata dataSetMetadata1 = dataSetMetadataRepository.get(dataSetId1);
dataSetMetadata1.getGovernance().setCertificationStep(DataSetGovernance.Certification.CERTIFIED);
dataSetMetadata1.setLastModificationDate((now().getEpochSecond() + 1) * 1_000);
dataSetMetadataRepository.save(dataSetMetadata1);
final DataSetMetadata dataSetMetadata2 = dataSetMetadataRepository.get(dataSetId2);
dataSetMetadataRepository.save(dataSetMetadata2);
final DataSetMetadata dataSetMetadata3 = dataSetMetadataRepository.get(dataSetId3);
dataSetMetadata3.getGovernance().setCertificationStep(DataSetGovernance.Certification.CERTIFIED);
dataSetMetadataRepository.save(dataSetMetadata3);
// add favorite
UserData userData = new UserData(security.getUserId(), versionService.version().getVersionId());
HashSet<String> favorites = new HashSet<>();
favorites.add(dataSetMetadata1.getId());
favorites.add(dataSetMetadata2.getId());
userData.setFavoritesDatasets(favorites);
userDataRepository.save(userData);
// @formatter:off
// certified, favorite and recent
given().queryParam("favorite", "true").queryParam("certified", "true").queryParam("limit", "true").queryParam("name", "dataset").when().get("/api/datasets").then().statusCode(200).body("name", hasItem("dataset1")).body("name", hasSize(1));
// certified, favorite and recent
given().queryParam("favorite", "true").queryParam("certified", "true").queryParam("limit", "true").queryParam("name", "2").when().get("/api/datasets").then().statusCode(200).body("name", hasSize(0));
// only names
given().queryParam("name", "ATASET2").when().get("/api/datasets").then().statusCode(200).body("name", hasItem("dataset2")).body("name", hasSize(1));
// only favorites
given().queryParam("favorite", "true").when().get("/api/datasets").then().statusCode(200).body("name", hasItems("dataset1", "dataset2")).body("name", hasSize(2));
// only certified
given().queryParam("certified", "true").when().get("/api/datasets").then().statusCode(200).body("name", hasItems("dataset1", "dataset3")).body("name", hasSize(2));
// only recent
given().queryParam("limit", "true").when().get("/api/datasets").then().statusCode(200).body("name", hasItems("dataset2", "dataset3", "dataset4")).body("name", hasSize(3));
// all
when().get("/api/datasets").then().statusCode(200).body("name", hasItems("dataset1", "dataset2", "dataset3", "dataset4")).body("name", hasSize(4));
// @formatter:on
}
use of org.talend.dataprep.api.user.UserData in project data-prep by Talend.
the class DataSetServiceTest method testGetFavoritesDatasetList.
@Test
public void testGetFavoritesDatasetList() {
when().get("/datasets/favorites").then().statusCode(OK.value()).body(equalTo("[]"));
String dsId1 = UUID.randomUUID().toString();
String dsId2 = UUID.randomUUID().toString();
UserData userData = new UserData(security.getUserId(), versionService.version().getVersionId());
HashSet<String> favorites = new HashSet<>();
favorites.add(dsId1);
favorites.add(dsId2);
userData.setFavoritesDatasets(favorites);
userDataRepository.save(userData);
List<String> favoritesResp = from(when().get("/datasets/favorites").asString()).get();
assertEquals(2, favoritesResp.size());
assertThat(favoritesResp, hasItems(dsId1, dsId2));
}
use of org.talend.dataprep.api.user.UserData in project data-prep by Talend.
the class DataSetServiceTest method should_list_filtered_datasets_properly.
@Test
public void should_list_filtered_datasets_properly() throws Exception {
// create data sets
final String dataSetId1 = createCSVDataSet(this.getClass().getResourceAsStream("../tagada3.csv"), "dataset1");
final String dataSetId2 = createCSVDataSet(this.getClass().getResourceAsStream("../avengers.csv"), "dataset2");
final String dataSetId3 = createCSVDataSet(this.getClass().getResourceAsStream("../tagada.csv"), "dataset3");
createCSVDataSet(this.getClass().getResourceAsStream("../tagada2.csv"), "dataset4");
// Make dataset1 more recent
final DataSetMetadata dataSetMetadata1 = dataSetMetadataRepository.get(dataSetId1);
dataSetMetadata1.getGovernance().setCertificationStep(Certification.CERTIFIED);
dataSetMetadata1.setLastModificationDate((now().getEpochSecond() + 1) * 1_000);
dataSetMetadataRepository.save(dataSetMetadata1);
final DataSetMetadata dataSetMetadata2 = dataSetMetadataRepository.get(dataSetId2);
dataSetMetadataRepository.save(dataSetMetadata2);
final DataSetMetadata dataSetMetadata3 = dataSetMetadataRepository.get(dataSetId3);
dataSetMetadata3.getGovernance().setCertificationStep(Certification.CERTIFIED);
dataSetMetadataRepository.save(dataSetMetadata3);
UserData userData = new UserData();
userData.setUserId(security.getUserId());
userData.addFavoriteDataset(dataSetMetadata1.getId());
userData.addFavoriteDataset(dataSetMetadata2.getId());
userDataRepository.save(userData);
// @formatter:off
// certified, favorite and recent
given().queryParam("favorite", "true").queryParam("certified", "true").queryParam("limit", "true").when().get("/datasets").then().statusCode(200).body("name", hasItem("dataset1")).body("name", hasSize(1));
// certified, favorite and recent
given().queryParam("favorite", "true").queryParam("certified", "true").queryParam("limit", "true").queryParam("name", "2").when().get("/datasets").then().statusCode(200).body("name", hasSize(0));
// only names
given().queryParam("name", "ATAset2").when().get("/datasets").then().statusCode(200).body("name", hasItem("dataset2")).body("name", hasSize(1));
// only favorites
given().queryParam("favorite", "true").when().get("/datasets").then().statusCode(200).body("name", hasItems("dataset1", "dataset2")).body("name", hasSize(2));
// only certified
given().queryParam("certified", "true").when().get("/datasets").then().statusCode(200).body("name", hasItems("dataset1", "dataset3")).body("name", hasSize(2));
// only recent
given().queryParam("limit", "true").queryParam("sort", LAST_MODIFICATION_DATE.camelName()).when().get("/datasets").then().statusCode(200).body("name", hasItems("dataset1", "dataset3", "dataset4")).body("name", hasSize(3));
// all
when().get("/datasets").then().statusCode(200).body("name", hasItems("dataset1", "dataset2", "dataset3", "dataset4")).body("name", hasSize(4));
// @formatter:on
}
use of org.talend.dataprep.api.user.UserData in project data-prep by Talend.
the class FileSystemUserDataRepositoryTest method getRandomUserData.
@Override
protected UserData getRandomUserData() {
UserData userData = new UserData();
userData.setUserId(UUID.randomUUID().toString());
userData.setAppVersion("12.3");
return userData;
}
use of org.talend.dataprep.api.user.UserData in project data-prep by Talend.
the class FileSystemUserDataRepositoryTest method shouldIgnoreHiddenFiles.
@Test
public void shouldIgnoreHiddenFiles() throws Exception {
// given
repository.clear();
// when
File hidden = new File("target/test/store/userdata/.hidden_file");
FileOutputStream fos = new FileOutputStream(hidden);
fos.write("hello".getBytes());
// then
final UserData userData = repository.get(".hidden");
hidden.delete();
assertNull(userData);
}
Aggregations