• fdwebmaster
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies

I have an apex page that posts a quantity variable that a user inputs to a class file.  It works fine when the user uses it, but when running the test functions it fails.  If I take the limit variable out on the SOQL statement though the test will pass.

 

If I hard code the quantity variable the test will pass as well, but if I leave the qantity variable as is, the test fails.  This is the only piece I can't get to pass so I can  push to production.  The quantity needs to come from the apex page as it pulls the necessary amount of records based upon the value from that quantity field.

 

 

public Integer quantity { get; set; }
public Integer licenseType {get; set;}

Integer previewCount;
Integer qty = 1;

public List<License_Inventory__c> LicenseInventoryItem {get; set; }  
public List<License_Inventory__c> Licenses {get; set;}

public License_Inventory__c generatePreview()
{
    previewCount = quantity > 15 ? 15 : quantity;
Licenses =  [SELECT Id, License__c, License_Type__c, Status__c FROM License_Inventory__c WHERE Status__c = 'Inventory' AND License_Type__c = :licenseType ORDER BY License__c ASC LIMIT :previewCount];   
		
    return null;
}

public  License_inventory__c getLicenses()
{ 
     sequential = 0;
     string status = 'Inventory';
		
     qty = quantity > 1 ? 1 : quantity;
		
     List<License_Inventory__c> LicenseInventoryItem = [SELECT Id, License__c, License_Type__c, Status__c, Product__c, Product_Code__c, Version__c, Total_Installations_Allowed__c FROM License_Inventory__c WHERE Status__c = :status AND License_Type__c = :licenseType ORDER BY License__c ASC LIMIT :qty];   
		
     inventories = new License_Inventory__c[0];
     for (License_Inventory__c l : LicenseInventoryItem) 
     {
       //additional code
     }
}

 
    @isTest(SeeAllData = True)
    public static void getLicensesTest()
    {
        License_Inventory__c ll = new License_Inventory__c();
        NumberPeelerController controller = new NumberPeelerController();

        integer sequential = 0;
        integer quantity;
        quantity = 10;
        Integer qty;
        qty = quantity;
        string status = 'Inventory';
        
        ll.License__c = '000-000-000-000';
        insert ll;
        
        //Run Licenses Test        
        List<License_Inventory__c> sl = [SELECT Id, License__c    FROM License_Inventory__c WHERE Status__c = :status AND License_Type__c = 'Full' LIMIT :qty]; 
        
        System.assertEquals(10, sl.size());
    }	

@isTest(SeeAllData = True)
	public static void getLicensesTest()
	{
		License_Inventory__c ll = new License_Inventory__c();
		NumberPeelerController controller = new NumberPeelerController();

		integer sequential = 0;
		integer quantity;
		quantity = 10;
		Integer qty;
		qty = quantity;
		string status = 'Inventory';
		
		ll.License__c = '000-000-000-000';
		insert ll;
		
		//Run Licenses Test		
		List<License_Inventory__c> sl = [SELECT Id, License__c	FROM License_Inventory__c WHERE Status__c = :status AND License_Type__c = 'Full' LIMIT :qty]; 
		
		System.assertEquals(10, sl.size());
	}

 

Any help would be appreciated as I'm stuck on this last portion.

 

Thanks

 

I have an apex page that posts a quantity variable that a user inputs to a class file.  It works fine when the user uses it, but when running the test functions it fails.  If I take the limit variable out on the SOQL statement though the test will pass.

 

If I hard code the quantity variable the test will pass as well, but if I leave the qantity variable as is, the test fails.  This is the only piece I can't get to pass so I can  push to production.  The quantity needs to come from the apex page as it pulls the necessary amount of records based upon the value from that quantity field.

 

 

public Integer quantity { get; set; }
public Integer licenseType {get; set;}

Integer previewCount;
Integer qty = 1;

public List<License_Inventory__c> LicenseInventoryItem {get; set; }  
public List<License_Inventory__c> Licenses {get; set;}

public License_Inventory__c generatePreview()
{
    previewCount = quantity > 15 ? 15 : quantity;
Licenses =  [SELECT Id, License__c, License_Type__c, Status__c FROM License_Inventory__c WHERE Status__c = 'Inventory' AND License_Type__c = :licenseType ORDER BY License__c ASC LIMIT :previewCount];   
		
    return null;
}

public  License_inventory__c getLicenses()
{ 
     sequential = 0;
     string status = 'Inventory';
		
     qty = quantity > 1 ? 1 : quantity;
		
     List<License_Inventory__c> LicenseInventoryItem = [SELECT Id, License__c, License_Type__c, Status__c, Product__c, Product_Code__c, Version__c, Total_Installations_Allowed__c FROM License_Inventory__c WHERE Status__c = :status AND License_Type__c = :licenseType ORDER BY License__c ASC LIMIT :qty];   
		
     inventories = new License_Inventory__c[0];
     for (License_Inventory__c l : LicenseInventoryItem) 
     {
       //additional code
     }
}

 
    @isTest(SeeAllData = True)
    public static void getLicensesTest()
    {
        License_Inventory__c ll = new License_Inventory__c();
        NumberPeelerController controller = new NumberPeelerController();

        integer sequential = 0;
        integer quantity;
        quantity = 10;
        Integer qty;
        qty = quantity;
        string status = 'Inventory';
        
        ll.License__c = '000-000-000-000';
        insert ll;
        
        //Run Licenses Test        
        List<License_Inventory__c> sl = [SELECT Id, License__c    FROM License_Inventory__c WHERE Status__c = :status AND License_Type__c = 'Full' LIMIT :qty]; 
        
        System.assertEquals(10, sl.size());
    }	

@isTest(SeeAllData = True)
	public static void getLicensesTest()
	{
		License_Inventory__c ll = new License_Inventory__c();
		NumberPeelerController controller = new NumberPeelerController();

		integer sequential = 0;
		integer quantity;
		quantity = 10;
		Integer qty;
		qty = quantity;
		string status = 'Inventory';
		
		ll.License__c = '000-000-000-000';
		insert ll;
		
		//Run Licenses Test		
		List<License_Inventory__c> sl = [SELECT Id, License__c	FROM License_Inventory__c WHERE Status__c = :status AND License_Type__c = 'Full' LIMIT :qty]; 
		
		System.assertEquals(10, sl.size());
	}

 

Any help would be appreciated as I'm stuck on this last portion.

 

Thanks