use of org.eclipse.scanning.api.points.Scalar in project gda-core by openGDA.
the class ScannableNexusWrapperTest method testSetPosition_withScanPosition.
@Test
public void testSetPosition_withScanPosition() throws Exception {
// Note: nexus writing tested separately by ScannableNexusWrapperScanTest
// Arrange
final double newPosition = 3.8;
final int scanIndex = 38;
IPositionListener posListener = mock(IPositionListener.class);
((IPositionListenable) scannable).addPositionListener(posListener);
final IPosition scanPosition = new Scalar<Double>("sax", scanIndex, newPosition);
assertThat(scannable.getPosition(), is(equalTo(3.7)));
// Act
scannable.setPosition(newPosition, scanPosition);
// Assert
assertThat(scannable.getPosition(), is(equalTo(newPosition)));
((IPositionListenable) scannable).removePositionListener(posListener);
ArgumentCaptor<PositionEvent> captor = ArgumentCaptor.forClass(PositionEvent.class);
InOrder order = inOrder(posListener);
order.verify(posListener).positionWillPerform(captor.capture());
order.verify(posListener).positionChanged(captor.capture());
order.verify(posListener).positionPerformed(captor.capture());
order.verifyNoMoreInteractions();
List<PositionEvent> posEvents = captor.getAllValues();
assertThat(posEvents, hasSize(3));
int i = 0;
for (PositionEvent posEvent : posEvents) {
// willPerform event doesn't have level set
assertThat(posEvent.getLevel(), is(i == 0 ? 0 : 5));
IPosition position = posEvent.getPosition();
assertThat(position.getNames(), contains(scannable.getName()));
// index not set for positionChanged
assertThat(position.getIndex("sax"), is(i == 1 ? -1 : 38));
assertThat(position.getValue(scannable.getName()), is(equalTo(Double.valueOf(newPosition))));
i++;
}
}
use of org.eclipse.scanning.api.points.Scalar in project gda-core by openGDA.
the class ScannableNexusWrapper method setPosition.
@Override
public Object setPosition(Object value, IPosition scanPosition) throws ScanningException {
try {
final Scannable scannable = getScannable();
if (value != null) {
final int index = (scanPosition == null ? -1 : scanPosition.getIndex(getName()));
final IPosition position = new Scalar<Object>(getName(), index, value);
positionDelegate.firePositionWillPerform(position);
logger.debug("Moving scannable {} to position {} at {}", scannable.getName(), value, scanPosition);
scannable.moveTo(value);
positionDelegate.firePositionPerformed(getLevel(), position);
} else {
logger.debug("Ignoring request to move scannable {} to position {} at {}", scannable.getName(), value, scanPosition);
}
if (scanPosition != null && getScannableNexusDevice(false) != null) {
// It stops it being read again.
return getScannableNexusDevice(false).writePosition(value, scanPosition);
}
} catch (Exception e) {
throw new ScanningException("Could not set position of scannable " + getName(), e);
}
// new position.
return null;
}
use of org.eclipse.scanning.api.points.Scalar in project gda-core by openGDA.
the class ScannableNexusWrapperTest method testNullSetPosition_withScanPosition.
@Test
public void testNullSetPosition_withScanPosition() throws Exception {
// Note: nexus writing tested separately by ScannableNexusWrapperScanTest
// Arrange
final int scanIndex = 38;
IPositionListener posListener = mock(IPositionListener.class);
((IPositionListenable) scannable).addPositionListener(posListener);
final IPosition scanPosition = new Scalar<Double>("sax", scanIndex, null);
assertThat(scannable.getPosition(), is(equalTo(3.7)));
// Act
scannable.setPosition(null, scanPosition);
// Assert
assertThat(scannable.getPosition(), is(equalTo(3.7)));
((IPositionListenable) scannable).removePositionListener(posListener);
verifyZeroInteractions(posListener);
}
Aggregations