Skip to content

fixing inconsistency for data = null in device registry table: adding…#3708

Open
DominikBasnerSotec wants to merge 6 commits intoeclipse-hono:masterfrom
sotec-iot:fix/handle-device-data-is-null-jdbc
Open

fixing inconsistency for data = null in device registry table: adding…#3708
DominikBasnerSotec wants to merge 6 commits intoeclipse-hono:masterfrom
sotec-iot:fix/handle-device-data-is-null-jdbc

Conversation

@DominikBasnerSotec
Copy link
Contributor

… null handling and tests

@sophokles73
Copy link
Contributor

@mattkaem would you mind taking a look? This seems to fall into your area of expertise ...

Comment on lines 238 to 240
final var preparedQueryMock = mock(io.vertx.sqlclient.PreparedQuery.class);
when(preparedQueryMock.execute(any(Tuple.class))).thenReturn(Future.succeededFuture(rowSet));
when(sqlConnection.preparedQuery(anyString())).thenReturn(preparedQueryMock);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be moved into a private method since it is replicated multiple times in this class. WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done the cleanup

Comment on lines +69 to +70
private final String TENANT_ID = "test-tenant";
private final String DEVICE_ID = "device-1";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private final String TENANT_ID = "test-tenant";
private final String DEVICE_ID = "device-1";
private static final String TENANT_ID = "test-tenant";
private static final String DEVICE_ID = "device-1";

And these should be moved to the top of the field declarations

Comment on lines +69 to +77
final Statement statement = Statement.statement("""
UPDATE devices
SET
data=:data::jsonb,
version=:next_version
WHERE
tenant_id=:tenant_id
AND
device_id=:device_id""");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice improvement 👍

return Future.succeededFuture(Optional.empty());
case 1:
final var entry = entries.get(0);
final var deviceJson = entry.getString("data") != null ? entry.getString("data") : "{}";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
final var deviceJson = entry.getString("data") != null ? entry.getString("data") : "{}";
final var deviceJson = Optional.ofNullable(entry.getString("data")).orElse("{}");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants