Skip to content

Commit

Permalink
Merge pull request pentaho#7390 from e-cuellar/DEV
Browse files Browse the repository at this point in the history
[PDI-18683] VFS connection is not created if edited while being created
  • Loading branch information
Corey Severino authored Apr 3, 2020
2 parents a68a858 + 3c6667a commit eebf5e3
Show file tree
Hide file tree
Showing 4 changed files with 265 additions and 0 deletions.
7 changes: 7 additions & 0 deletions plugins/connections/ui/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

<properties>
<maven-replacer-plugin.version>1.5.2</maven-replacer-plugin.version>
<mockito.version>1.9.5</mockito.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -98,6 +99,12 @@
<artifactId>jquery</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<resources>
Expand Down
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;
}
};
}
}
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;
}
}
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;
}
}

0 comments on commit eebf5e3

Please sign in to comment.