Wednesday, September 14, 2016

Change Java Compiler Version from pom.xml file

Add the following in your pom.xml file:
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

Quick Notes About Mockito

Unit Test Case:

JUnit Test Case:

Usually mokito is used for unit test cases. JUnit is rarely used.

autowiring - saturday
sunday: spring


Popular Mocking Unit Test:
1. Mockito
2. Easy Mock
3. Power Mock

only mock the code which you cannot setup and ....
we dont mock an implementation


we should know what we have to mock in a method


go to mockito.org to see some really good documentation



Optimized the code
next step is: mock the object but was it really called?


@Mock

@RunWith --> if we want to do all @Mock annotations, then we need to do the @RunWith annotation.



Familierize with mockito, try easy mock as well as try also power mock


times, atLeast, atMost can be used to verify how many times the method is called.
verify(dao, times(2)).createProduct(any(ProductEntity.classs) )




First we have to create a happy path scenario, then do a test coverage....


spy is a partial mock, it will only mock the things that you will tell to mock.
mock is a total mock.

mockito is much better than easy mock. no one will insist you to do a particular mock in job.


----------------------
java ee example, where we have reservation controller or ui component calling into the reservation BO
which pose the business logic and the BO calls the DAO which does the DB operations using jdbc, hibernate etc.

if we are testing the reservation controller, we mock out the reservationBo
and all the methods on the reservationBo which reservation controller methods are using
and test all the public methods on the reservation controller in isolation...

similarly, if we are testing reservationBO, we do the same for reservationDAO.

Friday, September 9, 2016

Creating a Simple ExpressJS Server

Lets create a server.js file. and add the routing information as:
//routing
app.get('/', function(req, RES){
res.redirect('/views/index.html'); //index.html file must be created inside views folder
});
Working Example server.js:
var express = require('express');
var app = express();
//setting up the static files for hosting
app.use(express.static(__dirname + '/'));

//routing
app.get('/', function(req, RES){
res.redirect('/views/index.html');
});

//... other routings

app.get('/landing', function(req, RES){
res.send('In landing page');
});
//end of routing

//launching application on localhost:1432
app.listen(1432, function(req, RES){
console.log('server loaded on port 1432');
});
Here, 
var express = require('express'); =>> it requires express folder inside the node_modules folder. For this execute the following command:
npm install --save-dev express


also, give any port for the server as:
//launching application on localhost:1432
 //you can put whatever port you want but that shouldn't be already used.
app.listen(1432, function(req, RES){
console.log('server loaded on port 1432');
});

Now, go to the cmd and enter:
node server //or node server.js
then, it will display the following console.log msg:
server loaded on port 1432
After that, if you enter 
http://localhost:1432/views/index.html
in the browser, it will work.


Sunday, September 4, 2016

View EndPoint is not Available on GlassFish

If you are writing a SOAP Webservice, then you may face the following situation once you deploy your project on GlassFishServer:

There is a "Launch" action available under the "Modules and Components" section but "View Endpoint" is not available.

In that case, you can solve this issue by changing the web.xml file (which is available under WEB-INF folder) of your project as follows:

<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="2.5"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  <display-name>Archetype Created Web Application</display-name>
</web-app>

Then, redeploy your project and then you are good to go! Good Luck.

WebService Client Tester is not Working on GlassFish Server

If you are writing a SOAP Webservice, then you may face the following situation:

WSDL: (/YourProject/YourService?wsdl) is working fine but 
Tester (/YourProject/YourService?Tester) is not working 

Then, this can be solved using:
Create a new text file and rename it jaxp.properties (if it doesn't exist under /path/to/jdk1.8.0/jre/lib) and then write this line in it: javax.xml.accessExternalSchema = all

Then, restart the glassfish server and you are good to go! Good Luck.

There is another way to fix this if you are facing this problem when working on a Maven Web Project:
(Since the above solution perfectly worked for me, I didn't test this solution:)


If you are using the jaxws Maven plugin and you get the same error message, add the mentioned property to the plugin configuration:

...
<plugin>
  <groupId>org.jvnet.jax-ws-commons</groupId>
  <artifactId>jaxws-maven-plugin</artifactId>
  <version>2.3</version>
  <configuration>
    <!-- Needed with JAXP 1.5 -->
    <vmArgs>
        <vmArg>-Djavax.xml.accessExternalSchema=all</vmArg>
    </vmArgs>
  </configuration>
</plugin>

I found the above plugin configuration on StackOverflow.