Search in sources :

Example 1 with ConfigurationController

use of cern.c2mon.daq.common.conf.core.ConfigurationController in project c2mon by c2mon.

the class RequestControllerTest method getBasicConfigurationController.

/**
 * @return configurationController
 */
private ConfigurationController getBasicConfigurationController() {
    ConfigurationController configurationController = new ConfigurationController();
    ProcessConfiguration processConfiguration = new ProcessConfiguration();
    EquipmentConfiguration equipmentConfiguration = new EquipmentConfiguration();
    EquipmentConfiguration equipmentConfiguration2 = new EquipmentConfiguration();
    SourceCommandTag commandTag = new SourceCommandTag(1L, "hello");
    DataTagAddress address = new DataTagAddress();
    SourceDataTag sourceDataTag = new SourceDataTag(1L, "asd", false, (short) 0, "Integer", address);
    SourceDataTag sourceDataTag2 = new SourceDataTag(2L, "asd", false, (short) 0, "Integer", address);
    SourceDataTag sourceDataTag3 = new SourceDataTag(3L, "asd", false, (short) 0, "Integer", address);
    processConfiguration.setProcessID(1L);
    equipmentConfiguration.setId(1L);
    sourceDataTag.update(new ValueUpdate(25));
    sourceDataTag2.update(new ValueUpdate(25));
    sourceDataTag3.update(new ValueUpdate(25));
    configurationController.setProcessConfiguration(processConfiguration);
    processConfiguration.getEquipmentConfigurations().put(1L, equipmentConfiguration);
    processConfiguration.getEquipmentConfigurations().put(2L, equipmentConfiguration2);
    equipmentConfiguration.getCommandTags().put(1L, commandTag);
    equipmentConfiguration.getDataTags().put(1L, sourceDataTag);
    equipmentConfiguration2.getDataTags().put(2L, sourceDataTag2);
    equipmentConfiguration2.getDataTags().put(3L, sourceDataTag3);
    return configurationController;
}
Also used : ValueUpdate(cern.c2mon.shared.common.datatag.ValueUpdate) ConfigurationController(cern.c2mon.daq.common.conf.core.ConfigurationController) ProcessConfiguration(cern.c2mon.shared.common.process.ProcessConfiguration) DataTagAddress(cern.c2mon.shared.common.datatag.DataTagAddress) SourceDataTag(cern.c2mon.shared.common.datatag.SourceDataTag) SourceCommandTag(cern.c2mon.shared.common.command.SourceCommandTag) EquipmentConfiguration(cern.c2mon.shared.common.process.EquipmentConfiguration)

Example 2 with ConfigurationController

use of cern.c2mon.daq.common.conf.core.ConfigurationController in project c2mon by c2mon.

the class RequestControllerTest method testOnSourceDataTagValueUpdateRequestProcess.

@Test
public void testOnSourceDataTagValueUpdateRequestProcess() {
    ConfigurationController configurationController = getBasicConfigurationController();
    RequestController handler = new RequestController(configurationController);
    SourceDataTagValueRequest valueRequest = new SourceDataTagValueRequest(PROCESS, 1L);
    SourceDataTagValueResponse response = handler.onSourceDataTagValueUpdateRequest(valueRequest);
    assertTrue(response.getAllDataTagValueObjects().size() == 3);
}
Also used : ConfigurationController(cern.c2mon.daq.common.conf.core.ConfigurationController) SourceDataTagValueRequest(cern.c2mon.shared.daq.datatag.SourceDataTagValueRequest) SourceDataTagValueResponse(cern.c2mon.shared.daq.datatag.SourceDataTagValueResponse) Test(org.junit.Test)

Example 3 with ConfigurationController

use of cern.c2mon.daq.common.conf.core.ConfigurationController in project c2mon by c2mon.

the class ConfigurationControllerTest method setUp.

@Before
public void setUp() throws ParserConfigurationException {
    configurationController = new ConfigurationController();
    configurationController.setEquipmentConfigurationFactory(new EquipmentConfigurationFactory());
    configurationController.setFreshnessMonitor(new FreshnessMonitor(new DaqProperties()));
    processConfiguration = new ProcessConfiguration();
    processConfiguration.setProcessID(TEST_PROCESS_ID);
    configurationController.setProcessConfiguration(processConfiguration);
    IEquipmentConfigurationChanger equipmentConfigurationChanger = new DefaultEquipmentConfigurationChanger();
    ICommandTagChanger commandTagChanger = new DefaultCommandTagChanger();
    EquipmentConfiguration equipmentConfiguration = new EquipmentConfiguration();
    equipmentConfiguration.setId(TEST_EQUIPMENT_ID);
    processConfiguration.getEquipmentConfigurations().put(TEST_EQUIPMENT_ID, equipmentConfiguration);
    appendSourceDataTag(TEST_DATA_TAG_ID, equipmentConfiguration);
    appendSourceCommandTag(TEST_COMMAND_TAG_ID, equipmentConfiguration);
    configurationController.putImplementationCommandTagChanger(TEST_EQUIPMENT_ID, commandTagChanger);
    configurationController.putImplementationDataTagChanger(TEST_EQUIPMENT_ID, new IDataTagChanger() {

        @Override
        public void onUpdateDataTag(ISourceDataTag sourceDataTag, ISourceDataTag oldSourceDataTag, ChangeReport changeReport) {
            changeReport.setState(CHANGE_STATE.SUCCESS);
        }

        @Override
        public void onRemoveDataTag(ISourceDataTag sourceDataTag, ChangeReport changeReport) {
            changeReport.setState(CHANGE_STATE.SUCCESS);
        }

        @Override
        public void onAddDataTag(ISourceDataTag sourceDataTag, ChangeReport changeReport) {
            changeReport.setState(CHANGE_STATE.SUCCESS);
        }
    });
    configurationController.putImplementationEquipmentConfigurationChanger(TEST_EQUIPMENT_ID, equipmentConfigurationChanger);
}
Also used : ConfigurationController(cern.c2mon.daq.common.conf.core.ConfigurationController) DefaultEquipmentConfigurationChanger(cern.c2mon.daq.common.conf.core.DefaultEquipmentConfigurationChanger) DaqProperties(cern.c2mon.daq.config.DaqProperties) EquipmentConfigurationFactory(cern.c2mon.daq.common.conf.core.EquipmentConfigurationFactory) ISourceDataTag(cern.c2mon.shared.common.datatag.ISourceDataTag) IDataTagChanger(cern.c2mon.daq.common.conf.equipment.IDataTagChanger) ProcessConfiguration(cern.c2mon.shared.common.process.ProcessConfiguration) ICommandTagChanger(cern.c2mon.daq.common.conf.equipment.ICommandTagChanger) FreshnessMonitor(cern.c2mon.daq.common.timer.FreshnessMonitor) IEquipmentConfigurationChanger(cern.c2mon.daq.common.conf.equipment.IEquipmentConfigurationChanger) DefaultCommandTagChanger(cern.c2mon.daq.common.conf.core.DefaultCommandTagChanger) EquipmentConfiguration(cern.c2mon.shared.common.process.EquipmentConfiguration) IEquipmentConfiguration(cern.c2mon.shared.common.process.IEquipmentConfiguration) Before(org.junit.Before)

Example 4 with ConfigurationController

use of cern.c2mon.daq.common.conf.core.ConfigurationController in project c2mon by c2mon.

the class GenericMessageHandlerTest method setUp.

@Before
public void setUp() throws Exception {
    int numTests = 0;
    // check how many test cases are defined in that test class
    for (Method m : this.getClass().getMethods()) {
        if (m.isAnnotationPresent(Test.class)) {
            numTests++;
        }
    }
    log.debug(format("number of tests configured in that class: %d", numTests));
    if (log.isDebugEnabled()) {
        log.debug("****************************************************************\n");
        log.debug(format("executing test: %s", testName.getMethodName()));
        log.debug("****************************************************************\n");
    }
    // find out which configuration file shall be taken
    String testConfig = configFileName(testName.getMethodName());
    // configure the handler only if the test requires it - i.e. is annotated with UseConf annotation
    if (testConfig != null) {
        messageSender = createMock(IProcessMessageSender.class);
        filterMessageSender = createMock(IFilterMessageSender.class);
        freshnessMonitorMock = new FreshnessMonitor(new DaqProperties());
        dynamicTimeDeadbandFilterActivator = new TimeDifferenceMovingAverageTimeDeadbandActivator(10, 110, 150, 30000);
        equipmentMessageSender = new EquipmentMessageSender(filterMessageSender, messageSender, dynamicTimeDeadbandFilterActivator, freshnessMonitorMock, new DaqProperties());
        configurationController = new ConfigurationController();
        configurationController.setProcessConfiguration(pconf);
        configurationController.setFreshnessMonitor(freshnessMonitorMock);
        pconf.setProcessID(TEST_PROCESS_ID);
        pconf.setProcessName(TEST_PROCESS_NAME);
        pconf.setAliveTagID(1000L);
        pconf.setAliveInterval(20000);
        if (log.isDebugEnabled()) {
            log.debug(format("configuring equipment with following test configuration file: %s\n", testConfig));
        }
        String confFileAbsPath = null;
        try {
            confFileAbsPath = this.getClass().getResource(testConfig).getPath();
        } catch (Exception ex) {
            fail("configuration file not found: " + testConfig);
        }
        Element rootConfElement = parseEquipmentConfiguration(confFileAbsPath);
        // ProcessConfigurationLoader processConfigurationLoader = new ProcessConfigurationLoader();
        assertNotNull(rootConfElement);
        assertNotNull("Did you annotate your test with @UseHandler annotation ?!", getHandlerClass());
        // update handler name
        rootConfElement.getElementsByTagName("handler-class-name").item(0).getFirstChild().setNodeValue(getHandlerClass());
        equipmentConfiguration = new EquipmentConfigurationFactory().createEquipmentConfiguration(rootConfElement);
        long equipmentId = equipmentConfiguration.getId();
        msgHandler = EquipmentMessageHandler.createEquipmentMessageHandler(equipmentConfiguration.getHandlerClassName(), new EquipmentCommandHandler(equipmentId, new RequestController(configurationController)), new EquipmentConfigurationHandler(equipmentId, configurationController), equipmentMessageSender, null);
        // equipmentMessageSender.setEquipmentConfiguration(equipmentConfiguration);
        // equipmentMessageSender.setEquipmentLoggerFactory(factory);
        this.equipmentMessageSender.init(equipmentConfiguration);
        pconf.getEquipmentConfigurations().put(equipmentId, equipmentConfiguration);
        msgHandler.setEquipmentMessageSender(equipmentMessageSender);
        // call some test-specific before test initializer
        beforeTest();
        Thread.sleep(120);
    }
}
Also used : TimeDifferenceMovingAverageTimeDeadbandActivator(cern.c2mon.daq.filter.dynamic.TimeDifferenceMovingAverageTimeDeadbandActivator) ConfigurationController(cern.c2mon.daq.common.conf.core.ConfigurationController) EquipmentCommandHandler(cern.c2mon.daq.common.impl.EquipmentCommandHandler) Element(org.w3c.dom.Element) DaqProperties(cern.c2mon.daq.config.DaqProperties) EquipmentConfigurationFactory(cern.c2mon.daq.common.conf.core.EquipmentConfigurationFactory) EquipmentConfigurationHandler(cern.c2mon.daq.common.conf.core.EquipmentConfigurationHandler) IProcessMessageSender(cern.c2mon.daq.common.messaging.IProcessMessageSender) Method(java.lang.reflect.Method) EquipmentMessageSender(cern.c2mon.daq.common.impl.EquipmentMessageSender) RequestController(cern.c2mon.daq.common.messaging.impl.RequestController) FreshnessMonitor(cern.c2mon.daq.common.timer.FreshnessMonitor) IFilterMessageSender(cern.c2mon.daq.filter.IFilterMessageSender) Before(org.junit.Before)

Example 5 with ConfigurationController

use of cern.c2mon.daq.common.conf.core.ConfigurationController in project c2mon by c2mon.

the class RequestControllerTest method testExecuteCommand.

@Test
public void testExecuteCommand() throws EqCommandTagException {
    ConfigurationController configurationController = getBasicConfigurationController();
    ICommandRunner commandRunner = createMock(ICommandRunner.class);
    RequestController requestController = new RequestController(configurationController);
    requestController.putCommandRunner(1L, commandRunner);
    SourceCommandTagValue sourceCommandTagValue = new SourceCommandTagValue(1L, null, 1L, (short) 0, null, null);
    // MessageHandler should try to call this.
    commandRunner.runCommand(sourceCommandTagValue);
    expectLastCall().andReturn("");
    replay(commandRunner);
    requestController.executeCommand(sourceCommandTagValue);
    verify(commandRunner);
}
Also used : ConfigurationController(cern.c2mon.daq.common.conf.core.ConfigurationController) ICommandRunner(cern.c2mon.daq.common.ICommandRunner) SourceCommandTagValue(cern.c2mon.shared.daq.command.SourceCommandTagValue) Test(org.junit.Test)

Aggregations

ConfigurationController (cern.c2mon.daq.common.conf.core.ConfigurationController)10 Test (org.junit.Test)7 SourceDataTagValueRequest (cern.c2mon.shared.daq.datatag.SourceDataTagValueRequest)6 SourceDataTagValueResponse (cern.c2mon.shared.daq.datatag.SourceDataTagValueResponse)6 EquipmentConfigurationFactory (cern.c2mon.daq.common.conf.core.EquipmentConfigurationFactory)2 FreshnessMonitor (cern.c2mon.daq.common.timer.FreshnessMonitor)2 DaqProperties (cern.c2mon.daq.config.DaqProperties)2 EquipmentConfiguration (cern.c2mon.shared.common.process.EquipmentConfiguration)2 ProcessConfiguration (cern.c2mon.shared.common.process.ProcessConfiguration)2 Before (org.junit.Before)2 ICommandRunner (cern.c2mon.daq.common.ICommandRunner)1 DefaultCommandTagChanger (cern.c2mon.daq.common.conf.core.DefaultCommandTagChanger)1 DefaultEquipmentConfigurationChanger (cern.c2mon.daq.common.conf.core.DefaultEquipmentConfigurationChanger)1 EquipmentConfigurationHandler (cern.c2mon.daq.common.conf.core.EquipmentConfigurationHandler)1 ICommandTagChanger (cern.c2mon.daq.common.conf.equipment.ICommandTagChanger)1 IDataTagChanger (cern.c2mon.daq.common.conf.equipment.IDataTagChanger)1 IEquipmentConfigurationChanger (cern.c2mon.daq.common.conf.equipment.IEquipmentConfigurationChanger)1 EquipmentCommandHandler (cern.c2mon.daq.common.impl.EquipmentCommandHandler)1 EquipmentMessageSender (cern.c2mon.daq.common.impl.EquipmentMessageSender)1 IProcessMessageSender (cern.c2mon.daq.common.messaging.IProcessMessageSender)1