i got 45% in test code coverage,but can't cover remote action method. how to cover remote action method in test class?
class:
global class RFLEET_ProtocolLineController
{
//declartion part
public Boolean refreshPage { get; set; }
public string volumeJSON {get;set;}
public string newlineinsertlist{get;set;}
List<String> v1= new List<String>();
List<List<String>> v2= new List<List<String>>();
List<String> v3= new List<String>();
List<List<String>> v4= new List<List<String>>();
string Id;
public String gridtype{get;set;}
public String gridname{get;set;}
public boolean hideExcel{get;set;}
public boolean hidetable2{get;set;}
public RFLEET_ProtocolLineController(ApexPages.StandardController controller) {
hideExcel=true;
hidetable2=false;
id=ApexPages.currentPage().getParameters().get('id');
RFLEET_Protocol_Grid__c grid=[select id,name,Rfleet_Type_of_Grid__c from RFLEET_Protocol_Grid__c where id=:id];
gridtype=grid.Rfleet_Type_of_Grid__c;
gridname=grid.id;
Rfleet_ProtocolLineList();
}
//copy-paste solution existing values fetching from protocol lines
public void Rfleet_ProtocolLineList(){
v2= new List<List<String>>();
for(RFLEET_Protocol_Line__c oli: [select id,Rfleet_Discount__c,Rfleet_Model__c,Rfleet_Option__c,Rfleet_Price__c,Rfleet_PricePercent__c ,Rfleet_Protocol_grid_name__c,Rfleet_Version__c ,Rfleet_Volume__c from RFLEET_Protocol_Line__c where Rfleet_Protocol_grid_name__c=:gridname ]) {
v1= new List<String>();
v1.add(oli.id);
v1.add(oli.Rfleet_Model__c);
v1.add(oli.Rfleet_Option__c);
v1.add(string.valueOf(oli.Rfleet_Price__c));
v1.add(String.valueOf(oli.Rfleet_Discount__c));
v1.add(String.valueOf(oli.Rfleet_PricePercent__c));
v1.add(oli.Rfleet_Version__c);
v1.add(String.valueOf(oli.Rfleet_Volume__c));
v1.add(oli.Rfleet_Protocol_grid_name__c);
v2.add(v1);
}
volumeJSON= JSON.serialize(v2);
}
//Rfresh table and redirect to home page protocol grids
public void cancel(){
hideExcel=true;
hidetable2=false;
refreshPage =true;
}
//copy-paste solution new line insert function empty values passing here
public void RfleetnewlineExcel(){
hideExcel=false;
hidetable2=true;
RFLEET_Protocol_Line__c ww=new RFLEET_Protocol_Line__c();
for(integer i=1; i<=20;i++){
String model=ww.Rfleet_Model__c;
String Option=ww.Rfleet_Option__c;
String Price=(string.valueOf(ww.Rfleet_Price__c));
String Discount=(String.valueOf(ww.Rfleet_Discount__c));
String Version=ww.Rfleet_Version__c;
String Volume=(String.valueOf(ww.Rfleet_Volume__c));
String PricePercent=(String.valueOf(ww.Rfleet_PricePercent__c));
String masterid=ww.Rfleet_Protocol_grid_name__c;
v3= new List<String>();
v3.add(model);
v3.add(Option);
v3.add(Price);
v3.add(Discount);
v3.add(Version);
v3.add(Volume);
v3.add(PricePercent);
v4.add(v3);
}
newlineinsertlist= JSON.serialize(v4);
}
//copy-paste solution update function starts here
@RemoteAction
global static pagereference AccSave(List<List<String>> valuefromJS){
List<RFLEET_Protocol_Line__c> volSave = new List<RFLEET_Protocol_Line__c>();
for(Integer i=0; i<valuefromJS.size(); i++){
RFLEET_Protocol_Line__c v=new RFLEET_Protocol_Line__c();
List<String> l1 = valuefromJS[i];
v.id=l1[0];
v.Rfleet_Model__c=l1[1];
if(l1[2] != null ){
v.Rfleet_Option__c= string.valueof(l1[2]);
}
if(!string.isBlank(l1[3])){
v.Rfleet_Price__c= Decimal.valueof(l1[3]);
}
else{
v.Rfleet_Price__c=null;
}
if(!string.isBlank(l1[4])){
v.Rfleet_Discount__c=Decimal.valueof(l1[4]);
}else{
v.Rfleet_Discount__c=null;
}
if(!string.isBlank(l1[5])){
v.Rfleet_PricePercent__c=Decimal.valueof(l1[5]);
}else{
v.Rfleet_PricePercent__c=null;
}
if(l1[6] != null ){
v.Rfleet_Version__c=string.valueof(l1[6]);
}
if(!string.isBlank(l1[7])){
v.Rfleet_Volume__c=Decimal.valueof(l1[7]);
}else{
v.Rfleet_Volume__c=null;
}
v.Rfleet_Protocol_grid_name__c=l1[8];
volSave.add(v);
}
update volSave;
return null;
}
// copy-paste solution action stared for newline insertion
@RemoteAction
global static pagereference newlineSave(List<List<String>> valuefromJSNewdata,string Masterid,string gtype ){
List<RFLEET_Protocol_Line__c> volSave1 = new List<RFLEET_Protocol_Line__c>();
for(Integer i=0; i<valuefromJSNewdata.size(); i++){
RFLEET_Protocol_Line__c proline=new RFLEET_Protocol_Line__c();
List<String> l2 = valuefromJSNewdata[i];
system.debug('<<<<<'+l2[0]);
system.debug('<<<<<'+l2[1]);
if(l2[0]==null && l2[1]==null && l2[2]==null && l2[3]==null && l2[4]==null && l2[5]==null && l2[6]==null)
{
system.debug('<<<<inside if null values');
}
else{
system.debug('<<<<inside else with values');
proline.Rfleet_Model__c=l2[0];
if(l2[1] != null ){
proline.Rfleet_Option__c= string.valueof(l2[1]);
}
if(l2[2] != null ){
proline.Rfleet_Price__c= Decimal.valueof(l2[2]);
}
if(l2[3] != null ){
proline.Rfleet_Discount__c=Decimal.valueof(l2[3]);
}
if(l2[6] != null ){
proline.Rfleet_PricePercent__c=Decimal.valueof(l2[6]);
}
if(l2[4] != null ){
proline.Rfleet_Version__c=string.valueof(l2[4]);
}
if(l2[5] != null ){
proline.Rfleet_Volume__c=Decimal.valueof(l2[5]);
}
proline.Rfleet_Protocol_grid_name__c=Masterid;
volSave1.add(proline);
}
}
insert volSave1;
return null;
}
}
test class:
@isTest
public class RFLEET_ProtocolLineController_Test{
public static testMethod void copy(){
RFLEET_Protocol_Grid__c din = new RFLEET_Protocol_Grid__c(Name='sand');
insert din;
din.Name = 'sanc';
update din;
system.debug('din.id'+din.id);
ApexPages.currentPage().getParameters().put('id',din.id);
ApexPages.StandardController sc = new ApexPages.standardController(din);
RFLEET_ProtocolLineController rp = new RFLEET_ProtocolLineController(sc);
string selcontactid;
selcontactid = System.currentPagereference().getParameters().get('conid');
Account Acc= New Account(Name='A1',Montant__c=1.4);
insert Acc;
RFLEET_Protocol__c Rpro=new RFLEET_Protocol__c(Name='Aggre',Rfleet_Agreement_Client__c=Acc.id,Rfleet_Status__c='Actif',Rfleet_Billing_Type__c='Dossier');
insert Rpro;
RFLEET_Protocol_Grid__c pg=new RFLEET_Protocol_Grid__c(Name='t1',Rfleet_Type_of_Grid__c='Model - Discount %',Rfleet_Type_of_Sales__c='VD');
insert pg;
RFLEET_Protocol_Line__c record = new RFLEET_Protocol_Line__c(Rfleet_Model__c='model',Rfleet_Discount__c=1.2,Rfleet_Version__c='test',Rfleet_Option__c='test',Rfleet_Volume__c=1,Rfleet_Price__c=12,Rfleet_Protocol_grid_name__c=pg.id);
insert record;
record.Rfleet_Model__c='test';
update record;
rp.cancel();
rp.Rfleet_ProtocolLineList();
rp.RfleetnewlineExcel();
list<string> str=new list<string>();
//rp.AccSave(List<List<String>> str);
}
public static testMethod void testremoteaction1(){
string[] sert = new string[]{};
RFLEET_ProtocolLineController_Test tred = new RFLEET_ProtocolLineController_Test();
sert = tred.AccSave('valuefromJS');
}
}