package io.blueocean.ath.offline.personalization;

import io.blueocean.ath.ATHJUnitRunner;
import io.blueocean.ath.BaseUrl;
import io.blueocean.ath.GitRepositoryRule;
import io.blueocean.ath.Login;
import io.blueocean.ath.ResourceResolver;
import io.blueocean.ath.WebDriverMixin;
import io.blueocean.ath.api.classic.ClassicJobApi;
import io.blueocean.ath.factory.ClassicPipelineFactory;
import io.blueocean.ath.factory.FreestyleJobFactory;
import io.blueocean.ath.factory.MultiBranchPipelineFactory;
import io.blueocean.ath.model.Folder;
import io.blueocean.ath.pages.blue.FavoritesDashboardPage;
import io.jenkins.blueocean.util.HttpRequest;
import org.apache.log4j.Logger;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.runner.RunWith;

import javax.inject.Inject;
import java.io.IOException;

/**
 * @author cliffmeyers
 */
@Login
@RunWith(ATHJUnitRunner.class)
abstract public class AbstractFavoritesTest implements WebDriverMixin {

    static final Folder FOLDER = new Folder("personalization-folder");

    @Rule @Inject
    public GitRepositoryRule git;

    @Inject @BaseUrl
    String base;

    @Inject
    ClassicJobApi jobApi;

    @Inject
    FreestyleJobFactory freestyleFactory;

    @Inject
    ClassicPipelineFactory pipelineFactory;

    @Inject
    MultiBranchPipelineFactory multibranchFactory;

    @Inject
    FavoritesDashboardPage dashboardPage;

    protected ResourceResolver resources;

    abstract protected Logger getLogger();

    private HttpRequest httpRequest() {
        return new HttpRequest(base + "/blue/rest");
    }

    @Before
    public void setUp() throws IOException {
        resources = new ResourceResolver(getClass());

        String user = "alice";
        getLogger().info(String.format("deleting any existing favorites for %s", user));

        httpRequest()
            .Delete("/users/{user}/favorites/")
            .urlPart("user", user)
            .auth(user, user)
            .status(204)
            .as(Void.class);
    }

    @After
    public void tearDown() throws IOException {
        // wipe out all jobs to avoid causing issues w/ SearchTest
        jobApi.deleteFolder(FOLDER);
    }
}

@@ -601,77 +601,108 @@
 ort 
-io.jenkins.blueocean.util.HttpRequest;%0Aimport org.apache.log4j.Logger
+org.apache.log4j.Logger;%0Aimport org.glassfish.jersey.client.authentication.HttpAuthenticationFeature
 ;%0Aim
@@ -833,16 +833,91 @@
 Inject;%0A
+import javax.ws.rs.client.Client;%0Aimport javax.ws.rs.client.ClientBuilder;%0A
 import j
@@ -1604,108 +1604,8 @@
 );%0A%0A
-    private HttpRequest httpRequest() %7B%0A        return new HttpRequest(base + %22/blue/rest%22);%0A    %7D%0A%0A
     
@@ -1845,104 +1845,108 @@
     
-httpRequest()%0A            .Delete(%22/users/%7Buser%7D/favorites/%22)%0A            .urlPart(%22
+Client restClient = ClientBuilder.newClient().register(HttpAuthenticationFeature.basic(
 user
-%22
 , user)
+);
 %0A   
@@ -1954,81 +1954,84 @@
     
-    .auth(user, user)%0A            .status(204)%0A            .as(Void.class
+restClient.target(base + %22/users/%22 + user + %22/favorites/%22).request().delete(
 );%0A 

Switch to the same http client that sseclientrule uses. If fav test is the first one run, then it doesn't have a user setup to delete favs from and returned 404