@Override
    public NativeEntity<ViewDTO> createNativeEntity(Entity entity,
                                                    Map<String, ValueReference> parameters,
                                                    Map<EntityDescriptor, Object> nativeEntities,
                                                    String username) {
        ensureV1(entity);
        final User user = Optional.ofNullable(userService.load(username)).orElseThrow(() -> new IllegalStateException("Cannot load user <" + username + "> from db"));
        return decode((EntityV1) entity, parameters, nativeEntities, user);
    }
@Test
    @MongoDBFixtures("ViewFacadeTest.json")
    public void itShouldCreateADTOFromAnEntity() throws Exception {
        final StreamImpl stream = new StreamImpl(Collections.emptyMap());
        final Entity viewEntity = createViewEntity();
        final Map<EntityDescriptor, Object> nativeEntities = Map.of(EntityDescriptor.create(newStreamId, ModelTypes.STREAM_V1), stream);
        final UserImpl fakeUser = new UserImpl(mock(PasswordAlgorithmFactory.class), new Permissions(ImmutableSet.of()),
                mock(ClusterConfigService.class), ImmutableMap.of("username", "testuser"));
        when(userService.load("testuser")).thenReturn(fakeUser);
        final NativeEntity<ViewDTO> nativeEntity = facade.createNativeEntity(viewEntity,
                Collections.emptyMap(), nativeEntities, "testuser");

        assertThat(nativeEntity.descriptor().title()).isEqualTo("title");
        assertThat(nativeEntity.descriptor().type()).isEqualTo(ModelTypes.SEARCH_V1);

        Optional<ViewDTO> resultedView = viewService.get(nativeEntity.descriptor().id().id());
        assertThat(resultedView).isPresent();
        Optional<Search> search = searchDbService.get(resultedView.get().searchId());
        assertThat(search).isPresent();
        final Query query = search.get().queries().iterator().next();
        assertThat(query.filter()).isNotNull();
        assertThat(query.filter().filters()).isNotEmpty();
        final StreamFilter streamFilter = (StreamFilter) query.filter().filters().iterator().next();
        assertThat(streamFilter.streamId()).doesNotMatch(newStreamId);
    }