KettleRowToHBaseTuple { public HBasePut createTuplePut( HBaseTableWriteOperationManager hBaseTableWriteOperationManager, ByteConversionUtil bu, Object[] row, boolean writeToWAL ) throws Exception { if ( keyInMeta.isNull( row[keyIndex] ) ) { throw new FieldException( Mapping.TupleMapping.KEY ); } if ( familyInMeta.isNull( row[familyIndex] ) ) { throw new FieldException( Mapping.TupleMapping.FAMILY ); } if ( columnInMeta.isNull( row[columnIndex] ) ) { throw new FieldException( Mapping.TupleMapping.COLUMN ); } if ( valueInMeta.isNull( row[valueIndex] ) ) { throw new FieldException( Mapping.TupleMapping.VALUE ); } byte[] encodedKey = bu.encodeKeyValue( row[keyIndex], keyInMeta, keyType ); HBasePut put = hBaseTableWriteOperationManager.createPut( encodedKey ); String columnFamily = familyInMeta.getString( row[familyIndex] ); boolean binaryColName = false; String columnName = columnInMeta.getString( row[columnIndex] ); if ( columnName.startsWith( "@@@binary@@@" ) ) { columnName = columnName.replace( "@@@binary@@@", "" ); binaryColName = true; } byte[] encodedValue = valueMeta.encodeColumnValue( row[valueIndex], valueInMeta ); put.addColumn( columnFamily, columnName, binaryColName, encodedValue ); if ( visibilityIndex >= 0 && !visibilityInMeta.isNull( row[visibilityIndex] ) ) { byte[] encodedVisibility = visibilityMeta.encodeColumnValue( row[visibilityIndex], visibilityInMeta ); put.addColumn( columnFamily, MappingUtils.TUPLE_MAPPING_VISIBILITY, false, encodedVisibility ); } put.setWriteToWAL( writeToWAL ); return put; } KettleRowToHBaseTuple( RowMetaInterface inputRowMeta, Mapping tupleMapping,
      Map<String, HBaseValueMetaInterface> columnMapping ); HBasePut createTuplePut( HBaseTableWriteOperationManager hBaseTableWriteOperationManager,
      ByteConversionUtil bu, Object[] row, boolean writeToWAL );  }
@Test public void testRowConversion() throws Exception { RowMetaInterface inputRowMeta = Mockito.mock( RowMetaInterface.class ); when( inputRowMeta.indexOfValue( Mapping.TupleMapping.KEY.toString() ) ).thenReturn( 0 ); when( inputRowMeta.indexOfValue( Mapping.TupleMapping.FAMILY.toString() ) ).thenReturn( 1 ); when( inputRowMeta.indexOfValue( Mapping.TupleMapping.COLUMN.toString() ) ).thenReturn( 2 ); when( inputRowMeta.indexOfValue( Mapping.TupleMapping.VALUE.toString() ) ).thenReturn( 3 ); when( inputRowMeta.indexOfValue( MappingUtils.TUPLE_MAPPING_VISIBILITY ) ).thenReturn( 4 ); ValueMetaString keyMeta = new ValueMetaString( Mapping.TupleMapping.KEY.toString() ); ValueMetaString familyMeta = new ValueMetaString( Mapping.TupleMapping.FAMILY.toString() ); ValueMetaString columnMeta = new ValueMetaString( Mapping.TupleMapping.COLUMN.toString() ); ValueMetaString valueMeta = new ValueMetaString( Mapping.TupleMapping.VALUE.toString() ); ValueMetaString visMeta = new ValueMetaString( MappingUtils.TUPLE_MAPPING_VISIBILITY ); when( inputRowMeta.getValueMeta( 0 ) ).thenReturn( keyMeta ); when( inputRowMeta.getValueMeta( 1 ) ).thenReturn( familyMeta ); when( inputRowMeta.getValueMeta( 2 ) ).thenReturn( columnMeta ); when( inputRowMeta.getValueMeta( 3 ) ).thenReturn( valueMeta ); when( inputRowMeta.getValueMeta( 4 ) ).thenReturn( visMeta ); Map<String, HBaseValueMetaInterface> columnMap = new HashMap<>(); HBaseValueMetaInterface hvmi = Mockito.mock( HBaseValueMetaInterface.class ); columnMap.put( valueMeta.getName(), hvmi ); HBaseValueMetaInterface hvmiv = Mockito.mock( HBaseValueMetaInterface.class ); columnMap.put( visMeta.getName(), hvmiv ); KettleRowToHBaseTuple rowConverter = new KettleRowToHBaseTuple( inputRowMeta, tupleMapping, columnMap ); ByteConversionUtil byteConversionUtil = Mockito.mock( ByteConversionUtil.class ); String[] row = { "key", "family", "@@@binary@@@column", "value", "public" }; HBaseTableWriteOperationManager writeManager = Mockito.mock( HBaseTableWriteOperationManager.class ); HBasePut put = Mockito.mock( HBasePut.class ); when( writeManager.createPut( row[ 0 ].getBytes() ) ).thenReturn( put ); when( byteConversionUtil.encodeKeyValue( row[ 0 ], keyMeta, KeyType.STRING ) ).thenReturn( row[ 0 ].getBytes() ); rowConverter.createTuplePut( writeManager, byteConversionUtil, row, true ); verify( put, times( 1 ) ).addColumn( eq( row[ 1 ] ), eq( "column" ), eq( true ), any() ); verify( put, times( 1 ) ).addColumn( eq( row[ 1 ] ), eq( MappingUtils.TUPLE_MAPPING_VISIBILITY ), eq( false ), any() ); verify( put, times( 1 ) ).setWriteToWAL( true ); try { rowConverter.createTuplePut( null, null, new String[] { null, null, null, null, null }, true ); } catch ( FieldException fe ) { Assert.assertEquals( fe.getFieldString(), TupleMapping.KEY.toString() ); } try { rowConverter.createTuplePut( null, null, new String[] { "key", null, null, null, null }, true ); } catch ( FieldException fe ) { Assert.assertEquals( fe.getFieldString(), TupleMapping.FAMILY.toString() ); } try { rowConverter.createTuplePut( null, null, new String[] { "key", "family", null, null, null }, true ); } catch ( FieldException fe ) { Assert.assertEquals( fe.getFieldString(), TupleMapping.COLUMN.toString() ); } try { rowConverter.createTuplePut( null, null, new String[] { "key", "family", "column", null, null }, true ); } catch ( FieldException fe ) { Assert.assertEquals( fe.getFieldString(), TupleMapping.VALUE.toString() ); } }