Junit unable to load properties file of web aplicaion - unit-testing

I have piece of code in webapp which loads a file from WEB-INF classes folder
ex-
PropertiesHelper.class.getClassLoader().getResourceAsStream("/test.properties);
I am writing a junit for the above method, but when test is executed it is unable to find/load properties file. I have added the properties file in test resources but still it is unable to load it.
If I change the main code and remove slash - '/', then junit works but code will not work when deployed in webapp.
How to write junit for the above case?

Related

Is there a way to show jacoco code coverage using an endpoint like /codecoverage?

i generated code coverage using the maven jacoco plugin successfully. Now i want access the report directly with an endpoint without actually opening index.html file. is there any way to add a path to show code coverage ?

Codename One: Webservice not available

I used the CN1 Webservice Wizard to add a the webservice proxy to my mobile app and to generate all the server side code. I have a local XAMPP installation with a tomcat linked within my Eclipse IDE. Also, I imported the server generated code as a new Java Project and added the "Dynamic Web Module" project facet to it so that I could launch it not as a local Java application but rather on the Tomcat server.
When starting my client, I noted that I get HTTP 404, resource not found errors. I traced the error back to the URL, where the server is hosted to.
I know I have to adapt the urlPatterns parameter in the generated class CN1WebServiceServlet, which I did. Also, I checked the context of my app in the Web project settings and defined the value for context root. So, in my client app, the URL to call the service should be
http://localhost:8080/< context root>/< urlPattern>
However, even when calling that in the browser, I should get the result of the doGet method of the server generated code, showing the message "Webservice access only". Instead, I get 404 errors all the time.
Is there some problem to importing the server generated code as a plain Java project and adding the web parts to it afterwards? How would that be done in the ideal case?
And what other problems might be hindering the URL from properly being published on the server side?
Thanks and best regards
EDIT
I stripped everything from the project to limit the options and I found the cause: when using the web service wizard to dump the source files into a new directory, adding that with the Eclipse import wizard, it will be looked at as a plain java project without any web components. Using the project settings to add the dynamic web piece to it (Eclipse calls those project facets), the CN1 webservice will NOT work.
If instead you create a "Dynamic Web Project" first and then use the CN1 Webservice Wizard to dump the server source files into the "src" folder of that project, it works without any issues.

Java weka DataSource loading issue with RESTful Web Service

I'm doing a prediction sytem application by using the weka APi with java.
I created a JavaSE application with weka and use following code for load the dataset
String filepath = "";
DataSource source = new DataSource(filepath);
when I try to implement it with restful web service JavaEE
it gives an error at that line as folowing
java.lang.ClassNotFoundException: weka.core.converters.ConverterUtils$DataSource
can some one help me
If some one having this problem,
Please re-check whether you set the weka.jar file path in to your web service.
Specially if you add the weka.jar file to the build path of your web service project it doesn't add to the hosting web service only for the application environment.
Make sure to add the file in to WebContent -> WEB-INF -> lib -> weka.jar
Then It will works fine.

Copy application config file to another application directory

I am testing a WCF service, which is hosted in a console application. I am running the test using NUnit. So I want to copy the console application and app.config of console application to the Bin\Debug folder of the Test assembly. I am able to copy the console application, by adding the reference to the test assembly, but app.config of console application is not coming. Also I tried to copy by setting the properties, it not worked. It is copying the app.config as it is, it not changing the name as ConsoleApp.exe.Config. Is there any way to fix this issue?
you can create a post build event to do this, which will copy the projects app.config and will rename it ConsoleApp.exe.config.
You could also just create a file in your project called ConsoleApp.exe.config and fill it with the config required for the tests and have it copy to the output directory. this would be my preferred solution as it would mean that the tests would be in control of the config and would not be affected by the potential changes to the app.config in the console applications project.

Web Service URL Problem

H!,
I have a solution in which there is several other sub projects (windows application).
in every project I have some web services added.
Now the problem :
how can i set the URL of each web service individually from the app.Config file??
is there a setting I missed to set ?
can it be automatically done or I have to code for it ?
Thank you friends.
There is only 1 app.Config file per executable - although the app.Config file is named app.Config in the solution, it is in fact renamed to the same name as the end executable:
So for example if my output executable is called Test.exe, the app.Config file will be named Test.exe.config.
Only config in that file has an effect - thats the file you need to set your web service URL in.