AsyncStorageModeValidator implements WorkspaceAttributeValidator { @Override public void validate(Map<String, String> attributes) throws ValidationException { if (parseBoolean(attributes.get(ASYNC_PERSIST_ATTRIBUTE))) { isEphemeralAttributeValidation(attributes); pvcStrategyValidation(); alowUserDefinedNamespaceValidation(); nameSpaceStrategyValidation(); runtimesPerUserValidation(); } } @Inject  AsyncStorageModeValidator(
      @Named("che.infra.kubernetes.pvc.strategy") String pvcStrategy,
      @Named("che.infra.kubernetes.namespace.allow_user_defined")
          boolean allowUserDefinedNamespaces,
      @Nullable @Named("che.infra.kubernetes.namespace.default") String defaultNamespaceName,
      @Named("che.limits.user.workspaces.run.count") int runtimesPerUser); @Override void validate(Map<String, String> attributes); @Override void validateUpdate(Map<String, String> existing, Map<String, String> update);  }
@Test( expectedExceptions = ValidationException.class, expectedExceptionsMessageRegExp = "Workspace configuration not valid: Asynchronous storage available only for 'common' PVC strategy, but got not-common") public void shouldThrowExceptionIfNotCommonStrategy() throws ValidationException { AsyncStorageModeValidator validator = new AsyncStorageModeValidator("not-common", false, "", 1); validator.validate(of(ASYNC_PERSIST_ATTRIBUTE, "true", PERSIST_VOLUMES_ATTRIBUTE, "false")); }
@Test( expectedExceptions = ValidationException.class, expectedExceptionsMessageRegExp = "Workspace configuration not valid: Asynchronous storage available only for 'per-user' namespace strategy") public void shouldThrowExceptionIfNotPerUserNamespaceStrategy() throws ValidationException { AsyncStorageModeValidator validator = new AsyncStorageModeValidator("common", false, "my-name", 1); validator.validate(of(ASYNC_PERSIST_ATTRIBUTE, "true", PERSIST_VOLUMES_ATTRIBUTE, "false")); }
@Test( expectedExceptions = ValidationException.class, expectedExceptionsMessageRegExp = "Workspace configuration not valid: Asynchronous storage available only for 'per-user' namespace strategy") public void shouldThrowExceptionWithNullNamespaceStrategy() throws ValidationException { AsyncStorageModeValidator validator = new AsyncStorageModeValidator("common", false, null, 1); validator.validate(of(ASYNC_PERSIST_ATTRIBUTE, "true", PERSIST_VOLUMES_ATTRIBUTE, "false")); }
@Test( expectedExceptions = ValidationException.class, expectedExceptionsMessageRegExp = "Workspace configuration not valid: Asynchronous storage available only if 'che.infra.kubernetes.namespace.allow_user_defined' set to 'false', but got 'true'") public void shouldThrowExceptionIfUserDefineNamespaceAllowed() throws ValidationException { AsyncStorageModeValidator validator = new AsyncStorageModeValidator("common", true, "<username>-che", 1); validator.validate(of(ASYNC_PERSIST_ATTRIBUTE, "true", PERSIST_VOLUMES_ATTRIBUTE, "false")); }
@Test( expectedExceptions = ValidationException.class, expectedExceptionsMessageRegExp = "Workspace configuration not valid: Asynchronous storage available only if 'che.limits.user.workspaces.run.count' set to 1, but got 2") public void shouldThrowExceptionIfMoreThanOneRuntimeEnabled() throws ValidationException { AsyncStorageModeValidator validator = new AsyncStorageModeValidator("common", false, "<username>-che", 2); validator.validate(of(ASYNC_PERSIST_ATTRIBUTE, "true", PERSIST_VOLUMES_ATTRIBUTE, "false")); }
@Test public void shouldBeFineForEphemeralMode() throws ValidationException { AsyncStorageModeValidator validator = new AsyncStorageModeValidator("common", false, "<username>-che", 1); validator.validate(of(PERSIST_VOLUMES_ATTRIBUTE, "false")); }
@Test public void shouldBeFineForPersistentMode() throws ValidationException { AsyncStorageModeValidator validator = new AsyncStorageModeValidator("common", false, "<username>-che", 1); validator.validate(of(PERSIST_VOLUMES_ATTRIBUTE, "true")); }
@Test public void shouldBeFineForEmptyAttribute() throws ValidationException { AsyncStorageModeValidator validator = new AsyncStorageModeValidator("common", false, "<username>-che", 1); validator.validate(of()); }
@Test public void shouldBeFineForAsyncMode() throws ValidationException { AsyncStorageModeValidator validator = new AsyncStorageModeValidator("common", false, "<username>-che", 1); validator.validate(of(ASYNC_PERSIST_ATTRIBUTE, "true", PERSIST_VOLUMES_ATTRIBUTE, "false")); }
@Test( expectedExceptions = ValidationException.class, expectedExceptionsMessageRegExp = "Workspace configuration not valid: Asynchronous storage available only for NOT persistent storage") public void shouldThrowExceptionIfAsyncAttributeForNotEphemeral() throws ValidationException { AsyncStorageModeValidator validator = new AsyncStorageModeValidator("common", false, "<username>-che", 1); validator.validate(of(ASYNC_PERSIST_ATTRIBUTE, "true", PERSIST_VOLUMES_ATTRIBUTE, "true")); }