4

I keep getting this error that says provider "jar" not found even though my test passed. I run it using testNG and I am wondering if I need a jar file for this one? I tried searching it but I only found issues about zip and not jar. Please see my code below for reference. I also provided the response log on the bottom part.

TestScript.java

package com.api_test;

import static io.restassured.RestAssured.given;
import java.io.FileReader;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.testng.annotations.Test;
import static org.hamcrest.Matchers.*;


public class TestScript {
    static final String JSON_FILE = "src/test/script-resources/TestScript.json";
    @Test
    public void scriptTest() throws Exception {
        JSONParser parser = new JSONParser();
        Object obj = parser.parse(new FileReader(JSON_FILE));
        JSONObject jsonObject = (JSONObject) obj;
        System.out.println(jsonObject);
        given().
            header("content-type", "application/json").
            body(jsonObject.toJSONString()).
        when().
            post("https://petstore.swagger.io/v2/pet").
        then().
            statusCode(200).
            body("name", equalTo(jsonObject.get("name"))).
            log().all();
    }
}

TestScript.json // File for my request body

{
    "id": 1,
    "category": {
        "id": 1,
        "name": "dog"
    },
    "name": "browny",
    "status": "available"
}

Logs / Result

Picked up JAVA_TOOL_OPTIONS: -agentpath:"C:\WINDOWS\system32\Aternity\Java\JavaHookLoader.dll"="C:\ProgramData\Aternity\hooks"
[RemoteTestNG] detected TestNG version 7.3.0
{"name":"browny","id":1,"category":{"name":"dog","id":1},"status":"available"}
java.nio.file.ProviderNotFoundException: Provider "jar" not found
    at java.base/java.nio.file.FileSystems.newFileSystem(Unknown Source)
    at java.base/java.nio.file.FileSystems.newFileSystem(Unknown Source)
    at org.codehaus.groovy.vmplugin.v9.ClassFinder.newFileSystem(ClassFinder.java:158)
    at org.codehaus.groovy.vmplugin.v9.ClassFinder.find(ClassFinder.java:118)
    at org.codehaus.groovy.vmplugin.v9.ClassFinder.find(ClassFinder.java:107)
    at org.codehaus.groovy.vmplugin.v9.Java9.doFindClasses(Java9.java:107)
    at org.codehaus.groovy.vmplugin.v9.Java9.getDefaultImportClasses(Java9.java:89)
    at org.codehaus.groovy.control.ResolveVisitor.<clinit>(ResolveVisitor.java:641)
    at org.codehaus.groovy.runtime.InvokerHelper.<clinit>(InvokerHelper.java:807)
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.createMap(ScriptBytecodeAdapter.java:635)
    at io.restassured.internal.ResponseParserRegistrar.<init>(ResponseParserRegistrar.groovy)
    at io.restassured.RestAssured.<clinit>(RestAssured.java:347)
    at com.contentadmin.api_test.TestScript.scriptTest(TestScript.java:19)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.base/java.lang.reflect.Method.invoke(Unknown Source)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:132)
    at org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:599)
    at org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:174)
    at org.testng.internal.MethodRunner.runInSequence(MethodRunner.java:46)
    at org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:822)
    at org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:147)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128)
    at java.base/java.util.ArrayList.forEach(Unknown Source)
    at org.testng.TestRunner.privateRun(TestRunner.java:764)
    at org.testng.TestRunner.run(TestRunner.java:585)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:384)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:378)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:337)
    at org.testng.SuiteRunner.run(SuiteRunner.java:286)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1218)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)
    at org.testng.TestNG.runSuites(TestNG.java:1069)
    at org.testng.TestNG.run(TestNG.java:1037)
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
HTTP/1.1 200 OK
Date: Wed, 24 Feb 2021 12:17:42 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: keep-alive
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, POST, DELETE, PUT
Access-Control-Allow-Headers: Content-Type, api_key, Authorization
Server: Jetty(9.2.9.v20150224)

{
    "id": 1,
    "category": {
        "id": 1,
        "name": "dog"
    },
    "name": "browny",
    "photoUrls": [
        
    ],
    "tags": [
        
    ],
    "status": "available"
}
PASSED: scriptTest

===============================================
    Default test
    Tests run: 1, Failures: 0, Skips: 0
===============================================


===============================================
Default suite
Total tests run: 1, Passes: 1, Failures: 0, Skips: 0
===============================================
Newbie10
  • 99
  • 1
  • 14
  • 1
    The problem comes from within RestAssured: You code in `com.contentadmin.api_test.TestScript.scriptTest(TestScript.java:19)` calls `io.restassured.RestAssured.(RestAssured.java:347)`. The `` indicates problems with the static initialization blocks for the class, and static field initialization. So that is where the error happens. So looks like you haven't added all necessary libraries (youre probably following a tutorial). Or maybe one of the files is faulty. .jar files are just plain simple .zip files, so maybe checking the .jar file integrity might help. – JayC667 Mar 01 '21 at 23:53
  • Have you tried running your test without the Aternity performance monitoring Java agent? Is it even a good idea to run it for your tests? I guess it somehow transforms the byte code when it is being loaded. That might affect what same byte code looks like and how it behaves. – kriegaex Mar 03 '21 at 07:04
  • Hi @JayC667, yep I am just following a tutorial for it and maybe I am lacking some necessary libraries. I will try to investigate it look for it. I am not sure though on what am I lacking. Thanks for this! – Newbie10 Mar 04 '21 at 08:38
  • Hi @kriegaex, to be honest I didn't set up that Aternity thing, it is there from the beginning and I don't remember it being set up while I am building this. – Newbie10 Mar 04 '21 at 08:39
  • Well, Aternity seems to be a commercial product, so if you did not set it up, probably one of your co-workers did. Anyway, I guess it makes sense to test without that Java agent, just in order to see if it makes any difference before you look somewhere else. The instrumentation also makes your test runs slower, so I would only use it where it is necessary. As for tests, that would only be rather special integration test scenarios where you explicitly want to make sure that your tools used in production for performance monitoring don't clash with the actual code. – kriegaex Mar 04 '21 at 10:14
  • Oh, another idea that might help you find the culprit: if you have the source code available in your IDE, try to set a debug break point in `at org.codehaus.groovy.vmplugin.v9.ClassFinder.newFileSystem(ClassFinder.java:158)` , run the App in Debug Mode, and see what file they're looking for. Also browse along the stack trace (most IDEs offer those in Debug Mode) to see where the actual problem starts. If you do NOT have the source code, it's probably available for download somewhere. Then tell your IDE to add that source code as known sources for the linked jar/class files. – JayC667 Mar 05 '21 at 11:57
  • Why are you wasting the bounty by not providing feedback to my suggestion and also not providing an [MCVE](https://stackoverflow.com/help/mcve) to reproduce the problem. I would like to help, but like this I am unable to. Did you even try to do what I suggested and deactivate Aternity from the equation? – kriegaex Mar 08 '21 at 00:52
  • Hi @kriegaex, sorry I got a problem with my machine and can't get back to this thread as soon as I can. I have successfully removed Aternity from my system by uninstalling it but I have the same response from my run and the error still occurs. Thanks for your responses. – Newbie10 Mar 08 '21 at 11:29
  • Hi @JayC667, I am still researching for your first comment as I think I maybe lacking some libraries and as for your latest comment I don't have any idea about this but I will try this one also. Thanks for your ideas! – Newbie10 Mar 08 '21 at 11:31
  • You removed Aternity, i.e. in your log the `Picked up JAVA_TOOL_OPTIONS: -agentpath:"C:\WINDOWS\system32\Aternity\..."` should be gone, right? – kriegaex Mar 09 '21 at 01:48
  • Yep it's gone now, thanks for that but I think the jar issue is a different one. – Newbie10 Mar 09 '21 at 09:12

0 Answers0