Search in sources :

Example 1 with RngDevice

use of org.ovirt.engine.api.model.RngDevice in project ovirt-engine by oVirt.

the class RngDeviceMapper method map.

@Mapping(from = VmRngDevice.class, to = RngDevice.class)
public static RngDevice map(VmRngDevice entity, RngDevice template) {
    RngDevice model = (template == null) ? new RngDevice() : template;
    if (entity.getBytes() != null) {
        model.setRate(new Rate());
        model.getRate().setBytes(entity.getBytes());
        if (entity.getPeriod() != null) {
            model.getRate().setPeriod(entity.getPeriod());
        }
    }
    RngSource restSource = map(entity.getSource(), null);
    model.setSource(restSource);
    return model;
}
Also used : RngSource(org.ovirt.engine.api.model.RngSource) Rate(org.ovirt.engine.api.model.Rate) VmRngDevice(org.ovirt.engine.core.common.businessentities.VmRngDevice) RngDevice(org.ovirt.engine.api.model.RngDevice)

Example 2 with RngDevice

use of org.ovirt.engine.api.model.RngDevice in project ovirt-engine by oVirt.

the class RngDeviceMapperTest method testMapFromRestToBackend.

@Test
public void testMapFromRestToBackend() throws Exception {
    RngDevice model = new RngDevice();
    model.setSource(RngSource.HWRNG);
    model.setRate(new Rate());
    model.getRate().setBytes(10);
    model.getRate().setPeriod(11);
    VmRngDevice expected = new VmRngDevice();
    expected.setBytes(10);
    expected.setPeriod(11);
    expected.setSource(VmRngDevice.Source.HWRNG);
    assertEquals(expected, RngDeviceMapper.map(model, null));
}
Also used : Rate(org.ovirt.engine.api.model.Rate) VmRngDevice(org.ovirt.engine.core.common.businessentities.VmRngDevice) VmRngDevice(org.ovirt.engine.core.common.businessentities.VmRngDevice) RngDevice(org.ovirt.engine.api.model.RngDevice) Test(org.junit.Test)

Example 3 with RngDevice

use of org.ovirt.engine.api.model.RngDevice in project ovirt-engine by oVirt.

the class RngDeviceMapperTest method testMapFromBackendToRest.

@Test
public void testMapFromBackendToRest() throws Exception {
    VmRngDevice entity = new VmRngDevice();
    entity.setBytes(11);
    entity.setPeriod(10);
    entity.setSource(VmRngDevice.Source.RANDOM);
    RngDevice expected = new RngDevice();
    expected.setRate(new Rate());
    expected.getRate().setBytes(11);
    expected.getRate().setPeriod(10);
    expected.setSource(RngSource.RANDOM);
    assertEquals(expected.getRate().getBytes(), RngDeviceMapper.map(entity, null).getRate().getBytes());
    assertEquals(expected.getRate().getPeriod(), RngDeviceMapper.map(entity, null).getRate().getPeriod());
    assertEquals(expected.getSource(), RngDeviceMapper.map(entity, null).getSource());
}
Also used : Rate(org.ovirt.engine.api.model.Rate) VmRngDevice(org.ovirt.engine.core.common.businessentities.VmRngDevice) VmRngDevice(org.ovirt.engine.core.common.businessentities.VmRngDevice) RngDevice(org.ovirt.engine.api.model.RngDevice) Test(org.junit.Test)

Aggregations

Rate (org.ovirt.engine.api.model.Rate)3 RngDevice (org.ovirt.engine.api.model.RngDevice)3 VmRngDevice (org.ovirt.engine.core.common.businessentities.VmRngDevice)3 Test (org.junit.Test)2 RngSource (org.ovirt.engine.api.model.RngSource)1