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; }
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"); } }
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); } }
private static void startServer() throws Exception { System.setProperty( "java.naming.factory.initial", "bitronix.tm.jndi.BitronixInitialContextFactory"); System.setProperty(KieServerConstants.CFG_BYPASS_AUTH_USER, "true"); System.setProperty(KieServerConstants.CFG_HT_CALLBACK, "custom"); System.setProperty( KieServerConstants.CFG_HT_CALLBACK_CLASS, "org.kie.server.integrationtests.jbpm.util.FixedUserGroupCallbackImpl"); System.setProperty(KieServerConstants.CFG_PERSISTANCE_DS, "jdbc/jbpm-ds"); System.setProperty( KieServerConstants.CFG_PERSISTANCE_TM, "org.hibernate.service.jta.platform.internal.BitronixJtaPlatform"); server = new TJWSEmbeddedJaxrsServer(); server.setPort(TestConfig.getAllocatedPort()); server.start(); KieServerEnvironment.setServerId( "target/" + KieServerBaseIntegrationTest.class.getSimpleName() + "@" + serverIdSuffixDateFormat.format(new Date())); server.getDeployment().getRegistry().addSingletonResource(new KieServerRestImpl()); KieServerImpl kieServer = KieServerLocator.getInstance(); List<KieServerExtension> extensions = kieServer.getServerExtensions(); for (KieServerExtension extension : extensions) { List<Object> components = extension.getAppComponents(SupportedTransports.REST); for (Object component : components) { server.getDeployment().getRegistry().addSingletonResource(component); } } server .getDeployment() .setProviderFactory(JacksonRestEasyTestConfig.createRestEasyProviderFactory()); }
protected static KieServicesConfiguration createKieServicesJmsConfiguration() { try { InitialContext context = TestConfig.getInitialRemoteContext(); Queue requestQueue = (Queue) context.lookup(TestConfig.getRequestQueueJndi()); Queue responseQueue = (Queue) context.lookup(TestConfig.getResponseQueueJndi()); ConnectionFactory connectionFactory = (ConnectionFactory) context.lookup(TestConfig.getConnectionFactory()); KieServicesConfiguration jmsConfiguration = KieServicesFactory.newJMSConfiguration( connectionFactory, requestQueue, responseQueue, TestConfig.getUsername(), TestConfig.getPassword()); return jmsConfiguration; } catch (Exception e) { throw new RuntimeException("Failed to create JMS client configuration!", e); } }
protected static KieServicesConfiguration createKieServicesRestConfiguration() { return KieServicesFactory.newRestConfiguration( TestConfig.getHttpUrl(), TestConfig.getUsername(), TestConfig.getPassword()); }