/*
 *
 *  * Copyright 2014 Orient Technologies.
 *  *
 *  * 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.
 *  
 */

package com.orientechnologies.lucene.test;

import com.orientechnologies.orient.core.command.script.OCommandScript;
import com.orientechnologies.orient.core.sql.OCommandSQL;
import org.testng.annotations.Test;

import java.io.InputStream;

/**
 * Created by enricorisa on 26/09/14.
 */
@Test(groups = "remote")
public class LuceneCreateIndexRemote extends LuceneCreateIndexTest {

  public LuceneCreateIndexRemote() {
    super(true);
  }

  @Override
  protected String getDatabaseName() {
    return "createIndexRemote";
  }

  @Override
  public void loadAndTest() {
    InputStream stream = ClassLoader.getSystemResourceAsStream("testLuceneIndex.sql");

    databaseDocumentTx.command(new OCommandScript("sql", getScriptFromStream(stream))).execute();

    databaseDocumentTx.command(new OCommandSQL("create index Song.title on Song (title) FULLTEXT ENGINE LUCENE")).execute();
    databaseDocumentTx.command(new OCommandSQL("create index Song.author on Song (author) FULLTEXT ENGINE LUCENE")).execute();

    assertQuery();

    restart();

    assertQuery();
  }
}

@@ -807,23 +807,180 @@
 ore.
-sql.OCommandSQL
+record.impl.ODocument;%0Aimport com.orientechnologies.orient.core.sql.OCommandSQL;%0Aimport com.orientechnologies.orient.core.sql.query.OSQLSynchQuery;%0Aimport org.testng.Assert
 ;%0Aim
@@ -1041,16 +1041,39 @@
 tStream;
+%0Aimport java.util.List;
 %0A%0A/**%0A *
@@ -1890,15 +1890,462 @@
 Query();
+%0A%0A    ODocument doc = new ODocument(%22Song%22);%0A%0A    doc.field(%22title%22, %22Test%22);%0A    doc.field(%22author%22, %22Author%22);%0A%0A    databaseDocumentTx.save(doc);%0A%0A    assertNewQuery();%0A%0A    restart();%0A%0A    assertNewQuery();%0A%0A  %7D%0A%0A  protected void assertNewQuery() %7B%0A%0A    List%3CODocument%3E docs = databaseDocumentTx.query(new OSQLSynchQuery%3CODocument%3E(%0A        %22select * from Song where %5Btitle%5D LUCENE %5C%22(title:Test)%5C%22%22));%0A%0A    Assert.assertEquals(docs.size(), 1);
 %0A  %7D%0A%7D%0A

test on shutdown