@VisibleForTesting
    Entity exportNativeEntity(InputWithExtractors inputWithExtractors, EntityDescriptorIds entityDescriptorIds) {
        final Input input = inputWithExtractors.input();

        // TODO: Create independent representation of entity?
        final Map<String, ValueReference> staticFields = input.getStaticFields().entrySet().stream()
                .collect(Collectors.toMap(Map.Entry::getKey, kv -> ValueReference.of(kv.getValue())));
        final ReferenceMap configuration = toReferenceMap(input.getConfiguration());
        final List<ExtractorEntity> extractors = inputWithExtractors.extractors().stream()
                .map(this::encodeExtractor)
                .collect(Collectors.toList());
        final InputEntity inputEntity = InputEntity.create(
                ValueReference.of(input.getTitle()),
                configuration,
                staticFields,
                ValueReference.of(input.getType()),
                ValueReference.of(input.isGlobal()),
                extractors);
        final JsonNode data = objectMapper.convertValue(inputEntity, JsonNode.class);
        final Set<Constraint> constraints = versionConstraints(input);
        return EntityV1.builder()
                .id(ModelId.of(entityDescriptorIds.getOrThrow(input.getId(), ModelTypes.INPUT_V1)))
                .type(ModelTypes.INPUT_V1)
                .data(data)
                .constraints(ImmutableSet.copyOf(constraints))
                .build();
    }
@Test
    public void exportNativeEntityWithEncryptedValues() {
        final ImmutableMap<String, Object> fields = ImmutableMap.of(
                MessageInput.FIELD_TITLE, "Input Title",
                MessageInput.FIELD_TYPE, "org.graylog2.inputs.misc.jsonpath.JsonPathInput",
                MessageInput.FIELD_CONFIGURATION,
                Map.of("encrypted_value",
                        new EncryptedValueService(UUID.randomUUID().toString()).encrypt("secret")));
        final InputImpl input = new InputImpl(fields);
        final ImmutableList<Extractor> extractors = ImmutableList.of();
        final InputWithExtractors inputWithExtractors = InputWithExtractors.create(input, extractors);
        final EntityDescriptor descriptor = EntityDescriptor.create(input.getId(), ModelTypes.INPUT_V1);
        final EntityDescriptorIds entityDescriptorIds = EntityDescriptorIds.of(descriptor);
        final Entity entity = facade.exportNativeEntity(inputWithExtractors, entityDescriptorIds);

        assertThat(entity).isInstanceOf(EntityV1.class);
        assertThat(entity.id()).isEqualTo(ModelId.of(entityDescriptorIds.get(descriptor).orElse(null)));
        assertThat(entity.type()).isEqualTo(ModelTypes.INPUT_V1);

        final EntityV1 entityV1 = (EntityV1) entity;
        final InputEntity inputEntity = objectMapper.convertValue(entityV1.data(), InputEntity.class);
        assertThat(inputEntity.title()).isEqualTo(ValueReference.of("Input Title"));
        assertThat(inputEntity.type()).isEqualTo(ValueReference.of("org.graylog2.inputs.misc.jsonpath.JsonPathInput"));
        assertThat(inputEntity.configuration()).hasSize(1).hasEntrySatisfying("encrypted_value", ref -> {
            assertThat(ref).isInstanceOf(ValueReference.class);
            assertThat(((ValueReference) ref).valueType()).isEqualTo(ValueType.STRING);
            assertThat(((ValueReference) ref).asString()).startsWith("<Encrypted value was replaced");
        });
    }