java - How to invoke a webservice using rest assured -
i new rest assured , having troubles using run basic program. created java project , added required rest assured jars. below simple code:
import com.jayway.restassured.restassured; import com.jayway.restassured.restassured.*; import com.jayway.restassured.matcher.restassuredmatchers.*; import org.hamcrest.matchers.*; public class restservicetest { public static void main(string args[]) throws exception { // restassured.baseuri="http://restcountries.eu/rest/v1/"; string str=restassured.get("http://restcountries.eu/rest/v1/name/norway").asstring(); system.out.println(str); } }
i have added pom.xml file add following dependencies.
<dependency> <groupid>com.sun.jersey.jersey-test-framework</groupid> <artifactid>jersey-test-framework-core</artifactid> <version>1.9</version> <scope>test</scope> </dependency> <dependency> <groupid>com.sun.jersey.jersey-test-framework</groupid> <artifactid>jersey-test-framework-external</artifactid> <version>1.9</version> </dependency>
i getting below exception when ran above code:
exception in thread "main" java.lang.noclassdeffounderror: groovyx/net/http/httpbuilder @ java.lang.class.getdeclaredmethods0(native method) @ java.lang.class.privategetdeclaredmethods(unknown source) @ java.lang.class.privategetpublicmethods(unknown source) @ java.lang.class.getmethods(unknown source) @ org.codehaus.groovy.reflection.stdclasses.cachedsamclass.getsammethod(cachedsamclass.java:164) @ org.codehaus.groovy.reflection.classinfo.issam(classinfo.java:359) @ org.codehaus.groovy.reflection.classinfo.createcachedclass(classinfo.java:349) @ org.codehaus.groovy.reflection.classinfo.access$700(classinfo.java:41) @ org.codehaus.groovy.reflection.classinfo$lazycachedclassref.initvalue(classinfo.java:497) @ org.codehaus.groovy.reflection.classinfo$lazycachedclassref.initvalue(classinfo.java:488) @ org.codehaus.groovy.util.lazyreference.getlocked(lazyreference.java:49) @ org.codehaus.groovy.util.lazyreference.get(lazyreference.java:36) @ org.codehaus.groovy.reflection.classinfo.getcachedclass(classinfo.java:111) @ org.codehaus.groovy.reflection.reflectioncache.getcachedclass(reflectioncache.java:110) @ org.codehaus.groovy.reflection.cachedclass$8.initvalue(cachedclass.java:209) @ org.codehaus.groovy.reflection.cachedclass$8.initvalue(cachedclass.java:200) @ org.codehaus.groovy.util.lazyreference.getlocked(lazyreference.java:49) @ org.codehaus.groovy.util.lazyreference.get(lazyreference.java:36) @ org.codehaus.groovy.reflection.cachedclass.getinterfaces(cachedclass.java:252) @ org.codehaus.groovy.reflection.cachedclass.<init>(cachedclass.java:238) @ org.codehaus.groovy.reflection.classinfo.createcachedclass(classinfo.java:352) @ org.codehaus.groovy.reflection.classinfo.access$700(classinfo.java:41) @ org.codehaus.groovy.reflection.classinfo$lazycachedclassref.initvalue(classinfo.java:497) @ org.codehaus.groovy.reflection.classinfo$lazycachedclassref.initvalue(classinfo.java:488) @ org.codehaus.groovy.util.lazyreference.getlocked(lazyreference.java:49) @ org.codehaus.groovy.util.lazyreference.get(lazyreference.java:36) @ org.codehaus.groovy.reflection.classinfo.getcachedclass(classinfo.java:111) @ org.codehaus.groovy.reflection.reflectioncache.getcachedclass(reflectioncache.java:110) @ groovy.lang.metaclassimpl.<init>(metaclassimpl.java:180) @ groovy.lang.metaclassimpl.<init>(metaclassimpl.java:216) @ groovy.lang.metaclassimpl.<init>(metaclassimpl.java:228) @ groovy.lang.metaclassregistry$metaclasscreationhandle.createnormalmetaclass(metaclassregistry.java:171) @ groovy.lang.metaclassregistry$metaclasscreationhandle.createwithcustomlookup(metaclassregistry.java:161) @ groovy.lang.metaclassregistry$metaclasscreationhandle.create(metaclassregistry.java:144) @ org.codehaus.groovy.reflection.classinfo.getmetaclassunderlock(classinfo.java:253) @ org.codehaus.groovy.reflection.classinfo.getmetaclass(classinfo.java:285) @ org.codehaus.groovy.runtime.metaclass.metaclassregistryimpl.getmetaclass(metaclassregistryimpl.java:257) @ org.codehaus.groovy.runtime.invokerhelper.getmetaclass(invokerhelper.java:875) @ org.codehaus.groovy.runtime.scriptbytecodeadapter.initmetaclass(scriptbytecodeadapter.java:825) @ com.jayway.restassured.authentication.noauthscheme.$getstaticmetaclass(noauthscheme.groovy) @ com.jayway.restassured.authentication.noauthscheme.<init>(noauthscheme.groovy) @ com.jayway.restassured.restassured.<clinit>(restassured.java:317) @ restservicetest.main(restservicetest.java:16) caused by: java.lang.classnotfoundexception: groovyx.net.http.httpbuilder @ java.net.urlclassloader$1.run(unknown source) @ java.net.urlclassloader$1.run(unknown source) @ java.security.accesscontroller.doprivileged(native method) @ java.net.urlclassloader.findclass(unknown source) @ java.lang.classloader.loadclass(unknown source) @ sun.misc.launcher$appclassloader.loadclass(unknown source) @ java.lang.classloader.loadclass(unknown source) ... 43 more
can need create maven project or java project , add pom.xml file?
i added maven environmental variables.
you need create maven project , add dependencies pom.xml file , build maven project.
other dependencies need add :
<dependency> <groupid>com.jayway.restassured</groupid> <artifactid>rest-assured</artifactid> <version>2.5.0</version> </dependency> <dependency> <groupid>org.apache.httpcomponents</groupid> <artifactid>httpclient</artifactid> <version>4.5</version> </dependency>
Comments
Post a Comment