Skip to content

Commit

Permalink
fixed test 3
Browse files Browse the repository at this point in the history
  • Loading branch information
salvatore-coppola committed Nov 26, 2024
1 parent 39bfab9 commit 14ad3a0
Showing 1 changed file with 44 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.TreeMap;

Expand All @@ -44,6 +45,7 @@
import org.eclipse.kura.channel.ChannelRecord;
import org.eclipse.kura.channel.ChannelStatus;
import org.eclipse.kura.channel.ChannelType;
import org.eclipse.kura.channel.ScaleOffsetType;
import org.eclipse.kura.core.testutil.TestUtil;
import org.eclipse.kura.type.DataType;
import org.eclipse.kura.type.TypedValue;
Expand All @@ -56,6 +58,7 @@

public class AssetRestServiceTest {

@SuppressWarnings("unchecked")
@Test
public void testListAssetPids() throws InvalidSyntaxException {
// test retrieval of asset service pids
Expand Down Expand Up @@ -122,10 +125,12 @@ public void testGetAssetChannels() {

Map<String, Channel> channels = new TreeMap<>();
Map<String, Object> channelConfig = new HashMap<>();
Channel ch1 = new Channel("ch1", ChannelType.READ, DataType.INTEGER, channelConfig);
Channel ch1 = new Channel("ch1", ChannelType.READ, DataType.INTEGER, ScaleOffsetType.DEFINED_BY_VALUE_TYPE,
Optional.empty(), Optional.empty(), channelConfig);
channels.put(ch1.getName(), ch1);
channelConfig = new HashMap<>();
Channel ch2 = new Channel("ch2", ChannelType.WRITE, DataType.STRING, channelConfig);
Channel ch2 = new Channel("ch2", ChannelType.WRITE, DataType.STRING, ScaleOffsetType.DEFINED_BY_VALUE_TYPE,
Optional.empty(), Optional.empty(), channelConfig);
channels.put(ch2.getName(), ch2);

AssetConfiguration assetConfig = new AssetConfiguration("description", "driverPid", channels);
Expand Down Expand Up @@ -153,37 +158,37 @@ public void testReadAllChannels() throws KuraException {
when(asMock.getAsset(pid)).thenReturn(asset);

List<ChannelRecord> records = new ArrayList<>();
ChannelRecord record = ChannelRecord.createReadRecord("ch1", DataType.INTEGER);
record.setChannelStatus(new ChannelStatus(ChannelFlag.SUCCESS));
record.setValue(TypedValues.newIntegerValue(1));
records.add(record);
record = ChannelRecord.createReadRecord("ch2", DataType.STRING);
record.setChannelStatus(new ChannelStatus(ChannelFlag.FAILURE));
records.add(record);
record = ChannelRecord.createReadRecord("ch3", DataType.STRING);
record.setChannelStatus(new ChannelStatus(ChannelFlag.SUCCESS));
record.setValue(TypedValues.newStringValue("val"));
records.add(record);
record = ChannelRecord.createReadRecord("ch4", DataType.BOOLEAN);
record.setChannelStatus(new ChannelStatus(ChannelFlag.SUCCESS));
record.setValue(TypedValues.newBooleanValue(true));
records.add(record);
record = ChannelRecord.createReadRecord("ch5", DataType.BYTE_ARRAY);
record.setChannelStatus(new ChannelStatus(ChannelFlag.SUCCESS));
record.setValue(TypedValues.newByteArrayValue(new byte[] {1,2,3}));
records.add(record);
record = ChannelRecord.createReadRecord("ch6", DataType.DOUBLE);
record.setChannelStatus(new ChannelStatus(ChannelFlag.SUCCESS));
record.setValue(TypedValues.newDoubleValue(1.234));
records.add(record);
record = ChannelRecord.createReadRecord("ch7", DataType.FLOAT);
record.setChannelStatus(new ChannelStatus(ChannelFlag.SUCCESS));
record.setValue(TypedValues.newFloatValue(12.34f));
records.add(record);
record = ChannelRecord.createReadRecord("ch8", DataType.LONG);
record.setChannelStatus(new ChannelStatus(ChannelFlag.SUCCESS));
record.setValue(TypedValues.newLongValue(1234));
records.add(record);
ChannelRecord channelRecord = ChannelRecord.createReadRecord("ch1", DataType.INTEGER);
channelRecord.setChannelStatus(new ChannelStatus(ChannelFlag.SUCCESS));
channelRecord.setValue(TypedValues.newIntegerValue(1));
records.add(channelRecord);
channelRecord = ChannelRecord.createReadRecord("ch2", DataType.STRING);
channelRecord.setChannelStatus(new ChannelStatus(ChannelFlag.FAILURE));
records.add(channelRecord);
channelRecord = ChannelRecord.createReadRecord("ch3", DataType.STRING);
channelRecord.setChannelStatus(new ChannelStatus(ChannelFlag.SUCCESS));
channelRecord.setValue(TypedValues.newStringValue("val"));
records.add(channelRecord);
channelRecord = ChannelRecord.createReadRecord("ch4", DataType.BOOLEAN);
channelRecord.setChannelStatus(new ChannelStatus(ChannelFlag.SUCCESS));
channelRecord.setValue(TypedValues.newBooleanValue(true));
records.add(channelRecord);
channelRecord = ChannelRecord.createReadRecord("ch5", DataType.BYTE_ARRAY);
channelRecord.setChannelStatus(new ChannelStatus(ChannelFlag.SUCCESS));
channelRecord.setValue(TypedValues.newByteArrayValue(new byte[] { 1, 2, 3 }));
records.add(channelRecord);
channelRecord = ChannelRecord.createReadRecord("ch6", DataType.DOUBLE);
channelRecord.setChannelStatus(new ChannelStatus(ChannelFlag.SUCCESS));
channelRecord.setValue(TypedValues.newDoubleValue(1.234));
records.add(channelRecord);
channelRecord = ChannelRecord.createReadRecord("ch7", DataType.FLOAT);
channelRecord.setChannelStatus(new ChannelStatus(ChannelFlag.SUCCESS));
channelRecord.setValue(TypedValues.newFloatValue(12.34f));
records.add(channelRecord);
channelRecord = ChannelRecord.createReadRecord("ch8", DataType.LONG);
channelRecord.setChannelStatus(new ChannelStatus(ChannelFlag.SUCCESS));
channelRecord.setValue(TypedValues.newLongValue(1234));
records.add(channelRecord);
when(asset.readAllChannels()).thenReturn(records);

JsonElement json = svc.read(pid);
Expand Down Expand Up @@ -242,10 +247,10 @@ public void testReadSelectedChannels() throws KuraException {
channelNames.add("ch1");

List<ChannelRecord> records = new ArrayList<>();
ChannelRecord record = ChannelRecord.createReadRecord("ch1", DataType.BOOLEAN);
record.setChannelStatus(new ChannelStatus(ChannelFlag.SUCCESS));
record.setValue(TypedValues.newBooleanValue(true));
records.add(record);
ChannelRecord channelRecord = ChannelRecord.createReadRecord("ch1", DataType.BOOLEAN);
channelRecord.setChannelStatus(new ChannelStatus(ChannelFlag.SUCCESS));
channelRecord.setValue(TypedValues.newBooleanValue(true));
records.add(channelRecord);
when(assetMock.read(channelNames)).thenReturn(records);

ReadRequest request = new ReadRequest() {
Expand Down Expand Up @@ -329,6 +334,7 @@ public boolean isValid() {
};

doAnswer(invocation -> {
@SuppressWarnings("unchecked")
List<ChannelRecord> records = invocation.getArgument(0, List.class);
assertEquals(7, records.size());

Expand All @@ -348,7 +354,7 @@ public boolean isValid() {
verify(asset, times(1)).write(any());
}

private void assertChannelWrite(List<ChannelRecord> records, int idx, String channel, TypedValue value) {
private void assertChannelWrite(List<ChannelRecord> records, int idx, String channel, TypedValue<?> value) {
ChannelRecord channelRecord = records.get(idx);
assertEquals(channel, channelRecord.getChannelName());
assertEquals(value, channelRecord.getValue());
Expand Down

0 comments on commit 14ad3a0

Please sign in to comment.