How to install a plugin before writing a test case on it?

I have created a plugin for custom default scoring in elastic search.
I created a Json template that uses that plugin but as soon as I create an index that uses that template I get an error:

java.lang.IllegalArgumentException: Unknown Similarity type [new_default] for [default]

where, new_default is name of the new default similarity. I have tested the plugin on my local system using cURL commands and it works as expected i.e. I don't get the error above.

I add the template using this:

PutIndexTemplateResponse putResponse = .... // set the template via a Json
GetIndexTemplatesResponse getResponse = client.admin().indices().prepareGetTemplates().get();
assertNotNull(getResponse.getIndexTemplates());
assertThat(getResponse.getIndexTemplates(), hasSize(1));

Both the test cases pass. The template is for indices that start with new_.

And I create an index using createIndex("new_index")

What should I do to correct this?

I have not tried with 2.x, but you should not need to create a plugin for a
new similarity or function score. The code just needs to be deployed as a
jar in elasticsearch's classpath, with the proper naming conventions.

Perhaps there is a chicken-and-egg problem with templates? Can you try
without them?

Ivan

Can you show the complete code so that it can be understood what you do in your plugin?

Especially, how you used addSimilarity() in SimilarityModule

Hi,

This is the class where I define the onModule functions:

public class NewTestPlugin extends Plugin {
    @Override
    public String name() {
        return "scoring-test-plugin";
    }
    @Override
    public String description() {
        return "Enables custom scoring functions";
    }
    public void onModule(SimilarityModule similarityModule) {
        similarityModule.addSimilarity("new_default", NewSimilarityProvider.class);
    }
}

@jprante

I have added the code where I use the addSimilarity function.

I need some time to reproduce, looks like template is not working.

The code for

PutIndexTemplateResponse putResponse = .... // set the template via a Json

would help.

Thanks for the reply.
After some debugging I noticed that there was an issue in TestCase only.
The test case was not extending ESIntegTestCase. When I did that, this error was not there any more!!