### Question:
DatabaseDelegate extends AbstractDelegate implements ITransformer, SharedObjectAssembler<DatabaseMeta>,
    java.io.Serializable { public DataNode elementToDataNode( final RepositoryElementInterface element ) throws KettleException { DatabaseMeta databaseMeta = (DatabaseMeta) element; DataNode rootNode = new DataNode( NODE_ROOT ); rootNode.setProperty( PROP_TYPE, databaseMeta.getPluginId() ); rootNode.setProperty( PROP_CONTYPE, DatabaseMeta.getAccessTypeDesc( databaseMeta.getAccessType() ) ); rootNode.setProperty( PROP_HOST_NAME, databaseMeta.getHostname() ); rootNode.setProperty( PROP_DATABASE_NAME, databaseMeta.getDatabaseName() ); rootNode.setProperty( PROP_PORT, new Long( Const.toInt( databaseMeta.getDatabasePortNumberString(), -1 ) ) ); rootNode.setProperty( PROP_USERNAME, databaseMeta.getUsername() ); rootNode.setProperty( PROP_PASSWORD, Encr.encryptPasswordIfNotUsingVariables( databaseMeta.getPassword() ) ); rootNode.setProperty( PROP_SERVERNAME, databaseMeta.getServername() ); rootNode.setProperty( PROP_DATA_TBS, databaseMeta.getDataTablespace() ); rootNode.setProperty( PROP_INDEX_TBS, databaseMeta.getIndexTablespace() ); DataNode attrNode = rootNode.addNode( NODE_ATTRIBUTES ); Properties attributes = databaseMeta.getAttributes(); Enumeration<Object> keys = databaseMeta.getAttributes().keys(); while ( keys.hasMoreElements() ) { String code = (String) keys.nextElement(); String attribute = (String) attributes.get( code ); String escapedCode = RepositoryFilenameUtils.escape( code, repo.getPur().getReservedChars() ); attrNode.setProperty( escapedCode, attribute ); } return rootNode; } DatabaseDelegate( final PurRepository repo ); DataNode elementToDataNode( final RepositoryElementInterface element ); RepositoryElementInterface dataNodeToElement( final DataNode rootNode ); void dataNodeToElement( final DataNode rootNode, final RepositoryElementInterface element ); Repository getRepository(); DatabaseMeta assemble( RepositoryFile file, NodeRepositoryFileData data, VersionSummary version );  }### Answer:
@Test public void testExtraOptionEscapeWithInvalidCharInDatabaseType() throws KettleException { DatabaseMeta dbMeta = mock( DatabaseMeta.class ); when( dbMeta.getPluginId() ).thenReturn( "pluginId" ); when( dbMeta.getAccessTypeDesc() ).thenReturn( "Native" ); when( dbMeta.getHostname() ).thenReturn( "AS/400Host" ); when( dbMeta.getDatabaseName() ).thenReturn( "mainframeTable" ); when( dbMeta.getDatabasePortNumberString() ).thenReturn( "1234" ); when( dbMeta.getUsername() ).thenReturn( "testUser" ); when( dbMeta.getPassword() ).thenReturn( "123" ); when( dbMeta.getServername() ).thenReturn( "as400.dot.com" ); when( dbMeta.getDataTablespace() ).thenReturn( "tableSpace" ); when( dbMeta.getIndexTablespace() ).thenReturn( "123" ); Properties extraOptions = new Properties(); extraOptions.setProperty( "EXTRA_OPTION_AS/400.optionExtraOption", "true" ); when( dbMeta.getAttributes() ).thenReturn( extraOptions ); IUnifiedRepository purRepo = mock( IUnifiedRepository.class ); when( purRepo.getReservedChars() ).thenReturn( Arrays.asList( new Character[] { '/' } ) ); when( mockPurRepository.getPur() ).thenReturn( purRepo ); DataNode escapedAttributes = dbDelegate.elementToDataNode( dbMeta ); for ( Iterator<DataNode> iter = escapedAttributes.getNodes().iterator(); iter.hasNext(); ) { DataNode options = iter.next(); assertTrue( "Invalid escaped extra options", options.hasProperty( "EXTRA_OPTION_AS%2F400.optionExtraOption" ) ); assertFalse( "Should not contain un-escaped option", options .hasProperty( "EXTRA_OPTION_AS/400.optionExtraOption" ) ); } }