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.action.admin.cluster.storedscripts.PutStoredScriptResponse;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.test.ESIntegTestCase;
import org.junit.Test;

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

    private static final String A_SCRIPT_NAME = "script-test";

    @Test
    public void delete_an_indexed_script_for_Groovy() throws Exception {
        PutStoredScriptResponse response = client().admin().cluster().preparePutStoredScript().setId(A_SCRIPT_NAME)
                .setSource(new BytesArray("{\"script\":\"def aVariable = 1\\nreturn aVariable\"}")).get();
        assertTrue("could not create indexed script on server", response.isAcknowledged());

        DeleteStoredScript deleteIndexedScript = new DeleteStoredScript.Builder(A_SCRIPT_NAME)
                .setLanguage(ScriptLanguage.GROOVY)
                .build();
        JestResult result = client.execute(deleteIndexedScript);
        assertTrue(result.getErrorMessage(), result.isSucceeded());

        GetStoredScriptResponse getIndexedScriptResponse =
                client().admin().cluster().prepareGetStoredScript().setId(A_SCRIPT_NAME).get();
        assertNull("Script should have been deleted", getIndexedScriptResponse.getStoredScript());
    }
}


@@ -813,32 +813,92 @@
 utStoredScript()
+%0A                .setScriptLang(%22painless%22)%0A                
 .setId(A_SCRIPT_
@@ -964,11 +964,11 @@
 %22:%5C%22
-def
+int
  aVa
@@ -981,11 +981,10 @@
  = 1
-%5C%5Cn
+; 
 retu
@@ -1245,14 +1245,16 @@
 age.
-GROOVY
+PAINLESS
 )%0A  
@@ -1470,16 +1470,16 @@
 ponse =%0A
-
         
@@ -1537,16 +1537,86 @@
 Script()
+%0A                        .setLang(%22painless%22)%0A                        
 .setId(A

Fix DeleteIndexedScriptIntegrationTest