A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
JavaRanch
»
Java Forums
»
Languages
»
Groovy
Author
Integration Test Case in Grails
jimmy eden
Greenhorn
Joined: Sep 21, 2011
Posts: 2
posted
Sep 22, 2011 03:31:59
0
how can i do integration
testing
of the following code
def sharePost(String accountType, String post){ if(accountType == AccountType.FACEBOOK.toValue()){ def facebookOauthDetails = OauthDetails.findWhere(username:springSecurityService.currentUser.username, account:AccountType.FACEBOOK.toValue()) def publishStatus = false try { def httpClient = new HttpClient() def postMethod = new PostMethod(Mappings.POST_FEED_URL) postMethod.addParameter(Mappings.ACCESSTOKEN,facebookOauthDetails.accessToken) postMethod.addParameter(Mappings.MESSAGE, post) httpClient.executeMethod(postMethod) def facebookResponse = postMethod.getResponseBodyAsString() if (facebookResponse != null) { def facebookResponseJsonObject = new JSONObject(facebookResponse) try { def facebookId = facebookResponseJsonObject.getString(Mappings.ID) publishStatus = true } catch (JSONException jsonException) { log.error("Message could not be published to WALL", jsonException) } } }catch(Exception publishException) { log.error("Error occurred while publish message to WALL", publishException) } } else if(accountType == AccountType.TWITTER.toValue()){ def consumerKeyValue, consumerSecretValue = null def configurationValues = fetchConfigurationValues(springSecurityService.currentUser.username, AccountType.TWITTER.toValue()) if(configurationValues != null){ consumerKeyValue = configurationValues.substring (0,configurationValues.indexOf(ApplicationConstants.TILDE_SEPARATOR)) consumerSecretValue = configurationValues.substring (configurationValues.lastIndexOf(ApplicationConstants.TILDE_SEPARATOR)+ 1, configurationValues.length()) } def twitterOauthDetails = OauthDetails.findWhere(username: springSecurityService.currentUser.username, account:accountType) if(twitterOauthDetails != null){ def oauthVerifier_twitter = twitterOauthDetails.oauthIdentifier def token = twitterOauthDetails.token def tokenSecret = twitterOauthDetails.tokenSecret AccessToken accessToken = new AccessToken(token, tokenSecret) Twitter twitter = new TwitterFactory().getInstance() twitter.setOAuthConsumer(consumerKeyValue,consumerSecretValue) twitter.setOAuthAccessToken(accessToken) User user = twitter.verifyCredentials() Status status = twitter.updateStatus(post) } } else if(accountType == AccountType.LINKEDIN.toValue()){ def consumerKey, redirectUri, consumerSecret, accessToken = null def configurationValues = fetchConfigurationValues(springSecurityService.currentUser.username, AccountType.LINKEDIN.toValue()) if(configurationValues!= null){ consumerKey = configurationValues.substring(0, configurationValues.indexOf(ApplicationConstants.TILDE_SEPARATOR)) redirectUri = configurationValues.substring(configurationValues.indexOf(ApplicationConstants.TILDE_SEPARATOR) + 1, configurationValues.lastIndexOf(ApplicationConstants.TILDE_SEPARATOR)) consumerSecret = configurationValues.substring(configurationValues.lastIndexOf(ApplicationConstants.TILDE_SEPARATOR) + 1, configurationValues.length()) } def linkedinOauthDetails = OauthDetails.findWhere(username: springSecurityService.currentUser.username, account:AccountType.LINKEDIN.toValue()) if(linkedinOauthDetails != null){ accessToken = new LinkedInAccessToken(linkedinOauthDetails.token, linkedinOauthDetails.tokenSecret) if(post!= null){ if(post.length()>0){ def linkedInApiClientFactory = LinkedInApiClientFactory.newInstance(consumerKey, consumerSecret) def linkedInApiClient = linkedInApiClientFactory.createLinkedInApiClient(accessToken) linkedInApiClient.updateCurrentStatus(post) } } } } }
I agree. Here's the link:
http://ej-technologies/jprofiler
- if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
subject: Integration Test Case in Grails
Similar Threads
java.io.IOException: Server returned HTTP response code: 400 for URL:
SSLHandshake Error while connection to remote server
Calling webservice: works from standalone app but not from weblogic
Java with curl (http://curl.haxx.se/)
How to provide basic authetication from SOAP request to access SAP XI service
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter