/*   Delete test data of samples of type CONTROL LAYOUT;
*/
delete from samples where code = 'CTLP_CODE' and saty_id = (select id from sample_types where code = 'CONTROL LAYOUT');

/*   Delete test data of samples of type CELL PLATE;
*/
delete from samples where code = 'CP_CODE' and saty_id = (select id from sample_types where code = 'CELL PLATE');

/*   Insert a sample of type CONTROL LAYOUT;
*/
insert into samples (id, code, saty_id, pers_id_registerer ) 
values (nextval('sample_id_seq'), 'CTLP_CODE', (select id from sample_types where code = 'CONTROL LAYOUT'), 1);

/*  There is now a sample of type CONTROL LAYOUT. 
    So, now attempt to insert a Sample of type CELL PLATE.
    The trigger should allow an insert and raise no exception.

Input Parameters of function br001_crtl_plate_chk_test are:
	p_sample_id          tech_id 
	p_sample_code        code 
	p_saty_id            tech_id 
	p_pers_id_registerer tech_id
	p_expect_failure     boolean
*/
select br001_crtl_plate_chk_test(
	      nextval('SAMPLE_ID_SEQ')
             ,'CP_CODE'
             ,(select id from sample_types where code = 'CELL PLATE') 
             ,1
             ,FALSE)
as test_result 
from samples where id = (select max(id) from samples);
