function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Digit1234Digit1234 

Apex Test class

Hey ,

i am having problem making test method for this class:

global class YouTubeCallout
{
public static void makeRequest(string url,FeedItem fi) {
HttpResponse response = null;
HttpRequest req = new HttpRequest();
req.setEndpoint(url);
req.setMethod('GET');

try {
Http http = new Http();
response = http.send(req);
System.debug('reCAPTCHA response: ' + response);

if (response.getStatusCode() == 200)
{
System.debug('Callout Success'+response);
String xml = response.getBody();
System.debug(xml);
Map<String,Object> myjson = (Map<String,Object>)JSON.deserializeUntyped(xml);
Object data1 = myjson.get('data');
Map<String,Object> data = (Map<String,Object>)data1;
String category = (String)data.get('category');
String title = (String)data.get('title');
System.debug('CATEGORY :: '+category+' TITLE :: '+title);
xml = xml.trim().toLowerCase();
System.debug(xml);
YouTubeCallout.filterXml(xml,fi);
}
} catch(System.Exception e) {
System.debug('ERROR: ' + e);
}
}

public static void filterXml(String xml,FeedItem fi)
{
if(xml.contains('sex') || xml.contains('**bleep**') || xml.contains('suck') || xml.contains('boob') || xml.contains('adult') || xml.contains('**bleep**') || xml.contains('breast') || xml.contains('**bleep**') || xml.contains('porn') || xml.contains('penish'))
{
System.debug('The Video contains bad things!!');
fi.addError('Adult Video!!!');
}
else
{
List<Chatter_Monitor_Policy__c> cmp = [SELECT ID,Chatter_Monitor_Policy_Keyword__c FROM Chatter_Monitor_Policy__c
WHERE Active__c = TRUE AND Monitor_Video__c = TRUE AND CreatedByID IN
:[SELECT ID FROM USER WHERE Profile.Name = 'System Administrator' OR Profile.Name = 'Sec_Chat_Moderator'
OR CreatedByID = :UserInfo.getUserID()]];
System.debug(cmp.size());

List<String> keys = new List<String>();
String key = '';
for(Chatter_Monitor_Policy__c cm : cmp)
{
String str = cm.Chatter_Monitor_Policy_Keyword__c;
List<String> adds = str.split(',');
keys.addAll(adds);
}

for(String word : keys)
{
if(xml.contains(word))
{
key += word+',';
}
}

if(key == null || key == '')
{
key = key.removeEnd(',');
}
System.debug('Video Contains following keywords : '+key);
}
}
}

 

 

 

In makeRequest parameter dont know what to insert as a parameter in test class. 

digamber.prasaddigamber.prasad

Hi,

 

You can use "HttpCalloutMock" interface to effectively write your test class for this scenario:-

 

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_restful_http_testing_httpcalloutmock.htm

 

Let me know if you have any specific question about this.

 

Happy to help you!

 

Regards,

Digamber Prasad

Turtle FuckerTurtle Fucker
Just give in to the porn, man. Embrace it