|
43 | 43 | import org.jetbrains.annotations.NotNull; |
44 | 44 | import org.junit.Test; |
45 | 45 | import udmi.schema.CloudModel; |
| 46 | +import udmi.schema.Credential.Key_format; |
46 | 47 | import udmi.schema.ExecutionConfiguration; |
47 | 48 | import udmi.schema.FamilyLocalnetModel; |
48 | 49 | import udmi.schema.LocalnetModel; |
@@ -524,6 +525,39 @@ public void localnetWithoutFamiliesTest() { |
524 | 525 | } |
525 | 526 | } |
526 | 527 |
|
| 528 | + @Test |
| 529 | + public void credentialsPreservedOnSettingsErrorTest() { |
| 530 | + Registrar registrar = getRegistrar(ImmutableList.of()); |
| 531 | + registrar.execute(() -> { |
| 532 | + Map<String, LocalDevice> localDevices = registrar.getWorkingDevices(); |
| 533 | + Metadata metadata = localDevices.get(GATEWAY_ID).getMetadata(); |
| 534 | + PointPointsetModel blankUnitsPoint = new PointPointsetModel(); |
| 535 | + blankUnitsPoint.units = ""; |
| 536 | + metadata.pointset.points.put("bad_blank_units_point", blankUnitsPoint); |
| 537 | + }); |
| 538 | + |
| 539 | + LocalDevice gateway = registrar.getWorkingDevices().get(GATEWAY_ID); |
| 540 | + assertTrue("Gateway should record settings error for blank units", |
| 541 | + gateway.hasCategory(ExceptionCategory.settings)); |
| 542 | + assertEquals("Gateway settings should still load public key credentials", |
| 543 | + 1, gateway.getSettings().credentials.size()); |
| 544 | + assertEquals("Gateway credential format should be ES256", |
| 545 | + Key_format.ES_256, gateway.getSettings().credentials.get(0).key_format); |
| 546 | + |
| 547 | + List<CloudModel> pushedModels = registrar.getMockActions().stream() |
| 548 | + .filter(action -> GATEWAY_ID.equals(action.deviceId) |
| 549 | + && (action.action == UPDATE_DEVICE_ACTION || action.action == CREATE_DEVICE_ACTION)) |
| 550 | + .map(action -> (CloudModel) action.data) |
| 551 | + .toList(); |
| 552 | + assertEquals("Gateway should be pushed to IoT provider once", 1, pushedModels.size()); |
| 553 | + assertNotNull("Pushed CloudModel credentials must not be null", |
| 554 | + pushedModels.get(0).credentials); |
| 555 | + assertEquals("Pushed CloudModel must retain public key credentials", |
| 556 | + 1, pushedModels.get(0).credentials.size()); |
| 557 | + assertEquals("Pushed CloudModel credential format should be ES256", |
| 558 | + Key_format.ES_256, pushedModels.get(0).credentials.get(0).key_format); |
| 559 | + } |
| 560 | + |
527 | 561 | private Boolean isNotBlocking(MockAction action) { |
528 | 562 | return !TRUE.equals(((CloudModel) action.data).blocked); |
529 | 563 | } |
|
0 commit comments