sreenivas vemula

Ranch Hand
+ Follow
since Jan 21, 2012
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
2
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by sreenivas vemula

Hi I writing test cases for the application and I am using jmock to mock the objects, but I am not able to do so . Please help:

Here is the Restful webservice implementation. Now I would like to write junit test case. In the following class "BusinessClass" I want to mock the part " partnerService.validatePartner(QuoteRQ.partnerid, transactionId)" and for that I have written mock class called " PartnerServiceMock" which will be injected at runtime.
The problem that I am facing is while running the junit test case, instead of mock object, actual code is getting executed, i.e., mock object is not getting injected at runtime. Please help.

Following is the code snippet

public interface BaseMockInjector {

public void injectMock(List<Class> clist);

public void injectMock(Class c);
}




public abstract class BusinessServiceBaseMockInjector implements BaseMockInjector {

AbstractMock abs = null;
PartnerService partnerService = new PartnerService();
try {
abs = (AbstractMock) Class.forName("test.chartis.tguard.stdoff.service." + c.getSimpleName() + "Mock").newInstance();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
abs.mock(context, mockSingleton);

public void injectMock(List<Class> clist) {
Mockery context = new JUnit4Mockery() {

{
setImposteriser(ClassImposteriser.INSTANCE);
}
};
try{
Class c = BusinessClass.class;
Field[] fields = c.getFields();
for(Field field : fields){
Class cls = field.getClass();
Object mock = context.mock(cls);
this.mock(context, mock, c);
if(field.getName().equalsIgnoreCase("partnerService"))
System.out.println("partnerService");
else if(field.getName().equalsIgnoreCase("isoCountryService"))
System.out.println("isoCountryService");
else if(field.getName().equalsIgnoreCase("uwCountryService"))
System.out.println("uwCountryService");
else if(field.getName().equalsIgnoreCase("agencyService"))
System.out.println("agencyService");
else if(field.getName().equalsIgnoreCase("productDTOService"))
System.out.println("productDTOService");
}

}catch(Exception e){

}

}


}



Test Class:
===========

public class TestBusinessClass extends BusinessServiceBaseMockInjector {

List<Class> classes = null;

@Before
public void test() throws Exception {
List<Class> classes = new ArrayList<Class>();
classes.add(PartnerService.class);
injectMock(classes);
}


@Test
public final void testExecuteRule() {
BusinessClass business = new BusinessClass();
QuoteRQ quoteRQ = new QuoteRQ();

quoteRQ.setTimestamp(today);
quoteRQ.setTransactionID("Scenario2Cycle206282012");

business .executeRule(quoteRQ);
}

}



Class under Test:
===================

@Path("/rule")
@Singleton
public class BusinessClass{
public PartnerService partnerService = new PartnerService();

@POST
@Path("/executeRule")
@Produces("application/xml")
@Consumes("application/xml")
public Response executeRule(QuoteRQ quoteRQ) {

// some code here
//now the following line will have a call to a web service
if (isPartnerNotNull) {
try {
isPartnerValid = partnerService.validatePartner(QuoteRQ.partnerid, transactionId);
} catch (ServiceException e1) {
logger.info("[" + transactionId + "ServiceException while validating partner Id");
}
}


}

}


Mock class for PartnerService:
==============================

public class PartnerServiceMock extends AbstractMock {

@Override
public void mock(Mockery context, Object obj) {
final PartnerService partnerService = (PartnerService) obj;
try {
final boolean isPartnerValid = true;
context.checking(new Expectations() {

{
atLeast(1).of(partnerService).validatePartner("QABHIAIR", "Scenario2Cycle206282012");
will(returnValue(isPartnerValid));
}
});
} catch (ServiceException serviceException) {
serviceException.printStackTrace();
}
}
}
your assumption is correct.


9 years ago
Hi,
I have 3 years of experience in web services. I want to know about AMAZON Web Services. Please provide some nice websites.

Regards,
sreeni,
9 years ago
FYI,
I am going to attend interview, not to take interview.

Regards,
sreeni.
9 years ago
Hi ,
I am getting following RuntimeException while running the Spring Restful Webservice. I am using Jersey framework.

java.lang.IncompatibleClassChangeError: Class javax.ws.rs.core.Response$Status does not implement the requested interface javax.ws.rs.core.Response$StatusType
at com.sun.jersey.spi.container.ContainerResponse.getStatus(ContainerResponse.java:558)
at com.sun.jersey.spi.container.ContainerResponse$CommittingOutputStream.commitWrite(ContainerResponse.java:156)
at com.sun.jersey.spi.container.ContainerResponse$CommittingOutputStream.write(ContainerResponse.java:133)
at sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:202)
at sun.nio.cs.StreamEncoder.implFlushBuffer(StreamEncoder.java:272)
at sun.nio.cs.StreamEncoder.implFlush(StreamEncoder.java:276)
at sun.nio.cs.StreamEncoder.flush(StreamEncoder.java:122)
at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:212)
at java.io.BufferedWriter.flush(BufferedWriter.java:236)

Please let me know what could be the issue.

Thanks in Advance.

Regards,
sreeni.
9 years ago
Hi,
Please provide some gook links for the webservices interview questions.

Regards,
sreeni.
9 years ago
Hi Tanuj,
Is you book available for free downloading? If so please share the link

Regards,
sreeni.
9 years ago
Hi I am getting following exception while running test client for RestFul Webservices application.

com.sun.jersey.api.client.UniformInterfaceException:

I tried to check the MIME type that I gave in the restful webservice. Its correct.

I just wanted to know what are the scenarios to get this kind of exception.

Please assist.

Thanks in advance,

Regards,
sreeni.
10 years ago
Hi I am using Restful Webservices. Following is the code.


import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;

HelloWorldResource.java

@Path("/helloworld")
public class HelloWorldResource{
@GET
@Produces("text/plain")
public String sayHello(@QueryParam("world") String world) {
return "Hello " + world;
}
}

Following is the REST client:

import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.WebResource;

public class HelloWorldRestClient{
public static void main(String[] args) {
Client client = Client.create();
WebResource webResource = client
.resource("http://localhost:8080/TESTREST/services");
String response = webResource.path("helloworld")
.queryParam("world", "World!").get(String.class);
System.out.println("Response: " + response);
}
}

When I try to the REST client I am getting the following errors:

Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/jersey/spi/inject/Errors$Closure
at HelloWorldRestClient.main(HelloWorldRestClient.java:6)
Caused by: java.lang.ClassNotFoundException: com.sun.jersey.spi.inject.Errors$Closure
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
... 1 more

I executed the same program at my PC in home. Working well that time. Don't know what I did that time.

I have added all the required jar files and added the same in the classpath too. No compilation errors.

Please assist me.

Thanks in advance


Regards,
sreeni.
10 years ago
Hi,
I am beginner to RESTFUL WebServices. I need some good tutorial on the same. Please assist me.

Thanks in Advance,

Regards,
sreeni.
10 years ago
Hi Rob,
Both the service are running on same java version. We are deploying the application in WAS.

10 years ago
Hi,
I want a working example on developing a webservices using JAX-WS Top Down Approach.Actually I have an application which provides two webservices. For one of the webservices it deals with SAAJ. The request and response xml both contain SOAP attachment. The problem is that there is some error showing in both WSDL and XSD.

</complexType>
<xsd:complexType name="SimpleSwaType">
<xsd:sequence>
<xsd:element name="Attachment" type="wsi:swaRef"></xsd:element>
</xsd:sequence>
</xsd:complexType>

and prefix wsi is defined as
xmlns:wsi="http://ws-i.org/profiles/basic/1.1/xsd"

and Here is my Java class for the above complex type.

public class SimpleSwaType {

@XmlElement(name = "Attachment", required = true, type = String.class)
@XmlAttachmentRef
protected DataHandler attachment;

/**
* Gets the value of the attachment property.
*
* @return possible object is {@link String }
*
*/
public DataHandler getAttachment() {
return attachment;
}

/**
* Sets the value of the attachment property.
*
* @param value
* allowed object is {@link String }
*
*/
public void setAttachment(DataHandler value) {
this.attachment = value;
}

}

The error throwing at highlighted line and The error throwing is "src-resolve : Cannot resolve the name 'wsi:swaRef' to a(n) 'type definition' component."

Please help.

Thanks in advance.

Regards,
sreeni.

10 years ago
When I try to use the wsgen tool I am getting the following error:

command : wsgen -classpath build/classes/ -wsdl -r WebRoot/WEB-INF/wsdl -s src -d build/classes/ com.mkyong.ws.ServerInfo

Error : MISSING SEI

I am following an example in http://javaeenotes.blogspot.in/2010/10/web-service-with-jax-ws-in-eclipse.html

Please assist.

Thanks in advance

Regards,
sreeni.
10 years ago
Hi Jesper,
I have two webservices in my application. In one of the two webservices I have used the code just like mentioned in the post, its working with no issues.


Regards,
sreeni.
10 years ago
Hi
I am getting the exception "java.lang.NoClassDefFoundError: com/sun/net/ssl/internal/ssl/Provider" when the following is executed in my code.

java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());

Please assist.

Thanks in advance.

Regards,
sreeni.
10 years ago