I'm using JwebUnit to test my JSP pages in a web application.
Since JWebUnit requires a base urlto work. JwebUnit has setBaseUrl("http://localhost:8080/MyWebapp"); to set the base url which is used #Beforeof Junit Test. I need to start a server and deploy the webapp there before each test and stop the server after that. Can anyone please suggest me a simple way to do this with Jetty or other options...
You may have a look at Server Rule. It provides a JUnit rule that starts and stops a Jetty web server.
Related
Is JUnit able to test a websocket server, or is JUnit unable to complete this task and should another tool then be used to test a websocket server using Java? As of note the websocket server is hosted on a page served by Tomcat 7.0.53.
Your question is confusing. However, perhaps you can look at HTMLUnit which is API that allows you to programmatically access webpages. You can use that with JUnit to test your webpage. You may also want to look at JWebUnit that is based on HTMLUnit. Something else that might be helpful is that you can debug your webapp using Eclipse. You can either run the tomcat server in eclipse or connect to a running server instance (You will need to set some options when starting tomcat if you do not run within Eclipse)
Hope this helps.
I am searching for a simple framework which is able to mock JSON responses for specific URLs and therefore starts an in-memory server. E.g. the framework could start a node.js server or similar.
I need a physical server since the unit tests are running against an external application (using selenium) and this application has a dependency to a JSON interface. The application itself is iPhone-App running inside of simulator and communicates to a REST interface.
Is there an existing framework for this or what would be the best approach given that I need to execute the tests with jUnit.
You can start a stub server, given that you can configure the JSON URL in your client application.
Have a look for example at:
https://github.com/dreamhead/moco
https://stubby4j.com
You can start these in your maven build during the pre-integrationtest phase and shut them down in post-integration test phase.
You can use npm package stubby-db. What you need to do is;
Install : npm install stubby-db -g
Mapping : Create a request response mapping which is quite easy. Specify the path of response file having JSON response.
Run the stub server: stubbydb
That's all. However since you just want to run it for your unit tests only which doesn't require much performance, you can also use wiremock. It starts internally, and you never feel like you are running an external application.
I have just finished developing a REST web service that is consumed by a mobile application. The web service is developed with Java and runs on an Apache server.
I'm now moving to the testing part. And for that purpose, I need to host my web service in a real server.
It is a first experience for, and I just knew that using mutualised (shared) hosting does not allow me to host whatever application, in whatever language.
The one I get to use is OVH, which does not support java web services hosting.
Does anybody have any other alternative to provide. It would help a lot!!
Like I said, if it is for testing purposes you could always use a "normal" PC, running something like XAMPP.
As an alternative you could give RedHat's OpenShift a try, which offers a free, getting-started plan (more info here) that should more than cover your testing requirements.
To run your app (in Eclipse) you would need to : Run As -> Run on Server
And then select a server. If you haven't done so; I suggest you install a local JBoss/WildFly server (the wizard can take care of that for you).
Doing this will display options to run your app either on the local or the OpenShift/rhcloud server.This makes testing faster and allow you to avoid testing on the OpenShift live server.
I want to develop a standalone java application, with web browser as front end. This application will run locally and won't be making any remote server calls. I'm essentially using java, as web-browser cannot perform file operations.
I want this application to be portable: no need of installation. Just copying a folder should be enough. I want to know how it can be done, how will javascript communicate with java code.
In continuation of #Quentin's answer.
Yes, you need web server.
There are 2 principal architectures:
Create stand alone application with embedded web server
Create ordinary web application and run it on proprietary web server.
IMHO I think that the second approach is better, however it strongly depend on your application functionality.
You can take jetty or grizzly as a web container. Both can run as in embedded or stand alone modes. You are welcome to share other details of your application with the community if you need concrete advises concerning to the design of your application.
The application would need to implement an HTTP server. Then all communication would be done over HTTP.
Write a small web application as you need and Deploy it using Jetty. Jetty is a pure Java-based HTTP server and Java Servlet container. You can use it by embedded mode also.
Deployment is so easy if you use Jetty-Runner
java -jar jetty-runner.jar my.war
You don't need a local web server. Take JavaFX (embedded webkit) and implement a URL protocol handler for say "myprotocol". Then you can access it from the browser using something myprotocol://xxx.yyy.zzz
I want to check deploying procedure of my struts2 web application developed using eclipse juno on local tomcat server. I want to deploy it to a remote host like 000webhost. Can you provide me any information how to do that?
well, I run my application by typing
http://localhost:8080/Struts2starter/
on browser I want to run it by typing
http://myapp.com/Struts2starter
like something on browser. I wanted to know how to do it.
I don't believe you can deploy a Java application in 000webhost. For example, you can deploy on Google App Engine. Here is an example of how to do that: http://www.mkyong.com/google-app-engine/google-app-engine-struts-2-example/
It depends on server in question. Most servers provide some kind of remote deployment using manager applications / rmi connectors / whaever else exitic means , and eclipse can work with most of them. But of course it needs to be configured on both sides in order to work. Be more specific about your server config, and you will surely get proper answer