View Javadoc

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