---
schema_version: "1"
id: a60262f70282ec6564735aae1e660242506e673e6486d328f7a15febbcf93fd4
title: Archive SDK Testing
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/platform/264-0-0/archive_o_archive_sdk_testing.md
canonical_url: https://help.salesforce.com/s/articleView?id=platform.archive_o_archive_sdk_testing.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: 8fdbd059f7a12b93e341625dad919030a5bd0a9cac366e04fb773ca3364dc682
description: Before working in your production environment in the Archive managed package, test your Apex Class Wrapper in the Archive SDK. This article explains creating and running tests to ensure the Apex Class Wrapper behaves as expected.
products:
  - Security
  - Salesforce Platform
release: "264"
---
# Archive SDK Testing

Before working in your production environment in the Archive managed package, test your Apex Class Wrapper in the Archive SDK. This article explains creating and running tests to ensure the Apex Class Wrapper behaves as expected.

![Note](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-platform-own_from_salesforce-264-0-0-production-enus/8ac98673-ede2-4046-a41e-2d5c846f24ff/images/icon_note.png)

Note This content relates to Archive. For Salesforce Archive, see [Store Data Externally with Salesforce Archive](https://help.salesforce.com/s/articleView?id=xcloud.archive_overview.htm&type=5&language=en_US).

## MockHttpResponseGenerator.cls

Depicts the mock for callout, and this class implements `HttpCalloutMock` Apex interface.

```
@isTest
global class MockHttpResponseGenerator implements HttpCalloutMock {
public String fakeResponseJson;
public integer statusCode;
String redirectHeader;

public MockHttpResponseGenerator(String fakeResponseJson,Integer statusCode){
this.statusCode = statusCode;
this.fakeResponseJson = fakeResponseJson;
this.redirectHeader = '/example/test';

}

public HTTPResponse respond(HTTPRequest req) {
HTTPResponse res = new HTTPResponse();
res.setBody(this.fakeResponseJson);
res.setStatusCode(this.statusCode);
res.setHeader('Location',  this.redirectHeader);
return res;
}
}
```

## SearchSdkTest.cls

This code tests the global search functionality of the `OB_Archiver.ArchiverAccessor` by setting up a mock HTTP using the above class. This test ensures the search operation returns the expected JSON data and status code.

```
@isTest
public with sharing class searchSdkTest {

@isTest
private static void searchSdk() {
// Define a JSON string to be used as the mock response body
String jsonBody = '{"records": [{"CaseNumber":"01916767", "Id":"500Xx000000XXXXXX"}], "total_result_count": 1, "scroll_id":"-1" }';

// Set up the mock HTTP response using the predefined JSON body and HTTP 200 status code
OB_Archiver.ArchiverAccessor.setMock((HttpCalloutMock) new MockHttpResponseGenerator(jsonBody, OB_Archiver.ArchiverAccessorResponse.HTTP_200_OK));

// Insert a test archive configuration
insert createTestArchiveConfiguration();

// Create a list to hold search filters
list<OB_Archiver.SearchFilter> request1 = new list<OB_Archiver.SearchFilter>();

// Create a new search filter with the name 'test' and add it to the list
OB_Archiver.SearchFilter filter1 = new OB_Archiver.SearchFilter('Name', 'test');
request1.add(filter1);

// Start the test context
Test.startTest();

// Perform a global search using the archiver accessor and capture the response
OB_Archiver.ArchiverAccessorResponse res = OB_Archiver.ArchiverAccessor.performArchiverGlobalSearch('Account', request1);

// Stop the test context
Test.stopTest();

// Assert that the response status code is HTTP 200 OK
system.assertEquals(OB_Archiver.ArchiverAccessorResponse.HTTP_200_OK, res.getStatusCode());

// Assert that the response body matches the predefined JSON body
system.assertEquals(res.getBody(), jsonBody);
}

private static OB_Archiver__Archive_Configuration__c createTestArchiveConfiguration(){
return createTestArchiveConfiguration('https://example');
}
public static OB_Archiver__Archive_Configuration__c createTestArchiveConfiguration(String url){
OB_Archiver__Archive_Configuration__c ac = new  OB_Archiver__Archive_Configuration__c();
ac.Name = 'OB_URL';
ac.OB_Archiver__URL__c = url;
ac.OB_Archiver__API_Name__c='OB_URL';
return ac;
}
}
```