EncryptAlgorithmMetaData { public Optional<EncryptAlgorithm> findEncryptor(final int columnIndex) { List<Projection> expandProjections = selectStatementContext.getProjectionsContext().getExpandProjections(); if (expandProjections.isEmpty()) { return Optional.empty(); } return findEncryptor(columnIndex, expandProjections); }  Optional<EncryptAlgorithm> findEncryptor(final int columnIndex);  }
@Test public void assertFindEncryptorByTableNameAndColumnName() { when(tablesContext.findTableName(columnProjection, schemaMetaData)).thenReturn(Optional.of("t_order")); when(encryptRule.findEncryptor("t_order", "id")).thenReturn(Optional.of(encryptAlgorithm)); EncryptAlgorithmMetaData encryptAlgorithmMetaData = new EncryptAlgorithmMetaData(schemaMetaData, encryptRule, selectStatementContext); Optional<EncryptAlgorithm> actualEncryptor = encryptAlgorithmMetaData.findEncryptor(1); assertTrue(actualEncryptor.isPresent()); assertThat(actualEncryptor.get().getType(), is("MD5")); }
@Test public void assertFindEncryptorByColumnName() { when(tablesContext.findTableName(columnProjection, schemaMetaData)).thenReturn(Optional.empty()); when(tablesContext.getTableNames()).thenReturn(Arrays.asList("t_user", "t_user_item", "t_order_item")); when(encryptRule.findEncryptor("t_order_item", "id")).thenReturn(Optional.of(encryptAlgorithm)); EncryptAlgorithmMetaData encryptAlgorithmMetaData = new EncryptAlgorithmMetaData(schemaMetaData, encryptRule, selectStatementContext); Optional<EncryptAlgorithm> actualEncryptor = encryptAlgorithmMetaData.findEncryptor(1); assertTrue(actualEncryptor.isPresent()); assertThat(actualEncryptor.get().getType(), is("MD5")); }
@Test public void assertFindEncryptorWhenColumnProjectionIsNotExist() { when(projectionsContext.getExpandProjections()).thenReturn(Collections.singletonList(mock(DerivedProjection.class))); EncryptAlgorithmMetaData encryptAlgorithmMetaData = new EncryptAlgorithmMetaData(schemaMetaData, encryptRule, selectStatementContext); Optional<EncryptAlgorithm> actualEncryptor = encryptAlgorithmMetaData.findEncryptor(1); assertFalse(actualEncryptor.isPresent()); }