Search in sources :

Example 96 with JSONObject

use of net.sf.json.JSONObject in project jmeter-plugins-manager by undera.

the class DependencyResolverTest method testLibVersionManagement.

@Test
public void testLibVersionManagement() throws Exception {
    URL url = PluginManagerTest.class.getResource("/lib_versions.json");
    JSONArray jsonArray = (JSONArray) JSONSerializer.toJSON(FileUtils.readFileToString(new File(url.getPath())), new JsonConfig());
    Map<Plugin, Boolean> map = new HashMap<>();
    for (Object obj : jsonArray) {
        Plugin plugin = Plugin.fromJSON((JSONObject) obj);
        plugin.detectInstalled(new HashSet<Plugin>());
        map.put(plugin, true);
    }
    DependencyResolver resolver = new DependencyResolver(map);
    Map<String, String> libs = resolver.getLibAdditions();
    for (String libName : libs.keySet()) {
        if (libName.equals("jmeter-plugins-cmn-jmeter")) {
            assertEquals("jmeter-plugins-cmn-jmeter-0.4.jar", libs.get(libName));
        } else if (libName.equals("kafka_2.8.2")) {
            assertEquals("kafka_2.8.2_v0.8.jar", libs.get(libName));
        } else if (libName.equals("commons-io")) {
            assertEquals("commons-io.jar", libs.get(libName));
        } else if (libName.equals("kafka_2.1.0")) {
            assertEquals("kafka_2.1.0_v.0.1.jar", libs.get(libName));
        } else if (libName.equals("lib")) {
            assertEquals("lib-0.8.jar", libs.get(libName));
        } else if (libName.equals("lib2")) {
            assertEquals("lib2-0.2.jar", libs.get(libName));
        } else {
            fail("Unexpected lib name: " + libName);
        }
    }
}
Also used : HashMap(java.util.HashMap) JsonConfig(net.sf.json.JsonConfig) JSONArray(net.sf.json.JSONArray) URL(java.net.URL) JSONObject(net.sf.json.JSONObject) File(java.io.File) Test(org.junit.Test)

Example 97 with JSONObject

use of net.sf.json.JSONObject in project jmeter-plugins-manager by undera.

the class DependencyResolverTest method testResolveLibBeforeDetete.

@Test
public void testResolveLibBeforeDetete() throws Exception {
    URL url = PluginManagerTest.class.getResource("/lib_for_delete");
    JSONArray jsonArray = (JSONArray) JSONSerializer.toJSON(FileUtils.readFileToString(new File(url.getPath())), new JsonConfig());
    Map<Plugin, Boolean> map = new HashMap<>();
    for (Object obj : jsonArray) {
        Plugin plugin = Plugin.fromJSON((JSONObject) obj);
        plugin.detectInstalled(new HashSet<Plugin>());
        plugin.installedPath = "";
        plugin.installedVersion = "0.1";
        map.put(plugin, !plugin.getName().startsWith("delete"));
    }
    DependencyResolver resolver = new DependencyResolver(map);
    Set<String> libs = resolver.getLibDeletions();
    assertEquals(3, libs.size());
    assertTrue(libs.contains("ApacheJMeter_core"));
    assertTrue(libs.contains("commons-lang3"));
    assertTrue(libs.contains("commons-httpclient"));
}
Also used : HashMap(java.util.HashMap) JsonConfig(net.sf.json.JsonConfig) JSONArray(net.sf.json.JSONArray) URL(java.net.URL) JSONObject(net.sf.json.JSONObject) File(java.io.File) Test(org.junit.Test)

Example 98 with JSONObject

use of net.sf.json.JSONObject in project jmeter-plugins-manager by undera.

the class DependencyResolverTest method testResolveDowngradeWithNPE.

@Test
public void testResolveDowngradeWithNPE() throws Exception {
    URL url = PluginManagerTest.class.getResource("/self_npe.json");
    JSONArray jsonArray = (JSONArray) JSONSerializer.toJSON(FileUtils.readFileToString(new File(url.getPath())), new JsonConfig());
    Map<Plugin, Boolean> map = new HashMap<>();
    for (Object obj : jsonArray) {
        Plugin plugin = Plugin.fromJSON((JSONObject) obj);
        plugin.detectInstalled(new HashSet<Plugin>());
        plugin.installedPath = "";
        plugin.installedVersion = "0.14";
        plugin.candidateVersion = "0.13";
        map.put(plugin, true);
    }
    DependencyResolver resolver = new DependencyResolver(map);
    Map<String, String> libs = resolver.getLibAdditions();
    assertEquals(1, libs.size());
    assertNotNull(libs.get("cmdbeginner"));
    Set<Plugin> pluginsAdd = resolver.getAdditions();
    assertEquals(1, pluginsAdd.size());
    assertEquals("jpgc-plugins-manager", pluginsAdd.toArray(new Plugin[1])[0].getID());
    Set<Plugin> pluginsDelete = resolver.getDeletions();
    assertEquals(1, pluginsDelete.size());
    assertEquals("jpgc-plugins-manager", pluginsDelete.toArray(new Plugin[1])[0].getID());
}
Also used : HashMap(java.util.HashMap) JsonConfig(net.sf.json.JsonConfig) JSONArray(net.sf.json.JSONArray) URL(java.net.URL) JSONObject(net.sf.json.JSONObject) File(java.io.File) Test(org.junit.Test)

Example 99 with JSONObject

use of net.sf.json.JSONObject in project jmeter-plugins-manager by undera.

the class DependencyResolverTest method testUpdateWhenInstall.

@Test
public void testUpdateWhenInstall() throws Exception {
    URL url = PluginManagerTest.class.getResource("/installed.json");
    JSONArray jsonArray = (JSONArray) JSONSerializer.toJSON(FileUtils.readFileToString(new File(url.getPath())), new JsonConfig());
    Map<Plugin, Boolean> map = new HashMap<>();
    for (Object obj : jsonArray) {
        Plugin plugin = Plugin.fromJSON((JSONObject) obj);
        plugin.detectInstalled(new HashSet<Plugin>());
        map.put(plugin, true);
    }
    DependencyResolver resolver = new DependencyResolver(map);
    Set<String> libsDeletions = resolver.getLibDeletions();
    assertEquals(1, libsDeletions.size());
    assertTrue(libsDeletions.contains("commons-codec"));
    Map<String, String> libsAdditions = resolver.getLibAdditions();
    assertEquals(1, libsAdditions.size());
    assertEquals("commons-codec-99.99.jar", libsAdditions.get("commons-codec"));
}
Also used : HashMap(java.util.HashMap) JsonConfig(net.sf.json.JsonConfig) JSONArray(net.sf.json.JSONArray) URL(java.net.URL) JSONObject(net.sf.json.JSONObject) File(java.io.File) Test(org.junit.Test)

Example 100 with JSONObject

use of net.sf.json.JSONObject in project jmeter-plugins-manager by undera.

the class Plugin method getDepends.

public Set<String> getDepends() {
    Set<String> depends = new HashSet<>();
    JSONObject version = versions.getJSONObject(getCandidateVersion());
    if (version.containsKey("depends")) {
        JSONArray list = version.getJSONArray("depends");
        for (Object o : list) {
            if (o instanceof String) {
                String dep = (String) o;
                Matcher m = dependsParser.matcher(dep);
                if (!m.find()) {
                    throw new IllegalArgumentException("Cannot parse depend str: " + dep);
                }
                depends.add(m.group(1));
            }
        }
    }
    return depends;
}
Also used : JSONObject(net.sf.json.JSONObject) Matcher(java.util.regex.Matcher) JSONArray(net.sf.json.JSONArray) JSONObject(net.sf.json.JSONObject) HashSet(java.util.HashSet)

Aggregations

JSONObject (net.sf.json.JSONObject)493 Test (org.junit.Test)99 JSONArray (net.sf.json.JSONArray)94 IOException (java.io.IOException)49 HashMap (java.util.HashMap)48 ArrayList (java.util.ArrayList)36 JSON (net.sf.json.JSON)26 PrintWriter (java.io.PrintWriter)25 Map (java.util.Map)23 File (java.io.File)21 InputStream (java.io.InputStream)18 URISyntaxException (java.net.URISyntaxException)15 UnsupportedEncodingException (java.io.UnsupportedEncodingException)14 JsonConfig (net.sf.json.JsonConfig)14 FreeStyleBuild (hudson.model.FreeStyleBuild)13 URI (java.net.URI)13 URL (java.net.URL)13 JSONException (net.sf.json.JSONException)13 Context (org.zaproxy.zap.model.Context)12 Transactional (org.springframework.transaction.annotation.Transactional)11