/**
 * Copyright (c) 2002-2010 "Neo Technology,"
 * Network Engine for Objects in Lund AB [http://neotechnology.com]
 *
 * This file is part of Neo4j.
 *
 * Neo4j is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

package org.neo4j.server.rrd;

import org.junit.Before;
import org.junit.Test;
import org.neo4j.graphdb.Transaction;
import org.neo4j.kernel.ImpermanentGraphDatabase;

import javax.management.MalformedObjectNameException;
import java.io.IOException;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.core.Is.is;

public class NodeIdsInUseSampleableTest
{
    public ImpermanentGraphDatabase db;
    public NodeIdsInUseSampleable sampleable;

    @Test
    public void emptyDbHasZeroNodesInUse() throws IOException, MalformedObjectNameException
    {
        assertThat( sampleable.getValue(), is( 1L ) ); //Reference node is always created in empty dbs
    }

    @Test
    public void addANodeAndSampleableGoesUp() throws IOException, MalformedObjectNameException
    {
        createNode( db );

        assertThat( sampleable.getValue(), greaterThan( 2L ) );
    }

    private void createNode( ImpermanentGraphDatabase db )
    {
        Transaction tx = db.beginTx();
        db.createNode();
        tx.success();
        tx.finish();
    }

    @Before
    public void setUp() throws Exception
    {
        db = new ImpermanentGraphDatabase();
        sampleable = new NodeIdsInUseSampleable( db );
    }
}

@@ -853,135 +853,169 @@
 ort 
-org.junit.Before;%0Aimport org.junit.Test;%0Aimport org.neo4j.graphdb.Transaction;%0Aimport org.neo4j.kernel.ImpermanentGraphDatabase
+static org.hamcrest.MatcherAssert.assertThat;%0Aimport static org.hamcrest.Matchers.greaterThan;%0Aimport static org.hamcrest.core.Is.is;%0A%0Aimport java.io.IOException
 ;%0A%0Ai
@@ -1071,176 +1071,167 @@
 on;%0A
+%0A
 import 
-java.io.IOException
+org.junit.After
 ;%0A
-%0A
 import 
-static org.hamcrest.MatcherAssert.assertThat;%0Aimport static org.hamcrest.Matchers.greaterThan;%0Aimport static org.hamcrest.core.Is.is
+org.junit.Before;%0Aimport org.junit.Test;%0Aimport org.neo4j.graphdb.Transaction;%0Aimport org.neo4j.kernel.ImpermanentGraphDatabase
 ;%0A%0Ap
@@ -1679,32 +1679,80 @@
 Exception%0A    %7B%0A
+        long oldValue = sampleable.getValue();%0A%0A
         createNo
@@ -1822,10 +1822,16 @@
 an( 
-2L
+oldValue
  ) )
@@ -2182,11 +2182,85 @@
 );%0A    %7D
+%0A%0A    @After%0A    public void shutdown()%0A    %7B%0A        db.shutdown();%0A    %7D
 %0A%7D%0A

Fixed a broken test case.