Skip to content

Commit

Permalink
[TEST] - More load/save tests for step metas
Browse files Browse the repository at this point in the history
  • Loading branch information
mbatchelor committed May 20, 2016
1 parent 961577a commit 1e98194
Show file tree
Hide file tree
Showing 20 changed files with 873 additions and 127 deletions.
35 changes: 23 additions & 12 deletions engine/src/org/pentaho/di/trans/steps/checksum/CheckSumMeta.java
Expand Up @@ -59,25 +59,13 @@
public class CheckSumMeta extends BaseStepMeta implements StepMetaInterface { public class CheckSumMeta extends BaseStepMeta implements StepMetaInterface {
private static Class<?> PKG = CheckSumMeta.class; // for i18n purposes, needed by Translator2!! private static Class<?> PKG = CheckSumMeta.class; // for i18n purposes, needed by Translator2!!


/** by which fields to display? */
private String[] fieldName;

private String resultfieldName;

public static final String TYPE_CRC32 = "CRC32"; public static final String TYPE_CRC32 = "CRC32";
public static final String TYPE_ADLER32 = "ADLER32"; public static final String TYPE_ADLER32 = "ADLER32";
public static final String TYPE_MD5 = "MD5"; public static final String TYPE_MD5 = "MD5";
public static final String TYPE_SHA1 = "SHA-1"; public static final String TYPE_SHA1 = "SHA-1";


public static String[] checksumtypeCodes = { TYPE_CRC32, TYPE_ADLER32, TYPE_MD5, TYPE_SHA1 }; public static String[] checksumtypeCodes = { TYPE_CRC32, TYPE_ADLER32, TYPE_MD5, TYPE_SHA1 };


private String checksumtype;

private boolean compatibilityMode;

/** result type */
private int resultType;

/** /**
* The result type description * The result type description
*/ */
Expand All @@ -94,6 +82,18 @@ public class CheckSumMeta extends BaseStepMeta implements StepMetaInterface {
public static final int result_TYPE_HEXADECIMAL = 1; public static final int result_TYPE_HEXADECIMAL = 1;
public static final int result_TYPE_BINARY = 2; public static final int result_TYPE_BINARY = 2;


/** by which fields to display? */
private String[] fieldName;

private String resultfieldName;

private String checksumtype;

private boolean compatibilityMode;

/** result type */
private int resultType;

public CheckSumMeta() { public CheckSumMeta() {
super(); // allocate BaseStepMeta super(); // allocate BaseStepMeta
} }
Expand Down Expand Up @@ -180,10 +180,12 @@ public void setResultFieldName( String resultfieldName ) {
this.resultfieldName = resultfieldName; this.resultfieldName = resultfieldName;
} }


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


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


Expand Down Expand Up @@ -249,6 +251,7 @@ private static String getResultTypeCode( int i ) {
return resultTypeCode[i]; return resultTypeCode[i];
} }


@Override
public String getXML() { public String getXML() {
StringBuilder retval = new StringBuilder( 200 ); StringBuilder retval = new StringBuilder( 200 );
retval.append( " " ).append( XMLHandler.addTagValue( "checksumtype", checksumtype ) ); retval.append( " " ).append( XMLHandler.addTagValue( "checksumtype", checksumtype ) );
Expand All @@ -267,6 +270,7 @@ public String getXML() {
return retval.toString(); return retval.toString();
} }


@Override
public void setDefault() { public void setDefault() {
resultfieldName = null; resultfieldName = null;
checksumtype = checksumtypeCodes[0]; checksumtype = checksumtypeCodes[0];
Expand All @@ -280,6 +284,7 @@ public void setDefault() {
} }
} }


@Override
public void readRep( Repository rep, IMetaStore metaStore, ObjectId id_step, List<DatabaseMeta> databases ) throws KettleException { public void readRep( Repository rep, IMetaStore metaStore, ObjectId id_step, List<DatabaseMeta> databases ) throws KettleException {
try { try {
checksumtype = rep.getStepAttributeString( id_step, "checksumtype" ); checksumtype = rep.getStepAttributeString( id_step, "checksumtype" );
Expand All @@ -300,6 +305,7 @@ 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 { public void saveRep( Repository rep, IMetaStore metaStore, ObjectId id_transformation, ObjectId id_step ) throws KettleException {
try { try {
rep.saveStepAttribute( id_transformation, id_step, "checksumtype", checksumtype ); rep.saveStepAttribute( id_transformation, id_step, "checksumtype", checksumtype );
Expand All @@ -316,6 +322,7 @@ public void saveRep( Repository rep, IMetaStore metaStore, ObjectId id_transform
} }
} }


@Override
public void getFields( RowMetaInterface inputRowMeta, String name, RowMetaInterface[] info, StepMeta nextStep, public void getFields( RowMetaInterface inputRowMeta, String name, RowMetaInterface[] info, StepMeta nextStep,
VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException { VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException {
// Output field (String) // Output field (String)
Expand All @@ -338,6 +345,7 @@ public void getFields( RowMetaInterface inputRowMeta, String name, RowMetaInterf
} }
} }


@Override
public void check( List<CheckResultInterface> remarks, TransMeta transMeta, StepMeta stepMeta, public void check( List<CheckResultInterface> remarks, TransMeta transMeta, StepMeta stepMeta,
RowMetaInterface prev, String[] input, String[] output, RowMetaInterface info, VariableSpace space, RowMetaInterface prev, String[] input, String[] output, RowMetaInterface info, VariableSpace space,
Repository repository, IMetaStore metaStore ) { Repository repository, IMetaStore metaStore ) {
Expand Down Expand Up @@ -410,15 +418,18 @@ public void check( List<CheckResultInterface> remarks, TransMeta transMeta, Step
} }
} }


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


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


@Override
public boolean supportsErrorHandling() { public boolean supportsErrorHandling() {
return true; return true;
} }
Expand Down
Expand Up @@ -2,7 +2,7 @@
* *
* Pentaho Data Integration * Pentaho Data Integration
* *
* Copyright (C) 2002-2015 by Pentaho : http://www.pentaho.com * Copyright (C) 2002-2016 by Pentaho : http://www.pentaho.com
* *
******************************************************************************* *******************************************************************************
* *
Expand Down Expand Up @@ -48,7 +48,6 @@ public void testRoundTrip() throws KettleException {
setterMap.put( "always_log_rows", "setAlwaysLogRows" ); setterMap.put( "always_log_rows", "setAlwaysLogRows" );


LoadSaveTester loadSaveTester = new LoadSaveTester( AbortMeta.class, attributes, getterMap, setterMap ); LoadSaveTester loadSaveTester = new LoadSaveTester( AbortMeta.class, attributes, getterMap, setterMap );
loadSaveTester.testRepoRoundTrip(); loadSaveTester.testSerialization();
loadSaveTester.testXmlRoundTrip();
} }
} }
Expand Up @@ -100,8 +100,7 @@ public void testRoundTrip() throws KettleException {


LoadSaveTester loadSaveTester = LoadSaveTester loadSaveTester =
new LoadSaveTester( AccessInputMeta.class, attributes, getterMap, setterMap, fieldValidators, typeValidators ); new LoadSaveTester( AccessInputMeta.class, attributes, getterMap, setterMap, fieldValidators, typeValidators );
loadSaveTester.testXmlRoundTrip(); loadSaveTester.testSerialization();
loadSaveTester.testRepoRoundTrip();
} }


public class FileRequiredLoadSaveValidator implements FieldLoadSaveValidator<String> { public class FileRequiredLoadSaveValidator implements FieldLoadSaveValidator<String> {
Expand Down
@@ -0,0 +1,63 @@
/*! ******************************************************************************
*
* 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.accessoutput;

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.FieldLoadSaveValidator;

public class AccessOutputMetaTest {
LoadSaveTester loadSaveTester;
Class<AccessOutputMeta> testMetaClass = AccessOutputMeta.class;

@Before
public void setUpLoadSave() throws Exception {
KettleEnvironment.init();
PluginRegistry.init( true );
List<String> attributes =
Arrays.asList( "filename", "fileCreated", "tablename", "tableCreated", "tableTruncated", "commitSize", "addToResultFiles", "DoNotOpenNewFileInit" );

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

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

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();
}
}
Expand Up @@ -55,7 +55,6 @@ public void testRoundTrip() throws KettleException {


LoadSaveTester loadSaveTester = LoadSaveTester loadSaveTester =
new LoadSaveTester( AddSequenceMeta.class, attributes, getterMap, setterMap, fieldValidators, typeValidators ); new LoadSaveTester( AddSequenceMeta.class, attributes, getterMap, setterMap, fieldValidators, typeValidators );
loadSaveTester.testXmlRoundTrip(); loadSaveTester.testSerialization();
loadSaveTester.testRepoRoundTrip();
} }
} }
Expand Up @@ -63,7 +63,6 @@ public void testRoundTrip() throws KettleException {


LoadSaveTester loadSaveTester = LoadSaveTester loadSaveTester =
new LoadSaveTester( AnalyticQueryMeta.class, attributes, getterMap, setterMap, fieldValidators, typeValidators ); new LoadSaveTester( AnalyticQueryMeta.class, attributes, getterMap, setterMap, fieldValidators, typeValidators );
loadSaveTester.testXmlRoundTrip(); loadSaveTester.testSerialization();
loadSaveTester.testRepoRoundTrip();
} }
} }
Expand Up @@ -2,7 +2,7 @@
* *
* Pentaho Data Integration * Pentaho Data Integration
* *
* Copyright (C) 2002-2015 by Pentaho : http://www.pentaho.com * Copyright (C) 2002-2016 by Pentaho : http://www.pentaho.com
* *
******************************************************************************* *******************************************************************************
* *
Expand Down Expand Up @@ -63,12 +63,7 @@ public void setUp() throws Exception {
} }


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

@Test
public void testLoadSaveRepo() throws KettleException {
loadSaveTester.testRepoRoundTrip();
} }
} }
Expand Up @@ -2,7 +2,7 @@
* *
* Pentaho Data Integration * Pentaho Data Integration
* *
* Copyright (C) 2002-2015 by Pentaho : http://www.pentaho.com * Copyright (C) 2002-2016 by Pentaho : http://www.pentaho.com
* *
******************************************************************************* *******************************************************************************
* *
Expand Down Expand Up @@ -57,7 +57,6 @@ public void testRoundTrip() throws KettleException {
setterMap.put( "compress", "setCompress" ); setterMap.put( "compress", "setCompress" );


LoadSaveTester loadSaveTester = new LoadSaveTester( BlockingStepMeta.class, attributes, getterMap, setterMap ); LoadSaveTester loadSaveTester = new LoadSaveTester( BlockingStepMeta.class, attributes, getterMap, setterMap );
loadSaveTester.testRepoRoundTrip(); loadSaveTester.testSerialization();
loadSaveTester.testXmlRoundTrip();
} }
} }
Expand Up @@ -21,11 +21,68 @@
******************************************************************************/ ******************************************************************************/
package org.pentaho.di.trans.steps.blockuntilstepsfinish; package org.pentaho.di.trans.steps.blockuntilstepsfinish;


import org.junit.Test; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import static org.junit.Assert.*; 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.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.StringLoadSaveValidator;

public class BlockUntilStepsFinishMetaTest implements InitializerInterface<StepMetaInterface> {
LoadSaveTester loadSaveTester;
Class<BlockUntilStepsFinishMeta> testMetaClass = BlockUntilStepsFinishMeta.class;

@Before
public void setUpLoadSave() throws Exception {
KettleEnvironment.init();
PluginRegistry.init( true );
List<String> attributes =
Arrays.asList( "stepName", "stepCopyNr" );

Map<String, String> getterMap = new HashMap<String, String>();
Map<String, String> setterMap = new HashMap<String, String>();
FieldLoadSaveValidator<String[]> stringArrayLoadSaveValidator =
new ArrayLoadSaveValidator<String>( new StringLoadSaveValidator(), 5 );



public class BlockUntilStepsFinishMetaTest { Map<String, FieldLoadSaveValidator<?>> attrValidatorMap = new HashMap<String, FieldLoadSaveValidator<?>>();
attrValidatorMap.put( "stepName", stringArrayLoadSaveValidator );
attrValidatorMap.put( "stepCopyNr", stringArrayLoadSaveValidator );

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 BlockUntilStepsFinishMeta ) {
( (BlockUntilStepsFinishMeta) someMeta ).allocate( 5 );
}
}

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


@Test @Test
public void cloneTest() throws Exception { public void cloneTest() throws Exception {
Expand Down

0 comments on commit 1e98194

Please sign in to comment.