diff --git a/kura/org.eclipse.kura.api/src/main/java/org/eclipse/kura/channel/ChannelRecord.java b/kura/org.eclipse.kura.api/src/main/java/org/eclipse/kura/channel/ChannelRecord.java index 50ccf2c885..fb7ff69418 100644 --- a/kura/org.eclipse.kura.api/src/main/java/org/eclipse/kura/channel/ChannelRecord.java +++ b/kura/org.eclipse.kura.api/src/main/java/org/eclipse/kura/channel/ChannelRecord.java @@ -68,6 +68,8 @@ @NotThreadSafe public class ChannelRecord { + private static final String NULL_CHANNEL_NAME_ERROR_MESSAGE = "Channel Name cannot be null"; + /** * Provided channel configuration to perform read or write * operation. @@ -115,7 +117,7 @@ private ChannelRecord() { * @return the channel record */ public static ChannelRecord createReadRecord(final String channelName, final DataType valueType) { - requireNonNull(channelName, "Channel Name cannot be null"); + requireNonNull(channelName, NULL_CHANNEL_NAME_ERROR_MESSAGE); requireNonNull(valueType, "Value Type cannot be null"); ChannelRecord result = new ChannelRecord(); @@ -131,7 +133,7 @@ public static ChannelRecord createReadRecord(final String channelName, final Dat */ public static ChannelRecord createReadRecord(final String channelName, final DataType valueType, final String unit) { - requireNonNull(channelName, "Channel Name cannot be null"); + requireNonNull(channelName, NULL_CHANNEL_NAME_ERROR_MESSAGE); requireNonNull(valueType, "Value Type cannot be null"); ChannelRecord result = new ChannelRecord(); @@ -154,7 +156,7 @@ public static ChannelRecord createReadRecord(final String channelName, final Dat * @return the channel record */ public static ChannelRecord createWriteRecord(final String channelName, final TypedValue value) { - requireNonNull(channelName, "Channel Name cannot be null"); + requireNonNull(channelName, NULL_CHANNEL_NAME_ERROR_MESSAGE); requireNonNull(value, "Value cannot be null"); ChannelRecord result = new ChannelRecord(); @@ -177,7 +179,7 @@ public static ChannelRecord createWriteRecord(final String channelName, final Ty * @return the channel record */ public static ChannelRecord createStatusRecord(final String channelName, final ChannelStatus status) { - requireNonNull(channelName, "Channel Name cannot be null"); + requireNonNull(channelName, NULL_CHANNEL_NAME_ERROR_MESSAGE); requireNonNull(status, "Status cannot be null"); ChannelRecord result = new ChannelRecord(); diff --git a/kura/org.eclipse.kura.api/src/main/java/org/eclipse/kura/channel/ScaleOffsetType.java b/kura/org.eclipse.kura.api/src/main/java/org/eclipse/kura/channel/ScaleOffsetType.java index b5cadd0005..0ce2473827 100644 --- a/kura/org.eclipse.kura.api/src/main/java/org/eclipse/kura/channel/ScaleOffsetType.java +++ b/kura/org.eclipse.kura.api/src/main/java/org/eclipse/kura/channel/ScaleOffsetType.java @@ -22,7 +22,9 @@ public enum ScaleOffsetType { DEFINED_BY_VALUE_TYPE, - DOUBLE; + DOUBLE, + + LONG; /** * Converts {@code stringScaleOffsetType}, if possible, to the related {@link ScaleOffsetType}. @@ -43,6 +45,10 @@ public static ScaleOffsetType getScaleOffsetType(String stringScaleOffsetType) { return DOUBLE; } + if (LONG.name().equalsIgnoreCase(stringScaleOffsetType)) { + return LONG; + } + throw new IllegalArgumentException("Cannot convert to DataType"); } diff --git a/kura/org.eclipse.kura.asset.provider/src/main/java/org/eclipse/kura/asset/provider/BaseAsset.java b/kura/org.eclipse.kura.asset.provider/src/main/java/org/eclipse/kura/asset/provider/BaseAsset.java index 63a287c538..62596a3f26 100644 --- a/kura/org.eclipse.kura.asset.provider/src/main/java/org/eclipse/kura/asset/provider/BaseAsset.java +++ b/kura/org.eclipse.kura.asset.provider/src/main/java/org/eclipse/kura/asset/provider/BaseAsset.java @@ -61,6 +61,7 @@ import org.eclipse.kura.driver.PreparedRead; import org.eclipse.kura.internal.asset.provider.BaseAssetConfiguration; import org.eclipse.kura.internal.asset.provider.DriverTrackerCustomizer; +import org.eclipse.kura.internal.asset.provider.helper.ChannelRecordHelper; import org.eclipse.kura.type.DataType; import org.eclipse.kura.type.TypedValue; import org.eclipse.kura.type.TypedValues; @@ -386,7 +387,8 @@ public List read(final Set channelNames) throws KuraExcep continue; } - final ChannelRecord channelRecord = channel.createReadRecord(); + final ChannelRecord channelRecord = ChannelRecordHelper.createModifiedChannelRecord(channel); + channel.createReadRecord(); validRecords.add(channelRecord); channelRecords.add(channelRecord); } @@ -435,8 +437,9 @@ private void applyScaleAndOffset(final ChannelRecord channelRecord, final Channe newValue = calculateScaleAndOffsetByTypedValue((TypedValue) channelRecord.getValue(), channelScale, channelOffset); } else { - newValue = calculateScaleAndOffset((TypedValue) channelRecord.getValue(), - channel.getScaleOffsetType(), channelScale, channelOffset); + newValue = calculateScaleAndOffset(channel.getValueType(), + (TypedValue) channelRecord.getValue(), channel.getScaleOffsetType(), + channelScale, channelOffset); } channelRecord.setValue(newValue); @@ -479,18 +482,23 @@ private TypedValue calculateScaleAndOffsetByTypedValue(TypedVa } - private TypedValue calculateScaleAndOffset(TypedValue typedValue, - ScaleOffsetType scaleOffsetType, Number scale, Number offset) { + private TypedValue calculateScaleAndOffset(DataType outputValueType, + TypedValue typedValue, ScaleOffsetType scaleOffsetType, Number scale, Number offset) { Number result = null; - if (ScaleOffsetType.DOUBLE.equals(scaleOffsetType)) { + switch (scaleOffsetType) { + case DOUBLE: result = scale.doubleValue() * typedValue.getValue().doubleValue() + offset.doubleValue(); - } else { + break; + case LONG: + result = scale.longValue() * typedValue.getValue().longValue() + offset.longValue(); + break; + default: throw new IllegalArgumentException("Invalid scale/offset type"); } - return toTypedValue(typedValue.getType(), result); + return toTypedValue(outputValueType, result); } diff --git a/kura/org.eclipse.kura.asset.provider/src/main/java/org/eclipse/kura/internal/asset/provider/BaseAssetConfiguration.java b/kura/org.eclipse.kura.asset.provider/src/main/java/org/eclipse/kura/internal/asset/provider/BaseAssetConfiguration.java index 46a0d440b5..02b26acbcc 100644 --- a/kura/org.eclipse.kura.asset.provider/src/main/java/org/eclipse/kura/internal/asset/provider/BaseAssetConfiguration.java +++ b/kura/org.eclipse.kura.asset.provider/src/main/java/org/eclipse/kura/internal/asset/provider/BaseAssetConfiguration.java @@ -51,6 +51,7 @@ import org.eclipse.kura.core.configuration.util.ComponentUtil; import org.eclipse.kura.driver.ChannelDescriptor; import org.eclipse.kura.driver.Driver; +import org.eclipse.kura.internal.asset.provider.helper.ChannelRecordHelper; import org.eclipse.kura.type.DataType; import org.osgi.service.component.ComponentContext; import org.slf4j.Logger; @@ -103,7 +104,7 @@ public List getAllReadRecords() { final Channel channel = e.getValue(); if (channel.isEnabled() && (channel.getType() == ChannelType.READ || channel.getType() == ChannelType.READ_WRITE)) { - readRecords.add(channel.createReadRecord()); + readRecords.add(ChannelRecordHelper.createModifiedChannelRecord(channel)); } } @@ -409,6 +410,9 @@ private static Number parseScaleOffsetTypedValue(ScaleOffsetType type, String va case DEFINED_BY_VALUE_TYPE: case DOUBLE: return Double.parseDouble(value); + case LONG: + // TODO replace with Long.parseLong(value) once scale and offset are turned in String in the metatype + return (Double.valueOf(value).longValue()); default: throw new IllegalArgumentException(value + " cannot be converted into a Number of type " + type); } diff --git a/kura/org.eclipse.kura.asset.provider/src/main/java/org/eclipse/kura/internal/asset/provider/helper/ChannelRecordHelper.java b/kura/org.eclipse.kura.asset.provider/src/main/java/org/eclipse/kura/internal/asset/provider/helper/ChannelRecordHelper.java new file mode 100644 index 0000000000..ae29390489 --- /dev/null +++ b/kura/org.eclipse.kura.asset.provider/src/main/java/org/eclipse/kura/internal/asset/provider/helper/ChannelRecordHelper.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2024 Eurotech and/or its affiliates and others + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Eurotech + *******************************************************************************/ + +package org.eclipse.kura.internal.asset.provider.helper; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.kura.asset.provider.AssetConstants; +import org.eclipse.kura.channel.Channel; +import org.eclipse.kura.channel.ChannelRecord; +import org.eclipse.kura.channel.ScaleOffsetType; +import org.eclipse.kura.type.DataType; + +public class ChannelRecordHelper { + + private ChannelRecordHelper() { + // Private constructor to prevent instantiation + } + + public static ChannelRecord createModifiedChannelRecord(Channel channel) { + + DataType actualDataType = channel.getScaleOffsetType() == ScaleOffsetType.DEFINED_BY_VALUE_TYPE + ? channel.getValueType() + : toDataType(channel.getScaleOffsetType()); + + ChannelRecord channelRecord = ChannelRecord.createReadRecord(channel.getName(), actualDataType, + channel.getUnit()); + + Map configMap = new HashMap<>(channel.getConfiguration()); + configMap.put(AssetConstants.VALUE_TYPE.value(), actualDataType.name()); + channelRecord.setChannelConfig(configMap); + + return channelRecord; + } + + private static DataType toDataType(ScaleOffsetType scaleOffsetType) { + switch (scaleOffsetType) { + case DOUBLE: + return DataType.DOUBLE; + case LONG: + return DataType.LONG; + default: + throw new IllegalArgumentException("Unsupported scale offset type: " + scaleOffsetType); + } + } +} diff --git a/kura/test/org.eclipse.kura.asset.provider.test/src/main/java/org/eclipse/kura/asset/provider/helper/test/ChannelRecordHelperTest.java b/kura/test/org.eclipse.kura.asset.provider.test/src/main/java/org/eclipse/kura/asset/provider/helper/test/ChannelRecordHelperTest.java new file mode 100644 index 0000000000..736350f150 --- /dev/null +++ b/kura/test/org.eclipse.kura.asset.provider.test/src/main/java/org/eclipse/kura/asset/provider/helper/test/ChannelRecordHelperTest.java @@ -0,0 +1,63 @@ +package org.eclipse.kura.asset.provider.helper.test; + +import static org.junit.Assert.assertEquals; + +import java.util.Collections; + +import org.eclipse.kura.channel.Channel; +import org.eclipse.kura.channel.ChannelRecord; +import org.eclipse.kura.channel.ChannelType; +import org.eclipse.kura.channel.ScaleOffsetType; +import org.eclipse.kura.internal.asset.provider.helper.ChannelRecordHelper; +import org.eclipse.kura.type.DataType; +import org.junit.Test; + +public class ChannelRecordHelperTest { + + private Channel channel; + private ChannelRecord channelRecord; + + @Test + public void shouldCreateChannelRecorWithDoubleValueType() { + givenChannel(new Channel("test-channel", ChannelType.READ, DataType.INTEGER, ScaleOffsetType.DOUBLE, 3.3d, 3.1d, + Collections.emptyMap())); + + whenCreatedChannelRecord(); + + thenChannelRecordValueTypeIs(DataType.DOUBLE); + } + + @Test + public void shouldCreateChannelRecorWithIntegerValueType() { + givenChannel(new Channel("test-channel", ChannelType.READ, DataType.INTEGER, + ScaleOffsetType.DEFINED_BY_VALUE_TYPE, 3.3d, 3.1d, Collections.emptyMap())); + + whenCreatedChannelRecord(); + + thenChannelRecordValueTypeIs(DataType.INTEGER); + } + + @Test + public void shouldCreateChannelRecorWithLongValueType() { + givenChannel(new Channel("test-channel", ChannelType.READ, DataType.INTEGER, ScaleOffsetType.LONG, 3l, 4l, + Collections.emptyMap())); + + whenCreatedChannelRecord(); + + thenChannelRecordValueTypeIs(DataType.LONG); + } + + private void thenChannelRecordValueTypeIs(DataType datatype) { + assertEquals(datatype, this.channelRecord.getValueType()); + + } + + private void givenChannel(Channel channel) { + this.channel = channel; + + } + + private void whenCreatedChannelRecord() { + this.channelRecord = ChannelRecordHelper.createModifiedChannelRecord(this.channel); + } +} diff --git a/kura/test/org.eclipse.kura.asset.provider.test/src/main/java/org/eclipse/kura/asset/provider/test/AssetTest.java b/kura/test/org.eclipse.kura.asset.provider.test/src/main/java/org/eclipse/kura/asset/provider/test/AssetTest.java index a7c1e3bfbc..22f9320dc3 100644 --- a/kura/test/org.eclipse.kura.asset.provider.test/src/main/java/org/eclipse/kura/asset/provider/test/AssetTest.java +++ b/kura/test/org.eclipse.kura.asset.provider.test/src/main/java/org/eclipse/kura/asset/provider/test/AssetTest.java @@ -40,6 +40,7 @@ import org.eclipse.kura.channel.ChannelFlag; import org.eclipse.kura.channel.ChannelRecord; import org.eclipse.kura.channel.ChannelType; +import org.eclipse.kura.channel.ScaleOffsetType; import org.eclipse.kura.channel.listener.ChannelListener; import org.eclipse.kura.configuration.ComponentConfiguration; import org.eclipse.kura.configuration.ConfigurationService; @@ -61,6 +62,8 @@ */ public final class AssetTest { + private static final String UNREGISTER_CHANNEL_NAME = "unregister"; + /** Logger */ private static final Logger logger = LoggerFactory.getLogger(AssetTest.class); @@ -74,23 +77,12 @@ public final class AssetTest { /** A latch to be initialized with the no of OSGi dependencies it needs */ private static CountDownLatch dependencyLatch = new CountDownLatch(1); - /** The Device Configuration instance. */ - public AssetConfiguration configuration; - - /** The properties to be parsed as Device Configuration. */ - public Map properties; - - /** The Channel Configuration */ - public Map sampleChannelConfig; - /** * JUnit Callback to be triggered before creating the instance of this suite * - * @throws Exception - * if the dependent services are null */ @BeforeClass - public static void setUpClass() throws Exception { + public static void setUpClass() { // Wait for OSGi dependencies logger.info("Setting Up The Testcase...."); try { @@ -101,58 +93,80 @@ public static void setUpClass() throws Exception { fail("OSGi dependencies unfulfilled"); } - // asset = new BaseAsset(); - - // initt(); } @Before public void init() throws InterruptedException { // may need to wait for asset to be registered and injected - if (asset == null) { + while (asset == null) { synchronized (assetLock) { assetLock.wait(3000); } } - initt(); + resetChannels(); } /** * Initializes asset data */ - private static void initt() { + private static void resetChannels() { final Map channels = CollectionUtil.newHashMap(); + channels.put("kura.service.pid", "AssetTest"); + channels.put(AssetConstants.ASSET_DESC_PROP.value(), "sample.asset.desc"); channels.put(AssetConstants.ASSET_DRIVER_PROP.value(), "org.eclipse.kura.asset.stub.driver"); channels.put("1.CH#+name", "1.CH"); channels.put("1.CH#+type", "READ"); - channels.put("1.CH#+value.type", "INTEGER"); + channels.put("1.CH#+value.type", DataType.INTEGER.name()); channels.put("1.CH#+scale", "1.0"); channels.put("1.CH#+offset", "0.0"); channels.put("1.CH#DRIVER.modbus.register", "sample.channel1.modbus.register"); channels.put("1.CH#DRIVER.modbus.FC", "sample.channel1.modbus.FC"); + channels.put("2.CH#+name", "2.CH"); channels.put("2.CH#+enabled", "true"); channels.put("2.CH#+type", "WRITE"); - channels.put("2.CH#+value.type", "BOOLEAN"); + channels.put("2.CH#+value.type", DataType.BOOLEAN.name()); channels.put("2.CH#DRIVER.modbus.register", "sample.channel2.modbus.register"); channels.put("2.CH#DRIVER.modbus.DUMMY.NN", "sample.channel2.modbus.FC"); + channels.put("3.CH#+name", "3.CH"); channels.put("3.CH#+type", "READ"); channels.put("3.CH#+enabled", "false"); - channels.put("3.CH#+value.type", "INTEGER"); + channels.put("3.CH#+value.type", DataType.INTEGER.name()); channels.put("3.CH#DRIVER.modbus.register", "sample.channel1.modbus.register"); channels.put("3.CH#DRIVER.modbus.FC", "sample.channel1.modbus.FC"); - channels.put("4.CH#+name", "3.CH"); + + channels.put("4.CH#+name", "4.CH"); channels.put("4.CH#+enabled", "false"); channels.put("4.CH#+type", "WRITE"); - channels.put("4.CH#+value.type", "BOOLEAN"); + channels.put("4.CH#+value.type", DataType.BOOLEAN.name()); channels.put("4.CH#DRIVER.modbus.register", "sample.channel2.modbus.register"); channels.put("4.CH#DRIVER.modbus.DUMMY.NN", "sample.channel2.modbus.FC"); + channels.put("5.CH#+name", "5.CH"); + channels.put("5.CH#+enabled", "true"); + channels.put("5.CH#+type", "READ"); + channels.put("5.CH#+value.type", DataType.INTEGER.name()); + channels.put("5.CH#+scaleoffset.type", ScaleOffsetType.DOUBLE.name()); + channels.put("5.CH#+scale", "3.3"); + channels.put("5.CH#+offset", "3.2"); + channels.put("5.CH#DRIVER.modbus.register", "sample.channel2.modbus.register"); + channels.put("5.CH#DRIVER.modbus.DUMMY.NN", "sample.channel2.modbus.FC"); + + channels.put("6.CH#+name", "6.CH"); + channels.put("6.CH#+enabled", "true"); + channels.put("6.CH#+type", "READ"); + channels.put("6.CH#+value.type", DataType.INTEGER.name()); + channels.put("6.CH#+scaleoffset.type", ScaleOffsetType.DEFINED_BY_VALUE_TYPE.name()); + channels.put("6.CH#+scale", "3"); + channels.put("6.CH#+offset", "4"); + channels.put("6.CH#DRIVER.modbus.register", "sample.channel2.modbus.register"); + channels.put("6.CH#DRIVER.modbus.DUMMY.NN", "sample.channel2.modbus.FC"); + ((BaseAsset) asset).updated(channels); sync(asset); } @@ -187,15 +201,15 @@ public void testChannelProperties() { final AssetConfiguration assetConfiguration = asset.getAssetConfiguration(); assertNotNull(assetConfiguration); final Map channels = assetConfiguration.getAssetChannels(); - assertEquals(4, channels.size()); + assertEquals(6, channels.size()); final Channel channel1 = channels.get("1.CH"); assertTrue(channel1.isEnabled()); assertEquals("1.CH", channel1.getName()); assertEquals(ChannelType.READ, channel1.getType()); assertEquals(DataType.INTEGER, channel1.getValueType()); - assertEquals(1.0d, channel1.getValueScale(), 0.0); - assertEquals(0.0d, channel1.getValueOffset(), 0.0); + assertEquals(1.0d, channel1.getValueScaleAsNumber().doubleValue(), 0.0); + assertEquals(0.0d, channel1.getValueOffsetAsNumber().doubleValue(), 0.0); assertEquals("sample.channel1.modbus.register", channel1.getConfiguration().get("DRIVER.modbus.register")); assertEquals("sample.channel1.modbus.FC", channel1.getConfiguration().get("DRIVER.modbus.FC")); @@ -240,11 +254,8 @@ public void testListenerAttachOnDriverChange() throws KuraException { final ArrayList attachSequence = new ArrayList<>(); final ChannelListener listener = event -> { - if ("unregister".equals(event.getChannelRecord().getChannelName())) { - attachSequence.add(false); - } else { - attachSequence.add(true); - } + boolean toBeAttached = !UNREGISTER_CHANNEL_NAME.equals(event.getChannelRecord().getChannelName()); + attachSequence.add(toBeAttached); }; asset.registerChannelListener("1.CH", listener); @@ -272,11 +283,8 @@ public void testAttachListenerWhitoutDriver() throws KuraException { final ArrayList attachSequence = new ArrayList<>(); final ChannelListener listener = event -> { - if ("unregister".equals(event.getChannelRecord().getChannelName())) { - attachSequence.add(false); - } else { - attachSequence.add(true); - } + boolean toBeAttached = !UNREGISTER_CHANNEL_NAME.equals(event.getChannelRecord().getChannelName()); + attachSequence.add(toBeAttached); }; ((BaseAsset) asset).unsetDriver(); @@ -305,11 +313,8 @@ public void testShouldNotReattachSameListener() throws KuraException { final ArrayList attachSequence = new ArrayList<>(); final ChannelListener listener = event -> { - if ("unregister".equals(event.getChannelRecord().getChannelName())) { - attachSequence.add(false); - } else { - attachSequence.add(true); - } + boolean toBeAttached = !UNREGISTER_CHANNEL_NAME.equals(event.getChannelRecord().getChannelName()); + attachSequence.add(toBeAttached); }; asset.registerChannelListener("1.CH", listener); @@ -343,7 +348,7 @@ public void testUnlisten() throws KuraException { if (cnt == 0) { assertEquals(1, event.getChannelRecord().getValue().getValue()); } else if (cnt == 1) { - assertEquals("unregister", event.getChannelRecord().getChannelName()); + assertEquals(UNREGISTER_CHANNEL_NAME, event.getChannelRecord().getChannelName()); assertEquals(DataType.BOOLEAN, event.getChannelRecord().getValueType()); } else { fail("Unexpected invocation."); @@ -434,8 +439,8 @@ public void testReadAllChannels() throws KuraException { final List records = asset.readAllChannels(); assertNotNull(records); - assertEquals(1, records.size()); - assertEquals(1, records.get(0).getValue().getValue()); + assertEquals(3, records.size()); + assertEquals(7, records.get(0).getValue().getValue()); } /** @@ -486,7 +491,7 @@ public void testGetConfiguration() throws KuraException { List ads = ocd.getAD(); assertNotNull(ads); - assertEquals(38, ads.size()); // description, driver, 32 from BaseChannelDescriptor and StubChannelDescriptor + assertEquals(56, ads.size()); // description, driver, 54 from BaseChannelDescriptor and StubChannelDescriptor assertEquals("asset.desc", ads.get(0).getId()); assertEquals("driver.pid", ads.get(1).getId()); @@ -542,11 +547,8 @@ public void testListenerAttachOnDisabledChannel() throws KuraException { final ArrayList attachSequence = new ArrayList<>(); final ChannelListener listener = event -> { - if ("unregister".equals(event.getChannelRecord().getChannelName())) { - attachSequence.add(false); - } else { - attachSequence.add(true); - } + boolean toBeAttached = !UNREGISTER_CHANNEL_NAME.equals(event.getChannelRecord().getChannelName()); + attachSequence.add(toBeAttached); }; asset.registerChannelListener("3.CH", listener); @@ -578,11 +580,8 @@ public void testEnableDisableChannelWithListener() throws KuraException { sync(asset); final ChannelListener listener = event -> { - if ("unregister".equals(event.getChannelRecord().getChannelName())) { - attachSequence.add(false); - } else { - attachSequence.add(true); - } + boolean toBeAttached = !UNREGISTER_CHANNEL_NAME.equals(event.getChannelRecord().getChannelName()); + attachSequence.add(toBeAttached); }; asset.registerChannelListener("3.CH", listener); @@ -602,7 +601,6 @@ public void testEnableDisableChannelWithListener() throws KuraException { assertEquals(Arrays.asList(true, false), attachSequence); - initt(); } /** @@ -611,7 +609,7 @@ public void testEnableDisableChannelWithListener() throws KuraException { */ @TestTarget(targetPlatforms = { TestTarget.PLATFORM_ALL }) @Test - public void testCompleteConfigWithDefaults() throws KuraException { + public void testCompleteConfigWithDefaults() { final Map channels = CollectionUtil.newHashMap(); channels.put("kura.service.pid", "AssetTest"); @@ -636,7 +634,23 @@ public void testCompleteConfigWithDefaults() throws KuraException { assertEquals("5", asset.getAssetConfiguration().getAssetChannels().get("3.CH").getConfiguration().get("unit.id")); - initt(); + } + + @Test + public void testChannelRecordValueTypeWithDoubleScaleOffset() throws KuraException { + + List records = asset.read(new HashSet<>(Arrays.asList("5.CH"))); + + assertEquals(DataType.DOUBLE, records.get(0).getValueType()); + + } + + @Test + public void testChannelRecordValueTypeWithDefiniedByValueScaleOffset() throws KuraException { + + List records = asset.read(new HashSet<>(Arrays.asList("6.CH"))); + + assertEquals(DataType.INTEGER, records.get(0).getValueType()); } public void bindAsset(Asset asset) { diff --git a/kura/test/org.eclipse.kura.rest.wire.provider.test/src/main/java/org/eclipse/kura/rest/wire/provider/test/Snippets.java b/kura/test/org.eclipse.kura.rest.wire.provider.test/src/main/java/org/eclipse/kura/rest/wire/provider/test/Snippets.java index 3984c28c00..7e3ad330ed 100644 --- a/kura/test/org.eclipse.kura.rest.wire.provider.test/src/main/java/org/eclipse/kura/rest/wire/provider/test/Snippets.java +++ b/kura/test/org.eclipse.kura.rest.wire.provider.test/src/main/java/org/eclipse/kura/rest/wire/provider/test/Snippets.java @@ -104,6 +104,10 @@ public class Snippets { + " {\n" // + " \"label\": \"DOUBLE\",\n" // + " \"value\": \"DOUBLE\"\n" // + + " },\n" // + + " {\n" // + + " \"label\": \"LONG\",\n" // + + " \"value\": \"LONG\"\n" // + " }\n" // + " ],\n" // + " \"name\": \"scaleoffset.type\",\n" // diff --git a/kura/test/org.eclipse.kura.wire.component.provider.test/src/main/java/org/eclipse/kura/internal/wire/asset/test/ScaleOffsetTest.java b/kura/test/org.eclipse.kura.wire.component.provider.test/src/main/java/org/eclipse/kura/internal/wire/asset/test/ScaleOffsetTest.java index e82a77c6a0..13c89393a4 100644 --- a/kura/test/org.eclipse.kura.wire.component.provider.test/src/main/java/org/eclipse/kura/internal/wire/asset/test/ScaleOffsetTest.java +++ b/kura/test/org.eclipse.kura.wire.component.provider.test/src/main/java/org/eclipse/kura/internal/wire/asset/test/ScaleOffsetTest.java @@ -88,6 +88,33 @@ public void shouldApplyScaleToLongWithDoubleScale() { thenAssetOutputContains(0, "foo", 3l); } + @Test + public void shouldApplyScaleToLongWithLongScale() { + givenAssetChannel("foo", DataType.LONG, ScaleOffsetType.LONG, Optional.of(3), Optional.empty()); + + whenDriverProducesValue("foo", 40l); + + thenAssetOutputContains(0, "foo", 120l); + } + + @Test + public void shouldApplyOffsetToLongWithLongScale() { + givenAssetChannel("foo", DataType.LONG, ScaleOffsetType.LONG, Optional.empty(), Optional.of(55)); + + whenDriverProducesValue("foo", 40l); + + thenAssetOutputContains(0, "foo", 95l); + } + + @Test + public void shouldApplyBothScaleAndOffsetToLongWithLongScale() { + givenAssetChannel("foo", DataType.LONG, ScaleOffsetType.LONG, Optional.of(2), Optional.of(55)); + + whenDriverProducesValue("foo", 40l); + + thenAssetOutputContains(0, "foo", 135l); + } + @Test public void shouldApplyOffsetToDouble() { givenAssetChannel("foo", DataType.DOUBLE, ScaleOffsetType.DOUBLE, Optional.empty(), Optional.of(10.0d));