Service Virtualization

 View Only
  • 1.  Error when trying to create and run a sample test using SV as code

    Posted Jul 21, 2017 10:28 AM

    java.lang.ExceptionInInitializerError at com.ca.svcode.protocols.http.agent.HttpAgentProtocol.getInterceptor(HttpAgentProtocol.java:77) at com.ca.svcode.protocols.http.agent.HttpAgentProtocol.getInterceptor(HttpAgentProtocol.java:48) at com.ca.svcode.engine.IpvConnectedServer.start(IpvConnectedServer.java:135) at com.ca.svcode.engine.IpvProtocolServer.withConnection(IpvProtocolServer.java:67) at com.ca.svcode.protocols.http.fluent.impl.HttpTransactionBuilderImpl.buildTransaction(HttpTransactionBuilderImpl.java:77) at com.ca.svcode.protocols.http.fluent.AbstractHttpTransactionBuilder.doReturn(AbstractHttpTransactionBuilder.java:132) at svascode.SVAsCodeTests.testSimpleHttpGetWithResponseCodeAndStringBody(SVAsCodeTests.java:24) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:48) at org.junit.rules.RunRules.evaluate(RunRules.java:20) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192) Caused by: java.lang.RuntimeException: Cannot load initialize agent with HTTP Protocol. at com.ca.svcode.protocols.http.agent.HttpInterceptor.(HttpInterceptor.java:45) ... 32 more Caused by: com.ca.svcode.agent.AgentException: Failed to initialize agent for protocol at com.ca.svcode.agent.Agent.initialize(Agent.java:76) at com.ca.svcode.protocols.http.agent.HttpInterceptor.(HttpInterceptor.java:43) ... 32 more Caused by: java.lang.RuntimeException: java.lang.ClassNotFoundException: com.sun.tools.attach.VirtualMachine at com.ca.svcode.agent.AgentLoader.loadAgent(AgentLoader.java:62) at com.ca.svcode.agent.Agent.initialize(Agent.java:70) ... 33 more Caused by: java.lang.ClassNotFoundException: com.sun.tools.attach.VirtualMachine at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at com.ca.svcode.agent.AgentLoader.dynamicLoadOfVirtualMachine(AgentLoader.java:87) at com.ca.svcode.agent.AgentLoader.loadAgent(AgentLoader.java:60) ... 34 more

     

     

    And here's my code:

     

    package svascode;

    import static com.ca.svcode.protocols.http.fluent.HttpFluentInterface.*;
    import static io.restassured.RestAssured.*;
    import static org.hamcrest.Matchers.*;

    import java.io.IOException;
    import org.junit.Rule;
    import org.junit.Test;
    import com.ca.svcode.engine.junit4.VirtualServerRule;

    public class SVAsCodeTests {

    private static final String URL = "http://www.ca.com/portfolio";

    private static String RESPONSE_BODY_GET = "Response body from virtualized service.";
    private static int CUSTOM_STATUS_CODE = 258;

    @Rule
    public VirtualServerRule vs = new VirtualServerRule();

    @Test
    public void testSimpleHttpGetWithResponseCodeAndStringBody() throws IOException {

    forGet(URL).doReturn(
    aMessage(CUSTOM_STATUS_CODE)
    .withStringBody(RESPONSE_BODY_GET)
    );

    given().
    when().
    get(URL).
    then().
    assertThat().
    statusCode(CUSTOM_STATUS_CODE).
    and().
    body(equalTo(RESPONSE_BODY_GET));
    }
    }



  • 2.  Re: Error when trying to create and run a sample test using SV as code
    Best Answer

    Broadcom Employee
    Posted Aug 09, 2017 04:54 PM

    This seems to be a class not found exception. Please verify if all the below sv as code specific jars have been referenced in the project or not. 

     

    svcode-agent-1.0.0.jar

    svcode-api-1.0.0.jar

    svcode-engine-1.0.0.jar

    svcode-protocols-1.0.0.jar

    svcode-sdk-1.0.0.jar

     

    Note: You also need to add the dependent jars present in the lib folder of the downloaded zip from github. 

     

    GitHub - CA-DevTest/SV-as-Code: A fluent Java API for virtualizing HTTP services. Service virtualization simplified. No… 

     

    Please let us know. 

     

    Thanks,

    Surya.



  • 3.  Re: Error when trying to create and run a sample test using SV as code

    Posted Aug 17, 2017 11:03 AM

    You're probably missing tools.jar from your classpath.  It's in the JDK lib folder so it ought to be picked up automatically by your IDE.  If you're running from the command line, make sure you're using java from a JDK and not JRE.



  • 4.  Re: Error when trying to create and run a sample test using SV as code

    Posted Aug 22, 2017 02:11 AM

    Hi All,

     

    Even I am facing same issue. Included all dependent JARs but still getting same error. Need help !!!



  • 5.  Re: Error when trying to create and run a sample test using SV as code

    Posted Aug 22, 2017 04:22 AM

    Dear user,

     

    Please try using a jdk instead of jre in project library and then try. PFB the steps :

     

    1)Right click your project > properties
    2)Select “Java Build Path” on left, then “JRE System Library”, click Edit…
    3)Select "Workspace Default JRE"
    4)Click "Installed JREs"
    5)If you see JRE you want in the list select it (selecting a JDK is OK too)
    6)If not, click Search…, navigate to Computer > Windows C: > Program Files > Java, then click OK
    7)Now you should see all installed JREs, select the one you want
    8)Click OK/Finish

     

    It resolved issue in my machine



  • 6.  Re: Error when trying to create and run a sample test using SV as code

    Posted Nov 08, 2017 03:34 PM

    Had the same issue and above steps fixed the problem.

     

    Thanks for the post.

     

    Alan



  • 7.  Re: Error when trying to create and run a sample test using SV as code

    Posted Mar 27, 2019 01:07 PM

    Had similar problem. Needed to select jre from installed jdk folder

    1)Right click your project > properties
    2)Select “Java Build Path” on left, then “JRE System Library”, click Edit…

    3) Select Alternate JRE

    4)Click "Installed JREs"
    5)If you see JRE you want in the list, select it and Edit to select jdk from Computer > Windows C: > Program Files > Java > jdk (JRE home directory)
    6)Now you should see all installed JREs, select the one you want
    7)Click OK/Finish