use of net.sf.json.JsonConfig in project Java by Everything1sPossible.
the class jsonUtil method pageToJsonNotDatelist.
/**
* ����ҳʵ������ת��json,�ɹ����ֶ�
* @param result:��ҳʵ������
* @param filterFields:��Ҫ���˵�����
* @param dateFormat:���ڸ�ʽ��
* @return
*/
public static <T> String pageToJsonNotDatelist(PageResult<T> result, String[] filterFields, String dateFormat) {
Map<String, Object> jsonMap = new HashMap<String, Object>();
jsonMap.put("pageNo", result.getPageNo());
jsonMap.put("pageSize", result.getPageSize());
jsonMap.put("total", result.getTotal());
jsonMap.put("pages", result.getPages());
JsonConfig config = new JsonConfig();
if (filterFields != null) {
config.setExcludes(filterFields);
}
// 1 �������ڸ�ʽ
if (dateFormat == null || dateFormat.equals("")) {
// Ĭ��Ϊ������
dateFormat = "yyyy-MM-dd";
}
if (dateFormat != null) {
config.registerJsonValueProcessor(Date.class, new JsonDateTransform(dateFormat));
}
return JSONObject.fromObject(jsonMap, config).toString();
}
use of net.sf.json.JsonConfig in project jmeter-plugins-manager by undera.
the class PluginManagerTest method testApplyChanges.
@Test
public void testApplyChanges() throws Exception {
String imgPath = "file:///" + new File(".").getAbsolutePath() + "/target/classes/org/jmeterplugins/logo.png";
String str = "{\"id\": 0, \"markerClass\": \"" + PluginsListTest.class.getName() + "\"," + " \"screenshotUrl\": \"" + imgPath + "\", \"name\": 3, \"description\": 4, \"helpUrl\": 5, \"vendor\": 5, \"installerClass\": \"test\", " + "\"versions\" : { \"0.1\" : { \"changes\": \"fix verified exception1\" }," + "\"0.2\" : { \"changes\": \"fix verified exception1\", \"libs\": {\n" + " \"jpgc-common\": \"http://httpstat.us/500\"\n" + " }}," + "\"0.3\" : { \"changes\": \"fix verified exception1\", \"downloadUrl\": \"http://httpstat.us/500\" } }}";
String addr = JMeterUtils.getPropDefault("jpgc.repo.address", "https://jmeter-plugins.org/repo/");
try {
JMeterUtils.setProperty("jpgc.repo.address", "http://httpstat.us/500");
Plugin p = Plugin.fromJSON(JSONObject.fromObject(str, new JsonConfig()));
PluginManager manager = new PluginManager();
// need to install
manager.allPlugins.put(p, true);
p.setCandidateVersion("9999");
try {
manager.applyChanges(new GenericCallback<String>() {
@Override
public void notify(String progress) {
}
}, true, null);
fail();
} catch (IllegalArgumentException ex) {
assertTrue(ex.getMessage().contains("Version 9999 not found for plugin"));
}
// need to install
manager.allPlugins.put(p, true);
p.setCandidateVersion("0.2");
try {
manager.applyChanges(new GenericCallback<String>() {
@Override
public void notify(String progress) {
}
}, true, null);
fail();
} catch (DownloadException ex) {
assertTrue(ex.getMessage().contains("Failed to download library"));
}
manager = new PluginManager();
// need to install
manager.allPlugins.put(p, true);
p.setCandidateVersion("0.3");
try {
manager.applyChanges(new GenericCallback<String>() {
@Override
public void notify(String progress) {
}
}, true, null);
fail();
} catch (DownloadException ex) {
assertTrue(ex.getMessage().contains("Failed to download plugin"));
}
} finally {
JMeterUtils.setProperty("jpgc.repo.address", addr);
}
}
use of net.sf.json.JsonConfig in project jmeter-plugins-manager by undera.
the class PluginsListTest method testFlow.
@Test
public void testFlow() throws Exception {
String imgPath = "file:///" + new File(".").getAbsolutePath() + "/target/classes/org/jmeterplugins/logo.png";
String str = "{\"id\": 0, \"markerClass\": \"" + PluginsListTest.class.getName() + "\"," + " \"screenshotUrl\": \"" + imgPath + "\", \"name\": 3, \"description\": 4, \"helpUrl\": 5, \"vendor\": 5, \"installerClass\": \"test\", " + "\"versions\" : { \"0.1\" : { \"changes\": \"fix verified exception1\", \"downloadUrl\": \"https://search.maven.org/remotecontent?filepath=kg/apc/jmeter-plugins-webdriver/0.3/jmeter-plugins-webdriver-0.1.jar\" }," + "\"0.2\" : { \"changes\": \"fix verified exception1\", \"downloadUrl\": \"https://search.maven.org/remotecontent?filepath=kg/apc/jmeter-plugins-webdriver/0.3/jmeter-plugins-webdriver-0.2.jar\"}," + "\"0.3\" : { \"changes\": \"fix verified exception1\", " + "\"downloadUrl\": \"https://search.maven.org/remotecontent?filepath=kg/apc/jmeter-plugins-webdriver/0.3/jmeter-plugins-webdriver-0.3.jar\"} }}";
Plugin p = Plugin.fromJSON(JSONObject.fromObject(str, new JsonConfig()));
Set<Plugin> set = new HashSet<>();
set.add(p);
PluginsListExt pluginsList = new PluginsListExt(set, null, null);
pluginsList.getList().setSelectedIndex(0);
ListSelectionEvent event = new ListSelectionEvent("0.2", 0, 2, false);
pluginsList.valueChanged(event);
p.setCandidateVersion("0.3");
assertEquals("0.3", pluginsList.getCbVersion(pluginsList.getCheckboxItem(p, null)));
String desc = pluginsList.getDescriptionHTML(p);
assertFalse(desc.indexOf(EXPECTED_DESC_MAVEN) < 0);
assertFalse(desc.indexOf(EXPECTED_DESC_CHANGES) < 0);
p.detectInstalled(null);
assertEquals(Plugin.VER_STOCK, pluginsList.getCbVersion(pluginsList.getCheckboxItem(p, null)));
pluginsList.setEnabled(false);
assertFalse(pluginsList.getList().isEnabled());
assertFalse(pluginsList.getVersion().isEnabled());
assertFalse(pluginsList.getList().getModel().getElementAt(0).isEnabled());
JTextField searchField = pluginsList.searchField;
ListModel model = pluginsList.getList().getModel();
searchField.setText("not found plugin");
KeyEvent keyEvent = new KeyEvent(pluginsList.searchField, KeyEvent.KEY_RELEASED, 20, 1, KeyEvent.VK_Z, 'z');
KeyboardFocusManager.getCurrentKeyboardFocusManager().redispatchEvent(searchField, keyEvent);
searchField.dispatchEvent(keyEvent);
assertEquals(0, pluginsList.getList().getModel().getSize());
assertFalse(model == pluginsList.getList().getModel());
searchField.setText("");
KeyboardFocusManager.getCurrentKeyboardFocusManager().redispatchEvent(searchField, keyEvent);
searchField.dispatchEvent(keyEvent);
assertEquals(1, pluginsList.getList().getModel().getSize());
assertEquals(model, pluginsList.getList().getModel());
}
use of net.sf.json.JsonConfig in project jmeter-plugins-manager by undera.
the class RepoTest method testAll.
public void testAll() throws IOException {
Map<String, String> env = System.getenv();
if (env.containsKey("TRAVIS")) {
System.out.println("Not running test inside Travis CI");
return;
}
List<String> problems = new ArrayList<>();
File[] files = getRepoFiles();
JSONArray merged = new JSONArray();
for (File repoFile : files) {
System.out.println("Checking repo: " + repoFile.getCanonicalPath());
String content = new String(Files.readAllBytes(Paths.get(repoFile.getAbsolutePath())), "UTF-8");
JSON json = JSONSerializer.toJSON(content, new JsonConfig());
JSONArray list = (JSONArray) json;
for (Object item : list) {
JSONObject spec = (JSONObject) item;
checkPlugin(problems, repoFile, spec);
merged.add(spec);
}
}
if (problems.size() > 0) {
throw new AssertionFailedError(problems.toString());
}
try (PrintWriter out = new PrintWriter(new File(repo.getAbsolutePath() + s + "all.json"))) {
out.print(merged.toString(1));
}
}
use of net.sf.json.JsonConfig 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);
}
}
}
Aggregations