diff --git a/engine/src/org/pentaho/di/trans/steps/metainject/MetaInjectMeta.java b/engine/src/org/pentaho/di/trans/steps/metainject/MetaInjectMeta.java index 4e454195450f..7bde0c0a04b1 100644 --- a/engine/src/org/pentaho/di/trans/steps/metainject/MetaInjectMeta.java +++ b/engine/src/org/pentaho/di/trans/steps/metainject/MetaInjectMeta.java @@ -2,7 +2,7 @@ * * Pentaho Data Integration * - * Copyright (C) 2002-2013 by Pentaho : http://www.pentaho.com + * Copyright (C) 2002-2016 by Pentaho : http://www.pentaho.com * ******************************************************************************* * diff --git a/engine/test-src/org/pentaho/di/trans/steps/mondrianinput/MondrianInputMetaTest.java b/engine/test-src/org/pentaho/di/trans/steps/mondrianinput/MondrianInputMetaTest.java new file mode 100644 index 000000000000..2f8d4f58264f --- /dev/null +++ b/engine/test-src/org/pentaho/di/trans/steps/mondrianinput/MondrianInputMetaTest.java @@ -0,0 +1,48 @@ +/*! ****************************************************************************** + * + * 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.mondrianinput; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +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; + +public class MondrianInputMetaTest { + + @Test + public void testStepMeta() throws KettleException { + KettleEnvironment.init(); + PluginRegistry.init( true ); + List attributes = Arrays.asList( "databaseMeta", "SQL", "catalog", "role" ); + + Map getterMap = new HashMap(); + Map setterMap = new HashMap(); + LoadSaveTester loadSaveTester = new LoadSaveTester( MondrianInputMeta.class, attributes, getterMap, setterMap ); + loadSaveTester.testSerialization(); + } + +} diff --git a/engine/test-src/org/pentaho/di/trans/steps/monetdbbulkloader/MonetDBBulkLoaderMetaTest.java b/engine/test-src/org/pentaho/di/trans/steps/monetdbbulkloader/MonetDBBulkLoaderMetaTest.java index a55a4dbcfe0e..9218d0724ac5 100644 --- a/engine/test-src/org/pentaho/di/trans/steps/monetdbbulkloader/MonetDBBulkLoaderMetaTest.java +++ b/engine/test-src/org/pentaho/di/trans/steps/monetdbbulkloader/MonetDBBulkLoaderMetaTest.java @@ -21,9 +21,21 @@ ******************************************************************************/ package org.pentaho.di.trans.steps.monetdbbulkloader; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + import org.junit.Before; import org.junit.BeforeClass; 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.core.plugins.StepPluginType; @@ -33,21 +45,27 @@ import org.pentaho.di.trans.TransMeta; import org.pentaho.di.trans.step.StepInjectionMetaEntry; import org.pentaho.di.trans.step.StepMeta; +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.BooleanLoadSaveValidator; +import org.pentaho.di.trans.steps.loadsave.validator.FieldLoadSaveValidator; +import org.pentaho.di.trans.steps.loadsave.validator.PrimitiveBooleanArrayLoadSaveValidator; +import org.pentaho.di.trans.steps.loadsave.validator.StringLoadSaveValidator; -import java.util.Arrays; -import java.util.List; - -import static org.junit.Assert.*; /** * Created by gmoran on 2/25/14. */ -public class MonetDBBulkLoaderMetaTest { +public class MonetDBBulkLoaderMetaTest implements InitializerInterface { private StepMeta stepMeta; private MonetDBBulkLoader loader; private MonetDBBulkLoaderData ld; private MonetDBBulkLoaderMeta lm; + LoadSaveTester loadSaveTester; + Class testMetaClass = MonetDBBulkLoaderMeta.class; @BeforeClass public static void setUpBeforeClass() throws Exception { @@ -56,7 +74,9 @@ public static void setUpBeforeClass() throws Exception { } @Before - public void setUp() { + public void setUp() throws Exception { + KettleEnvironment.init(); + PluginRegistry.init( true ); TransMeta transMeta = new TransMeta(); transMeta.setName( "loader" ); @@ -72,6 +92,45 @@ public void setUp() { transMeta.addStep( stepMeta ); loader = new MonetDBBulkLoader( stepMeta, ld, 1, transMeta, trans ); + + List attributes = + Arrays.asList( "dbConnectionName", "schemaName", "tableName", "logFile", "fieldSeparator", "fieldEnclosure", + "NULLrepresentation", "encoding", "truncate", "fullyQuoteSQL", "autoSchema", "autoStringWidths", "fieldTable", "fieldStream", + "fieldFormatOk" ); + + // Important note - the "databaseMeta" is not tested here as it's tied to the dbConnectionName. Since the loader + // has assymetry here, we have to not test the databaseMeta, or we have to do surgery on the MonetDBBulkLoaderMeta + // so that it's symmetric (and has no dependent variables like this). + // MB -5/2016 + + FieldLoadSaveValidator stringArrayLoadSaveValidator = + new ArrayLoadSaveValidator( new StringLoadSaveValidator(), 5 ); + + + Map> attrValidatorMap = new HashMap>(); + attrValidatorMap.put( "fieldTable", stringArrayLoadSaveValidator ); + attrValidatorMap.put( "fieldStream", stringArrayLoadSaveValidator ); + attrValidatorMap.put( "fieldFormatOk", + new PrimitiveBooleanArrayLoadSaveValidator( new BooleanLoadSaveValidator(), 5 ) ); + + Map> typeValidatorMap = new HashMap>(); + + loadSaveTester = + new LoadSaveTester( testMetaClass, attributes, new ArrayList(), new ArrayList(), + new HashMap(), new HashMap(), attrValidatorMap, typeValidatorMap, this ); + } + + // Call the allocate method on the LoadSaveTester meta class + @Override + public void modify( StepMetaInterface someMeta ) { + if ( someMeta instanceof MonetDBBulkLoaderMeta ) { + ( (MonetDBBulkLoaderMeta) someMeta ).allocate( 5 ); + } + } + + @Test + public void testSerialization() throws KettleException { + loadSaveTester.testSerialization(); } @Test @@ -137,22 +196,7 @@ public void testChildLevelMetadataEntries() { } - @Test - public void cloneTest() throws Exception { - MonetDBBulkLoaderMeta meta = new MonetDBBulkLoaderMeta(); - meta.allocate( 2 ); - meta.setFieldTable( new String[] { "Table1", "Table2" } ); - meta.setFieldStream( new String[] { "Stream1", "Stream2" } ); - meta.setFieldFormatOk( new boolean[] { false, true } ); - // scalars should be cloned using super.clone() - makes sure they're calling super.clone() - meta.setLogFile( "somelogfile" ); - MonetDBBulkLoaderMeta aClone = (MonetDBBulkLoaderMeta) meta.clone(); - assertFalse( aClone == meta ); - assertTrue( Arrays.equals( meta.getFieldTable(), aClone.getFieldTable() ) ); - assertTrue( Arrays.equals( meta.getFieldStream(), aClone.getFieldStream() ) ); - assertTrue( Arrays.equals( meta.getFieldFormatOk(), aClone.getFieldFormatOk() ) ); - assertEquals( meta.getLogFile(), aClone.getLogFile() ); - } + // Note - the cloneTest() was removed since it's being covered by the load/save tester now. @Test public void testInjection() {