AnsweredAssumed Answered

Error when trying to create and run a sample test using SV as code

Question asked by basdijkstra on Jul 21, 2017
Latest reply on Nov 8, 2017 by rooal01

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));
}
}

Outcomes