Test websocket server with junit - java

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.

Related

How to debug a dynamic web project with post request in eclipse juno

I can debug easily with a Get request (Debug on Server, Tomcat is started and I can proceed easily) as I just need to pass parameter in url but I am not sure how to debug with a post request.
Currently I am using Advanced Rest Client to run the application and checking logs to find any error.
Any help is appreciated.
Postman is very useful chrome extension for that.
Start the server in debug mode, then send post request via Postman. You can also use any other http methods.
I added a screenshot that shows how to send a post request to local machine with json parameters.
Set-up and start Tomcat from Eclispe and set a break point in your POST method.
Then use a client linke curl, wget or SOAP UI.
Or even bether: Write integration tests which start tomcat and use soemthing like the Apache HttpClient. You could write a JUnit class rule which starts and stops tomcat for your tests.
This is more initial work, but gives you infinitely repeatable test for continous integration.

Setting a server for JWebunit Tests

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.

Mock a physical web server while junit test running

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.

how to deploy struts2 eclipse web application on remote server

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

how configure jwebsockets with my existing application running on tomcat server

I am trying to use Jwebsockets with my existing project. I have done the configuration with my Tomcat Apache server and able to run all the demo application using
http://localhost:8080/jWebSocketAppSrvDemo-1.0/
Its working fine Jwebsocket server is running fine on my machine.
Now I don't know what to do to integrate it with my exiting application how I can send the messages to jwebsockets server and receive messages from server. I am new to this kind of technology. I tried the tutorial mentioned on website but I am not able do that like in first jWebSocket "Hello World" tutorial I don't know where I set the IURL,gUsername,IPassword. Same with the next tutorial I don't know where I can get WebSocketTokenListener interface. I have added jWebSocketServer-Bundle-1.0.jar file to my lib folder. I feel that tutorial is not step by step tutorial.
Can anyone suggest how I can integrate it with my application if I want to post and reply some message on my website.
Is this right to use jWebsockets with the java application? I am using spring and springMVC framework with Apache Tomcate on Ubuntu

Categories

Resources