Search in sources :

Example 36 with BoundedReader

use of org.talend.components.api.component.runtime.BoundedReader in project components by Talend.

the class AzureStorageBaseBlobTestIT method doContainerDelete.

/**
 * doContainerDelete.
 *
 * @param container {@link String} container
 * @return <code>Boolean</code> {@link Boolean} boolean
 * @throws Exception the exception
 */
@SuppressWarnings("rawtypes")
public Boolean doContainerDelete(String container) throws Exception {
    TAzureStorageContainerDeleteProperties properties = new TAzureStorageContainerDeleteProperties("tests");
    setupConnectionProperties(properties);
    properties.container.setValue(container);
    BoundedReader reader = createBoundedReader(properties);
    return reader.start();
}
Also used : TAzureStorageContainerDeleteProperties(org.talend.components.azurestorage.blob.tazurestoragecontainerdelete.TAzureStorageContainerDeleteProperties) BoundedReader(org.talend.components.api.component.runtime.BoundedReader)

Example 37 with BoundedReader

use of org.talend.components.api.component.runtime.BoundedReader in project components by Talend.

the class AzureStorageBaseBlobTestIT method doContainerExist.

/**
 * doContainerExist - Checks if container exists
 *
 * @param container {@link String} container
 * @return {@link Boolean} true if exists.
 * @throws Exception the exception
 */
@SuppressWarnings("rawtypes")
public Boolean doContainerExist(String container) throws Exception {
    TAzureStorageContainerExistProperties properties = new TAzureStorageContainerExistProperties("tests");
    setupConnectionProperties(properties);
    properties.container.setValue(container);
    BoundedReader reader = createBoundedReader(properties);
    return reader.start();
}
Also used : TAzureStorageContainerExistProperties(org.talend.components.azurestorage.blob.tazurestoragecontainerexist.TAzureStorageContainerExistProperties) BoundedReader(org.talend.components.api.component.runtime.BoundedReader)

Example 38 with BoundedReader

use of org.talend.components.api.component.runtime.BoundedReader in project components by Talend.

the class AzureStorageDeleteReaderTestIT method testBlobDelete.

@SuppressWarnings("rawtypes")
@Test
public void testBlobDelete() throws Exception {
    TAzureStorageDeleteProperties props = new TAzureStorageDeleteProperties("tests");
    props.container.setValue(CONTAINER);
    setupConnectionProperties(props);
    RemoteBlobsTable rmt = new RemoteBlobsTable("tests");
    List<String> pfx = new ArrayList<>();
    List<Boolean> inc = new ArrayList<>();
    pfx.add("");
    inc.add(false);
    rmt.prefix.setValue(pfx);
    rmt.include.setValue(inc);
    props.remoteBlobs = rmt;
    BoundedReader reader = createBoundedReader(props);
    assertTrue(reader.start());
    List<String> blobs = listAllBlobs(CONTAINER);
    // blob1.txt, blob2.txt & blob3.txt should be deleted
    for (String b : TEST_ROOT_BLOBS) assertFalse(isInBlobList(b, blobs));
    // the others should exist
    for (String b : TEST_SUB_BLOBS) assertTrue(isInBlobList(b, blobs));
    // 
    // delete sub1 and sub3
    // 
    pfx.clear();
    pfx.add("sub1/");
    pfx.add("sub3/");
    inc.clear();
    inc.add(true);
    inc.add(true);
    rmt.prefix.setValue(pfx);
    rmt.include.setValue(inc);
    props.remoteBlobs = rmt;
    reader = createBoundedReader(props);
    assertTrue(reader.start());
    blobs = listAllBlobs(CONTAINER);
    for (String b : TEST_ROOT_BLOBS) assertFalse(isInBlobList(b, blobs));
    for (String b : TEST_SUB1_BLOBS) assertFalse(isInBlobList(b, blobs));
    for (String b : TEST_SUB3_BLOBS) assertFalse(isInBlobList(b, blobs));
    // the others should exist
    for (String b : TEST_SUB2_BLOBS) assertTrue(isInBlobList(b, blobs));
    // 
    // finally delete everything
    // 
    pfx.clear();
    pfx.add("");
    inc.clear();
    inc.add(true);
    rmt.prefix.setValue(pfx);
    rmt.include.setValue(inc);
    props.remoteBlobs = rmt;
    reader = createBoundedReader(props);
    assertTrue(reader.start());
    blobs = listAllBlobs(CONTAINER);
    assertTrue(blobs.size() == 0);
}
Also used : RemoteBlobsTable(org.talend.components.azurestorage.blob.helpers.RemoteBlobsTable) ArrayList(java.util.ArrayList) TAzureStorageDeleteProperties(org.talend.components.azurestorage.blob.tazurestoragedelete.TAzureStorageDeleteProperties) BoundedReader(org.talend.components.api.component.runtime.BoundedReader) Test(org.junit.Test)

Example 39 with BoundedReader

use of org.talend.components.api.component.runtime.BoundedReader in project components by Talend.

the class GoogleDriveCopyReaderTest method testStartCopyFileAndRename.

@Test
public void testStartCopyFileAndRename() throws Exception {
    properties.rename.setValue(true);
    source.initialize(container, properties);
    BoundedReader reader = source.createReader(container);
    assertTrue(reader.start());
    IndexedRecord record = (IndexedRecord) reader.getCurrent();
    assertNotNull(record);
    assertEquals(2, record.getSchema().getFields().size());
    assertEquals(SOURCE_ID, record.get(0));
    assertEquals(DESTINATION_ID, record.get(1));
    reader.close();
    Map<String, Object> returnValues = reader.getReturnValues();
    assertNotNull(returnValues);
    assertEquals(SOURCE_ID, returnValues.get(GoogleDriveCopyDefinition.RETURN_SOURCE_ID));
    assertEquals(DESTINATION_ID, returnValues.get(GoogleDriveCopyDefinition.RETURN_DESTINATION_ID));
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) Matchers.anyString(org.mockito.Matchers.anyString) BoundedReader(org.talend.components.api.component.runtime.BoundedReader) Test(org.junit.Test)

Example 40 with BoundedReader

use of org.talend.components.api.component.runtime.BoundedReader in project components by Talend.

the class GoogleDriveCopyReaderTest method testStartCopyFileAndRemove.

@Test
public void testStartCopyFileAndRemove() throws Exception {
    properties.deleteSourceFile.setValue(true);
    source.initialize(container, properties);
    BoundedReader reader = source.createReader(container);
    assertTrue(reader.start());
    IndexedRecord record = (IndexedRecord) reader.getCurrent();
    assertNotNull(record);
    assertEquals(2, record.getSchema().getFields().size());
    assertEquals(SOURCE_ID, record.get(0));
    assertEquals(DESTINATION_ID, record.get(1));
    reader.close();
    Map<String, Object> returnValues = reader.getReturnValues();
    assertNotNull(returnValues);
    assertEquals(SOURCE_ID, returnValues.get(GoogleDriveCopyDefinition.RETURN_SOURCE_ID));
    assertEquals(DESTINATION_ID, returnValues.get(GoogleDriveCopyDefinition.RETURN_DESTINATION_ID));
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) Matchers.anyString(org.mockito.Matchers.anyString) BoundedReader(org.talend.components.api.component.runtime.BoundedReader) Test(org.junit.Test)

Aggregations

BoundedReader (org.talend.components.api.component.runtime.BoundedReader)45 Test (org.junit.Test)37 IndexedRecord (org.apache.avro.generic.IndexedRecord)24 Matchers.anyString (org.mockito.Matchers.anyString)6 ArrayList (java.util.ArrayList)5 TAzureStorageQueueCreateProperties (org.talend.components.azurestorage.queue.tazurestoragequeuecreate.TAzureStorageQueueCreateProperties)4 GenericData (org.apache.avro.generic.GenericData)3 RemoteBlobsTable (org.talend.components.azurestorage.blob.helpers.RemoteBlobsTable)2 TAzureStorageQueueDeleteProperties (org.talend.components.azurestorage.queue.tazurestoragequeuedelete.TAzureStorageQueueDeleteProperties)2 Drive (com.google.api.services.drive.Drive)1 File (com.google.api.services.drive.model.File)1 FileList (com.google.api.services.drive.model.FileList)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 Map (java.util.Map)1 Before (org.junit.Before)1 TAzureStorageContainerCreateProperties (org.talend.components.azurestorage.blob.tazurestoragecontainercreate.TAzureStorageContainerCreateProperties)1 TAzureStorageContainerDeleteProperties (org.talend.components.azurestorage.blob.tazurestoragecontainerdelete.TAzureStorageContainerDeleteProperties)1 TAzureStorageContainerExistProperties (org.talend.components.azurestorage.blob.tazurestoragecontainerexist.TAzureStorageContainerExistProperties)1 TAzureStorageContainerListProperties (org.talend.components.azurestorage.blob.tazurestoragecontainerlist.TAzureStorageContainerListProperties)1