When you are writing test cases, there might be a case that you want to mock only a selected method and other methods of the class should run the real implementation. This is specially useful when the method you are testing calls another methods in the same class.You can use following way to achieve that task.
Class A{
methodA();
methodB();
methodC();
}
We need to test methodA() and it calls methodB() inside. We need to mock methodB().
ClassATest extends TestCase{
testMethodA()
{
A a = new A();
spy = Mockito.spy(a);
Mockito.doReturn(
}
}
Some times when working with sql server you may get following error.
TITLE: Connect to Server
------------------------------
Cannot connect to
------------------------------
ADDITIONAL INFORMATION:
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) (Microsoft SQL Server, Error: 2)
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&EvtSrc=MSSQLServer&EvtID=2&LinkId=20476
------------------------------
BUTTONS:
OK
------------------------------
Last week, I had to face following scenario.
My application is a client server application. An object of type class A, is encoded using java.beans.XMLEncoder in client side and saved in database. Class A is located in client side. I need to decode that object at server side. When I try to use java.beans.XMLDecoder,xmlDecoder.readObject() method returns null.
So I investigated why it is happening. It was because class A is not available at server side, when XMLDecorder try to un marshall the object.
I was trying to update some rows of a table using sql update statement, but it always returned "0 rows affected " message. I was using following syntax for that.
UPDATE table_name
SET column1=value1,column2=value2,...
WHERE column1='AB1 2CD';
The issue was the space inserted within the value I compare in where statement. So I used a column value, which has no spaces within its value for where statement. Then it worked.
You can get more information about this issue from following link.
http://stackoverflow.com/questions/14511018/where-clause-doesnt-work-in-sql-because-of-space-character
Debugging a Web service running in tomcat is really useful some times. Following are the necessary steps for that.
1) Add following line to startup.bat file within
set CATALINA_OPTS=-Xdebug -Xnoagent -DJava.compiler=NONE Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
2) Create a new eclipse debug configuration of type Remote Java Application for the project and set its connection properties as below.
Host: localhost
Port:8000
3) Start tomcat and run the debug configuration.
Now, you can debug your web service.
I got this exception last week when I was writing a task service to perform a task that involves retrieving data from a database. I found the SQL statements that it try to run from the The log files. They worked fine and gave correct results when I run it from SQL Server Management Studio.Then I googled the exception and found following details are helpful.
Most of the time this exception occur because of a timeout.
You can fix it by increasing the value of transactiontimeout property in conf/jboss-server.xml.
more info: http://ttlnews.blogspot.com/2012/04/jboss-exception-transaction-is-not.html
Another possible scenario is that there is a Null Pointer Exception in the flaw of your application. This caused the transaction to end and re-enter a loop when the transaction was not active.
more info: http://thejavablog.wordpress.com/2010/04/05/transaction-is-not-active-txtransactionimple-ac-basicaction





