public void upgrade() {
        final List<User> users = userService.loadAll();

        for (User user : users) {
            final Map<String, Set<String>> migratableEntities = getMigratableEntities(ImmutableSet.copyOf(user.getPermissions()));
            if (!migratableEntities.isEmpty()) {
                migrateUserPermissions(user, migratableEntities);
            }
        }
    }
@Test
    void migrateAllUserPermissions() {
        final ViewDTO view1 = mock(ViewDTO.class);
        final ViewDTO view2 = mock(ViewDTO.class);

        when(view1.type()).thenReturn(ViewDTO.Type.DASHBOARD);
        when(view2.type()).thenReturn(ViewDTO.Type.SEARCH);
        when(viewService.get("5c40ad603c034441a56943be")).thenReturn(Optional.of(view1));
        when(viewService.get("5c40ad603c034441a56943c0")).thenReturn(Optional.of(view2));

        User testuser1 = userService.load("testuser1");
        assertThat(testuser1).isNotNull();

        assertThat(testuser1.getPermissions().size()).isEqualTo(11 + userSelfEditPermissionCount);
        assertThat(dbGrantService.getForGranteesOrGlobal(ImmutableSet.of(grnRegistry.ofUser(testuser1)))).isEmpty();

        migration.upgrade();

        // check created grants for testuser1
        final ImmutableSet<GrantDTO> grants = dbGrantService.getForGranteesOrGlobal(ImmutableSet.of(grnRegistry.ofUser(testuser1)));
        assertGrantInSet(grants, "grn::::dashboard:5e2afc66cd19517ec2dabadd", Capability.VIEW);
        assertGrantInSet(grants, "grn::::dashboard:5e2afc66cd19517ec2dabadf", Capability.MANAGE);
        assertGrantInSet(grants, "grn::::stream:5c40ad603c034441a56942bd", Capability.VIEW);
        assertGrantInSet(grants, "grn::::stream:5e2f5cfb4868e67ad4da562d", Capability.VIEW);
        assertGrantInSet(grants, "grn::::dashboard:5c40ad603c034441a56943be", Capability.MANAGE);
        assertGrantInSet(grants, "grn::::search:5c40ad603c034441a56943c0", Capability.VIEW);
        assertGrantInSet(grants, "grn::::event_definition:5c40ad603c034441a56942bf", Capability.MANAGE);
        assertGrantInSet(grants, "grn::::event_definition:5c40ad603c034441a56942c0", Capability.VIEW);
        assertThat(grants.size()).isEqualTo(8);

        // reload user and check that all migrated permissions have been removed
        testuser1 = userService.load("testuser1");
        assertThat(testuser1).isNotNull();
        assertThat(testuser1.getPermissions().size()).isEqualTo(userSelfEditPermissionCount);
    }