package com.cloudhandson.vpdbackoffice.service;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.jupiter.api.Test;

class MaskingPolicySynchronizerTest {

  @Test
  void maskingExpressionIsAParseableSqlConditionForRedactionExpressionBindValue() {
    assertThat(MaskingPolicySynchronizer.maskingExpression(11))
        .isEqualTo(
            "SYS_CONTEXT('CB_AGENT_CTX', 'MR_11') IS NULL "
                + "OR SYS_CONTEXT('CB_AGENT_CTX', 'MR_11') <> 'Y'");
  }

  @Test
  void maskingExpressionDoesNotUsePlsqlLiteralEscapingBecauseJdbcBindsTheValue() {
    assertThat(MaskingPolicySynchronizer.maskingExpression(11))
        .doesNotContain("''CB_AGENT_CTX''")
        .doesNotContain("''MR_11''")
        .doesNotContain("''Y''");
  }

  @Test
  void redactionPolicyManagementIsNotBoundToAProductSpecificMapping() {
    assertThat(MaskingPolicySynchronizer.class.getDeclaredFields())
        .extracting(field -> field.getName())
        .doesNotContain("MANAGED_POLICIES", "OWNER");
  }
}
