Search in sources :

Example 1 with DeviceProperty

use of cern.c2mon.shared.client.device.DeviceProperty in project c2mon by c2mon.

the class ObjectComparison method assertDevicePropertyEquals.

public static void assertDevicePropertyEquals(DeviceProperty expectedObject, DeviceProperty cacheObject) throws ClassNotFoundException {
    assertEquals(expectedObject.getId(), cacheObject.getId());
    assertEquals(expectedObject.getName(), cacheObject.getName());
    assertEquals(expectedObject.getCategory(), cacheObject.getCategory());
    if ((expectedObject.getCategory() != null && expectedObject.getCategory().equals("mappedProperty")) || expectedObject.getFields() != null) {
        for (DeviceProperty field : expectedObject.getFields().values()) {
            assertDevicePropertyListContains(new ArrayList<>(cacheObject.getFields().values()), field);
        }
    } else {
        assertEquals(expectedObject.getValue(), cacheObject.getValue());
        assertEquals(expectedObject.getResultType(), cacheObject.getResultType());
    }
}
Also used : DeviceProperty(cern.c2mon.shared.client.device.DeviceProperty)

Example 2 with DeviceProperty

use of cern.c2mon.shared.client.device.DeviceProperty in project c2mon by c2mon.

the class DeviceFacadeImplTest method testGetDevices.

@Test
public void testGetDevices() {
    // Reset the mock
    EasyMock.reset(deviceCacheMock, deviceClassCacheMock);
    String deviceClassName = "test_device_class_name";
    DeviceClassCacheObject deviceClassReturn = new DeviceClassCacheObject(1L, "test_device_class_name_1", "Test description");
    List<Long> deviceIds = new ArrayList<>();
    deviceIds.add(1000L);
    deviceIds.add(2000L);
    deviceClassReturn.setDeviceIds(deviceIds);
    DeviceCacheObject device1 = new DeviceCacheObject(1000L, "test_device_1", 1L);
    device1.setDeviceProperties(new ArrayList<>(Arrays.asList(new DeviceProperty(10L, "test_property", "10", "tagId", null))));
    device1.setDeviceCommands(new ArrayList<>(Arrays.asList(new DeviceCommand(10L, "test_command", "20", "commandTagId", null))));
    Device device2 = new DeviceCacheObject(2000L, "test_device_2", 1L);
    List<Device> deviceReturn = new ArrayList<>();
    deviceReturn.add(device1);
    deviceReturn.add(device2);
    // Expect the facade to get the device class object
    EasyMock.expect(deviceClassCacheMock.getDeviceClassIdByName(deviceClassName)).andReturn(deviceClassReturn.getId());
    EasyMock.expect(deviceCacheMock.getByDeviceClassId(deviceClassReturn.getId())).andReturn(deviceReturn);
    // Setup is finished, need to activate the mock
    EasyMock.replay(deviceCacheMock, deviceClassCacheMock);
    List<Device> devices = deviceFacade.getDevices(deviceClassName);
    Assert.assertTrue(devices.get(0).getId() == device1.getId());
    Assert.assertTrue(devices.get(1).getId() == device2.getId());
    Assert.assertTrue(devices.get(0).getDeviceClassId() == device1.getDeviceClassId());
    Assert.assertTrue(devices.get(1).getDeviceClassId() == device2.getDeviceClassId());
    // Verify that everything happened as expected
    EasyMock.verify(deviceCacheMock, deviceClassCacheMock);
}
Also used : DeviceProperty(cern.c2mon.shared.client.device.DeviceProperty) DeviceCommand(cern.c2mon.shared.client.device.DeviceCommand) Test(org.junit.Test)

Example 3 with DeviceProperty

use of cern.c2mon.shared.client.device.DeviceProperty in project c2mon by c2mon.

the class DeviceMapperTest method testGetItem.

@Test
public void testGetItem() throws ClassNotFoundException {
    // getDevice(300L);
    Device device1 = deviceMapper.getItem(300L);
    Assert.assertNotNull(device1);
    List<DeviceProperty> deviceProperties = device1.getDeviceProperties();
    Assert.assertNotNull(deviceProperties);
    Assert.assertTrue(deviceProperties.size() == 4);
    assertDevicePropertyListContains(deviceProperties, new DeviceProperty(1L, "cpuLoadInPercent", "210000", "tagId", null));
    assertDevicePropertyListContains(deviceProperties, new DeviceProperty(2L, "responsiblePerson", "Mr. Administrator", "constantValue", null));
    assertDevicePropertyListContains(deviceProperties, new DeviceProperty(3L, "someCalculations", "(#123 + #234) / 2", "clientRule", "Float"));
    assertDevicePropertyListContains(deviceProperties, new DeviceProperty(4L, "numCores", "4", "constantValue", "Integer"));
    List<DeviceCommand> deviceCommands = device1.getDeviceCommands();
    Assert.assertNotNull(deviceCommands);
    Assert.assertTrue(deviceCommands.size() == 1);
    assertDeviceCommandEquals(new DeviceCommand(1L, "TEST_COMMAND_1", "210004", "commandTagId", null), deviceCommands.get(0));
    // getDevice(301L);
    Device device2 = deviceMapper.getItem(301L);
    Assert.assertNotNull(device2);
    deviceProperties = device2.getDeviceProperties();
    Assert.assertNotNull(deviceProperties);
    Assert.assertTrue(deviceProperties.size() == 2);
    assertDevicePropertyListContains(deviceProperties, new DeviceProperty(5L, "TEST_PROPERTY_1", "210001", "tagId", null));
    assertDevicePropertyListContains(deviceProperties, new DeviceProperty(9L, "TEST_PROPERTY_WITH_FIELDS", null, "mappedProperty", null));
    List<DeviceProperty> expectedFields = new ArrayList<>();
    expectedFields.add(new DeviceProperty(1L, "FIELD_CPULOAD", "210008", "tagId", null));
    expectedFields.add(new DeviceProperty(2L, "FIELD_RESPONSIBLE_PERSON", "Mr. Administrator", "constantValue", null));
    expectedFields.add(new DeviceProperty(3L, "FIELD_SOME_CALCULATIONS", "(#123 + #234) / 2", "clientRule", "Float"));
    expectedFields.add(new DeviceProperty(4L, "FIELD_NUM_CORES", "2", "constantValue", "Integer"));
    DeviceProperty expectedMappedProperty = new DeviceProperty(9L, "TEST_PROPERTY_WITH_FIELDS", "mappedProperty", expectedFields);
    assertDevicePropertyListContains(deviceProperties, expectedMappedProperty);
    deviceCommands = device2.getDeviceCommands();
    Assert.assertNotNull(deviceCommands);
    Assert.assertTrue(deviceCommands.size() == 1);
    assertDeviceCommandEquals(new DeviceCommand(2L, "TEST_COMMAND_2", "210005", "commandTagId", null), deviceCommands.get(0));
}
Also used : DeviceProperty(cern.c2mon.shared.client.device.DeviceProperty) Device(cern.c2mon.server.common.device.Device) ArrayList(java.util.ArrayList) DeviceCommand(cern.c2mon.shared.client.device.DeviceCommand) Test(org.junit.Test)

Example 4 with DeviceProperty

use of cern.c2mon.shared.client.device.DeviceProperty in project c2mon by c2mon.

the class DeviceFacadeImpl method parseDevicePropertiesXML.

/**
 * Parse the XML representation of the properties of a device (which comes
 * from configuration) and return it as a list of {@link DeviceProperty}
 * objects.
 *
 * @param xmlString the XML representation string of the device properties
 *
 * @return the list of device properties
 * @throws Exception if the XML could not be parsed
 */
private List<DeviceProperty> parseDevicePropertiesXML(String xmlString) throws Exception {
    List<DeviceProperty> deviceProperties = new ArrayList<>();
    Serializer serializer = new Persister();
    DevicePropertyList devicePropertyList = serializer.read(DevicePropertyList.class, xmlString);
    for (DeviceProperty deviceProperty : devicePropertyList.getDeviceProperties()) {
        // Remove all whitespace and control characters
        if (deviceProperty.getValue() != null) {
            deviceProperty.setValue(deviceProperty.getValue().replaceAll("[\u0000-\u001f]", "").trim());
        }
        deviceProperties.add(deviceProperty);
    }
    return deviceProperties;
}
Also used : DeviceProperty(cern.c2mon.shared.client.device.DeviceProperty) Persister(org.simpleframework.xml.core.Persister) Serializer(org.simpleframework.xml.Serializer)

Example 5 with DeviceProperty

use of cern.c2mon.shared.client.device.DeviceProperty in project c2mon by c2mon.

the class ConfigurationLoaderTest method testCreateUpdateDevice.

@Test
public void testCreateUpdateDevice() throws ClassNotFoundException {
    replay(mockManager);
    ConfigurationReport report = configurationLoader.applyConfiguration(33);
    assertFalse(report.toXML().contains(Status.FAILURE.toString()));
    DeviceCacheObject cacheObject = (DeviceCacheObject) deviceCache.get(20L);
    DeviceCacheObject expectedObject = new DeviceCacheObject(20L, "TEST_DEVICE_20", 400L);
    List<DeviceProperty> expectedProperties = new ArrayList<>();
    expectedProperties.add(new DeviceProperty(1L, "cpuLoadInPercent", "987654", "tagId", null));
    expectedProperties.add(new DeviceProperty(2L, "responsiblePerson", "Mr. Administrator", "constantValue", null));
    expectedProperties.add(new DeviceProperty(3L, "someCalculations", "(#123 + #234) / 2", "clientRule", "Float"));
    List<DeviceProperty> expectedFields = new ArrayList<>();
    expectedFields.add(new DeviceProperty(1L, "field1", "987654", "tagId", null));
    expectedFields.add(new DeviceProperty(2L, "field2", "(#123 + #234) / 2", "clientRule", null));
    expectedProperties.add(new DeviceProperty(9L, "TEST_PROPERTY_WITH_FIELDS", "mappedProperty", expectedFields));
    List<DeviceCommand> expectedCommands = new ArrayList<>();
    expectedCommands.add(new DeviceCommand(1L, "TEST_COMMAND_1", "4287", "commandTagId", null));
    expectedCommands.add(new DeviceCommand(2L, "TEST_COMMAND_2", "4288", "commandTagId", null));
    expectedObject.setDeviceProperties(expectedProperties);
    expectedObject.setDeviceCommands(expectedCommands);
    ObjectEqualityComparison.assertDeviceEquals(expectedObject, cacheObject);
    // Update should succeed
    report = configurationLoader.applyConfiguration(34);
    assertFalse(report.toXML().contains(Status.FAILURE.toString()));
    cacheObject = (DeviceCacheObject) deviceCache.get(20L);
    expectedProperties.add(new DeviceProperty(4L, "numCores", "4", "constantValue", "Integer"));
    expectedObject.setDeviceProperties(expectedProperties);
    ObjectEqualityComparison.assertDeviceEquals(expectedObject, cacheObject);
    verify(mockManager);
}
Also used : DeviceProperty(cern.c2mon.shared.client.device.DeviceProperty) ConfigurationReport(cern.c2mon.shared.client.configuration.ConfigurationReport) DeviceCommand(cern.c2mon.shared.client.device.DeviceCommand)

Aggregations

DeviceProperty (cern.c2mon.shared.client.device.DeviceProperty)12 DeviceCommand (cern.c2mon.shared.client.device.DeviceCommand)7 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)3 Device (cern.c2mon.server.common.device.Device)2 ConfigurationException (cern.c2mon.shared.common.ConfigurationException)2 AbstractCacheIntegrationTest (cern.c2mon.server.cache.AbstractCacheIntegrationTest)1 CacheElementNotFoundException (cern.c2mon.server.cache.exception.CacheElementNotFoundException)1 DeviceCacheObject (cern.c2mon.server.common.device.DeviceCacheObject)1 ConfigurationReport (cern.c2mon.shared.client.configuration.ConfigurationReport)1 TransferDevice (cern.c2mon.shared.client.device.TransferDevice)1 TransferDeviceImpl (cern.c2mon.shared.client.device.TransferDeviceImpl)1 Serializer (org.simpleframework.xml.Serializer)1 Persister (org.simpleframework.xml.core.Persister)1