I am trying to write my test class for a wrapper class that just does not function. Right now my test class is coming back with
Constructor not defined: [OpportunityBrandWinListEditController].(ApexPages.StandardController)
I think it has to do first with my vf page using a custom controller and not a standard controller. I'm also wondering how I am going to handle the addition of new opportunities.
Any help would be greatly appreciated. Below is my controller, followed by the wrapper, followed by my test class that I have now:
public class OpportunityBrandWinListEditController {
public List<OpportunityBrandWinWrapper> wrappers {get; set;}
public Integer addItemCount {get; set;}
public Integer keyToDelete {get; set;}
public Integer mainKey {get; set;}
private List<Opportunity> toDelete=new List<Opportunity>();
public String bwOppId = ApexPages.currentPage().getParameters().get('bwOppId');
public Opportunity bwOpp = [Select MRRPerUnit__c,
ID,
Account.Name,
AccountId,
Brand__c,
Units__c
From Opportunity
Where ID =:bwOppId];
public Opportunity firstForecastOpp = [Select MRRPerUnit__c,
ID,
Account.Name,
AccountId,
Brand__c,
OwnerId,
Type,
CloseDate,
MatchonFlow__c,
CreatedFromFlow__c
From Opportunity
Where RelatedDesignWin__c =:bwOppId
Order by CloseDate ASC
Limit 1];
public Double totalUnits = 0;
public Double remainingUnits = 0;
public OpportunityBrandWinListEditController()
{
mainKey=1;
addItemCount=1;
wrappers=new List<OpportunityBrandWinWrapper>();
List<Opportunity> opps = [select id,
CloseDate,
OwnerId,
Total_MRR__c,
Units__c,
Total_NRR__c,
RelatedDesignWin__r.ForecastedUnits__c,
RelatedDesignWin__r.MRRPerUnit__c,
ForecastedUnits__c,
CumulativeForecast__c,
DiscreteExpectedUnits__c,
DiscreteTotalUnits__c,
Expected_Units__c,
Name,
Account.Name
from Opportunity
WHERE RelatedDesignWin__c =: bwOppId
order by CloseDate ASC];
for (Opportunity opp : opps)
{
wrappers.add(new OpportunityBrandWinWrapper(mainKey++, opp));
}
}
public PageReference addItems()
{
if ( (addItemCount>0) && (addItemCount<10) )
{
for (Integer idx=0; idx<addItemCount; idx++)
{
wrappers.add(new OpportunityBrandWinWrapper(mainKey++, new Opportunity
(DiscreteExpectedUnits__c = 0,
DiscreteTotalUnits__c = 0,
DiscreteTotalARR__c = 0,
DiscreteExpectedARR__c = 0,
CloseDate = firstForecastOpp.CloseDate.addMonths(((mainkey-1)*3)+1).toStartofMonth().addDays(-1),
Name = 'Q' + firstForecastOpp.CloseDate.addMonths(((mainkey-1)*3)+1).toStartofMonth().addDays(-1).month()/3 + ' ' + firstForecastOpp.CloseDate.addMonths(((mainkey-1)*3)+1).toStartofMonth().addDays(-1).year())));
}
}
return null;
}
public PageReference save()
{
PageReference result = null;
Boolean error = false;
List<Opportunity> toUpsert = new List<Opportunity>();
for (OpportunityBrandWinWrapper wrapper : wrappers)
{
{
if((wrapper.opp.ForecastedUnits__c - wrapper.opp.DiscreteExpectedUnits__c - remainingUnits) <= 0){
wrapper.opp.Units__c = 0;
wrapper.opp.Total_MRR__c = 0;
remainingUnits = Math.abs(wrapper.opp.ForecastedUnits__c - wrapper.opp.DiscreteExpectedUnits__c - remainingUnits);
}
else {
wrapper.opp.Units__c = (wrapper.opp.ForecastedUnits__c - wrapper.opp.DiscreteExpectedUnits__c - remainingUnits);
wrapper.opp.Total_MRR__c = (wrapper.opp.ForecastedUnits__c - wrapper.opp.DiscreteExpectedUnits__c - remainingUnits) * bwOpp.MRRPerUnit__c;
remainingUnits = 0;
}
wrapper.opp.RelatedDesignWin__c = bwOppId;
wrapper.opp.StageName = 'Commitment';
wrapper.opp.Probability = 1;
wrapper.opp.Total_NRR__c = 0;
wrapper.opp.AccountId = bwOpp.AccountId;
wrapper.opp.Brand__c = bwOpp.Brand__c;
wrapper.opp.CreatedFromFlow__c = firstForecastOpp.CreatedFromFlow__c;
wrapper.opp.MatchonFlow__c = firstForecastOpp.MatchonFlow__c;
wrapper.opp.Type = firstForecastOpp.Type;
wrapper.opp.Description = String.ValueOf(wrapper.opp.Units__c);
wrapper.opp.CloseDate = firstForecastOpp.CloseDate.addMonths(((wrapper.key-1)*3)+1).toStartofMonth().addDays(-1);
totalUnits += wrapper.opp.ForecastedUnits__c;
wrapper.opp.CumulativeForecast__c = totalUnits;
wrapper.opp.OwnerId = firstForecastOpp.OwnerId;
wrapper.opp.Name = bwOpp.Account.Name + ' > Q' + wrapper.opp.CloseDate.month()/3 + ' ' + wrapper.opp.CloseDate.year();
toUpsert.add(wrapper.opp);
}
}
if (!error)
{
bwOpp.Units__c = totalUnits;
bwOpp.Total_MRR__c = totalUnits * firstForecastOpp.MRRPerUnit__c;
update bwOpp;
upsert toUpsert;
result=new PageReference('/' + bwOppId);
}
return result;
}
}
Here is the wrapper:
public class OpportunityBrandWinWrapper {
public Integer key {get; set;}
public Opportunity opp {get; set;}
public OpportunityBrandWinWrapper(Integer inKey, Opportunity inOpp)
{
key=inKey;
opp=inOpp;
}
}
Here is the test class I have written:
@isTest private class testBWOppForecastJunction { static testMethod void myUnitTest()
{
Profile p = [SELECT Id FROM Profile WHERE Name='System Administrator'];
User u3 = new User(Alias = 'newUser', Email='[email protected]',
EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US',
LocaleSidKey='en_US', ProfileId = p.Id,
TimeZoneSidKey='America/Los_Angeles', UserName='[email protected]');
System.runAs(u3){
List<sObject> accs = Test.loadData(Account.sobjectType, 'AccTestData');
List<sObject> opps = Test.loadData(Opportunity.sobjectType, 'OppTestData');
Opportunity opp1 = (Opportunity)opps[0];
PageReference myVfPage = Page.vfOppBWForecast;
System.Test.setCurrentPageReference(myVfPage);
ApexPages.currentPage().getParameters().put('bwOppId',opp1.Id);
String id = ApexPages.currentPage().getParameters().get('bwOppId');
Test.setCurrentPageReference(myVFPage);
system.assertEquals(true,id==opp1.Id);
OpportunityBrandWinListEditController bwOppTest = new OpportunityBrandWinListEditController(new ApexPages.StandardController(opp1));
LIST<OpportunityBrandWinListEditController> lstAccLoc = bwOppTest.opps();
for(OpportunityBrandWinListEditController oppList : bwOppTest.wrappers )
{
oppList.key != null;
}
bwOpp.createFR();
bwOpp.insertRec();
}
}
}