Saturday, December 22, 2012

Simple Selenium UI web Testing

Simple Selenium UI web Testing:

1. Download Firefox Selenium from
https://addons.mozilla.org/en-us/firefox/addon/selenium-expert-selenium-ide/

2. Restart firefox.

3. Go the the web URL you want to test it (May be to your login screen if your website required login credential)

4. From that url just click 'Tools' ->  'Selenium IDE'

5. Selenium IDE will be opened, it will be in default start recording your website action.

6. Now in your website do any action like login followed by searching products etc.

7. Now come to selenium IDE, stop the recording and execute the command by clicking play.

8. Web-browser automatically open by selenium and do all the activities earlier manually performed!

Thansk to Selenium :)





Friday, December 14, 2012

Spring JMS ActiveMQ - Introduction/Perfomance

What is JMS?


Java Message Service(JMS) is a Specification/Interface/API provided by SUN for sending messages between two or more clients
JMS Producer (Client) ---> Provider/Broker/ActiveMQ ----> JMS Listener (Client)
Producer: In simple word it create message and send it to provider's destination Queue through JMSConnectionFactory
Destination: Destination is a .Queue where message resides in the provider.
Provider: Provide implements the JMS specification for sending messages between clients. ActiveMQ is one the well know provider. Provider is also known as broker as it does the job of transferring the message from producer to listener,
Listener: It listen to the queue when even there is a message in the queue listener process it inside onMessage method.
Persistence and Non-Persistence Mode: ActiveMQ in default runs in persistence mode. Persistence mode means message is persisted by the provider in file system or db. 
Why JMS Persistance Mode? 
Consider message is transferred from producer to provider, in persistence mode provider(ActiveMQ) will persist the message in file system. Consider listener is busy in processing other task or listener server is down. Due to some other issue if provider(ActiveMQ) server is also down if message is not persisted then message will be lost without reaching the listener. In our case since we run it in persistence mode message is persisted and it will be used by the listener when both provider and listener servers are up and running!  

JMS Performace:
Non-persistent delivery of message improves the performace of the overall system. 

When to use Non-Persistance mode:
For usage scenarios where only reliability is required we can go with non-persistance JMS, where as when we need guaranteed message delivery we can use persistance mode. Even in non-persistence mode JMS specification allows the messaging provider to make best efforts to deliver the message to currently active message consumers.

Wednesday, October 3, 2012

Compare Restful and Soap Webservice

Why SOAP?

Here are a few reasons you may want to use SOAP.

Why REST?

Here are a few reasons why REST is almost always the right answer.
Since REST uses standard HTTP it is much simpler in just about ever way. Creating clients, developing APIs, the documentation is much easier to understand and there aren’t very many things that REST doesn’t do easier/better than SOAP.
REST permits many different data formats where as SOAP only permits XML. While this may seem like it adds complexity to REST because you need to handle multiple formats, in my experience it has actually been quite beneficial. JSON usually is a better fit for data and parses much faster. REST allows better support for browser clients due to it’s support for JSON.
REST has better performance and scalability. REST reads can be cached, SOAP based reads cannot be cached.
It’s a bad argument (by authority), but it’s worth mentioning that Yahoo uses REST for all their services including Flickr and del.ici.ous. Amazon and Ebay provide both though Amazon’s internal usage is nearly all REST source. Google used to provide only SOAP for all their services, but in 2006 they deprecated in favor of REST source. It’s interesting how there has been an internal battle between rest vs soap at amazon. For the most part REST dominates their architecture for web services.

 

WS-Security

While SOAP supports SSL (just like REST) it also supports WS-Security which adds some enterprise security features. Supports identity through intermediaries, not just point to point (SSL). It also provides a standard implementation of data integrity and data privacy. Calling it “Enterprise” isn’t to say it’s more secure, it simply supports some security tools that typical internet services have no need for, in fact they are really only needed in a few “enterprise” scenarios.

WS-AtomicTransaction

Need ACID Transactions over a service, you’re going to need SOAP. While REST supports transactions, it isn’t as comprehensive and isn’t ACID compliant. Fortunately ACID transactions almost never make sense over the internet. REST is limited by HTTP itself which can’t provide two-phase commit across distributed transactional resources, but SOAP can. Internet apps generally don’t need this level of transactional reliability, enterprise apps sometimes do.

WS-ReliableMessaging

Rest doesn’t have a standard messaging system and expects clients to deal with communication failures by retrying. SOAP has successful/retry logic built in and provides end-to-end reliability even through SOAP intermediaries.

Summary

In Summary, SOAP is clearly useful, and important. For instance, if I was writing an application to interface with my bank I would definitely need to use SOAP. All three features above are required for banking transactions. For example, if I was transferring money from one account to the other, I would need to be certain that it completed. Retrying it could be catastrophic if it succeed the first time, but the response failed.

Source: http://spf13.com/post/soap-vs-rest/
 

Monday, June 11, 2012

MYSQL - Special Character persisted for hyphon - Solution

Root cause of persisting/displaying of special character is Characterset of MYSQL database.

Execute below query in DB, check the  character set values. Character set client need to be in UTF8 format.

If it is working in testing db and not working in production db, then you can compare the result by running below sql query iin both the db and compare it. Comparing result can be applied in production db from testing db.

"SHOW VARIABLES LIKE 'character_set%';"

Tuesday, June 5, 2012

Solution for Spring circular reference

In Spring injection we may come acros circular reference exception.

Example for circular reference:
 <bean id="lookupService " class="com.AddressLookupServiceImpl">  
     <property name="xyzService" ref="xyzService" />  
   </bean>  
   <bean id="xyzService" class="com.XYZServiceImpl">  
     <property name="xyzService" ref="xyzService" />  
   </bean>    


  Here bean lookupService is referring to bean xyzService. Again bean xyzServiceis referring to lookupService. This is called circular reference.

To avoid circular reference issue, instead of having reference in child to parent we can just have the reference in parent bean alone as given below    

 <bean id="lookupService " class="com.AddressLookupServiceImpl">  
     <property name="xyzService" ref="xyzService" />  
   </bean>  
   <bean id="xyzService" class="com.XYZServiceImpl">  
   </bean>    

 Error creating bean with name 'XYZ': Bean with name 'XYZ' has been injected into other beans [XYZHelper, AHelper] in its raw version as part of a circular reference, but has eventually been wrapped. This means that said other beans do not use the final version of the bean. This is often the result of over-eager type matching - consider using 'getBeanNamesOfType' with the 'allowEagerInit' flag turned off, for example.

Solution for NoSuchMethodError

Sometime we face NoSuchMethodError exception in production environment. One of the root cause of this exception is same class exist in two different jar. But particular method is not present in the loaded class.

Lets explain with an example below exception says method readWSDL is not available in WSDLReader class.
In my project  WSDLReader class was available in two different jars namely axis-wsdl4j-1.5.1.jar and wsdl4j-1.6.2.jar. WSDLReaderinside axis jar doesn't have the method readWSDL(Ljavax/wsdl/xml/WSDLLocator;Lorg/w3c/dom/Element;). So we can exclude axis jar from pom and use only wsdl4j-1.6.2.jar.

Exception:
java.lang.NoSuchMethodError: javax.wsdl.xml.WSDLReader.readWSDL(Ljavax/wsdl/xml/WSDLLocator;Lorg/w3c/dom/Element;)Ljavax/wsdl/Definition;

POM changes:

 <dependency>  
       <groupId>com.ExampleService</groupId>  
       <artifactId>service</artifactId>  
         <exclusions>  
            <exclusion>  
             <artifactId>axis-wsdl4j</artifactId>  
             <groupId>axis</groupId>  
           </exclusion>  
         </exclusions>  
   </dependency  
               
   dependency>  

Wednesday, March 28, 2012

Master/Slave database - Replication Database

What is Master/Slave database?

Syncronized data between two database is set to be maste/Slave configuration.

When to consider Master/Slave database approach?
It is helpful in Batch Reporting Application.
In usual realtime there will be two application one as portal application and another is batch reporting application. Portal application can use the Master DB and Batch process can use Slave DB. Slave DB get the replicated data from Master DB. This replication usually taken care by DBA. So dev team concentrate on business logic.

What is the advantage of Master/Slave database approach?
Performance :)
Because Portal can keep using the Master and there is no hindrance in database by huge sql activity in slave DB. Batch can continue using the slave DB as and when required.

Wednesday, March 21, 2012

JUnit Mockitto - Void Method Testing

To test the void method using Junit and Mockitto use below approach
Concider someMethod s a void method inside  SomeClass

Use the below approach:

SomeClass classObjMock = (Mock)SomeClas;
doNothing().doThrow(new RuntimeException()).when(classObjMock).someMethod ();

JUnit Code Coverage - EClemma

EClemma  works pretty well to know the JUnit code coverage from eclipse
It displays green shade for the files which is covered and red for the lines which are not code covered.

Junit class file -> Right click -> Coverege As -> Junit

http://www.eclemma.org/installation.html


Unzip the archive into dropins folder of your Eclipse installation and restart Eclipse:
/
+- dropins/
   +- eclemma-x.y.z/
      +- plugins/
      |  +- ...
      +- feature/
         +- ...

Tuesday, February 28, 2012

Google App Engine - Supported Framework

Google App Engine Supports Spring Framework. List of frameworks supported by GAE is listed below.

http://code.google.com/p/googleappengine/wiki/WillItPlayInJava

Google App Engine - Sample code - Java/Phyton
http://code.google.com/p/pgae-examples/downloads/list