use of org.talend.dataprep.api.user.UserData in project data-prep by Talend.
the class DataSetServiceTest method list.
@Test
public void list() throws Exception {
when().get("/datasets").then().statusCode(OK.value()).body(equalTo("[]"));
// Adds 1 data set to store
String id1 = UUID.randomUUID().toString();
final DataSetMetadata metadata = metadataBuilder.metadata().id(id1).name("name1").author("anonymous").created(0).formatFamilyId(new CSVFormatFamily().getBeanId()).build();
metadata.getContent().addParameter(CSVFormatFamily.SEPARATOR_PARAMETER, ";");
dataSetMetadataRepository.save(metadata);
String expected = "[{\"id\":\"" + id1 + "\",\"name\":\"name1\",\"records\":0,\"author\":\"anonymous\",\"nbLinesHeader\":0,\"nbLinesFooter\":0,\"created\":0}]";
InputStream content = when().get("/datasets").asInputStream();
String contentAsString = IOUtils.toString(content, UTF_8);
assertThat(contentAsString, sameJSONAs(expected).allowingExtraUnexpectedFields().allowingAnyArrayOrdering());
// Adds a new data set to store
String id2 = UUID.randomUUID().toString();
DataSetMetadata metadata2 = metadataBuilder.metadata().id(id2).name("name2").author("anonymous").created(0).formatFamilyId(new CSVFormatFamily().getBeanId()).build();
metadata2.getContent().addParameter(CSVFormatFamily.SEPARATOR_PARAMETER, ";");
dataSetMetadataRepository.save(metadata2);
when().get("/datasets").then().statusCode(OK.value());
String response = when().get("/datasets").asString();
List<String> ids = from(response).get("id");
assertThat(ids, hasItems(id1, id2));
// check favorites
// $NON-NLS-1$
List<Boolean> favoritesResp = from(response).get("favorite");
assertEquals(2, favoritesResp.size());
assertFalse(favoritesResp.get(0));
assertFalse(favoritesResp.get(1));
// add favorite
UserData userData = new UserData(security.getUserId(), versionService.version().getVersionId());
HashSet<String> favorites = new HashSet<>();
favorites.add(id1);
favorites.add(id2);
userData.setFavoritesDatasets(favorites);
userDataRepository.save(userData);
// $NON-NLS-1$
favoritesResp = from(when().get("/datasets").asString()).get("favorite");
assertEquals(2, favoritesResp.size());
assertTrue(favoritesResp.get(0));
assertTrue(favoritesResp.get(1));
}
use of org.talend.dataprep.api.user.UserData in project data-prep by Talend.
the class DataSetServiceTest method testFavorite.
@Test
public void testFavorite() {
// given
final String datasetId = UUID.randomUUID().toString();
final DataSetMetadata dataSetMetadata = metadataBuilder.metadata().id(datasetId).formatFamilyId(new CSVFormatFamily().getBeanId()).build();
dataSetMetadata.getContent().addParameter(CSVFormatFamily.SEPARATOR_PARAMETER, ";");
dataSetMetadataRepository.save(dataSetMetadata);
contentStore.storeAsRaw(dataSetMetadata, new ByteArrayInputStream(new byte[0]));
final UserData userData = new UserData(security.getUserId(), versionService.version().getVersionId());
userDataRepository.save(userData);
final Set<String> favorites = new HashSet<>();
favorites.add(datasetId);
boolean isFavorite = from(when().get("/datasets/{id}/content", datasetId).asString()).get("metadata.favorite");
assertFalse(isFavorite);
// when
userData.setFavoritesDatasets(favorites);
userDataRepository.save(userData);
// then
isFavorite = from(when().get("/datasets/{id}/content", datasetId).asString()).get("metadata.favorite");
assertTrue(isFavorite);
}
Aggregations