List of usage examples for org.apache.commons.configuration MapConfiguration MapConfiguration
public MapConfiguration(Map map)
From source file:org.powertac.factoredcustomer.FactoredCustomerServiceTests.java
public void initializeService() { TreeMap<String, String> map = new TreeMap<String, String>(); map.put("factoredcustomer.factoredCustomerService.configResource", "FactoredCustomers.xml"); Configuration mapConfig = new MapConfiguration(map); config.setConfiguration(mapConfig);/*from w ww . j a va 2 s .c o m*/ List<String> inits = new ArrayList<String>(); inits.add("DefaultBroker"); inits.add("TariffMarket"); factoredCustomerService.initialize(comp, inits); }
From source file:org.powertac.genco.CpGencoTest.java
@Test public void configTest() { TreeMap<String, String> map = new TreeMap<String, String>(); map.put("genco.cpGenco.coefficients", "1.0, 2.0, 3.0"); map.put("genco.cpGenco.pSigma", "0.22"); init();/*from ww w . j av a2 s . c o m*/ Configuration conf = new MapConfiguration(map); Configurator configurator = new Configurator(); configurator.setConfiguration(conf); configurator.configureSingleton(genco); assertEquals("3-element list", 3, genco.getCoefficients().size()); assertEquals("correct 1st", "1.0", genco.getCoefficients().get(0)); assertEquals("correct last", "3.0", genco.getCoefficients().get(2)); assertEquals("correct pSigma", 0.22, genco.getPSigma(), 1e-6); }
From source file:org.powertac.genco.GencoTests.java
@Test public void testGenerateOrders2() { // set up the genco with commitment leadtime=3 TreeMap<String, String> map = new TreeMap<String, String>(); map.put("genco.genco.commitmentLeadtime", "3"); Configuration mapConfig = new MapConfiguration(map); config.setConfiguration(mapConfig);/*www .j av a 2 s. c o m*/ serverConfig.configureMe(genco); // 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); assertEquals("first ts has sn=24", 24, 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 genco.generateOrders(start, timeslotRepo.enabledTimeslots()); assertEquals("two orders", 2, orderList.size()); Order first = orderList.get(0); assertEquals("first order for ts3", 27, first.getTimeslotIndex()); 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", 28, second.getTimeslotIndex()); 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.genco.GencoTests.java
@Test public void testGenerateOrders3() { // set up the genco with commitment leadtime=3 TreeMap<String, String> map = new TreeMap<String, String>(); map.put("genco.genco.commitmentLeadtime", "3"); Configuration mapConfig = new MapConfiguration(map); config.setConfiguration(mapConfig);/* ww w .j a v a 2 s . c o m*/ serverConfig.configureMe(genco); // 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); assertEquals("first ts has sn=24", 24, 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(26); MarketPosition posn2 = new MarketPosition(genco, ts2, -50.0); genco.addMarketPosition(posn2, ts2.getSerialNumber()); // generate orders and check genco.generateOrders(start, timeslotRepo.enabledTimeslots()); assertEquals("three orders", 3, orderList.size()); Order order = orderList.get(0); assertEquals("first order for ts2", 26, order.getTimeslotIndex()); assertEquals("first order price", 1.0, order.getLimitPrice(), 1e-6); assertEquals("first order for 50 mwh", -50.0, order.getMWh(), 1e-6); order = orderList.get(1); assertEquals("second order for ts3", 27, order.getTimeslotIndex()); 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", 28, order.getTimeslotIndex()); 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.powertac.householdcustomer.HouseholdControllableCapacitiesTests.java
@Before public void setUp() { customerRepo.recycle();/*from ww w . j a va 2 s. c o m*/ brokerRepo.recycle(); tariffRepo.recycle(); tariffSubscriptionRepo.recycle(); randomSeedRepo.recycle(); timeslotRepo.recycle(); weatherReportRepo.recycle(); weatherReportRepo.runOnce(); householdCustomerService.clearConfiguration(); reset(mockAccounting); reset(mockServerProperties); // create a Competition, needed for initialization comp = Competition.newInstance("household-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.222)); defaultTariffSpec = new TariffSpecification(broker1, PowerType.CONSUMPTION).withExpiration(exp) .addRate(new Rate().withValue(-0.222)); defaultTariff = new Tariff(defaultTariffSpec); defaultTariff.init(); defaultTariff.setState(Tariff.State.OFFERED); tariffRepo.setDefaultTariff(defaultTariffSpec); defaultTariffSpecControllable = new TariffSpecification(broker1, PowerType.INTERRUPTIBLE_CONSUMPTION) .withExpiration(exp).withMinDuration(TimeService.WEEK * 8) .addRate(new Rate().withValue(-0.121).withMaxCurtailment(0.3)); defaultTariffControllable = new Tariff(defaultTariffSpecControllable); defaultTariffControllable.init(); defaultTariffControllable.setState(Tariff.State.OFFERED); tariffRepo.setDefaultTariff(defaultTariffSpecControllable); when(mockTariffMarket.getDefaultTariff(PowerType.CONSUMPTION)).thenReturn(defaultTariff); when(mockTariffMarket.getDefaultTariff(PowerType.INTERRUPTIBLE_CONSUMPTION)) .thenReturn(defaultTariffControllable); 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(householdCustomerService, "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("householdcustomer.householdCustomerService.configFile1", "VillageType1.properties"); map.put("common.competition.expectedTimeslotCount", "1440"); Configuration mapConfig = new MapConfiguration(map); config.setConfiguration(mapConfig); config.configureSingleton(comp); }
From source file:org.powertac.householdcustomer.HouseholdControllableCapacitiesTests.java
@Test public void testNormalInitializationWithoutConfig() { TreeMap<String, String> map2 = new TreeMap<String, String>(); map2.put("householdcustomer.householdCustomerService.configFile1", null); Configuration mapConfig = new MapConfiguration(map2); config.setConfiguration(mapConfig);/*from w w w. jav a2 s .c o m*/ List<String> inits = new ArrayList<String>(); inits.add("DefaultBroker"); String result = householdCustomerService.initialize(comp, inits); assertEquals("correct return value", "HouseholdCustomer", result); assertEquals("correct configuration file", "VillageDefault.properties", householdCustomerService.getConfigFile1()); assertTrue(householdCustomerService .getDaysOfCompetition() >= Competition.currentCompetition().getExpectedTimeslotCount() / VillageConstants.HOURS_OF_DAY); assertTrue(householdCustomerService.getVillageList().size() == 2); }
From source file:org.powertac.householdcustomer.HouseholdCustomerServiceTests.java
@Before public void setUp() { customerRepo.recycle();/*w w w.j a v a 2 s .c om*/ brokerRepo.recycle(); tariffRepo.recycle(); tariffSubscriptionRepo.recycle(); randomSeedRepo.recycle(); timeslotRepo.recycle(); weatherReportRepo.recycle(); weatherReportRepo.runOnce(); householdCustomerService.clearConfiguration(); reset(mockAccounting); reset(mockServerProperties); // create a Competition, needed for initialization comp = Competition.newInstance("household-customer-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.setBase(now.getMillis()); exp = now.plus(TimeService.WEEK * 10); defaultTariffSpec = new TariffSpecification(broker1, PowerType.CONSUMPTION).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.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(householdCustomerService, "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("householdcustomer.householdCustomerService.configFile1", "VillageType1.properties"); map.put("common.competition.expectedTimeslotCount", "1440"); Configuration mapConfig = new MapConfiguration(map); config.setConfiguration(mapConfig); config.configureSingleton(comp); }
From source file:org.powertac.householdcustomer.HouseholdCustomerServiceTests.java
@Test public void testNormalInitializationWithoutConfig() { TreeMap<String, String> map2 = new TreeMap<String, String>(); map2.put("householdcustomer.householdCustomerService.configFile1", null); Configuration mapConfig = new MapConfiguration(map2); config.setConfiguration(mapConfig);//from w w w.j a v a 2 s. co m List<String> inits = new ArrayList<String>(); inits.add("DefaultBroker"); String result = householdCustomerService.initialize(comp, inits); assertEquals("correct return value", "HouseholdCustomer", result); assertEquals("correct configuration file", "VillageDefault.properties", householdCustomerService.getConfigFile1()); assertTrue(householdCustomerService .getDaysOfCompetition() >= Competition.currentCompetition().getExpectedTimeslotCount() / VillageConstants.HOURS_OF_DAY); }
From source file:org.powertac.officecomplexcustomer.OfficeComplexControllableCapacitiesTests.java
@Before public void setUp() { customerRepo.recycle();/*ww w . j a va2s . 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.222)); defaultTariff = new Tariff(defaultTariffSpec); defaultTariff.init(); defaultTariff.setState(Tariff.State.OFFERED); tariffRepo.setDefaultTariff(defaultTariffSpec); defaultTariffSpecControllable = new TariffSpecification(broker1, PowerType.INTERRUPTIBLE_CONSUMPTION) .withExpiration(exp).withMinDuration(TimeService.WEEK * 8) .addRate(new Rate().withValue(-0.121).withMaxCurtailment(0.3)); defaultTariffControllable = new Tariff(defaultTariffSpecControllable); defaultTariffControllable.init(); defaultTariffControllable.setState(Tariff.State.OFFERED); tariffRepo.setDefaultTariff(defaultTariffSpecControllable); when(mockTariffMarket.getDefaultTariff(PowerType.CONSUMPTION)).thenReturn(defaultTariff); when(mockTariffMarket.getDefaultTariff(PowerType.INTERRUPTIBLE_CONSUMPTION)) .thenReturn(defaultTariffControllable); 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.OfficeComplexControllableCapacitiesTests.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 ww w . j av a 2 s. c om 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); }