1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.neo4j.server.configuration;
21
22 import org.neo4j.server.ServerTestUtils;
23
24 import java.io.File;
25 import java.io.IOException;
26 import java.util.ArrayList;
27
28 import static org.neo4j.server.ServerTestUtils.createTempPropertyFile;
29 import static org.neo4j.server.ServerTestUtils.writePropertyToFile;
30
31 public class PropertyFileBuilder
32 {
33
34 private String portNo = "7474";
35 private String webAdminUri = "http://localhost:7474/db/manage/";
36 private String webAdminDataUri = "http://localhost:7474/db/data/";
37 private String dbTuningPropertyFile = null;
38 private ArrayList<Tuple> nameValuePairs = new ArrayList<Tuple>();
39
40 private static class Tuple
41 {
42 public Tuple( String name, String value )
43 {
44 this.name = name;
45 this.value = value;
46 }
47
48 public String name;
49 public String value;
50 }
51
52 public static PropertyFileBuilder builder()
53 {
54 return new PropertyFileBuilder();
55 }
56
57 private PropertyFileBuilder()
58 {
59 }
60
61 public File build() throws IOException
62 {
63 File temporaryConfigFile = createTempPropertyFile();
64
65 String dbDir = ServerTestUtils.createTempDir().getAbsolutePath();
66 String rrdbDir = ServerTestUtils.createTempDir().getAbsolutePath();
67 writePropertyToFile( Configurator.DATABASE_LOCATION_PROPERTY_KEY, dbDir, temporaryConfigFile );
68 if ( portNo != null )
69 {
70 writePropertyToFile( Configurator.WEBSERVER_PORT_PROPERTY_KEY, portNo, temporaryConfigFile );
71 }
72 writePropertyToFile( Configurator.RRDB_LOCATION_PROPERTY_KEY, rrdbDir, temporaryConfigFile );
73 writePropertyToFile( Configurator.MANAGEMENT_PATH_PROPERTY_KEY, webAdminUri, temporaryConfigFile );
74 writePropertyToFile( Configurator.DATA_API_PATH_PROPERTY_KEY, webAdminDataUri, temporaryConfigFile );
75 if ( dbTuningPropertyFile != null )
76 {
77 writePropertyToFile( Configurator.DB_TUNING_PROPERTY_FILE_KEY, dbTuningPropertyFile, temporaryConfigFile );
78 }
79
80 for ( Tuple t : nameValuePairs )
81 {
82 writePropertyToFile( t.name, t.value, temporaryConfigFile );
83 }
84
85
86 return temporaryConfigFile;
87 }
88
89 public PropertyFileBuilder withDbTuningPropertyFile( File f )
90 {
91 dbTuningPropertyFile = f.getAbsolutePath();
92 return this;
93 }
94
95 public PropertyFileBuilder withNameValue( String name, String value )
96 {
97 nameValuePairs.add( new Tuple( name, value ) );
98 return this;
99 }
100
101 public PropertyFileBuilder withDbTuningPropertyFile( String propertyFileLocation )
102 {
103 dbTuningPropertyFile = propertyFileLocation;
104 return this;
105 }
106 }