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;
}
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);
}
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);
}
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);
}
}
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);
}
Aggregations