package io.searchbox.indices.script;

import io.searchbox.client.JestResult;
import io.searchbox.common.AbstractIntegrationTest;
import org.elasticsearch.action.admin.cluster.storedscripts.GetStoredScriptResponse;
import org.elasticsearch.test.ESIntegTestCase;
import org.junit.Test;

import java.io.IOException;
import static io.searchbox.indices.script.ScriptLanguage.GROOVY;

@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 1)
public class CreateIndexedScriptIntegrationTest extends AbstractIntegrationTest {

    @Test
    public void createAnIndexedScript() throws IOException {
        String name = "script-test";
        String script = "def aVariable = 1\n" +
                "return aVariable";

        CreateStoredScript createIndexedScript = new CreateStoredScript.Builder(name)
                .setLanguage(GROOVY)
                .setSource(script)
                .build();
        JestResult result = client.execute(createIndexedScript);
        assertTrue(result.getErrorMessage(), result.isSucceeded());

        GetStoredScriptResponse getIndexedScriptResponse =
                client().admin().cluster().prepareGetStoredScript().setId(name).get();
        assertNotNull(getIndexedScriptResponse.getStoredScript());
        assertEquals(script, getIndexedScriptResponse.getStoredScript());
    }
}


@@ -306,16 +306,17 @@
 eption;%0A
+%0A
 import s
@@ -364,22 +364,24 @@
 anguage.
-GROOVY
+PAINLESS
 ;%0A%0A@ESIn
@@ -679,11 +679,11 @@
  = %22
-def
+int
  aVa
@@ -696,31 +696,10 @@
  = 1
-%5Cn%22 +%0A                %22
+; 
 retu
@@ -833,14 +833,16 @@
 age(
-GROOVY
+PAINLESS
 )%0A  
@@ -1093,16 +1093,16 @@
 ponse =%0A
-
         
@@ -1160,16 +1160,86 @@
 Script()
+%0A                        .setLang(%22painless%22)%0A                        
 .setId(n

Fix CreateIndexedScriptIntegrationTest