I have a function, which calls an ElasticSearch function:
List<Long> docItems = docFieldLongs(docItemField).getValues();
It then does some calculation and output based on docItems.
The issue is in testing, I do not create a big mock elasticsearch node and such. Instead I want to create an override of this function, to be called in testing.
The question is how do I do this? This new function should be called in the test rather than the Elasticsearch function. I wanted to do something like below, but this doesn't work due to Unknown macro not being available. Else I can create ScriptDocValues.Longs although can't seem to find how to do this!
@Override
private ScriptDocValues.Longs docFieldLongs(String getter){
    List<Long> docFields =  new ArrayList<Long>();
    docFields.add(new Long(101));
    docFields.add(new Long(102));
    Unknown macro: return docFields;
}
My two questions are as follows:
- How to override a function for test purposes only?
- How to imitate the docFieldLongs?
EDIT - note this is NOT a solution, just along the lines to one:
I have been working on this for a while, seems very long winded. Here is a rough solution, so far:
    @Test
public void testRunAsLongs()
{
    script = new MaxiScoreScript(params){
        @Override
        public ScriptDocValues.Longs docFieldLongs(String getter)
        {
            try{
                writer = new IndexWriter(new RAMDirectory(), new IndexWriterConfig(Lucene.VERSION, new StandardAnalyzer(Lucene.VERSION)).setMergePolicy(new LogByteSizeMergePolicy()));
            }
            catch(IOException e){
            }
            Document d  = new Document();
            d.add(new LongField("value", 102, Field.Store.NO));
            d.add(new LongField("value" ,101, Field.Store.NO));
            try{
                writer.addDocument(d);
            }
            catch(IOException e){
            }
            IndexNumericFieldData indexFieldData = null;
            try {
                indexFieldData = IndexFieldDataService.getForField("value");
            }
            catch(IOException e){
                System.out.println("getting field data failed");
            }
            AtomicNumericFieldData fieldData = null;
            try{
                fieldData = indexFieldData.load(refreshReader());
            }
            catch(Exception e)
            {
            }
            return (ScriptDocValues.Longs) fieldData.getScriptValues();
        }
    }
}
If you are interested in seeing the behaviour of docFieldLongs also you may wish to look into Longs
 
    