Have a problem when run jbmp sample in eclipse - database

Coud anybody help me fix my problem? When I tried to run jbpm sample in eclipse. This is code:
public class ProcessMain {
public static void main(String[] args) {
KieServices ks = KieServices.Factory.get();
KieContainer kContainer = ks.getKieClasspathContainer();
KieBase kbase = kContainer.getKieBase("kbase");
RuntimeManager manager = createRuntimeManager(kbase);
RuntimeEngine engine = manager.getRuntimeEngine(null);
KieSession ksession = engine.getKieSession();
ksession.startProcess("com.sample.bpmn.hello");
manager.disposeRuntimeEngine(engine);
System.exit(0);
}
private static RuntimeManager createRuntimeManager(KieBase kbase) {
JBPMHelper.startH2Server();
JBPMHelper.setupDataSource();
EntityManagerFactory emf = Persistence.createEntityManagerFactory("org.jbpm.persistence.jpa");
RuntimeEnvironmentBuilder builder = RuntimeEnvironmentBuilder.Factory.get()
.newDefaultBuilder().entityManagerFactory(emf)
.knowledgeBase(kbase);
return RuntimeManagerFactory.Factory.get()
.newSingletonRuntimeManager(builder.get(), "com.sample:example:1.0");
}
}
Then, this is error in console window:
Exception in thread "main" java.lang.IllegalArgumentException: Driver class name cannot be empty.
at org.kie.test.util.db.internal.DatabaseProvider.fromDriverClassName(DatabaseProvider.java:32)
at org.kie.test.util.db.DataSourceFactory.setupPoolingDataSource(DataSourceFactory.java:57)
at org.kie.test.util.db.DataSourceFactory.setupPoolingDataSource(DataSourceFactory.java:42)
at org.jbpm.test.JBPMHelper.setupDataSource(JBPMHelper.java:103)
at com.sample.ProcessMain.createRuntimeManager(ProcessMain.java:34)
at com.sample.ProcessMain.main(ProcessMain.java:23)

jBPMHelper no longer sets default values for H2,- https://github.com/kiegroup/drools/commit/34293e9675ae4f36f2a3a9e633305bbcc8260d19
We need to use - PersistenceUtil.setupPoolingDataSource(); instead JBPMHelper.setupDataSource();
Also include datasource.properties file at resources folder.
datasource.properties - > https://github.com/kiegroup/jbpm/blob/master/jbpm-examples/src/main/resources/datasource.properties

Related

Rest Client - Can i set connectionPoolSize?

Microprofile allows to define connectionPoolSize from RestClient like this:
io.smallrye.restclient.tests.proxy.HelloClient/property/resteasy.connectionPoolSize = 4
When I set this property in my project, quarkus ignores it. How can i define it?
Create class MyRestClientBuilderListener implements RestClientBuilderListener:
package org.myproject.config
public class MyRestClientBuilderListener implements RestClientBuilderListener {
static final Logger LOG = LoggerFactory.getLogger(MgiRestClientBuilderListener.class);
static final String CONNECTION_POOL_SIZE_PROP = "config.restclient.connectionPoolSize";
#Override
public void onNewBuilder(RestClientBuilder builder) {
Config cfg = ConfigProvider.getConfig();
Integer poolSizeConnection = cfg.getValue(CONNECTION_POOL_SIZE_PROP, Integer.class);
if(poolSizeConnection == null) {
poolSizeConnection = 50;//default
}
builder.property("resteasy.connectionPoolSize", poolSizeConnection);
}
}
Create file with name org.eclipse.microprofile.rest.client.spi.RestClientBuilderListener in META-INF\services with content:
org.myproject.config.MyRestClientBuilderListener
If your configured client is #RegisterRestClient(configKey="myClient"), to set the pool size use:
quarkus.rest-client.myClient.connection-pool-size: 5
(...and not myClient/mp-rest/connectionPoolSize)

What is the use of System.getProperty() while taking Screenshot in Selenium?

I'm running a program for adding screenshot in extent report automatically using selenium. Program is running perfectly,but I want to know the meaning of System.getProperty line in below program .
public class SST
{
public static String getScreenshot(WebDriver driver)
{
TakesScreenshot ts=(TakesScreenshot) driver;
File src=ts.getScreenshotAs(OutputType.FILE);
String path = System.getProperty("user.dir")+"/Screenshot/"+System.currentTimeMillis()+".png";
File destination=new File(path);
try
{
FileUtils.copyFile(src, destination);
} catch (IOException e)
{
System.out.println("Capture Failed "+e.getMessage());
}
return path;
}
}
It is getting the user home directory, for example, C:\Users\user10796675.

How to use different webdrivers based on environment

I use selenium-jupiter. I am getting a webdriver from method arguments like this:
#Test
public void testWithChrome(ChromeDriver chromeDriver) {
chromeDriver.get("someUrlHere");
}
Now I want to run tests on grid so I need to use webdriver based on environment. For example when developing tests on my PC I want to use (local) ChromeDriver, but when running tests on grid with Jenkins, I want to use RemoteDriver.
So I need something like this: (That gives me local Chrome when env = 0 or gives me remote Chrome when env = 1 but it's not working)
int env = 0;
#Test
public void testWithChrome(
(env == 0 ? ChromeDriver driver : RemoteDriver driver)) {
driver.get("someUrlHere");
}
In short: When configuring your Selenium extension programmatically you can force usage of a Selenium Grid by configuring its URL as follows (using JUnit 5 annotations):
abstract class UiTest {
#RegisterExtension
static SeleniumExtension seleniumExtension = new SeleniumExtension();
#BeforeAll
static void setUpOnce() {
boolean isRunningInCiEnvironment = ...
if( isRunningInCiEnvironment ) {
// this will force Selenium Jupiter to use a RemoteWebDriver
seleniumExtension.getConfig().setSeleniumServerUrl("http://...");
}
// without above condition, a FirefoxDriver will be used locally
seleniumExtension.addBrowsers(BrowserBuilder.firefox().build(););
}
}
class MyTest extends UiTest {
// Use WebDriver interface in test method: concrete browser detected
// at execution time (via #BeforeAll, inherited from parent class)
#Test
void my_test_Case(WebDriver webDriver) {
webDriver.get(...)
Assert.(...)
}
}
The problem in length is decribed here.
I think what would be better here is to have a method that is executed before any test (annotated with #BeforeAll) that determines what environment the script is being run in. It probably reads from some config file local vs grid. Once that is determined, assign the driver variable either an instance of ChromeDriver or RemoteDriver. From then on, your tests will pass around the driver instance which will be of type WebDriver because both ChromeDriver and RemoteDriver inherit from it.
WebDriver driver;
#BeforeAll
public void setup()
{
// read from config file, etc. to determine if local or grid
if (local)
{
driver = new ChromeDriver();
}
else
{
driver = new RemoteDriver();
}
}
#Test
public void test()
{
driver.get("someUrlHere");
}
You can do that with WebDriverManager that comes with this extension.
#BeforeEach
public void setUp()
{
switch(browser)
{
case "chrome" ->
{
WebDriverManager.chromedriver().setup();
driver = new ChromeDriver();
}
case "firefox" ->
{
WebDriverManager.firefoxdriver().setup();
driver = new FirefoxDriver();
}
case "edge" ->
{
WebDriverManager.edgedriver().setup();
driver = new EdgeDriver();
}
}
driver.manage().window().maximize();
}

Strange behaviour in code exection in java

I face strange execution behaviors in login test methods. I run this code Under selenium Grid. and Grid is configured as a standalone server. So, first I start the selenium grid(Hub\Node) using the batch file to execute by tests.
Following is my class and specs.
code:
1. pojDataSource.java:
public class pojDataSource {
private static WebElement element = null;
private static List<WebElement> elements = null;
public static WebElement txt_UserName(WebDriver driver){
driver.findElement(By.id("txtUserName")).clear();
element = driver.findElement(By.id("txtUserName"));
return element;
}
public static WebElement txt_Password(WebDriver driver){
driver.findElement(By.id("txtPassword")).clear();
element = driver.findElement(By.id("txtPassword"));
return element;
}
}
clsConstant.java:
public class clsConstant {
public static final String URL = "http://localhost:1234/";
public static final String Username = "username";
public static final String Password = "password";
}
ModuleTest.java:
public class ModuleTest {
public RemoteWebDriver mDriver = null;
public DesiredCapabilities mCapability = new DesiredCapabilities() ;
public WebElement mWebElement = null;
public String mBaseURL = clsConstant.URL;
public static clsExcelSampleData mAddConnectorXls;
#Test
public void beforeMethod() throws Exception {
WebDriverWait wdw =null;
mCapability.setCapability("platform", org.openqa.selenium.Platform.WINDOWS);
mCapability = DesiredCapabilities.firefox();
mCapability.setVersion("45.0.2");
mDriver = new RemoteWebDriver(new URL("http://127.0.0.1:4444/wd/hub/"), mCapability);
mDriver.get(mBaseURL);
mDriver.manage().window().maximize();
pojDataSource.txt_UserName(mDriver).sendKeys(clsConstant.Username ) ;
pojDataSource.txt_Password(mDriver).sendKeys(clsConstant.Password ) ;
pojDataSource.btn_LogIn(mDriver).click();
}
When I execute the code in DEBUG mode in eclipese IDE it shows me the strange behaviors. First it start browser and open the mBaseURL successful with login screen. After loading page it shows default userName\password in browser.
Now when debug point comes to pojDataSource.txt_UserName(mDriver).sendKeys(clsConstant.Username ); line. By pressing F5 my debug point goes to pojDataSource.txt_Password(); line and it fetch wrong password and script execution fails. I worry about how this will be happens if my debug point is at username but still it goes to fetch value of password?
Tried solutions:
1. As I use Firefox browser to run test. I clear my password from browser catch.
Recheck the WebElements IDs and make sure they are reachable by WebDriver while debugging. Also try to avoid using 'static' to WebElements. Take a look on Page Objects Pattern.

Custom HighRepJobPolicy in Google App Engine development server

I am using a custom HighRepJobPolicy in the App Engine development server. The same class works fine when I use it in my unit tests:
LocalDatastoreServiceTestConfig datastoreConfig = new LocalDatastoreServiceTestConfig();
datastoreConfig.setAlternateHighRepJobPolicyClass(CustomHighRepJobPolicy.class);
But when I try to use this class in the Java development server by adding the JVM tag
-Ddatastore.high_replication_job_policy_class=foo.bar.CustomHighRepJobPolicy
I get a ClassNotFoundException:
Caused by: java.lang.ClassNotFoundException: foo.bar.CustomHighRepJobPolicy
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at com.google.appengine.tools.development.DevAppServerClassLoader.loadClass(DevAppServerClassLoader.java:87)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:186)
at com.google.appengine.api.datastore.dev.LocalDatastoreService.initHighRepJobPolicy(LocalDatastoreService.java:426)
... 66 more
Is this expected to work, or has anyone else tried this before? I ask because I could not find any information about this via Google, and the App Engine docs only mention the DefaultHighRepJobPolicy.
Looks like you were early to the party :
public class LocalCustomPolicyHighRepDatastoreTest {
private static final class CustomHighRepJobPolicy implements HighRepJobPolicy {
static int count = 0;
#Override
public boolean shouldApplyNewJob(Key entityGroup) {
// every other new job fails to apply
return count++ % 2 == 0;
}
#Override
public boolean shouldRollForwardExistingJob(Key entityGroup) {
// every other existing job fails to apply
return count++ % 2 == 0;
}
}
private final LocalServiceTestHelper helper =
new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig()
.setAlternateHighRepJobPolicyClass(CustomHighRepJobPolicy.class));
#Before
public void setUp() {
helper.setUp();
}
#After
public void tearDown() {
helper.tearDown();
}
#Test
public void testEventuallyConsistentGlobalQueryResult() {
DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
ds.put(new Entity("yam")); // applies
ds.put(new Entity("yam")); // does not apply
// first global query only sees the first Entity
assertEquals(1, ds.prepare(new Query("yam")).countEntities(withLimit(10)));
// second global query sees both Entities because we "groom" (attempt to
// apply unapplied jobs) after every query
assertEquals(2, ds.prepare(new Query("yam")).countEntities(withLimit(10)));
}
}

Resources