Skip to content

Commit

Permalink
[TEST] - More load/save tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mbatchelor committed May 24, 2016
1 parent bcfd980 commit 8c45fac
Show file tree
Hide file tree
Showing 9 changed files with 263 additions and 72 deletions.
22 changes: 20 additions & 2 deletions engine/src/org/pentaho/di/trans/steps/joinrows/JoinRowsMeta.java
Expand Up @@ -165,10 +165,12 @@ public JoinRowsMeta() {
condition = new Condition();
}

@Override
public void loadXML( Node stepnode, List<DatabaseMeta> databases, IMetaStore metaStore ) throws KettleXMLException {
readData( stepnode );
}

@Override
public Object clone() {
JoinRowsMeta retval = (JoinRowsMeta) super.clone();

Expand Down Expand Up @@ -199,6 +201,7 @@ private void readData( Node stepnode ) throws KettleXMLException {
}
}

@Override
public void setDefault() {
directory = "%%java.io.tmpdir%%";
prefix = "out";
Expand All @@ -207,14 +210,18 @@ public void setDefault() {
mainStepname = null;
}

@Override
public String getXML() throws KettleException {
StringBuilder retval = new StringBuilder( 300 );

retval.append( " " ).append( XMLHandler.addTagValue( "directory", directory ) );
retval.append( " " ).append( XMLHandler.addTagValue( "prefix", prefix ) );
retval.append( " " ).append( XMLHandler.addTagValue( "cache_size", cacheSize ) );

retval.append( " " ).append( XMLHandler.addTagValue( "main", getLookupStepname() ) );
if ( mainStepname == null ) {
mainStepname = getLookupStepname();
}
retval.append( " " ).append( XMLHandler.addTagValue( "main", mainStepname ) );

retval.append( " <compare>" ).append( Const.CR );

Expand All @@ -227,6 +234,7 @@ public String getXML() throws KettleException {
return retval.toString();
}

@Override
public void readRep( Repository rep, IMetaStore metaStore, ObjectId id_step, List<DatabaseMeta> databases ) throws KettleException {
try {
directory = rep.getStepAttributeString( id_step, "directory" );
Expand All @@ -245,13 +253,17 @@ public void readRep( Repository rep, IMetaStore metaStore, ObjectId id_step, Lis
}
}

@Override
public void saveRep( Repository rep, IMetaStore metaStore, ObjectId id_transformation, ObjectId id_step ) throws KettleException {
try {
rep.saveStepAttribute( id_transformation, id_step, "directory", directory );
rep.saveStepAttribute( id_transformation, id_step, "prefix", prefix );
rep.saveStepAttribute( id_transformation, id_step, "cache_size", cacheSize );

rep.saveStepAttribute( id_transformation, id_step, "main", getLookupStepname() );
if ( mainStepname == null ) {
mainStepname = getLookupStepname();
}
rep.saveStepAttribute( id_transformation, id_step, "main", mainStepname );

rep.saveConditionStepAttribute( id_transformation, id_step, "id_condition", condition );
} catch ( Exception e ) {
Expand All @@ -261,6 +273,7 @@ public void saveRep( Repository rep, IMetaStore metaStore, ObjectId id_transform
}
}

@Override
public void getFields( RowMetaInterface rowMeta, String origin, RowMetaInterface[] info, StepMeta nextStep,
VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException {
if ( space instanceof TransMeta ) {
Expand All @@ -279,6 +292,7 @@ public void getFields( RowMetaInterface rowMeta, String origin, RowMetaInterface
}
}

@Override
public void check( List<CheckResultInterface> remarks, TransMeta transMeta, StepMeta stepMeta,
RowMetaInterface prev, String[] input, String[] output, RowMetaInterface info, VariableSpace space,
Repository repository, IMetaStore metaStore ) {
Expand Down Expand Up @@ -346,19 +360,23 @@ public String getLookupStepname() {
* @param steps
* optionally search the info step in a list of steps
*/
@Override
public void searchInfoAndTargetSteps( List<StepMeta> steps ) {
mainStep = StepMeta.findStep( steps, mainStepname );
}

@Override
public StepInterface getStep( StepMeta stepMeta, StepDataInterface stepDataInterface, int cnr,
TransMeta transMeta, Trans trans ) {
return new JoinRows( stepMeta, stepDataInterface, cnr, transMeta, trans );
}

@Override
public StepDataInterface getStepData() {
return new JoinRowsData();
}

@Override
public boolean excludeFromRowLayoutVerification() {
return true;
}
Expand Down
Expand Up @@ -26,7 +26,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

import org.junit.Before;
import org.junit.Test;
Expand All @@ -37,6 +36,7 @@
import org.pentaho.di.trans.steps.loadsave.validator.ArrayLoadSaveValidator;
import org.pentaho.di.trans.steps.loadsave.validator.FieldLoadSaveValidator;
import org.pentaho.di.trans.steps.loadsave.validator.StringLoadSaveValidator;
import org.pentaho.di.trans.steps.loadsave.validator.YNLoadSaveValidator;

public class GetFilesRowsCountMetaTest implements InitializerInterface<StepMetaInterface> {

Expand Down Expand Up @@ -114,20 +114,4 @@ public void testLoadSaveXML() throws KettleException {
}

// Note - cloneTest() removed as it's now covered by the load/save tester.

public class YNLoadSaveValidator implements FieldLoadSaveValidator<String> {
Random r = new Random();

@Override
public String getTestObject() {
boolean ltr = r.nextBoolean();
String letter = ltr ? "Y" : "N";
return letter;
}

@Override
public boolean validateTestObject( String test, Object actual ) {
return test.equals( actual );
}
}
}
@@ -0,0 +1,65 @@
/*! ******************************************************************************
*
* 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.joinrows;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.Before;
import org.junit.Test;
import org.pentaho.di.core.KettleEnvironment;
import org.pentaho.di.core.exception.KettleException;
import org.pentaho.di.core.plugins.PluginRegistry;
import org.pentaho.di.trans.steps.loadsave.LoadSaveTester;
import org.pentaho.di.trans.steps.loadsave.validator.ConditionLoadSaveValidator;
import org.pentaho.di.trans.steps.loadsave.validator.FieldLoadSaveValidator;

public class JoinRowsMetaTest {
LoadSaveTester loadSaveTester;
Class<JoinRowsMeta> testMetaClass = JoinRowsMeta.class;

@Before
public void setUpLoadSave() throws Exception {
KettleEnvironment.init();
PluginRegistry.init( true );
List<String> attributes =
Arrays.asList( "directory", "prefix", "cacheSize", "mainStepname", "condition" );

Map<String, String> getterMap = new HashMap<String, String>();
Map<String, String> setterMap = new HashMap<String, String>();

Map<String, FieldLoadSaveValidator<?>> attrValidatorMap = new HashMap<String, FieldLoadSaveValidator<?>>();
attrValidatorMap.put( "condition", new ConditionLoadSaveValidator() );

Map<String, FieldLoadSaveValidator<?>> typeValidatorMap = new HashMap<String, FieldLoadSaveValidator<?>>();

loadSaveTester =
new LoadSaveTester( testMetaClass, attributes, getterMap, setterMap, attrValidatorMap, typeValidatorMap );
}

@Test
public void testSerialization() throws KettleException {
loadSaveTester.testSerialization();
}
}
@@ -0,0 +1,138 @@
/*! ******************************************************************************
*
* 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.ldapinput;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.UUID;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.junit.Before;
import org.junit.Test;
import org.pentaho.di.core.KettleEnvironment;
import org.pentaho.di.core.exception.KettleException;
import org.pentaho.di.core.plugins.PluginRegistry;
import org.pentaho.di.trans.step.StepMetaInterface;
import org.pentaho.di.trans.steps.loadsave.LoadSaveTester;
import org.pentaho.di.trans.steps.loadsave.initializer.InitializerInterface;
import org.pentaho.di.trans.steps.loadsave.validator.ArrayLoadSaveValidator;
import org.pentaho.di.trans.steps.loadsave.validator.FieldLoadSaveValidator;
import org.pentaho.di.trans.steps.loadsave.validator.IntLoadSaveValidator;

public class LDAPInputMetaTest implements InitializerInterface<StepMetaInterface> {
LoadSaveTester loadSaveTester;
Class<LDAPInputMeta> testMetaClass = LDAPInputMeta.class;

@Before
public void setUpLoadSave() throws Exception {
KettleEnvironment.init();
PluginRegistry.init( true );
List<String> attributes =
Arrays.asList( "useAuthentication", "paging", "pageSize", "includeRowNumber", "rowNumberField", "rowLimit", "Host", "userName",
"password", "port", "filterString", "searchBase", "timeLimit", "multiValuedSeparator", "dynamicSearch", "dynamicSearchFieldName",
"dynamicFilter", "dynamicFilterFieldName", "searchScope", "protocol", "useCertificate", "trustStorePath", "trustStorePassword",
"trustAllCertificates", "inputFields" );

Map<String, String> getterMap = new HashMap<String, String>() {
{
put( "useAuthentication", "UseAuthentication" );
put( "includeRowNumber", "includeRowNumber" );
}
};

Map<String, String> setterMap = new HashMap<String, String>();

Map<String, FieldLoadSaveValidator<?>> attrValidatorMap = new HashMap<String, FieldLoadSaveValidator<?>>();
attrValidatorMap.put( "inputFields",
new ArrayLoadSaveValidator<LDAPInputField>( new LDAPInputFieldLoadSaveValidator(), 5 ) );
attrValidatorMap.put( "searchScope", new IntLoadSaveValidator( LDAPInputMeta.searchScopeCode.length ) );

Map<String, FieldLoadSaveValidator<?>> typeValidatorMap = new HashMap<String, FieldLoadSaveValidator<?>>();

loadSaveTester =
new LoadSaveTester( testMetaClass, attributes, new ArrayList<String>(), new ArrayList<String>(),
getterMap, setterMap, attrValidatorMap, typeValidatorMap, this );
}

// Call the allocate method on the LoadSaveTester meta class
@Override
public void modify( StepMetaInterface someMeta ) {
if ( someMeta instanceof LDAPInputMeta ) {
( (LDAPInputMeta) someMeta ).allocate( 5 );
}
}

@Test
public void testSerialization() throws KettleException {
loadSaveTester.testSerialization();
}


public class LDAPInputFieldLoadSaveValidator implements FieldLoadSaveValidator<LDAPInputField> {
final Random rand = new Random();
@Override
public LDAPInputField getTestObject() {
LDAPInputField rtn = new LDAPInputField();
rtn.setCurrencySymbol( UUID.randomUUID().toString() );
rtn.setDecimalSymbol( UUID.randomUUID().toString() );
rtn.setFormat( UUID.randomUUID().toString() );
rtn.setGroupSymbol( UUID.randomUUID().toString() );
rtn.setName( UUID.randomUUID().toString() );
rtn.setTrimType( rand.nextInt( 4 ) );
rtn.setPrecision( rand.nextInt( 9 ) );
rtn.setRepeated( rand.nextBoolean() );
rtn.setLength( rand.nextInt( 50 ) );
rtn.setType( rand.nextInt( 7 ) );
rtn.setSortedKey( rand.nextBoolean() );
rtn.setFetchAttributeAs( rand.nextInt( LDAPInputField.FetchAttributeAsCode.length ) );
rtn.setAttribute( UUID.randomUUID().toString() );
return rtn;
}

@Override
public boolean validateTestObject( LDAPInputField testObject, Object actual ) {
if ( !( actual instanceof LDAPInputField ) ) {
return false;
}
LDAPInputField another = (LDAPInputField) actual;
return new EqualsBuilder()
.append( testObject.getName(), another.getName() )
.append( testObject.getAttribute(), another.getAttribute() )
.append( testObject.getReturnType(), another.getReturnType() )
.append( testObject.getType(), another.getType() )
.append( testObject.getLength(), another.getLength() )
.append( testObject.getFormat(), another.getFormat() )
.append( testObject.getTrimType(), another.getTrimType() )
.append( testObject.getPrecision(), another.getPrecision() )
.append( testObject.getCurrencySymbol(), another.getCurrencySymbol() )
.append( testObject.getDecimalSymbol(), another.getDecimalSymbol() )
.append( testObject.getGroupSymbol(), another.getGroupSymbol() )
.append( testObject.isRepeated(), another.isRepeated() )
.append( testObject.isSortedKey(), another.isSortedKey() )
.isEquals();
}
}
}
Expand Up @@ -104,8 +104,6 @@ public void setUp() throws Exception {
attrValidatorMap.put( "operationType", new IntLoadSaveValidator( 5 ) );

Map<String, FieldLoadSaveValidator<?>> typeValidatorMap = new HashMap<String, FieldLoadSaveValidator<?>>();
// typeValidatorMap.put( int[].class.getCanonicalName(), new PrimitiveIntArrayLoadSaveValidator( new IntLoadSaveValidator(), 3 ) );
// typeValidatorMap.put( boolean[].class.getCanonicalName(), new PrimitiveBooleanArrayLoadSaveValidator( new BooleanLoadSaveValidator(), 3 ) );

loadSaveTester = new LoadSaveTester( LDAPOutputMeta.class, attributes, getterMap, setterMap, attrValidatorMap, typeValidatorMap );

Expand All @@ -117,13 +115,8 @@ public void setUp() throws Exception {
}

@Test
public void testLoadSaveXML() throws KettleException {
loadSaveTester.testXmlRoundTrip();
}

@Test
public void testLoadSaveRepo() throws KettleException {
loadSaveTester.testRepoRoundTrip();
public void testSerialization() throws KettleException {
loadSaveTester.testSerialization();
}

}

0 comments on commit 8c45fac

Please sign in to comment.