AspectJ - pointcut with dynamic value - aspectj

Is it possible doing something like this?
private static final String PACKAGE = System.getProperty("packagePrefix", "org.company_name");
#Around("execution(* "+PACKAGE+"..*.*(..)) && #annotation(validate)")

Unfortunately, no. This is not possible since the compiler/weaver must know exactly what will be woven at compile time. Using compile time weaving, pointcuts may not change across restarts of the application.

Related

In Katalon Studio, How to retrieve the values using the javascript executor. document.getElementsByTagName('input')[29].value

enter image description here
I tried below code but not works.
a = WebUI.executeJavaScript('document.getElementsByTagName("input")[29].value', null)
Thread.sleep(5000)
System.out.println(a)
There is so much wrong with this question that I don't even know where to begin...
What are you trying to accomplish by using JavaScript (this is a testing code smell, for 99% of testing cases) to fetch a value ?
Why not do the following:
create a TestObject, preferably in the Object Repository, that points to the object in question.
give that Test Object the locator. This is, by default, some xpath.
In your case, give it xpath
(//input)[29]
. However, I advise you come up with a more meaningful selector for it (for example, select it by some class, data-* attribute, name) that is easier to maintain
use the built-in Keyword for getting attribute, like this:
WebUI.getAttribute(findTestObject('[whateverYourTestObjectNameIs]'), 'value')
this is just good code design, but write this to some Custom Keyword for this util:
// import statements here. Ctrl + Shift + O on your keyboard to bring those in
public final class GeneralWebUIUtils {
public static final String Value = "value";
public static final String GetValue(TestObject to) {
return WebUI.getAttribute(to, this.Value);
}
}
Also, why are you pausing runtime by some hard-coded time amount? That is a testing code smell. Stop it!
What exactly are you waiting on? Use the WebUI keywords for this thing you are waiting on, and if none of those suffice, hmu and I may have the wait method you're looking for ....
Oh, and looking at that image you linked, it looks like you solved your own question.

Method refactor in Intellij Idea and/or Eclipse

I have many classes (45 at least). Each one has its own method to validate something that is repeated in all the classes, so I have the code repeated in all those classes. I'd like to have one method and call it from all the classes.
If have the following code to know if a mobile device is connecting to the server
private boolean isMobileDevice(HttpServletRequest request) {
String userAgent = request.getHeader("user-agent");
return userAgent.indexOf("Windows CE") != -1;
}
As said before, This method is repeated in many classes
Is it possible in Intellij Idea and/or Eclipse to do that refactor? and How can I perform that refactor?
private boolean isMobileDevice(HttpServletRequest request) {
String userAgent = request.getHeader("user-agent");
return userAgent.indexOf("Windows CE") != -1;
}
I bet that my Eclipse will warn me that this method can be declared as static, because it does not use any fields of enclosing class - such method should be declared as static to let you know that it is not essentially needed in enclosing class, and if there will be a reason (having 45 methods in place of one is THE REASON) you can move it to some other class, and just call it as public or package method.
EDIT: It did: The method isMobileDevice(HttpServletRequest) from the type Test can be declared as static:
So:
Copy it to some other class, make it public static boolean isMobileDevice(HttpServletRequest request) and use in every classes where it was private boolean.
That's all, but I don't see and way to make it with automatic refactor.
With Intellij you could try "Refactor" > "Find and Replace Code Duplicates...".
It will replace the duplicate code by a static function.

GWT Deferred binding failed for custom class: No class matching "..." in urn:import:

I am developing a couple of custom widgets that I would like to be able to use with UiBinder. Unfortunately I keep wasting my life away with chasing down the following error:
No class matching "..." in urn:import:...
This seems to be the catch-all exception that is thrown any time there is any error in the class that prevents the GWT compiler from processing it. This includes anything in the class's entire dependency tree.
To save myself and anyone of you who is running into the same issue some time and pain, let's compile a list here of the most unexpected and hard to find causes for this. I'll start with my latest one, which has made me decide to post this here.
I was using a CellList thusly:
private static RelationshipViewerUiBinder uiBinder = GWT.create(RelationshipViewerUiBinder.class);
#UiField(provided=true)
CellList<String> prioritisedDisplay;
public RelationshipViewer() {
prioritisedDisplay = new CellList<>(new TextCell());
initWidget(uiBinder.createAndBindUi(this));
}
note the Java 7 style <> on the CellList. Despite my IDE's protestations to the contrary, it turns out you DO need to explicitly say CellList< String> in that new call, or it wont compile and all you get is the above mentioned error. Thanks by the way, the existance of this question prompted me to scrutinise my code and probably saved me a couple of hours! This fixed it:
private static RelationshipViewerUiBinder uiBinder = GWT.create(RelationshipViewerUiBinder.class);
#UiField(provided=true)
CellList<String> prioritisedDisplay;
public RelationshipViewer() {
prioritisedDisplay = new CellList<String>(new TextCell());
initWidget(uiBinder.createAndBindUi(this));
}
I had written a component that used the GWT JSON functionality, but hadn't imported com.google.gwt.json.JSON into the module.
Thanks to your message here, this was only 2 hours down the drain...
I wrote a helper-class that this widget uses somewhere deep inside its dependency tree.
For this helper-class, I told Eclipse to auto-generate the hashCode() and equals(...) functions. The class contained a field of type double, for which Eclipse generates code that uses Double.doubleToLongBits().
Turns out GWT does not implement this method on its version of Double. But of course, neither does Eclipse detect this as a possible compile-error, nor does it cause any issues in Dev Mode if I use the widget inside the GWT-App's Java code rather than inside UiBinder.
3 hours down the drain... Great... Yay for helpful error messages.
UPDATE:
As of GWT 2.5.0 (RC1) GWT now supports Double.doubleToLongBits() rendering this particular error obsolete, but the general error mechanism of a missing JRE emulation remains and will probably manifest itself in a similarly unhelpful way.
I was trying to use a GwtQuery DragAndDropCellTree in a UiBinder .ui.xml, which was impossible as DragAndDropCellTree has no zero-arg constructor.
See more details

How do you handle instantiation of Messages classes in GWT?

I have a question on how you usually instantiate GWT Messages. I usually do this:
private static final GenericMessages GENERIC_MESSAGES = GWT.create(GenericMessages.class);
I usually do this in every class that uses the GenericMessages Interface, is this a nice thing to do, or should I create a MessagesSingleton that instantiates all my Messages interface and I just access it from there?
Thanks in advance.
You don't have to worry about it. The GWT compiler will replace all your GENERIC_MASSAGES inside the code.
Example:
If you have in your propert file:
applicationName=My Application
and in your java class like this:
label.setText(GENERIC_MESSAGES.applicationName());
in compilation time the gwt compiler will replace to
label.setText("My Application");
and will remove your variable.

Why can't I have static public fields in my managed beans?

I just started using the Netbeans 7.1 beta and it is calling out errors of a type which I have never seen before. Specifically:
A managed bean with a public field should not declare any scope other than #Dependent.
The fields it is complaining about are public static final. I can understand the restriction on non-static fields, but I can't think of a good reason this would not be allowed for a static field. Unfortunately I use a lot of them since I don't like having constants in my code.
I note that even though I get the red dot in the margin in the editor, the maven-driven build still works and GlassFish still runs my application the way I would expect.
So what is my denoument on this issue? Am I going to have to move my static fields elsewhere or is there another way of handling this?
Quoting the javax.enterprise.inject package javadocs:
If a managed bean has a public field, it must have scope #Dependent.
But I do agree wih #BalusC that if this compiles, Netbeans should report it as Warning (does it?).
Anyway, are those constants really part of the API? I mean, do you access they anywhere else but within their own classes? If not, reduce visibility to private. (If you just need to access the constants from the view you can also create accessors for the private constant). If yes, I would suggest you to move them somewhere else anyway.
Public fields (static or not) aren't proxyable - that's why they can only be dependent scoped. To work around this you obviously can access them through getter methods.