-
ChatterFeed
-
0Best Answers
-
0Likes Received
-
0Likes Given
-
4Questions
-
0Replies
how to improve code coverage of below test class
@isTest(SeeAllData=false)
private class TestOrderProductComponentController {
/*
public variables here
*/
public static NA_Order__c order4Test;
public static Account acc4Test;
/*
testMethod here
*/
static testMethod void testWithOutProduct() {
initalize();
OrderProductComponentController controller = new OrderProductComponentController();
Test.startTest();
Map<String, Set<String>> cropVarietyMap = controller.cropVarietyMap;
controller.queryTECP();
Map<String, Map<String, Map<String, Set<String>>>> TECPMapofMapTest = controller.TECPMapofMap;
NA_Order_Line_Item__c orderLineTest = controller.orderLine;
List<SelectOption> cropOptionsTest = controller.cropOptions;
List<SelectOption> varietyOptionsTest = controller.varietyOptions;
List<SelectOption> treatmentOptionsTest = controller.treatmentOptions;
List<SelectOption> enhancementOptionsTest = controller.enhancementOptions;
List<SelectOption> carrierOptionsTest = controller.carrierOptions;
List<SelectOption> packagingOptionsTest = controller.packagingOptions;
String cropTest = controller.crop;
String varietyTest = controller.variety;
controller.validateQuantity();
Test.stopTest();
}
static testMethod void testWithProducts() {
initalize();
OrderProductComponentController controller = new OrderProductComponentController();
Test.startTest();
Test.stopTest();
}
/*
initalize here
*/
public static void initalize() {
acc4Test = TestUtils.createAccount('AccForTestingOrderProductPicker', 'USD', true);
order4Test = TestUtils.createOrder('Spot Order', Date.today(), 'UPS', 'OrderForTestingOrderProductPicker', 'Created', acc4Test.Id, true);
PageReference orderProductPicker = Page.Order;
orderProductPicker.getParameters().put('Id', order4Test.Id);
Test.setCurrentPage(orderProductPicker);
}
}
private class TestOrderProductComponentController {
/*
public variables here
*/
public static NA_Order__c order4Test;
public static Account acc4Test;
/*
testMethod here
*/
static testMethod void testWithOutProduct() {
initalize();
OrderProductComponentController controller = new OrderProductComponentController();
Test.startTest();
Map<String, Set<String>> cropVarietyMap = controller.cropVarietyMap;
controller.queryTECP();
Map<String, Map<String, Map<String, Set<String>>>> TECPMapofMapTest = controller.TECPMapofMap;
NA_Order_Line_Item__c orderLineTest = controller.orderLine;
List<SelectOption> cropOptionsTest = controller.cropOptions;
List<SelectOption> varietyOptionsTest = controller.varietyOptions;
List<SelectOption> treatmentOptionsTest = controller.treatmentOptions;
List<SelectOption> enhancementOptionsTest = controller.enhancementOptions;
List<SelectOption> carrierOptionsTest = controller.carrierOptions;
List<SelectOption> packagingOptionsTest = controller.packagingOptions;
String cropTest = controller.crop;
String varietyTest = controller.variety;
controller.validateQuantity();
Test.stopTest();
}
static testMethod void testWithProducts() {
initalize();
OrderProductComponentController controller = new OrderProductComponentController();
Test.startTest();
Test.stopTest();
}
/*
initalize here
*/
public static void initalize() {
acc4Test = TestUtils.createAccount('AccForTestingOrderProductPicker', 'USD', true);
order4Test = TestUtils.createOrder('Spot Order', Date.today(), 'UPS', 'OrderForTestingOrderProductPicker', 'Created', acc4Test.Id, true);
PageReference orderProductPicker = Page.Order;
orderProductPicker.getParameters().put('Id', order4Test.Id);
Test.setCurrentPage(orderProductPicker);
}
}
- vara sree
- December 09, 2014
- Like
- 0
how to improve code coverage of below test class
public class OrderProductComponentController_SIND extends OrderComponentControllerBase_SIND {
public Map<String, Set<String>> cropVarietyMap{get{
if((cropVarietyMap == null || cropVarietyMap.isEmpty() || cropVarietyMap.size() == 1) && myorder != null ) {
cropVarietyMap = new Map<String, Set<String>>();
AggregateResult[] ARList = [SELECT Crop__c, Variety__c FROM Crop_And_Variety__c WHERE CurrencyIsoCode =: currencyCode AND PriceBook_ID__c IN: pricebookIDs GROUP BY Crop__c, Variety__c];
for(AggregateResult AR: ARList) {
String cropS = String.ValueOf(ar.get('Crop__c'));
String varietyS = String.ValueOf(ar.get('Variety__c'));
if(cropVarietyMap.get(cropS) == null) {
Set<String> s = new Set<String>{varietyS};
cropVarietyMap.put(cropS, s);
} else {
Set<String> s = cropVarietyMap.get(cropS);
s.add(varietyS);
cropVarietyMap.put(cropS, s);
}
}
}
return cropVarietyMap;
} set;}
public void queryTECP(){
treatment = null;
enhancement = null;
carrier = null;
system.debug('--1 ' + packaging);
packaging = null;
totalUnits = null;
quantityError = null;
pbeList = new List<PriceBookEntry>();
Map<String, Map<String, Map<String, Set<String>>>> newMap = TECPMapOfMap;
}
public List<PriceBookEntry> pbeList {get; set;}
public Map<String, Map<String, Map<String, Set<String>>>> cachedMap {get; set;}
public Map<String, Map<String, Map<String, Set<String>>>> TECPMapofMap {get {//key1-enhancement, key2-treatment, key 3-carrier
if(!String.isBlank(crop) && !String.isBlank(variety)){
if(pbeList == null || pbeList.isEmpty()) {
pbeList = [SELECT Id,
Product2Id,
Product2.Vs_Treatment_Desc__c,
Product2.Vs_Carrier_Desc__c,
Product2.Vs_Seedenhancement_Desc__c,
Product2.Packaging__c,
Product2.Vs_Packagesize__c
FROM PriceBookEntry
WHERE Product2.Matrl_Group__r.Name =: crop AND PriceBook2Id IN: pricebookIDs AND Product2.IsActive = true
AND Product2.Hierarchy_Level__c = 'Material' AND Product2.Vs_Variety__r.Name =: variety];
for(PriceBookEntry pbe: pbeList) {
string enhc = pbe.Product2.Vs_Seedenhancement_Desc__c;
string treat = pbe.Product2.Vs_Treatment_Desc__c;
string carr = pbe.Product2.Vs_Carrier_Desc__c;
string pckg = pbe.Product2.Packaging__c;
if(TECPMapofMap.get(treat) == null) { //add treatment
TECPMapofMap.put(treat, new Map<String, Map<String, Set<String>>>());
}
if(TECPMapofMap.get(treat).get(carr) == null) { //add carrier
TECPMapofMap.get(treat).put(carr, new Map<String, Set<String>>());
}
if(TECPMapofMap.get(treat).get(carr).get(enhc) == null) { //add enhancement
TECPMapofMap.get(treat).get(carr).put(enhc, new Set<String>());
}
if(TECPMapofMap.get(treat).get(carr).get(enhc) == null) { //add packaging
TECPMapofMap.get(treat).get(carr).put(enhc, new Set<String>{pckg});
} else {
TECPMapofMap.get(treat).get(carr).get(enhc).add(pckg);
}
}
}
} else {
TECPMapofMap = new Map<String, Map<String, Map<String, Set<String>>>>(); //key1-treat, key2-carr, key 3-enhancement
}
return TECPMapofMap;
}set;}
public NA_Order_Line_Item__c orderLine{get {
if(orderLine == null) {
orderLine = new NA_Order_Line_Item__c();
}
return orderLine;
} set;}
public List<SelectOption> cropOptions {get {
cropOptions = new List<SelectOption>();
cropOptions.add(new SelectOption(' ', ' '));
if(cropVarietyMap != null && !cropVarietyMap.isEmpty() && cropVarietyMap.size() != 1) {
for(string s: cropVarietyMap.keySet()){
cropOptions.add(new SelectOption(s, s));
}
}
cropOptions.sort();
return cropOptions;
} set;}
public List<SelectOption> varietyOptions {get {
varietyOptions = new List<SelectOption>();
varietyOptions.add(new SelectOption(' ', ' '));
if(cropVarietyMap != null && !cropVarietyMap.isEmpty() && !String.IsBlank(crop)) {
for(string s: cropVarietyMap.get(crop)){
if(s != null) {
varietyOptions.add(new SelectOption(s, s));
}
}
}
varietyOptions.sort();
return varietyOptions;
} set;}
public List<SelectOption> treatmentOptions {get {
treatmentOptions = new List<SelectOption>();
treatmentOptions.add(new SelectOption(' ', ' '));
if(TECPMapofMap != null && !TECPMapofMap.isEmpty() && crop != null && variety != null) {
for(string s: TECPMapofMap.keySet()){
if(s != null) {
treatmentOptions.add(new SelectOption(s, s));
}
}
}
treatmentOptions.sort();
return treatmentOptions;
} set;}
public void onTreatmentChange(){
enhancement = null;
carrier = null;
system.debug('--2 ' + packaging);
packaging = null;
}
public void onEnhancementChange(){
system.debug('--3 ' + packaging);
packaging = null;
}
public void onPackagingChange(){
}
public void onCarrierChange(){
enhancement = null;
system.debug('--4 ' + packaging);
packaging = null;
}
public List<SelectOption> enhancementOptions {get {
enhancementOptions = new List<SelectOption>();
enhancementOptions.add(new SelectOption(' ', ' '));
if(TECPMapofMap != null && !TECPMapofMap.isEmpty() && !String.isBlank(crop) && !String.isBlank(variety) && !String.isBlank(treatment) && !String.isBlank(carrier)) {
for(string s: TECPMapofMap.get(treatment).get(carrier).keySet()){
if(s != null) {
enhancementOptions.add(new SelectOption(s, s));
}
}
}
enhancementOptions.sort();
return enhancementOptions;
} set;}
public List<SelectOption> carrierOptions {get {
carrierOptions = new List<SelectOption>();
carrierOptions.add(new SelectOption(' ', ' '));
if(TECPMapofMap != null && !TECPMapofMap.isEmpty() && !String.isBlank(crop) && !String.isBlank(variety) && !String.isBlank(treatment)) {
for(string s: TECPMapofMap.get(treatment).keySet()){
if(s != null) {
carrierOptions.add(new SelectOption(s, s));
}
}
}
carrierOptions.sort();
return carrierOptions;
} set;}
public List<SelectOption> packagingOptions {get {
packagingOptions = new List<SelectOption>();
packagingOptions.add(new SelectOption(' ', ' '));
if(TECPMapofMap != null && !TECPMapofMap.isEmpty() && !String.isBlank(crop) && !String.isBlank(variety) && !String.isBlank(treatment) && !String.isBlank(enhancement) && !String.isBlank(carrier)) {
for(string s: TECPMapofMap.get(treatment).get(carrier).get(enhancement)){
if(s != null) {
packagingOptions.add(new SelectOption(s, s));
}
}
}
packagingOptions.sort();
return packagingOptions;
} set;}
public String crop {get; set {
PageReference pr = ApexPages.currentPage();
pr.getParameters().put('newLineId', null);
variety = null;
crop = value;}}
public String variety {get; set{
queryTECP();
variety = value;}}
//public String treatment {get; set { carrier = null; treatment = value;}}
//public String carrier {get; set {enhancement = null; carrier = value;}}
//public String enhancement {get; set {system.debug('--5 ' + packaging); packaging = null; enhancement = value; system.debug('--5-1 ' + packaging + '#' + enhancement);}}
//public String packaging {get; set {system.debug('--6 ' + packaging); packaging = value; system.debug('--6-1 ' + packaging);}}
public String treatment {get; set { treatment = value;}}
public String carrier {get; set {carrier = value;}}
public String enhancement {get; set {system.debug('--5 ' + packaging); enhancement = value; system.debug('--5-1 ' + packaging + '#' + enhancement);}}
public String packaging {get; set {system.debug('--6 ' + packaging); packaging = value; system.debug('--6-1 ' + packaging);}}
public Integer totalUnits {get; set;}
public string shippingDateTwo {get; set;}
public string QuantityError {get; set;}
public void validateQuantity() {
if(!String.isBlank(treatment) &&
!String.isBlank(enhancement) &&
!String.isBlank(carrier) &&
!String.isBlank(packaging)) {
Product2 p = [SELECT Id, Vs_Packagesize__c from Product2 WHERE
Matrl_Group__r.Name =: crop
AND Vs_Variety__r.Name =: variety
AND Hierarchy_Level__c = 'Material'
AND Vs_Seedenhancement_Desc__c =: enhancement
AND Vs_Treatment_Desc__c =: treatment
AND Vs_Carrier_Desc__c =: carrier
AND Packaging__c =: packaging
AND Product2.IsActive = true
LIMIT 1];
validateQuantity(p);
}
}
public void validateQuantity(product2 p) {
try{
if(Integer.ValueOf(orderLine.Quantity__c) < 0){
quantityError = 'Wrong product quantity entered';
}
else if(Math.mod(Integer.ValueOf(orderLine.Quantity__c), Integer.ValueOf(p.Vs_Packagesize__c)) != 0) {
quantityError = 'Must be in increments of ' + Integer.ValueOf(p.Vs_Packagesize__c);
}
else{
totalUnits = Integer.ValueOf(orderLine.Quantity__c) / Integer.ValueOf(p.Vs_Packagesize__c);
quantityError = null;
}
} catch (exception e) {
system.debug('ValidateQuantity Failed' + e.getMessage());
quantityError = null;
}
}
public pageReference save(){
boolean success = false;
if (String.isBlank(crop) || String.isBlank(variety)) {
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Please select Crop and Variety'));
} else if((!String.isBlank(treatment) ||
!String.isBlank(enhancement) ||
!String.isBlank(carrier) ||
!String.isBlank(packaging)) &&
!(!String.isBlank(treatment) &&
!String.isBlank(enhancement) &&
!String.isBlank(carrier) &&
!String.isBlank(packaging))
) {
String msg = '';
String[] errMsg = new List<String>{'Please fill out the following fields: '};
if(String.isBlank(treatment)) {errMsg.add('treatment');}
if(String.isBlank(enhancement)) {errMsg.add('enhancement');}
if(String.isBlank(carrier)) {errMsg.add('carrier');}
if(String.isBlank(packaging)) {errMsg.add('packaging');}
if(errMsg.size()>1) {
for(Integer i = 0; i<errMsg.size(); i++) {
msg = msg + errMsg[i];
if(i!= errMsg.size()-1 && i != 0) {
msg = msg + ', ';
} else if (i != 0) {
msg = msg +'.';
}
}
}
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, msg));
} else if(String.isBlank(treatment) &&
String.isBlank(enhancement) &&
String.isBlank(carrier) &&
String.isBlank(packaging) &&
String.isBlank(orderLine.Customer_Requirements__c)) {
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Please fill out Customer Requirements or Variety Options.'));
} else if (orderLine.Requested_Delivery_Date__c == null || orderLine.Requested_Delivery_Date__c < system.today()) {
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Requested Delivery Date must be in the future.'));
} else {
try {
//for Material products
Product2 p;
if(!String.isBlank(treatment) &&
!String.isBlank(enhancement) &&
!String.isBlank(carrier) &&
!String.isBlank(packaging)) {
p = [SELECT Id, Vs_Packagesize__c from Product2 WHERE
Matrl_Group__r.Name =: crop
AND Vs_Variety__r.Name =: variety
AND Hierarchy_Level__c = 'Material'
AND Vs_Seedenhancement_Desc__c =: enhancement
AND Vs_Treatment_Desc__c =: treatment
AND Vs_Carrier_Desc__c =: carrier
AND Packaging__c =: packaging
AND Product2.IsActive = true
LIMIT 1];
validateQuantity(p);
} else { //for variety level products
p = [SELECT Id from Product2 WHERE
Matrl_Group__r.Name =: crop
AND Name =: variety
AND Hierarchy_Level__c = 'Variety'
AND Product2.IsActive = true
LIMIT 1];
}
if(quantityError != null) {
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Quantity: ' + QuantityError));
} else if(p!= null) {
NA_Order_Line_Item__c oli = orderLine;
oli.Product__c = p.Id;
oli.Order__c = orderId;
try {
upsert oli;
newLineId = oli.Id;
crop = null;
variety = null;
treatment = null;
carrier = null;
enhancement = null;
system.debug('--7 ' + packaging);
packaging = null;
totalUnits = null;
orderLine = null;
success = true;
} catch (exception ue) {
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Failed to add product'));
}
}
} catch (exception e) {
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Failed to find the matching product'));
}
}
PageReference pr = null;
if(success) {
pr = new PageReference('/apex/Order_SIND2?orderId='+orderId+'&newLineId='+newLineId);
}
System.debug('!!!!!!!!!!!!!!!!!!!!!!!!!!' + pr);
return pr;
}
public boolean displayPopup {get; set;}
public void closePopup(){
displayPopup = false;
}
public void showPopup() {
displayPopup = true;
}
public string popupMsg{get; set;}
}
test class
continue post
public Map<String, Set<String>> cropVarietyMap{get{
if((cropVarietyMap == null || cropVarietyMap.isEmpty() || cropVarietyMap.size() == 1) && myorder != null ) {
cropVarietyMap = new Map<String, Set<String>>();
AggregateResult[] ARList = [SELECT Crop__c, Variety__c FROM Crop_And_Variety__c WHERE CurrencyIsoCode =: currencyCode AND PriceBook_ID__c IN: pricebookIDs GROUP BY Crop__c, Variety__c];
for(AggregateResult AR: ARList) {
String cropS = String.ValueOf(ar.get('Crop__c'));
String varietyS = String.ValueOf(ar.get('Variety__c'));
if(cropVarietyMap.get(cropS) == null) {
Set<String> s = new Set<String>{varietyS};
cropVarietyMap.put(cropS, s);
} else {
Set<String> s = cropVarietyMap.get(cropS);
s.add(varietyS);
cropVarietyMap.put(cropS, s);
}
}
}
return cropVarietyMap;
} set;}
public void queryTECP(){
treatment = null;
enhancement = null;
carrier = null;
system.debug('--1 ' + packaging);
packaging = null;
totalUnits = null;
quantityError = null;
pbeList = new List<PriceBookEntry>();
Map<String, Map<String, Map<String, Set<String>>>> newMap = TECPMapOfMap;
}
public List<PriceBookEntry> pbeList {get; set;}
public Map<String, Map<String, Map<String, Set<String>>>> cachedMap {get; set;}
public Map<String, Map<String, Map<String, Set<String>>>> TECPMapofMap {get {//key1-enhancement, key2-treatment, key 3-carrier
if(!String.isBlank(crop) && !String.isBlank(variety)){
if(pbeList == null || pbeList.isEmpty()) {
pbeList = [SELECT Id,
Product2Id,
Product2.Vs_Treatment_Desc__c,
Product2.Vs_Carrier_Desc__c,
Product2.Vs_Seedenhancement_Desc__c,
Product2.Packaging__c,
Product2.Vs_Packagesize__c
FROM PriceBookEntry
WHERE Product2.Matrl_Group__r.Name =: crop AND PriceBook2Id IN: pricebookIDs AND Product2.IsActive = true
AND Product2.Hierarchy_Level__c = 'Material' AND Product2.Vs_Variety__r.Name =: variety];
for(PriceBookEntry pbe: pbeList) {
string enhc = pbe.Product2.Vs_Seedenhancement_Desc__c;
string treat = pbe.Product2.Vs_Treatment_Desc__c;
string carr = pbe.Product2.Vs_Carrier_Desc__c;
string pckg = pbe.Product2.Packaging__c;
if(TECPMapofMap.get(treat) == null) { //add treatment
TECPMapofMap.put(treat, new Map<String, Map<String, Set<String>>>());
}
if(TECPMapofMap.get(treat).get(carr) == null) { //add carrier
TECPMapofMap.get(treat).put(carr, new Map<String, Set<String>>());
}
if(TECPMapofMap.get(treat).get(carr).get(enhc) == null) { //add enhancement
TECPMapofMap.get(treat).get(carr).put(enhc, new Set<String>());
}
if(TECPMapofMap.get(treat).get(carr).get(enhc) == null) { //add packaging
TECPMapofMap.get(treat).get(carr).put(enhc, new Set<String>{pckg});
} else {
TECPMapofMap.get(treat).get(carr).get(enhc).add(pckg);
}
}
}
} else {
TECPMapofMap = new Map<String, Map<String, Map<String, Set<String>>>>(); //key1-treat, key2-carr, key 3-enhancement
}
return TECPMapofMap;
}set;}
public NA_Order_Line_Item__c orderLine{get {
if(orderLine == null) {
orderLine = new NA_Order_Line_Item__c();
}
return orderLine;
} set;}
public List<SelectOption> cropOptions {get {
cropOptions = new List<SelectOption>();
cropOptions.add(new SelectOption(' ', ' '));
if(cropVarietyMap != null && !cropVarietyMap.isEmpty() && cropVarietyMap.size() != 1) {
for(string s: cropVarietyMap.keySet()){
cropOptions.add(new SelectOption(s, s));
}
}
cropOptions.sort();
return cropOptions;
} set;}
public List<SelectOption> varietyOptions {get {
varietyOptions = new List<SelectOption>();
varietyOptions.add(new SelectOption(' ', ' '));
if(cropVarietyMap != null && !cropVarietyMap.isEmpty() && !String.IsBlank(crop)) {
for(string s: cropVarietyMap.get(crop)){
if(s != null) {
varietyOptions.add(new SelectOption(s, s));
}
}
}
varietyOptions.sort();
return varietyOptions;
} set;}
public List<SelectOption> treatmentOptions {get {
treatmentOptions = new List<SelectOption>();
treatmentOptions.add(new SelectOption(' ', ' '));
if(TECPMapofMap != null && !TECPMapofMap.isEmpty() && crop != null && variety != null) {
for(string s: TECPMapofMap.keySet()){
if(s != null) {
treatmentOptions.add(new SelectOption(s, s));
}
}
}
treatmentOptions.sort();
return treatmentOptions;
} set;}
public void onTreatmentChange(){
enhancement = null;
carrier = null;
system.debug('--2 ' + packaging);
packaging = null;
}
public void onEnhancementChange(){
system.debug('--3 ' + packaging);
packaging = null;
}
public void onPackagingChange(){
}
public void onCarrierChange(){
enhancement = null;
system.debug('--4 ' + packaging);
packaging = null;
}
public List<SelectOption> enhancementOptions {get {
enhancementOptions = new List<SelectOption>();
enhancementOptions.add(new SelectOption(' ', ' '));
if(TECPMapofMap != null && !TECPMapofMap.isEmpty() && !String.isBlank(crop) && !String.isBlank(variety) && !String.isBlank(treatment) && !String.isBlank(carrier)) {
for(string s: TECPMapofMap.get(treatment).get(carrier).keySet()){
if(s != null) {
enhancementOptions.add(new SelectOption(s, s));
}
}
}
enhancementOptions.sort();
return enhancementOptions;
} set;}
public List<SelectOption> carrierOptions {get {
carrierOptions = new List<SelectOption>();
carrierOptions.add(new SelectOption(' ', ' '));
if(TECPMapofMap != null && !TECPMapofMap.isEmpty() && !String.isBlank(crop) && !String.isBlank(variety) && !String.isBlank(treatment)) {
for(string s: TECPMapofMap.get(treatment).keySet()){
if(s != null) {
carrierOptions.add(new SelectOption(s, s));
}
}
}
carrierOptions.sort();
return carrierOptions;
} set;}
public List<SelectOption> packagingOptions {get {
packagingOptions = new List<SelectOption>();
packagingOptions.add(new SelectOption(' ', ' '));
if(TECPMapofMap != null && !TECPMapofMap.isEmpty() && !String.isBlank(crop) && !String.isBlank(variety) && !String.isBlank(treatment) && !String.isBlank(enhancement) && !String.isBlank(carrier)) {
for(string s: TECPMapofMap.get(treatment).get(carrier).get(enhancement)){
if(s != null) {
packagingOptions.add(new SelectOption(s, s));
}
}
}
packagingOptions.sort();
return packagingOptions;
} set;}
public String crop {get; set {
PageReference pr = ApexPages.currentPage();
pr.getParameters().put('newLineId', null);
variety = null;
crop = value;}}
public String variety {get; set{
queryTECP();
variety = value;}}
//public String treatment {get; set { carrier = null; treatment = value;}}
//public String carrier {get; set {enhancement = null; carrier = value;}}
//public String enhancement {get; set {system.debug('--5 ' + packaging); packaging = null; enhancement = value; system.debug('--5-1 ' + packaging + '#' + enhancement);}}
//public String packaging {get; set {system.debug('--6 ' + packaging); packaging = value; system.debug('--6-1 ' + packaging);}}
public String treatment {get; set { treatment = value;}}
public String carrier {get; set {carrier = value;}}
public String enhancement {get; set {system.debug('--5 ' + packaging); enhancement = value; system.debug('--5-1 ' + packaging + '#' + enhancement);}}
public String packaging {get; set {system.debug('--6 ' + packaging); packaging = value; system.debug('--6-1 ' + packaging);}}
public Integer totalUnits {get; set;}
public string shippingDateTwo {get; set;}
public string QuantityError {get; set;}
public void validateQuantity() {
if(!String.isBlank(treatment) &&
!String.isBlank(enhancement) &&
!String.isBlank(carrier) &&
!String.isBlank(packaging)) {
Product2 p = [SELECT Id, Vs_Packagesize__c from Product2 WHERE
Matrl_Group__r.Name =: crop
AND Vs_Variety__r.Name =: variety
AND Hierarchy_Level__c = 'Material'
AND Vs_Seedenhancement_Desc__c =: enhancement
AND Vs_Treatment_Desc__c =: treatment
AND Vs_Carrier_Desc__c =: carrier
AND Packaging__c =: packaging
AND Product2.IsActive = true
LIMIT 1];
validateQuantity(p);
}
}
public void validateQuantity(product2 p) {
try{
if(Integer.ValueOf(orderLine.Quantity__c) < 0){
quantityError = 'Wrong product quantity entered';
}
else if(Math.mod(Integer.ValueOf(orderLine.Quantity__c), Integer.ValueOf(p.Vs_Packagesize__c)) != 0) {
quantityError = 'Must be in increments of ' + Integer.ValueOf(p.Vs_Packagesize__c);
}
else{
totalUnits = Integer.ValueOf(orderLine.Quantity__c) / Integer.ValueOf(p.Vs_Packagesize__c);
quantityError = null;
}
} catch (exception e) {
system.debug('ValidateQuantity Failed' + e.getMessage());
quantityError = null;
}
}
public pageReference save(){
boolean success = false;
if (String.isBlank(crop) || String.isBlank(variety)) {
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Please select Crop and Variety'));
} else if((!String.isBlank(treatment) ||
!String.isBlank(enhancement) ||
!String.isBlank(carrier) ||
!String.isBlank(packaging)) &&
!(!String.isBlank(treatment) &&
!String.isBlank(enhancement) &&
!String.isBlank(carrier) &&
!String.isBlank(packaging))
) {
String msg = '';
String[] errMsg = new List<String>{'Please fill out the following fields: '};
if(String.isBlank(treatment)) {errMsg.add('treatment');}
if(String.isBlank(enhancement)) {errMsg.add('enhancement');}
if(String.isBlank(carrier)) {errMsg.add('carrier');}
if(String.isBlank(packaging)) {errMsg.add('packaging');}
if(errMsg.size()>1) {
for(Integer i = 0; i<errMsg.size(); i++) {
msg = msg + errMsg[i];
if(i!= errMsg.size()-1 && i != 0) {
msg = msg + ', ';
} else if (i != 0) {
msg = msg +'.';
}
}
}
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, msg));
} else if(String.isBlank(treatment) &&
String.isBlank(enhancement) &&
String.isBlank(carrier) &&
String.isBlank(packaging) &&
String.isBlank(orderLine.Customer_Requirements__c)) {
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Please fill out Customer Requirements or Variety Options.'));
} else if (orderLine.Requested_Delivery_Date__c == null || orderLine.Requested_Delivery_Date__c < system.today()) {
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Requested Delivery Date must be in the future.'));
} else {
try {
//for Material products
Product2 p;
if(!String.isBlank(treatment) &&
!String.isBlank(enhancement) &&
!String.isBlank(carrier) &&
!String.isBlank(packaging)) {
p = [SELECT Id, Vs_Packagesize__c from Product2 WHERE
Matrl_Group__r.Name =: crop
AND Vs_Variety__r.Name =: variety
AND Hierarchy_Level__c = 'Material'
AND Vs_Seedenhancement_Desc__c =: enhancement
AND Vs_Treatment_Desc__c =: treatment
AND Vs_Carrier_Desc__c =: carrier
AND Packaging__c =: packaging
AND Product2.IsActive = true
LIMIT 1];
validateQuantity(p);
} else { //for variety level products
p = [SELECT Id from Product2 WHERE
Matrl_Group__r.Name =: crop
AND Name =: variety
AND Hierarchy_Level__c = 'Variety'
AND Product2.IsActive = true
LIMIT 1];
}
if(quantityError != null) {
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Quantity: ' + QuantityError));
} else if(p!= null) {
NA_Order_Line_Item__c oli = orderLine;
oli.Product__c = p.Id;
oli.Order__c = orderId;
try {
upsert oli;
newLineId = oli.Id;
crop = null;
variety = null;
treatment = null;
carrier = null;
enhancement = null;
system.debug('--7 ' + packaging);
packaging = null;
totalUnits = null;
orderLine = null;
success = true;
} catch (exception ue) {
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Failed to add product'));
}
}
} catch (exception e) {
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Failed to find the matching product'));
}
}
PageReference pr = null;
if(success) {
pr = new PageReference('/apex/Order_SIND2?orderId='+orderId+'&newLineId='+newLineId);
}
System.debug('!!!!!!!!!!!!!!!!!!!!!!!!!!' + pr);
return pr;
}
public boolean displayPopup {get; set;}
public void closePopup(){
displayPopup = false;
}
public void showPopup() {
displayPopup = true;
}
public string popupMsg{get; set;}
}
test class
continue post
- vara sree
- December 09, 2014
- Like
- 0
how to improve code coverage below test class
@isTest(SeeAllData=false)
private class OrderProductComponentController_sindtest {
public static NA_Order__c orderTest;
public static Account accTest;
static testMethod void testWithProduct() {
initalize();
OrderProductComponentController_sind controller = new OrderProductComponentController_sind();
Test.startTest();
Map<String, Set<String>> cropVarietyMap = controller.cropVarietyMap;
controller.queryTECP();
Map<String, Map<String, Map<String, Set<String>>>> TECPMapofMapTest = controller.TECPMapofMap;
NA_Order_Line_Item__c orderLineTest = controller.orderLine;
List<SelectOption> cropOptionsTest = controller.cropOptions;
List<SelectOption> varietyOptionsTest = controller.varietyOptions;
List<SelectOption> treatmentOptionsTest = controller.treatmentOptions;
List<SelectOption> enhancementOptionsTest = controller.enhancementOptions;
List<SelectOption> carrierOptionsTest = controller.carrierOptions;
List<SelectOption> packagingOptionsTest = controller.packagingOptions;
String cropTest = controller.crop;
String varietyTest = controller.variety;
controller.validateQuantity();
Test.stopTest();
}
public static void initalize() {
accTest = TestUtils.createAccount('AccForTestingOrderProductPicker', 'USD', true);
orderTest = TestUtils.createOrder('Spot Order', Date.today(), 'UPS', 'OrderForTestingOrderProductPicker', 'Created', accTest.Id, true);
PageReference orderProductPicker = Page.Order;
orderProductPicker.getParameters().put('Id', orderTest.Id);
Test.setCurrentPage(orderProductPicker);
}
}
private class OrderProductComponentController_sindtest {
public static NA_Order__c orderTest;
public static Account accTest;
static testMethod void testWithProduct() {
initalize();
OrderProductComponentController_sind controller = new OrderProductComponentController_sind();
Test.startTest();
Map<String, Set<String>> cropVarietyMap = controller.cropVarietyMap;
controller.queryTECP();
Map<String, Map<String, Map<String, Set<String>>>> TECPMapofMapTest = controller.TECPMapofMap;
NA_Order_Line_Item__c orderLineTest = controller.orderLine;
List<SelectOption> cropOptionsTest = controller.cropOptions;
List<SelectOption> varietyOptionsTest = controller.varietyOptions;
List<SelectOption> treatmentOptionsTest = controller.treatmentOptions;
List<SelectOption> enhancementOptionsTest = controller.enhancementOptions;
List<SelectOption> carrierOptionsTest = controller.carrierOptions;
List<SelectOption> packagingOptionsTest = controller.packagingOptions;
String cropTest = controller.crop;
String varietyTest = controller.variety;
controller.validateQuantity();
Test.stopTest();
}
public static void initalize() {
accTest = TestUtils.createAccount('AccForTestingOrderProductPicker', 'USD', true);
orderTest = TestUtils.createOrder('Spot Order', Date.today(), 'UPS', 'OrderForTestingOrderProductPicker', 'Created', accTest.Id, true);
PageReference orderProductPicker = Page.Order;
orderProductPicker.getParameters().put('Id', orderTest.Id);
Test.setCurrentPage(orderProductPicker);
}
}
- vara sree
- December 08, 2014
- Like
- 0
how to write test class for the below code page controller
public with sharing virtual class OrderPageControllerBase {
private OrderComponentControllerBase myComponentController;
public virtual OrderComponentControllerBase getOrderComponentController() {
return myComponentController;
}
public virtual void setComponentController(OrderComponentControllerBase_SIND compController) {
myComponentController = compController;
}
public OrderPageControllerBase getThis() {
return this;
}
public NA_Order__c myOrder {get; set {
myOrder = value;
if(myOrder.Id != null) {
myOrder = [SELECT Id, Name,
CurrencyIsoCode,
Order_Type__c,
Order_Status__c,
Order_Date__c,
SAP_Order_ID__c,
PO_Number__c,
PO_Date__c,
CreatedBy.Name,
LastModifiedBy.Name,
Ship_Via__c,
Sold_To_ID__c,
Account__c,
Sold_To_Address__c,
Ship_To_ID__c,
Contact_Attention__c,
Ship_To_Address__c,
Ship_To__c,
Account__r.Name,
RecordTypeId,
CreatedDate,
LastModifiedDate,
Notes__c FROM NA_Order__c WHERE Id =: myOrder.Id];
}
}
}
}
private OrderComponentControllerBase myComponentController;
public virtual OrderComponentControllerBase getOrderComponentController() {
return myComponentController;
}
public virtual void setComponentController(OrderComponentControllerBase_SIND compController) {
myComponentController = compController;
}
public OrderPageControllerBase getThis() {
return this;
}
public NA_Order__c myOrder {get; set {
myOrder = value;
if(myOrder.Id != null) {
myOrder = [SELECT Id, Name,
CurrencyIsoCode,
Order_Type__c,
Order_Status__c,
Order_Date__c,
SAP_Order_ID__c,
PO_Number__c,
PO_Date__c,
CreatedBy.Name,
LastModifiedBy.Name,
Ship_Via__c,
Sold_To_ID__c,
Account__c,
Sold_To_Address__c,
Ship_To_ID__c,
Contact_Attention__c,
Ship_To_Address__c,
Ship_To__c,
Account__r.Name,
RecordTypeId,
CreatedDate,
LastModifiedDate,
Notes__c FROM NA_Order__c WHERE Id =: myOrder.Id];
}
}
}
}
- vara sree
- December 01, 2014
- Like
- 0