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"));
}
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"));
}
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());
}
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());
}
}
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());
}
}
Aggregations