Search in sources :

Example 21 with JsonConfig

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

the class DependencyResolverTest method testResolveLibIfLibBroken.

@Test
public void testResolveLibIfLibBroken() throws Exception {
    URL url = PluginManagerTest.class.getResource("/broken.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.1";
        map.put(plugin, true);
    }
    DependencyResolver resolver = new DependencyResolver(map);
    Set<String> libs = resolver.getLibDeletions();
    assertEquals(1, libs.size());
    assertTrue(libs.contains("bsf"));
    Map<String, String> libAdditions = resolver.getLibAdditions();
    assertEquals(1, libAdditions.size());
    assertEquals("lib-99.8.jar", libAdditions.get("bsf"));
}
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 22 with JsonConfig

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

the class DependencyResolverTest method testUpdateLibWithPlugin.

@Test
public void testUpdateLibWithPlugin() throws Exception {
    URL url = PluginManagerTest.class.getResource("/lib_update.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.1";
        map.put(plugin, true);
    }
    DependencyResolver resolver = new DependencyResolver(map);
    Set<String> libsDeletions = resolver.getLibDeletions();
    assertEquals(2, libsDeletions.size());
    assertTrue(libsDeletions.contains("cmdrunner"));
    assertTrue(libsDeletions.contains("commons-codec"));
    Map<String, String> libsAdditions = resolver.getLibAdditions();
    assertEquals(2, libsAdditions.size());
    assertEquals("cmdrunner-9999.8.jar", libsAdditions.get("cmdrunner"));
    assertEquals("commons-codec-999.5.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 23 with JsonConfig

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

the class DependencyResolverTest method testResolveMissingLib.

@Test
public void testResolveMissingLib() 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";
        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 24 with JsonConfig

use of net.sf.json.JsonConfig in project onebusaway-application-modules by camsys.

the class CustomJsonLibHandler method toObject.

public void toObject(Reader in, Object target) throws IOException {
    StringBuilder sb = new StringBuilder();
    char[] buffer = new char[1024];
    int len = 0;
    while ((len = in.read(buffer)) > 0) {
        sb.append(buffer, 0, len);
    }
    if (target != null && sb.length() > 0 && sb.charAt(0) == '[') {
        JSONArray jsonArray = JSONArray.fromObject(sb.toString());
        if (target.getClass().isArray()) {
            JSONArray.toArray(jsonArray, target, new JsonConfig());
        } else {
            JSONArray.toList(jsonArray, target, new JsonConfig());
        }
    } else {
        JSONObject jsonObject = JSONObject.fromObject(sb.toString());
        JSONObject.toBean(jsonObject, target, new JsonConfig());
    }
}
Also used : JSONObject(net.sf.json.JSONObject) JsonConfig(net.sf.json.JsonConfig) JSONArray(net.sf.json.JSONArray)

Example 25 with JsonConfig

use of net.sf.json.JsonConfig in project onebusaway-application-modules by camsys.

the class CustomJsonLibHandler method toObject.

public void toObject(Reader in, Object target) throws IOException {
    StringBuilder sb = new StringBuilder();
    char[] buffer = new char[1024];
    int len = 0;
    while ((len = in.read(buffer)) > 0) {
        sb.append(buffer, 0, len);
    }
    if (target != null && sb.length() > 0 && sb.charAt(0) == '[') {
        JSONArray jsonArray = JSONArray.fromObject(sb.toString());
        if (target.getClass().isArray()) {
            JSONArray.toArray(jsonArray, target, new JsonConfig());
        } else {
            JSONArray.toList(jsonArray, target, new JsonConfig());
        }
    } else {
        JSONObject jsonObject = JSONObject.fromObject(sb.toString());
        JSONObject.toBean(jsonObject, target, new JsonConfig());
    }
}
Also used : JSONObject(net.sf.json.JSONObject) JsonConfig(net.sf.json.JsonConfig) JSONArray(net.sf.json.JSONArray)

Aggregations

JsonConfig (net.sf.json.JsonConfig)28 JSONObject (net.sf.json.JSONObject)17 File (java.io.File)10 HashMap (java.util.HashMap)10 JSONArray (net.sf.json.JSONArray)10 Test (org.junit.Test)10 URL (java.net.URL)7 PrintWriter (java.io.PrintWriter)5 JSON (net.sf.json.JSON)5 Writer (java.io.Writer)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 NewBeanInstanceStrategy (net.sf.json.util.NewBeanInstanceStrategy)2 FlexClass (org.jaffa.flexfields.FlexClass)2 FlexCriteriaBean (org.jaffa.flexfields.FlexCriteriaBean)2 Status (io.milton.http.Response.Status)1 NameAndError (io.milton.http.webdav.PropFindResponse.NameAndError)1 CollectionResource (io.milton.resource.CollectionResource)1