@Override public void execute() { mainPanel.setDriver(getContent().getDef().getDriverUuid()); } };
/** * Creates a data source in the Wildfly server. * @param dataSourceDef Data source definition to be created. * @param jndi jndi name to be use the Wildly server to bound the data source in the jndi context. * @return returns the deployment information for the created data source. * @throws Exception exceptions may be thrown if the data source couldn't be created. */ private DataSourceDeploymentInfo deploy(final DataSourceDef dataSourceDef, final String jndi, String deploymentId) throws Exception { DriverDeploymentInfo driverDeploymentInfo = driverProvider.getDeploymentInfo(dataSourceDef.getDriverUuid()); if (driverDeploymentInfo == null) { throw new Exception("Required driver: " + dataSourceDef.getDriverUuid() + " is not deployed."); } WildflyDataSourceDef wfDataSourceDef = buildWFDataSource(deploymentId, jndi, dataSourceDef, driverDeploymentInfo.getDriverDeploymentId()); dataSourceMgmtClient.createDataSource(wfDataSourceDef); return new DataSourceDeploymentInfo(deploymentId, true, dataSourceDef.getUuid(), jndi, false); }
@Override public synchronized DataSourceDeploymentInfo deployDataSource(DataSourceDef dataSourceDef, DeploymentOptions options) throws Exception { try { DataSourceDeploymentInfo dataSourceDeploymentInfo = dataSourceProvider.getDeploymentInfo(dataSourceDef.getUuid()); DriverDeploymentInfo driverDeploymentInfo = driverProvider.getDeploymentInfo(dataSourceDef.getDriverUuid()); if (dataSourceDeploymentInfo != null) { if (options.isCreateOrResyncDeployment()) { dataSourceDeploymentInfo = dataSourceProvider.resync(dataSourceDef, dataSourceDeploymentInfo); } else { throw new Exception("Data source: " + dataSourceDef + " is already deployed"); } } else if (driverDeploymentInfo != null) { dataSourceDeploymentInfo = dataSourceProvider.deploy(dataSourceDef); } else { throw new Exception("Required driver: " + dataSourceDef.getDriverUuid() + " is not deployed."); } if (driverDeploymentInfo != null && driverDeploymentCache.get(driverDeploymentInfo) != null) { driverDeploymentCache.get(driverDeploymentInfo).addDependant(dataSourceDeploymentInfo); } return dataSourceDeploymentInfo; } catch (Exception e) { logger.error("Data source deployment failed for dataSourceDef: " + dataSourceDef, e); throw e; } }
if (isEmpty(dataSourceDef.getDriverUuid())) { result.setMessage("A valid driver is required"); return result; driverDefInfo = dataSourceDefQueryService.findModuleDriver(dataSourceDef.getDriverUuid(), module.getRootPath()); } else { driverDefInfo = dataSourceDefQueryService.findGlobalDriver(dataSourceDef.getDriverUuid());
private void testDriverChange(boolean isValid) { if (isValid) { when(mainPanel.getDriver()).thenReturn(DRIVER_UUID); } else { when(mainPanel.getDriver()).thenReturn(null); } when(translationService.getTranslation( DataSourceManagementConstants.DataSourceDefEditor_DriverRequiredMessage)).thenReturn(ERROR); //emulates the helper receiving the change event editorHelper.onDriverChange(); if (isValid) { assertTrue(editorHelper.isDriverValid()); assertEquals(DRIVER_UUID, dataSourceDef.getDriverUuid()); verify(mainPanel, times(1)).clearDriverErrorMessage(); } else { assertFalse(editorHelper.isDriverValid()); assertNull(dataSourceDef.getDriverUuid()); verify(mainPanel, times(1)).setDriverErrorMessage(ERROR); } verify(handler, times(1)).onDriverChange(); }
@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()); }
try { if (!driverDeployed) { expectedException.expectMessage("Required driver: " + dataSourceDef.getDriverUuid() + " is not deployed."); runtimeManager.deployDataSource(dataSourceDef, options); } else { when(driverProvider.getDeploymentInfo(dataSourceDef.getDriverUuid())).thenReturn(driverDeploymentInfo);
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)).setUser(dataSourceDef.getUser()); verify(mainPanel, times(1)).setPassword(dataSourceDef.getPassword()); verify(mainPanel, times(1)).setDriver(dataSourceDef.getDriverUuid());
/** * Tests the un-deployment of a data source. */ @Test public void testUnDeployDataSource() { try { // emulates that the required driver is properly deployed. when(driverProvider.getDeploymentInfo(dataSourceDef.getDriverUuid())).thenReturn(driverDeploymentInfo); // simulate we have an already deployed data source deployDataSource(dataSourceDef); DataSourceDeploymentInfo deploymentInfo = runtimeManager.getDataSourceDeploymentInfo(dataSourceDef.getUuid()); assertNotNull(deploymentInfo); runtimeManager.unDeployDataSource(deploymentInfo, UnDeploymentOptions.forcedUnDeployment()); when(dataSourceProvider.getDeploymentInfo(dataSourceDef.getUuid())).thenReturn(null); // the data source should have been un-deployed with the provider. verify(dataSourceProvider, times(1)).undeploy(dataSourceDeploymentInfo); deploymentInfo = runtimeManager.getDataSourceDeploymentInfo(dataSourceDef.getUuid()); // no deployment info should exist assertNull(deploymentInfo); } catch (Exception e) { fail(e.getMessage()); } }
private void testLookupDataSource(boolean isDeployed) { try { if (isDeployed) { // emulates that the required driver is properly deployed. when(driverProvider.getDeploymentInfo(dataSourceDef.getDriverUuid())).thenReturn(driverDeploymentInfo); // deploy the data source. deployDataSource(dataSourceDef); // the data source should exist. DataSource dataSource = runtimeManager.lookupDataSource(dataSourceDef.getUuid()); assertNotNull(dataSource); } else { expectedException.expectMessage("Data source: " + dataSourceDef.getUuid() + " is not deployed in current system."); runtimeManager.lookupDataSource(dataSourceDef.getUuid()); } } catch (Exception e) { fail(e.getMessage()); } }
/** * Tests a data source deployment attempt in the case when the required driver is not deployed. */ @Test public void testDeployDataSourceWithMissingDriver( ) throws Exception { // an exception should have been thrown. expectedException.expectMessage( "Required driver: " + dataSourceDef.getDriverUuid( ) + " is not deployed" ); dataSourceProvider.deploy( dataSourceDef ); DataSourceDeploymentInfo deploymentInfo = dataSourceProvider.getDeploymentInfo( dataSourceDef.getUuid( ) ); assertNull( deploymentInfo ); }
@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 ); } } ); }