Skip to content

Commit

Permalink
[TEST] Tests for org.pentaho.di.core package
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel-sakun committed Dec 9, 2015
1 parent 001a0ab commit 39a4d3d
Show file tree
Hide file tree
Showing 18 changed files with 1,601 additions and 155 deletions.
209 changes: 100 additions & 109 deletions core/src/org/pentaho/di/core/Const.java

Large diffs are not rendered by default.

49 changes: 49 additions & 0 deletions core/test-src/org/pentaho/di/core/BlockingListeningRowSetTest.java
@@ -0,0 +1,49 @@
/*! ******************************************************************************
*
* Pentaho Data Integration
*
* Copyright (C) 2002-2015 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.core;

import org.junit.Test;
import org.pentaho.di.core.row.RowMeta;

import static org.junit.Assert.*;

public class BlockingListeningRowSetTest {
@Test
public void testClass() {
BlockingListeningRowSet rowSet = new BlockingListeningRowSet( 1 );
assertEquals( 0, rowSet.size() );
final Object[] row = new Object[]{};
final RowMeta meta = new RowMeta();
rowSet.putRow( meta, row );
assertSame( meta, rowSet.getRowMeta() );
assertEquals( 1, rowSet.size() );
assertFalse( rowSet.isBlocking() );
assertSame( row, rowSet.getRow() );
assertEquals( 0, rowSet.size() );
rowSet.putRow( meta, row );
assertSame( row, rowSet.getRowImmediate() );
rowSet.putRow( meta, row );
assertEquals( 1, rowSet.size() );
rowSet.clear();
assertEquals( 0, rowSet.size() );
}
}
65 changes: 65 additions & 0 deletions core/test-src/org/pentaho/di/core/CheckResultTest.java
@@ -0,0 +1,65 @@
/*! ******************************************************************************
*
* Pentaho Data Integration
*
* Copyright (C) 2002-2015 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.core;

import org.junit.Test;

import static org.junit.Assert.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class CheckResultTest {
@Test
public void testClass() {
final int type = CheckResultInterface.TYPE_RESULT_ERROR;
final String text = "some text";
final String sourceMetaName = "meta name";
final CheckResultSourceInterface sourceMeta = mock( CheckResultSourceInterface.class );
final String errorCode = "error code";

CheckResult cr = new CheckResult();
assertEquals( CheckResultInterface.TYPE_RESULT_NONE, cr.getType() );
assertTrue( cr.getTypeDesc() != null && cr.getTypeDesc().isEmpty() );
cr.setType( type );
assertEquals( type, cr.getType() );

assertTrue( cr.getText().isEmpty() );
cr.setText( text );
assertSame( text, cr.getText() );

assertNull( null, cr.getSourceInfo() );

assertNull( cr.getErrorCode() );
cr.setErrorCode( errorCode );
assertSame( errorCode, cr.getErrorCode() );

when( sourceMeta.getName() ).thenReturn( sourceMetaName );
cr = new CheckResult( type, text, sourceMeta );
assertSame( sourceMeta, cr.getSourceInfo() );
assertTrue( cr.getTypeDesc() != null && !cr.getTypeDesc().isEmpty() );
final String stringValue = String.format( "%s: %s (%s)", cr.getTypeDesc(), text, sourceMetaName );
assertEquals( stringValue, cr.toString() );

cr = new CheckResult( type, errorCode, text, sourceMeta );
assertSame( errorCode, cr.getErrorCode() );
}
}
51 changes: 51 additions & 0 deletions core/test-src/org/pentaho/di/core/ConstDBTest.java
@@ -0,0 +1,51 @@
/*! ******************************************************************************
*
* Pentaho Data Integration
*
* Copyright (C) 2002-2015 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.core;

import org.junit.Test;
import org.pentaho.di.core.database.DatabaseMeta;
import org.pentaho.di.core.database.MySQLDatabaseMeta;
import org.pentaho.di.core.database.SAPR3DatabaseMeta;

import java.util.ArrayList;
import java.util.List;

import static org.junit.Assert.*;

public class ConstDBTest {

@Test
public void testSelectSAPR3Databases() throws Exception {
KettleClientEnvironment.init();
final DatabaseMeta mysqlMeta = new DatabaseMeta();
mysqlMeta.setDatabaseInterface( new MySQLDatabaseMeta() );
final DatabaseMeta sapR3Meta = new DatabaseMeta();
sapR3Meta.setDatabaseInterface( new SAPR3DatabaseMeta() );
List<DatabaseMeta> databaseMetas = new ArrayList<>();
databaseMetas.add( mysqlMeta );
databaseMetas.add( sapR3Meta );

List<DatabaseMeta> sapR3Metas = ConstDB.selectSAPR3Databases( databaseMetas );
assertEquals( 1, sapR3Metas.size() );
assertSame( sapR3Meta, sapR3Metas.get( 0 ) );
}
}

0 comments on commit 39a4d3d

Please sign in to comment.