Search in sources :

Example 1 with ExtensionPointWrapper

use of org.pentaho.di.ui.core.events.dialog.extension.ExtensionPointWrapper in project pentaho-kettle by pentaho.

the class ConditionSelectionAdapterFileDialogTest method testWidgetSelectedHelper.

@Test
public void testWidgetSelectedHelper() {
    // SETUP
    LogChannelInterface log = mock(LogChannelInterface.class);
    TextVar textVar = mock(TextVar.class);
    AbstractMeta meta = mock(AbstractMeta.class);
    RepositoryUtility repositoryUtility = mock(RepositoryUtility.class);
    ExtensionPointWrapper extensionPointWrapper = mock(ExtensionPointWrapper.class);
    SelectionAdapterOptions options = new SelectionAdapterOptions(SelectionOperation.FILE);
    SelectionEvent event = mock(SelectionEvent.class);
    String testPath = "/home/devuser/some/path";
    when(meta.environmentSubstitute(testPath)).thenReturn(testPath);
    when(textVar.getText()).thenReturn(testPath);
    ArgumentCaptor textCapture = ArgumentCaptor.forClass(String.class);
    doNothing().when(textVar).setText((String) textCapture.capture());
    ConditionSelectionAdapterFileDialogTextVar testInstance = new ConditionSelectionAdapterFileDialogTextVar(log, textVar, meta, options, repositoryUtility, extensionPointWrapper, () -> SelectionOperation.FOLDER);
    testInstance.widgetSelected(event);
    assertTrue(testInstance.getSelectionOptions().getSelectionOperation() == SelectionOperation.FOLDER);
    options = new SelectionAdapterOptions(SelectionOperation.FILE);
    ConditionSelectionAdapterFileDialogTextVar testInstance2 = new ConditionSelectionAdapterFileDialogTextVar(log, textVar, meta, options, repositoryUtility, extensionPointWrapper, () -> SelectionOperation.FILE);
    testInstance.widgetSelected(event);
    assertTrue(testInstance2.getSelectionOptions().getSelectionOperation() == SelectionOperation.FILE);
}
Also used : ExtensionPointWrapper(org.pentaho.di.ui.core.events.dialog.extension.ExtensionPointWrapper) ArgumentCaptor(org.mockito.ArgumentCaptor) AbstractMeta(org.pentaho.di.base.AbstractMeta) SelectionEvent(org.eclipse.swt.events.SelectionEvent) LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface) TextVar(org.pentaho.di.ui.core.widget.TextVar) Test(org.junit.Test)

Example 2 with ExtensionPointWrapper

use of org.pentaho.di.ui.core.events.dialog.extension.ExtensionPointWrapper in project pentaho-kettle by pentaho.

the class SelectionAdapterFileDialogTest method testIsConnectedToRepository.

@Test
public void testIsConnectedToRepository() {
    // SETUP
    LogChannelInterface log = mock(LogChannelInterface.class);
    StringBuilder textVar = new StringBuilder();
    AbstractMeta meta = mock(AbstractMeta.class);
    ExtensionPointWrapper extensionPointWrapper = mock(ExtensionPointWrapper.class);
    SelectionAdapterOptions options = new SelectionAdapterOptions(SelectionOperation.FILE);
    // True case:
    RepositoryUtility repositoryUtilityTrue = mock(RepositoryUtility.class);
    when(repositoryUtilityTrue.isConnectedToRepository()).thenReturn(true);
    SelectionAdapterFileDialog testInstance1 = createTestInstance(log, textVar, meta, options, repositoryUtilityTrue, extensionPointWrapper);
    assertTrue(testInstance1.isConnectedToRepository());
    // False case:
    RepositoryUtility repositoryUtilityFalse = mock(RepositoryUtility.class);
    when(repositoryUtilityFalse.isConnectedToRepository()).thenReturn(false);
    SelectionAdapterFileDialog testInstance2 = createTestInstance(log, textVar, meta, options, repositoryUtilityFalse, extensionPointWrapper);
    assertFalse(testInstance2.isConnectedToRepository());
}
Also used : ExtensionPointWrapper(org.pentaho.di.ui.core.events.dialog.extension.ExtensionPointWrapper) AbstractMeta(org.pentaho.di.base.AbstractMeta) LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface) Test(org.junit.Test)

Example 3 with ExtensionPointWrapper

use of org.pentaho.di.ui.core.events.dialog.extension.ExtensionPointWrapper in project pentaho-kettle by pentaho.

the class SelectionAdapterFileDialogTest method testApplyRelativePathEnvVar.

@Test
public void testApplyRelativePathEnvVar() throws IOException {
    // SETUP
    LogChannelInterface log = mock(LogChannelInterface.class);
    StringBuilder textVar = new StringBuilder();
    AbstractMeta meta = mock(AbstractMeta.class);
    RepositoryUtility repositoryUtility = mock(RepositoryUtility.class);
    ExtensionPointWrapper extensionPointWrapper = mock(ExtensionPointWrapper.class);
    SelectionAdapterOptions options = new SelectionAdapterOptions(SelectionOperation.FILE);
    File testFile = temporaryFolder.newFile("testFileName");
    String testPath = testFile.getPath();
    when(meta.environmentSubstitute(testPath)).thenReturn(testPath);
    SelectionAdapterFileDialog testInstance1 = createTestInstance(log, textVar, meta, options, repositoryUtility, extensionPointWrapper);
    testInstance1.setText(testPath);
    String pathWithCurrentDirVar = testInstance1.applyRelativePathEnvVar(testPath);
    assertEquals(testPath, pathWithCurrentDirVar);
    when(meta.getFilename()).thenReturn(testPath);
    pathWithCurrentDirVar = testInstance1.applyRelativePathEnvVar(testPath);
    assertEquals("${" + Const.INTERNAL_VARIABLE_ENTRY_CURRENT_DIRECTORY + "}/testFileName", pathWithCurrentDirVar);
}
Also used : ExtensionPointWrapper(org.pentaho.di.ui.core.events.dialog.extension.ExtensionPointWrapper) AbstractMeta(org.pentaho.di.base.AbstractMeta) LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface) File(java.io.File) Test(org.junit.Test)

Example 4 with ExtensionPointWrapper

use of org.pentaho.di.ui.core.events.dialog.extension.ExtensionPointWrapper in project pentaho-kettle by pentaho.

the class SelectionAdapterFileDialogTest method testWidgetSelectedHelper.

@Test
public void testWidgetSelectedHelper() {
    // SETUP
    LogChannelInterface log = mock(LogChannelInterface.class);
    StringBuilder textVar = new StringBuilder();
    AbstractMeta meta = mock(AbstractMeta.class);
    RepositoryUtility repositoryUtility = mock(RepositoryUtility.class);
    ExtensionPointWrapper extensionPointWrapper = mock(ExtensionPointWrapper.class);
    SelectionAdapterOptions options = new SelectionAdapterOptions(SelectionOperation.FILE);
    SelectionEvent event = mock(SelectionEvent.class);
    String testPath = "/home/devuser/some/path";
    when(meta.environmentSubstitute(testPath)).thenReturn(testPath);
    SelectionAdapterFileDialog testInstance1 = createTestInstance(log, textVar, meta, options, repositoryUtility, extensionPointWrapper);
    testInstance1.setText(testPath);
    testInstance1.widgetSelected(event);
    assertEquals(testInstance1.getText(), testPath);
}
Also used : ExtensionPointWrapper(org.pentaho.di.ui.core.events.dialog.extension.ExtensionPointWrapper) AbstractMeta(org.pentaho.di.base.AbstractMeta) SelectionEvent(org.eclipse.swt.events.SelectionEvent) LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface) Test(org.junit.Test)

Example 5 with ExtensionPointWrapper

use of org.pentaho.di.ui.core.events.dialog.extension.ExtensionPointWrapper in project pentaho-kettle by pentaho.

the class SelectionAdapterFileDialogTest method createTestInstance.

protected SelectionAdapterFileDialog createTestInstance() {
    LogChannelInterface log = mock(LogChannelInterface.class);
    StringBuilder textWidget = new StringBuilder();
    AbstractMeta meta = mock(AbstractMeta.class);
    RepositoryUtility repositoryUtility = mock(RepositoryUtility.class);
    ExtensionPointWrapper extensionPointWrapper = mock(ExtensionPointWrapper.class);
    SelectionAdapterOptions options = new SelectionAdapterOptions(SelectionOperation.FILE, new String[] {}, "");
    return createTestInstance(log, textWidget, meta, options, repositoryUtility, extensionPointWrapper);
}
Also used : ExtensionPointWrapper(org.pentaho.di.ui.core.events.dialog.extension.ExtensionPointWrapper) AbstractMeta(org.pentaho.di.base.AbstractMeta) LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface)

Aggregations

AbstractMeta (org.pentaho.di.base.AbstractMeta)5 LogChannelInterface (org.pentaho.di.core.logging.LogChannelInterface)5 ExtensionPointWrapper (org.pentaho.di.ui.core.events.dialog.extension.ExtensionPointWrapper)5 Test (org.junit.Test)4 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 File (java.io.File)1 ArgumentCaptor (org.mockito.ArgumentCaptor)1 TextVar (org.pentaho.di.ui.core.widget.TextVar)1