@ -13,19 +13,28 @@ my($opt,$report,$api_config,$api_info,$config,$test_machine,$fake_data) =
 
			
		
	
		
			
				
					    ( { } , { } , { } , { }  ) ; 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					$ opt  =  {  
			
		
	
		
			
				
					    'collections'       = >  { ' callcontrol s' = >  1 , } , 
 
			
		
	
		
			
				
					    'collections'       = >  { ' sm s' = >  1 , } , 
 
			
		
	
		
			
				
					    'collections'       = >  { } , 
 
			
		
	
		
			
				
					    'ignore_existence'  = >  1 , 
 
			
		
	
		
			
				
					    'test_groups'       = >  {  post  = >  1 ,  } , #get2put,get2patch,bundle 
 
			
		
	
		
			
				
					    'test_groups'       = >  {  
 
			
		
	
		
			
				
					        get2put  = >  1 ,  
 
			
		
	
		
			
				
					        #get2patch => 1,  
 
			
		
	
		
			
				
					        post  = > 1 ,  
 
			
		
	
		
			
				
					        get  = > 1 ,  
 
			
		
	
		
			
				
					        bundle  = > 1  
 
			
		
	
		
			
				
					    } , #post,get2put,get2patch,bundle 
 
			
		
	
		
			
				
					    #'test_groups'      => { post => 1 },#post,get2put,get2patch,bundle 
 
			
		
	
		
			
				
					} ;  
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					$ test_machine  =  Test::Collection - > new (  
			
		
	
		
			
				
					    name                    = >  '' , 
 
			
		
	
		
			
				
					    ALLOW_EMPTY_COLLECTION  = >  1 , 
 
			
		
	
		
			
				
					    QUIET_DELETION          = >  0 , 
 
			
		
	
		
			
				
					    runas_role              = >  'reseller' , 
 
			
		
	
		
			
				
					    runas_role              = >  ' admin ', 
 
			
		
	
		
			
				
					) ;  
			
		
	
		
			
				
					$ fake_data  =  Test::FakeData - > new ;  
			
		
	
		
			
				
					$ fake_data - > test_machine - > QUIET_DELETION ( 0 ) ;  
			
		
	
		
			
				
					$ fake_data - > test_machine - > KEEP_CREATED ( 0 ) ;  
			
		
	
		
			
				
					$ test_machine - > clear_cache ;  
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					get_opt ( ) ;  
			
		
	
	
		
			
				
					
						
						
						
							
								 
						
					 
				
				@ -36,10 +45,11 @@ init_report();
 
			
		
	
		
			
				
					run ( ) ;  
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					$ test_machine - > clear_test_data_all ( ) ;  
			
		
	
		
			
				
					done_testing ;  
			
		
	
		
			
				
					undef  $ fake_data ;  
			
		
	
		
			
				
					undef  $ test_machine ;  
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					done_testing ;  
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					print  Dumper  $ report ;  
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					
 
			
		
	
	
		
			
				
					
						
						
						
							
								 
						
					 
				
				@ -48,8 +58,7 @@ print Dumper $report;
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					sub  run {  
			
		
	
		
			
				
					    #my($opt,$report,$api_info,$test_machine,$fake_data,$config) 
 
			
		
	
		
			
				
					    foreach  my  $ collection  (  sort  grep  {  collection4testing ( $ _ )  }  keys  % { $ api_info }  ) { 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					    foreach  my  $ collection  (  sort  grep  {  collection4testing ( $ _ )  ?  1  :  ( )  }  keys  % { $ api_info }  ) { 
 
			
		
	
		
			
				
					        $ test_machine - > name ( $ collection ) ; 
 
			
		
	
		
			
				
					        $ test_machine - > NO_ITEM_MODULE ( $ api_info - > { $ collection } - > { module_item }  ?  0  :  1  ) ; 
 
			
		
	
		
			
				
					        $ test_machine - > methods ( { 
 
			
		
	
	
		
			
				
					
						
						
						
							
								 
						
					 
				
				@ -57,51 +66,63 @@ sub run{
 
			
		
	
		
			
				
					            item        = >  {  allowed  = >  {  map  {  $ _  = >  1  }  keys  % { $ api_info - > { $ collection } - > { allowed_methods_item } }  } } , 
 
			
		
	
		
			
				
					        } ) ; 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					        if ( $ opt - > { test_groups } - > { bundle } ) { 
 
			
		
	
		
			
				
					            $ test_machine - > check_bundle ( ) ; 
 
			
		
	
		
			
				
					        if ( ! $ fake_data - > { data } - > { $ collection } - > { data } ) { 
 
			
		
	
		
			
				
					            testscript_under_framework ( $ collection ) ; 
 
			
		
	
		
			
				
					        } 
 
			
		
	
		
			
				
					        print  "collection: $collection;\n" ; 
 
			
		
	
		
			
				
					        if ( $ opt - > { test_groups } - > { post } ) { 
 
			
		
	
		
			
				
					            if ( $ test_machine - > { methods } - > { collection } - > { allowed } - > { POST } ) { 
 
			
		
	
		
			
				
					                print  "collection: $collection: post;\n" ; 
 
			
		
	
		
			
				
					                #load date  
 
			
		
	
		
			
				
					                if ( ! $ fake_data - > { data } - > { $ collection } - > { data } ) { 
 
			
		
	
		
			
				
					                    testscript_under_framework ( $ collection ) ; 
 
			
		
	
		
			
				
					                } 
 
			
		
	
		
			
				
					                if ( $ fake_data - > { data } - > { $ collection } - > { data } ) { 
 
			
		
	
		
			
				
					                    my  $ data  =  $ fake_data - > { data } - > { $ collection } - > { data } ; 
 
			
		
	
		
			
				
					                    #$data->{json} && ( $data = $data->{json}); 
 
			
		
	
		
			
				
					                    #TODO: ALL packages should have information about content_typr 
 
			
		
	
		
			
				
					                    if ( $ data - > { json }  &&  (  $ data  =  $ data - > { json } ) ) { 
 
			
		
	
		
			
				
					                        $ test_machine - > content_type - > { POST }  =  'multipart/form-data' ; 
 
			
		
	
		
			
				
					                    $ fake_data - > process ( $ collection ) ; 
 
			
		
	
		
			
				
					                    if ( $ fake_data - > { data } - > { $ collection } - > { create_special } ) { 
 
			
		
	
		
			
				
					                        $ fake_data - > { data } - > { $ collection } - > { create_special } - > ( $ fake_data , $ collection , $ test_machine ) ; 
 
			
		
	
		
			
				
					                    } else { 
 
			
		
	
		
			
				
					                        $ test_machine - > content_type - > { POST }  =  'application/json' ; 
 
			
		
	
		
			
				
					                        $ test_machine - > check_create_correct (  
 
			
		
	
		
			
				
					                            1 ,  
 
			
		
	
		
			
				
					                            $ fake_data - > { data } - > { $ collection } - > { data_callbacks } - > { uniquizer_cb } ,  
 
			
		
	
		
			
				
					                            clone  $ fake_data - > { data } - > { $ collection } - > { data }  
 
			
		
	
		
			
				
					                        ) ; 
 
			
		
	
		
			
				
					                    } 
 
			
		
	
		
			
				
					                    $ fake_data - > process ( $ collection ) ; 
 
			
		
	
		
			
				
					                    $ test_machine - > check_create_correct (  
 
			
		
	
		
			
				
					                        1 ,  
 
			
		
	
		
			
				
					                        $ fake_data - > { data } - > { $ collection } - > { uniquizer_cb } ,  
 
			
		
	
		
			
				
					                        clone  $ fake_data - > { data } - > { $ collection } - > { data }  
 
			
		
	
		
			
				
					                    ) ; 
 
			
		
	
		
			
				
					                    push  @ { $ report - > { post_tested } } ,  $ collection ; 
 
			
		
	
		
			
				
					                } else { 
 
			
		
	
		
			
				
					                    push  @ { $ report - > { post_untested } } ,  $ collection ; 
 
			
		
	
		
			
				
					                } 
 
			
		
	
		
			
				
					            } 
 
			
		
	
		
			
				
					        } 
 
			
		
	
		
			
				
					        if ( $ opt - > { test_groups } - > { bundle } ) { 
 
			
		
	
		
			
				
					            @ { $ test_machine - > content_type } { qw/POST PUT/ }     =  ( 
 
			
		
	
		
			
				
					                $ api_info - > { $ collection } - > { allowed_methods } - > { POST } - > { ContentType } - > [ 0 ]  ||  'application/json' , 
 
			
		
	
		
			
				
					                $ api_info - > { $ collection } - > { allowed_methods_item } - > { PUT } - > { ContentType } > [ 0 ]  ||  'application/json' , 
 
			
		
	
		
			
				
					            ) ; 
 
			
		
	
		
			
				
					            $ test_machine - > check_bundle ( ) ; 
 
			
		
	
		
			
				
					        } 
 
			
		
	
		
			
				
					        if ( $ opt - > { test_groups } - > { get } ) { 
 
			
		
	
		
			
				
					            if ( $ test_machine - > { methods } - > { collection } - > { allowed } - > { GET } ) { 
 
			
		
	
		
			
				
					                my  $ item  =  $ test_machine - > get_item_hal (  undef ,  undef ,  1 ) ; #reload 
 
			
		
	
		
			
				
					            } 
 
			
		
	
		
			
				
					        } 
 
			
		
	
		
			
				
					        if ( $ opt - > { test_groups } - > { get2put } ) { 
 
			
		
	
		
			
				
					            print  "collection: $collection: get2put;\n" ; 
 
			
		
	
		
			
				
					            #$test_machine->DATA_ITEM_STORE($fake_data->process($collection)); 
 
			
		
	
		
			
				
					            if ( $ test_machine - > { methods } - > { collection } - > { allowed } - > { GET } ) { 
 
			
		
	
		
			
				
					                my  $ item  =  $ test_machine - > get_item_hal (  undef ,  undef ,  1 ) ; #reload 
 
			
		
	
		
			
				
					                if ( ! $ test_machine - > IS_EMPTY_COLLECTION ) { 
 
			
		
	
		
			
				
					                    if ( $ test_machine - > { methods } - > { item } - > { allowed } - > { PUT } ) { 
 
			
		
	
		
			
				
					                        $ test_machine - > check_get2put ( ) ; 
 
			
		
	
		
			
				
					                        my  $ ignore_fields_parameter  =  $ fake_data - > { data } - > { $ collection } - > { update_change_fields } ; 
 
			
		
	
		
			
				
					                        $ ignore_fields_parameter  and  $ ignore_fields_parameter  =  {  ignore_fields  = >  $ ignore_fields_parameter  } ;  
 
			
		
	
		
			
				
					                        $ test_machine - > check_get2put (  { 
 
			
		
	
		
			
				
					                                data_cb  = >  $ fake_data - > { data } - > { $ collection } - > { data_callbacks } - > { get2put } , 
 
			
		
	
		
			
				
					                            } ,  {  
 
			
		
	
		
			
				
					                                uri  = >  $ item - > { location }  , 
 
			
		
	
		
			
				
					                            } ,  $ ignore_fields_parameter  ) ; 
 
			
		
	
		
			
				
					                    } 
 
			
		
	
		
			
				
					                } 
 
			
		
	
		
			
				
					            } 
 
			
		
	
		
			
				
					        } 
 
			
		
	
		
			
				
					        $ test_machine - > clear_data_created ; 
 
			
		
	
		
			
				
					        if ( ! $ test_machine - > { methods } - > { collection } - > { allowed } - > { GET } ) { 
 
			
		
	
		
			
				
					            push  @ { $ report - > { 'collections_no_get' } } ,  $ collection ; 
 
			
		
	
		
			
				
					        } 
 
			
		
	
	
		
			
				
					
						
							
								 
						
						
							
								 
						
						
					 
				
				@ -150,27 +171,37 @@ sub init_config{#init config
 
			
		
	
		
			
				
					        'domainpreferencedefs'  = >  1 , 
 
			
		
	
		
			
				
					        'peeringserverpreferencedefs'  = >  1 , 
 
			
		
	
		
			
				
					        'profilepreferencedefs'  = >  1 , 
 
			
		
	
		
			
				
					        'pbxdevicepreferencedefs'  = >  1 , 
 
			
		
	
		
			
				
					        'pbxdeviceprofilepreferencedefs'  = >  1 , 
 
			
		
	
		
			
				
					        'subscriberpreferences'  = >  1 , 
 
			
		
	
		
			
				
					        'customerpreferences'  = >  1 , 
 
			
		
	
		
			
				
					        'domainpreferences'  = >  1 , 
 
			
		
	
		
			
				
					        'peeringserverpreferences'  = >  1 , 
 
			
		
	
		
			
				
					        'profilepreferences'  = >  1 , 
 
			
		
	
		
			
				
					        'pbxdevicepreference def s' = >  1 , 
 
			
		
	
		
			
				
					        'pbxdeviceprofilepreference def s' = >  1 , 
 
			
		
	
		
			
				
					        'pbxdevicepreference s' = >  1 , 
 
			
		
	
		
			
				
					        'pbxdeviceprofilepreference s' = >  1 , 
 
			
		
	
		
			
				
					        #defs and preferences are tested in context of preferences 
 
			
		
	
		
			
				
					        'pbxdevicefirmwares'  = >  1 ,  #too hard, fails with timeout on get 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					    #falis with: not ok 163 - ccmapentries: check_get2put: check put successful (Unprocessable Entity: Validation failed. field='mappings', input='ARRAY(0x1a53f278)', errors='Mappings field is required') 
 
			
		
	
		
			
				
					        'ccmapentries'  = >  1 
 
			
		
	
		
			
				
					        #'ccmapentries' => 1 
 
			
		
	
		
			
				
					    #fails with: 
 
			
		
	
		
			
				
					    #          got: 'https://127.0.0.1:1443/api/customerzonecosts/?page=1&rows=5&start=2016-10-01T000000&end=2016-10-31T235959' 
 
			
		
	
		
			
				
					    #     expected: 'https://127.0.0.1:1443/api/customerzonecosts/?page=1&rows=5' 
 
			
		
	
		
			
				
					        'customerzonecosts'  = >  1 
 
			
		
	
		
			
				
					        #'customerzonecosts' => 1 
 
			
		
	
		
			
				
					    #fails with: Unsupported media type 'application/json', accepting text/plain or text/xml only.) 
 
			
		
	
		
			
				
					        'pbxdeviceconfigs'  = >  1 
 
			
		
	
		
			
				
					        #'pbxdeviceconfigs' => 1 
 
			
		
	
		
			
				
					    #fails with: not ok 1131 - rtcapps: check_get2put: check put successful (Unprocessable Entity: Invalid field 'apps'. Must be an array.) 
 
			
		
	
		
			
				
					        'rtcapps'  = >  1 
 
			
		
	
		
			
				
					        #'rtcapps' => 1 
 
			
		
	
		
			
				
					    #fails with: not ok 1176 - rtcnetworks: check_get2put: check put successful (Unprocessable Entity: Invalid field 'networks'. Must be an array.) 
 
			
		
	
		
			
				
					        'rtcnetworks'  = >  1 , 
 
			
		
	
		
			
				
					        #'rtcnetworks' => 1, 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					#--------- interceptions:  
			
		
	
		
			
				
					# No intercept agents configured in ngcp_panel.conf, rejecting request  
			
		
	
		
			
				
					#--------- callcontrols:  
			
		
	
		
			
				
					#Jan  3 12:48:20 sp1 ngcp-panel: INFO: received from dispatcher: $VAR1 = [#012 2,#012 1,#012 '<?xml version="1.0"?>#015#012<methodResponse><fault>#015#012#011<value><struct><member><name>faultCode</name><value><i4>-1</i4></value></member><member><name>faultString</name><value>dial_auth_b2b: unknown method name</value></member></struct></value>#015#012</fault></methodResponse>#015#012'#012];  
			
		
	
		
			
				
					#Jan  3 12:48:20 sp1 ngcp-panel: ERROR: failed to dial out: failed to trigger dial-out at /media/sf_/VMHost/ngcp-panel/lib/NGCP/Panel/Utils/Sems.pm line 326, <$fh> line 1.  
			
		
	
		
			
				
					#Jan  3 12:48:20 sp1 ngcp-panel: ERROR: error 500 - Failed to create call.  
			
		
	
		
			
				
					    ) ; 
 
			
		
	
		
			
				
					    my  % test_exists ; 
 
			
		
	
		
			
				
					    { 
 
			
		
	
	
		
			
				
					
						
							
								 
						
						
							
								 
						
						
					 
				
				@ -205,20 +236,43 @@ sub testscript_under_framework{
 
			
		
	
		
			
				
					}  
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					sub  collection4testing {  
			
		
	
		
			
				
					    my  $ collection  =  shift ; 
 
			
		
	
		
			
				
					    my  $ r  =  ( !  (  scalar  keys  % { $ opt - > { collections } }  )  )  ||  $ opt - > { collections } - > { $ collection } ; 
 
			
		
	
		
			
				
					    if ( $ r ) { 
 
			
		
	
		
			
				
					        #by default we run requested collection scripts even when exists 
 
			
		
	
		
			
				
					        if ( ! $ opt - > { collections } - > { $ collection } ) { 
 
			
		
	
		
			
				
					            if ( testscript_exists ( $ collection )  &&  ! $ opt - > { ignore_existence } ) { 
 
			
		
	
		
			
				
					    my  ( $ collection , $ method )  =  @ _ ; 
 
			
		
	
		
			
				
					    $ method  // =  '' ; 
 
			
		
	
		
			
				
					    #check if collection is among directly requested. If no particular collections were requested, then all are requested 
 
			
		
	
		
			
				
					    my  $ run_collection_test  =  ( !  (  scalar  keys  % { $ opt - > { collections } }  )  )  ||  $ opt - > { collections } - > { $ collection } ; 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					    if ( $ run_collection_test ) { 
 
			
		
	
		
			
				
					        #we run requested collection scripts even when exists or is excluded. So Now check for not requested 
 
			
		
	
		
			
				
					        if ( !  $ opt - > { collections } - > { $ collection } ) { 
 
			
		
	
		
			
				
					            if (  $ config - > { tests_exclude } - > { $ collection }  ) { 
 
			
		
	
		
			
				
					                if ( $ method  &&  $ method  ne  'all' ) { 
 
			
		
	
		
			
				
					                    if  ( ( 
 
			
		
	
		
			
				
					                            'HASH'  eq  ref  $ config - > { tests_exclude } - > { $ collection } 
 
			
		
	
		
			
				
					                            &&  $ config - > { tests_exclude } - > { $ collection } - > { $ method } 
 
			
		
	
		
			
				
					                        ) 
 
			
		
	
		
			
				
					                        || 
 
			
		
	
		
			
				
					                        ( 
 
			
		
	
		
			
				
					                            'ARRAY'  eq  ref  $ config - > { tests_exclude } - > { $ collection } 
 
			
		
	
		
			
				
					                            &&  grep  {  $ method  eq  $ _ }  @ { $ config - > { tests_exclude } - > { $ collection } } 
 
			
		
	
		
			
				
					                    ) ) { 
 
			
		
	
		
			
				
					                        #method excluded 
 
			
		
	
		
			
				
					                        $ run_collection_test  =  0 ; 
 
			
		
	
		
			
				
					                    }  else  { 
 
			
		
	
		
			
				
					                        $ run_collection_test  =  1 ;                     
 
			
		
	
		
			
				
					                    } 
 
			
		
	
		
			
				
					                }  elsif  ( !  ref  $ config - > { tests_exclude } - > { $ collection } )  { 
 
			
		
	
		
			
				
					                    $ run_collection_test  =  0  ; 
 
			
		
	
		
			
				
					                }  else  { 
 
			
		
	
		
			
				
					                    $ run_collection_test  =  1 ; 
 
			
		
	
		
			
				
					                } 
 
			
		
	
		
			
				
					            } elsif ( testscript_exists ( $ collection )  &&  ! $ opt - > { ignore_existence } ) { 
 
			
		
	
		
			
				
					                push  @ { $ report - > { 'tests_exists_skipped' } } ,  $ collection ; 
 
			
		
	
		
			
				
					                #we will not test the same twice 
 
			
		
	
		
			
				
					                $ r  =  0 ; 
 
			
		
	
		
			
				
					                $ r un_collection_test  =  0 ; 
 
			
		
	
		
			
				
					            } 
 
			
		
	
		
			
				
					            $ r  =  0  if  $ config - > { test_exclude } - > { $ collection } ; 
 
			
		
	
		
			
				
					        } 
 
			
		
	
		
			
				
					    } 
 
			
		
	
		
			
				
					    return  $ r ; 
 
			
		
	
		
			
				
					    return  $ r un_collection_test ; 
 
			
		
	
		
			
				
					}  
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					sub  init_report {