From 86eeb412ea6216c4f416cc4ced13b4d341ab4203 Mon Sep 17 00:00:00 2001 From: Salvatore Coppola <83589980+salvatore-coppola@users.noreply.github.com> Date: Tue, 3 Dec 2024 16:41:57 +0100 Subject: [PATCH] fix(asset.provider): Added integer and float as possible Scale and Offset type (#5584) * Set default scale and offset value to Optional.empty() * Fixed tests * fixed test 2 * fixed test 3 * Fixed test * Added missing type in the webui * Added missing types in ScaleOffsetType copy * fixed bug * Reverted scale and offset default state tu 1.0d and 0.0d * Fixed tests * added test coverage and fixed missing types in datatype method * fixed typos * restored old code * Restored and deprecated old methods --- .../META-INF/MANIFEST.MF | 2 +- .../META-INF/MANIFEST.MF | 2 +- .../org.eclipse.kura.api/META-INF/MANIFEST.MF | 2 +- .../org/eclipse/kura/channel/Channel.java | 63 +------- .../eclipse/kura/channel/ScaleOffsetType.java | 19 ++- .../META-INF/MANIFEST.MF | 2 +- .../META-INF/MANIFEST.MF | 2 +- .../kura/asset/provider/BaseAsset.java | 12 +- .../provider/BaseAssetConfiguration.java | 38 ++++- .../provider/helper/ChannelRecordHelper.java | 4 + .../META-INF/MANIFEST.MF | 2 +- .../META-INF/MANIFEST.MF | 2 +- .../META-INF/MANIFEST.MF | 2 +- .../META-INF/MANIFEST.MF | 2 +- .../META-INF/MANIFEST.MF | 2 +- .../META-INF/MANIFEST.MF | 2 +- .../META-INF/MANIFEST.MF | 2 +- .../META-INF/MANIFEST.MF | 2 +- .../META-INF/MANIFEST.MF | 2 +- .../META-INF/MANIFEST.MF | 2 +- .../kura/web/shared/ScaleOffsetType.java | 17 ++- .../META-INF/MANIFEST.MF | 2 +- .../META-INF/MANIFEST.MF | 2 +- .../helper/test/ChannelRecordHelperTest.java | 8 +- .../kura/asset/provider/test/AssetTest.java | 141 ++++++++++++++++-- .../asset/cloudlet/AssetCloudletTest.java | 22 +-- .../rest/asset/AssetRestServiceTest.java | 81 +++++----- .../rest/wire/provider/test/Snippets.java | 8 + .../internal/wire/asset/WireAssetTest.java | 16 +- 29 files changed, 306 insertions(+), 157 deletions(-) diff --git a/kura/examples/org.eclipse.kura.example.driver.sensehat/META-INF/MANIFEST.MF b/kura/examples/org.eclipse.kura.example.driver.sensehat/META-INF/MANIFEST.MF index b6426a4f39c..f54688c779b 100644 --- a/kura/examples/org.eclipse.kura.example.driver.sensehat/META-INF/MANIFEST.MF +++ b/kura/examples/org.eclipse.kura.example.driver.sensehat/META-INF/MANIFEST.MF @@ -8,7 +8,7 @@ Bundle-License: Eclipse Public License v2.0 Bundle-Category: Asset-Driver Management Bundle-ActivationPolicy: lazy Import-Package: org.eclipse.kura;version="[1.2,2.0)", - org.eclipse.kura.channel;version="[1.0,2.0)", + org.eclipse.kura.channel;version="[2.0,3.0)", org.eclipse.kura.channel.listener;version="[1.0,1.1)", org.eclipse.kura.configuration;version="[1.1,2.0)", org.eclipse.kura.configuration.metatype;version="[1.0,2.0)", diff --git a/kura/examples/org.eclipse.kura.wire.devel.component.provider/META-INF/MANIFEST.MF b/kura/examples/org.eclipse.kura.wire.devel.component.provider/META-INF/MANIFEST.MF index 1013119cc44..b038d82bced 100644 --- a/kura/examples/org.eclipse.kura.wire.devel.component.provider/META-INF/MANIFEST.MF +++ b/kura/examples/org.eclipse.kura.wire.devel.component.provider/META-INF/MANIFEST.MF @@ -5,7 +5,7 @@ Bundle-SymbolicName: org.eclipse.kura.wire.devel.component.provider Bundle-Version: 2.0.0.qualifier Bundle-ActivationPolicy: lazy Import-Package: org.eclipse.kura;version="[1.0,2.0)", - org.eclipse.kura.channel;version="[1.0,2.0)", + org.eclipse.kura.channel;version="[2.0,3.0)", org.eclipse.kura.channel.listener;version="[1.0,2.0)", org.eclipse.kura.configuration;version="[1.0,2.0)", org.eclipse.kura.configuration.metatype;version="[1.0,2.0)", diff --git a/kura/org.eclipse.kura.api/META-INF/MANIFEST.MF b/kura/org.eclipse.kura.api/META-INF/MANIFEST.MF index 45cc542e232..1e7eaa3bb13 100644 --- a/kura/org.eclipse.kura.api/META-INF/MANIFEST.MF +++ b/kura/org.eclipse.kura.api/META-INF/MANIFEST.MF @@ -15,7 +15,7 @@ Export-Package: org.eclipse.kura;version="1.7.0", org.eclipse.kura.bluetooth.le.beacon.listener;version="1.0.0", org.eclipse.kura.certificate;version="2.1.0", org.eclipse.kura.certificate.enrollment;version="1.0.0", - org.eclipse.kura.channel;version="1.3.0", + org.eclipse.kura.channel;version="2.0.0", org.eclipse.kura.channel.listener;version="1.0.0", org.eclipse.kura.clock;version="1.0.1", org.eclipse.kura.cloud;version="1.1.0", diff --git a/kura/org.eclipse.kura.api/src/main/java/org/eclipse/kura/channel/Channel.java b/kura/org.eclipse.kura.api/src/main/java/org/eclipse/kura/channel/Channel.java index 242d67582e8..67d89db208c 100644 --- a/kura/org.eclipse.kura.api/src/main/java/org/eclipse/kura/channel/Channel.java +++ b/kura/org.eclipse.kura.api/src/main/java/org/eclipse/kura/channel/Channel.java @@ -80,37 +80,6 @@ public class Channel { */ private boolean isEnabled = true; - /** - * Instantiates a new channel. - * - * @param name - * the name for this channel - * @param type - * the type - * @param valueType - * the value type - * @param config - * the configuration - * @throws NullPointerException - * if any of the arguments is null - * @deprecated Use {@link #Channel(String, ChannelType, DataType, ScaleOffsetType, Number, Number, Map)} - */ - - @Deprecated - public Channel(final String name, final ChannelType type, final DataType valueType, - final Map config) { - - requireNonNull(name, MESSAGE_CHANNEL_NAME_CANNOT_BE_NULL); - requireNonNull(type, MESSAGE_CHANNEL_TYPE_CANNOT_BE_NULL); - requireNonNull(valueType, MESSAGE_CHANNEL_VALUE_TYPE_CANNOT_BE_NULL); - requireNonNull(config, MESSAGE_CHANNEL_CONFIGURATION_CANNOT_BE_NULL); - - this.configuration = Collections.unmodifiableMap(config); - this.name = name; - this.type = type; - this.valueType = valueType; - } - /** * Instantiates a new channel. * @@ -215,20 +184,6 @@ public boolean isEnabled() { return this.isEnabled; } - /** - * Returns a double that represents the scale factor to be applied to the read value - * - * @return a double that represents the scale factor to be applied to the read value - * - * @since 2.3 - * - * @deprecated Use {@link #getValueScaleAsNumber()} - */ - @Deprecated - public double getValueScale() { - return this.valueScale.doubleValue(); - } - /** * Returns a {@link Number} that represents the scale factor to be applied to the read * value @@ -241,20 +196,6 @@ public Number getValueScaleAsNumber() { return this.valueScale; } - /** - * Returns a double that represents the offset to be applied to the read value - * - * @return a double that represents the offset to be applied to the read value - * - * @since 2.3 - * - * @deprecated Use {@link #getValueOffsetAsNumber()} - */ - @Deprecated - public double getValueOffset() { - return this.valueOffset.doubleValue(); - } - /** * Returns a {@link TypedValue} that represents the offset factor to be applied to the read * value @@ -345,7 +286,9 @@ public void setEnabled(boolean isEnabled) { * @param scale * a double value that specifies the scale to be applied to the channel value * @since 2.3 + * @deprecated since version 3.0 */ + @Deprecated public void setScale(double scale) { this.valueScale = scale; } @@ -367,7 +310,9 @@ public void setScale(Number scale) { * @param offset * a double value that specifies the offset to be applied to the channel value * @since 2.3 + * @deprecated since version 3.0 */ + @Deprecated public void setOffset(double offset) { this.valueOffset = offset; } 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 0ce24738275..fde2bc36028 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,8 +22,15 @@ public enum ScaleOffsetType { DEFINED_BY_VALUE_TYPE, + /** + * @since 3.0 + */ + FLOAT, DOUBLE, - + /** + * @since 3.0 + */ + INTEGER, LONG; /** @@ -41,15 +48,23 @@ public static ScaleOffsetType getScaleOffsetType(String stringScaleOffsetType) { return DEFINED_BY_VALUE_TYPE; } + if (FLOAT.name().equalsIgnoreCase(stringScaleOffsetType)) { + return FLOAT; + } + if (DOUBLE.name().equalsIgnoreCase(stringScaleOffsetType)) { return DOUBLE; } + if (INTEGER.name().equalsIgnoreCase(stringScaleOffsetType)) { + return INTEGER; + } + if (LONG.name().equalsIgnoreCase(stringScaleOffsetType)) { return LONG; } - throw new IllegalArgumentException("Cannot convert to DataType"); + throw new IllegalArgumentException("Cannot convert to ScaleOffsetType"); } } diff --git a/kura/org.eclipse.kura.asset.cloudlet.provider/META-INF/MANIFEST.MF b/kura/org.eclipse.kura.asset.cloudlet.provider/META-INF/MANIFEST.MF index 666964899d3..2b401ac501c 100644 --- a/kura/org.eclipse.kura.asset.cloudlet.provider/META-INF/MANIFEST.MF +++ b/kura/org.eclipse.kura.asset.cloudlet.provider/META-INF/MANIFEST.MF @@ -10,7 +10,7 @@ Require-Capability: osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=1.8))" Import-Package: com.eclipsesource.json;version="0.9.5", org.eclipse.kura;version="[1.3,2.0)", org.eclipse.kura.asset;version="[1.0,2.0)", - org.eclipse.kura.channel;version="[1.0,2.0)", + org.eclipse.kura.channel;version="[2.0,3.0)", org.eclipse.kura.cloud;version="[1.1,1.2)", org.eclipse.kura.cloudconnection.message;version="[1.0,2.0)", org.eclipse.kura.cloudconnection.request;version="[1.0,1.1)", diff --git a/kura/org.eclipse.kura.asset.provider/META-INF/MANIFEST.MF b/kura/org.eclipse.kura.asset.provider/META-INF/MANIFEST.MF index 7b213a75efc..dfe541b5fa3 100644 --- a/kura/org.eclipse.kura.asset.provider/META-INF/MANIFEST.MF +++ b/kura/org.eclipse.kura.asset.provider/META-INF/MANIFEST.MF @@ -10,7 +10,7 @@ Require-Capability: osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=1.8))" Import-Package: org.eclipse.kura;version="[1.2,2.0)", org.eclipse.kura.annotation;version="[1.0,2.0)", org.eclipse.kura.asset;version="[1.0,1.1)", - org.eclipse.kura.channel;version="[1.2,2.0)", + org.eclipse.kura.channel;version="[2.0,3.0)", org.eclipse.kura.channel.listener;version="[1.0,1.1)", org.eclipse.kura.configuration;version="[1.1,2.0)", org.eclipse.kura.configuration.metatype;version="[1.1,2.0)", 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 62596a3f26d..627ed0ddf00 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 @@ -462,12 +462,12 @@ private TypedValue calculateScaleAndOffsetByTypedValue(TypedVa Number result; switch (typedValue.getType()) { - case DOUBLE: - result = (double) typedValue.getValue() * scale.doubleValue() + offset.doubleValue(); - break; case FLOAT: result = (float) typedValue.getValue() * scale.floatValue() + offset.floatValue(); break; + case DOUBLE: + result = (double) typedValue.getValue() * scale.doubleValue() + offset.doubleValue(); + break; case INTEGER: result = (int) typedValue.getValue() * scale.intValue() + offset.intValue(); break; @@ -488,9 +488,15 @@ private TypedValue calculateScaleAndOffset(DataType outputValu Number result = null; switch (scaleOffsetType) { + case FLOAT: + result = scale.floatValue() * typedValue.getValue().floatValue() + offset.floatValue(); + break; case DOUBLE: result = scale.doubleValue() * typedValue.getValue().doubleValue() + offset.doubleValue(); break; + case INTEGER: + result = scale.intValue() * typedValue.getValue().intValue() + offset.intValue(); + break; case LONG: result = scale.longValue() * typedValue.getValue().longValue() + offset.longValue(); break; 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 02b5f3d20d1..c9107ebc115 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 @@ -345,7 +345,7 @@ private static Number getValueScale(final Map properties) { if (valueScale == null || valueScale.isEmpty()) { return 1.0d; } - return parseScaleOffsetTypedValue(getScaleOffsetType(properties), valueScale); + return parseScaleOffsetTypedValue(getScaleOffsetType(properties), getDataType(properties), valueScale); } private static Number getValueOffset(final Map properties) { @@ -354,7 +354,7 @@ private static Number getValueOffset(final Map properties) { if (valueOffset == null || valueOffset.isEmpty()) { return 0.0d; } - return parseScaleOffsetTypedValue(getScaleOffsetType(properties), valueOffset); + return parseScaleOffsetTypedValue(getScaleOffsetType(properties), getDataType(properties), valueOffset); } private static String getUnit(final Map properties) { @@ -402,18 +402,42 @@ private static Channel extractChannel(final String channelName, final Map channels = assetConfiguration.getAssetChannels(); - assertEquals(6, channels.size()); + assertEquals(12, 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.getValueScaleAsNumber().doubleValue(), 0.0); - assertEquals(0.0d, channel1.getValueOffsetAsNumber().doubleValue(), 0.0); + assertEquals(1, channel1.getValueScaleAsNumber()); + assertEquals(0, channel1.getValueOffsetAsNumber()); assertEquals("sample.channel1.modbus.register", channel1.getConfiguration().get("DRIVER.modbus.register")); assertEquals("sample.channel1.modbus.FC", channel1.getConfiguration().get("DRIVER.modbus.FC")); @@ -232,7 +298,9 @@ public void testListen() throws KuraException { AtomicBoolean invoked = new AtomicBoolean(false); final ChannelListener listener = event -> { - assertEquals(1, event.getChannelRecord().getValue().getValue()); + if (event.getChannelRecord().getValue() != null) { + assertEquals(1, event.getChannelRecord().getValue().getValue()); + } invoked.set(true); }; @@ -410,7 +478,7 @@ public void testUnlistenDriverException() throws KuraException { @TestTarget(targetPlatforms = { TestTarget.PLATFORM_ALL }) @Test public void testRead() throws KuraException { - final List records = asset.read(new HashSet(Arrays.asList("1.CH"))); + final List records = asset.read(new HashSet<>(Arrays.asList("1.CH"))); assertNotNull(records); assertEquals(1, records.size()); @@ -423,7 +491,7 @@ public void testRead() throws KuraException { @TestTarget(targetPlatforms = { TestTarget.PLATFORM_ALL }) @Test public void testReadChannelNotReadable() throws KuraException { - List result = asset.read(new HashSet(Arrays.asList("2.CH"))); + List result = asset.read(new HashSet<>(Arrays.asList("2.CH"))); assertNotNull(result); assertEquals(1, result.size()); @@ -439,7 +507,7 @@ public void testReadAllChannels() throws KuraException { final List records = asset.readAllChannels(); assertNotNull(records); - assertEquals(3, records.size()); + assertEquals(9, records.size()); assertEquals(7, records.get(0).getValue().getValue()); } @@ -491,7 +559,7 @@ public void testGetConfiguration() throws KuraException { List ads = ocd.getAD(); assertNotNull(ads); - assertEquals(56, ads.size()); // description, driver, 54 from BaseChannelDescriptor and StubChannelDescriptor + assertEquals(110, ads.size()); assertEquals("asset.desc", ads.get(0).getId()); assertEquals("driver.pid", ads.get(1).getId()); @@ -514,7 +582,7 @@ public void testGetConfiguration() throws KuraException { @TestTarget(targetPlatforms = { TestTarget.PLATFORM_ALL }) @Test public void testReadChannelDisabled() throws KuraException { - List result = asset.read(new HashSet(Arrays.asList("3.CH"))); + List result = asset.read(new HashSet<>(Arrays.asList("3.CH"))); assertNotNull(result); assertEquals(1, result.size()); @@ -646,13 +714,62 @@ public void testChannelRecordValueTypeWithDoubleScaleOffset() throws KuraExcepti } @Test - public void testChannelRecordValueTypeWithDefiniedByValueScaleOffset() throws KuraException { + public void testChannelRecordValueTypeWithIntegerScaleOffset() throws KuraException { + + List records = asset.read(new HashSet<>(Arrays.asList("7.CH"))); + + assertEquals(DataType.INTEGER, records.get(0).getValueType()); + } + + @Test + public void testChannelRecordValueTypeWithLongScaleOffset() throws KuraException { + + List records = asset.read(new HashSet<>(Arrays.asList("8.CH"))); + + assertEquals(DataType.LONG, records.get(0).getValueType()); + } + + @Test + public void testChannelRecordValueTypeWithFloatScaleOffset() throws KuraException { + + List records = asset.read(new HashSet<>(Arrays.asList("9.CH"))); + + assertEquals(DataType.FLOAT, records.get(0).getValueType()); + + } + + @Test + public void testChannelRecordValueTypeWithDefiniedByValueScaleOffsetInteger() throws KuraException { List records = asset.read(new HashSet<>(Arrays.asList("6.CH"))); assertEquals(DataType.INTEGER, records.get(0).getValueType()); } + @Test + public void testChannelRecordValueTypeWithDefiniedByValueScaleOffsetLong() throws KuraException { + + List records = asset.read(new HashSet<>(Arrays.asList("11.CH"))); + + assertEquals(DataType.LONG, records.get(0).getValueType()); + } + + @Test + public void testChannelRecordValueTypeWithDefiniedByValueScaleOffsetFloat() throws KuraException { + + List records = asset.read(new HashSet<>(Arrays.asList("12.CH"))); + + assertEquals(DataType.FLOAT, records.get(0).getValueType()); + } + + @Test + public void testChannelRecordValueTypeWithDefiniedByValueScaleOffsetDouble() throws KuraException { + + List records = asset.read(new HashSet<>(Arrays.asList("13.CH"))); + + assertEquals(DataType.DOUBLE, records.get(0).getValueType()); + } + public void bindAsset(Asset asset) { AssetTest.asset = asset; diff --git a/kura/test/org.eclipse.kura.internal.asset.cloudlet.test/src/test/java/org/eclipse/kura/internal/asset/cloudlet/AssetCloudletTest.java b/kura/test/org.eclipse.kura.internal.asset.cloudlet.test/src/test/java/org/eclipse/kura/internal/asset/cloudlet/AssetCloudletTest.java index ac3d235d491..ceec7547ecf 100644 --- a/kura/test/org.eclipse.kura.internal.asset.cloudlet.test/src/test/java/org/eclipse/kura/internal/asset/cloudlet/AssetCloudletTest.java +++ b/kura/test/org.eclipse.kura.internal.asset.cloudlet.test/src/test/java/org/eclipse/kura/internal/asset/cloudlet/AssetCloudletTest.java @@ -13,7 +13,6 @@ package org.eclipse.kura.internal.asset.cloudlet; import static org.eclipse.kura.cloudconnection.request.RequestHandlerMessageConstants.ARGS_KEY; - import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.mock; @@ -32,6 +31,7 @@ import org.eclipse.kura.asset.AssetService; import org.eclipse.kura.channel.Channel; import org.eclipse.kura.channel.ChannelType; +import org.eclipse.kura.channel.ScaleOffsetType; import org.eclipse.kura.cloudconnection.message.KuraMessage; import org.eclipse.kura.core.testutil.TestUtil; import org.eclipse.kura.message.KuraRequestPayload; @@ -39,7 +39,6 @@ import org.eclipse.kura.type.DataType; import org.junit.Test; import org.osgi.framework.BundleContext; -import org.osgi.framework.InvalidSyntaxException; import org.osgi.service.component.ComponentContext; public class AssetCloudletTest { @@ -125,7 +124,8 @@ public void testDoGetEmptyRequest() throws NoSuchFieldException, KuraException { Asset assetMock = mock(Asset.class); Map channels = new HashMap<>(); Map channelConfig = new HashMap<>(); - Channel channel = new Channel("ch1", ChannelType.READ_WRITE, DataType.INTEGER, channelConfig); + Channel channel = new Channel("ch1", ChannelType.READ_WRITE, DataType.INTEGER, + ScaleOffsetType.DEFINED_BY_VALUE_TYPE, 1.0d, 0.0d, channelConfig); channels.put("ch1", channel); AssetConfiguration assetConfiguration = new AssetConfiguration("description", "driverPid", channels); when(assetMock.getAssetConfiguration()).thenReturn(assetConfiguration); @@ -212,7 +212,8 @@ public void testDoGet() throws NoSuchFieldException, KuraException { Asset assetMock = mock(Asset.class); Map channels = new HashMap<>(); Map channelConfig = new HashMap<>(); - Channel channel = new Channel("ch1", ChannelType.READ_WRITE, DataType.INTEGER, channelConfig); + Channel channel = new Channel("ch1", ChannelType.READ_WRITE, DataType.INTEGER, + ScaleOffsetType.DEFINED_BY_VALUE_TYPE, 1.0d, 0.0d, channelConfig); channels.put("ch1", channel); AssetConfiguration assetConfiguration = new AssetConfiguration("description", "driverPid", channels); when(assetMock.getAssetConfiguration()).thenReturn(assetConfiguration); @@ -298,7 +299,8 @@ public void testDoExecReadJsonParseException() throws KuraException, NoSuchField Asset assetMock = mock(Asset.class); Map channels = new HashMap<>(); Map channelConfig = new HashMap<>(); - Channel channel = new Channel("ch1", ChannelType.READ_WRITE, DataType.INTEGER, channelConfig); + Channel channel = new Channel("ch1", ChannelType.READ_WRITE, DataType.INTEGER, + ScaleOffsetType.DEFINED_BY_VALUE_TYPE, 1.0d, 0.0d, channelConfig); channels.put("ch1", channel); AssetConfiguration assetConfiguration = new AssetConfiguration("description", "driverPid", channels); when(assetMock.getAssetConfiguration()).thenReturn(assetConfiguration); @@ -342,7 +344,8 @@ public void testDoExecReadNull() throws KuraException, NoSuchFieldException { Asset assetMock = mock(Asset.class); Map channels = new HashMap<>(); Map channelConfig = new HashMap<>(); - Channel channel = new Channel("ch1", ChannelType.READ_WRITE, DataType.INTEGER, channelConfig); + Channel channel = new Channel("ch1", ChannelType.READ_WRITE, DataType.INTEGER, + ScaleOffsetType.DEFINED_BY_VALUE_TYPE, 1.0d, 0.0d, channelConfig); channels.put("ch1", channel); AssetConfiguration assetConfiguration = new AssetConfiguration("description", "driverPid", channels); when(assetMock.getAssetConfiguration()).thenReturn(assetConfiguration); @@ -391,7 +394,8 @@ public void testDoExecRead() throws KuraException, NoSuchFieldException { Asset assetMock = mock(Asset.class); Map channels = new HashMap<>(); Map channelConfig = new HashMap<>(); - Channel channel = new Channel("ch1", ChannelType.READ_WRITE, DataType.INTEGER, channelConfig); + Channel channel = new Channel("ch1", ChannelType.READ_WRITE, DataType.INTEGER, + ScaleOffsetType.DEFINED_BY_VALUE_TYPE, 1.0d, 0.0d, channelConfig); channels.put("ch1", channel); AssetConfiguration assetConfiguration = new AssetConfiguration("description", "driverPid", channels); when(assetMock.getAssetConfiguration()).thenReturn(assetConfiguration); @@ -431,7 +435,7 @@ public void testDoExecRead() throws KuraException, NoSuchFieldException { } @Test(expected = KuraException.class) - public void testDoExecWriteNoRequestBody() throws NoSuchFieldException, InvalidSyntaxException, KuraException { + public void testDoExecWriteNoRequestBody() throws NoSuchFieldException, KuraException { // test doExec initiating write with no request body AssetCloudlet svc = new AssetCloudlet(); @@ -464,7 +468,7 @@ public void testDoExecWriteNoRequestBody() throws NoSuchFieldException, InvalidS } @Test - public void testDoExecWrite() throws NoSuchFieldException, InvalidSyntaxException, KuraException { + public void testDoExecWrite() throws NoSuchFieldException, KuraException { // test doExec initiating write AssetCloudlet svc = new AssetCloudlet(); diff --git a/kura/test/org.eclipse.kura.rest.asset.provider.test/src/test/java/org/eclipse/kura/internal/rest/asset/AssetRestServiceTest.java b/kura/test/org.eclipse.kura.rest.asset.provider.test/src/test/java/org/eclipse/kura/internal/rest/asset/AssetRestServiceTest.java index 3b24515cd6a..6113ae0032c 100644 --- a/kura/test/org.eclipse.kura.rest.asset.provider.test/src/test/java/org/eclipse/kura/internal/rest/asset/AssetRestServiceTest.java +++ b/kura/test/org.eclipse.kura.rest.asset.provider.test/src/test/java/org/eclipse/kura/internal/rest/asset/AssetRestServiceTest.java @@ -44,6 +44,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; @@ -56,6 +57,7 @@ public class AssetRestServiceTest { + @SuppressWarnings("unchecked") @Test public void testListAssetPids() throws InvalidSyntaxException { // test retrieval of asset service pids @@ -122,10 +124,12 @@ public void testGetAssetChannels() { Map channels = new TreeMap<>(); Map 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, + 1.0d, 0.0d, 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, + 1.0d, 0.0d, channelConfig); channels.put(ch2.getName(), ch2); AssetConfiguration assetConfig = new AssetConfiguration("description", "driverPid", channels); @@ -153,37 +157,37 @@ public void testReadAllChannels() throws KuraException { when(asMock.getAsset(pid)).thenReturn(asset); List 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); @@ -242,10 +246,10 @@ public void testReadSelectedChannels() throws KuraException { channelNames.add("ch1"); List 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() { @@ -329,6 +333,7 @@ public boolean isValid() { }; doAnswer(invocation -> { + @SuppressWarnings("unchecked") List records = invocation.getArgument(0, List.class); assertEquals(7, records.size()); @@ -348,7 +353,7 @@ public boolean isValid() { verify(asset, times(1)).write(any()); } - private void assertChannelWrite(List records, int idx, String channel, TypedValue value) { + private void assertChannelWrite(List records, int idx, String channel, TypedValue value) { ChannelRecord channelRecord = records.get(idx); assertEquals(channel, channelRecord.getChannelName()); assertEquals(value, channelRecord.getValue()); 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 87a883a60e3..937fb98221e 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 @@ -102,10 +102,18 @@ public class Snippets { + " \"value\": \"DEFINED_BY_VALUE_TYPE\"\n" // + " },\n" // + " {\n" // + + " \"label\": \"FLOAT\",\n" // + + " \"value\": \"FLOAT\"\n" // + + " },\n" // + + " {\n" // + " \"label\": \"DOUBLE\",\n" // + " \"value\": \"DOUBLE\"\n" // + " },\n" // + " {\n" // + + " \"label\": \"INTEGER\",\n" // + + " \"value\": \"INTEGER\"\n" // + + " },\n" // + + " {\n" // + " \"label\": \"LONG\",\n" // + " \"value\": \"LONG\"\n" // + " }\n" // diff --git a/kura/test/org.eclipse.kura.wire.component.provider.test/src/test/java/org/eclipse/kura/internal/wire/asset/WireAssetTest.java b/kura/test/org.eclipse.kura.wire.component.provider.test/src/test/java/org/eclipse/kura/internal/wire/asset/WireAssetTest.java index 1e002a70994..05518fd2f72 100644 --- a/kura/test/org.eclipse.kura.wire.component.provider.test/src/test/java/org/eclipse/kura/internal/wire/asset/WireAssetTest.java +++ b/kura/test/org.eclipse.kura.wire.component.provider.test/src/test/java/org/eclipse/kura/internal/wire/asset/WireAssetTest.java @@ -35,6 +35,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.configuration.ConfigurationService; import org.eclipse.kura.driver.Driver; import org.eclipse.kura.driver.Driver.ConnectionException; @@ -91,8 +92,10 @@ public void testOnWireReceive() throws NoSuchFieldException, ConnectionException wireAssetProperties.put(AssetConstants.ASSET_DRIVER_PROP.value(), "driverPid"); wireAssetProperties.put(ConfigurationService.KURA_SERVICE_PID, "componentName"); - Channel readChannel1 = new Channel("readChannel1", ChannelType.READ, DataType.BOOLEAN, new HashMap<>()); - Channel writeChannel2 = new Channel("writeChannel2", ChannelType.WRITE, DataType.BOOLEAN, new HashMap<>()); + Channel readChannel1 = new Channel("readChannel1", ChannelType.READ, DataType.BOOLEAN, + ScaleOffsetType.DEFINED_BY_VALUE_TYPE, 1.0d, 0.0d, new HashMap<>()); + Channel writeChannel2 = new Channel("writeChannel2", ChannelType.WRITE, DataType.BOOLEAN, + ScaleOffsetType.DEFINED_BY_VALUE_TYPE, 1.0d, 0.0d, new HashMap<>()); putChannel(readChannel1, wireAssetProperties); putChannel(writeChannel2, wireAssetProperties); @@ -196,9 +199,12 @@ public void testTimestampModes() throws NoSuchFieldException, ConnectionExceptio wireAssetProperties.put(AssetConstants.ASSET_DRIVER_PROP.value(), "driverPid"); wireAssetProperties.put(ConfigurationService.KURA_SERVICE_PID, "componentName"); - Channel readChannel1 = new Channel("0", ChannelType.READ, DataType.BOOLEAN, Collections.emptyMap()); - Channel readChannel2 = new Channel("1", ChannelType.READ, DataType.BOOLEAN, Collections.emptyMap()); - Channel readChannel3 = new Channel("2", ChannelType.READ, DataType.BOOLEAN, Collections.emptyMap()); + Channel readChannel1 = new Channel("0", ChannelType.READ, DataType.BOOLEAN, + ScaleOffsetType.DEFINED_BY_VALUE_TYPE, 1.0d, 0.0d, Collections.emptyMap()); + Channel readChannel2 = new Channel("1", ChannelType.READ, DataType.BOOLEAN, + ScaleOffsetType.DEFINED_BY_VALUE_TYPE, 1.0d, 0.0d, Collections.emptyMap()); + Channel readChannel3 = new Channel("2", ChannelType.READ, DataType.BOOLEAN, + ScaleOffsetType.DEFINED_BY_VALUE_TYPE, 1.0d, 0.0d, Collections.emptyMap()); putChannel(readChannel1, wireAssetProperties); putChannel(readChannel2, wireAssetProperties);