package com.orientechnologies.orient.core.db.tool;

import com.orientechnologies.orient.core.command.OCommandOutputListener;
import com.orientechnologies.orient.core.db.ODatabaseDocumentInternal;
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import org.junit.Assert;
import org.junit.Test;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

/**
 * Created by tglman on 23/05/16.
 */
public class ODatabaseImportTest {

  @Test
  public void exportImportOnlySchemaTest() throws IOException {
    ODatabaseDocument db = new ODatabaseDocumentTx("memory:" + ODatabaseImportTest.class.getSimpleName());
    db.create();
    db.getMetadata().getSchema().createClass("SimpleClass");
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    ODatabaseExport export = new ODatabaseExport((ODatabaseDocumentInternal) db, output, new OCommandOutputListener() {
      @Override
      public void onMessage(String iText) {
      }
    });

    export.setOptions(" -excludeAll -includeSchema=true");
    export.exportDatabase();
    db.drop();

    ODatabaseDocument dbImp = new ODatabaseDocumentTx("memory:import_" + ODatabaseImportTest.class.getSimpleName());
    dbImp.create();
    ODatabaseImport importer = new ODatabaseImport((ODatabaseDocumentInternal) dbImp,
        new ByteArrayInputStream(output.toByteArray()), new OCommandOutputListener() {
      @Override
      public void onMessage(String iText) {

      }
    });
    importer.importDatabase();

    Assert.assertTrue(dbImp.getMetadata().getSchema().existsClass("SimpleClass"));
    dbImp.drop();
  }

}

@@ -1713,10 +1713,1171 @@
 );%0A  %7D%0A%0A
+  @Test%0A  public void exportImportExcludeClusters() throws IOException %7B%0A    ODatabaseDocument db = new ODatabaseDocumentTx(%22memory:%22 + ODatabaseImportTest.class.getSimpleName()+%22_excludeclusters%22);%0A    db.create();%0A    db.getMetadata().getSchema().createClass(%22SimpleClass%22);%0A    ByteArrayOutputStream output = new ByteArrayOutputStream();%0A    ODatabaseExport export = new ODatabaseExport((ODatabaseDocumentInternal) db, output, new OCommandOutputListener() %7B%0A      @Override%0A      public void onMessage(String iText) %7B%0A      %7D%0A    %7D);%0A%0A    export.setOptions(%22 -includeClusterDefinitions=false%22);%0A    export.exportDatabase();%0A    db.drop();%0A%0A    ODatabaseDocument dbImp = new ODatabaseDocumentTx(%22memory:import_%22 + ODatabaseImportTest.class.getSimpleName());%0A    dbImp.create();%0A    ODatabaseImport importer = new ODatabaseImport((ODatabaseDocumentInternal) dbImp,%0A        new ByteArrayInputStream(output.toByteArray()), new OCommandOutputListener() %7B%0A      @Override%0A      public void onMessage(String iText) %7B%0A%0A      %7D%0A    %7D);%0A    importer.importDatabase();%0A%0A    assertTrue(dbImp.getMetadata().getSchema().existsClass(%22SimpleClass%22));%0A    dbImp.drop();%0A  %7D%0A%0A
 %7D%0A

Add test on import/export with -includeClusterDefinitions=false