function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
divya1234divya1234 

Challenge Not yet complete... here's what's wrong: Could not find a class named 'WarehouseCalloutServiceMock' containing a mock callout response.

I have developed some code for Step 5 in the Superbadge, but appear to stuck as I run the test. I am encountering an error and attempting to determine how to configure my code to pass the test. Are there any steps I am missing? I've covered much of the superbadge, but remain stuck here. 
@isTest
global class WarehouseCalloutServiceMock implements HttpCalloutMock {
    // implement http mock callout
    global HttpResponse respond(HttpRequest request){
        
        System.assertEquals('https://th-superbadge-apex.herokuapp.com/equipment', request.getEndpoint());
        System.assertEquals('GET', request.getMethod());
        
    	// Create a fake response
		HttpResponse response = new HttpResponse();
        response.setHeader('Content-Type', 'application/json');
		response.setBody('[{"_id":"55d66226726b611100aaf741","replacement":false,"quantity":5,"name":"Generator 1000 kW","maintenanceperiod":365,"lifespan":120,"cost":5000,"sku":"100003"}]');
        response.setStatusCode(200);
        return response;
    }
}
@isTest
private class WarehouseCalloutServiceTest {
  // implement your mock callout test here
	@isTest
    static void WarehouseEquipmentSync(){
        Test.startTest();
        // Set mock callout class 
        Test.setMock(HttpCalloutMock.class, new WarehouseCalloutServiceMock()); 
        // This causes a fake response to be sent from the class that implements HttpCalloutMock. 
        WarehouseCalloutService.runWarehouseEquipmentSync();
        Test.stopTest();        
        System.assertEquals(1, [SELECT count() FROM Product2]);        
        
    }
    
}
public with sharing class WarehouseCalloutService {

    private static final String WAREHOUSE_URL = 'https://th-superbadge-apex.herokuapp.com/equipment';
    
    // complete this method to make the callout (using @future) to the
    // REST endpoint and update equipment on hand.
    @future(callout=true)
    public static void runWarehouseEquipmentSync(){
        Http http = new Http();
		HttpRequest request = new HttpRequest();
		request.setEndpoint(WAREHOUSE_URL);
		request.setMethod('GET');
		HttpResponse response = http.send(request);
		// If the request is successful, parse the JSON response.
		if (response.getStatusCode() == 200) {
    		// Deserialize the JSON string into collections of primitive data types.
    		List<Object> equipments = (List<Object>) JSON.deserializeUntyped(response.getBody());
            List<Product2> products = new List<Product2>();
            for(Object o :  equipments){
                Map<String, Object> mapProduct = (Map<String, Object>)o;
                Product2 product = new Product2();
                product.Name = (String)mapProduct.get('name');
                product.Cost__c = (Integer)mapProduct.get('cost');
                product.Current_Inventory__c = (Integer)mapProduct.get('quantity');
                product.Maintenance_Cycle__c = (Integer)mapProduct.get('maintenanceperiod');
                product.Replacement_Part__c = (Boolean)mapProduct.get('replacement');
                product.Lifespan_Months__c = (Integer)mapProduct.get('lifespan');
                product.Warehouse_SKU__c = (String)mapProduct.get('sku');
                product.ProductCode = (String)mapProduct.get('_id');
                products.add(product);
            }
            if(products.size() > 0){
                System.debug(products);
                upsert products;
            }
		}
    }

}

Please Help!



 
Amit Chaudhary 8Amit Chaudhary 8
Try to delete the same class and create again
Narender Singh(Nads)Narender Singh(Nads)
Hi Divya,
Please define your method as static in class WarehouseCalloutServiceMock and try again.
Like this:
@isTest
global class WarehouseCalloutServiceMock implements HttpCalloutMock {
    // implement http mock callout
    global static HttpResponse respond(HttpRequest request){
        
        System.assertEquals('https://th-superbadge-apex.herokuapp.com/equipment', request.getEndpoint());
        System.assertEquals('GET', request.getMethod());
        
        // Create a fake response
        HttpResponse response = new HttpResponse();
        response.setHeader('Content-Type', 'application/json');
        response.setBody('[{"_id":"55d66226726b611100aaf741","replacement":false,"quantity":5,"name":"Generator 1000 kW","maintenanceperiod":365,"lifespan":120,"cost":5000,"sku":"100003"}]');
        response.setStatusCode(200);
        return response;
    }
}

Let me know if it helps.
Thanks
Yuriy NesterenkoYuriy Nesterenko
Make sure the trailhead has checked the required playground.
 
Kaleb HermesKaleb Hermes
I just wanted to drop in and say that Yuriy is right, make sure you're checking against the correct playground. Step 5 was the first step that made me want to go back and check the code that I'd written during the training leading up to the Super Badge challenge. I forgot that I'd changed my playground selection to an older playground, so I was checking againt that, instead of the new one I made for the challenge. 
Rahul Jain 152Rahul Jain 152
Mock Test class is perfect , please start a new TP to avoid this issue .

Thanks
Rahul Jain 
Abhishek Kumar 793Abhishek Kumar 793
Hi All,

Please check below URL, you will pass this challenge :

https://github.com/abhishekcse122/Apex-Specialist-Superbadge
Shubham DahibhateShubham Dahibhate
Apex Specialist 7th 
apex class == WarehouseSyncSchedule 
global class WarehouseSyncSchedule implements Queueable   {
    
    global void execute(System.QueueableContext  SC) {
        System.enqueueJob(new WarehouseCalloutService());
    }
    private static String CRON_EXP = '0 0 0 * * ? 2020';
    public static Id scheduleMorningRun() {
        Integer pstTargetHour = 1; // 24 hour time     
        Integer pstOffset = -8;
        Integer userOffset = UserInfo.getTimeZone().getOffset(Date.today());
        Integer userTime = Math.mod(pstTargetHour - pstOffset + userOffSet, 24);         
        
        System.debug('==15='+pstTargetHour);
        System.debug('==16='+pstOffset);
        System.debug('===17='+userOffset);
        System.debug('===18='+userTime);
        String schedule = '0 1 0 1 1/1 ? *';
        System.debug('===19='+schedule);
        return System.enqueueJob(new WarehouseSyncSchedule());
    }
}
===============================================================================================================
@isTest(seeallData = true)
private class WarehouseSyncScheduleTest {
    //private static final User TestRunner = TEST_RunAsUserFactory.create(); 
    private static String CRON_EXP = '0 0 0 * * ? 2022';
    @isTest static void testScheduleMorningRun(){
        Test.setMock(HttpCalloutMock.class, new WarehouseCalloutServiceMock());
        
        Id resultJobId;
        Test.startTest();{
        WarehouseSyncSchedule URL = new WarehouseSyncSchedule();
        }
        resultJobId = WarehouseSyncSchedule.scheduleMorningRun(); 
        System.enqueueJob(new WarehouseSyncSchedule());
        Test.stopTest();
        System.assertEquals('Test', resultJobId) ;       
    }        
}

Try this One you will get 100% test coverage.
Thank you...