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

import static org.testng.AssertJUnit.assertEquals;
import java.util.concurrent.atomic.AtomicInteger;

import org.testng.annotations.Test;

import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import com.orientechnologies.orient.core.hook.ORecordHook;
import com.orientechnologies.orient.core.record.ORecord;
import com.orientechnologies.orient.core.record.impl.ODocument;

public class HookRegisterRemoveTest {

  @Test
  public void addAndRemoveHookTest() {

    ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory:" + HookRegisterRemoveTest.class.getSimpleName());
    db.create();
    final AtomicInteger integer = new AtomicInteger(0);
    ORecordHook iHookImpl = new ORecordHook() {

      @Override
      public void onUnregister() {

      }

      @Override
      public RESULT onTrigger(TYPE iType, ORecord iRecord) {
        integer.incrementAndGet();
        return null;
      }

      @Override
      public DISTRIBUTED_EXECUTION_MODE getDistributedExecutionMode() {
        return null;
      }
    };
    db.registerHook(iHookImpl);

    db.save(new ODocument());
    assertEquals(3, integer.get());
    db.unregisterHook(iHookImpl);
    db.save(new ODocument());
    assertEquals(3, integer.get());
    db.drop();
  }
}

@@ -96,16 +96,17 @@
 Equals;%0A
+%0A
 import j
@@ -185,16 +185,86 @@
 .Test;%0A%0A
+import com.orientechnologies.orient.core.config.OGlobalConfiguration;%0A
 import c
@@ -445,16 +445,16 @@
 Record;%0A
-
 import c
@@ -508,16 +508,130 @@
 ocument;
+%0Aimport com.orientechnologies.orient.core.serialization.serializer.record.string.ORecordSerializerSchemaAware2CSV;
 %0A%0Apublic
@@ -1324,32 +1324,54 @@
 (new ODocument()
+.field(%22test%22, %22test%22)
 );%0A    assertEqu

fix hook tests in case of csv serialization.