@Before
 public void createConfigurationReader() {
   eventLogger.reinitialise();
   configurationReader =
       new PropertiesRepositoryConfigurationReader(
           new File("indices"), Collections.<ArtifactBridge>emptySet(), eventLogger, null);
 }
  @Test
  public void defaultingOfIndexRefreshIntervalAndWatchIntervalWhenMalformed()
      throws RepositoryConfigurationException {
    Properties properties = new Properties();
    properties.setProperty("watched-repo.type", "watched");
    properties.setProperty("watched-repo.watchDirectory", "build/repository/watched");
    properties.setProperty("watched-repo.watchInterval", "alpha");
    properties.setProperty("remote-repo.type", "remote");
    properties.setProperty(
        "remote-repo.uri", "http://localhost:8080/org.eclipse.virgo.repository/foo");
    properties.setProperty("remote-repo.indexRefreshInterval", "bravo");
    properties.setProperty("chain", "watched-repo,remote-repo");

    OrderedPair<Map<String, RepositoryConfiguration>, List<String>> configurations =
        configurationReader.readConfiguration(properties);
    Map<String, RepositoryConfiguration> configurationMap = configurations.getFirst();
    List<String> chainList = configurations.getSecond();

    assertEquals(2, chainList.size());
    assertEquals(2, configurationMap.size());

    RepositoryConfiguration configuration = configurationMap.get(chainList.get(0));
    assertTrue(configuration instanceof WatchedStorageRepositoryConfiguration);
    assertEquals(5, ((WatchedStorageRepositoryConfiguration) configuration).getWatchInterval());

    configuration = configurationMap.get(chainList.get(1));
    assertTrue(configuration instanceof RemoteRepositoryConfiguration);
    assertEquals(30, ((RemoteRepositoryConfiguration) configuration).getIndexUpdateInterval());

    assertEquals(2, eventLogger.getLoggedEvents().size());
  }
  @Test
  public void variableExpansion() throws RepositoryConfigurationException, IOException {
    try {
      System.setProperty("org.eclipse.virgo.repository.internal.test.string", "a");
      System.setProperty("org.eclipse.virgo.repository.internal.test.int", "1");

      Properties properties = new Properties();

      properties.setProperty("bundles-ext.type", "external");
      properties.setProperty(
          "bundles-ext.searchPattern",
          "repository/${org.eclipse.virgo.repository.internal.test.string}/ext/*.jar");

      properties.setProperty("watched-repo.type", "watched");
      properties.setProperty(
          "watched-repo.watchDirectory",
          "build/repository/${org.eclipse.virgo.repository.internal.test.string}");
      properties.setProperty(
          "watched-repo.watchInterval", "${org.eclipse.virgo.repository.internal.test.int}");

      properties.setProperty("remote-repo.type", "remote");
      properties.setProperty(
          "remote-repo.uri",
          "http://localhost:${org.eclipse.virgo.repository.internal.test.int}/org.eclipse.virgo.repository/${org.eclipse.virgo.repository.internal.test.string}");
      properties.setProperty(
          "remote-repo.indexRefreshInterval", "${org.eclipse.virgo.repository.internal.test.int}");

      properties.setProperty("chain", "bundles-ext,watched-repo,remote-repo");

      OrderedPair<Map<String, RepositoryConfiguration>, List<String>> configurations =
          configurationReader.readConfiguration(properties);
      Map<String, RepositoryConfiguration> configurationMap = configurations.getFirst();
      List<String> chainList = configurations.getSecond();

      assertEquals(3, chainList.size());
      assertEquals(3, configurationMap.size());

      ExternalStorageRepositoryConfiguration externalConfiguration =
          (ExternalStorageRepositoryConfiguration) configurationMap.get(chainList.get(0));
      assertEquals(
          new File(".").getAbsolutePath()
              + File.separator
              + "repository"
              + File.separator
              + "a"
              + File.separator
              + "ext"
              + File.separatorChar
              + "*.jar",
          externalConfiguration.getSearchPattern());

      WatchedStorageRepositoryConfiguration watchedConfiguration =
          (WatchedStorageRepositoryConfiguration) configurationMap.get(chainList.get(1));
      assertEquals(
          new File("build/repository", "a").getCanonicalFile(),
          watchedConfiguration.getDirectoryToWatch().getCanonicalFile());
      assertEquals(1, watchedConfiguration.getWatchInterval());

      RemoteRepositoryConfiguration remoteConfiguration =
          (RemoteRepositoryConfiguration) configurationMap.get(chainList.get(2));
      assertEquals(1, remoteConfiguration.getIndexUpdateInterval());
      assertEquals(
          URI.create("http://localhost:1/org.eclipse.virgo.repository/a"),
          remoteConfiguration.getRepositoryUri());

      assertEquals(0, eventLogger.getLoggedEvents().size());
    } finally {
      System.clearProperty("org.eclipse.virgo.repository.internal.test.string");
      System.clearProperty("org.eclipse.virgo.repository.internal.test.int");
    }
  }