protected static void buildAndDeployMavenProject(String basedir) {
   // need to backup (and later restore) the current class loader, because the Maven/Plexus does
   // some classloader
   // magic which then results in CNFE in RestEasy client
   // run the Maven build which will create the kjar. The kjar is then either installed or deployed
   // to local and
   // remote repo
   logger.debug("Building and deploying Maven project from basedir '{}'.", basedir);
   ClassLoader classLoaderBak = Thread.currentThread().getContextClassLoader();
   MavenCli cli = new MavenCli();
   String[] mvnArgs;
   if (TestConfig.isLocalServer()) {
     // just install into local repository when running the local server. Deploying to remote repo
     // will fail
     // if the repo does not exist.
     mvnArgs = new String[] {"-B", "clean", "install"};
   } else {
     mvnArgs = new String[] {"-B", "clean", "deploy"};
   }
   int mvnRunResult = cli.doMain(mvnArgs, basedir, System.out, System.out);
   if (mvnRunResult != 0) {
     throw new RuntimeException(
         "Error while building Maven project from basedir "
             + basedir
             + ". Return code="
             + mvnRunResult);
   }
   Thread.currentThread().setContextClassLoader(classLoaderBak);
   logger.debug("Maven project successfully built and deployed!");
 }
 @AfterClass
 public static void tearDown() {
   if (TestConfig.isLocalServer()) {
     server.stop();
     System.clearProperty("java.naming.factory.initial");
   }
 }
  protected KieServicesClient createDefaultClient() {
    Set<Class<?>> extraClasses = new HashSet<Class<?>>();
    try {
      extraClasses.add(Class.forName("org.jbpm.data.Person", true, kieContainer.getClassLoader()));
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
    }
    KieServicesClient kieServicesClient = null;
    if (TestConfig.isLocalServer()) {
      KieServicesConfiguration localServerConfig =
          KieServicesFactory.newRestConfiguration(TestConfig.getHttpUrl(), null, null)
              .setMarshallingFormat(marshallingFormat);

      localServerConfig.addJaxbClasses(extraClasses);
      kieServicesClient =
          KieServicesFactory.newKieServicesClient(localServerConfig, kieContainer.getClassLoader());
    } else {
      configuration.setMarshallingFormat(marshallingFormat);
      configuration.addJaxbClasses(extraClasses);
      configuration.setUserName("Administrator");
      kieServicesClient =
          KieServicesFactory.newKieServicesClient(configuration, kieContainer.getClassLoader());
    }
    configuration.setTimeout(5000);
    setupClients(kieServicesClient);

    return kieServicesClient;
  }
 private static void setupCustomSettingsXml() {
   if (!TestConfig.isLocalServer()) {
     String clientDeploymentSettingsXml =
         ClassLoader.class
             .getResource("/kie-server-testing-client-deployment-settings.xml")
             .getFile();
     System.setProperty(KieServerConstants.CFG_KIE_MVN_SETTINGS, clientDeploymentSettingsXml);
   }
 }
  @BeforeClass
  public static void setupClass() throws Exception {
    if (TestConfig.isLocalServer()) {

      startServer();
    }
    setupCustomSettingsXml();
    warmUpServer();
  }
 protected ClientRequest newRequest(String uriString) {
   URI uri;
   try {
     uri = new URI(uriString);
   } catch (URISyntaxException e) {
     throw new RuntimeException("Malformed request URI was specified: '" + uriString + "'!", e);
   }
   if (TestConfig.isLocalServer()) {
     return new ClientRequest(uriString);
   } else {
     CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
     credentialsProvider.setCredentials(
         new AuthScope(uri.getHost(), uri.getPort()),
         new UsernamePasswordCredentials(TestConfig.getUsername(), TestConfig.getPassword()));
     HttpClient client =
         HttpClientBuilder.create().setDefaultCredentialsProvider(credentialsProvider).build();
     ApacheHttpClient4Executor executor = new ApacheHttpClient4Executor(client);
     return new ClientRequest(uriString, executor);
   }
 }