List of usage examples for org.apache.commons.configuration MapConfiguration MapConfiguration
public MapConfiguration(Map map)
From source file:org.powertac.officecomplexcustomer.OfficeComplexCustomerServiceTests.java
@Before public void setUp() { customerRepo.recycle();//from ww w . java2 s. com brokerRepo.recycle(); tariffRepo.recycle(); tariffSubscriptionRepo.recycle(); randomSeedRepo.recycle(); timeslotRepo.recycle(); weatherReportRepo.recycle(); weatherReportRepo.runOnce(); officeComplexCustomerService.clearConfiguration(); reset(mockAccounting); reset(mockServerProperties); // create a Competition, needed for initialization comp = Competition.newInstance("officecomplex-customer-test"); broker1 = new Broker("Joe"); now = new DateTime(2011, 1, 10, 0, 0, 0, 0, DateTimeZone.UTC).toInstant(); timeService.setCurrentTime(now); timeService.setBase(now.getMillis()); exp = now.plus(TimeService.WEEK * 10); defaultTariffSpec = new TariffSpecification(broker1, PowerType.CONSUMPTION).withExpiration(exp) .withMinDuration(TimeService.WEEK * 8).addRate(new Rate().withValue(-0.5)); defaultTariff = new Tariff(defaultTariffSpec); defaultTariff.init(); defaultTariff.setState(Tariff.State.OFFERED); tariffRepo.setDefaultTariff(defaultTariffSpec); when(mockTariffMarket.getDefaultTariff(PowerType.CONSUMPTION)).thenReturn(defaultTariff); when(mockTariffMarket.getDefaultTariff(PowerType.INTERRUPTIBLE_CONSUMPTION)).thenReturn(defaultTariff); accountingArgs = new ArrayList<Object[]>(); // mock the AccountingService, capture args doAnswer(new Answer() { public Object answer(InvocationOnMock invocation) { Object[] args = invocation.getArguments(); accountingArgs.add(args); return null; } }).when(mockAccounting).addTariffTransaction(isA(TariffTransaction.Type.class), isA(Tariff.class), isA(CustomerInfo.class), anyInt(), anyDouble(), anyDouble()); // Set up serverProperties mock ReflectionTestUtils.setField(officeComplexCustomerService, "serverPropertiesService", mockServerProperties); config = new Configurator(); doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) { Object[] args = invocation.getArguments(); config.configureSingleton(args[0]); return null; } }).when(mockServerProperties).configureMe(anyObject()); TreeMap<String, String> map = new TreeMap<String, String>(); map.put("officecomplexcustomer.officeComplexCustomerService.configFile1", "OfficeComplexType1.properties"); map.put("common.competition.expectedTimeslotCount", "1440"); Configuration mapConfig = new MapConfiguration(map); config.setConfiguration(mapConfig); config.configureSingleton(comp); }
From source file:org.powertac.officecomplexcustomer.OfficeComplexCustomerServiceTests.java
@Test public void testNormalInitializationWithoutConfig() { TreeMap<String, String> map2 = new TreeMap<String, String>(); map2.put("officecomplexcustomer.officeComplexCustomerService.configFile1", null); Configuration mapConfig = new MapConfiguration(map2); config.setConfiguration(mapConfig);//from www . j ava 2 s . co m List<String> inits = new ArrayList<String>(); inits.add("DefaultBroker"); String result = officeComplexCustomerService.initialize(comp, inits); assertEquals("correct return value", "OfficeComplexCustomer", result); assertEquals("correct configuration file", "OfficeComplexDefault.properties", officeComplexCustomerService.getConfigFile1()); assertTrue(officeComplexCustomerService .getDaysOfCompetition() >= Competition.currentCompetition().getExpectedTimeslotCount() / OfficeComplexConstants.HOURS_OF_DAY); }
From source file:org.powertac.producer.ProducerServiceTest.java
@Before public void setUp() { customerRepo.recycle();/*from w ww.j a v a2 s . c o m*/ brokerRepo.recycle(); tariffRepo.recycle(); reset(mockTariffSubscriptionRepo); randomSeedRepo.recycle(); timeslotRepo.recycle(); weatherReportRepo.recycle(); weatherReportRepo.runOnce(); producerService.clearConfiguration(); reset(mockAccounting); reset(mockServerProperties); // create a Competition, needed for initialization comp = Competition.newInstance("producer-test"); broker1 = new Broker("Joe"); // now = new DateTime(2009, 10, 10, 0, 0, 0, 0, // DateTimeZone.UTC).toInstant(); now = comp.getSimulationBaseTime(); timeService.setCurrentTime(now); timeService.setClockParameters(now.toInstant().getMillis(), 720l, 60 * 60 * 1000); exp = now.plus(TimeService.WEEK * 10); defaultTariffSpec = new TariffSpecification(broker1, PowerType.PRODUCTION).withExpiration(exp) .addRate(new Rate().withValue(0.5)); defaultTariff = new Tariff(defaultTariffSpec); defaultTariff.init(); defaultTariff.setState(Tariff.State.OFFERED); tariffRepo.setDefaultTariff(defaultTariffSpec); when(mockTariffMarket.getDefaultTariff(PowerType.FOSSIL_PRODUCTION)).thenReturn(defaultTariff); when(mockTariffMarket.getDefaultTariff(PowerType.RUN_OF_RIVER_PRODUCTION)).thenReturn(defaultTariff); when(mockTariffMarket.getDefaultTariff(PowerType.SOLAR_PRODUCTION)).thenReturn(defaultTariff); when(mockTariffMarket.getDefaultTariff(PowerType.WIND_PRODUCTION)).thenReturn(defaultTariff); accountingArgs = new ArrayList<Object[]>(); // mock the AccountingService, capture args doAnswer(new Answer<Object>() { public Object answer(InvocationOnMock invocation) { Object[] args = invocation.getArguments(); accountingArgs.add(args); return null; } }).when(mockAccounting).addTariffTransaction(isA(TariffTransaction.Type.class), isA(Tariff.class), isA(CustomerInfo.class), anyInt(), anyDouble(), anyDouble()); // Set up serverProperties mock config = new Configurator(); doAnswer(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) { Object[] args = invocation.getArguments(); config.configureSingleton(args[0]); return null; } }).when(mockServerProperties).configureMe(anyObject()); TreeMap<String, String> map = new TreeMap<String, String>(); map.put("common.competition.expectedTimeslotCount", "1440"); Configuration mapConfig = new MapConfiguration(map); config.setConfiguration(mapConfig); config.configureSingleton(comp); }
From source file:org.powertac.producer.ProducerServiceTest.java
@Test public void testConfigure() { List<String> inits = new ArrayList<String>(); inits.add("DefaultBroker"); TariffSubscription sub = mock(TariffSubscription.class); List<TariffSubscription> l = new ArrayList<TariffSubscription>(); l.add(sub);/*w w w. j av a 2 s . c o m*/ Configurator conf = new Configurator(); TreeMap<String, String> map = new TreeMap<String, String>(); map.put("producer.producerService.producerFileFolder", "bla"); Configuration mapConfig = new MapConfiguration(map); conf.setConfiguration(mapConfig); conf.configureSingleton(producerService); assertTrue(producerService.getProducerFileFolder() != null); when(mockTariffSubscriptionRepo.findActiveSubscriptionsForCustomer(any(CustomerInfo.class))).thenReturn(l); }
From source file:org.powertac.producer.ProducerTest.java
@Before public void setUp() { customerRepo.recycle();//from w w w . java 2 s . c o m brokerRepo.recycle(); tariffRepo.recycle(); tariffSubscriptionRepo.recycle(); randomSeedRepo.recycle(); timeslotRepo.recycle(); weatherReportRepo.recycle(); weatherReportRepo.runOnce(); reset(mockAccounting); reset(mockServerProperties); // create a Competition, needed for initialization comp = Competition.newInstance("producer-test"); broker1 = new Broker("Joe"); // now = new DateTime(2009, 10, 10, 0, 0, 0, 0, // DateTimeZone.UTC).toInstant(); now = comp.getSimulationBaseTime(); timeService.setCurrentTime(now); timeService.setClockParameters(now.toInstant().getMillis(), 720l, 60 * 60 * 1000); exp = now.plus(TimeService.WEEK * 10); defaultTariffSpec = new TariffSpecification(broker1, PowerType.PRODUCTION).withExpiration(exp) .addRate(new Rate().withValue(0.5)); defaultTariff = new Tariff(defaultTariffSpec); defaultTariff.init(); defaultTariff.setState(Tariff.State.OFFERED); tariffRepo.setDefaultTariff(defaultTariffSpec); when(mockTariffMarket.getDefaultTariff(PowerType.FOSSIL_PRODUCTION)).thenReturn(defaultTariff); when(mockTariffMarket.getDefaultTariff(PowerType.RUN_OF_RIVER_PRODUCTION)).thenReturn(defaultTariff); when(mockTariffMarket.getDefaultTariff(PowerType.SOLAR_PRODUCTION)).thenReturn(defaultTariff); when(mockTariffMarket.getDefaultTariff(PowerType.WIND_PRODUCTION)).thenReturn(defaultTariff); accountingArgs = new ArrayList<Object[]>(); // mock the AccountingService, capture args doAnswer(new Answer<Object>() { public Object answer(InvocationOnMock invocation) { Object[] args = invocation.getArguments(); accountingArgs.add(args); return null; } }).when(mockAccounting).addTariffTransaction(isA(TariffTransaction.Type.class), isA(Tariff.class), isA(CustomerInfo.class), anyInt(), anyDouble(), anyDouble()); // Set up serverProperties mock config = new Configurator(); doAnswer(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) { Object[] args = invocation.getArguments(); config.configureSingleton(args[0]); return null; } }).when(mockServerProperties).configureMe(anyObject()); TreeMap<String, String> map = new TreeMap<String, String>(); map.put("common.competition.expectedTimeslotCount", "1440"); Configuration mapConfig = new MapConfiguration(map); config.setConfiguration(mapConfig); config.configureSingleton(comp); }
From source file:org.powertac.tariffmarket.TariffMarketServiceTests.java
@Test public void initializeService() { TreeMap<String, String> map = new TreeMap<String, String>(); map.put("tariffmarket.tariffMarketService.publicationFee", "-42.0"); map.put("tariffmarket.tariffMarketService.revocationFee", "-420.0"); map.put("tariffmarket.tariffMarketService.publicationInterval", "3"); map.put("tariffmarket.tariffMarketService.publicationOffset", "0"); Configuration mapConfig = new MapConfiguration(map); config.setConfiguration(mapConfig);/*from w w w .ja v a2 s. co m*/ List<String> inits = new ArrayList<String>(); inits.add("AccountingService"); tariffMarketService.initialize(comp, inits); assertEquals("correct publication fee", -42.0, tariffMarketService.getPublicationFee(), 1e-6); }
From source file:org.powertac.wpgenco.GencoTests.java
@Test public void testGenerateOrders2() { // set up the windfarmGenco with commitment leadtime=3 TreeMap<String, String> map = new TreeMap<String, String>(); map.put("windfarmGenco.genco.commitmentLeadtime", "3"); Configuration mapConfig = new MapConfiguration(map); config.setConfiguration(mapConfig);/*from w w w . j a v a2 s .c o m*/ serverConfig.configureMe(windfarmGenco); // capture orders final ArrayList<Order> orderList = new ArrayList<Order>(); doAnswer(new Answer() { public Object answer(InvocationOnMock invocation) { Object[] args = invocation.getArguments(); orderList.add((Order) args[0]); return null; } }).when(mockProxy).routeMessage(isA(Order.class)); // set up some timeslots Timeslot ts0 = timeslotRepo.makeTimeslot(start); ts0.disable(); assertEquals("first ts has sn=0", 0, ts0.getSerialNumber()); timeslotRepo.makeTimeslot(start.plus(TimeService.HOUR)); timeslotRepo.makeTimeslot(start.plus(TimeService.HOUR * 2)); timeslotRepo.makeTimeslot(start.plus(TimeService.HOUR * 3)); timeslotRepo.makeTimeslot(start.plus(TimeService.HOUR * 4)); assertEquals("4 enabled timeslots", 4, timeslotRepo.enabledTimeslots().size()); // generate orders and check windfarmGenco.generateOrders(start, timeslotRepo.enabledTimeslots()); assertEquals("two orders", 2, orderList.size()); Order first = orderList.get(0); assertEquals("first order for ts3", 3, first.getTimeslot().getSerialNumber()); assertEquals("first order price", 1.0, first.getLimitPrice(), 1e-6); assertEquals("first order for 100 mwh", -100.0, first.getMWh(), 1e-6); Order second = orderList.get(1); assertEquals("second order for ts4", 4, second.getTimeslot().getSerialNumber()); assertEquals("second order price", 1.0, second.getLimitPrice(), 1e-6); assertEquals("second order for 100 mwh", -100.0, second.getMWh(), 1e-6); }
From source file:org.powertac.wpgenco.GencoTests.java
@Test public void testGenerateOrders3() { // set up the windfarmGenco with commitment leadtime=3 TreeMap<String, String> map = new TreeMap<String, String>(); map.put("windfarmGenco.genco.commitmentLeadtime", "3"); Configuration mapConfig = new MapConfiguration(map); config.setConfiguration(mapConfig);/*from ww w. j a v a2s.c om*/ serverConfig.configureMe(windfarmGenco); // capture orders final ArrayList<Order> orderList = new ArrayList<Order>(); doAnswer(new Answer() { public Object answer(InvocationOnMock invocation) { Object[] args = invocation.getArguments(); orderList.add((Order) args[0]); return null; } }).when(mockProxy).routeMessage(isA(Order.class)); // set up some timeslots Timeslot ts0 = timeslotRepo.makeTimeslot(start); ts0.disable(); assertEquals("first ts has sn=0", 0, ts0.getSerialNumber()); timeslotRepo.makeTimeslot(start.plus(TimeService.HOUR)); timeslotRepo.makeTimeslot(start.plus(TimeService.HOUR * 2)); timeslotRepo.makeTimeslot(start.plus(TimeService.HOUR * 3)); timeslotRepo.makeTimeslot(start.plus(TimeService.HOUR * 4)); assertEquals("4 enabled timeslots", 4, timeslotRepo.enabledTimeslots().size()); // 50 mwh already sold in ts2 Timeslot ts2 = timeslotRepo.findBySerialNumber(2); MarketPosition posn2 = new MarketPosition(windfarmGenco, ts2, -50.0); windfarmGenco.addMarketPosition(posn2, ts2); // generate orders and check windfarmGenco.generateOrders(start, timeslotRepo.enabledTimeslots()); assertEquals("two orders", 3, orderList.size()); Order order = orderList.get(0); assertEquals("second order for ts2", 2, order.getTimeslot().getSerialNumber()); assertEquals("second order price", 1.0, order.getLimitPrice(), 1e-6); assertEquals("second order for 50 mwh", -50.0, order.getMWh(), 1e-6); order = orderList.get(1); assertEquals("second order for ts3", 3, order.getTimeslot().getSerialNumber()); assertEquals("second order price", 1.0, order.getLimitPrice(), 1e-6); assertEquals("second order for 100 mwh", -100.0, order.getMWh(), 1e-6); order = orderList.get(2); assertEquals("third order for ts4", 4, order.getTimeslot().getSerialNumber()); assertEquals("third order price", 1.0, order.getLimitPrice(), 1e-6); assertEquals("third order for 100 mwh", -100.0, order.getMWh(), 1e-6); }
From source file:org.seedstack.javamail.internal.PropertyFileSessionConfigurerTest.java
@Before public void setUp() throws Exception { Props props = new Props(); Map<String, Object> config = new HashMap<String, Object>(); props.load(PropertyFileSessionConfigurerTest.class.getResourceAsStream("/test.props")); props.extractProps(config);/*from ww w . jav a 2s. c o m*/ Configuration configuration = new MapConfiguration(config); assertThat(config).isNotEmpty(); assertThat(configuration).isNotNull(); SessionConfigurer configurer = new PropertyFileSessionConfigurer( configuration.subset(JavaMailPlugin.CONFIGURATION_PREFIX)); this.sessionsConfig = configurer.doConfigure(); }
From source file:org.seedstack.seed.core.internal.application.ApplicationImpl.java
@Override public Configuration getConfiguration(Class<?> clazz) { return new MapConfiguration(ImmutableMap.<String, Object>copyOf(getEntityConfiguration(clazz.getName()))); }