@Test
public void testRejectsBadIdentifiers() throws Exception {
control.replay();
buildScheduler();
Identity validIdentity = new Identity("foo", "bar");
Identity[] invalidIdentities = {
new Identity().setRole("foo"),
new Identity("foo/", "bar"),
new Identity("foo", "&bar"),
new Identity().setUser("bar")
};
String validJob = "baz";
String[] invalidIdentifiers = {"&baz", "/baz", "baz&", ""};
for (Identity ident : invalidIdentities) {
for (String env : invalidIdentifiers) {
for (String job : invalidIdentifiers) {
// Subvert JobKeys.from to avoid IllegalArgumentExceptions.
expectRejected(ident, IJobKey.build(new JobKey()
.setRole(ident.getRole())
.setEnvironment(env)
.setName(job)));
}
}
}
for (String jobName : invalidIdentifiers) {
expectRejected(validIdentity, IJobKey.build(new JobKey()
.setRole(validIdentity.getRole())
.setEnvironment(validJob)
.setName(jobName)));
}
for (Identity ident : invalidIdentities) {