• Helen Y.
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 10
    Replies
Hi Experts,

This is the first time I am working on xml, please give some help. I've completed a method on XmlStreamReader, it is now working fine, can extract the data out correct. But the issue is with the test class coverage.

Error:

Below is my code:
Post method:
//Variables store data
public static String toUserName {get; set;}
public static String fromUserName {get; set;}
public static String msgType {get; set;}
 
@HttpPost
    global static void doPost(){
        //Set up for XML processing
       RestRequest req = RestContext.request;
        RestResponse res = RestContext.response;
        string strMsg = req.requestBody.toString();  
        System.debug('Request Contents' + strMsg);
        XmlStreamReader reader = new XmlStreamReader(strMsg);
        //Deserialize
        while(reader.hasNext()){
            if(reader.getLocalName() == 'ToUserName'){
                reader.next();
                if(String.isNotBlank(reader.getText())){
                    toUserName = reader.getText();
                }
            }
            else if(reader.getLocalName() == 'FromUserName'){
                reader.next();
                if(String.isNotBlank(reader.getText())){
                    fromUserName = reader.getText();
                }
            }
            else if(reader.getLocalName() == 'MsgType'){
                reader.next();
                if(String.isNotBlank(reader.getText())){
                    msgType = reader.getText();
                }
            }
            reader.next();
        }
    }

Test Method:
static testMethod void testDoPost(){
        RestRequest req = new RestRequest();
        RestResponse res = new RestResponse();
        String strTmp = '<xml><ToUserName>tUN</ToUserName><FromUserName>fUN</FromUserName><MsgType>mT</MsgType></xml>';
        req.requestBody = Blob.valueOf(strTmp);
        req.requestURI = 'https://ap1.salesforce.com/services/apexrest/Demo//CoreService';
        req.httpMethod = 'POST';
        test.startTest();
        RestContext.request = req;
        RestContext.response = res;
        ApexRESTCycle.doPost();
        XmlStreamReader reader = new XmlStreamReader(req.requestBody.toString());
        test.stopTest();
        System.assert(ApexRESTCycleExample.fromUName == 'fUN');
        System.assert(ApexRESTCycleExample.toUName == 'tUN');
        System.assert(ApexRESTCycleExample.mType == 'mT');
}

The issue now is in the Post method, only the first node <ToUserName> got covered, other nodes are not covered, error attached on above.

I need a perfect coverage, please help.

Thanks,
Helen
    Hi,

    I got lost here, so my work is to give several labels each a differernt name.

    Till now, all upload attachment buttons with one name "Upload Vehicle Photo" in front:
    <apex:repeat value="{!newAttachments}" var="att"  >
                       <apex:pageBlockSectionItem >
                       <apex:outputLabel value="Upload Vehicle Photo"/>
                       <apex:inputfile value="{!att.body}" filename="{!att.Name}" />
                       </apex:pageBlockSectionItem>
                       <apex:commandlink value="Upload" action="{!insertatt}" styleClass="btn" style="padding:1px 10px 2px 5px; text-decoration:none;">
                           <apex:param name="attNameAdd" value="{!att.id}" assignTo="{!attNameAdd}"/>
                       </apex:commandlink>
                    </apex:repeat>

    But now I need to revise the name from "Upload Vehicle Photo"  to:
    -- "Upload Vehicle Photo" for first row;
    -- "Upload Old Photo" for second row;
    -- "Upload New Photo" for third row.
    It looks like have to revise the passing value from my controller to the page, but cannot figure it out.

    Any help will be appreciated!Sample
    Hi All,

    I am totally new in program language world, just doing exercise on Headtrail and met this question in debug log:
    Assertion Failed: Expected: Account:{Name=}, Actual: null
    Cannot figure out what is the difference between Name = and null, can someone help how can this work? Thanks.
     
    Hi Experts,

    This is the first time I am working on xml, please give some help. I've completed a method on XmlStreamReader, it is now working fine, can extract the data out correct. But the issue is with the test class coverage.

    Error:

    Below is my code:
    Post method:
    //Variables store data
    public static String toUserName {get; set;}
    public static String fromUserName {get; set;}
    public static String msgType {get; set;}
     
    @HttpPost
        global static void doPost(){
            //Set up for XML processing
           RestRequest req = RestContext.request;
            RestResponse res = RestContext.response;
            string strMsg = req.requestBody.toString();  
            System.debug('Request Contents' + strMsg);
            XmlStreamReader reader = new XmlStreamReader(strMsg);
            //Deserialize
            while(reader.hasNext()){
                if(reader.getLocalName() == 'ToUserName'){
                    reader.next();
                    if(String.isNotBlank(reader.getText())){
                        toUserName = reader.getText();
                    }
                }
                else if(reader.getLocalName() == 'FromUserName'){
                    reader.next();
                    if(String.isNotBlank(reader.getText())){
                        fromUserName = reader.getText();
                    }
                }
                else if(reader.getLocalName() == 'MsgType'){
                    reader.next();
                    if(String.isNotBlank(reader.getText())){
                        msgType = reader.getText();
                    }
                }
                reader.next();
            }
        }

    Test Method:
    static testMethod void testDoPost(){
            RestRequest req = new RestRequest();
            RestResponse res = new RestResponse();
            String strTmp = '<xml><ToUserName>tUN</ToUserName><FromUserName>fUN</FromUserName><MsgType>mT</MsgType></xml>';
            req.requestBody = Blob.valueOf(strTmp);
            req.requestURI = 'https://ap1.salesforce.com/services/apexrest/Demo//CoreService';
            req.httpMethod = 'POST';
            test.startTest();
            RestContext.request = req;
            RestContext.response = res;
            ApexRESTCycle.doPost();
            XmlStreamReader reader = new XmlStreamReader(req.requestBody.toString());
            test.stopTest();
            System.assert(ApexRESTCycleExample.fromUName == 'fUN');
            System.assert(ApexRESTCycleExample.toUName == 'tUN');
            System.assert(ApexRESTCycleExample.mType == 'mT');
    }

    The issue now is in the Post method, only the first node <ToUserName> got covered, other nodes are not covered, error attached on above.

    I need a perfect coverage, please help.

    Thanks,
    Helen
      I'm struggeling a little bit with the following.

      I've got a visualforce page where i need to change the value of the output label when another field is changed.

      Got this code in my VF page

       <apex:pageBlock mode="maindetail" id="thePageBlock"> 
                              <apex:outputPanel layout="block" id="pbsNL" >
                                  <apex:pageBlockSection columns="1" title="Kies taal" id="pbsectNL">
                                      <apex:pageBlockSectionItem id="pbsitemNL">
                                          <apex:outputLabel value="Taal"/>
                                          <apex:selectList size="1" id="nlSelectList" multiselect="false" onChange="changeLanguage(this.value);"> 
                                              <apex:selectOption itemValue="nl" itemLabel="Nederlands"/>
                                              <apex:selectOption itemValue="en" itemLabel="English" title="Choose language"/>
                                          </apex:selectList>
                                      </apex:pageBlockSectionItem>
                                  </apex:pageBlockSection>
                              </apex:outputPanel>


      The bold values have to change on choosing "en" or "nl".

      Anyone any suggestions?


      Regards
      Chiel
      Hi,

      I got lost here, so my work is to give several labels each a differernt name.

      Till now, all upload attachment buttons with one name "Upload Vehicle Photo" in front:
      <apex:repeat value="{!newAttachments}" var="att"  >
                         <apex:pageBlockSectionItem >
                         <apex:outputLabel value="Upload Vehicle Photo"/>
                         <apex:inputfile value="{!att.body}" filename="{!att.Name}" />
                         </apex:pageBlockSectionItem>
                         <apex:commandlink value="Upload" action="{!insertatt}" styleClass="btn" style="padding:1px 10px 2px 5px; text-decoration:none;">
                             <apex:param name="attNameAdd" value="{!att.id}" assignTo="{!attNameAdd}"/>
                         </apex:commandlink>
                      </apex:repeat>

      But now I need to revise the name from "Upload Vehicle Photo"  to:
      -- "Upload Vehicle Photo" for first row;
      -- "Upload Old Photo" for second row;
      -- "Upload New Photo" for third row.
      It looks like have to revise the passing value from my controller to the page, but cannot figure it out.

      Any help will be appreciated!Sample
      Hi All,

      I am totally new in program language world, just doing exercise on Headtrail and met this question in debug log:
      Assertion Failed: Expected: Account:{Name=}, Actual: null
      Cannot figure out what is the difference between Name = and null, can someone help how can this work? Thanks.