Search in sources :

Example 11 with UserData

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));
}
Also used : UserData(org.talend.dataprep.api.user.UserData) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata) CSVFormatFamily(org.talend.dataprep.schema.csv.CSVFormatFamily) HashSet(java.util.HashSet) DataSetBaseTest(org.talend.dataprep.dataset.DataSetBaseTest) Test(org.junit.Test)

Example 12 with UserData

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);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) UserData(org.talend.dataprep.api.user.UserData) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata) CSVFormatFamily(org.talend.dataprep.schema.csv.CSVFormatFamily) HashSet(java.util.HashSet) DataSetBaseTest(org.talend.dataprep.dataset.DataSetBaseTest) Test(org.junit.Test)

Aggregations

UserData (org.talend.dataprep.api.user.UserData)12 Test (org.junit.Test)7 DataSetMetadata (org.talend.dataprep.api.dataset.DataSetMetadata)7 HashSet (java.util.HashSet)5 Matchers.containsString (org.hamcrest.Matchers.containsString)5 Matchers.isEmptyString (org.hamcrest.Matchers.isEmptyString)5 DataSetBaseTest (org.talend.dataprep.dataset.DataSetBaseTest)5 ApiOperation (io.swagger.annotations.ApiOperation)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 Timed (org.talend.dataprep.metrics.Timed)3 CSVFormatFamily (org.talend.dataprep.schema.csv.CSVFormatFamily)3 InputStream (java.io.InputStream)2 UserDataSetMetadata (org.talend.dataprep.dataset.service.UserDataSetMetadata)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 ArrayList (java.util.ArrayList)1 Owner (org.talend.dataprep.api.share.Owner)1 DataSetMetadataBuilder (org.talend.dataprep.dataset.DataSetMetadataBuilder)1 TDPException (org.talend.dataprep.exception.TDPException)1