Search in sources :

Example 11 with Preparation

use of org.talend.dataprep.api.preparation.Preparation in project data-prep by Talend.

the class FileSystemPreparationRepositoryTest method shouldListOnlyPreparationsExactlyMatchingGivenName.

@Test
public void shouldListOnlyPreparationsExactlyMatchingGivenName() {
    final List<Integer> ids = Arrays.asList(1, 12, 3);
    // store preparations
    final List<Preparation> preparations = // 
    ids.stream().map(// 
    i -> getPreparation(String.valueOf(i))).collect(Collectors.toList());
    preparations.forEach(prep -> repository.add(prep));
    // and some steps to add some noise
    // 
    ids.stream().map(i -> new Step(Step.ROOT_STEP.id(), "step" + i, versionService.version().getVersionId())).forEach(step -> repository.add(step));
    // get some preparation by dataset id
    final Preparation expected = preparations.get(0);
    final Collection<Preparation> actual = repository.list(Preparation.class, eq("name", "prep-1")).collect(Collectors.toList());
    assertEquals(1, actual.size());
    assertTrue(actual.contains(expected));
}
Also used : Preparation(org.talend.dataprep.api.preparation.Preparation) Arrays(java.util.Arrays) PreparationTest(org.talend.dataprep.preparation.PreparationTest) PreparationRepositoryTest(org.talend.dataprep.preparation.store.PreparationRepositoryTest) Collection(java.util.Collection) TqlBuilder.contains(org.talend.tql.api.TqlBuilder.contains) Autowired(org.springframework.beans.factory.annotation.Autowired) Test(org.junit.Test) TestPropertySource(org.springframework.test.context.TestPropertySource) Step(org.talend.dataprep.api.preparation.Step) PreparationRepository(org.talend.dataprep.preparation.store.PreparationRepository) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) TqlBuilder.eq(org.talend.tql.api.TqlBuilder.eq) List(java.util.List) After(org.junit.After) VersionService(org.talend.dataprep.api.service.info.VersionService) PreparationActions(org.talend.dataprep.api.preparation.PreparationActions) Assert(org.junit.Assert) Action(org.talend.dataprep.api.preparation.Action) Preparation(org.talend.dataprep.api.preparation.Preparation) Step(org.talend.dataprep.api.preparation.Step) PreparationTest(org.talend.dataprep.preparation.PreparationTest) PreparationRepositoryTest(org.talend.dataprep.preparation.store.PreparationRepositoryTest) Test(org.junit.Test)

Example 12 with Preparation

use of org.talend.dataprep.api.preparation.Preparation in project data-prep by Talend.

the class FileSystemPreparationRepositoryTest method getPreparation.

/**
 * @param datasetId the preparation id.
 * @return a preparation with a root step an a the given dataset id.
 */
@Override
protected Preparation getPreparation(String datasetId) {
    Preparation preparation = new Preparation(UUID.randomUUID().toString(), datasetId, Step.ROOT_STEP.id(), versionService.version().getVersionId());
    preparation.setName("prep-" + datasetId);
    return preparation;
}
Also used : Preparation(org.talend.dataprep.api.preparation.Preparation)

Example 13 with Preparation

use of org.talend.dataprep.api.preparation.Preparation in project data-prep by Talend.

the class FileSystemPreparationRepositoryTest method shouldListOnlyPreparationsContainingGivenName.

@Test
public void shouldListOnlyPreparationsContainingGivenName() {
    final List<Integer> ids = Arrays.asList(1, 12, 3);
    // store preparations
    final List<Preparation> preparations = // 
    ids.stream().map(// 
    i -> getPreparation(String.valueOf(i))).collect(Collectors.toList());
    preparations.forEach(prep -> repository.add(prep));
    // and some steps to add some noise
    // 
    ids.stream().map(i -> new Step(Step.ROOT_STEP.id(), "step" + i, versionService.version().getVersionId())).forEach(step -> repository.add(step));
    // get some preparation by dataset id
    final Preparation expected1 = preparations.get(0);
    final Preparation expected2 = preparations.get(1);
    final Collection<Preparation> actual = repository.list(Preparation.class, contains("name", "1")).collect(Collectors.toList());
    assertEquals(2, actual.size());
    assertTrue(actual.contains(expected1));
    assertTrue(actual.contains(expected2));
}
Also used : Preparation(org.talend.dataprep.api.preparation.Preparation) Arrays(java.util.Arrays) PreparationTest(org.talend.dataprep.preparation.PreparationTest) PreparationRepositoryTest(org.talend.dataprep.preparation.store.PreparationRepositoryTest) Collection(java.util.Collection) TqlBuilder.contains(org.talend.tql.api.TqlBuilder.contains) Autowired(org.springframework.beans.factory.annotation.Autowired) Test(org.junit.Test) TestPropertySource(org.springframework.test.context.TestPropertySource) Step(org.talend.dataprep.api.preparation.Step) PreparationRepository(org.talend.dataprep.preparation.store.PreparationRepository) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) TqlBuilder.eq(org.talend.tql.api.TqlBuilder.eq) List(java.util.List) After(org.junit.After) VersionService(org.talend.dataprep.api.service.info.VersionService) PreparationActions(org.talend.dataprep.api.preparation.PreparationActions) Assert(org.junit.Assert) Action(org.talend.dataprep.api.preparation.Action) Preparation(org.talend.dataprep.api.preparation.Preparation) Step(org.talend.dataprep.api.preparation.Step) PreparationTest(org.talend.dataprep.preparation.PreparationTest) PreparationRepositoryTest(org.talend.dataprep.preparation.store.PreparationRepositoryTest) Test(org.junit.Test)

Example 14 with Preparation

use of org.talend.dataprep.api.preparation.Preparation in project data-prep by Talend.

the class InMemoryPreparationRepositoryTest method getByDataSetTest.

/**
 * Test the getByDataSet method.
 */
@Test
public void getByDataSetTest() {
    // populate repository with noise (steps and preparations to be ignored)
    repository.add(getStep("s1"));
    repository.add(getStep("s2"));
    repository.add(getStep("s3"));
    repository.add(getStep("s4"));
    repository.add(getStep("s5"));
    repository.add(getPreparation("p1"));
    repository.add(getPreparation("p2"));
    repository.add(getPreparation("p3"));
    repository.add(getPreparation("p4"));
    repository.add(getPreparation("p5"));
    // add relevant data
    String dataSetId = "wantedId";
    Collection<Preparation> expected = Arrays.asList(getPreparation(dataSetId, "10"), getPreparation(dataSetId, "11"), getPreparation(dataSetId, "12"));
    for (Preparation preparation : expected) {
        repository.add(preparation);
    }
    // run the test
    Collection<Preparation> actual = getRepository().list(Preparation.class, eq("dataSetId", dataSetId)).collect(Collectors.toList());
    // check the result
    Assert.assertEquals(3, actual.size());
    for (Preparation preparation : expected) {
        Assert.assertTrue(actual.contains(preparation));
    }
}
Also used : Preparation(org.talend.dataprep.api.preparation.Preparation) PreparationRepositoryTest(org.talend.dataprep.preparation.store.PreparationRepositoryTest) Test(org.junit.Test)

Example 15 with Preparation

use of org.talend.dataprep.api.preparation.Preparation in project data-prep by Talend.

the class FolderServiceTest method searchFolderShouldUpdateNbPreparationsFound.

@Test
public void searchFolderShouldUpdateNbPreparationsFound() throws Exception {
    // given
    createFolder(home.getId(), "foo");
    final Folder foo = getFolder(home.getId(), "foo");
    Preparation preparation = new Preparation();
    preparation.setName("test_name");
    preparation.setDataSetId("1234");
    preparation.setRowMetadata(new RowMetadata());
    clientTest.createPreparation(preparation, foo.getId());
    // when
    final Response response = // 
    given().queryParam("name", // 
    "foo").expect().statusCode(200).log().ifError().when().get("/folders/search");
    // then
    final List<Folder> folders = mapper.readValue(response.asString(), new TypeReference<List<Folder>>() {
    });
    assertThat(folders, hasSize(1));
    final Folder folder = folders.get(0);
    assertThat(folder.getName(), is("foo"));
    assertEquals(1, folder.getNbPreparations());
}
Also used : Response(com.jayway.restassured.response.Response) Preparation(org.talend.dataprep.api.preparation.Preparation) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Folder(org.talend.dataprep.api.folder.Folder) Test(org.junit.Test) BasePreparationTest(org.talend.dataprep.preparation.BasePreparationTest)

Aggregations

Preparation (org.talend.dataprep.api.preparation.Preparation)65 Test (org.junit.Test)44 Step (org.talend.dataprep.api.preparation.Step)18 List (java.util.List)14 ServiceBaseTest (org.talend.ServiceBaseTest)11 ArrayList (java.util.ArrayList)10 Action (org.talend.dataprep.api.preparation.Action)10 PreparationActions (org.talend.dataprep.api.preparation.PreparationActions)10 Response (com.jayway.restassured.response.Response)9 Arrays (java.util.Arrays)8 DataSetMetadata (org.talend.dataprep.api.dataset.DataSetMetadata)8 ExportParameters (org.talend.dataprep.api.export.ExportParameters)8 UserPreparation (org.talend.dataprep.preparation.service.UserPreparation)8 TransformationCacheKey (org.talend.dataprep.cache.TransformationCacheKey)7 PreparationRepository (org.talend.dataprep.preparation.store.PreparationRepository)7 RowMetadata (org.talend.dataprep.api.dataset.RowMetadata)6 Folder (org.talend.dataprep.api.folder.Folder)6 TDPException (org.talend.dataprep.exception.TDPException)6 PersistentStep (org.talend.dataprep.preparation.store.PersistentStep)6 PreparationRepositoryTest (org.talend.dataprep.preparation.store.PreparationRepositoryTest)6