Skip to content

Commit

Permalink
[TEST] - New load/save test, fix date
Browse files Browse the repository at this point in the history
  • Loading branch information
mbatchelor committed May 25, 2016
1 parent d3a348f commit 317c14c
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 23 deletions.
Expand Up @@ -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
*
*******************************************************************************
*
Expand Down
@@ -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<String> attributes = Arrays.asList( "databaseMeta", "SQL", "catalog", "role" );

Map<String, String> getterMap = new HashMap<String, String>();
Map<String, String> setterMap = new HashMap<String, String>();
LoadSaveTester loadSaveTester = new LoadSaveTester( MondrianInputMeta.class, attributes, getterMap, setterMap );
loadSaveTester.testSerialization();
}

}
Expand Up @@ -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;
Expand All @@ -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<StepMetaInterface> {

private StepMeta stepMeta;
private MonetDBBulkLoader loader;
private MonetDBBulkLoaderData ld;
private MonetDBBulkLoaderMeta lm;
LoadSaveTester loadSaveTester;
Class<MonetDBBulkLoaderMeta> testMetaClass = MonetDBBulkLoaderMeta.class;

@BeforeClass
public static void setUpBeforeClass() throws Exception {
Expand All @@ -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" );

Expand All @@ -72,6 +92,45 @@ public void setUp() {
transMeta.addStep( stepMeta );

loader = new MonetDBBulkLoader( stepMeta, ld, 1, transMeta, trans );

List<String> 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<String[]> stringArrayLoadSaveValidator =
new ArrayLoadSaveValidator<String>( new StringLoadSaveValidator(), 5 );


Map<String, FieldLoadSaveValidator<?>> attrValidatorMap = new HashMap<String, FieldLoadSaveValidator<?>>();
attrValidatorMap.put( "fieldTable", stringArrayLoadSaveValidator );
attrValidatorMap.put( "fieldStream", stringArrayLoadSaveValidator );
attrValidatorMap.put( "fieldFormatOk",
new PrimitiveBooleanArrayLoadSaveValidator( new BooleanLoadSaveValidator(), 5 ) );

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

loadSaveTester =
new LoadSaveTester( testMetaClass, attributes, new ArrayList<String>(), new ArrayList<String>(),
new HashMap<String, String>(), new HashMap<String, String>(), 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
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 317c14c

Please sign in to comment.