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 static org.junit.Assert.assertEquals;
    23  import static org.junit.Assert.assertNotNull;
    24
    25  import java.io.BufferedWriter;
    26  import java.io.File;
    27  import java.io.FileWriter;
    28  import java.io.IOException;
    29  import java.util.Map;
    30  import java.util.Set;
    31
    32  import org.apache.commons.configuration.Configuration;
    33  import org.junit.Test;
    34  import org.neo4j.server.ServerTestUtils;
    35  import org.neo4j.server.configuration.validation.Validator;
    36
    37  public class ConfiguratorTest {
    38
    39      @Test
    40      public void shouldProvideAConfiguration() throws IOException {
    41          File configFile = PropertyFileBuilder.builder().build();
    42          Configuration config = new PropertyFileConfigurator(new Validator(), configFile).configuration();
    43          assertNotNull(config);
    44          configFile.delete();
    45      }
    46
    47      @Test
    48      public void shouldUseSpecifiedConfigFile() throws Exception {
    49
    50          File configFile = PropertyFileBuilder.builder().withNameValue("foo", "bar").build();
    51
    52          Configuration testConf = new PropertyFileConfigurator(new Validator(), configFile).configuration();
    53
    54          final String EXPECTED_VALUE = "bar";
    55          assertEquals(EXPECTED_VALUE, testConf.getString("foo"));
    56
    57          configFile.delete();
    58      }
    59
    60      @Test
    61      public void shouldAcceptDuplicateKeysWithSameValue() throws IOException {
    62          File configFile = PropertyFileBuilder.builder().withNameValue("foo", "bar").withNameValue("foo", "bar").build();
    63
    64          Configurator configurator = new PropertyFileConfigurator(configFile);
    65          Configuration testConf = configurator.configuration();
    66
    67          assertNotNull(testConf);
    68          final String EXPECTED_VALUE = "bar";
    69          assertEquals(EXPECTED_VALUE, testConf.getString("foo"));
    70
    71          configFile.delete();
    72      }
    73
    74      @Test
    75      public void shouldSupportProvidingDatabaseTuningParametersSeparately() throws IOException {
    76          File databaseTuningPropertyFile = DatabaseTuningPropertyFileBuilder.builder().build();
    77
    78
    79          File propertyFileWithDbTuningProperty = PropertyFileBuilder.builder().withDbTuningPropertyFile(databaseTuningPropertyFile).build();
    80
    81          System.out.println(databaseTuningPropertyFile.getAbsolutePath());
    82          System.out.println(propertyFileWithDbTuningProperty.getAbsolutePath());
    83
    84          Configurator configurator = new PropertyFileConfigurator(propertyFileWithDbTuningProperty);
    85
    86          Map<String, String> databaseTuningProperties = configurator.getDatabaseTuningProperties();
    87          assertNotNull(databaseTuningProperties);
    88          assertEquals(5, databaseTuningProperties.size());
    89
    90          propertyFileWithDbTuningProperty.delete();
    91      }
    92
    93      @Test
    94      public void shouldFindThirdPartyJaxRsClasses() throws IOException {
    95
    96          File file = ServerTestUtils.createTempPropertyFile();
    97
    98          FileWriter fstream = new FileWriter(file, true);
    99          BufferedWriter out = new BufferedWriter(fstream);
    100         out.write(Configurator.THIRD_PARTY_PACKAGES_KEY);
    101         out.write("=");
    102         out.write("com.foo.bar=\"mount/point/foo\",");
    103         out.write("com.foo.baz=\"/bar\",");
    104         out.write("com.foo.foobarbaz=\"/\"");
    105         out.write(System.getProperty("line.separator"));
    106         out.close();
    107
    108         Configurator configurator = new PropertyFileConfigurator(file);
    109
    110         Set<ThirdPartyJaxRsPackage> thirdpartyJaxRsClasses = configurator.getThirdpartyJaxRsClasses();
    111         assertNotNull(thirdpartyJaxRsClasses);
    112         assertEquals(3, thirdpartyJaxRsClasses.size());
    113
    114         file.delete();
    115     }
    116 }