/**
|
* This class contains unit tests for vaaidating the behavior of Apex classes
|
* and triggers.
|
*
|
* Unit tests are class methods that verify whether a particular piece
|
* of code is working properly. Unit test methods take no arguments,
|
* commit no data to the database, and are flagged with the testMethod
|
* keyword in the method definition.
|
*
|
* All test methods in an organization are executed whenever Apex code is deployed
|
* to a production organization to confirm correctness, ensure code
|
* coverage, and prevent regressions. All Apex classes are
|
* required to have at least 75% code coverage in order to be deployed
|
* to a production organization. In addition, all triggers must have some code coverage.
|
*
|
* The @isTest class annotation indicates this class only contains test
|
* methods. Classes defined with the @isTest annotation do not count against
|
* the organization size limit for all Apex scripts.
|
*
|
* See the Apex Language Reference for more information about Testing and Code Coverage.
|
*/
|
|
@isTest
|
private class OFSEventCreateRestTest {
|
//aid is not blank
|
static testMethod void myUnitTest1() {
|
// TO DO: implement unit test
|
|
//RecordType を取得
|
List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
|
if (rectCo.size() == 0) {
|
return;
|
}
|
|
String subject = 'test_task';
|
Datetime startDate = Datetime.now().addDays(1);
|
String dt = startDate.format('yyyy-MM-dd');
|
// insert
|
Account company1 = new Account();
|
company1.RecordTypeId = rectCo[0].Id;
|
company1.Name = '病院テスト1';
|
insert company1;
|
|
List<Account> accs = [select Name, Id from Account where Id = :company1.Id];
|
system.assertEquals(1, accs.size());
|
company1 = accs[0];
|
String loc = company1.Name;
|
Id aid = company1.Id;
|
system.debug('Testaid:'+ aid);
|
String cid = '';
|
String mid = '';
|
String oid = '';
|
|
Test.startTest();
|
RestResponse res = new RestResponse();
|
RestContext.response= res;
|
|
OFSEventCreateRest.doPost(subject, '病院', '', dt,
|
startDate.addMinutes(60 * 10).getTime(),
|
startDate.addMinutes(60 * 12).getTime(),
|
aid, '', cid, oid, mid, loc
|
);
|
Test.stopTest();
|
System.debug('RestResponse res:' + res);
|
String str = res.responseBody.toString();
|
system.assert(str.contains(System.Label.OFSErrorSuccess));
|
|
List<Event> elist=[select id, Activity_Type2__c, StartDateTime from Event where Subject =:subject];
|
system.assertEquals(1, elist.size());
|
system.assertEquals('病院', elist[0].Activity_Type2__c);
|
}
|
//aid = ''
|
static testMethod void myUnitTest2() {
|
// TO DO: implement unit test
|
//RecordType を取得
|
List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
|
if (rectCo.size() == 0) {
|
return;
|
}
|
|
String subject = 'test_task';
|
Datetime startDate = Datetime.now().addDays(1);
|
String dt = startDate.format('yyyy-MM-dd');
|
// insert
|
Account company1 = new Account();
|
company1.RecordTypeId = rectCo[0].Id;
|
company1.Name = '病院テスト1';
|
insert company1;
|
company1 = [select Name, Id from Account where Id = :company1.Id];
|
String loc = company1.Name;
|
Id aid = company1.Id;
|
String cid = '';
|
String mid = '';
|
String oid = '';
|
Test.startTest();
|
RestResponse res = new RestResponse();
|
RestContext.response= res;
|
OFSEventCreateRest.doPost(subject, '病院', '', dt,
|
startDate.addMinutes(60 * 10).getTime(),
|
startDate.addMinutes(60 * 12).getTime(),
|
'', '', cid, oid, mid, loc
|
);
|
Test.stopTest();
|
System.debug('RestResponse res:' + res);
|
String str = res.responseBody.toString();
|
system.assert(str.contains(System.Label.OFSErrorSuccess));
|
|
List<Event> elist=[select id, Activity_Type2__c, StartDateTime from Event where Subject =:subject];
|
system.assertEquals(1, elist.size());
|
system.assertEquals('病院', elist[0].Activity_Type2__c);
|
}
|
}
|