private void validateDriver(DriverDef driverDef) throws Exception { final URI uri = artifactResolver.resolve(driverDef.getGroupId(), driverDef.getArtifactId(), driverDef.getVersion()); if (uri == null) { throw new Exception("maven artifact was not found: " + driverDef.getGroupId() + ":" + driverDef.getArtifactId() + ":" + driverDef.getVersion()); } final URL[] urls = {uri.toURL()}; final URLClassLoader classLoader = new URLClassLoader(urls); try { Class driverClass = classLoader.loadClass(driverDef.getDriverClass()); if (!Driver.class.isAssignableFrom(driverClass)) { throw new Exception("class: " + driverDef.getDriverClass() + " do not extend from: " + Driver.class.getName()); } } catch (ClassNotFoundException e) { throw new Exception("driver class: " + driverDef.getDriverClass() + " was not found in current gav"); } } }
uri = artifactResolver.resolve(driverDef.getGroupId(), driverDef.getArtifactId(), driverDef.getVersion()); } catch (Exception e) { result.setMessage("Connection could not be tested due to the following error: " + e.getMessage()); + driverDef.getArtifactId() + ":" + driverDef.getVersion() + " was not found"); return result;
private void testVersionChange( boolean isValid ) { if ( isValid ) { when( mainPanel.getVersion() ).thenReturn( VERSION ); } else { when( mainPanel.getVersion() ).thenReturn( INVALID_VERSION ); } when( translationService.getTranslation( DataSourceManagementConstants.DriverDefEditor_InvalidVersionMessage ) ).thenReturn( ERROR ); //emulates the helper receiving the change event editorHelper.onVersionIdChange(); if ( isValid ) { assertTrue( editorHelper.isVersionValid() ); assertEquals( VERSION, driverDef.getVersion() ); verify( mainPanel, times( 1 ) ).clearVersionErrorMessage(); } else { assertFalse( editorHelper.isVersionValid() ); assertEquals( INVALID_VERSION, driverDef.getVersion() ); verify( mainPanel, times( 1 ) ).setVersionErrorMessage( ERROR ); } verify( handler, times( 1 ) ).onVersionChange(); }
@Test public void testLoadFileSuccessFul() { prepareLoadFileSuccessful(); //verifies the content was properly loaded and properly set on the UI verify( view, times( 1 ) ).showLoading(); verify( view, times( 1 ) ).hideBusyIndicator(); assertEquals( content, editor.getContent() ); verify( mainPanelView, times( 1 ) ).setName( content.getDef().getName() ); verify( mainPanelView, times( 1 ) ).setGroupId( content.getDef().getGroupId() ); verify( mainPanelView, times( 1 ) ).setArtifactId( content.getDef().getArtifactId() ); verify( mainPanelView, times( 1 ) ).setVersion( content.getDef().getVersion() ); verify( mainPanelView, times( 1 ) ).setDriverClass( content.getDef().getDriverClass() ); }
@Before public void setup() { clientValidationService = new ClientValidationServiceMock(); editorHelper = new DriverDefEditorHelper( translationService, clientValidationService ); editorHelper.setHandler( handler ); editorHelper.init( mainPanel ); driverDef = new DriverDef(); editorHelper.setDriverDef( driverDef ); verify( mainPanel, times( 1 ) ).clear(); verify( mainPanel, times( 1 ) ).setName( driverDef.getName() ); verify( mainPanel, times( 1 ) ).setDriverClass( driverDef.getDriverClass() ); verify( mainPanel, times( 1 ) ).setGroupId( driverDef.getGroupId() ); verify( mainPanel, times( 1 ) ).setArtifactId( driverDef.getArtifactId() ); verify( mainPanel, times( 1 ) ).setVersion( driverDef.getVersion() ); }
/** * Deploys a driver definition on the Wildfly server. * @param driverDef A driver definition to be deployed. * @return The deployment information for the just deployed driver. * @throws Exception exceptions may be thrown if was not possible to deploy the driver. */ public DriverDeploymentInfo deploy(final DriverDef driverDef) throws Exception { final URI uri = artifactResolver.resolve(driverDef.getGroupId(), driverDef.getArtifactId(), driverDef.getVersion()); if (uri == null) { throw new Exception("Unable to get driver library artifact for driver: " + driverDef); } String deploymentId = DeploymentIdGenerator.generateDeploymentId(driverDef); driverMgmtClient.deploy(deploymentId, uri); DriverDeploymentInfo generatedDeploymentInfo = findDeploymentInfo(deploymentId, driverDef); DriverDeploymentInfo deploymentInfo = new DriverDeploymentInfo(deploymentId, generatedDeploymentInfo.getDeploymentId(), true, driverDef.getUuid(), driverDef.getDriverClass()); managedDrivers.put(deploymentInfo.getDeploymentId(), deploymentInfo); return deploymentInfo; }
public void setDriverDef( DriverDef driverDef ) { this.driverDef = driverDef; mainPanel.clear(); mainPanel.setName( driverDef.getName() ); mainPanel.setDriverClass( driverDef.getDriverClass() ); mainPanel.setGroupId( driverDef.getGroupId() ); mainPanel.setArtifactId( driverDef.getArtifactId() ); mainPanel.setVersion( driverDef.getVersion() ); }
public void setup( ) throws Exception { driverDef1 = new DriverDef( ); driverDef1.setUuid( DRIVER1_UUID ); driverDef1.setName( DRIVER1_NAME ); driverDef1.setDriverClass( DRIVER1_CLASS ); driverDef1.setArtifactId( ARTIFACT_ID ); driverDef1.setGroupId( GROUP_ID ); driverDef1.setVersion( VERSION ); driver1Uri = new URI( "file:///maven_dir/driver1_file.jar" ); when( artifactResolver.resolve( driverDef1.getGroupId( ), driverDef1.getArtifactId( ), driverDef1.getVersion( ) ) ) .thenReturn( driver1Uri ); }
public boolean validate( DriverDef driverDef ) { return hasValue( driverDef.getUuid( ) ) && hasValue( driverDef.getName( ) ) && hasValue( driverDef.getDriverClass( ) ) && hasValue( driverDef.getArtifactId( ) ) && hasValue( driverDef.getGroupId( ) ) && hasValue( driverDef.getVersion( ) ); }
/** * Tests the case where the user completes the page by entering correct values. */ @Test public void testValidCompletion() { //emulates the user completing the page by typing valid values in all fields. completeValidDefPage(); //modification event should have been fired. verify( statusChangeEvent, times( 5 ) ).fire( any( WizardPageStatusChangeEvent.class ) ); //the DriverDef should have been populated assertEquals( NAME, driverDef.getName() ); assertEquals( GROUP_ID, driverDef.getGroupId() ); assertEquals( ARTIFACT_ID, driverDef.getArtifactId() ); assertEquals( VERSION, driverDef.getVersion() ); assertEquals( DRIVER_CLASS, driverDef.getDriverClass() ); //the page should be in completed state. defPage.isComplete( new Callback<Boolean>() { @Override public void callback( Boolean result ) { assertTrue( result ); } } ); }
@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.getDriverClass() ).thenReturn( DRIVER_CLASS_2 ); when( mainPanelView.getGroupId() ).thenReturn( GROUP_ID_2 ); when( mainPanelView.getArtifactId() ).thenReturn( ARTIFACT_ID_2 ); when( mainPanelView.getVersion() ).thenReturn( VERSION_2 ); mainPanel.onNameChange(); mainPanel.onDriverClassChange(); mainPanel.onGroupIdChange(); mainPanel.onArtifactIdChange(); mainPanel.onVersionChange(); //the content of the editor should have been properly modified. assertEquals( NAME_2, editor.getContent().getDef().getName() ); assertEquals( GROUP_ID_2, editor.getContent().getDef().getGroupId() ); assertEquals( ARTIFACT_ID_2, editor.getContent().getDef().getArtifactId() ); assertEquals( VERSION_2, editor.getContent().getDef().getVersion() ); assertEquals( DRIVER_CLASS_2, editor.getContent().getDef().getDriverClass() ); }
when(artifactResolver.resolve(driverDef.getGroupId(), driverDef.getArtifactId(), driverDef.getVersion())).thenReturn(uri); } catch (Exception e) { fail(e.getMessage());