List of usage examples for org.json JSONObject get
public Object get(String key) throws JSONException
From source file:org.wso2.carbon.connector.integration.test.spotify.SpotifyConnectorIntegrationTest.java
/** * Mandatory parameter test case for getAnAlbumMetadata method. *///from w w w. j a v a2s. c o m @Test(enabled = true, groups = { "wso2.esb" }, description = "spotify {getAnAlbumMetadata} integration test with mandatory parameter.") public void testGetAnAlbumMetadataWithMandatoryParameter() throws Exception { String jsonRequestFilePath = pathToRequestsDirectory + "getAnAlbumMetadata_Mandatory.txt"; String methodName = "spotify"; final String jsonString = ConnectorIntegrationUtil.getFileContent(jsonRequestFilePath); final String proxyFilePath = "file:///" + pathToProxiesDirectory + methodName + ".xml"; proxyAdmin.addProxyService(new DataHandler(new URL(proxyFilePath))); String modifiedJsonString = String.format(jsonString, spotifyConnectorProperties.getProperty("albumId1")); JSONObject jsonResponse; try { jsonResponse = ConnectorIntegrationUtil.sendRequest(getProxyServiceURL(methodName), modifiedJsonString); JSONObject jsonObject = new JSONObject(modifiedJsonString); Assert.assertEquals(jsonResponse.getString("id"), jsonObject.get("albumId")); } finally { proxyAdmin.deleteProxy(methodName); } }
From source file:org.wso2.carbon.connector.integration.test.spotify.SpotifyConnectorIntegrationTest.java
/** * Optional parameter test case for getAnAlbumsTracks method. *//*w w w . j a v a 2s. c o m*/ @Test(enabled = true, groups = { "wso2.esb" }, description = "spotify {getAnAlbumsTracks} integration test with optional parameter.") public void testGetAnAlbumsTracksWithOptionalParameters() throws Exception { String jsonRequestFilePath = pathToRequestsDirectory + "getAnAlbumsTracks_Optional.txt"; String methodName = "spotify"; final String jsonString = ConnectorIntegrationUtil.getFileContent(jsonRequestFilePath); final String proxyFilePath = "file:///" + pathToProxiesDirectory + methodName + ".xml"; proxyAdmin.addProxyService(new DataHandler(new URL(proxyFilePath))); String modifiedJsonString = String.format(jsonString, spotifyConnectorProperties.getProperty("albumId1")); JSONObject jsonResponse; try { jsonResponse = ConnectorIntegrationUtil.sendRequest(getProxyServiceURL(methodName), modifiedJsonString); JSONObject jsonObject = new JSONObject(modifiedJsonString); Assert.assertEquals(jsonResponse.getString("limit"), jsonObject.get("spotifylimit")); } finally { proxyAdmin.deleteProxy(methodName); } }
From source file:org.wso2.carbon.connector.integration.test.spotify.SpotifyConnectorIntegrationTest.java
/** * Optional parameter test case for searchForAnItem method. *//*from w ww . j a va2 s.c o m*/ @Test(enabled = true, groups = { "wso2.esb" }, description = "spotify {searchForAnItem} integration test with optional parameter.") public void testSearchForAnItemWithOptionalParameters() throws Exception { String jsonRequestFilePath = pathToRequestsDirectory + "searchForAnItem_Optional.txt"; String methodName = "spotify"; final String jsonString = ConnectorIntegrationUtil.getFileContent(jsonRequestFilePath); final String proxyFilePath = "file:///" + pathToProxiesDirectory + methodName + ".xml"; proxyAdmin.addProxyService(new DataHandler(new URL(proxyFilePath))); String modifiedJsonString = String.format(jsonString, spotifyConnectorProperties.getProperty("albumId1")); JSONObject jsonResponse; try { jsonResponse = ConnectorIntegrationUtil.sendRequest(getProxyServiceURL(methodName), modifiedJsonString); JSONObject jsonObject = new JSONObject(jsonString); Assert.assertEquals(jsonResponse.getJSONObject("albums").getString("limit"), jsonObject.get("spotifylimit")); } finally { proxyAdmin.deleteProxy(methodName); } }
From source file:org.wso2.carbon.connector.integration.test.spotify.SpotifyConnectorIntegrationTest.java
/** * Optional parameter test case for getAListUsersPlaylists method. *///from ww w.jav a2s .co m @Test(enabled = true, groups = { "wso2.esb" }, description = "spotify {GetAListUsersPlaylists} integration test with optional parameter.") public void testGetAListUsersPlaylistsOptionalParameter() throws Exception { String jsonRequestFilePath = pathToRequestsDirectory + "getAListUsersPlaylists_Optional.txt"; String methodName = "spotify"; final String jsonString = ConnectorIntegrationUtil.getFileContent(jsonRequestFilePath); String modifiedJsonString = String.format(jsonString, spotifyConnectorProperties.getProperty("clientId"), spotifyConnectorProperties.getProperty("clientSecret"), spotifyConnectorProperties.getProperty("grantType"), spotifyConnectorProperties.getProperty("refreshToken"), spotifyConnectorProperties.getProperty("userId")); final String proxyFilePath = "file:///" + pathToProxiesDirectory + methodName + ".xml"; proxyAdmin.addProxyService(new DataHandler(new URL(proxyFilePath))); JSONObject jsonResponse; try { jsonResponse = ConnectorIntegrationUtil.sendRequest(getProxyServiceURL(methodName), modifiedJsonString); JSONObject jsonObject = new JSONObject(jsonString); Assert.assertEquals(jsonResponse.getString("limit"), jsonObject.get("spotifylimit")); } finally { proxyAdmin.deleteProxy(methodName); } }
From source file:org.wso2.carbon.connector.integration.test.spotify.SpotifyConnectorIntegrationTest.java
/** * Mandatory parameter test case for getAPlaylist method. *///from w w w. ja v a2 s . c o m @Test(enabled = true, groups = { "wso2.esb" }, dependsOnMethods = { "testCreateAPlaylistMandatoryParameter" }, description = "spotify {getAListUsersLPlaylists} integration test with mandatory parameter.") public void testGetAPlaylistMandatoryParameter() throws Exception { String jsonRequestFilePath = pathToRequestsDirectory + "getAPlaylist_Mandatory.txt"; String methodName = "spotify"; final String jsonString = ConnectorIntegrationUtil.getFileContent(jsonRequestFilePath); String modifiedJsonString = String.format(jsonString, spotifyConnectorProperties.getProperty("clientId"), spotifyConnectorProperties.getProperty("clientSecret"), spotifyConnectorProperties.getProperty("grantType"), spotifyConnectorProperties.getProperty("refreshToken"), spotifyConnectorProperties.getProperty("userId"), spotifyConnectorProperties.getProperty("playListId")); final String proxyFilePath = "file:///" + pathToProxiesDirectory + methodName + ".xml"; proxyAdmin.addProxyService(new DataHandler(new URL(proxyFilePath))); JSONObject jsonResponse; try { jsonResponse = ConnectorIntegrationUtil.sendRequest(getProxyServiceURL(methodName), modifiedJsonString); JSONObject jsonObject = new JSONObject(modifiedJsonString); Assert.assertEquals(jsonResponse.getString("id"), jsonObject.get("playListId")); } finally { proxyAdmin.deleteProxy(methodName); } }
From source file:org.wso2.carbon.connector.integration.test.spotify.SpotifyConnectorIntegrationTest.java
/** * Mandatory parameter test case for createAPlaylist method. *///from w w w .j a va2 s.com @Test(enabled = true, groups = { "wso2.esb" }, description = "spotify {createAPlaylist} integration test with mandatory parameter.") public void testCreateAPlaylistMandatoryParameter() throws Exception { String jsonRequestFilePath = pathToRequestsDirectory + "createAPlaylist_Mandatory.txt"; String methodName = "spotify"; final String jsonString = ConnectorIntegrationUtil.getFileContent(jsonRequestFilePath); String modifiedJsonString = String.format(jsonString, spotifyConnectorProperties.getProperty("clientId"), spotifyConnectorProperties.getProperty("clientSecret"), spotifyConnectorProperties.getProperty("grantType"), spotifyConnectorProperties.getProperty("refreshToken"), spotifyConnectorProperties.getProperty("userId")); final String proxyFilePath = "file:///" + pathToProxiesDirectory + methodName + ".xml"; proxyAdmin.addProxyService(new DataHandler(new URL(proxyFilePath))); JSONObject jsonResponse; try { jsonResponse = ConnectorIntegrationUtil.sendRequest(getProxyServiceURL(methodName), modifiedJsonString); spotifyConnectorProperties.setProperty("playListId", jsonResponse.getString("id")); JSONObject jsonObject = new JSONObject(jsonString); Assert.assertEquals(jsonResponse.getString("name"), jsonObject.get("name")); } finally { proxyAdmin.deleteProxy(methodName); } }
From source file:org.wso2.carbon.connector.integration.test.spotify.SpotifyConnectorIntegrationTest.java
/** * Optional parameter test case for createAPlaylist method. *///from w ww.ja va2 s .c o m @Test(enabled = true, groups = { "wso2.esb" }, description = "spotify {createAPlaylist} integration test with optional parameter.") public void testCreateAPlaylistOptionalParameter() throws Exception { String jsonRequestFilePath = pathToRequestsDirectory + "createAPlaylist_Optional.txt"; String methodName = "spotify"; final String jsonString = ConnectorIntegrationUtil.getFileContent(jsonRequestFilePath); String modifiedJsonString = String.format(jsonString, spotifyConnectorProperties.getProperty("clientId"), spotifyConnectorProperties.getProperty("clientSecret"), spotifyConnectorProperties.getProperty("grantType"), spotifyConnectorProperties.getProperty("refreshToken"), spotifyConnectorProperties.getProperty("userId")); final String proxyFilePath = "file:///" + pathToProxiesDirectory + methodName + ".xml"; proxyAdmin.addProxyService(new DataHandler(new URL(proxyFilePath))); JSONObject jsonResponse; try { jsonResponse = ConnectorIntegrationUtil.sendRequest(getProxyServiceURL(methodName), modifiedJsonString); JSONObject jsonObject = new JSONObject(jsonString); Assert.assertEquals(jsonResponse.getString("name"), jsonObject.get("name")); } finally { proxyAdmin.deleteProxy(methodName); } }
From source file:org.qi4j.entitystore.sql.SQLEntityStoreMixin.java
protected DefaultEntityState readEntityState(DefaultEntityStoreUnitOfWork unitOfWork, Reader entityState) throws EntityStoreException { try {/* w ww . j a v a2 s. c om*/ ModuleSPI module = unitOfWork.module(); JSONObject jsonObject = new JSONObject(new JSONTokener(entityState)); EntityStatus status = EntityStatus.LOADED; String version = jsonObject.getString("version"); long modified = jsonObject.getLong("modified"); String identity = jsonObject.getString("identity"); // Check if version is correct String currentAppVersion = jsonObject.optString(MapEntityStore.JSONKeys.application_version.name(), "0.0"); if (!currentAppVersion.equals(application.version())) { if (migration != null) { migration.migrate(jsonObject, application.version(), this); } else { // Do nothing - set version to be correct jsonObject.put(MapEntityStore.JSONKeys.application_version.name(), application.version()); } LOGGER.trace("Updated version nr on {} from {} to {}", new Object[] { identity, currentAppVersion, application.version() }); // State changed status = EntityStatus.UPDATED; } String type = jsonObject.getString("type"); EntityDescriptor entityDescriptor = module.entityDescriptor(type); if (entityDescriptor == null) { throw new EntityTypeNotFoundException(type); } Map<QualifiedName, Object> properties = new HashMap<QualifiedName, Object>(); JSONObject props = jsonObject.getJSONObject("properties"); for (PropertyDescriptor propertyDescriptor : entityDescriptor.state().properties()) { Object jsonValue; try { jsonValue = props.get(propertyDescriptor.qualifiedName().name()); } catch (JSONException e) { // Value not found, default it Object initialValue = propertyDescriptor.initialValue(); properties.put(propertyDescriptor.qualifiedName(), initialValue); status = EntityStatus.UPDATED; continue; } if (jsonValue == JSONObject.NULL) { properties.put(propertyDescriptor.qualifiedName(), null); } else { Object value = ((PropertyTypeDescriptor) propertyDescriptor).propertyType().type() .fromJSON(jsonValue, module); properties.put(propertyDescriptor.qualifiedName(), value); } } Map<QualifiedName, EntityReference> associations = new HashMap<QualifiedName, EntityReference>(); JSONObject assocs = jsonObject.getJSONObject("associations"); for (AssociationDescriptor associationType : entityDescriptor.state().associations()) { try { Object jsonValue = assocs.get(associationType.qualifiedName().name()); EntityReference value = jsonValue == JSONObject.NULL ? null : EntityReference.parseEntityReference((String) jsonValue); associations.put(associationType.qualifiedName(), value); } catch (JSONException e) { // Association not found, default it to null associations.put(associationType.qualifiedName(), null); status = EntityStatus.UPDATED; } } Map<QualifiedName, List<EntityReference>> manyAssociations = createManyAssociations(jsonObject, entityDescriptor); Map<QualifiedName, Map<String, EntityReference>> namedAssociations = createNamedAssociations(jsonObject, entityDescriptor); return new DefaultEntityState(unitOfWork, version, modified, EntityReference.parseEntityReference(identity), status, entityDescriptor, properties, associations, manyAssociations, namedAssociations); } catch (JSONException e) { throw new EntityStoreException(e); } }
From source file:clases.Main.java
public static void main(String[] args) { try {//www . j av a2 s . com Manejador admin = new Manejador(); admin.setRuta("notebooks.json"); admin.Conectar(); admin.setNom_bd("notebooks"); admin.setNom_coleccion("notebooks"); DateFormat format_date = new SimpleDateFormat("yyyy-MM-dd"); Date fecha = new Date(); String date_now = format_date.format(fecha); JSONObject param_1 = new JSONObject("{id_notebook: 1}"); JSONObject busqueda = admin.Select(param_1); if (busqueda.has("id") && busqueda.get("id").equals(0)) { System.out.println(busqueda.toString(4)); } else { JSONObject[] obj_param_arr = { new JSONObject("{ notes: [{id_note: 1}] }"), new JSONObject("{ prueba: [{id_pedo: 1}] }") }; JSONObject nota = admin.SelectIntoArray(busqueda, obj_param_arr[0]); String claves = "\"HESOYAM\\nLXGIWYL\""; String str_js = "{ notes: [{titulo: Claves GTA San andreas PC, note: " + claves + ", fecha_modificacion: " + date_now + "}] }"; String str_js2 = "{ prueba: [{texto: HOla}] }"; String str_js3 = "{ notes: [{note: \"No c, weno si c pero no te wa decir\"}] }"; String[] arr_changes = { str_js, str_js2, str_js3 }; /*JSONObject cambios = new JSONObject(arr_changes[2]); boolean exito = admin.updateIntoArray(nota, cambios); if(exito) { System.out.println("Registro editado de manera satisfactoria!"); } else { System.out.println("Registro no encontrado"); }*/ String[] targets = { "{ notes: [{id_note: 1}] }" }; //admin.delete(param_1); JSONObject target = new JSONObject(targets[0]); admin.deleteIntoArray(busqueda, target); } /* JSONObject cambio = new JSONObject("{nombre: Cronicas Rata, fecha_modificacion: \""+ date_now +"\"}"); boolean exito = admin.update(new JSONObject("{id_notebook: 2}"), cambio); if(exito) { System.out.println("Registro modificado de manera satisfactoria"); }*/ } catch (FileNotFoundException fe) { fe.printStackTrace(); } catch (IOException ioe) { ioe.printStackTrace(); } catch (JSONException je) { je.printStackTrace(); } }
From source file:menusearch.json.JSONProcessor.java
/** * //from www. j a va 2 s.co m * @param results: requires the JSON string of the parameters the user enter for the search * @return a RecipeSummaryList where it contains information about the recipes that matches the search the user made * @throws IOException * @throws JSONException */ public static RecipeSummaryList parseRecipes(String results) throws IOException, JSONException { RecipeSummaryList recipeSummary = new RecipeSummaryList(); JSONObject newObject = new JSONObject(results); JSONObject at = newObject.getJSONObject("attribution"); String html = (String) at.get("html"); recipeSummary.setHtml(html); String url = (String) at.get("url"); recipeSummary.setUrl(url); String text = (String) at.get("text"); recipeSummary.setText(text); String logo = (String) at.get("logo"); recipeSummary.setLogo(logo); int totalMatches = newObject.getInt("totalMatchCount"); recipeSummary.setTotalmatches(totalMatches); return recipeSummary; }