JavaService and QTP - java

Can I test/call a Java Service from QTP and how?

You could look into the QTP Service Test add-in which is used for testing "non GUI-based services."

You can also test directly from VBScript in QTP, without the Service Test add-in. See this SQAForums post.

To call the jar file:
To call the jar file, you can use QTP’s SystemUtil.Run like this:
SystemUtil.Run “cmd”,”/c java -jar parsingclass.jar”,””
To call the java class:
For a java class you would do something like this:
SystemUtil.Run “cmd”,”/K java D:\HL7Parser\bin\CORUExtractorFlow1151.class”,””
Explanation About the Code:
SystemUtil Object is a QTP object that can be used to control an application or process during a test run.
The Run method runs a file or application. cmd starts a new instance of a command interpreter.
/K is a parameter that runs the command and leaves the command window open. (If you want to close the command window instead of keeping it open, you would need to replace the /K parameters with the /C parameter.) For more info on CMD and its parameters, check out Microsoft’s documentation website
For move complicate Java calls
If you have a more complicated Java DLL that you need to interact with, you could use Service Test 11, which contains a call java class activity. With a “Unified Functional license ,” you could call Service Test from QTP; in our case, however, this would have been overkill, so we kept it simple by using the method described above.

Related

How to pass system system properties from jruby to Rails server

I'm running a local Rails server (WEBrick) via JRuby and want to test some code that will eventually be running on Torquebox. I'm trying to access some custom Java system properties via ENV_JAVA. These system properties will be available when running on Torquebox so to test my code locally, I'm passing in the system properties on the command line using the "-J" argument.
When I run just JRuby, everything works fine, I can access my custom property.
C:\jruby\jruby-1.7.24\bin\jruby.exe -J-Dmy_prop=my_value -e "puts ENV_JAVA['my_prop']"
This simply prints "my_value" to output.
My problem is trying access these custom properties when running a local Rails server. My command line to startup the local Rails server looks something like this:
C:\jruby\jruby-1.7.24\bin\jruby.exe -J-Dmy_prop=my_value C:\jruby\jruby-1.7.24\bin\rails s
When WEBrick starts up, my custom property "my_prop" is no longer in ENV_JAVA. It looks like this is because inside the railties Rails::AppRailsLoader module, exec_app_rails simply replaces the current process with another one by calling the Kernel exec method and passing in the command arguments.
This does NOT keep the custom properties around. Does anyone know how I can work around this? I'm currently running Rails 4.2.6. It looks like in Rails 5 the module name changed to Rails::AppLoader.
So I figured out a better(?) way to handle this. Instead of:
exec RUBY, exe, *ARGV
I can do this:
custom_sys_props = {}
current_sys_props = ENV_JAVA.to_hash
default_sys_props = eval(%x(#{RUBY} -e "puts ENV_JAVA"))
current_sys_props.each {|k,v| custom_sys_props[k] = v if default_sys_props[k] != v }
jruby_props = []
custom_sys_props.each{|k,v| jruby_props << "-J-D#{k}=#{v}"}
exec RUBY, *jruby_props, exe, *ARGV
Its ugly and really only works for JRuby, but I dont know of a better way to handle it. Still a shame that this hasn't been addressed before
After discussing with a colleague, turns out I can run my rails server by calling
jruby.exe -J-Dmy_prop=my_value script/rails
from within my project directory. So I dont even need to run the rails.bat script. Hope this helps someone

How to call a shell script from UI with out App server and web server?

I have a shell script and argument as a date. I'm looking for some help in design, where I will have to create a UI and pass the date, so that it will call the shell script with an argument (it should open unix terminal and call the shell script with username and password). The whole shell script runs on LINUX server. I would preferably be on MarkLogic/Java/Unix and Scala. I should not use web server in my application.
Can someone please suggest how to call the shell script from Java application with out using an Appserver/Webserver.
I find your actual question quite confusing and even more so after your clarification to nhouser9.
What I interpret is :
1) You need a user interface (but not a terminal?)
- Your simple need may be addressed with the tried and true old timer Java Abstract Windows Toolkit (AWT). Have a look at the wikipedia page: https://en.wikipedia.org/wiki/Abstract_Window_Toolkit
The sample code there compiles into a very simple Hello World GUI. (Java package info here: https://docs.oracle.com/javase/8/docs/api/java/awt/package-summary.html)
2) You need to call a shell script from Java:
Then for this part of the question, have a look at nhouser9's original comment. That answer can be found here: calling-shell-script-from-java The heart of this is ProcessBuilder
Add 1 and 2 together and you can create a GUI to take a parameter and then execute a shell script.

Java: How to detach from console?

Given the source code of a Java application with a GUI
when I compile it
and invoke it from the command line
then I would like it to run the GUI
and detach from the console it was invoked on, so I could resume typing there.
How can I modify the source code to achieve this?
An example of this behaviour - though not a Java program - would be ReKonq.
Note: I want to achieve this independent of the OS, i.e. I do not want to change the way I invoke it, but modify my public static von main(String[] args) method.
You can launch it from the command line with a & at the end of the line to run it in background :
java MyApplication &
If it is already launched, you can press ctrl + z and then type bg to get the same result.
(Assuming your are on Linux)
I don't think you can achieve this with pure Java, because in the end Java is just another process to the operating system you're on. As you want to avoid OS specific details, you may consider using a Java service wrapper. Some Apache software too use this, one that I'm aware of is this service wrapper.

How can I run my Java program with a set "name" in the command line?

I'm very new to all Java related programming. For a school assignment, I've created my Java application using BlueJ. Apparently, the application should be able to run from the command prompt with the following line:
myapp -compress fileName
Honestly, I don't have the slightest idea about how to setup such:
My application has a Main class. Am I supposed to change it to be called myapp?
I've been running my app with java Main compress filename. I see that now I shouldn't be using the java key. But of course, as it is now, it won't work if I remove it. How can I run the app without it?
Is there a difference between having the compress argument I always use and the -compress one they tell me? Is that dash (-) any special?
Looking at this page: http://docs.oracle.com/javase/1.4.2/docs/tooldocs/windows/java.html, it seems to insist that to run my program I do need to use the java key. And the dash seems to be used for something called options - there are standard and non-standard. However, there doesn't seem a way to make a "custom" one (-compress).
So my question is, how can I run my application with the above format?
The easiest way it to create a one-line shell script (if you're using Unix) or a one-line batch file (if you're using Windows). Call it myapp (or myapp.bat) and make it launch Java, passing the appropriate arguments.
As to the -compress argument, your main() takes an argv. You'll need to examine that to figure out what arguments have been passed to your program. You can either code everything yourself (very easy in your case), or use an existing framework:
How to parse command line arguments in Java?

Starting other Applications with Java

Is it possible to start other application that are installed on the system with my java app and pass a file as a parameter to them? I have a client which receives videos from a server and I want my client program to start, lets say the VLC player with the file that I received. How do I manage to do that?
Use Desktop#open(). It will launch the platform default associated application to open the given file.
File file = new File("/absolute/path/to/file.vlc");
Desktop.getDesktop().open(file);
No need to hassle with Runtime#exec() or ProcessBuilder for which you would have to add platform detection and to write platform specific logics for.
Quite simply:
Runtime.getRuntime().exec("vlc [arguments]"); //Write all arguments as you would in your shell.
Make sure you catch all relevant exceptions
You can call the exec method on the Runtime object.
Runtime.getRuntime().exec("System specific command line text here");
You can run an external program pretty easily on Java 5+ with ProcessBuilder, including passing arguments and handling input/output streams.
eg.
ProcessBuilder movieProcess = new ProcessBuilder("/path/to/movieplayer", "/path/to.moviefile");
movieProcess.start();
Only used it myself executing non-UI stuff, I'll give it a quick go and see what happens with something like VLC.
Update - works a treat for flv on Ubuntu, UI is visible and accepts file arguments.

Categories

Resources