|
25 | 25 | import org.junit.jupiter.params.provider.Arguments; |
26 | 26 | import org.junit.jupiter.params.provider.CsvSource; |
27 | 27 | import org.junit.jupiter.params.provider.MethodSource; |
| 28 | +import org.junit.jupiter.params.provider.ValueSource; |
28 | 29 | import org.mockito.Answers; |
29 | 30 | import org.mockito.ArgumentCaptor; |
30 | 31 | import org.mockito.Mock; |
|
40 | 41 | import static org.hamcrest.MatcherAssert.assertThat; |
41 | 42 | import static org.hamcrest.Matchers.containsString; |
42 | 43 | import static org.hamcrest.Matchers.hasItems; |
| 44 | +import static org.hamcrest.Matchers.is; |
43 | 45 | import static org.junit.jupiter.api.Assertions.assertThrows; |
44 | 46 | import static org.junit.jupiter.api.Assertions.assertTrue; |
45 | 47 | import static org.mockito.ArgumentMatchers.any; |
@@ -487,4 +489,42 @@ void GIVEN_setup_script_WHEN_trusted_plugin_provided_THEN_jar_copied_to_trusted_ |
487 | 489 | greengrassSetup.performSetup(); |
488 | 490 | assertTrue(Files.exists(mockTrustedDirectory.resolve(Utils.namePart(pluginJarPath.toString())))); |
489 | 491 | } |
| 492 | + |
| 493 | + @ParameterizedTest |
| 494 | + @ValueSource(strings = {"group:", "group:1", "group:1:"}) |
| 495 | + void GIVEN_invalid_thing_group_name_WHEN_script_is_used_THEN_error(String groupName, ExtensionContext context) { |
| 496 | + ignoreExceptionUltimateCauseOfType(context, IOException.class); |
| 497 | + Kernel realKernel = new Kernel(); |
| 498 | + greengrassSetup = |
| 499 | + new GreengrassSetup(System.out, System.err, deviceProvisioningHelper, platform, kernel, "--config", |
| 500 | + "mock_config_path", "--root", "mock_root", "--thing-name", "mock_thing_name", |
| 501 | + "--thing-group-name", groupName, "--thing-policy-name", "mock_thing_policy_name", |
| 502 | + "--tes-role-name", "mock_tes_role_name", "--tes-role-alias-name", "mock_tes_role_alias_name", |
| 503 | + "--provision", "--aws-region","us-east-1", "-ss", "false"); |
| 504 | + Exception e = assertThrows(RuntimeException.class, () -> { |
| 505 | + greengrassSetup.parseArgs(); |
| 506 | + greengrassSetup.performSetup(); |
| 507 | + }); |
| 508 | + realKernel.shutdown(); |
| 509 | + assertThat(e.getMessage(), is("Thing group name cannot contain colon characters")); |
| 510 | + } |
| 511 | + |
| 512 | + @ParameterizedTest |
| 513 | + @ValueSource(strings = {"thing:", "thing:1", "thing:1:"}) |
| 514 | + void GIVEN_invalid_thing_name_WHEN_script_is_used_THEN_error(String thingName, ExtensionContext context) { |
| 515 | + ignoreExceptionUltimateCauseOfType(context, IOException.class); |
| 516 | + Kernel realKernel = new Kernel(); |
| 517 | + greengrassSetup = |
| 518 | + new GreengrassSetup(System.out, System.err, deviceProvisioningHelper, platform, kernel, "--config", |
| 519 | + "mock_config_path", "--root", "mock_root", "--thing-name", thingName, |
| 520 | + "--thing-group-name", "group", "--thing-policy-name", "mock_thing_policy_name", |
| 521 | + "--tes-role-name", "mock_tes_role_name", "--tes-role-alias-name", "mock_tes_role_alias_name", |
| 522 | + "--provision", "--aws-region","us-east-1", "-ss", "false"); |
| 523 | + Exception e = assertThrows(RuntimeException.class, () -> { |
| 524 | + greengrassSetup.parseArgs(); |
| 525 | + greengrassSetup.performSetup(); |
| 526 | + }); |
| 527 | + realKernel.shutdown(); |
| 528 | + assertThat(e.getMessage(), is("Thing name cannot contain colon characters")); |
| 529 | + } |
490 | 530 | } |
0 commit comments