11@IsTest
22public with sharing class libak_TestRestFramework {
33
4- public static final String URI_TEMPLATE = ' /testRestFramework/:uriParam' ;
4+ public static final String URI_TEMPLATE_WITH_PARAMS = ' /testRestFramework/:uriParam' ;
5+ public static final String URI_TEMPLATE_WITHOUT_PARAMS = ' /testRestFramework' ;
56
67 @IsTest
78 static void testHandleRequestPositive (){
@@ -23,6 +24,46 @@ public with sharing class libak_TestRestFramework {
2324 );
2425 }
2526
27+ @IsTest
28+ static void testHandleRequestWithoutParamsPositive (){
29+ RestRequest request = new RestRequest ();
30+ request .requestURI = ' /testRestFramework' ;
31+ RestContext .request = request ;
32+ RestContext .response = new RestResponse ();
33+
34+ Test .startTest ();
35+
36+ libak_RestFramework .handleRequest (RestRouterInstance .class );
37+
38+ Test .stopTest ();
39+
40+ System .assertEquals (
41+ libak_RestFramework .HTTP_CODE_METHOD_NOT_ALLOWED ,
42+ RestContext .response .statusCode ,
43+ ' The status code of response should be 405'
44+ );
45+ }
46+
47+ @IsTest
48+ static void testHandleRequestWithoutParamsWithSlashAtTheEnd (){
49+ RestRequest request = new RestRequest ();
50+ request .requestURI = ' /testRestFramework/' ;
51+ RestContext .request = request ;
52+ RestContext .response = new RestResponse ();
53+
54+ Test .startTest ();
55+
56+ libak_RestFramework .handleRequest (RestRouterInstance .class );
57+
58+ Test .stopTest ();
59+
60+ System .assertEquals (
61+ libak_RestFramework .HTTP_CODE_METHOD_NOT_ALLOWED ,
62+ RestContext .response .statusCode ,
63+ ' The status code of response should be 405'
64+ );
65+ }
66+
2667 @IsTest
2768 static void testHandleRequestWrongRouter (){
2869 RestRequest request = new RestRequest ();
@@ -56,7 +97,8 @@ public with sharing class libak_TestRestFramework {
5697 private class RestRouterInstance extends libak_RestRouter {
5798 override public libak_RestRouter setRoutes () {
5899 this .routeToRestProcessorType = new Map <String , Type >{
59- URI_TEMPLATE = > libak_RestProcessor .class
100+ URI_TEMPLATE_WITH_PARAMS = > libak_RestProcessor .class ,
101+ URI_TEMPLATE_WITHOUT_PARAMS = > libak_RestProcessor .class
60102 };
61103 return this ;
62104 }
0 commit comments