/*! ******************************************************************************
*
* Pentaho Data Integration
*
* Copyright (C) 2002-2016 by Pentaho : 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.trans.steps.salesforce;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.junit.BeforeClass;
import org.junit.Test;
import org.mockito.Mockito;
import org.pentaho.di.core.CheckResult;
import org.pentaho.di.core.CheckResultInterface;
import org.pentaho.di.core.Const;
import org.pentaho.di.core.encryption.Encr;
import org.pentaho.di.core.encryption.TwoWayPasswordEncoderPluginType;
import org.pentaho.di.core.exception.KettleException;
import org.pentaho.di.core.plugins.PluginRegistry;
import org.pentaho.di.core.row.value.ValueMetaPluginType;
import org.pentaho.di.core.util.EnvUtil;
public class SalesforceMetaTest {
@BeforeClass
public static void setUpBeforeClass() throws KettleException {
PluginRegistry.addPluginType( ValueMetaPluginType.getInstance() );
PluginRegistry.addPluginType( TwoWayPasswordEncoderPluginType.getInstance() );
PluginRegistry.init( true );
String passwordEncoderPluginID =
Const.NVL( EnvUtil.getSystemProperty( Const.KETTLE_PASSWORD_ENCODER_PLUGIN ), "Kettle" );
Encr.init( passwordEncoderPluginID );
}
public static List<String> getDefaultAttributes() {
return Arrays.asList( "targetURL", "username", "password", "timeout", "compression", "module" );
}
@SuppressWarnings( "deprecation" )
@Test
public void testBaseCheck() {
SalesforceStepMeta meta = mock( SalesforceStepMeta.class, Mockito.CALLS_REAL_METHODS );
meta.setDefault();
List<CheckResultInterface> remarks = new ArrayList<CheckResultInterface>();
meta.check( remarks, null, null, null, null, null, null, null, null, null );
boolean hasError = false;
for ( CheckResultInterface cr : remarks ) {
if ( cr.getType() == CheckResult.TYPE_RESULT_ERROR ) {
hasError = true;
}
}
assertFalse( remarks.isEmpty() );
assertTrue( hasError );
remarks.clear();
meta.setDefault();
meta.setUsername( "anonymous" );
meta.check( remarks, null, null, null, null, null, null, null, null, null );
hasError = false;
for ( CheckResultInterface cr : remarks ) {
if ( cr.getType() == CheckResult.TYPE_RESULT_ERROR ) {
hasError = true;
}
}
assertFalse( remarks.isEmpty() );
assertFalse( hasError );
remarks.clear();
meta.setDefault();
meta.setTargetURL( null );
meta.setUserName( "anonymous" );
meta.setPassword( "password" );
meta.check( remarks, null, null, null, null, null, null, null, null, null );
hasError = false;
for ( CheckResultInterface cr : remarks ) {
if ( cr.getType() == CheckResult.TYPE_RESULT_ERROR ) {
hasError = true;
}
}
assertFalse( remarks.isEmpty() );
assertTrue( hasError );
remarks.clear();
meta.setDefault();
meta.setUsername( "anonymous" );
meta.setModule( null );
meta.check( remarks, null, null, null, null, null, null, null, null, null );
hasError = false;
for ( CheckResultInterface cr : remarks ) {
if ( cr.getType() == CheckResult.TYPE_RESULT_ERROR ) {
hasError = true;
}
}
assertFalse( remarks.isEmpty() );
assertTrue( hasError );
}
}