text:
<?php

namespace Tests\Unit\Models\APICommands;

use App\Models\Contracts\APICommand;
use App\Models\LocalAPIClient;
use Exception;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Support\Facades\Config;
use Tests\TestCase;
use Illuminate\Support\Facades\Validator;
use App\Models\User;

abstract class APICommandTestCase extends TestCase
{
    /**
     * @var array A valid (existing) layout name and version
     */
    protected $test_layout = [
        'name' => 'test-layout',
        'version' => 1
    ];

    /**
     * @return array Valid input data.
     */
    abstract public function getValidData();

    /**
     * @return APICommand A new instance of the class to test.
     */
    abstract public function command();

    /**
     * Get an API Client to use.
     * @param Authenticatable|null $user Optional Authenticatable. If null, will be auto-provided.
     * @return LocalAPIClient
     */
    public function api($user = null)
    {
        $user = $user ? $user : factory(User::class)->create();
        $api = new LocalAPIClient($user);
        return $api;
    }

    /**
     * Provide default valid input that can be overridden with invalid values.
     * @param array $override key => value pairs for fields to override.
     * @param array $unset Array keys to unset.
     * @return array
     */
    public function input($override, $unset = [])
    {
        if(null == $override){
            $override = [];
        }
        if( is_string($unset)){
            $unset = [$unset];
        }
        $data = array_merge($this->getValidData(), $override);
        foreach($unset as $key){
            unset($data[$key]);
        }
        return $data;
    }

    /**
     * Create and initalize a validator with the rules and messages from this command.
     * @param array $data The input data to validate.
     * @return \Illuminate\Validation\Validator
     */
    public function validator($data, $user = null)
    {
        if(null == $user){
            $user = factory(User::class)->states('admin')->create();
        }
        $command = $this->command();
        $data = collect($data);
        $validator = Validator::make(
            $data->toArray(),
            $command->rules($data, $user)
        );
        $validator->setCustomMessages($command->messages($data, $user));
        return $validator;
    }

    /**
     * Creates and executes an API command without any data validation
     * @param string $command Name of the command class
     * @param array $data The parameters to the command
     * @param null|Authenticatable $user
     * @return mixed The result of the command.
     */
    public function execute($command, $data, $user = null)
    {
        if(null == $user){
            $user = factory(User::class)->states('admin')->create();
        }
        $command = new $command;
        $data = collect($data);
        return $command->execute($data, $user);
    }

    public function setup()
    {
        parent::setup();
        Config::set('app.definitions_path', realpath(dirname(__FILE__ ). '/../../../Support/Fixtures/definitions'));
    }

    /**
     * The execute method of every APICommand should thrown an exception in case of DB error.
     * @test
     * @group APICommands
     */
    public function execute_throwsException_onDBError()
    {
        $this->expectException(Exception::class);
        $this->markTestIncomplete();
    }

    /**
     * The execute method of every APICommand should do all DB modifications within a transactions, so if an
     * error occurs the database state should remain unchanged.
     * @test
     * @group APICommands
     */
    public function execute_rollsback_onDBError()
    {
        $this->expectException(Exception::class);
        $this->markTestIncomplete();
    }

}


text:
module NaiveBayesClassifier
  class Gaussian
    DEFAULT_OPTIONS = {
      default_features: [],
      error_on_feature_mismatch: false
    }

    attr_accessor :training_sets, :statistics, :options
    attr_reader :features

    def initialize options = {}
      self.options       = DEFAULT_OPTIONS.merge(options)
      self.training_sets = Hash.new{|h, k| h[k] = [] }
      self.statistics    = {}
      self.features      = self.options[:default_features]
    end

    def validate_feature_set training_hash
      self.features = training_hash.keys  if self.features.empty?

      self.features == training_hash.keys.sort
    end

    def classify target_features
      results = calculate_numerator_for_each_klass target_features

      results.invert[results.values.max]
    end

    def calculate_numerator_for_each_klass target_features
      self.training_sets.keys.each_with_object({}) do |klass, obj|
        obj[klass] = posterior_numerator klass, target_features
      end
    end

    def posterior_numerator klass, target_features
      return 0 if !self.statistics[klass] or self.statistics[klass].empty?

      self.probability_of_klass(klass) * self.features.collect do |feature|
        probability_of_feature klass, feature, target_features[feature]
      end.inject(:*)
    end

    def probability_of_feature klass, feature, value
      variance = self.statistics[klass][feature][:variance]
      mean     = self.statistics[klass][feature][:mean]

       Math.exp( -((value - mean) ** 2) / (2 * variance ) ) /
         Math.sqrt( 2 * Math::PI * variance )
    end

    def probability_of_klass klass
      self.training_sets[klass].length.to_f / total_training_sets
    end

    def total_training_sets
      self.training_sets.values.map(&:length).inject(:+)
    end

    def calculate_statistics_for klass
      self.statistics[klass] = self.features.each_with_object({}) do |feature, obj|
        feature_values = self.training_sets[klass].map{|ts| ts[feature] }

        obj[feature] = {
          variance: ClassifierMath.sample_variance(feature_values),
          mean: ClassifierMath.mean(feature_values)
        }
      end
    end

    def train! klass, training_sets
      training_sets = prune_training_sets(training_sets)

      self.training_sets[klass.to_sym] += training_sets

      calculate_statistics_for klass
    end

    def features= features
      @features = features.sort
    end

    def prune_training_sets training_sets
      valid_sets = training_sets.select do |training_set|
        validate_feature_set training_set
      end

      if self.options[:error_on_feature_mismatch] and
          valid_sets.length != training_sets.length

        raise ArgumentError,
          "Training set features differs in keys from #{self.features}"
      end

      valid_sets
    end
  end
end

redpajama_set_name: RedPajamaGithub


text:
from Asap import *
from Asap.Dynamics.VelocityVerlet import VelocityVerlet
from Asap.Dynamics.Langevin import Langevin
from Asap.Setup.Lattice.Cubic import FaceCenteredCubic
import sys, cPickle, time, commands, os, re
import RandomArray
from Numeric import *
from Asap.testtools import ReportTest
import ASE.ChemicalElements.mass

# cpu time:  time.clock().   Wall clock time: time.time()

AsapThreads()

host = commands.getoutput("hostname")
timesteps = 5
dbfilename = "bigtiming.dat"
selfcheckfilename = "bigtiming-selfcheck.dat"
logfilename = "bigtiming.log"
asapversion = GetVersion()
when = time.strftime("%a %d %b %Y %H:%M", time.localtime(time.time()))

RandomArray.seed(42, 12345)

PrintVersion(1)
print "Running ASAP timing on "+host+"."
if re.match("^n\d\d\d.dcsc.fysik.dtu.dk$", host):
    print "    This is a d512 node on Niflheim."
    fullhost = "niflheim-d512/%s" % (host.split(".")[0])
    host = "niflheim-d512"
elif re.match("^[stu]\d\d\d.dcsc.fysik.dtu.dk$", host):
    print "    This is an s50 node on Niflheim."
    fullhost = "niflheim-s50/%s" % (host.split(".")[0])
    host = "niflheim-s50"
else:
    fullhost = host
print "Current time is "+when
print ""

print "Preparing system"
initial = FaceCenteredCubic([[1,0,0],[0,1,0],[0,0,1]], size=(50, 50, 50),
                            element="Cu")
#initial = FaceCenteredCubic([[1,0,0],[0,1,0],[0,0,1]], size=(25, 25, 25),
#                            element="Cu")
print "Number of atoms:", len(initial)
ReportTest("Number of atoms", len(initial), 500000, 0)
r = initial.GetCartesianPositions()
r.flat[:] += 0.14 * sin(arange(3*len(initial)))
initial.SetCartesianPositions(r)

print "Preparing to run Verlet dynamics (periodic boundaries)."
atoms = ListOfAtoms(initial, periodic=(1,1,1))
elements = [29]
epsilon  = [0.15]
sigma    = [2.7]
masses   = [ASE.ChemicalElements.mass.masses[29]]

atoms.SetCalculator(LJPotential(1, elements, epsilon, sigma, masses, -1.0,
                                True, False))
dynamics = VelocityVerlet(atoms, 5*femtosecond)

print "Running Verlet dynamics."
startcpu, startwall = time.clock(), time.time()
dynamics.Run(timesteps)

vpcpu, vpwall = time.clock() - startcpu, time.time() - startwall
vpfraction = vpcpu/vpwall
sys.stderr.write("\n")
print "Verlet dynamics done."
del dynamics, atoms

print ""
print ""
print "TIMING RESULTS:"
print "Verlet (pbc):   CPU time %.2fs  Wall clock time %.2fs (%.0f%%)" % (vpcpu, vpwall, vpfraction * 100)
print ""


text:
.. streamcorpus-pipeline documentation master file, created by
   sphinx-quickstart on Thu Mar  6 17:19:40 2014.
   You can adapt this file completely to your liking, but it should at least
   contain the root `toctree` directive.

Welcome to StreamCorpus
=======================

StreamCorpus provides a toolkit for processing massive streams of text
and running natural language extractors on the text.  StreamCorpus
does not provide any extractors itself; it operates third-party
extractors, such as Serif and Factorie, and unifies their output.
StreamCorpus pipline can store documents in S3, Accumulo, or flat
files.

StreamCorpus is used extensively in `TREC KBA <http://trec-kba.org/>`_
and at `Diffeo <http://diffeo.com/>`_.

Ask more at `StreamCorpus Google Group <http://groups.google.com/group/streamcorpus>`_

All of these python package are hosted in `github.com/trec-kba <http://github.com/trec-kba/>`_
and `github.com/diffeo <http://github.com/diffeo/>`_

Contents:

.. toctree::
   :maxdepth: 2
   :numbered:

   sphinx-docs/overview
   sphinx-docs/streamcorpus
   sphinx-docs/streamcorpus_pipeline
   sphinx-docs/yakonfig
   sphinx-docs/dblogger
   sphinx-docs/kvlayer
   sphinx-docs/rejester

Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`


text:
'use strict';

/**
 * @ngdoc filter
 * @name tomTomApp.filter:lang
 * @function
 * @description
 * # lang
 * Filter in the tomTomApp.
 */
angular.module('tomTomApp')
    .filter('lang', function() {
        return function(input, lang) {
        	var r = [];
            if (Object.prototype.toString.call(input) === '[object Array]') {
                // input is an array
                for (var i = input.length - 1; i >= 0; i--) {
                    if (input[i]['@lang'] === lang) {

                        // language is found, are there sub paragraphs?
                        if (!input[i].p) {
                            return input[i].$; // return string
                        } else if (Object.prototype.toString.call(input[i].p) === '[object Array]') {
                            for (var j = input[i].p.length - 1; j >= 0; j--) {
                                r.push(input[i].p[j].$);
                            }
                            return r; // return paragraphs as array
                        } else {
                            return [input[i].p.$]; // return paragraph as array
                        }

                    }
                }
                return input[1].$; // Language not foud, return the first language
            } else {
                if (input === undefined) {
                    return input;
                } else if (input.p) {

                    if (Object.prototype.toString.call(input.p) === '[object Array]') {
                        for (var k = input.p.length - 1; k >= 0; k--) {
                            r.push(input.p[k].$);
                        }
                        return r; // return paragraphs as array
                    } else {
                        return [input.p.$]; // return paragraph as array
                    }

                } else {
                    if (input['@lang']) {
                        return input.$;
                    }
                }
            }
        };
    });


text:
import getDeviceNames

rv = getDeviceNames.getDevices()

print rv[0]

for device in rv:
  print device['id']  + " " + device['name'] + " " + str(device['location']['lat']) + " " + str(device['location']['lng'])


text:
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package org.chromium.chrome.browser.notifications;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.robolectric.Shadows.shadowOf;

import android.app.NotificationManager;
import android.content.Context;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowNotificationManager;

import org.chromium.base.test.BaseRobolectricTestRunner;

/**
 * JUnit tests for NotificationSystemStatusUtil which run against Robolectric so that we can
 * manipulate what NotificationManagerCompat.getNotificationsEnabled returns.
 */
@RunWith(BaseRobolectricTestRunner.class)
@Config(manifest = Config.NONE)
public class NotificationSystemStatusUtilUnitTest {
    @Test
    public void testAppNotificationStatusEnabled() {
        getShadowNotificationManager().setNotificationsEnabled(true);
        assertThat(NotificationSystemStatusUtil.getAppNotificationStatus(),
                is(NotificationSystemStatusUtil.APP_NOTIFICATIONS_STATUS_ENABLED));
    }

    @Test
    public void testAppNotificationStatusDisabled() {
        getShadowNotificationManager().setNotificationsEnabled(false);
        assertThat(NotificationSystemStatusUtil.getAppNotificationStatus(),
                is(NotificationSystemStatusUtil.APP_NOTIFICATIONS_STATUS_DISABLED));
    }

    private ShadowNotificationManager getShadowNotificationManager() {
        return shadowOf((NotificationManager) RuntimeEnvironment.application.getSystemService(
                Context.NOTIFICATION_SERVICE));
    }
}


text:
import asyncio
import asyncio.futures
import errno
import logging
import os

logger = logging.getLogger('asyncio.aionotify')

class UnixFileDescriptorTransport(asyncio.ReadTransport):
    # Inspired from asyncio.unix_events._UnixReadPipeTransport
    max_size = 1024

    def __init__(self, loop, fileno, protocol, waiter=None):
        super().__init__()
        self._loop = loop
        self._fileno = fileno
        self._protocol = protocol

        self._active = False
        self._closing = False

        self._loop.call_soon(self._protocol.connection_made, self)
        # only start reading when connection_made() has been called.
        self._loop.call_soon(self.resume_reading)
        if waiter is not None:
            # only wake up the waiter when connection_made() has been called.
            self._loop.call_soon(self._notify_waiter, waiter)

    def _notify_waiter(self, waiter):
        if not waiter.cancelled():
            waiter.set_result(None)

    def _read_ready(self):
        """Called by the event loop whenever the fd is ready for reading."""

        try:
            data = os.read(self._fileno, self.max_size)
        except InterruptedError:
            # No worries ;)
            pass
        except OSError as exc:
            # Some OS-level problem, crash.
            self._fatal_error(exc, "Fatal read error on file descriptor read")
        else:
            if data:
                self._protocol.data_received(data)
            else:
                # We reached end-of-file.
                if self._loop.get_debug():
                    logger.info("%r was closed by the kernel", self)
                self._closing = False
                self.pause_reading()
                self._loop.call_soon(self._protocol.eof_received)
                self._loop.call_soon(self._call_connection_lost, None)

    def pause_reading(self):
        """Public API: pause reading the transport."""
        self._loop.remove_reader(self._fileno)
        self._active = False

    def resume_reading(self):
        """Public API: resume transport reading."""
        self._loop.add_reader(self._fileno, self._read_ready)
        self._active = True

    def close(self):
        """Public API: close the transport."""
        if not self._closing:
            self._close()

    def _fatal_error(self, exc, message):
        if isinstance(exc, OSError) and exc.errno == errno.EIO:
            if self._loop.get_debug():
                logger.debug("%r: %s", self, message, exc_info=True)
        else:
            self._loop.call_exception_handler({
                'message': message,
                'exception': exc,
                'transport': self,
                'protocol': self._protocol,
            })
        self._close(error=exc)

    def _close(self, error=None):
        """Actual closing code, both from manual close and errors."""
        self._closing = True
        self.pause_reading()
        self._loop.call_soon(self._call_connection_lost, error)

    def _call_connection_lost(self, error):
        """Finalize closing."""
        try:
            self._protocol.connection_lost(error)
        finally:
            os.close(self._fileno)
            self._fileno = None
            self._protocol = None
            self._loop = None

    def __repr__(self):
        if self._active:
            status = 'active'
        elif self._closing:
            status = 'closing'
        elif self._fileno:
            status = 'paused'
        else:
            status = 'closed'

        parts = [
            self.__class__.__name__,
            status,
            'fd=%s' % self._fileno,
        ]
        return '<%s>' % ' '.join(parts)

@asyncio.coroutine
def stream_from_fd(fd, loop):
    """Recieve a streamer for a given file descriptor."""
    reader = asyncio.StreamReader(loop=loop)
    protocol = asyncio.StreamReaderProtocol(reader, loop=loop)
    waiter = asyncio.futures.Future(loop=loop)

    transport = UnixFileDescriptorTransport(
        loop=loop,
        fileno=fd,
        protocol=protocol,
        waiter=waiter,
    )

    try:
        yield from waiter
    except Exception:
        transport.close()

    if loop.get_debug():
        logger.debug("Read fd %r connected: (%r, %r)", fd, transport, protocol)
    return reader, transport


text:
package io.getlime.push.model.request;

/**
 * Class representing request object responsible for updating activation status.
 *
 * @author Petr Dvorak, petr@lime-company.eu
 */
public class UpdateDeviceStatusRequest {

    private String activationId;

    /**
     * Get PowerAuth 2.0 Activation ID.
     * @return Activation ID.
     */
    public String getActivationId() {
        return activationId;
    }

    /**
     * Set PowerAuth 2.0 Activation ID.
     * @param activationId Activation ID.
     */
    public void setActivationId(String activationId) {
        this.activationId = activationId;
    }

}


text:
import { _, path, config } from 'azk';
import { utils as Utils } from 'azk';

class docker {
  // TODO: Add test
  static resolvePath(target, point = config('agent:vm:mount_point')) {
    target = Utils.resolve(target);
    if (config('agent:requires_vm')) {
      target = path.join(point, target);
    }

    return target;
  }
}

export default docker;


text:
<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of page
 *
 * @author Wilson McCoubrey <wilson@mccoubreys.co.uk>
 */
class page extends My_Controller{

    public function __construct() {
        parent::__construct();
    }

    public function index() {
        $url = $this->uri->segment(2);
        if(!$url){
            $url = $this->uri->segment(1);
        }
        if($url == FALSE){
            redirect('home', 'refresh');
        }else{
            $this->load->model('Model_Page');
            $page = $this->Model_Page->getPage($url);

            if($page != null){
                $data['page'] = $page;
                parent::loadPage('page', $page->page_title, $data);
            }else{
                show_404($url);
            }
        }

    }
}


text:
//>>built
define("dojox/data/ClientFilter", ["dojo/_base/declare", "dojo/_base/lang", "dojo/_base/array", "dojo/_base/Deferred", "dojo/data/util/filter"],
  function(declare, lang, array, Deferred, filter) {

// This is an abstract data store module for adding updateable result set functionality to an existing data store class

	var addUpdate = function(store,create,remove){
		// create a handler that adds to the list of notifications
		return function(item){
			store._updates.push({
					create:create && item,
					remove:remove && item
				});
			ClientFilter.onUpdate();
		}
	};
	var ClientFilter = declare("dojox.data.ClientFilter", null, {
			cacheByDefault: false,
			constructor: function(){
				// summary:
				//		This is an abstract class that data stores can extend to add updateable result set functionality
				//		as well as client side querying capabilities. This enables
				//		widgets to be aware of how active results change in response to the modifications/notifications.
				//
				//	description:
				//		To a update a result set after a notification (onNew, onSet, and onDelete),
				//		widgets can call the updateResultSet method. Widgets can use the updated
				//		result sets to determine how to react to notifications, and how to update their displayed results
				//		based on changes.
				//
				//		This module will use the best available information to update result sets, using query attribute
				//		objects to determine if items are in a result set, and using the sort arrays to maintain sort
				//		information. However, queries can be opaque strings, and this module can not update
				//		results by itself in this case. In this situations, data stores can provide a isUpdateable(request) function
				//		and matchesQuery(item,request) function. If a data store can handle a query, it can return true from
				//		isUpdateable and if an item matches a query, it can return true from matchesQuery. Here is
				//		definition of isUpdateable and matchesQuery
				//		isUpdateable(request)  - request is the keywords arguments as is passed to the fetch function.
				//		matchesQuery(item,request) - item is the item to test, and request is the value arguments object
				//				for the fetch function.
				//
				//		You can define a property on this object instance "cacheByDefault" to a value of true that will
				//		cause all queries to be cached by default unless the cache queryOption is explicitly set to false.
				//		This can be defined in the constructor options for ServiceStore/JsonRestStore and subtypes.
				//
				// example:
				//		to make a updated-result-set data store from an existing data store:
				//	|	dojo.declare("dojox.data.MyLiveDataStore",
				//	|		dojox.data.MyDataStore,dojox.data.ClientFilter], // subclass LiveResultSets if available
				//	|		{}
				//	|	);
				this.onSet = addUpdate(this,true,true);
				this.onNew = addUpdate(this,true,false);
				this.onDelete = addUpdate(this,false,true);
				this._updates= [];
				this._fetchCache = [];
			},
			clearCache: function(){
				//	summary:
				//		Clears the cache of client side queries
				this._fetchCache = [];
			},
			updateResultSet: function(/*Array*/ resultSet, /*Object*/ request){
				//	summary:
				//		Attempts to update the given result set based on previous notifications
				//	resultSet:
				//		The result set array that should be updated
				//	request:
				//		This object follows the same meaning as the keywordArgs passed to a dojo.data.api.Read.fetch.
				//	description:
				// 		This will attempt to update the provide result based on previous notification, adding new items
				// 		from onNew calls, removing deleted items, and updating modified items, and properly removing
				//  	and adding items as required by the query and sort parameters. This function will return:
				//		0: Indicates it could not successfully update the result set
				//		1: Indicates it could successfully handle all the notifications, but no changes were made to the result set
				//		2: Indicates it successfully handled all the notifications and result set has been updated.
				if(this.isUpdateable(request)){
					// we try to avoid rerunning notification updates more than once on the same object for performance
					for(var i = request._version || 0; i < this._updates.length;i++){
						// for each notification,we will update the result set
						var create = this._updates[i].create;
						var remove = this._updates[i].remove;
						if(remove){
							for(var j = 0; j < resultSet.length;j++){
								if(this.getIdentity(resultSet[j]) == this.getIdentity(remove)){
									resultSet.splice(j--,1);
									var updated = true;
								}
							}
						}
						if(create && this.matchesQuery(create,request) && // if there is a new/replacement item and it matches the query
								array.indexOf(resultSet,create) == -1){ // and it doesn't already exist in query
							resultSet.push(create); // should this go at the beginning by default instead?
							updated = true;
						}
					}
					if(request.sort && updated){
						// do the sort if needed
						resultSet.sort(this.makeComparator(request.sort.concat()));
					}
					resultSet._fullLength = resultSet.length;
					if(request.count && updated && request.count !== Infinity){
						// do we really need to do this?
						// make sure we still find within the defined paging set
						resultSet.splice(request.count, resultSet.length);
					}
					request._version = this._updates.length;
					return updated ? 2 : 1;
				}
				return 0;
			},
			querySuperSet: function(argsSuper, argsSub){
				//	summary:
				//		Determines whether the provided arguments are super/sub sets of each other
				// argsSuper:
				//		Dojo Data Fetch arguments
				// argsSub:
				//		Dojo Data Fetch arguments
				if(argsSuper.query == argsSub.query){
					return {};
				}
				if(!(argsSub.query instanceof Object && // sub query must be an object
						// super query must be non-existent or an object
						(!argsSuper.query || typeof argsSuper.query == 'object'))){
					return false;
				}
				var clientQuery = lang.mixin({},argsSub.query);
				for(var i in argsSuper.query){
					if(clientQuery[i] == argsSuper.query[i]){
						delete clientQuery[i];
					}else if(!(typeof argsSuper.query[i] == 'string' &&
							// if it is a pattern, we can test to see if it is a sub-pattern
							// FIXME: This is not technically correct, but it will work for the majority of cases
							filter.patternToRegExp(argsSuper.query[i]).test(clientQuery[i]))){
						return false;
					}
				}
				return clientQuery;
			},
			//	This is the point in the version notification history at which it is known that the server is in sync, this should
			//	be updated to this._updates.length on commit operations.
			serverVersion: 0,

			cachingFetch: function(args){
				var self = this;
				for(var i = 0; i < this._fetchCache.length;i++){
					var cachedArgs = this._fetchCache[i];
					var clientQuery = this.querySuperSet(cachedArgs,args);
					if(clientQuery !== false){
						var defResult = cachedArgs._loading;
						if(!defResult){
							defResult = new Deferred();
							defResult.callback(cachedArgs.cacheResults);
						}
						defResult.addCallback(function(results){
							results = self.clientSideFetch(lang.mixin(lang.mixin({}, args),{query:clientQuery}), results);
							defResult.fullLength = results._fullLength;
							return results;
						});
						args._version = cachedArgs._version;
						break;
					}
				}
				if(!defResult){
					var serverArgs = lang.mixin({}, args);
					var putInCache = (args.queryOptions || 0).cache;
					var fetchCache = this._fetchCache;
					if(putInCache === undefined ? this.cacheByDefault : putInCache){
						// we are caching this request, so we want to get all the data, and page on the client side
						if(args.start || args.count){
							delete serverArgs.start;
							delete serverArgs.count;
							args.clientQuery = lang.mixin(args.clientQuery || {}, {
								start: args.start,
								count: args.count
							});
						}
						args = serverArgs;
						fetchCache.push(args);
					}
					defResult= args._loading = this._doQuery(args);

					defResult.addErrback(function(){
						fetchCache.splice(array.indexOf(fetchCache, args), 1);
					});
				}
				var version = this.serverVersion;

				defResult.addCallback(function(results){
					delete args._loading;
					// update the result set in case anything changed while we were waiting for the fetch
					if(results){
						args._version = typeof args._version == "number" ? args._version : version;
						self.updateResultSet(results,args);
						args.cacheResults = results;
						if(!args.count || results.length < args.count){
							defResult.fullLength = ((args.start)?args.start:0) + results.length;
						}
					}
					return results;
				});
				return defResult;
			},
			isUpdateable: function(/*Object*/ request){
				//	summary:
				//		Returns whether the provide fetch arguments can be used to update an existing list
				//	request:
				//		See dojo.data.api.Read.fetch request

				return typeof request.query == "object";
			},
			clientSideFetch: function(/*Object*/ request,/*Array*/ baseResults){
				// summary:
				//		Performs a query on the client side and returns the results as an array
				//
				//	request:
				//		See dojo.data.api.Read.fetch request
				//
				//	baseResults:
				//		This provides the result set to start with for client side querying
				if(request.queryOptions && request.queryOptions.results){
					baseResults = request.queryOptions.results;
				}
				if(request.query){
					// filter by the query
					var results = [];
					for(var i = 0; i < baseResults.length; i++){
						var value = baseResults[i];
						if(value && this.matchesQuery(value,request)){
							results.push(baseResults[i]);
						}
					}
				}else{
					results = request.sort ? baseResults.concat() : baseResults; // we don't want to mutate the baseResults if we are doing a sort
				}
				if(request.sort){
					// do the sort if needed
					results.sort(this.makeComparator(request.sort.concat()));
				}
				return this.clientSidePaging(request, results);
			},
			clientSidePaging: function(/*Object*/ request,/*Array*/ baseResults){
				var start = request.start || 0;
				var finalResults = (start || request.count) ? baseResults.slice(start,start + (request.count || baseResults.length)) : baseResults;
				finalResults._fullLength = baseResults.length;
				return finalResults;
			},
			matchesQuery: function(item,request){
				var query = request.query;
				var ignoreCase = request.queryOptions && request.queryOptions.ignoreCase;
				for(var i in query){
					// if anything doesn't match, than this should be in the query
					var match = query[i];
					var value = this.getValue(item,i);
					if((typeof match == 'string' && (match.match(/[\*\.]/) || ignoreCase)) ?
						!filter.patternToRegExp(match, ignoreCase).test(value) :
						value != match){
						return false;
					}
				}
				return true;
			},
			makeComparator: function(sort){
				//	summary:
				//		returns a comparator function for the given sort order array
				//	sort:
				//		See dojox.data.api.Read.fetch
				var current = sort.shift();
				if(!current){
					// sort order for ties and no sort orders
					return function(){
						return 0;// keep the order unchanged
					};
				}
				var attribute = current.attribute;
				var descending = !!current.descending;
				var next = this.makeComparator(sort);
				var store = this;
				return function(a,b){
					var av = store.getValue(a,attribute);
					var bv = store.getValue(b,attribute);
					if(av != bv){
						return av < bv == descending ? 1 : -1;
					}
					return next(a,b);
				};
			}
		}
	);
	ClientFilter.onUpdate = function(){};

	return ClientFilter;
});


text:
package com.streamsets.pipeline.stage.processor.fieldvaluereplacer;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.streamsets.pipeline.api.Field;
import com.streamsets.pipeline.api.OnRecordError;
import com.streamsets.pipeline.api.Record;
import com.streamsets.pipeline.api.StageException;
import com.streamsets.pipeline.config.OnStagePreConditionFailure;
import com.streamsets.pipeline.sdk.ProcessorRunner;
import com.streamsets.pipeline.sdk.RecordCreator;
import com.streamsets.pipeline.sdk.StageRunner;
import org.jetbrains.annotations.NotNull;
import org.junit.Assert;
import org.junit.Test;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.Matchers.empty;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.collection.IsMapContaining.hasKey;
import static com.streamsets.testing.Matchers.fieldWithValue;
public class TestFieldValueReplacer {

  @Test
  public void testNonExistingFieldsContinue() throws StageException {

    FieldValueReplacerConfig nameReplacement = new FieldValueReplacerConfig();
    nameReplacement.fields = ImmutableList.of("/nonExisting");
    nameReplacement.newValue = "StreamSets";

    NullReplacerConditionalConfig nullReplacerConditionalConfig = new NullReplacerConditionalConfig();
    nullReplacerConditionalConfig.fieldsToNull = ImmutableList.of("/nonExisting");

    ProcessorRunner runner = new ProcessorRunner.Builder(FieldValueReplacerDProcessor.class)
      .addConfiguration("nullReplacerConditionalConfigs", ImmutableList.of(nullReplacerConditionalConfig))
        .addConfiguration("fieldsToReplaceIfNull", ImmutableList.of(nameReplacement))
        .addConfiguration("fieldsToConditionallyReplace", null)
      .addConfiguration("onStagePreConditionFailure", OnStagePreConditionFailure.CONTINUE)
      .addOutputLane("a").build();
    runner.runInit();

    try {
      Map<String, Field> map = new LinkedHashMap<>();
      map.put("name", Field.create(Field.Type.STRING, null));
            Record record = RecordCreator.create("s", "s:1");
      record.set(Field.create(map));

      StageRunner.Output output = runner.runProcess(ImmutableList.of(record));
      Assert.assertEquals(1, output.getRecords().get("a").size());
      Field field = output.getRecords().get("a").get(0).get();
      Assert.assertTrue(field.getValue() instanceof Map);
      Map<String, Field> result = field.getValueAsMap();
      Assert.assertTrue(result.size() == 1);
      Assert.assertTrue(result.containsKey("name"));
      Assert.assertEquals(null, result.get("name").getValue());
    } finally {
      runner.runDestroy();
    }
  }

  @Test
  public void testNonExistingFieldsError() throws StageException {

    FieldValueReplacerConfig nameReplacement = new FieldValueReplacerConfig();
    nameReplacement.fields = ImmutableList.of("/nonExisting");
    nameReplacement.newValue = "StreamSets";

    NullReplacerConditionalConfig nullReplacerConditionalConfig = new NullReplacerConditionalConfig();
    nullReplacerConditionalConfig.fieldsToNull = ImmutableList.of("/nonExisting");

    ProcessorRunner runner = new ProcessorRunner.Builder(FieldValueReplacerDProcessor.class)
      .setOnRecordError(OnRecordError.TO_ERROR)
      .addConfiguration("nullReplacerConditionalConfigs", ImmutableList.of(nullReplacerConditionalConfig))
      .addConfiguration("fieldsToReplaceIfNull", ImmutableList.of(nameReplacement))
        .addConfiguration("fieldsToConditionallyReplace", null)
      .addConfiguration("onStagePreConditionFailure", OnStagePreConditionFailure.TO_ERROR)
      .addOutputLane("a").build();
    runner.runInit();

    try {
      Map<String, Field> map = new LinkedHashMap<>();
      map.put("name", Field.create(Field.Type.STRING, null));
      Record record = RecordCreator.create("s", "s:1");
      record.set(Field.create(map));

      StageRunner.Output output = runner.runProcess(ImmutableList.of(record));

      Assert.assertEquals(0, output.getRecords().get("a").size());
      Assert.assertEquals(1, runner.getErrorRecords().size());

    } finally {
      runner.runDestroy();
    }
  }

  @Test
  public void testNullConfiguration() throws StageException {
    ProcessorRunner runner = new ProcessorRunner.Builder(FieldValueReplacerDProcessor.class)
      .addConfiguration("nullReplacerConditionalConfigs", null)
      .addConfiguration("fieldsToReplaceIfNull", null)
        .addConfiguration("fieldsToConditionallyReplace", null)
      .addConfiguration("onStagePreConditionFailure", OnStagePreConditionFailure.CONTINUE)
      .addOutputLane("a").build();
    runner.runInit();

    try {
      Map<String, Field> map = new LinkedHashMap<>();
      map.put("name", Field.create(Field.Type.STRING, null));
            Record record = RecordCreator.create("s", "s:1");
      record.set(Field.create(map));

      StageRunner.Output output = runner.runProcess(ImmutableList.of(record));
      Assert.assertEquals(1, output.getRecords().get("a").size());
      Field field = output.getRecords().get("a").get(0).get();
      Assert.assertTrue(field.getValue() instanceof Map);
      Map<String, Field> result = field.getValueAsMap();
      Assert.assertTrue(result.size() == 1);
      Assert.assertTrue(result.containsKey("name"));
      Assert.assertEquals(null, result.get("name").getValue());
    } finally {
      runner.runDestroy();
    }
  }

  @Test
  public void testEmptyConfiguration() throws StageException {
    ProcessorRunner runner = new ProcessorRunner.Builder(FieldValueReplacerDProcessor.class)
      .addConfiguration("nullReplacerConditionalConfigs", new ArrayList<>())
      .addConfiguration("fieldsToReplaceIfNull", new ArrayList<>())
        .addConfiguration("fieldsToConditionallyReplace", new ArrayList<>())
      .addConfiguration("onStagePreConditionFailure", OnStagePreConditionFailure.CONTINUE)
      .addOutputLane("a").build();
    runner.runInit();

    try {
      Map<String, Field> map = new LinkedHashMap<>();
      map.put("name", Field.create(Field.Type.STRING, null));
            Record record = RecordCreator.create("s", "s:1");
      record.set(Field.create(map));

      StageRunner.Output output = runner.runProcess(ImmutableList.of(record));
      Assert.assertEquals(1, output.getRecords().get("a").size());
      Field field = output.getRecords().get("a").get(0).get();
      Assert.assertTrue(field.getValue() instanceof Map);
      Map<String, Field> result = field.getValueAsMap();
      Assert.assertTrue(result.size() == 1);
      Assert.assertTrue(result.containsKey("name"));
      Assert.assertEquals(null, result.get("name").getValue());
    } finally {
      runner.runDestroy();
    }
  }

  @Test
  public void testFieldsToNull() throws StageException {
    NullReplacerConditionalConfig nullReplacerConditionalConfig = new NullReplacerConditionalConfig();
    nullReplacerConditionalConfig.fieldsToNull = ImmutableList.of("/age");

    ProcessorRunner runner = new ProcessorRunner.Builder(FieldValueReplacerDProcessor.class)
      .addConfiguration("nullReplacerConditionalConfigs", ImmutableList.of(nullReplacerConditionalConfig))
      .addConfiguration("fieldsToReplaceIfNull", null)
        .addConfiguration("fieldsToConditionallyReplace", null)
      .addConfiguration("onStagePreConditionFailure", OnStagePreConditionFailure.CONTINUE)
      .addOutputLane("a").build();
    runner.runInit();

    try {
      Map<String, Field> map = new LinkedHashMap<>();
      map.put("name", Field.create(Field.Type.STRING, null));
      map.put("age", Field.create(21));
      map.put("streetAddress", Field.create("c"));
            Record record = RecordCreator.create("s", "s:1");
      record.set(Field.create(map));

      StageRunner.Output output = runner.runProcess(ImmutableList.of(record));
      Assert.assertEquals(1, output.getRecords().get("a").size());
      Field field = output.getRecords().get("a").get(0).get();
      Assert.assertTrue(field.getValue() instanceof Map);
      Map<String, Field> result = field.getValueAsMap();
      Assert.assertTrue(result.size() == 3);
      Assert.assertTrue(result.containsKey("name"));
      Assert.assertEquals(null, result.get("name").getValue());
      Assert.assertTrue(result.containsKey("age"));
      Assert.assertEquals(null, result.get("age").getValue());
      Assert.assertTrue(result.containsKey("streetAddress"));
      Assert.assertEquals("c", result.get("streetAddress").getValue());
    } finally {
      runner.runDestroy();
    }
  }

  @Test
  public void testReplaceNullStringFields() throws StageException {

    FieldValueReplacerConfig stringFieldReplacement = new FieldValueReplacerConfig();
    stringFieldReplacement.fields = ImmutableList.of("/stringField");
    stringFieldReplacement.newValue = "StreamSets";

    ProcessorRunner runner = new ProcessorRunner.Builder(FieldValueReplacerDProcessor.class)
      .addConfiguration("nullReplacerConditionalConfigs", null)
      .addConfiguration("fieldsToReplaceIfNull", ImmutableList.of(stringFieldReplacement))
        .addConfiguration("fieldsToConditionallyReplace", null)
      .addConfiguration("onStagePreConditionFailure", OnStagePreConditionFailure.CONTINUE)
      .addOutputLane("a").build();
    runner.runInit();

    try {
      Map<String, Field> map = new LinkedHashMap<>();
      map.put("stringField", Field.create(Field.Type.STRING, null));
            Record record = RecordCreator.create("s", "s:1");
      record.set(Field.create(map));

      StageRunner.Output output = runner.runProcess(ImmutableList.of(record));
      Assert.assertEquals(1, output.getRecords().get("a").size());
      Field field = output.getRecords().get("a").get(0).get();
      Assert.assertTrue(field.getValue() instanceof Map);
      Map<String, Field> result = field.getValueAsMap();
      Assert.assertTrue(result.size() == 1);
      Assert.assertTrue(result.containsKey("stringField"));
      Assert.assertEquals("StreamSets", result.get("stringField").getValue());
    } finally {
      runner.runDestroy();
    }
  }

  @Test
  public void testReplaceNullIntegerFields() throws StageException {

    FieldValueReplacerConfig stringFieldReplacement = new FieldValueReplacerConfig();
    stringFieldReplacement.fields = ImmutableList.of("/intField");
    stringFieldReplacement.newValue = "123";

    ProcessorRunner runner = new ProcessorRunner.Builder(FieldValueReplacerDProcessor.class)
      .addConfiguration("nullReplacerConditionalConfigs", null)
      .addConfiguration("fieldsToReplaceIfNull", ImmutableList.of(stringFieldReplacement))
        .addConfiguration("fieldsToConditionallyReplace", null)
      .addConfiguration("onStagePreConditionFailure", OnStagePreConditionFailure.CONTINUE)
      .addOutputLane("a").build();
    runner.runInit();

    try {
      Map<String, Field> map = new LinkedHashMap<>();
      map.put("intField", Field.create(Field.Type.INTEGER, null));
            Record record = RecordCreator.create("s", "s:1");
      record.set(Field.create(map));

      StageRunner.Output output = runner.runProcess(ImmutableList.of(record));
      Assert.assertEquals(1, output.getRecords().get("a").size());
      Field field = output.getRecords().get("a").get(0).get();
      Assert.assertTrue(field.getValue() instanceof Map);
      Map<String, Field> result = field.getValueAsMap();
      Assert.assertTrue(result.size() == 1);
      Assert.assertTrue(result.containsKey("intField"));
      Assert.assertEquals(123, result.get("intField").getValue());
    } finally {
      runner.runDestroy();
    }
  }

  @Test
  public void testReplaceNullDoubleFields() throws StageException {

    FieldValueReplacerConfig stringFieldReplacement = new FieldValueReplacerConfig();
    stringFieldReplacement.fields = ImmutableList.of("/doubleField");
    stringFieldReplacement.newValue = "12345.6789";

    ProcessorRunner runner = new ProcessorRunner.Builder(FieldValueReplacerDProcessor.class)
      .addConfiguration("nullReplacerConditionalConfigs", null)
      .addConfiguration("fieldsToReplaceIfNull", ImmutableList.of(stringFieldReplacement))
        .addConfiguration("fieldsToConditionallyReplace", null)
      .addConfiguration("onStagePreConditionFailure", OnStagePreConditionFailure.CONTINUE)
      .addOutputLane("a").build();
    runner.runInit();

    try {
      Map<String, Field> map = new LinkedHashMap<>();
      map.put("doubleField", Field.create(Field.Type.DOUBLE, null));
            Record record = RecordCreator.create("s", "s:1");
      record.set(Field.create(map));

      StageRunner.Output output = runner.runProcess(ImmutableList.of(record));
      Assert.assertEquals(1, output.getRecords().get("a").size());
      Field field = output.getRecords().get("a").get(0).get();
      Assert.assertTrue(field.getValue() instanceof Map);
      Map<String, Field> result = field.getValueAsMap();
      Assert.assertTrue(result.size() == 1);
      Assert.assertTrue(result.containsKey("doubleField"));
      Assert.assertEquals(12345.6789, result.get("doubleField").getValue());
    } finally {
      runner.runDestroy();
    }
  }

  @Test
  public void testReplaceNullLongFields() throws StageException {

    FieldValueReplacerConfig stringFieldReplacement = new FieldValueReplacerConfig();
    stringFieldReplacement.fields = ImmutableList.of("/longField");
    stringFieldReplacement.newValue = "523456789345";

    ProcessorRunner runner = new ProcessorRunner.Builder(FieldValueReplacerDProcessor.class)
      .addConfiguration("nullReplacerConditionalConfigs", null)
      .addConfiguration("fieldsToReplaceIfNull", ImmutableList.of(stringFieldReplacement))
        .addConfiguration("fieldsToConditionallyReplace", null)
      .addConfiguration("onStagePreConditionFailure", OnStagePreConditionFailure.CONTINUE)
      .addOutputLane("a").build();
    runner.runInit();

    try {
      Map<String, Field> map = new LinkedHashMap<>();
      map.put("longField", Field.create(Field.Type.LONG, null));
            Record record = RecordCreator.create("s", "s:1");
      record.set(Field.create(map));

      StageRunner.Output output = runner.runProcess(ImmutableList.of(record));
      Assert.assertEquals(1, output.getRecords().get("a").size());
      Field field = output.getRecords().get("a").get(0).get();
      Assert.assertTrue(field.getValue() instanceof Map);
      Map<String, Field> result = field.getValueAsMap();
      Assert.assertTrue(result.size() == 1);
      Assert.assertTrue(result.containsKey("longField"));
      Assert.assertEquals(523456789345L, result.get("longField").getValue());
    } finally {
      runner.runDestroy();
    }
  }

  @Test
  public void testReplaceNullShortFields() throws StageException {

    FieldValueReplacerConfig stringFieldReplacement = new FieldValueReplacerConfig();
    stringFieldReplacement.fields = ImmutableList.of("/shortField");
    stringFieldReplacement.newValue = "32762";

    ProcessorRunner runner = new ProcessorRunner.Builder(FieldValueReplacerDProcessor.class)
      .addConfiguration("nullReplacerConditionalConfigs", null)
      .addConfiguration("fieldsToReplaceIfNull", ImmutableList.of(stringFieldReplacement))
        .addConfiguration("fieldsToConditionallyReplace", null)
      .addConfiguration("onStagePreConditionFailure", OnStagePreConditionFailure.CONTINUE)
      .addOutputLane("a").build();
    runner.runInit();

    try {
      Map<String, Field> map = new LinkedHashMap<>();
      map.put("shortField", Field.create(Field.Type.SHORT, null));
            Record record = RecordCreator.create("s", "s:1");
      record.set(Field.create(map));

      StageRunner.Output output = runner.runProcess(ImmutableList.of(record));
      Assert.assertEquals(1, output.getRecords().get("a").size());
      Field field = output.getRecords().get("a").get(0).get();
      Assert.assertTrue(field.getValue() instanceof Map);
      Map<String, Field> result = field.getValueAsMap();
      Assert.assertTrue(result.size() == 1);
      Assert.assertTrue(result.containsKey("shortField"));
      Assert.assertEquals((short)32762, result.get("shortField").getValue());
    } finally {
      runner.runDestroy();
    }
  }

  @Test
  public void testReplaceNullFloatFields() throws StageException {

    FieldValueReplacerConfig stringFieldReplacement = new FieldValueReplacerConfig();
    stringFieldReplacement.fields = ImmutableList.of("/floatField");
    stringFieldReplacement.newValue = "10.345f";

    ProcessorRunner runner = new ProcessorRunner.Builder(FieldValueReplacerDProcessor.class)
      .addConfiguration("nullReplacerConditionalConfigs", null)
      .addConfiguration("fieldsToReplaceIfNull", ImmutableList.of(stringFieldReplacement))
        .addConfiguration("fieldsToConditionallyReplace", null)
      .addConfiguration("onStagePreConditionFailure", OnStagePreConditionFailure.CONTINUE)
      .addOutputLane("a").build();
    runner.runInit();

    try {
      Map<String, Field> map = new LinkedHashMap<>();
      map.put("floatField", Field.create(Field.Type.FLOAT, null));
            Record record = RecordCreator.create("s", "s:1");
      record.set(Field.create(map));

      StageRunner.Output output = runner.runProcess(ImmutableList.of(record));
      Assert.assertEquals(1, output.getRecords().get("a").size());
      Field field = output.getRecords().get("a").get(0).get();
      Assert.assertTrue(field.getValue() instanceof Map);
      Map<String, Field> result = field.getValueAsMap();
      Assert.assertTrue(result.size() == 1);
      Assert.assertTrue(result.containsKey("floatField"));
      Assert.assertEquals(10.345f, result.get("floatField").getValue());
    } finally {
      runner.runDestroy();
    }
  }

  @Test
  public void testReplaceNullDecimalFields() throws StageException {

    FieldValueReplacerConfig stringFieldReplacement = new FieldValueReplacerConfig();
    stringFieldReplacement.fields = ImmutableList.of("/decimalField");
    stringFieldReplacement.newValue = "12345678";

    ProcessorRunner runner = new ProcessorRunner.Builder(FieldValueReplacerDProcessor.class)
      .addConfiguration("nullReplacerConditionalConfigs", null)
      .addConfiguration("fieldsToReplaceIfNull", ImmutableList.of(stringFieldReplacement))
        .addConfiguration("fieldsToConditionallyReplace", null)
      .addConfiguration("onStagePreConditionFailure", OnStagePreConditionFailure.CONTINUE)
      .addOutputLane("a").build();
    runner.runInit();

    try {
      Map<String, Field> map = new LinkedHashMap<>();
      map.put("decimalField", Field.create(Field.Type.DECIMAL, null));
            Record record = RecordCreator.create("s", "s:1");
      record.set(Field.create(map));

      StageRunner.Output output = runner.runProcess(ImmutableList.of(record));
      Assert.assertEquals(1, output.getRecords().get("a").size());
      Field field = output.getRecords().get("a").get(0).get();
      Assert.assertTrue(field.getValue() instanceof Map);
      Map<String, Field> result = field.getValueAsMap();
      Assert.assertTrue(result.size() == 1);
      Assert.assertTrue(result.containsKey("decimalField"));
      Assert.assertEquals(new BigDecimal(12345678), result.get("decimalField").getValue());
    } finally {
      runner.runDestroy();
    }
  }

  @Test
  public void testReplaceNullByteFields() throws StageException {

    FieldValueReplacerConfig stringFieldReplacement = new FieldValueReplacerConfig();
    stringFieldReplacement.fields = ImmutableList.of("/byteField");
    stringFieldReplacement.newValue = "123";

    ProcessorRunner runner = new ProcessorRunner.Builder(FieldValueReplacerDProcessor.class)
      .addConfiguration("nullReplacerConditionalConfigs", null)
      .addConfiguration("fieldsToReplaceIfNull", ImmutableList.of(stringFieldReplacement))
        .addConfiguration("fieldsToConditionallyReplace", null)
      .addConfiguration("onStagePreConditionFailure", OnStagePreConditionFailure.CONTINUE)
      .addOutputLane("a").build();
    runner.runInit();

    try {
      Map<String, Field> map = new LinkedHashMap<>();
      map.put("byteField", Field.create(Field.Type.BYTE, null));
      Record record = RecordCreator.create("s", "s:1");
      record.set(Field.create(map));
      Assert.assertNotNull(runner);
      Assert.assertNotNull(record);
      Assert.assertNotNull(ImmutableList.of(record));

      StageRunner.Output output = runner.runProcess(ImmutableList.of(record));
      Assert.assertEquals(1, output.getRecords().get("a").size());
      Field field = output.getRecords().get("a").get(0).get();
      Assert.assertTrue(field.getValue() instanceof Map);
      Map<String, Field> result = field.getValueAsMap();
      Assert.assertTrue(result.size() == 1);
      Assert.assertTrue(result.containsKey("byteField"));
      Assert.assertEquals((byte)123, result.get("byteField").getValue());
    } finally {
      runner.runDestroy();
    }
  }

  @Test
  public void testReplaceNullByteArrayFields() throws StageException {

    FieldValueReplacerConfig stringFieldReplacement = new FieldValueReplacerConfig();
    stringFieldReplacement.fields = ImmutableList.of("/byteArrayField");
    stringFieldReplacement.newValue = "streamsets";

    ProcessorRunner runner = new ProcessorRunner.Builder(FieldValueReplacerDProcessor.class)
      .addConfiguration("nullReplacerConditionalConfigs", null)
      .addConfiguration("fieldsToReplaceIfNull", ImmutableList.of(stringFieldReplacement))
        .addConfiguration("fieldsToConditionallyReplace", null)
      .addConfiguration("onStagePreConditionFailure", OnStagePreConditionFailure.CONTINUE)
      .addOutputLane("a").build();
    runner.runInit();

    try {
      Map<String, Field> map = new LinkedHashMap<>();
      map.put("byteArrayField", Field.create(Field.Type.BYTE_ARRAY, null));
            Record record = RecordCreator.create("s", "s:1");
      record.set(Field.create(map));

      StageRunner.Output output = runner.runProcess(ImmutableList.of(record));
      Assert.assertEquals(1, output.getRecords().get("a").size());
      Field field = output.getRecords().get("a").get(0).get();
      Assert.assertTrue(field.getValue() instanceof Map);
      Map<String, Field> result = field.getValueAsMap();
      Assert.assertTrue(result.size() == 1);
      Assert.assertTrue(result.containsKey("byteArrayField"));
      Assert.assertTrue(Arrays.equals("streamsets".getBytes(), result.get("byteArrayField").getValueAsByteArray()));
    } finally {
      runner.runDestroy();
    }
  }

  @Test
  public void testReplaceNullCharFields() throws StageException {

    FieldValueReplacerConfig stringFieldReplacement = new FieldValueReplacerConfig();
    stringFieldReplacement.fields = ImmutableList.of("/charField");
    stringFieldReplacement.newValue = "c";

    ProcessorRunner runner = new ProcessorRunner.Builder(FieldValueReplacerDProcessor.class)
      .addConfiguration("nullReplacerConditionalConfigs", null)
      .addConfiguration("fieldsToReplaceIfNull", ImmutableList.of(stringFieldReplacement))
        .addConfiguration("fieldsToConditionallyReplace", null)
      .addConfiguration("onStagePreConditionFailure", OnStagePreConditionFailure.CONTINUE)
      .addOutputLane("a").build();
    runner.runInit();

    try {
      Map<String, Field> map = new LinkedHashMap<>();
      map.put("charField", Field.create(Field.Type.CHAR, null));
            Record record = RecordCreator.create("s", "s:1");
      record.set(Field.create(map));

      StageRunner.Output output = runner.runProcess(ImmutableList.of(record));
      Assert.assertEquals(1, output.getRecords().get("a").size());
      Field field = output.getRecords().get("a").get(0).get();
      Assert.assertTrue(field.getValue() instanceof Map);
      Map<String, Field> result = field.getValueAsMap();
      Assert.assertTrue(result.size() == 1);
      Assert.assertTrue(result.containsKey("charField"));
      Assert.assertEquals('c', result.get("charField").getValue());
    } finally {
      runner.runDestroy();
    }
  }

  @Test
  public void testReplaceNullBooleanFields() throws StageException {

    FieldValueReplacerConfig stringFieldReplacement = new FieldValueReplacerConfig();
    stringFieldReplacement.fields = ImmutableList.of("/booleanField");
    stringFieldReplacement.newValue = "true";

    ProcessorRunner runner = new ProcessorRunner.Builder(FieldValueReplacerDProcessor.class)
      .addConfiguration("nullReplacerConditionalConfigs", null)
      .addConfiguration("fieldsToReplaceIfNull", ImmutableList.of(stringFieldReplacement))
        .addConfiguration("fieldsToConditionallyReplace", null)
      .addConfiguration("onStagePreConditionFailure", OnStagePreConditionFailure.CONTINUE)
      .addOutputLane("a").build();
    runner.runInit();

    try {
      Map<String, Field> map = new LinkedHashMap<>();
      map.put("booleanField", Field.create(Field.Type.BOOLEAN, null));
            Record record = RecordCreator.create("s", "s:1");
      record.set(Field.create(map));

      StageRunner.Output output = runner.runProcess(ImmutableList.of(record));
      Assert.assertEquals(1, output.getRecords().get("a").size());
      Field field = output.getRecords().get("a").get(0).get();
      Assert.assertTrue(field.getValue() instanceof Map);
      Map<String, Field> result = field.getValueAsMap();
      Assert.assertTrue(result.size() == 1);
      Assert.assertTrue(result.containsKey("booleanField"));
      Assert.assertEquals(true, result.get("booleanField").getValue());
    } finally {
      runner.runDestroy();
    }
  }

  public void testReplaceNullDateTimeTypesFields(Field.Type type, SimpleDateFormat format) throws Exception {
    Date d = format.parse(format.format(new Date()));

    FieldValueReplacerConfig stringFieldReplacement = new FieldValueReplacerConfig();
    stringFieldReplacement.fields = ImmutableList.of("/dateField");
    stringFieldReplacement.newValue = format.format(d);

    ProcessorRunner runner = new ProcessorRunner.Builder(FieldValueReplacerDProcessor.class)
      .addConfiguration("nullReplacerConditionalConfigs", null)
      .addConfiguration("fieldsToReplaceIfNull", ImmutableList.of(stringFieldReplacement))
        .addConfiguration("fieldsToConditionallyReplace", null)
      .addConfiguration("onStagePreConditionFailure", OnStagePreConditionFailure.CONTINUE)
      .addOutputLane("a").build();
    runner.runInit();

    try {
      Map<String, Field> map = new LinkedHashMap<>();
      map.put("dateField", Field.create(type, null));
      Record record = RecordCreator.create("s", "s:1");
      record.set(Field.create(map));

      StageRunner.Output output = runner.runProcess(ImmutableList.of(record));
      Assert.assertEquals(1, output.getRecords().get("a").size());

      Record outputRecord = output.getRecords().get("a").get(0);
      Assert.assertTrue(outputRecord.has("/dateField"));
      Field field = outputRecord.get("/dateField");
      Assert.assertEquals(type, field.getType());
      Assert.assertEquals(d, field.getValueAsDatetime());
    } finally {
      runner.runDestroy();
    }
  }

  @Test
  public void testReplaceNullDateFields() throws Exception {
    testReplaceNullDateTimeTypesFields(Field.Type.DATE, new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH));
  }
  @Test
  public void testReplaceNullTimeFields() throws Exception {
    testReplaceNullDateTimeTypesFields(Field.Type.TIME, new SimpleDateFormat("HH:mm:ss", Locale.ENGLISH));
  }
  @Test
  public void testReplaceNullDateTimeFields() throws Exception {
    testReplaceNullDateTimeTypesFields(Field.Type.DATETIME, new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSZ", Locale.ENGLISH));
  }

  @Test
  public void testFieldsToNullAndReplaceNulls() throws StageException {

    FieldValueReplacerConfig nameReplacement = new FieldValueReplacerConfig();
    nameReplacement.fields = ImmutableList.of("/name");
    nameReplacement.newValue = "StreamSets";

    FieldValueReplacerConfig addressReplacement = new FieldValueReplacerConfig();
    addressReplacement.fields = ImmutableList.of("/streetAddress");
    addressReplacement.newValue = "Sansome Street";

    NullReplacerConditionalConfig nullReplacerConditionalConfig = new NullReplacerConditionalConfig();
    nullReplacerConditionalConfig.fieldsToNull = ImmutableList.of("/age");

    ProcessorRunner runner = new ProcessorRunner.Builder(FieldValueReplacerDProcessor.class)
      .addConfiguration("nullReplacerConditionalConfigs", ImmutableList.of(nullReplacerConditionalConfig))
      .addConfiguration("fieldsToReplaceIfNull", ImmutableList.of(nameReplacement, addressReplacement))
        .addConfiguration("fieldsToConditionallyReplace", null)
      .addConfiguration("onStagePreConditionFailure", OnStagePreConditionFailure.CONTINUE)
      .addOutputLane("a").build();
    runner.runInit();

    try {
      Map<String, Field> map = new LinkedHashMap<>();
      map.put("name", Field.create(Field.Type.STRING, null));
      map.put("age", Field.create(21));
      map.put("streetAddress", Field.create(Field.Type.STRING, null));
            Record record = RecordCreator.create("s", "s:1");
      record.set(Field.create(map));

      StageRunner.Output output = runner.runProcess(ImmutableList.of(record));
      Assert.assertEquals(1, output.getRecords().get("a").size());
      Field field = output.getRecords().get("a").get(0).get();
      Assert.assertTrue(field.getValue() instanceof Map);
      Map<String, Field> result = field.getValueAsMap();
      Assert.assertTrue(result.size() == 3);
      Assert.assertTrue(result.containsKey("name"));
      Assert.assertEquals("StreamSets", result.get("name").getValue());
      Assert.assertTrue(result.containsKey("age"));
      Assert.assertEquals(null, result.get("age").getValue());
      Assert.assertTrue(result.containsKey("streetAddress"));
      Assert.assertEquals("Sansome Street", result.get("streetAddress").getValue());
    } finally {
      runner.runDestroy();
    }
  }

  @Test
  public void testNonNullFields() throws StageException {

    FieldValueReplacerConfig nameReplacement = new FieldValueReplacerConfig();
    nameReplacement.fields = ImmutableList.of("/name");
    nameReplacement.newValue = "NewValue";

    ProcessorRunner runner = new ProcessorRunner.Builder(FieldValueReplacerDProcessor.class)
      .addConfiguration("nullReplacerConditionalConfigs", null)
      .addConfiguration("fieldsToReplaceIfNull", ImmutableList.of(nameReplacement))
        .addConfiguration("fieldsToConditionallyReplace", null)
      .addConfiguration("onStagePreConditionFailure", OnStagePreConditionFailure.CONTINUE)
      .addOutputLane("a").build();
    runner.runInit();

    try {
      Map<String, Field> map = new LinkedHashMap<>();
      map.put("name", Field.create(Field.Type.STRING, "streamsets"));
            Record record = RecordCreator.create("s", "s:1");
      record.set(Field.create(map));

      StageRunner.Output output = runner.runProcess(ImmutableList.of(record));
      Assert.assertEquals(1, output.getRecords().get("a").size());
      Field field = output.getRecords().get("a").get(0).get();
      Assert.assertTrue(field.getValue() instanceof Map);
      Map<String, Field> result = field.getValueAsMap();
      Assert.assertTrue(result.size() == 1);
      Assert.assertTrue(result.containsKey("name"));
      Assert.assertEquals("streamsets", result.get("name").getValue());
    } finally {
      runner.runDestroy();
    }
  }

  @Test
  public void testWildCardReplacement() throws StageException {

    Field name1 = Field.create("jon");
    Field name2 = Field.create("natty");
    Map<String, Field> nameMap1 = new HashMap<>();
    nameMap1.put("name", name1);
    Map<String, Field> nameMap2 = new HashMap<>();
    nameMap2.put("name", name2);

    Field name3 = Field.create("adam");
    Field name4 = Field.create("hari");
    Map<String, Field> nameMap3 = new HashMap<>();
    nameMap3.put("name", name3);
    Map<String, Field> nameMap4 = new HashMap<>();
    nameMap4.put("name", name4);

    Field name5 = Field.create(Field.Type.STRING, null);
    Field name6 = Field.create(Field.Type.STRING, null);
    Map<String, Field> nameMap5 = new HashMap<>();
    nameMap5.put("name", name5);
    Map<String, Field> nameMap6 = new HashMap<>();
    nameMap6.put("name", name6);

    Field first = Field.create(Field.Type.LIST, ImmutableList.of(Field.create(nameMap1), Field.create(nameMap2)));
    Field second = Field.create(Field.Type.LIST, ImmutableList.of(Field.create(nameMap3), Field.create(nameMap4)));
    Field third = Field.create(Field.Type.LIST, ImmutableList.of(Field.create(nameMap5), Field.create(nameMap6)));

    Map<String, Field> noe = new HashMap<>();
    noe.put("streets", Field.create(ImmutableList.of(first, second)));

    Map<String, Field> cole = new HashMap<>();
    cole.put("streets", Field.create(ImmutableList.of(third)));

    Map<String, Field> sfArea = new HashMap<>();
    sfArea.put("noe", Field.create(noe));

    Map<String, Field> utahArea = new HashMap<>();
    utahArea.put("cole", Field.create(cole));

    Map<String, Field> california = new HashMap<>();
    california.put("SanFrancisco", Field.create(sfArea));

    Map<String, Field> utah = new HashMap<>();
    utah.put("SantaMonica", Field.create(utahArea));

    Map<String, Field> map = new LinkedHashMap<>();
    map.put("USA", Field.create(Field.Type.LIST,
      ImmutableList.of(Field.create(california), Field.create(utah))));

    Record record = RecordCreator.create("s", "s:1");
    record.set(Field.create(map));

    Assert.assertEquals(record.get("/USA[0]/SanFrancisco/noe/streets[0][0]/name").getValueAsString(), "jon");
    Assert.assertEquals(record.get("/USA[0]/SanFrancisco/noe/streets[0][1]/name").getValueAsString(), "natty");
    Assert.assertEquals(record.get("/USA[0]/SanFrancisco/noe/streets[1][0]/name").getValueAsString(), "adam");
    Assert.assertEquals(record.get("/USA[0]/SanFrancisco/noe/streets[1][1]/name").getValueAsString(), "hari");
    Assert.assertEquals(record.get("/USA[1]/SantaMonica/cole/streets[0][0]/name").getValueAsString(), null);
    Assert.assertEquals(record.get("/USA[1]/SantaMonica/cole/streets[0][1]/name").getValueAsString(), null);

    /* All the field Paths in the record are
        /USA
        /USA[0]
        /USA[0]/SantaMonica
        /USA[0]/SantaMonica/noe
        /USA[0]/SantaMonica/noe/streets
        /USA[0]/SantaMonica/noe/streets[0]
        /USA[0]/SantaMonica/noe/streets[0][0]
        /USA[0]/SantaMonica/noe/streets[0][0]/name
        /USA[0]/SantaMonica/noe/streets[0][1]
        /USA[0]/SantaMonica/noe/streets[0][1]/name
        /USA[0]/SantaMonica/noe/streets[1]
        /USA[0]/SantaMonica/noe/streets[1][0]
        /USA[0]/SantaMonica/noe/streets[1][0]/name
        /USA[0]/SantaMonica/noe/streets[1][1]
        /USA[0]/SantaMonica/noe/streets[1][1]/name
        /USA[1]
        /USA[1]/SantaMonica
        /USA[1]/SantaMonica/cole
        /USA[1]/SantaMonica/cole/streets
        /USA[1]/SantaMonica/cole/streets[0]
        /USA[1]/SantaMonica/cole/streets[0][0]
        /USA[1]/SantaMonica/cole/streets[0][0]/name
        /USA[1]/SantaMonica/cole/streets[0][1]
        /USA[1]/SantaMonica/cole/streets[0][1]/name
      */

    FieldValueReplacerConfig nameReplacement = new FieldValueReplacerConfig();
    nameReplacement.fields = ImmutableList.of("/USA[*]/SantaMonica/*/streets[*][*]/name");
    nameReplacement.newValue = "Razor";

    NullReplacerConditionalConfig nullReplacerConditionalConfig = new NullReplacerConditionalConfig();
    nullReplacerConditionalConfig.fieldsToNull = ImmutableList.of("/USA[*]/SanFrancisco/*/streets[*][*]/name");

    ProcessorRunner runner = new ProcessorRunner.Builder(FieldValueReplacerDProcessor.class)
      .addConfiguration("nullReplacerConditionalConfigs", ImmutableList.of(nullReplacerConditionalConfig))
      .addConfiguration("fieldsToReplaceIfNull", ImmutableList.of(nameReplacement))
        .addConfiguration("fieldsToConditionallyReplace", null)
      .addConfiguration("onStagePreConditionFailure", OnStagePreConditionFailure.CONTINUE)
      .addOutputLane("a").build();
    runner.runInit();

    try {

      StageRunner.Output output = runner.runProcess(ImmutableList.of(record));
      Assert.assertEquals(1, output.getRecords().get("a").size());

      Record resultRecord = output.getRecords().get("a").get(0);
      Assert.assertEquals(resultRecord.get("/USA[0]/SanFrancisco/noe/streets[0][0]/name").getValueAsString(), null);
      Assert.assertEquals(resultRecord.get("/USA[0]/SanFrancisco/noe/streets[0][1]/name").getValueAsString(), null);
      Assert.assertEquals(resultRecord.get("/USA[0]/SanFrancisco/noe/streets[1][0]/name").getValueAsString(), null);
      Assert.assertEquals(resultRecord.get("/USA[0]/SanFrancisco/noe/streets[1][1]/name").getValueAsString(), null);
      Assert.assertEquals(resultRecord.get("/USA[1]/SantaMonica/cole/streets[0][0]/name").getValueAsString(), "Razor");
      Assert.assertEquals(resultRecord.get("/USA[1]/SantaMonica/cole/streets[0][1]/name").getValueAsString(), "Razor");

    } finally {
      runner.runDestroy();
    }
  }

  @Test
  public void testFieldsToConditionallyReplace() throws StageException {

    FieldValueConditionalReplacerConfig repl = new FieldValueConditionalReplacerConfig();
    repl.operator = "LESS_THAN";
    repl.comparisonValue = "300";
    repl.replacementValue = "100";
    repl.fieldNames = new ArrayList<>();
    repl.fieldNames.add("/money");

    FieldValueConditionalReplacerConfig repl2 = new FieldValueConditionalReplacerConfig();
    repl2.operator = "EQUALS";
    repl2.comparisonValue = "Steve";
    repl2.replacementValue = "Marsha";
    repl2.fieldNames = new ArrayList<>();
    repl2.fieldNames.add("/name");

    FieldValueConditionalReplacerConfig repl3 = new FieldValueConditionalReplacerConfig();
    repl3.operator = "LESS_THAN";
    repl3.comparisonValue = "40.0";
    repl3.replacementValue = "50.5";
    repl3.fieldNames = new ArrayList<>();
    repl3.fieldNames.add("/stateTax");
    repl3.fieldNames.add("/fedTax");

    ArrayList<FieldValueConditionalReplacerConfig> toReplace = new ArrayList<>();
    toReplace.add(repl);
    toReplace.add(repl2);
    toReplace.add(repl3);

    ProcessorRunner runner = new ProcessorRunner.Builder(FieldValueReplacerDProcessor.class)
        .addConfiguration("nullReplacerConditionalConfigs", null)
        .addConfiguration("fieldsToReplaceIfNull", null)
        .addConfiguration("fieldsToConditionallyReplace", toReplace)
        .addConfiguration("onStagePreConditionFailure", OnStagePreConditionFailure.CONTINUE)
        .addOutputLane("a")
        .build();
    runner.runInit();

    try {
      Record record = getConditionallyReplaceRecord();

      StageRunner.Output output = runner.runProcess(ImmutableList.of(record));
      Assert.assertEquals(1, output.getRecords().get("a").size());
      Field field = output.getRecords().get("a").get(0).get();
      Assert.assertTrue(field.getValue() instanceof Map);
      Map<String, Field> result = field.getValueAsMap();
      Assert.assertTrue(result.size() == 5);

      Assert.assertTrue(result.containsKey("name"));
      Assert.assertEquals("Marsha", result.get("name").getValue());

      Assert.assertTrue(result.containsKey("money"));
      Assert.assertEquals(100, result.get("money").getValue());

      Assert.assertTrue(result.containsKey("streetAddress"));
      Assert.assertEquals("123 Street", result.get("streetAddress").getValue());

      Assert.assertTrue(result.containsKey("stateTax"));
      Assert.assertEquals(50.5, result.get("stateTax").getValue());

      Assert.assertTrue(result.containsKey("fedTax"));
      Assert.assertEquals(50.5, result.get("fedTax").getValue());

    } finally {
      runner.runDestroy();
    }
  }

  @NotNull
  protected static Record getConditionallyReplaceRecord() {
    Map<String, Field> map = new LinkedHashMap<>();
    map.put("name", Field.create(Field.Type.STRING, "Steve"));
    map.put("money", Field.create(Field.Type.INTEGER, 200));
    map.put("streetAddress", Field.create(Field.Type.STRING, "123 Street"));
    map.put("stateTax", Field.create(Field.Type.DOUBLE,  7.5));
    map.put("fedTax", Field.create(Field.Type.DOUBLE, 30.34));
    Record record = RecordCreator.create("s", "s:1");
    record.set(Field.create(map));
    return record;
  }

  @Test
  public void testFieldsToConditionallyReplaceInNestedMap() throws StageException {
    FieldValueConditionalReplacerConfig repl = new FieldValueConditionalReplacerConfig();
    repl.operator = "LESS_THAN";
    repl.comparisonValue = "20";
    repl.replacementValue = "3";
    repl.fieldNames = new ArrayList<>();
    repl.fieldNames.add("/pets/dogyears");

    FieldValueConditionalReplacerConfig repl2 = new FieldValueConditionalReplacerConfig();
    repl2.operator = "EQUALS";
    repl2.comparisonValue = "Chip";
    repl2.replacementValue = "Butch";
    repl2.fieldNames = new ArrayList<>();
    repl2.fieldNames.add("/pets/cat");

    ArrayList<FieldValueConditionalReplacerConfig> toReplace = new ArrayList<>();
    toReplace.add(repl);
    toReplace.add(repl2);

    ProcessorRunner runner = new ProcessorRunner.Builder(FieldValueReplacerDProcessor.class)
        .addConfiguration("nullReplacerConditionalConfigs", null)
        .addConfiguration("fieldsToReplaceIfNull", null)
        .addConfiguration("fieldsToConditionallyReplace", toReplace)
        .addConfiguration("onStagePreConditionFailure", OnStagePreConditionFailure.CONTINUE)
        .addOutputLane("a")
        .build();
    runner.runInit();

    try {

      Map<String, Field> map = new LinkedHashMap<>();
      map.put("name", Field.create(Field.Type.STRING, "Steve"));
      map.put("streetAddress", Field.create(Field.Type.STRING, "123 Street"));

      map.put("pets", Field.create(Field.Type.MAP,
          ImmutableMap.builder()
              .put("dog", Field.create(Field.Type.STRING, "Manny"))
              .put("dogyears", Field.create(Field.Type.INTEGER, 19))
              .put("cat", Field.create(Field.Type.STRING, "Chip"))
          .build()));

      Record record = RecordCreator.create("s", "s:1");
      record.set(Field.create(map));

      StageRunner.Output output = runner.runProcess(ImmutableList.of(record));
      Assert.assertEquals(1, output.getRecords().get("a").size());
      Field field = output.getRecords().get("a").get(0).get();
      Assert.assertTrue(field.getValue() instanceof Map);
      Map<String, Field> result = field.getValueAsMap();

      Assert.assertTrue(result.size() == 3);

      Assert.assertTrue(result.containsKey("pets"));

      Field f2 = result.get("pets");
      Map<String, Field> res2 = f2.getValueAsMap();
      Assert.assertTrue(res2.containsKey("dog"));
      Assert.assertEquals("Manny", res2.get("dog").getValueAsString());

      Assert.assertTrue(res2.containsKey("dogyears"));
      Assert.assertEquals(3, res2.get("dogyears").getValueAsInteger());

      Assert.assertTrue(res2.containsKey("cat"));
      Assert.assertEquals("Butch", res2.get("cat").getValueAsString());

    } finally {
      runner.runDestroy();
    }
  }

  @Test
  public void testConditionallyNullStringFieldsIfTheyAreEmpty() throws Exception {
    NullReplacerConditionalConfig nullReplacerConditionalConfig = new NullReplacerConditionalConfig();
    nullReplacerConditionalConfig.fieldsToNull = ImmutableList.of("/stringField");
    nullReplacerConditionalConfig.condition = "${str:length(record:value('/stringField')) == 0}";

    ProcessorRunner runner = new ProcessorRunner.Builder(FieldValueReplacerDProcessor.class)
        .addConfiguration("nullReplacerConditionalConfigs", ImmutableList.of(nullReplacerConditionalConfig))
        .addConfiguration("fieldsToReplaceIfNull", null)
        .addConfiguration("fieldsToConditionallyReplace", null)
        .addConfiguration("onStagePreConditionFailure", OnStagePreConditionFailure.CONTINUE)
        .addOutputLane("a")
        .build();
    runner.runInit();

    try {

      Map<String, Field> map = new LinkedHashMap<>();
      map.put("stringField", Field.create(Field.Type.STRING, ""));

      Record record1 = RecordCreator.create("s", "s:1");
      record1.set(Field.create(map));

      map.clear();

      map.put("stringField", Field.create(Field.Type.STRING, "Steve"));

      Record record2 = RecordCreator.create("s", "s:2");
      record2.set(Field.create(map));

      StageRunner.Output output = runner.runProcess(ImmutableList.of(record1, record2));
      List<Record> outputRecords = output.getRecords().get("a");

      Assert.assertEquals(2, outputRecords.size());

      Record outputRecord1 = outputRecords.get(0);

      Assert.assertTrue(outputRecord1.has("/stringField"));
      Assert.assertNull(outputRecord1.get("/stringField").getValueAsString());

      Record outputRecord2 = outputRecords.get(1);

      Assert.assertTrue(outputRecord2.has("/stringField"));
      Assert.assertNotNull(outputRecord2.get("/stringField").getValueAsString());
      Assert.assertEquals("Steve", outputRecord2.get("/stringField").getValueAsString());
    } finally {
      runner.runDestroy();
    }
  }

  @Test
  public void testConditionallyNullNumericFieldsIfLessThanOrEqualToZero() throws Exception {
    NullReplacerConditionalConfig nullReplacerConditionalConfig1 = new NullReplacerConditionalConfig();
    nullReplacerConditionalConfig1.fieldsToNull = ImmutableList.of("/shortField");
    nullReplacerConditionalConfig1.condition = "${record:value('/shortField') <= 0}";

    NullReplacerConditionalConfig nullReplacerConditionalConfig2 = new NullReplacerConditionalConfig();
    nullReplacerConditionalConfig2.fieldsToNull = ImmutableList.of("/intField");
    nullReplacerConditionalConfig2.condition = "${record:value('/intField') <= 0}";

    NullReplacerConditionalConfig nullReplacerConditionalConfig3 = new NullReplacerConditionalConfig();
    nullReplacerConditionalConfig3.fieldsToNull = ImmutableList.of("/longField");
    nullReplacerConditionalConfig3.condition = "${record:value('/longField') <= 0}";

    NullReplacerConditionalConfig nullReplacerConditionalConfig4 = new NullReplacerConditionalConfig();
    nullReplacerConditionalConfig4.fieldsToNull = ImmutableList.of("/floatField");
    nullReplacerConditionalConfig4.condition = "${record:value('/floatField') <= 0}";

    NullReplacerConditionalConfig nullReplacerConditionalConfig5 = new NullReplacerConditionalConfig();
    nullReplacerConditionalConfig5.fieldsToNull = ImmutableList.of("/doubleField");
    nullReplacerConditionalConfig5.condition = "${record:value('/doubleField') <= 0}";

    NullReplacerConditionalConfig nullReplacerConditionalConfig6 = new NullReplacerConditionalConfig();
    nullReplacerConditionalConfig6.fieldsToNull = ImmutableList.of("/decimalField");
    nullReplacerConditionalConfig6.condition = "${record:value('/decimalField') <= 0}";

    ProcessorRunner runner = new ProcessorRunner.Builder(FieldValueReplacerDProcessor.class)
        .addConfiguration("nullReplacerConditionalConfigs",
            ImmutableList.of(
                nullReplacerConditionalConfig1,
                nullReplacerConditionalConfig2,
                nullReplacerConditionalConfig3,
                nullReplacerConditionalConfig4,
                nullReplacerConditionalConfig5,
                nullReplacerConditionalConfig6
            )
        )
        .addConfiguration("fieldsToReplaceIfNull", null)
        .addConfiguration("fieldsToConditionallyReplace", null)
        .addConfiguration("onStagePreConditionFailure", OnStagePreConditionFailure.CONTINUE)
        .addOutputLane("a")
        .build();
    runner.runInit();

    try {

      Map<String, Field> map = new LinkedHashMap<>();
      map.put("shortField", Field.create(Field.Type.SHORT, 0));
      map.put("intField", Field.create(Field.Type.INTEGER, 0));
      map.put("longField", Field.create(Field.Type.LONG, 0L));
      map.put("floatField", Field.create(Field.Type.FLOAT, 0.0000F));
      map.put("doubleField", Field.create(Field.Type.DOUBLE, 0.0000D));
      map.put("decimalField", Field.create(Field.Type.DECIMAL, BigDecimal.valueOf(0).setScale(20, BigDecimal.ROUND_UNNECESSARY)));

      Record record1 = RecordCreator.create("s", "s:1");
      record1.set(Field.create(map));

      map.clear();
      map.put("shortField", Field.create(Field.Type.SHORT, -1));
      map.put("intField", Field.create(Field.Type.INTEGER, -2));
      map.put("longField", Field.create(Field.Type.LONG, -3L));
      map.put("floatField", Field.create(Field.Type.FLOAT, -4.05F));
      map.put("doubleField", Field.create(Field.Type.DOUBLE, -5.06D));
      map.put("decimalField", Field.create(Field.Type.DECIMAL, BigDecimal.valueOf(-6.07).setScale(20, BigDecimal.ROUND_DOWN)));

      Record record2 = RecordCreator.create("s", "s:2");
      record2.set(Field.create(map));

      map.clear();
      map.put("shortField", Field.create(Field.Type.SHORT, 1));
      map.put("intField", Field.create(Field.Type.INTEGER, 2));
      map.put("longField", Field.create(Field.Type.LONG, 3L));
      map.put("floatField", Field.create(Field.Type.FLOAT, 4.05F));
      map.put("doubleField", Field.create(Field.Type.DOUBLE, 5.06D));
      map.put("decimalField", Field.create(Field.Type.DECIMAL, BigDecimal.valueOf(6.07).setScale(20, BigDecimal.ROUND_UP)));

      Record record3 = RecordCreator.create("s", "s:3");
      record3.set(Field.create(map));

      StageRunner.Output output = runner.runProcess(ImmutableList.of(record1, record2, record3));
      List<Record> outputRecords = output.getRecords().get("a");

      Assert.assertEquals(3, outputRecords.size());

      Record outputRecord1 = outputRecords.get(0);

      Assert.assertNull(outputRecord1.get("/shortField").getValue());
      Assert.assertNull(outputRecord1.get("/intField").getValue());
      Assert.assertNull(outputRecord1.get("/longField").getValue());
      Assert.assertNull(outputRecord1.get("/floatField").getValue());
      Assert.assertNull(outputRecord1.get("/doubleField").getValue());
      Assert.assertNull(outputRecord1.get("/decimalField").getValue());

      Record outputRecord2 = outputRecords.get(1);

      Assert.assertNull(outputRecord2.get("/shortField").getValue());
      Assert.assertNull(outputRecord2.get("/intField").getValue());
      Assert.assertNull(outputRecord2.get("/longField").getValue());
      Assert.assertNull(outputRecord2.get("/floatField").getValue());
      Assert.assertNull(outputRecord2.get("/doubleField").getValue());
      Assert.assertNull(outputRecord2.get("/decimalField").getValue());

      Record outputRecord3 = outputRecords.get(2);

      Assert.assertEquals(1, outputRecord3.get("/shortField").getValueAsShort());
      Assert.assertEquals(2, outputRecord3.get("/intField").getValueAsInteger());
      Assert.assertEquals(3L, outputRecord3.get("/longField").getValue());
      Assert.assertEquals(4.05F, outputRecord3.get("/floatField").getValueAsFloat(), 0);
      Assert.assertEquals(5.06D, outputRecord3.get("/doubleField").getValueAsDouble(), 0);
      Assert.assertEquals(
          BigDecimal.valueOf(6.07).setScale(20, BigDecimal.ROUND_UP),
          outputRecord3.get("/decimalField").getValueAsDecimal()
      );

    } finally {
      runner.runDestroy();
    }
  }

  @Test
  public void testConditionallyNullMultipleFieldsWithSingleCondition() throws Exception {
    NullReplacerConditionalConfig nullReplacerConditionalConfig = new NullReplacerConditionalConfig();
    nullReplacerConditionalConfig.fieldsToNull = ImmutableList.of("/b", "/c", "/d", "/e[*]", "/f/*");
    nullReplacerConditionalConfig.condition = "${record:value('/a') == NULL}";

    ProcessorRunner runner = new ProcessorRunner.Builder(FieldValueReplacerDProcessor.class)
        .addConfiguration("nullReplacerConditionalConfigs", ImmutableList.of(nullReplacerConditionalConfig))
        .addConfiguration("fieldsToReplaceIfNull", null)
        .addConfiguration("fieldsToConditionallyReplace", null)
        .addConfiguration("onStagePreConditionFailure", OnStagePreConditionFailure.CONTINUE)
        .addOutputLane("a")
        .build();
    runner.runInit();

    try {
      Map<String, Field> map = new LinkedHashMap<>();
      map.put("a", Field.create(Field.Type.STRING, null));
      map.put("b", Field.create(Field.Type.INTEGER, 2));
      map.put("c", Field.create(Field.Type.SHORT, 3));
      map.put("d", Field.create(Field.Type.LONG, 4L));
      map.put("e", Field.create(Field.Type.LIST, ImmutableList.of(Field.create("list1_1"), Field.create("list1_2"), Field.create("list1_3"))));
      map.put("f", Field.create(Field.Type.LIST_MAP, new LinkedHashMap<>(ImmutableMap.of("map_a", Field.create("map_a1"), "map_b", Field.create("map_b1"), "map_c", Field.create("map_c1")))));

      Record record1 = RecordCreator.create("s", "s:1");
      record1.set(Field.create(map));

      map.clear();
      map.put("a", Field.create(Field.Type.STRING, "Not Null"));
      map.put("b", Field.create(Field.Type.INTEGER, 2));
      map.put("c", Field.create(Field.Type.SHORT, 3));
      map.put("d", Field.create(Field.Type.LONG, 4L));
      map.put("e", Field.create(Field.Type.LIST, ImmutableList.of(Field.create("list2_1"), Field.create("list2_2"), Field.create("list2_3"))));
      map.put("f", Field.create(Field.Type.LIST_MAP, new LinkedHashMap<>(ImmutableMap.of("map_a", Field.create("map2_1"), "map_b", Field.create("map2_2"), "map_c", Field.create("map2_3")))));

      Record record2 = RecordCreator.create("s", "s:2");
      record2.set(Field.create(map));

      StageRunner.Output output = runner.runProcess(ImmutableList.of(record1, record2));
      List<Record> outputRecords = output.getRecords().get("a");

      Assert.assertEquals(2, outputRecords.size());

      Record outputRecord1 = outputRecords.get(0);

      Assert.assertNull(outputRecord1.get("/a").getValue());
      Assert.assertNull(outputRecord1.get("/b").getValue());
      Assert.assertNull(outputRecord1.get("/c").getValue());
      Assert.assertNull(outputRecord1.get("/d").getValue());

      Assert.assertNotNull(outputRecord1.get("/e").getValue());
      for (Field list_field : outputRecord1.get("/e").getValueAsList()) {
        Assert.assertNull(list_field.getValue());
      }

      Assert.assertNotNull(outputRecord1.get("/f").getValue());
      for (Field map_field : outputRecord1.get("/f").getValueAsMap().values()) {
        Assert.assertNull(map_field.getValue());
      }

      Record outputRecord2 = outputRecords.get(1);
      Assert.assertEquals("Not Null", outputRecord2.get("/a").getValueAsString());
      Assert.assertEquals(2, outputRecord2.get("/b").getValueAsInteger());
      Assert.assertEquals(3, outputRecord2.get("/c").getValueAsShort());
      Assert.assertEquals(4L, outputRecord2.get("/d").getValueAsLong());
      Assert.assertNotNull(outputRecord2.get("/e").getValue());
      int i = 1;
      for (Field list_field : outputRecord2.get("/e").getValueAsList()) {
        Assert.assertNotNull(list_field.getValue());
        Assert.assertEquals("list2_" + (i++), list_field.getValueAsString());
      }
      Assert.assertNotNull(outputRecord1.get("/f").getValue());
      i = 1;
      for (Field map_field : outputRecord2.get("/f").getValueAsMap().values()) {
        Assert.assertNotNull(map_field.getValue());
        Assert.assertEquals("map2_" + (i++), map_field.getValueAsString());

      }
    } finally {
      runner.runDestroy();
    }
  }

  @Test
  public void testPreserveExceptionCauseReplacementValue() throws StageException {

    FieldValueConditionalReplacerConfig replacement1 = new FieldValueConditionalReplacerConfig();
    replacement1.operator = "LESS_THAN";
    replacement1.comparisonValue = "40.0";
    replacement1.replacementValue = "invalidNumber";
    replacement1.fieldNames = new ArrayList<>();
    replacement1.fieldNames.add("/stateTax");
    replacement1.fieldNames.add("/fedTax");

    assertNumberFormatExceptionCause(replacement1);
  }

  @Test
  public void testPreserveExceptionCauseComparisonValue() throws StageException {
    FieldValueConditionalReplacerConfig replacement1 = new FieldValueConditionalReplacerConfig();
    replacement1.operator = "LESS_THAN";
    replacement1.comparisonValue = "stillInvalidNumber";
    replacement1.replacementValue = "25.0";
    replacement1.fieldNames = new ArrayList<>();
    replacement1.fieldNames.add("/stateTax");
    replacement1.fieldNames.add("/fedTax");

    assertNumberFormatExceptionCause(replacement1);
  }

  public static void assertNumberFormatExceptionCause(FieldValueConditionalReplacerConfig config) throws StageException {

    ProcessorRunner runner = new ProcessorRunner.Builder(FieldValueReplacerDProcessor.class)
        .addConfiguration("nullReplacerConditionalConfigs", null)
        .addConfiguration("fieldsToReplaceIfNull", null)
        .addConfiguration("fieldsToConditionallyReplace", Collections.singletonList(config))
        .addConfiguration("onStagePreConditionFailure", OnStagePreConditionFailure.CONTINUE)
        .addOutputLane("a")
        .build();
    runner.runInit();

    try {
      Record record = getConditionallyReplaceRecord();

      try {
        StageRunner.Output output = runner.runProcess(ImmutableList.of(record));
        Assert.fail("Exception should have been thrown");
      } catch (Exception e) {
        // IllegalArgumentException is the type we throw
        assertThat(e, instanceOf(IllegalArgumentException.class));
        assertThat(e.getCause(), notNullValue());
        // in the case of exception during comparison, there is another wrapped IllegalArgumentException
        assertThat(e.getCause(), instanceOf(NumberFormatException.class));
      }
    } finally {
      runner.runDestroy();
    }
  }
}


text:
/** @file texture.h
 *  @brief Defines texture helper structures for the library
 *
 * Used for file formats which embed their textures into the model file.
 * Supported are both normal textures, which are stored as uncompressed
 * pixels, and "compressed" textures, which are stored in a file format
 * such as PNG or TGA.
 */
#pragma once
#ifndef AI_TEXTURE_H_INC
#define AI_TEXTURE_H_INC

#include "types.h"

#ifdef __cplusplus
extern "C" {
#endif

// --------------------------------------------------------------------------------

/** \def AI_EMBEDDED_TEXNAME_PREFIX
 * \ref AI_MAKE_EMBEDDED_TEXNAME
 */
#ifndef AI_EMBEDDED_TEXNAME_PREFIX
#   define AI_EMBEDDED_TEXNAME_PREFIX	"*"
#endif

/** @def AI_MAKE_EMBEDDED_TEXNAME
 *  Used to build the reserved path name used by the material system to
 *  reference textures that are embedded into their corresponding
 *  model files. The parameter specifies the index of the texture
 *  (zero-based, in the aiScene::mTextures array)
 */
#if (!defined AI_MAKE_EMBEDDED_TEXNAME)
#   define AI_MAKE_EMBEDDED_TEXNAME(_n_) AI_EMBEDDED_TEXNAME_PREFIX # _n_
#endif

#include "./Compiler/pushpack1.h"

// --------------------------------------------------------------------------------
/** @brief Helper structure to represent a texel in a ARGB8888 format
*
*  Used by aiTexture.
*/
struct aiTexel
{
    unsigned char b,g,r,a;

#ifdef __cplusplus
    //! Comparison operator
    bool operator== (const aiTexel& other) const
    {
        return b == other.b && r == other.r &&
               g == other.g && a == other.a;
    }

    //! Inverse comparison operator
    bool operator!= (const aiTexel& other) const
    {
        return b != other.b || r != other.r ||
               g != other.g || a != other.a;
    }

    //! Conversion to a floating-point 4d color
    operator aiColor4D() const
    {
        return aiColor4D(r/255.f,g/255.f,b/255.f,a/255.f);
    }
#endif // __cplusplus

} PACK_STRUCT;

#include "./Compiler/poppack1.h"

// --------------------------------------------------------------------------------
/** Helper structure to describe an embedded texture
 *
 * Normally textures are contained in external files but some file formats embed
 * them directly in the model file. There are two types of embedded textures:
 * 1. Uncompressed textures. The color data is given in an uncompressed format.
 * 2. Compressed textures stored in a file format like png or jpg. The raw file
 * bytes are given so the application must utilize an image decoder (e.g. DevIL) to
 * get access to the actual color data.
 *
 * Embedded textures are referenced from materials using strings like "*0", "*1", etc.
 * as the texture paths (a single asterisk character followed by the
 * zero-based index of the texture in the aiScene::mTextures array).
 */
struct aiTexture
{
    /** Width of the texture, in pixels
     *
     * If mHeight is zero the texture is compressed in a format
     * like JPEG. In this case mWidth specifies the size of the
     * memory area pcData is pointing to, in bytes.
     */
    unsigned int mWidth;

    /** Height of the texture, in pixels
     *
     * If this value is zero, pcData points to an compressed texture
     * in any format (e.g. JPEG).
     */
    unsigned int mHeight;

    /** A hint from the loader to make it easier for applications
     *  to determine the type of embedded textures.
     *
     * If mHeight != 0 this member is show how data is packed. Hint will consist of
     * two parts: channel order and channel bitness (count of the bits for every
     * color channel). For simple parsing by the viewer it's better to not omit
     * absent color channel and just use 0 for bitness. For example:
     * 1. Image contain RGBA and 8 bit per channel, achFormatHint == "rgba8888";
     * 2. Image contain ARGB and 8 bit per channel, achFormatHint == "argb8888";
     * 3. Image contain RGB and 5 bit for R and B channels and 6 bit for G channel, achFormatHint == "rgba5650";
     * 4. One color image with B channel and 1 bit for it, achFormatHint == "rgba0010";
     * If mHeight == 0 then achFormatHint is set set to '\\0\\0\\0\\0' if the loader has no additional
     * information about the texture file format used OR the
     * file extension of the format without a trailing dot. If there
     * are multiple file extensions for a format, the shortest
     * extension is chosen (JPEG maps to 'jpg', not to 'jpeg').
     * E.g. 'dds\\0', 'pcx\\0', 'jpg\\0'.  All characters are lower-case.
     * The fourth character will always be '\\0'.
     */
    char achFormatHint[9];// 8 for string + 1 for terminator.

    /** Data of the texture.
     *
     * Points to an array of mWidth * mHeight aiTexel's.
     * The format of the texture data is always ARGB8888 to
     * make the implementation for user of the library as easy
     * as possible. If mHeight = 0 this is a pointer to a memory
     * buffer of size mWidth containing the compressed texture
     * data. Good luck, have fun!
     */
    C_STRUCT aiTexel* pcData;

#ifdef __cplusplus

    //! For compressed textures (mHeight == 0): compare the
    //! format hint against a given string.
    //! @param s Input string. 3 characters are maximally processed.
    //!        Example values: "jpg", "png"
    //! @return true if the given string matches the format hint
    bool CheckFormat(const char* s) const
    {
		return (0 == ::strncmp(achFormatHint, s, sizeof(achFormatHint)));
    }

    // Construction
    aiTexture ()
        : mWidth  (0)
        , mHeight (0)
        , pcData  (NULL)
    {
        achFormatHint[0] = achFormatHint[1] = 0;
        achFormatHint[2] = achFormatHint[3] = 0;
    }

    // Destruction
    ~aiTexture ()
    {
        delete[] pcData;
    }
#endif
};

#ifdef __cplusplus
}
#endif

#endif // AI_TEXTURE_H_INC


text:
<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Copyright 2014 Stephen Connolly.
  ~
  ~ 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.
  -->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>io.github.stephenc.maven.rfmm.its</groupId>
  <artifactId>maven-scm-provider-dummy</artifactId>
  <version>1.0</version>

  <name>Maven SCM Dummy Provider</name>
  <description>Does nothing but telling the Release Plugin that the working copy is up-to-date.</description>

  <dependencies>
    <dependency>
      <groupId>org.apache.maven.scm</groupId>
      <artifactId>maven-scm-api</artifactId>
      <version>1.1</version>
    </dependency>
    <dependency>
      <groupId>commons-io</groupId>
      <artifactId>commons-io</artifactId>
      <version>2.3</version>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.0.2</version>
        <configuration>
          <source>1.4</source>
          <target>1.4</target>
          <encoding>UTF-8</encoding>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.codehaus.plexus</groupId>
        <artifactId>plexus-maven-plugin</artifactId>
        <version>1.3.8</version>
        <executions>
          <execution>
            <goals>
              <goal>descriptor</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>