Example usage for org.apache.commons.configuration MapConfiguration MapConfiguration

List of usage examples for org.apache.commons.configuration MapConfiguration MapConfiguration

Introduction

In this page you can find the example usage for org.apache.commons.configuration MapConfiguration MapConfiguration.

Prototype

public MapConfiguration(Map map) 

Source Link

Document

Create a Configuration decorator around the specified Map.

Usage

From source file:org.neo4j.server.NeoServerShellConfigIT.java

@Test
public void shouldBeAbleToOverrideShellConfig() throws Throwable {
    final int customPort = findFreeShellPortToUse(8881);
    // Given/*from ww  w  .ja  v a 2s. c  o m*/
    CommunityNeoServer server = new CommunityNeoServer(new Configurator.Adapter() {
        @Override
        public Configuration configuration() {
            return new MapConfiguration(
                    stringMap(Configurator.DATABASE_LOCATION_PROPERTY_KEY, testDir.absolutePath()));
        }

        @Override
        public Map<String, String> getDatabaseTuningProperties() {
            return stringMap(ShellSettings.remote_shell_enabled.name(), Settings.TRUE,
                    ShellSettings.remote_shell_port.name(), "" + customPort);
        }
    }, GraphDatabaseDependencies.newDependencies().logging(DevNullLoggingService.DEV_NULL));

    // When
    server.start();

    // Then
    // Try to connect with a shell client to that custom port.
    // Throws exception if unable to connect
    ShellLobby.newClient(customPort).shutdown();

    server.stop();
}

From source file:org.neo4j.server.NeoServerShellConfigIT.java

@Test
public void connectWithShellOnDefaultPortWhenNoShellConfigSupplied() throws Throwable {
    // Given/* ww w .java2 s. c  o  m*/
    CommunityNeoServer server = new CommunityNeoServer(new Configurator.Adapter() {
        @Override
        public Configuration configuration() {
            return new MapConfiguration(
                    stringMap(Configurator.DATABASE_LOCATION_PROPERTY_KEY, testDir.absolutePath()));
        }

        @Override
        public Map<String, String> getDatabaseTuningProperties() {
            return stringMap();
        }
    }, GraphDatabaseDependencies.newDependencies().logging(DevNullLoggingService.DEV_NULL));

    // When
    server.start();

    // Then
    ShellLobby.newClient().shutdown();

    server.stop();
}

From source file:org.neo4j.server.rrd.RrdFactoryTest.java

@Before
public void setUp() throws IOException {
    config = new MapConfiguration(new HashMap<String, String>());
    db = new Database(new ImpermanentGraphDatabase());
}

From source file:org.overlord.commons.config.configurator.FuseConfigurator.java

/**
 * @see org.overlord.commons.config.configurator.AbstractPropertiesFileConfigurator#provideConfiguration(java.lang.String, java.lang.Long)
 *///  w  w w  .j a va 2s  . c  o  m
@Override
public Configuration provideConfiguration(String configName, Long refreshDelay) throws ConfigurationException {
    if (getFabricService() != null) {
        Map<String, String> properties = getProperties(configName);
        return new MapConfiguration(properties);
    } else {
        return super.provideConfiguration(configName, refreshDelay);
    }
}

From source file:org.overlord.commons.config.configurator.JndiConfigurator.java

/**
 * @see org.overlord.commons.config.configurator.Configurator#provideConfiguration(java.lang.String, java.lang.Long)
 *///from  www . j  av a  2  s .c om
@Override
public Configuration provideConfiguration(String configName, Long refreshDelay) throws ConfigurationException {
    if (configName.endsWith(".properties")) { //$NON-NLS-1$
        configName = configName.substring(0, configName.lastIndexOf(".properties")); //$NON-NLS-1$
    }

    try {
        Context ctx = new InitialContext();
        @SuppressWarnings("unchecked")
        Map<String, String> properties = (Map<String, String>) ctx
                .lookup("java:/global/overlord-config/" + configName); //$NON-NLS-1$
        return new MapConfiguration(properties);
    } catch (Exception e) {
        return null;
    }
}

From source file:org.powertac.accounting.AccountingServiceTests.java

@Test
public void testMaxMinInitialization() {
    TreeMap<String, String> map = new TreeMap<String, String>();
    map.put("accounting.accountingService.minInterest", "0.01");
    map.put("accounting.accountingService.maxInterest", "0.20");
    Configuration mapConfig = new MapConfiguration(map);
    config.setConfiguration(mapConfig);/*w w  w. j  a va 2 s  .c o m*/

    String result = accountingService.initialize(comp, new ArrayList<String>());
    assertEquals("correct return value", "AccountingService", result);
    assertEquals("correct min value", 0.01, accountingService.getMinInterest(), 1e-6);
    assertEquals("correct max value", 0.20, accountingService.getMaxInterest(), 1e-6);
    assertTrue("correct bank interest",
            accountingService.getMinInterest() <= accountingService.getBankInterest());
    assertTrue("correct bank interest",
            accountingService.getMaxInterest() >= accountingService.getBankInterest());
}

From source file:org.powertac.accounting.AccountingServiceTests.java

@Test
public void testInterestInitialization() {
    TreeMap<String, String> map = new TreeMap<String, String>();
    map.put("accounting.accountingService.minInterest", "0.01");
    map.put("accounting.accountingService.maxInterest", "0.20");
    map.put("accounting.accountingService.bankInterest", "0.008");
    Configuration mapConfig = new MapConfiguration(map);
    config.setConfiguration(mapConfig);/*from   w  w w .  j a  va  2 s  .  co m*/

    accountingService.initialize(comp, new ArrayList<String>());
    assertEquals("correct bank interest", 0.008, accountingService.getBankInterest(), 1e-6);
}

From source file:org.powertac.auctioneer.AuctionServiceTests.java

@SuppressWarnings("rawtypes")
@Before//from w  w  w .  j a v a2s.c  o  m
public void setUp() throws Exception {
    // clean up from previous tests
    timeslotRepo.recycle();
    reset(mockProxy);
    reset(mockControl);
    reset(mockServerProps);
    accountingArgs = new ArrayList<Object[]>();
    brokerMsgs = new ArrayList<Object>();

    // create a Competition, needed for initialization
    competition = Competition.newInstance("auctioneer-test").withTimeslotsOpen(4);
    Competition.setCurrent(competition);

    // mock the ServerProperties

    // Set up serverProperties mock
    config = new Configurator();
    doAnswer(new Answer() {
        @Override
        public Object answer(InvocationOnMock invocation) {
            Object[] args = invocation.getArguments();
            config.configureSingleton(args[0]);
            return null;
        }
    }).when(mockServerProps).configureMe(anyObject());

    // Create some brokers who can trade
    b1 = new Broker("Buyer #1");
    b2 = new Broker("Buyer #2");
    s1 = new Broker("Seller #1");
    s2 = new Broker("Seller #2");

    // set the clock, create some useful timeslots
    Instant now = Competition.currentCompetition().getSimulationBaseTime();
    timeService.setCurrentTime(now);
    ts0 = timeslotRepo.makeTimeslot(now);
    ts1 = timeslotRepo.makeTimeslot(now.plus(TimeService.HOUR));
    ts2 = timeslotRepo.makeTimeslot(now.plus(TimeService.HOUR * 2));
    //timeslotRepo.makeTimeslot(now.plus(TimeService.HOUR * 3));
    //timeslotRepo.makeTimeslot(now.plus(TimeService.HOUR * 4));
    svc.clearEnabledTimeslots();

    // mock the AccountingService, capture args
    doAnswer(new Answer() {
        @Override
        public Object answer(InvocationOnMock invocation) {
            Object[] args = invocation.getArguments();
            accountingArgs.add(args);
            return null;
        }
    }).when(accountingService).addMarketTransaction(isA(Broker.class), isA(Timeslot.class), anyDouble(),
            anyDouble());
    // mock the Broker Proxy, capture messages
    doAnswer(new Answer() {
        @Override
        public Object answer(InvocationOnMock invocation) {
            Object[] args = invocation.getArguments();
            brokerMsgs.add(args[0]);
            return null;
        }
    }).when(mockProxy).broadcastMessage(anyObject());

    // Configure the AuctionService
    TreeMap<String, String> map = new TreeMap<String, String>();
    map.put("auctioneer.auctionService.sellerSurplusRatio", "0.5");
    map.put("auctioneer.auctionService.defaultMargin", "0.2");
    map.put("auctioneer.auctionService.defaultClearingPrice", "40.0");
    Configuration mapConfig = new MapConfiguration(map);
    config.setConfiguration(mapConfig);
    svc.initialize(competition, new ArrayList<String>());
}

From source file:org.powertac.customer.coldstorage.ColdStorageTest.java

@Test
public void testConfig() {
    TreeMap<String, String> map = new TreeMap<String, String>();
    map.put("customer.coldstorage.coldStorage.minTemp", "-30");
    map.put("customer.coldstorage.coldStorage.maxTemp", "-5");
    Configuration mapConfig = new MapConfiguration(map);
    config.setConfiguration(mapConfig);//from  w  ww  . j a  va2 s.  c  om
    serverConfig.configureMe(uut);
    assertEquals("correct min temp", -30.0, uut.getMinTemp(), 1e-6);
    assertEquals("correct max temp", -5.0, uut.getMaxTemp(), 1e-6);
}

From source file:org.powertac.du.DefaultBrokerServiceTests.java

@Test
public void testConfig() {
    service.setDefaults();//from  w  w  w .  ja  v a  2  s  .c om
    List<String> completedInits = new ArrayList<String>();
    completedInits.add("TariffMarket");

    TreeMap<String, String> map = new TreeMap<String, String>();
    map.put("du.defaultBrokerService.consumptionRate", "-0.50");
    map.put("du.defaultBrokerService.productionRate", "0.02");
    map.put("du.defaultBrokerService.initialBidKWh", "1000.0");
    Configuration mapConfig = new MapConfiguration(map);
    config.setConfiguration(mapConfig);
    service.initialize(competition, completedInits);
    assertEquals("correct consumption rate", -0.5, service.getConsumptionRate(), 1e-6);
    assertEquals("correct production rate", 0.02, service.getProductionRate(), 1e-6);
    assertEquals("correct initial kwh", 1000.0, service.getInitialBidKWh(), 1e-6);
}