1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.neo4j.server.database;
21
22 import static org.hamcrest.Matchers.containsString;
23 import static org.junit.Assert.assertThat;
24
25 import java.io.File;
26 import java.io.IOException;
27
28 import org.apache.commons.io.FileUtils;
29 import org.junit.After;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.neo4j.graphdb.TransactionFailureException;
33 import org.neo4j.server.ServerTestUtils;
34 import org.neo4j.server.logging.InMemoryAppender;
35
36 public class DatabaseTest {
37
38 private File databaseDirectory;
39 private Database theDatabase;
40 private boolean deletionFailureOk;
41
42 @Before
43 public void setup() throws Exception {
44 databaseDirectory = ServerTestUtils.createTempDir();
45 theDatabase = new Database( ServerTestUtils.EMBEDDED_GRAPH_DATABASE_FACTORY,
46 databaseDirectory.getAbsolutePath() );
47 }
48
49 @After
50 public void shutdownDatabase() throws IOException
51 {
52 this.theDatabase.shutdown();
53
54 try
55 {
56 FileUtils.forceDelete( databaseDirectory );
57 }
58 catch ( IOException e )
59 {
60
61
62 if ( !deletionFailureOk )
63 {
64 throw e;
65 }
66 }
67 }
68
69 @Test
70 public void shouldLogOnSuccessfulStartup() {
71 InMemoryAppender appender = new InMemoryAppender(Database.log);
72
73 theDatabase.startup();
74
75 assertThat(appender.toString(), containsString("Successfully started database"));
76 }
77
78 @Test
79 public void shouldShutdownCleanly() {
80 InMemoryAppender appender = new InMemoryAppender(Database.log);
81
82 theDatabase.startup();
83 theDatabase.shutdown();
84
85 assertThat(appender.toString(), containsString("Successfully shutdown database"));
86 }
87
88 @Test(expected = TransactionFailureException.class)
89 public void shouldComplainIfDatabaseLocationIsAlreadyInUse() {
90 deletionFailureOk = true;
91 new Database( ServerTestUtils.EMBEDDED_GRAPH_DATABASE_FACTORY, theDatabase.getLocation() );
92 }
93 }