diff options
-rw-r--r-- | config-provisioning/src/main/java/com/yahoo/config/provision/ApplicationId.java | 3 | ||||
-rw-r--r-- | config-provisioning/src/test/java/com/yahoo/config/provision/ApplicationIdTest.java | 30 |
2 files changed, 30 insertions, 3 deletions
diff --git a/config-provisioning/src/main/java/com/yahoo/config/provision/ApplicationId.java b/config-provisioning/src/main/java/com/yahoo/config/provision/ApplicationId.java index c13f41a8f28..1a7cc5db580 100644 --- a/config-provisioning/src/main/java/com/yahoo/config/provision/ApplicationId.java +++ b/config-provisioning/src/main/java/com/yahoo/config/provision/ApplicationId.java @@ -68,11 +68,12 @@ public class ApplicationId implements Comparable<ApplicationId> { private static ApplicationId fromIdString(String idString, String splitCharacter) { String[] parts = idString.split(splitCharacter); - String errorMessage = "Application ids must be on the form tenant " + + String errorMessage = "Application ids must be on the form tenant" + splitCharacter + "application" + splitCharacter + "instance, but was " + idString; if (parts.length < 3) throw new IllegalArgumentException(errorMessage); // TODO: Throw exception when we have verified no-one is abusing this with more than 3 parts in id string + // Include code in require_that_invalid_idstring_throws_exception() in ApplicationIdTest to test this if (parts.length > 3) log.log(SEVERE, errorMessage); return from(parts[0], parts[1], parts[2]); diff --git a/config-provisioning/src/test/java/com/yahoo/config/provision/ApplicationIdTest.java b/config-provisioning/src/test/java/com/yahoo/config/provision/ApplicationIdTest.java index 0a60b868bde..0b22de35cf0 100644 --- a/config-provisioning/src/test/java/com/yahoo/config/provision/ApplicationIdTest.java +++ b/config-provisioning/src/test/java/com/yahoo/config/provision/ApplicationIdTest.java @@ -14,6 +14,7 @@ import static com.yahoo.config.provision.ApplicationId.global; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.fail; /** * @author Ulf Lilleengen @@ -81,9 +82,34 @@ public class ApplicationIdTest { @Test void require_that_invalid_idstring_throws_exception() { - assertThrows(IllegalArgumentException.class, () -> { + try { ApplicationId.fromSerializedForm("foo:baz"); - }); + fail("Expected to fail"); + } catch (IllegalArgumentException e) { + assertEquals("Application ids must be on the form tenant:application:instance, but was foo:baz", e.getMessage()); + } + try { + ApplicationId.fromSerializedForm("foo.baz"); + fail("Expected to fail"); + } catch (IllegalArgumentException e) { + assertEquals("Application ids must be on the form tenant:application:instance, but was foo.baz", e.getMessage()); + } + + // TODO: Add when we throw exception on strings with too many parts + /* + try { + ApplicationId.fromSerializedForm("foo:baz:bar:xyzzy"); + fail("Expected to fail"); + } catch (IllegalArgumentException e) { + assertEquals("Application ids must be on the form tenant:application:instance, but was foo:baz:bar:xyzzy", e.getMessage()); + } + try { + ApplicationId.fromSerializedForm("foo.baz:bar:xyzzy"); + fail("Expected to fail"); + } catch (IllegalArgumentException e) { + assertEquals("Application ids must be on the form tenant:application:instance, but was foo.baz.bar.xyzzy", e.getMessage()); + } + */ } @Test |