I have a VF page where I am appending labels/values to a dropdown input from Custom Labels, like this:
<apex:selectList label="{!$Label.Type}" value="{!lstInputs.typeValue}" multiselect="false" size="1">
<apex:selectOption itemValue="{!$Label.Option1}" itemLabel="{!$Label.Label1}"/>
<apex:selectOption itemValue="{!$Label.Option2}" itemLabel="{!$Label.Label2}"/>
</apex:selectList>
<apex:commandButton value="{!$Label.Submit}" action="{!callImplementor}" reRender="refresh"/>
I am using a Wrapper class to access all variables from my VF page. In my actual controller, I am using a method that gets this wrapper record as a parameter and builds a HTTP request.
public pagereference callImplementor() {
try {
implementor(lstInputs);
} catch (Exception ex){
}
}
public HttpRequest implementor(InputWrapper inp) {
String selectedValue = (inp.typeValue != null ? inp.typeValue : '');
System.debug('selectedValue :' +selectedValue);
<--some code -->
}
//Wrapper
public class InputWrapper {
public string typeValue {get; set;}
//Other variables.
}
Test class:
public static String adjValue = 'Option1';
//test method
static testmethod void testForCalloutSuccess(){
Pagereference testPage = Page.MyVFPage;
test.setCurrentPageReference(testPage);
testPage.getParameters().put('acctId', actId);
Test.startTest();
MyControllerClass ctrl = new MyControllerClass();
MyControllerClass.InputWrapper lstInput = new MyControllerClass.InputWrapper();
lstInput.typeValue = adjValue;
ctrl.callImplementor();
//ctrl.implementor(lstInput);
Test.stopTest();
}
I am getting my selectedValue
as null
in my test class. If I declare a test wrapper record, and call the method implementor(InputWrapper inp)
by passing this record, some other field values are getting null
as some values are set from constructor. How can I set the test data for this <apex:selectList>
dropdown field from VF page?