@Override protected String buildFileName(DataSourceDef def) { return def.getName() + ".datasource"; }
@Override protected String getExpectedFileName() { return dataSourceDef.getName() + ".datasource"; }
@Override public Collection<DataSourceDefInfo> findGlobalDataSources(boolean includeUnManaged) { Collection<DataSourceDefInfo> result = resolveDataSources(serviceHelper.getGlobalDataSourcesContext()); if (includeUnManaged) { Map<String, DataSourceDefInfo> managedDataSources = new HashMap<>(); for (DataSourceDefInfo dataSourceDefInfo : result) { managedDataSources.put(dataSourceDefInfo.getUuid(), dataSourceDefInfo); } try { List<DataSourceDef> allDeployments = providerFactory.getDataSourceProvider().getDeployments(); DeploymentInfo deploymentInfo; for (DataSourceDef dataSourceDef : allDeployments) { deploymentInfo = runtimeManager.getDataSourceDeploymentInfo(dataSourceDef.getUuid()); if (!managedDataSources.containsKey(dataSourceDef.getUuid()) && (deploymentInfo != null && !deploymentInfo.isManaged())) { result.add(new DataSourceDefInfo(dataSourceDef.getUuid(), dataSourceDef.getName(), runtimeManager.getDataSourceDeploymentInfo(dataSourceDef.getUuid()))); } } } catch (Exception e) { logger.warn("It was not possible to read all deployed data sources. ", e); } } return result; }
private DataSourceDefInfo createDataSourceDefInfo(final org.uberfire.java.nio.file.Path path) { String content = ioService.readAllString(path); DataSourceDef dataSourceDef = DataSourceDefSerializer.deserialize(content); DataSourceDeploymentInfo deploymentInfo = null; try { deploymentInfo = runtimeManager.getDataSourceDeploymentInfo(dataSourceDef.getUuid()); } catch (Exception e) { logger.warn("It was not possible to read deployment info when building DataSourceDefInfo for data source: " + dataSourceDef.getUuid(), e); } return new DataSourceDefInfo(dataSourceDef.getUuid(), dataSourceDef.getName(), Paths.convert(path), deploymentInfo); }
protected void setContent(final DataSourceDefEditorContent editorContent) { this.editorContent = editorContent; view.setDataSourceName(editorContent.getDef().getName()); editorHelper.setDataSourceDef(editorContent.getDef()); editorHelper.setModule(editorContent.getModule()); editorHelper.setValid(true); }
private void testNameChange(boolean isValid) { if (isValid) { when(mainPanel.getName()).thenReturn(NAME); } else { when(mainPanel.getName()).thenReturn(INVALID_NAME); } when(translationService.getTranslation( DataSourceManagementConstants.DataSourceDefEditor_InvalidNameMessage)).thenReturn(ERROR); //emulates the helper receiving the change event editorHelper.onNameChange(); if (isValid) { assertTrue(editorHelper.isNameValid()); assertEquals(NAME, dataSourceDef.getName()); verify(mainPanel, times(1)).clearNameErrorMessage(); } else { assertFalse(editorHelper.isNameValid()); assertEquals(INVALID_NAME, dataSourceDef.getName()); verify(mainPanel, times(1)).setNameErrorMessage(ERROR); } verify(handler, times(1)).onNameChange(); }
@Test public void testLoadFileSuccessFul() { prepareLoadFileSuccessful(); //verifies the content was properly loaded. verify(view, times(1)).showLoading(); verify(view, times(1)).hideBusyIndicator(); assertEquals(content, editor.getContent()); verify(mainPanelView, times(1)).loadDriverOptions(eq(options), eq(true)); verify(mainPanelView, times(1)).setName(content.getDef().getName()); verify(mainPanelView, times(1)).setConnectionURL(content.getDef().getConnectionURL()); verify(mainPanelView, times(1)).setUser(content.getDef().getUser()); verify(mainPanelView, times(1)).setPassword(content.getDef().getPassword()); verify(mainPanelView, times(2)).setDriver(content.getDef().getDriverUuid()); }
@Test public void testOnBrowseDatabase() { //open the editor with a valid content prepareLoadFileSuccessful(); //emulates the selection of the show content action from the UI editor.onShowContent(); DatabaseStructureExplorer.Settings expectedSettings = new DatabaseStructureExplorer.Settings(); expectedSettings.dataSourceUuid(content.getDef().getUuid()); expectedSettings.dataSourceName(content.getDef().getName()); //dbStructureExplorer should have been initialized with the proper datasource parameters. verify(dbStructureExplorer, times(1)).initialize(eq(expectedSettings), any(InitializeCallback.class)); }
public void setDataSourceDef(final DataSourceDef dataSourceDef) { this.dataSourceDef = dataSourceDef; mainPanel.clear(); mainPanel.setName(dataSourceDef.getName()); mainPanel.setConnectionURL(dataSourceDef.getConnectionURL()); mainPanel.setUser(dataSourceDef.getUser()); mainPanel.setPassword(dataSourceDef.getPassword()); mainPanel.setDriver(dataSourceDef.getDriverUuid()); }
verify(mainPanel, times(1)).setName(dataSourceDef.getName()); verify(mainPanel, times(1)).setConnectionURL(dataSourceDef.getConnectionURL()); verify(mainPanel, times(1)).setUser(dataSourceDef.getUser());
@Override public void onShowContent() { DatabaseStructureExplorer.Settings settings = new DatabaseStructureExplorer.Settings() .dataSourceUuid(getContent().getDef().getUuid()) .dataSourceName(getContent().getDef().getName()); dbStructureExplorer.initialize(settings, new InitializeCallback() { @Override public void onInitializeError(Throwable throwable) { // do nothing, just stay showing the parameters edition. } @Override public void onInitializeSuccess() { showContent(); } }); }
@Test public void testEditorChanges() { //open the editor with a valid content prepareLoadFileSuccessful(); //emulates some valid changes in the editor. when(mainPanelView.getName()).thenReturn(NAME_2); when(mainPanelView.getConnectionURL()).thenReturn(CONNECTION_URL_2); when(mainPanelView.getUser()).thenReturn(USER_2); when(mainPanelView.getPassword()).thenReturn(PASSWORD_2); when(mainPanelView.getDriver()).thenReturn(DRIVER_UUID_2); mainPanel.onNameChange(); mainPanel.onConnectionURLChange(); mainPanel.onUserChange(); mainPanel.onPasswordChange(); mainPanel.onDriverChange(); //the content of the editor should have been properly modified. assertEquals(NAME_2, content.getDef().getName()); assertEquals(CONNECTION_URL_2, content.getDef().getConnectionURL()); assertEquals(USER_2, content.getDef().getUser()); assertEquals(PASSWORD_2, content.getDef().getPassword()); assertEquals(DRIVER_UUID_2, content.getDef().getDriverUuid()); }
/** * Tests the case where the user completes the page by entering correct values. */ @Test public void testValidCompletion() { //emulates the page has already been loaded by the Wizard. loadPage(); //emulates the user completing the page by typing valid values in all fields. completeValidDefPage(); //status change event should have been fired for all the modified fields. verify( statusChangeEvent, times( 5 ) ).fire( any( WizardPageStatusChangeEvent.class ) ); //the DataSourceDef should have been properly populated. assertEquals( NAME, dataSourceDef.getName() ); assertEquals( CONNECTION_URL, dataSourceDef.getConnectionURL() ); assertEquals( USER, dataSourceDef.getUser() ); assertEquals( PASSWORD, dataSourceDef.getPassword() ); assertEquals( DRIVER_UUID, dataSourceDef.getDriverUuid() ); //the page should be in completed state. defPage.isComplete( new Callback<Boolean>() { @Override public void callback( Boolean result ) { assertTrue( result ); } } ); }