forked from pentaho/pentaho-kettle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request pentaho#7390 from e-cuellar/DEV
[PDI-18683] VFS connection is not created if edited while being created
- Loading branch information
Showing
4 changed files
with
265 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
...s/connections/ui/src/test/java/org/pentaho/di/connections/ui/ConnectionEndpointsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/*! ****************************************************************************** | ||
* | ||
* Pentaho Data Integration | ||
* | ||
* Copyright (C) 2020 by Hitachi Vantara : http://www.pentaho.com | ||
* | ||
******************************************************************************* | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
******************************************************************************/ | ||
|
||
package org.pentaho.di.connections.ui; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.pentaho.di.connections.ConnectionManager; | ||
import org.pentaho.di.connections.ui.endpoints.ConnectionEndpoints; | ||
import org.pentaho.di.core.KettleClientEnvironment; | ||
import org.pentaho.metastore.api.IMetaStore; | ||
import org.pentaho.metastore.stores.memory.MemoryMetaStore; | ||
import org.pentaho.osgi.metastore.locator.api.MetastoreLocator; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import javax.ws.rs.core.Response; | ||
|
||
public class ConnectionEndpointsTest { | ||
|
||
private ConnectionManager connectionManager = ConnectionManager.getInstance(); | ||
private MemoryMetaStore memoryMetaStore = new MemoryMetaStore(); | ||
private static String DESCRIPTION = "Connection Description"; | ||
private static String CONNECTION_NAME = "Connection Name"; | ||
private static String PASSWORD = "testpassword"; | ||
private static String PASSWORD2 = "testpassword2"; | ||
|
||
@Before | ||
public void setup() throws Exception { | ||
KettleClientEnvironment.init(); | ||
connectionManager.setMetastoreSupplier( () -> memoryMetaStore ); | ||
} | ||
|
||
@Test | ||
public void createConnection() { | ||
addProvider(); | ||
ConnectionEndpoints connectionEndpoints = new ConnectionEndpoints( getMetaStoreLocator() ); | ||
try { | ||
connectionEndpoints.createConnection( getConnectionDetails(), CONNECTION_NAME ); | ||
} catch ( Exception e ) { | ||
// Bypass exceptions thrown by lack of getSpoon().getShell().getDisplay() since we are not running the UI | ||
} | ||
|
||
Response response = connectionEndpoints.getConnectionExists( CONNECTION_NAME ); | ||
assertEquals( "true", response.getEntity() ); | ||
} | ||
|
||
private void addProvider() { | ||
TestConnectionProvider testConnectionProvider = new TestConnectionProvider( connectionManager ); | ||
connectionManager.addConnectionProvider( TestConnectionProvider.SCHEME, testConnectionProvider ); | ||
} | ||
|
||
private TestConnectionDetails getConnectionDetails() { | ||
TestConnectionDetails testConnectionDetails = new TestConnectionDetails(); | ||
testConnectionDetails.setDescription( DESCRIPTION ); | ||
testConnectionDetails.setName( CONNECTION_NAME ); | ||
testConnectionDetails.setPassword( PASSWORD ); | ||
testConnectionDetails.setPassword1( PASSWORD2 ); | ||
return testConnectionDetails; | ||
} | ||
|
||
private MetastoreLocator getMetaStoreLocator() { | ||
return new MetastoreLocator() { | ||
@Override public IMetaStore getMetastore() { | ||
return memoryMetaStore; | ||
} | ||
|
||
@Override public IMetaStore getMetastore( String s ) { | ||
return null; | ||
} | ||
|
||
@Override public String setEmbeddedMetastore( IMetaStore iMetaStore ) { | ||
return null; | ||
} | ||
|
||
@Override public void disposeMetastoreProvider( String s ) { | ||
} | ||
|
||
@Override public IMetaStore getExplicitMetastore( String s ) { | ||
return null; | ||
} | ||
}; | ||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
...ins/connections/ui/src/test/java/org/pentaho/di/connections/ui/TestConnectionDetails.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/*! ****************************************************************************** | ||
* | ||
* Pentaho Data Integration | ||
* | ||
* Copyright (C) 2020 by Hitachi Vantara : http://www.pentaho.com | ||
* | ||
******************************************************************************* | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
******************************************************************************/ | ||
|
||
package org.pentaho.di.connections.ui; | ||
|
||
import org.pentaho.di.connections.annotations.Encrypted; | ||
import org.pentaho.di.connections.vfs.VFSConnectionDetails; | ||
import org.pentaho.metastore.persist.MetaStoreAttribute; | ||
import org.pentaho.metastore.persist.MetaStoreElementType; | ||
|
||
@MetaStoreElementType( | ||
name = "Test VFS Connection", | ||
description = "Defines the connection details for a test vfs connection" ) | ||
public class TestConnectionDetails implements VFSConnectionDetails { | ||
|
||
private static String TYPE = "test"; | ||
|
||
@MetaStoreAttribute | ||
private String name; | ||
|
||
@MetaStoreAttribute | ||
private String description; | ||
|
||
@Encrypted | ||
@MetaStoreAttribute | ||
private String password; | ||
|
||
@Encrypted | ||
@MetaStoreAttribute | ||
private String password1; | ||
|
||
@Override public String getName() { | ||
return name; | ||
} | ||
|
||
@Override public void setName( String name ) { | ||
this.name = name; | ||
} | ||
|
||
@Override public String getType() { | ||
return TYPE; | ||
} | ||
|
||
@Override public String getDescription() { | ||
return description; | ||
} | ||
|
||
public void setDescription( String description ) { | ||
this.description = description; | ||
} | ||
|
||
public String getPassword() { | ||
return password; | ||
} | ||
|
||
public void setPassword( String password ) { | ||
this.password = password; | ||
} | ||
|
||
public String getPassword1() { | ||
return password1; | ||
} | ||
|
||
public void setPassword1( String password1 ) { | ||
this.password1 = password1; | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
...ns/connections/ui/src/test/java/org/pentaho/di/connections/ui/TestConnectionProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/*! ****************************************************************************** | ||
* | ||
* Pentaho Data Integration | ||
* | ||
* Copyright (C) 2020 by Hitachi Vantara : http://www.pentaho.com | ||
* | ||
******************************************************************************* | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
******************************************************************************/ | ||
|
||
package org.pentaho.di.connections.ui; | ||
|
||
import org.pentaho.di.connections.ConnectionManager; | ||
import org.pentaho.di.connections.ConnectionProvider; | ||
|
||
import java.util.List; | ||
|
||
public class TestConnectionProvider implements ConnectionProvider<TestConnectionDetails> { | ||
|
||
private ConnectionManager connectionManager; | ||
|
||
public TestConnectionProvider( ConnectionManager connectionManager ) { | ||
this.connectionManager = connectionManager; | ||
} | ||
|
||
public static final String NAME = "Test"; | ||
public static final String SCHEME = "test"; | ||
|
||
@Override public String getName() { | ||
return NAME; | ||
} | ||
|
||
@Override public String getKey() { | ||
return SCHEME; | ||
} | ||
|
||
@Override public Class<TestConnectionDetails> getClassType() { | ||
return TestConnectionDetails.class; | ||
} | ||
|
||
@Override public List<String> getNames() { | ||
return connectionManager.getNamesByType( getClass() ); | ||
} | ||
|
||
@SuppressWarnings( "unchecked" ) | ||
@Override public List<TestConnectionDetails> getConnectionDetails() { | ||
return (List<TestConnectionDetails>) connectionManager.getConnectionDetailsByScheme( getKey() ); | ||
} | ||
|
||
@Override public boolean test( TestConnectionDetails connectionDetails ) { | ||
return true; | ||
} | ||
|
||
@Override public TestConnectionDetails prepare( TestConnectionDetails connectionDetails ) { | ||
return connectionDetails; | ||
} | ||
} |