Unable to select Combobox option using TestStack white - teststack

Using the below code to select Combobox Option. Combo box is clicked but option is not selected.
window.Get<ComboBox>(SearchCriteria.ByAutomationId("cbotire")).Select("Three");

public static bool TrySelect(ComboBox combo, string val)
{
TryCollapse(combo.AutomationElement);
try
{
TryExpand(combo.AutomationElement);
Thread.Sleep(200);
combo.Select(val);
TryCollapse(combo.AutomationElement);
}
catch (Exception e) { }
if (combo.SelectedItemText == candidate)
{
TryCollapse(combo.AutomationElement);
return true;
}
TryCollapse(combo.AutomationElement);
return false;
}
public static void TryCollapse(AutomationElement ae)
{
object invoke;
if (ae.TryGetCurrentPattern(ExpandCollapsePattern.Pattern, out invoke))
{
try
{
(invoke as ExpandCollapsePattern).Collapse();
}
catch (Exception e) { }
}
}
public static void TryExpand(AutomationElement ae)
{
object invoke;
if (ae.TryGetCurrentPattern(ExpandCollapsePattern.Pattern, out invoke))
{
try
{
(invoke as ExpandCollapsePattern).Expand();
}
catch (Exception e) { }
}
}

Related

Custom annotation Quarkus

We are building the following method that copies values from one entity to another and then persists the changes which works fine for us.
private void copyProperties(E orig, E dest) {
try {
for (Field origField : orig.getClass().getDeclaredFields()) {
try {
origField.setAccessible(true);
Object value = origField.get(orig);
if (value != null) {
Field destField = dest.getClass().getDeclaredField(origField.getName());
destField.setAccessible(true);
destField.set(dest, value);
}
} catch (IllegalAccessException | NoSuchFieldException ex) {
System.out.println("IllegalAccessException ");
ex.printStackTrace();
}
}
} catch (SecurityException ex) {
System.out.println("SecurityException ");
ex.printStackTrace();
}
}
But now we need to update only the properties that have present a specific annotation called #updatable.
#Documented
#Target({ElementType.FIELD, ElementType.TYPE_USE})#Retention(RetentionPolicy.RUNTIME)public #interface Updatable {
#Nonbindingboolean nullable() default false;
}
private void copyProperties(E orig, E dest) {
try {
for (Field origField : orig.getClass().getDeclaredFields()) {
Updatable annotation = origField.getAnnotation(Updatable.class);
if (annotation != null) {
System.out.println("Field "+origField.getName()+" annotation present");
try {
origField.setAccessible(true);
Object value = origField.get(orig);
if (value != null || annotation.nullable()) {
Field destField = dest.getClass().getDeclaredField(origField.getName());
destField.setAccessible(true);
destField.set(dest, value);
}
} catch (IllegalAccessException | NoSuchFieldException ex) {
System.out.println("IllegalAccessException ");
ex.printStackTrace();
}
}
}
} catch (SecurityException ex) {
System.out.println("SecurityException ");
ex.printStackTrace();
}
}
The problem is that when we analyze the annotation and return by reference the destination entity with the updated properties, the merge method in quarkus does not detect the changes.

Get queue size of ThreadPoolTaskExecutor and add to queue in Spring boot

I have the following class which has multiple custom ThreadPoolTaskExecutors I am showing it with one in this example.
#Configuration
#EnableAsync
public class ExecutorConfig {
#Bean(name = "streetCheckerExecutor")
public Executor getStreetAsyncExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(50);
executor.setQueueCapacity(1000000);
executor.setThreadNamePrefix("streetCheckerExecutor-");
executor.initialize();
return executor;
}
}
I have the following class which gets content from the database, I want to be able to check the queue size of streetCheckerExecutor and if it's less than a certain number, to add the content to the queue
#Component
public class StreetChecker {
#Autowired
StreetRepository streetRepository;
#Autowired
StreetCheckService streetChecker;
#EventListener(ApplicationReadyEvent.class)
public void checkStreets() {
try {
List<Street> streetList = streetRepository.getStreets();
for (int i = 0; i < streetList.size(); i++) {
streetChecker.run(streetList.get(i));
}
} catch (Exception e) {
e.printStackTrace();
} finally {
System.out.println("---------------------");
}
}
}
And below is the worker class
#Component
public class StreetCheckService {
#Async("streetCheckerExecutor")
public void run(Content content) {
try {
//do work
} catch (Exception e) {
e.printStackTrace();
} finally {
}
}
}
I am working with a lot of data and I don't want to grab everything from the database every time, but I want to check the queue size of streetCheckerExecutor and if it's less than a number, I want to get more content from the database and add it to the streetCheckerExecutor queque
Below is how I'm thinking I can do it by converting the above checkStreets to the one below
#EventListener(ApplicationReadyEvent.class)
public void checkStreets() {
while (true) {
try {
// check the queue size of streetCheckerExecutor
// if less than a number
// add to the queue
// else keep waiting and will try again in X minutes
} catch (Exception e) {
} finally {
try {
Thread.sleep(1000 * 60);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
But how would I be able to get the size of the queue in the checkStreets() method?
You can just autowire in your ThreadPoolTaskExecutor and get the queue with getThreadPoolExecutor().getQueue().
#Autowire
#Qualifier("streetCheckerExecutor")
private Executor streetExecutor;
#EventListener(ApplicationReadyEvent.class)
public void checkStreets() {
while (true) {
try {
final BlockingQueue<Runnable> queue = streetExecutor.getThreadPoolExecutor().getQueue();
if(queue.size() <= 5) {
queue.add(() -> {
final List<Street> streetList = streetRepository.getStreets();
streetList.forEach(street -> {
streetChecker.run(street);
});
});
}
} catch (Exception e) {
} finally {
try {
Thread.sleep(1000 * 60);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
i'm not sure this is what you meant, but something like this maybe.

Callbacks are not been called

I'm writing an app with Tango and getting a strange bug.
My program successfully connected to the tango service,and i have setup a callback with "mTango.connectListener(framePairs, new Tango.TangoUpdateCallback() {...});",but i can not get any tango datas because the callback have never been called.
here is my main code
private void bindTangoService() {
Log.d(TAG, "正在绑定Tango 服务");
if (mIsConnected) {
return;
}
mTango = new Tango(mContext, new Runnable() {
#Override
public void run() {
synchronized (TangoAR.this) {
try {
mConfig = setupTangoConfig(mTango, false, false);
mTango.connect(mConfig);
startupTango();
TangoSupport.initialize(mTango);
mIsConnected = true;
onRotationUpdated(Util.getDisplayRotation(mContext));
makeToast("tango 连接成功");
Log.d(TAG, "tango 连接成功");
} catch (TangoOutOfDateException e) {
makeToast("TangoOutOfDateException");
} catch (Throwable e) {
makeToast(e.getMessage());
}
}
}
});
}
private TangoConfig setupTangoConfig(Tango tango, boolean isLearningMode, boolean isLoadAdf) {
Log.d(TAG, "setupTangoConfig");
TangoConfig config = tango.getConfig(TangoConfig.CONFIG_TYPE_DEFAULT);
//在tango连接后使用相机必须使用true
config.putBoolean(TangoConfig.KEY_BOOLEAN_COLORCAMERA, false);
//motion
config.putBoolean(TangoConfig.KEY_BOOLEAN_MOTIONTRACKING, true);
config.putBoolean(TangoConfig.KEY_BOOLEAN_AUTORECOVERY, true);
config.putBoolean(TangoConfig.KEY_BOOLEAN_DRIFT_CORRECTION, true);
//depth
config.putBoolean(TangoConfig.KEY_BOOLEAN_DEPTH, true);
config.putBoolean(TangoConfig.KEY_BOOLEAN_LOWLATENCYIMUINTEGRATION, true);
config.putInt(TangoConfig.KEY_INT_DEPTH_MODE, TangoConfig.TANGO_DEPTH_MODE_POINT_CLOUD);//使用点云,不使用老版本的TANGO_DEPTH_MODE_XYZ_IJ
//area learning
if (isLearningMode) {
//区域学习需要权限授权
if (checkAndRequestTangoPermissions(Tango.PERMISSIONTYPE_ADF_LOAD_SAVE)) {
Log.d(TAG, "PERMISSIONTYPE_ADF_LOAD_SAVE 开启");
config.putBoolean(TangoConfig.KEY_BOOLEAN_LEARNINGMODE, true);
}
}
if (isLoadAdf) {
//加载ADF
ArrayList<String> fullUuidList;
fullUuidList = tango.listAreaDescriptions();
if (fullUuidList.size() > 0) {
config.putString(TangoConfig.KEY_STRING_AREADESCRIPTION,
fullUuidList.get(fullUuidList.size() - 1));
}
}
return config;
}
private void startupTango() {
Log.d(TAG, "startupTango");
ArrayList<TangoCoordinateFramePair> framePairs = new ArrayList<>();
//设置参考系,0,0,0点为tango服务启动时设备的位置,测量目标为设备的位置
Log.d(TAG, "startup");
framePairs.add(new TangoCoordinateFramePair(
TangoPoseData.COORDINATE_FRAME_START_OF_SERVICE,
TangoPoseData.COORDINATE_FRAME_DEVICE));
Log.d(TAG, "startup-listener");
mTango.connectListener(framePairs, new Tango.TangoUpdateCallback() {
#Override
public void onPoseAvailable(final TangoPoseData pose) {
//motion
Log.d(TAG, "onPoseAvailable");
//获取手机新的状态
mTangoTime = pose.timestamp;
TangoPoseData poseData = TangoSupport.getPoseAtTime(
mTangoTime,
TangoPoseData.COORDINATE_FRAME_START_OF_SERVICE,
TangoPoseData.COORDINATE_FRAME_CAMERA_COLOR,
TangoSupport.ENGINE_OPENGL,
TangoSupport.ENGINE_OPENGL,
mDisplayRotation);
if (poseData.statusCode == TangoPoseData.POSE_VALID) {
mTangoPoseData = poseData;
}
}
#Override
public void onPointCloudAvailable(TangoPointCloudData pointCloud) {
//记录当扫描到到的深度信息
mPointCloudManager.updatePointCloud(pointCloud);
Log.d(TAG, "depth size:" + pointCloud.numPoints);
}
#Override
public void onXyzIjAvailable(TangoXyzIjData xyzIj) {
Log.d(TAG, "onXyzIjAvailable");
}
#Override
public void onFrameAvailable(int cameraId) {
Log.d(TAG, "onFrameAvailable");
}
#Override
public void onTangoEvent(TangoEvent event) {
Log.d(TAG, event.eventValue);
}
});
Log.d(TAG, "startup-listener-end");
}
mTango.connect(mConfig); execute successfully and without any exception.
I have been plagued by this problem for three days.I need a hero.Thanks everyone.
Notes:The rear camera is not be used for tango because i use it elsewhere.
I had the same problem. For me the solution was to request permissions:
startActivityForResult(
Tango.getRequestPermissionIntent(Tango.PERMISSIONTYPE_MOTION_TRACKING),
Tango.TANGO_INTENT_ACTIVITYCODE);

Spring Jpa Specification and Eager loading

How can i get list of tiket with its categories through Jpa Specification
Example model:
#Entity
#Table(name = "tickets")
public class Ticket {
#Id
private Integer id;
#ManyToOne(fetch = FetchType.LAZY)
#JoinColumn(name = "category_id")
private Category
}
Method of service:
public Page<Ticket> findAll(Pageable pageable) {
return ticketRepository.findAll((root, query, cb) -> {
root.join("category");
return query.getRestriction();
}, pageable);
}
I was able to eager load the collection by using a fetch instead of a join.
public Page<Ticket> findAll(Pageable pageable) {
return ticketRepository.findAll((root, query, cb) -> {
root.fetch("category");
return query.getRestriction();
}, pageable);
}
The fetch method will use the default join type (inner). If want to load tickets with no category, you'll have to pass JoinType.LEFT as the second parameter.
as they say, stackoverflow giveth, stackoverflow taketh..
I took this class off SO quite some time ago, feel free to recycle it..
import java.beans.PropertyDescriptor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Collection;
import org.apache.commons.beanutils.PropertyUtils;
import org.hibernate.Hibernate;
public class BeanLoader {
/**
* StackOverflow safe, if called before json creation, cyclic object must be avoided
*/
public static void eagerize(Object obj) {
if(!Hibernate.isInitialized(obj))
Hibernate.initialize(obj);
PropertyDescriptor[] properties = PropertyUtils.getPropertyDescriptors(obj);
for (PropertyDescriptor propertyDescriptor : properties) {
Object origProp = null;
try {
origProp = PropertyUtils.getProperty(obj, propertyDescriptor.getName());
} catch (IllegalAccessException e) {
// Handled, but hopefully dead code
origProp=null;
} catch (InvocationTargetException e) {
// Single catch for obsolete java developers!
origProp=null;
} catch (NoSuchMethodException e) {
// Single catch for obsolete java developers!
origProp=null;
}
if (origProp != null
&& origProp.getClass().getPackage().toString().contains("domain")) {
eagerize(origProp, new ArrayList<String>());
}
if (origProp instanceof Collection) {
for (Object item : (Collection) origProp) {
if (item.getClass().getPackage().toString().contains("domain")){
eagerize(item, new ArrayList<String>());
}
}
}
}
}
/**
* StackOverflows if passed a bean containing cyclic fields. Call only if sure that this won't happen!
*/
public static void eagerizeUnsafe(Object obj) {
if(!Hibernate.isInitialized(obj))
Hibernate.initialize(obj);
PropertyDescriptor[] properties = PropertyUtils.getPropertyDescriptors(obj);
for (PropertyDescriptor propertyDescriptor : properties) {
Object origProp = null;
try {
origProp = PropertyUtils.getProperty(obj, propertyDescriptor.getName());
} catch (IllegalAccessException e) {
// Handled, but hopefully dead code
origProp=null;
} catch (InvocationTargetException e) {
// Single catch for obsolete java developers!
origProp=null;
} catch (NoSuchMethodException e) {
// Single catch for obsolete java developers!
origProp=null;
}
if (origProp != null
&& origProp.getClass().getPackage().toString().contains("domain")) {
eagerize(origProp);
}
if (origProp instanceof Collection) {
for (Object item : (Collection) origProp) {
if (item.getClass().getPackage().toString().contains("domain")){
eagerize(item);
}
}
}
}
}
private static void eagerize(Object obj, ArrayList<String> visitedBeans) {
if (!visitedBeans.contains(obj.getClass().getName())){
visitedBeans.add(obj.getClass().getName());
} else {
return;
}
if(!Hibernate.isInitialized(obj))
Hibernate.initialize(obj);
PropertyDescriptor[] properties = PropertyUtils.getPropertyDescriptors(obj);
for (PropertyDescriptor propertyDescriptor : properties) {
Object origProp = null;
try {
origProp = PropertyUtils.getProperty(obj, propertyDescriptor.getName());
} catch (IllegalAccessException e) {
// Handled, but hopefully dead code
origProp=null;
} catch (InvocationTargetException e) {
// Single catch for obsolete java developers!
origProp=null;
} catch (NoSuchMethodException e) {
// Single catch for obsolete java developers!
origProp=null;
}
if (origProp != null
&& origProp.getClass().getPackage().toString().contains("domain")) {
eagerize(origProp, visitedBeans);
}
if (origProp instanceof User){
((User) origProp).setRelatedNra(null);
User u=(User) origProp;
if (u.getRelatedMps()!=null)
u.getRelatedMps().clear();
if (u.getRelatedDps()!=null)
u.getRelatedDps().clear();
}
if (origProp instanceof Collection) {
for (Object item : (Collection) origProp) {
if (item.getClass().getPackage().toString().contains("domain")){
eagerize(item, (ArrayList<String>) visitedBeans.clone());
}
}
}
}
}
}
modify it as you see fit.. the method you'll call is "eagerizeUnsafe".
YMMV, but this should to the trick to eagerize all the collections of a lazily initialized bean.

how to create a image slideshow for blackberry?

what i am trying to do is that on click of a button in screen1, i try push the screen2 repeatedly with different images and different Transition Context.
the code is as follows
public void fieldChanged(Field field, int context)
{
if(field==slideButton)
{
for(int i=0;i<bitmaps.length;i++)
{
slideScreen = new SliderScreen(bitmaps[i]);
UiApplication.getUiApplication().pushScreen(slideScreen);
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
UiApplication.getUiApplication().popScreen(slideScreen);
}
}
}
}
Problem is that nothing appears.Is there any other way to achieve this..
Fixed version of your initial idea:
public void fieldChanged(Field field, int context) {
if (field==slideButton) {
final UiApplication app = UiApplication.getUiApplication();
new Thread(new Runnable() {
public void run() {
for (int i = 0; i < bitmaps.length; i++) {
final SliderScreen slideScreen =
new SliderScreen(bitmaps[i]);
app.invokeAndWait(new Runnable() {
public void run() {
app.pushScreen(slideScreen);
}
});
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
app.invokeAndWait(new Runnable() {
public void run() {
app.popScreen(slideScreen);
}
});
}
}
}).start();
}
}
Your code did not work because the UI thread was sleeping between push and pop, so it has no time/chance to start drawing the screen. Note I moved the entire action into a separate thread. So now the main UI thread has free time to actually make drawing.

Resources