@Test
public void validateInvalidWorkflow() {

  final String id = Strings.repeat("id", 1024);
  final String schedule = Strings.repeat("schedule", 1024);
  final String offset = Strings.repeat("offset", 1024);
  final String commitSha = Strings.repeat("sha", 1024);
  final List<String> args = IntStream.range(0, 100).mapToObj(i -> "arg-" + i).collect(toList());
  final Secret secret = Secret.create(Strings.repeat("foo", 1024), Strings.repeat("bar", 4711));
  final String serviceAccount = Strings.repeat("account@abc.com", 1024);
  final List<String> resources = IntStream.range(0, 10)
      .mapToObj(i -> Strings.repeat("res-" + i, 100)).collect(toList());
  final Map<String, String> env = IntStream.range(0, 2000).boxed()
      .collect(toMap(i -> "env-var-" + i, i -> "env-val-" + i));
  final long envSize = env.entrySet().stream().mapToLong(e -> e.getKey().length() + e.getValue().length()).sum();
  final Duration runningTimeout = Duration.ofSeconds(59L);
  var retryCondition = Strings.repeat("foo -> bar", 1024);
  final WorkflowConfiguration invalidConfiguration = WorkflowConfiguration.builder()
      .id(id)
      .schedule(Schedule.parse(schedule))
      .offset(offset)
      .commitSha(commitSha)
      .dockerArgs(args)
      .secret(secret)
      .serviceAccount(serviceAccount)
      .resources(resources)
      .serviceAccount(serviceAccount)
      .env(env)
      .runningTimeout(runningTimeout)
      .retryCondition(retryCondition)
      .build();
  final List<String> errors = sut.validateWorkflow(Workflow.create("test", invalidConfiguration));
  final List<String> expectedErrors = ImmutableList.<String>builder()
      .add(limit("id too long", id.length(), MAX_ID_LENGTH))
      .add("invalid schedule")
      .add(limit("commitSha too long", commitSha.length(), MAX_COMMIT_SHA_LENGTH))
      .add(limit("secret name too long", secret.name().length(), MAX_SECRET_NAME_LENGTH))
      .add(limit("secret mount path too long", secret.mountPath().length(), MAX_SECRET_MOUNT_PATH_LENGTH))
      .add(limit("service account too long", serviceAccount.length(), MAX_SERVICE_ACCOUNT_LENGTH))
      .add(limit("too many resources", resources.size(), MAX_RESOURCES))
      .add(resources.stream().map(r ->
          limit("resource name too long", r.length(), MAX_RESOURCE_LENGTH)).toArray(String[]::new))
      .add("invalid offset: Unable to parse offset period")
      .add(limit("too many env vars", env.size(), MAX_ENV_VARS))
      .add(limit("env too big", envSize, MAX_ENV_SIZE))
      .add(limit("running timeout is too small", runningTimeout, MIN_RUNNING_TIMEOUT))
      .add("service account is not a valid email address: " + serviceAccount)
      .add(limit("retry condition too long", retryCondition.length(), MAX_RETRY_CONDITION_LENGTH))
      .add("invalid retry condition: Expression [" + retryCondition + "] @4: EL1042E: Problem parsing right operand")
      .build();
  assertThat(errors, containsInAnyOrder(expectedErrors.toArray()));
}