Merge pull request #5191 from solgenomics/topic/quality_control
[sgn.git] / t / unit_mech / AJAX / _BrAPIv2_phenotyping.t
bloba32e61a00f2e4260b8ad879601ccf146800573bf
2 use strict;
3 use warnings;
6 use lib 't/lib';
7 use SGN::Test::Fixture;
8 use Test::More;
9 use Test::WWW::Mechanize;
10 use LWP::UserAgent;
11 use DateTime;
13 #Needed to update IO::Socket::SSL
14 use Data::Dumper;
15 use JSON;
16 local $Data::Dumper::Indent = 1;
18 my $f = SGN::Test::Fixture->new(); # calculate db stats
20 my $mech = Test::WWW::Mechanize->new;
21 my $ua   = LWP::UserAgent->new;
22 my $response; my $searchId; my $resp; my $data;
24 $mech->post_ok('http://localhost:3010/brapi/v2/token', [ "username"=> "janedoe", "password"=> "secretpw", "grant_type"=> "password" ]);
25 $response = decode_json $mech->content;
26 #print STDERR "\n\n" . Dumper$response;
28 is($response->{'metadata'}->{'status'}->[2]->{'message'}, 'Login Successfull');
30 is($response->{'userDisplayName'}, 'Jane Doe');
32 is($response->{'expires_in'}, '7200');
34 $mech->delete_ok('http://localhost:3010/brapi/v2/token');
35 $response = decode_json $mech->content;
36 #print STDERR "\n\n" . Dumper$response;
38 is($response->{'metadata'}->{'status'}->[2]->{'message'}, 'User Logged Out');
40 $mech->post_ok('http://localhost:3010/brapi/v2/token', [ "username"=> "janedoe", "password"=> "secretpw", "grant_type"=> "password" ]);
41 $response = decode_json $mech->content;
42 #print STDERR "\n\n" . Dumper$response;
44 is($response->{'metadata'}->{'status'}->[2]->{'message'}, 'Login Successfull');
46 is($response->{'userDisplayName'}, 'Jane Doe');
48 is($response->{'expires_in'}, '7200');
49 my $access_token = $response->{access_token};
51 $ua->default_header("Content-Type" => "application/json");
52 $ua->default_header('Authorization'=> 'Bearer ' . $access_token);
53 $mech->default_header("Content-Type" => "application/json");
54 $mech->default_header('Authorization'=> 'Bearer ' . $access_token);
57 # Phenotyping
59 $mech->get_ok('http://localhost:3010/brapi/v2/observationlevels');
60 $response = decode_json $mech->content;
61 #print STDERR "\n\n" . Dumper$response;
63 is_deeply($response, {'result' => {'data' => [{'levelName' => 'rep','levelOrder' => 0},{'levelName' => 'block','levelOrder' => 1},{'levelName' => 'plot','levelOrder' => 2},{'levelName' => 'subplot','levelOrder' => 3},{'levelName' => 'plant','levelOrder' => 4},{'levelName' => 'tissue_sample','levelOrder' => 5}]},'metadata' => {'pagination' => {'totalPages' => 1,'pageSize' => 6,'totalCount' => 6,'currentPage' => 0},'datafiles' => [],'status' => [{'message' => 'BrAPI base call found with page=0, pageSize=10','messageType' => 'INFO'},{'messageType' => 'INFO','message' => 'Loading CXGN::BrAPI::v2::ObservationVariables'},{'messageType' => 'INFO','message' => 'Observation Levels result constructed'}]}}, "observation levels test");
65 ####### ObservationUnits
66 $mech->get_ok('http://localhost:3010/brapi/v2/observationunits');
67 $response = decode_json $mech->content;
68 #print STDERR "\n\n" . Dumper$response;
69 #10
70 is_deeply($response,{'metadata'=>{'pagination'=>{'pageSize'=>10,'totalCount'=>1954,'totalPages'=>196,'currentPage'=>0},'status'=>[{'messageType'=>'INFO','message'=>'BrAPI base call found with page=0, pageSize=10'},{'message'=>'Loading CXGN::BrAPI::v2::ObservationUnits','messageType'=>'INFO'},{'message'=>'Observation Units search result constructed','messageType'=>'INFO'}],'datafiles'=>[]},'result'=>{'data'=>[{'studyName'=>'CASS_6Genotypes_Sampling_2015','studyDbId'=>'165','programName'=>'test','locationDbId'=>'23','treatments'=>[{'factor'=>'No ManagementFactor','modality'=>undef}],'germplasmName'=>'IITA-TMS-IBA980581','plotImageDbIds'=>[],'seedLotName'=>undef,'germplasmDbId'=>'41283','crossDbId'=>undef,'crossName'=>undef,'observationUnitPosition'=>{'entryType'=>'test','positionCoordinateYType'=>'GRID_ROW','positionCoordinateY'=>undef,'observationLevelRelationships'=>[{'levelCode'=>'1','levelName'=>'rep','levelOrder'=>0},{'levelOrder'=>1,'levelCode'=>'1','levelName'=>'block'},{'levelName'=>'plot','levelCode'=>'103','levelOrder'=>2}],'positionCoordinateX'=>undef,'observationLevel'=>{'levelOrder'=>2,'levelCode'=>'103','levelName'=>'plot'},'geoCoordinates'=>undef,'positionCoordinateXType'=>'GRID_COL'},'locationName'=>'test_location','observations'=>[],'programDbId'=>'134','observationUnitDbId'=>'41284','observationUnitPUI'=>'http://localhost:3010/stock/41284/view','additionalInfo'=>undef,'seedLotDbId'=>undef,'externalReferences'=>[],'observationUnitName'=>'CASS_6Genotypes_103','trialName'=>'CASS_6Genotypes_Sampling_2015','trialDbId'=>'165'},{'locationDbId'=>'23','treatments'=>[{'factor'=>'No ManagementFactor','modality'=>undef}],'programName'=>'test','studyDbId'=>'165','studyName'=>'CASS_6Genotypes_Sampling_2015','plotImageDbIds'=>[],'seedLotName'=>undef,'germplasmName'=>'IITA-TMS-IBA980002','observations'=>[],'programDbId'=>'134','locationName'=>'test_location','observationUnitPosition'=>{'positionCoordinateX'=>undef,'observationLevelRelationships'=>[{'levelOrder'=>0,'levelName'=>'rep','levelCode'=>'1'},{'levelCode'=>'1','levelName'=>'block','levelOrder'=>1},{'levelOrder'=>2,'levelName'=>'plot','levelCode'=>'104'}],'positionCoordinateXType'=>'GRID_COL','geoCoordinates'=>undef,'observationLevel'=>{'levelCode'=>'104','levelName'=>'plot','levelOrder'=>2},'positionCoordinateYType'=>'GRID_ROW','entryType'=>'test','positionCoordinateY'=>undef},'germplasmDbId'=>'41282','crossDbId'=>undef,'crossName'=>undef,'trialDbId'=>'165','trialName'=>'CASS_6Genotypes_Sampling_2015','seedLotDbId'=>undef,'externalReferences'=>[],'observationUnitName'=>'CASS_6Genotypes_104','additionalInfo'=>undef,'observationUnitPUI'=>'http://localhost:3010/stock/41295/view','observationUnitDbId'=>'41295'},{'seedLotName'=>undef,'plotImageDbIds'=>[],'germplasmName'=>'IITA-TMS-IBA30572','treatments'=>[{'factor'=>'No ManagementFactor','modality'=>undef}],'locationDbId'=>'23','programName'=>'test','studyDbId'=>'165','studyName'=>'CASS_6Genotypes_Sampling_2015','trialDbId'=>'165','trialName'=>'CASS_6Genotypes_Sampling_2015','observationUnitName'=>'CASS_6Genotypes_105','externalReferences'=>[],'seedLotDbId'=>undef,'additionalInfo'=>undef,'observationUnitPUI'=>'http://localhost:3010/stock/41296/view','observationUnitDbId'=>'41296','programDbId'=>'134','observations'=>[],'locationName'=>'test_location','observationUnitPosition'=>{'geoCoordinates'=>undef,'positionCoordinateXType'=>'GRID_COL','observationLevel'=>{'levelCode'=>'105','levelName'=>'plot','levelOrder'=>2},'positionCoordinateX'=>undef,'observationLevelRelationships'=>[{'levelName'=>'rep','levelCode'=>'1','levelOrder'=>0},{'levelOrder'=>1,'levelName'=>'block','levelCode'=>'1'},{'levelCode'=>'105','levelName'=>'plot','levelOrder'=>2}],'positionCoordinateY'=>undef,'positionCoordinateYType'=>'GRID_ROW','entryType'=>'test'},'germplasmDbId'=>'41279','crossDbId'=>undef,'crossName'=>undef},{'seedLotName'=>undef,'plotImageDbIds'=>[],'germplasmName'=>'IITA-TMS-IBA011412','studyDbId'=>'165','studyName'=>'CASS_6Genotypes_Sampling_2015','treatments'=>[{'modality'=>undef,'factor'=>'No ManagementFactor'}],'locationDbId'=>'23','programName'=>'test','additionalInfo'=>undef,'observationUnitPUI'=>'http://localhost:3010/stock/41297/view','observationUnitDbId'=>'41297','trialDbId'=>'165','trialName'=>'CASS_6Genotypes_Sampling_2015','observationUnitName'=>'CASS_6Genotypes_106','externalReferences'=>[],'seedLotDbId'=>undef,'observationUnitPosition'=>{'positionCoordinateY'=>undef,'entryType'=>'test','positionCoordinateYType'=>'GRID_ROW','observationLevel'=>{'levelOrder'=>2,'levelName'=>'plot','levelCode'=>'106'},'geoCoordinates'=>undef,'positionCoordinateXType'=>'GRID_COL','positionCoordinateX'=>undef,'observationLevelRelationships'=>[{'levelOrder'=>0,'levelName'=>'rep','levelCode'=>'1'},{'levelOrder'=>1,'levelName'=>'block','levelCode'=>'1'},{'levelName'=>'plot','levelCode'=>'106','levelOrder'=>2}]},'germplasmDbId'=>'41281','crossDbId'=>undef,'crossName'=>undef,'programDbId'=>'134','observations'=>[],'locationName'=>'test_location'},{'plotImageDbIds'=>[],'seedLotName'=>undef,'germplasmName'=>'TMEB693','studyName'=>'CASS_6Genotypes_Sampling_2015','studyDbId'=>'165','locationDbId'=>'23','treatments'=>[{'factor'=>'No ManagementFactor','modality'=>undef}],'programName'=>'test','additionalInfo'=>undef,'observationUnitDbId'=>'41298','observationUnitPUI'=>'http://localhost:3010/stock/41298/view','trialName'=>'CASS_6Genotypes_Sampling_2015','trialDbId'=>'165','seedLotDbId'=>undef,'observationUnitName'=>'CASS_6Genotypes_107','externalReferences'=>[],'observationUnitPosition'=>{'positionCoordinateXType'=>'GRID_COL','geoCoordinates'=>undef,'observationLevel'=>{'levelCode'=>'107','levelName'=>'plot','levelOrder'=>2},'positionCoordinateX'=>undef,'observationLevelRelationships'=>[{'levelName'=>'rep','levelCode'=>'1','levelOrder'=>0},{'levelOrder'=>1,'levelCode'=>'1','levelName'=>'block'},{'levelCode'=>'107','levelName'=>'plot','levelOrder'=>2}],'positionCoordinateY'=>undef,'positionCoordinateYType'=>'GRID_ROW','entryType'=>'test'},'germplasmDbId'=>'41280','crossDbId'=>undef,'crossName'=>undef,'observations'=>[],'programDbId'=>'134','locationName'=>'test_location'},{'observationUnitPosition'=>{'positionCoordinateX'=>undef,'observationLevelRelationships'=>[{'levelOrder'=>0,'levelCode'=>'1','levelName'=>'rep'},{'levelCode'=>'2','levelName'=>'block','levelOrder'=>1},{'levelName'=>'plot','levelCode'=>'201','levelOrder'=>2}],'observationLevel'=>{'levelOrder'=>2,'levelName'=>'plot','levelCode'=>'201'},'geoCoordinates'=>undef,'positionCoordinateXType'=>'GRID_COL','entryType'=>'test','positionCoordinateYType'=>'GRID_ROW','positionCoordinateY'=>undef},'germplasmDbId'=>'40326','crossDbId'=>undef,'crossName'=>undef,'observations'=>[],'programDbId'=>'134','locationName'=>'test_location','additionalInfo'=>undef,'observationUnitDbId'=>'41299','observationUnitPUI'=>'http://localhost:3010/stock/41299/view','trialDbId'=>'165','trialName'=>'CASS_6Genotypes_Sampling_2015','externalReferences'=>[],'observationUnitName'=>'CASS_6Genotypes_201','seedLotDbId'=>undef,'studyDbId'=>'165','studyName'=>'CASS_6Genotypes_Sampling_2015','treatments'=>[{'factor'=>'No ManagementFactor','modality'=>undef}],'locationDbId'=>'23','programName'=>'test','seedLotName'=>undef,'plotImageDbIds'=>[],'germplasmName'=>'BLANK'},{'programName'=>'test','treatments'=>[{'modality'=>undef,'factor'=>'No ManagementFactor'}],'locationDbId'=>'23','studyDbId'=>'165','studyName'=>'CASS_6Genotypes_Sampling_2015','germplasmName'=>'TMEB693','seedLotName'=>undef,'plotImageDbIds'=>[],'locationName'=>'test_location','observations'=>[],'programDbId'=>'134','germplasmDbId'=>'41280','crossDbId'=>undef,'crossName'=>undef,'observationUnitPosition'=>{'positionCoordinateY'=>undef,'entryType'=>'test','positionCoordinateYType'=>'GRID_ROW','observationLevel'=>{'levelOrder'=>2,'levelName'=>'plot','levelCode'=>'202'},'geoCoordinates'=>undef,'positionCoordinateXType'=>'GRID_COL','positionCoordinateX'=>undef,'observationLevelRelationships'=>[{'levelOrder'=>0,'levelCode'=>'1','levelName'=>'rep'},{'levelOrder'=>1,'levelCode'=>'2','levelName'=>'block'},{'levelOrder'=>2,'levelCode'=>'202','levelName'=>'plot'}]},'externalReferences'=>[],'observationUnitName'=>'CASS_6Genotypes_202','seedLotDbId'=>undef,'trialName'=>'CASS_6Genotypes_Sampling_2015','trialDbId'=>'165','observationUnitPUI'=>'http://localhost:3010/stock/41300/view','observationUnitDbId'=>'41300','additionalInfo'=>undef},{'germplasmName'=>'IITA-TMS-IBA980002','seedLotName'=>undef,'plotImageDbIds'=>[],'studyDbId'=>'165','studyName'=>'CASS_6Genotypes_Sampling_2015','programName'=>'test','treatments'=>[{'modality'=>undef,'factor'=>'No ManagementFactor'}],'locationDbId'=>'23','observationUnitDbId'=>'41301','observationUnitPUI'=>'http://localhost:3010/stock/41301/view','additionalInfo'=>undef,'externalReferences'=>[],'observationUnitName'=>'CASS_6Genotypes_203','seedLotDbId'=>undef,'trialName'=>'CASS_6Genotypes_Sampling_2015','trialDbId'=>'165','germplasmDbId'=>'41282','crossDbId'=>undef,'crossName'=>undef,'observationUnitPosition'=>{'positionCoordinateY'=>undef,'positionCoordinateYType'=>'GRID_ROW','entryType'=>'test','positionCoordinateXType'=>'GRID_COL','geoCoordinates'=>undef,'observationLevel'=>{'levelCode'=>'203','levelName'=>'plot','levelOrder'=>2},'positionCoordinateX'=>undef,'observationLevelRelationships'=>[{'levelOrder'=>0,'levelCode'=>'1','levelName'=>'rep'},{'levelCode'=>'2','levelName'=>'block','levelOrder'=>1},{'levelName'=>'plot','levelCode'=>'203','levelOrder'=>2}]},'locationName'=>'test_location','observations'=>[],'programDbId'=>'134'},{'observationUnitPUI'=>'http://localhost:3010/stock/41302/view','observationUnitDbId'=>'41302','additionalInfo'=>undef,'seedLotDbId'=>undef,'observationUnitName'=>'CASS_6Genotypes_204','externalReferences'=>[],'trialName'=>'CASS_6Genotypes_Sampling_2015','trialDbId'=>'165','germplasmDbId'=>'41283','crossDbId'=>undef,'crossName'=>undef,'observationUnitPosition'=>{'positionCoordinateXType'=>'GRID_COL','geoCoordinates'=>undef,'observationLevel'=>{'levelName'=>'plot','levelCode'=>'204','levelOrder'=>2},'positionCoordinateX'=>undef,'observationLevelRelationships'=>[{'levelOrder'=>0,'levelName'=>'rep','levelCode'=>'1'},{'levelOrder'=>1,'levelName'=>'block','levelCode'=>'2'},{'levelCode'=>'204','levelName'=>'plot','levelOrder'=>2}],'positionCoordinateY'=>undef,'positionCoordinateYType'=>'GRID_ROW','entryType'=>'test'},'locationName'=>'test_location','observations'=>[],'programDbId'=>'134','germplasmName'=>'IITA-TMS-IBA980581','plotImageDbIds'=>[],'seedLotName'=>undef,'studyName'=>'CASS_6Genotypes_Sampling_2015','studyDbId'=>'165','programName'=>'test','locationDbId'=>'23','treatments'=>[{'factor'=>'No ManagementFactor','modality'=>undef}]},{'seedLotName'=>undef,'plotImageDbIds'=>[],'germplasmName'=>'IITA-TMS-IBA011412','treatments'=>[{'factor'=>'No ManagementFactor','modality'=>undef}],'locationDbId'=>'23','programName'=>'test','studyDbId'=>'165','studyName'=>'CASS_6Genotypes_Sampling_2015','trialName'=>'CASS_6Genotypes_Sampling_2015','trialDbId'=>'165','externalReferences'=>[],'observationUnitName'=>'CASS_6Genotypes_205','seedLotDbId'=>undef,'additionalInfo'=>undef,'observationUnitPUI'=>'http://localhost:3010/stock/41285/view','observationUnitDbId'=>'41285','observations'=>[],'programDbId'=>'134','locationName'=>'test_location','observationUnitPosition'=>{'positionCoordinateY'=>undef,'entryType'=>'test','positionCoordinateYType'=>'GRID_ROW','observationLevel'=>{'levelOrder'=>2,'levelName'=>'plot','levelCode'=>'205'},'geoCoordinates'=>undef,'positionCoordinateXType'=>'GRID_COL','positionCoordinateX'=>undef,'observationLevelRelationships'=>[{'levelCode'=>'1','levelName'=>'rep','levelOrder'=>0},{'levelOrder'=>1,'levelCode'=>'2','levelName'=>'block'},{'levelOrder'=>2,'levelCode'=>'205','levelName'=>'plot'}]},'germplasmDbId'=>'41281','crossDbId'=>undef,'crossName'=>undef}]}}, "GET observationunits test");
73 #it doesn't test geoCoordinates
74 $data = '[{ "additionalInfo": {"control": 1,"field" : "Field2" },"germplasmDbId": "41281","germplasmName": "IITA-TMS-IBA011412","locationDbId": "23","locationName": "test_location","observationUnitName": "Testing Plot","observationUnitPUI": "10","programDbId": "134","programName": "test","seedLotDbId": "","studyDbId": "165","studyName": "CASS_6Genotypes_Sampling_2015","treatments": [],"trialDbId": "165","trialName": "","observationUnitPosition": {"entryType": "TEST","geoCoordinates": {},"observationLevel": {"levelName": "plot","levelOrder": 2,"levelCode": "10"},"observationLevelRelationships": [{  "levelCode": "Field_1",  "levelName": "field",  "levelOrder": 0},{  "levelCode": "Block_12",  "levelName": "block",  "levelOrder": 1},{  "levelCode": "Plot_123",  "levelName": "plot",  "levelOrder": 2}],"positionCoordinateX": "74","positionCoordinateXType": "GRID_COL","positionCoordinateY": "03","positionCoordinateYType": "GRID_ROW"} }]';
75 $mech->post('http://localhost:3010/brapi/v2/observationunits/', Content => $data);
76 $response = decode_json $mech->content;
77 #print STDERR "\n\n" . Dumper$response;
79 my $rs = $f->bcs_schema()->resultset('Stock::Stock')->search( undef, { columns => [ { stock_id => { max => "stock_id" }} ]} );
80 my $row = $rs->next();
81 my $stock_id = $row->stock_id();
83 #11
84 is_deeply($response, {'result' => {'data' => [{'observationUnitDbId' => $stock_id,'observationUnitPUI' => 'http://localhost:3010/stock/'.$stock_id.'/view','externalReferences' => [],'additionalInfo' => {'field' => 'Field2'},'observationUnitPosition' => {'geoCoordinates' => undef,'observationLevel' => {'levelCode' => '10','levelOrder' => 2,'levelName' => 'plot'},'positionCoordinateY' => 3,'entryType' => 'test','positionCoordinateXType' => 'GRID_COL','positionCoordinateYType' => 'GRID_ROW','observationLevelRelationships' => [{'levelName' => 'rep','levelOrder' => 0,'levelCode' => '1'}, {'levelCode' => 'Block_12','levelName' => 'block','levelOrder' => 1},{'levelCode' => '10','levelOrder' => 2,'levelName' => 'plot'}],'positionCoordinateX' => 74},'studyName' => 'CASS_6Genotypes_Sampling_2015','trialDbId' => '165','programDbId' => '134','plotImageDbIds' => [],'locationName' => 'test_location','studyDbId' => '165','locationDbId' => '23','observationUnitName' => 'Testing Plot','germplasmName' => 'IITA-TMS-IBA011412','seedLotDbId' => undef,'seedLotName' => undef,'programName' => 'test','treatments' => [{'factor' => 'No ManagementFactor','modality' => undef}],'trialName' => 'CASS_6Genotypes_Sampling_2015','germplasmDbId' => '41281','crossDbId'=>undef,'crossName'=>undef,'observations' => [] }]},'metadata' => {'pagination' => {'totalCount' => 1,'totalPages' => 1,'pageSize' => 1,'currentPage' => 0},'datafiles' => [],'status' => [{'messageType' => 'INFO','message' => 'BrAPI base call found with page=0, pageSize=10'},{'message' => 'Loading CXGN::BrAPI::v2::ObservationUnits','messageType' => 'INFO'},{'message' => 'Observation Units search result constructed','messageType' => 'INFO'}]}} ,"POST observationunits test");
87 $mech->get_ok('http://localhost:3010/brapi/v2/observationunits/41284');
88 $response = decode_json $mech->content;
89 #print STDERR "\n\n" . Dumper$response;
90 #12
91 is_deeply($response, {'metadata' => {'status' => [{'messageType' => 'INFO','message' => 'BrAPI base call found with page=0, pageSize=10'},{'messageType' => 'INFO','message' => 'Loading CXGN::BrAPI::v2::ObservationUnits'},{'messageType' => 'INFO','message' => 'Observation Units search result constructed'}],'pagination' => {'pageSize' => 10,'currentPage' => 0,'totalPages' => 1,'totalCount' => 1},'datafiles' => []},'result' => {'observationUnitDbId' => '41284','observationUnitPUI' => 'http://localhost:3010/stock/41284/view', 'additionalInfo' => undef,'externalReferences' => [],'studyName' => 'CASS_6Genotypes_Sampling_2015','observationUnitPosition' => {'observationLevelRelationships' => [{'levelCode' => '1','levelName' => 'rep','levelOrder' => 0}, {'levelCode' => '1','levelName' => 'block','levelOrder' => 1},{'levelCode' => '103','levelName' => 'plot','levelOrder' => 2}],'positionCoordinateX' => undef,'positionCoordinateYType' => 'GRID_ROW','positionCoordinateXType' => 'GRID_COL','entryType' => 'test','observationLevel' => {'levelName' => 'plot','levelOrder' => 2,'levelCode' => '103'},'positionCoordinateY' => undef,'geoCoordinates' => undef},'trialDbId' => '165','programDbId' => '134','plotImageDbIds' => [],'studyDbId' => '165','locationName' => 'test_location','observationUnitName' => 'CASS_6Genotypes_103','seedLotDbId' => undef,'seedLotName' => undef,'germplasmName' => 'IITA-TMS-IBA980581','locationDbId' => '23','programName' => 'test','treatments' => [{'modality' => undef,'factor' => 'No ManagementFactor'}],'trialName' => 'CASS_6Genotypes_Sampling_2015','observations' => [{'studyDbId' => '165','observationTimeStamp' => undef,'observationUnitDbId' => '41284','collector' => undef,'observationVariableDbId' => '77559','observationDbId' => '740336','externalReferences' => undef,'additionalInfo' =>undef,'observationUnitName' => 'CASS_6Genotypes_103','germplasmName' => 'IITA-TMS-IBA980581','uploadedBy' => undef,'value' => '601.518','season' => {'seasonDbId' => undef,'season' => undef,'year' => '2017'},'germplasmDbId' => '41283','observationVariableName' => 'cass sink leaf|3-phosphoglyceric acid|ug/g|week 16|COMP:0000013'},{'germplasmName' => 'IITA-TMS-IBA980581','observationUnitName' => 'CASS_6Genotypes_103','uploadedBy' => undef,'observationVariableDbId' => '77557','externalReferences' => undef,'observationDbId' => '740337','additionalInfo' =>undef,'collector' => undef,'observationTimeStamp' => undef,'observationUnitDbId' => '41284','studyDbId' => '165','observationVariableName' => 'cass sink leaf|ADP alpha-D-glucoside|ug/g|week 16|COMP:0000011','germplasmDbId' => '41283','season' => {'year' => '2017','seasonDbId' => undef,'season' => undef},'value' => '39.84365'},{'observationVariableName' => 'cass sink leaf|ADP|ug/g|week 16|COMP:0000010','germplasmDbId' => '41283','season' => {'year' => '2017','season' => undef,'seasonDbId' => undef},'value' => '655.92','uploadedBy' => undef,'germplasmName' => 'IITA-TMS-IBA980581','observationUnitName' => 'CASS_6Genotypes_103','externalReferences' => undef,'additionalInfo' => undef,'observationDbId' => '740338','observationVariableDbId' => '77556','collector' => undef,'studyDbId' => '165','observationTimeStamp' => undef,'observationUnitDbId' => '41284'},{'value' => '1259.08','season' => {'season' => undef,'seasonDbId' => undef,'year' => '2017'},'germplasmDbId' => '41283','observationVariableName' => 'cass source leaf|3-phosphoglyceric acid|ug/g|week 16|COMP:0000002','observationUnitDbId' => '41284','studyDbId' => '165','observationTimeStamp' => undef,'collector' => undef,'externalReferences' => undef,'observationDbId' => '740339','additionalInfo' => undef,'observationVariableDbId' => '77548','uploadedBy' => undef,'germplasmName' => 'IITA-TMS-IBA980581','observationUnitName' => 'CASS_6Genotypes_103'},{'value' => '17.38275','season' => {'year' => '2017','seasonDbId' => undef,'season' => undef},'germplasmDbId' => '41283','observationVariableName' => 'cass source leaf|ADP alpha-D-glucoside|ug/g|week 16|COMP:0000007','studyDbId' => '165','observationTimeStamp' => undef,'observationUnitDbId' => '41284','collector' => undef,'observationDbId' => '740340','additionalInfo' => undef,'externalReferences' => undef,'observationVariableDbId' => '77553','uploadedBy' => undef,'germplasmName' => 'IITA-TMS-IBA980581','observationUnitName' => 'CASS_6Genotypes_103'},{'collector' => undef,'observationUnitDbId' => '41284','studyDbId' => '165','observationTimeStamp' => undef,'observationUnitName' => 'CASS_6Genotypes_103','germplasmName' => 'IITA-TMS-IBA980581','uploadedBy' => undef,'observationVariableDbId' => '77549','externalReferences' => undef,'additionalInfo' => undef,'observationDbId' => '740341','season' => {'seasonDbId' => undef,'season' => undef,'year' => '2017'},'value' => '192.1495','observationVariableName' => 'cass source leaf|ADP|ug/g|week 16|COMP:0000003','germplasmDbId' => '41283'},{'germplasmDbId' => '41283','observationVariableName' => 'cass storage root|3-phosphoglyceric acid|ug/g|week 16|COMP:0000006','value' => '67.9959','season' => {'year' => '2017','season' => undef,'seasonDbId' => undef},'observationVariableDbId' => '77552','observationDbId' => '740342','externalReferences' => undef,'additionalInfo' => undef,'germplasmName' => 'IITA-TMS-IBA980581','observationUnitName' => 'CASS_6Genotypes_103','uploadedBy' => undef,'observationTimeStamp' => undef,'observationUnitDbId' => '41284','studyDbId' => '165','collector' => undef},{'observationVariableName' => 'cass storage root|ADP alpha-D-glucoside|ug/g|week 16|COMP:0000004','germplasmDbId' => '41283','season' => {'season' => undef,'seasonDbId' => undef,'year' => '2017'},'value' => '20.3038','uploadedBy' => undef,'germplasmName' => 'IITA-TMS-IBA980581','observationUnitName' => 'CASS_6Genotypes_103','additionalInfo' => undef,'observationDbId' => '740343','externalReferences' => undef,'observationVariableDbId' => '77550','collector' => undef,'observationTimeStamp' => undef,'observationUnitDbId' => '41284','studyDbId' => '165'},{'observationTimeStamp' => undef,'studyDbId' => '165','observationUnitDbId' => '41284','collector' => undef,'additionalInfo' => undef,'externalReferences' => undef,'observationDbId' => '740344','observationVariableDbId' => '77551','uploadedBy' => undef,'observationUnitName' => 'CASS_6Genotypes_103','germplasmName' => 'IITA-TMS-IBA980581','value' => '102.0875','season' => {'season' => undef,'seasonDbId' => undef,'year' => '2017'},'germplasmDbId' => '41283','observationVariableName' => 'cass storage root|ADP|ug/g|week 16|COMP:0000005'},{'germplasmName' => 'IITA-TMS-IBA980581','observationUnitName' => 'CASS_6Genotypes_103','uploadedBy' => undef,'observationVariableDbId' => '77558','additionalInfo' => undef,'externalReferences' => undef,'observationDbId' => '740345','collector' => undef,'observationUnitDbId' => '41284','observationTimeStamp' => undef,'studyDbId' => '165','observationVariableName' => 'cass upper stem|3-phosphoglyceric acid|ug/g|week 16|COMP:0000012','germplasmDbId' => '41283','season' => {'seasonDbId' => undef,'season' => undef,'year' => '2017'},'value' => '108.56995'},{'studyDbId' => '165','observationTimeStamp' => undef,'observationUnitDbId' => '41284','collector' => undef,'observationDbId' => '740346','externalReferences' => undef,'additionalInfo' => undef,'observationVariableDbId' => '77554','uploadedBy' => undef,'germplasmName' => 'IITA-TMS-IBA980581','observationUnitName' => 'CASS_6Genotypes_103','value' => '28.83915','season' => {'season' => undef,'seasonDbId' => undef,'year' => '2017'},'germplasmDbId' => '41283','observationVariableName' => 'cass upper stem|ADP alpha-D-glucoside|ug/g|week 16|COMP:0000008'},{'germplasmDbId' => '41283','observationVariableName' => 'cass upper stem|ADP|ug/g|week 16|COMP:0000009','value' => '379.16','season' => {'year' => '2017','season' => undef,'seasonDbId' => undef},'observationVariableDbId' => '77555','externalReferences' => undef,'additionalInfo' => undef,'observationDbId' => '740347','germplasmName' => 'IITA-TMS-IBA980581','observationUnitName' => 'CASS_6Genotypes_103','uploadedBy' => undef,'observationTimeStamp' => undef,'studyDbId' => '165','observationUnitDbId' => '41284','collector' => undef}],'germplasmDbId' => '41283','crossDbId'=>undef,'crossName'=>undef}} ,"GET observationunits/41284 test");
93 $mech->get_ok('http://localhost:3010/brapi/v2/observationunits/41299?pageSize=1&page=0');
94 $response = decode_json $mech->content;
95 #print STDERR "\n\n" . Dumper$response;
96 #13
97 is_deeply($response, {'result' => {'trialName' => 'CASS_6Genotypes_Sampling_2015','germplasmDbId' => '40326','crossDbId'=>undef,'crossName'=>undef,'observations' => [],'treatments' => [{'factor' => 'No ManagementFactor','modality' => undef}],'locationDbId' => '23','seedLotDbId' => undef,'seedLotName' => undef,'observationUnitName' => 'CASS_6Genotypes_201','germplasmName' => 'BLANK','programName' => 'test','locationName' => 'test_location','studyDbId' => '165','trialDbId' => '165','programDbId' => '134','plotImageDbIds' => [],'observationUnitPosition' => {'geoCoordinates' => undef,'positionCoordinateY' => undef,'observationLevel' => {'levelCode' => '201','levelOrder' => 2,'levelName' => 'plot'},'entryType' => 'test','positionCoordinateXType' => 'GRID_COL','positionCoordinateYType' => 'GRID_ROW','positionCoordinateX' => undef,'observationLevelRelationships' => [{'levelCode' => '1','levelOrder' => 0,'levelName' => 'rep'},{'levelOrder' => 1,'levelName' => 'block','levelCode' => '2'},{'levelCode' => '201','levelOrder' => 2,'levelName' => 'plot'}]},'studyName' => 'CASS_6Genotypes_Sampling_2015','externalReferences' => [],'additionalInfo' => undef,'observationUnitDbId' => '41299','observationUnitPUI' => 'http://localhost:3010/stock/41299/view'},'metadata' => {'pagination' => {'totalPages' => 1,'totalCount' => 1,'pageSize' => 1,'currentPage' => 0},'datafiles' => [],'status' => [{'messageType' => 'INFO','message' => 'BrAPI base call found with page=0, pageSize=1'},{'messageType' => 'INFO','message' => 'Loading CXGN::BrAPI::v2::ObservationUnits'},{'message' => 'Observation Units search result constructed','messageType' => 'INFO'}]}}, "GET observationunits/41299 page 0 test");
99 $mech->get_ok('http://localhost:3010/brapi/v2/observationunits/table');
100 $response = decode_json $mech->content;
101 #print STDERR "\n\n observationunits/table response:" . Dumper $response;
104 my $expected = {'metadata'=>{'datafiles'=>[],'pagination'=>{'totalPages'=>102,'totalCount'=>1016,'pageSize'=>10,'currentPage'=>0},'status'=>[{'messageType'=>'INFO','message'=>'BrAPI base call found with page=0, pageSize=10'},{'message'=>'Loading CXGN::BrAPI::v2::ObservationTables','messageType'=>'INFO'},{'messageType'=>'INFO','message'=>'Observation Units table result constructed'}]},'result'=>{'headerRow'=>['studyYear','programDbId','programName','programDescription','studyDbId','studyName','studyDescription','studyDesign','plotWidth','plotLength','fieldSize','fieldTrialIsPlannedToBeGenotyped','fieldTrialIsPlannedToCross','plantingDate','harvestDate','locationDbId','locationName','germplasmDbId','germplasmName','germplasmSynonyms','observationLevel','observationUnitDbId','observationUnitName','replicate','blockNumber','plotNumber','rowNumber','colNumber','entryType','plantNumber'],'observationVariables'=>[{'observationVariableDbId'=>'77559','observationVariableName'=>'cass sink leaf|3-phosphoglyceric acid|ug/g|week 16|COMP:0000013'},{'observationVariableName'=>'cass sink leaf|ADP alpha-D-glucoside|ug/g|week 16|COMP:0000011','observationVariableDbId'=>'77557'},{'observationVariableName'=>'cass sink leaf|ADP|ug/g|week 16|COMP:0000010','observationVariableDbId'=>'77556'},{'observationVariableName'=>'cass source leaf|3-phosphoglyceric acid|ug/g|week 16|COMP:0000002','observationVariableDbId'=>'77548'},{'observationVariableName'=>'cass source leaf|ADP alpha-D-glucoside|ug/g|week 16|COMP:0000007','observationVariableDbId'=>'77553'},{'observationVariableDbId'=>'77549','observationVariableName'=>'cass source leaf|ADP|ug/g|week 16|COMP:0000003'},{'observationVariableName'=>'cass storage root|3-phosphoglyceric acid|ug/g|week 16|COMP:0000006','observationVariableDbId'=>'77552'},{'observationVariableDbId'=>'77550','observationVariableName'=>'cass storage root|ADP alpha-D-glucoside|ug/g|week 16|COMP:0000004'},{'observationVariableName'=>'cass storage root|ADP|ug/g|week 16|COMP:0000005','observationVariableDbId'=>'77551'},{'observationVariableName'=>'cass upper stem|3-phosphoglyceric acid|ug/g|week 16|COMP:0000012','observationVariableDbId'=>'77558'},{'observationVariableName'=>'cass upper stem|ADP alpha-D-glucoside|ug/g|week 16|COMP:0000008','observationVariableDbId'=>'77554'},{'observationVariableName'=>'cass upper stem|ADP|ug/g|week 16|COMP:0000009','observationVariableDbId'=>'77555'},{'observationVariableDbId'=>'70741','observationVariableName'=>'dry matter content percentage|CO_334:0000092'},{'observationVariableDbId'=>'70666','observationVariableName'=>'fresh root weight|CO_334:0000012'},{'observationVariableName'=>'fresh shoot weight measurement in kg|CO_334:0000016','observationVariableDbId'=>'70773'},{'observationVariableName'=>'harvest index variable|CO_334:0000015','observationVariableDbId'=>'70668'}],'data'=>[['2014',134,'test','test',139,'Kasese solgs trial','This trial was loaded into the fixture to test solgs.','Alpha',undef,undef,undef,undef,undef,undef,undef,'23','test_location',39086,'UG120250','','plot',39691,'KASESE_TP2013_1000','1','53','36014',undef,undef,'test',undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef],['2014',134,'test','test',139,'Kasese solgs trial','This trial was loaded into the fixture to test solgs.','Alpha',undef,undef,undef,undef,undef,undef,undef,'23','test_location',38960,'UG120092','','plot',39493,'KASESE_TP2013_1001','1','53','36015',undef,undef,'test',undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef],['2014',134,'test','test',139,'Kasese solgs trial','This trial was loaded into the fixture to test solgs.','Alpha',undef,undef,undef,undef,undef,undef,undef,'23','test_location',38981,'UG120120','','plot',39819,'KASESE_TP2013_1002','1','53','36016',undef,undef,'test',undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,'30.1','3.93','3',undef,undef],['2014',134,'test','test',139,'Kasese solgs trial','This trial was loaded into the fixture to test solgs.','Alpha',undef,undef,undef,undef,undef,undef,undef,'23','test_location',39194,'UG130076','','plot',39311,'KASESE_TP2013_1003','1','53','36017',undef,undef,'test',undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef],['2014',134,'test','test',139,'Kasese solgs trial','This trial was loaded into the fixture to test solgs.','Alpha',undef,undef,undef,undef,undef,undef,undef,'23','test_location',39174,'UG130050','','plot',39632,'KASESE_TP2013_1004','1','54','36018',undef,undef,'test',undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,'24.2','7.26','12.5',undef,undef],['2014',134,'test','test',139,'Kasese solgs trial','This trial was loaded into the fixture to test solgs.','Alpha',undef,undef,undef,undef,undef,undef,undef,'23','test_location',38919,'UG120043','','plot',39846,'KASESE_TP2013_1005','1','54','36019',undef,undef,'test',undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef],['2014',134,'test','test',139,'Kasese solgs trial','This trial was loaded into the fixture to test solgs.','Alpha',undef,undef,undef,undef,undef,undef,undef,'23','test_location',38952,'UG120084','','plot',39919,'KASESE_TP2013_1006','1','54','36020',undef,undef,'test',undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,'27.4','5.4','4.5',undef,undef],['2014',134,'test','test',139,'Kasese solgs trial','This trial was loaded into the fixture to test solgs.','Alpha',undef,undef,undef,undef,undef,undef,undef,'23','test_location',39049,'UG120202','','plot',39836,'KASESE_TP2013_1007','1','54','36021',undef,undef,'test',undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,'16.3','0.47','6.5',undef,undef],['2014',134,'test','test',139,'Kasese solgs trial','This trial was loaded into the fixture to test solgs.','Alpha',undef,undef,undef,undef,undef,undef,undef,'23','test_location',39105,'UG120273','','plot',39350,'KASESE_TP2013_1008','1','54','36022',undef,undef,'test',undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef],['2014',134,'test','test',139,'Kasese solgs trial','This trial was loaded into the fixture to test solgs.','Alpha',undef,undef,undef,undef,undef,undef,undef,'23','test_location',38966,'UG120099','','plot',39322,'KASESE_TP2013_1009','1','54','36023',undef,undef,'test',undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef]]}};
106 #print STDERR "\n\nobservation_unit/table expected: ".Dumper($expected);
108 is_deeply($response, $expected , "GET observationunits table test");
110 ####### Observations
112 $mech->get_ok('http://localhost:3010/brapi/v2/observations?pageSize=2');
113 $response = decode_json $mech->content;
115 #print STDERR "\n\nOBSERVATIONS RESPONSE: " . Dumper $response;
119 my $expected = { 'metadata' => { 'status' => [ { 'message' => 'BrAPI base call found with page=0, pageSize=2', 'messageType' => 'INFO' }, { 'message' => 'Loading CXGN::BrAPI::v2::Observations', 'messageType' => 'INFO' }, { 'message' => 'Observations result constructed', 'messageType' => 'INFO' } ], 'pagination' => { 'totalCount' => 2781, 'pageSize' => 2, 'totalPages' => 1391, 'currentPage' => 0 }, 'datafiles' => [] }, 'result' => { 'data' => [ { 'observationVariableDbId' => '70773', 'collector' => undef, 'studyDbId' => '139', 'germplasmDbId' => '38981', 'observationUnitDbId' => '39819', 'observationVariableName' => 'fresh shoot weight measurement in kg|CO_334:0000016', 'value' => '3', 'observationTimeStamp' => undef, 'additionalInfo' => undef, 'season' => { 'seasonDbId' => '2014', 'season' => '2014', 'year' => '2014' }, 'uploadedBy' => undef, 'externalReferences' => undef, 'germplasmName' => 'UG120120', 'observationUnitName' => 'KASESE_TP2013_1002', 'observationDbId' => '737974' }, { 'season' => { 'seasonDbId' => '2014', 'season' => '2014', 'year' => '2014' }, 'additionalInfo' => undef, 'observationTimeStamp' => undef, 'value' => '30.1', 'observationVariableName' => 'dry matter content percentage|CO_334:0000092', 'observationUnitDbId' => '39819', 'germplasmDbId' => '38981', 'studyDbId' => '139', 'collector' => undef, 'observationVariableDbId' => '70741', 'observationDbId' => '737975', 'observationUnitName' => 'KASESE_TP2013_1002', 'germplasmName' => 'UG120120', 'uploadedBy' => undef, 'externalReferences' => undef } ] }};
121 #print STDERR "\n\nOBSERVATIONS EXPECTED: " . Dumper $expected;
123 is_deeply($response, $expected, "GET observations pageSize 2 test");
125 $mech->get_ok('http://localhost:3010/brapi/v2/observations/740338');
126 $response = decode_json $mech->content;
127 #print STDERR "\n\n" . Dumper$response;
129 is_deeply($response,  {'metadata' => {'datafiles' => [],'status' => [{'messageType' => 'INFO','message' => 'BrAPI base call found with page=0, pageSize=10'},{'messageType' => 'INFO','message' => 'Loading CXGN::BrAPI::v2::Observations'},{'messageType' => 'INFO','message' => 'Observations result constructed'}],'pagination' => {'totalCount' => 1,'totalPages' => 1,'currentPage' => 0,'pageSize' => 10}},'result' => {'externalReferences' => undef,'value' => '655.92','germplasmDbId' => '41283','season' => {'seasonDbId' => '2017','season' => '2017','year' => '2017'},'studyDbId' => '165','observationVariableName' => 'cass sink leaf|ADP|ug/g|week 16|COMP:0000010','observationVariableDbId' => '77556','observationUnitDbId' => '41284','germplasmName' => 'IITA-TMS-IBA980581','observationTimeStamp' => undef,'uploadedBy' => undef,'collector' => undef,'observationUnitName' => 'CASS_6Genotypes_103','observationDbId' => '740338','additionalInfo' => undef}}, "GET observations test");
131 $mech->get_ok('http://localhost:3010/brapi/v2/observations/table?pageSize=2');
132 $response = decode_json $mech->content;
133 print STDERR "\n\n" . Dumper$response;
135 is_deeply($response, {'result' => {'observationVariables' => [{'observationVariableDbId' => '77559','observationVariableName' => 'cass sink leaf|3-phosphoglyceric acid|ug/g|week 16|COMP:0000013'},{'observationVariableName' => 'cass sink leaf|ADP alpha-D-glucoside|ug/g|week 16|COMP:0000011','observationVariableDbId' => '77557'},{'observationVariableDbId' => '77556','observationVariableName' => 'cass sink leaf|ADP|ug/g|week 16|COMP:0000010'},{'observationVariableName' => 'cass source leaf|3-phosphoglyceric acid|ug/g|week 16|COMP:0000002','observationVariableDbId' => '77548'},{'observationVariableName' => 'cass source leaf|ADP alpha-D-glucoside|ug/g|week 16|COMP:0000007','observationVariableDbId' => '77553'},{'observationVariableDbId' => '77549','observationVariableName' => 'cass source leaf|ADP|ug/g|week 16|COMP:0000003'},{'observationVariableName' => 'cass storage root|3-phosphoglyceric acid|ug/g|week 16|COMP:0000006','observationVariableDbId' => '77552'},{'observationVariableDbId' => '77550','observationVariableName' => 'cass storage root|ADP alpha-D-glucoside|ug/g|week 16|COMP:0000004'},{'observationVariableDbId' => '77551','observationVariableName' => 'cass storage root|ADP|ug/g|week 16|COMP:0000005'},{'observationVariableDbId' => '77558','observationVariableName' => 'cass upper stem|3-phosphoglyceric acid|ug/g|week 16|COMP:0000012'},{'observationVariableDbId' => '77554','observationVariableName' => 'cass upper stem|ADP alpha-D-glucoside|ug/g|week 16|COMP:0000008'},{'observationVariableName' => 'cass upper stem|ADP|ug/g|week 16|COMP:0000009','observationVariableDbId' => '77555'},{'observationVariableName' => 'dry matter content percentage|CO_334:0000092','observationVariableDbId' => '70741'},{'observationVariableName' => 'fresh root weight|CO_334:0000012','observationVariableDbId' => '70666'},{'observationVariableDbId' => '70773','observationVariableName' => 'fresh shoot weight measurement in kg|CO_334:0000016'},{'observationVariableDbId' => '70668','observationVariableName' => 'harvest index variable|CO_334:0000015'}],'data' => [[ '2014', 134, 'test', 'test', 139, 'Kasese solgs trial', 'This trial was loaded into the fixture to test solgs.', 'Alpha', undef, undef, undef, undef, undef, undef, undef, '23', 'test_location', 39086, 'UG120250', '', 'plot', 39691, 'KASESE_TP2013_1000', '1', '53', '36014', undef, undef, 'test', undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef ], [ '2014', 134, 'test', 'test', 139, 'Kasese solgs trial', 'This trial was loaded into the fixture to test solgs.', 'Alpha', undef, undef, undef, undef, undef, undef, undef, '23', 'test_location', 38960, 'UG120092', '', 'plot', 39493, 'KASESE_TP2013_1001', '1', '53', '36015', undef, undef, 'test', undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef ]],'headerRow' => ['studyYear','programDbId','programName','programDescription','studyDbId','studyName','studyDescription','studyDesign','plotWidth','plotLength','fieldSize','fieldTrialIsPlannedToBeGenotyped','fieldTrialIsPlannedToCross','plantingDate','harvestDate','locationDbId','locationName','germplasmDbId','germplasmName','germplasmSynonyms','observationLevel','observationUnitDbId','observationUnitName','replicate','blockNumber','plotNumber','rowNumber','colNumber','entryType','plantNumber']},'metadata' => {'pagination' => {'currentPage' => 0,'totalPages' => 508,'totalCount' => 1016,'pageSize' => 2},'status' => [{'message' => 'BrAPI base call found with page=0, pageSize=2','messageType' => 'INFO'},{'message' => 'Loading CXGN::BrAPI::v2::ObservationTables','messageType' => 'INFO'},{'message' => 'Observations table result constructed','messageType' => 'INFO'}],'datafiles' => []}}, "GET observations table test");
137 $mech->post_ok('http://localhost:3010/brapi/v2/search/observations', ['pageSize'=>'2', 'observationDbIds' => ['740337']]);
138 $response = decode_json $mech->content;
139 $searchId = $response->{result} ->{searchResultsDbId};
140 #print STDERR "\n\n" . Dumper$response;
141 $mech->get_ok('http://localhost:3010/brapi/v2/search/observations/'. $searchId);
142 $response = decode_json $mech->content;
143 #print STDERR "\n\n" . Dumper$response;
145 is_deeply($response, {'metadata' => {'status' => [{'messageType' => 'INFO','message' => 'BrAPI base call found with page=0, pageSize=10'},{'messageType' => 'INFO','message' => 'Loading CXGN::BrAPI::v2::Results'},{'message' => 'search result constructed','messageType' => 'INFO'}],'pagination' => {'totalCount' => 1,'currentPage' => 0,'pageSize' => 10,'totalPages' => 1},'datafiles' => []},'result' => {'data' => [{'observationVariableName' => 'cass sink leaf|ADP alpha-D-glucoside|ug/g|week 16|COMP:0000011','germplasmDbId' => '41283','studyDbId' => '165','observationTimeStamp' => undef,'collector' => undef,'value' => '39.84365','observationVariableDbId' => '77557','observationDbId' => '740337','observationUnitName' => 'CASS_6Genotypes_103','externalReferences' => undef,'observationUnitDbId' => '41284','season' => {'seasonDbId' => '2017','season' => '2017','year' => '2017'},'uploadedBy' => undef,'germplasmName' => 'IITA-TMS-IBA980581','additionalInfo' => undef}]}}, "Search observations test");
148 # POST /observations
149 $data = '[ {"observationUnitDbId": 41294,  "uploadedBy": "Jane Doe", "observationTimeStamp": "2019-01-05T14:47:23Z", "observationVariableDbId":"70741", "season": "2011",   "value": "15", "externalReferences" : [{ "referenceId": "doi:10.155454/12341234", "referenceSource" : "DOI" } ], "additionalInfo" : { "year" : "2011" } } ]';
150 $mech->post('http://localhost:3010/brapi/v2/observations/', Content => $data);
151 $response = decode_json $mech->content;
153 my $column = $f->bcs_schema()->resultset('Phenotype::Phenotype')->get_column('phenotype_id');
154 my $phenotype_id = $column->max();
157 is_deeply($response,{"result"=>{"data"=>[{"value"=>"15","observationUnitName"=>"CASS_6Genotypes_307","observationVariableName"=>"dry matter content percentage","observationTimeStamp"=>"2019-01-05T14:47:23Z","collector"=>"janedoe","studyDbId"=>165,"uploadedBy"=>"janedoe","observationVariableDbId"=>"70741","observationDbId"=>$phenotype_id,"observationLevel"=>"plot","observationUnitDbId"=>41294,"germplasmName"=>"IITA-TMS-IBA980581","germplasmDbId"=>41283, "externalReferences" => [{ "referenceId"=> "doi:10.155454/12341234", "referenceSource" => "DOI" }], "additionalInfo" => { "year" => "2011" } } ]},"metadata"=>{"pagination"=>{"currentPage"=>0,"totalCount"=>1,"totalPages"=>1,"pageSize"=>10},"datafiles"=>[],"status"=>[{"message"=>"BrAPI base call found with page=0, pageSize=10","messageType"=>"INFO"},{"message"=>"Loading CXGN::BrAPI::v2::Observations","messageType"=>"INFO"},{"messageType"=>"info","message"=>"Request structure is valid"},{"message"=>"Request data is valid","messageType"=>"info"},{"messageType"=>"info","message"=>"File for incoming brapi obserations saved in archive."},{"messageType"=>"INFO","message"=>"All values in your file have been successfully processed!<br><br>1 new values stored<br>0 previously stored values skipped<br>0 previously stored values overwritten<br>0 previously stored values removed<br><br>"}]} } , "check observation storage");
160 # GET /observations/{observationDbId}
161 #21 verify
162 $mech->get_ok('http://localhost:3010/brapi/v2/observations/' . $phenotype_id);
163 $response = decode_json $mech->content;
165 is_deeply($response,{'metadata' => { 'datafiles' => [], 'status' => [ {   'message' => 'BrAPI base call found with page=0, pageSize=10',   'messageType' => 'INFO' }, {   'message' => 'Loading CXGN::BrAPI::v2::Observations',   'messageType' => 'INFO' }, {   'messageType' => 'INFO',   'message' => 'Observations result constructed' } ], 'pagination' => { 'currentPage' => 0, 'pageSize' => 10, 'totalPages' => 1, 'totalCount' => 1 } },'result' => { 'uploadedBy' => 'janedoe', 'value' => '15', 'studyDbId' => '165', 'observationUnitName' => 'CASS_6Genotypes_307', 'season' => {   'seasonDbId' => '2017',   'season' => '2017',   'year' => '2017' } , 'observationDbId' => $phenotype_id, 'observationTimeStamp' => '2019-01-05T14:47:23Z', 'germplasmDbId' => '41283', 'observationVariableDbId' => '70741', 'observationVariableName' => 'dry matter content percentage|CO_334:0000092', 'collector' => 'janedoe', 'observationUnitDbId' => '41294', 'externalReferences' => [ {   'referenceId' => 'doi:10.155454/12341234',   'referenceSource' => 'DOI' } ], 'germplasmName' => 'IITA-TMS-IBA980581', 'additionalInfo' => { 'year' => '2011' } }} ,"check stored observation");
167 # PUT /observations
168 $data = '{ "740336":  { "observationUnitDbId": "41284",  "collector": "Jane Doe", "observationTimeStamp": "2020-01-01T14:47:23-07:00", "observationVariableDbId":"77559", "season": "2011",  "value": "value 5", "observationUnitName" : "CASS_6Genotypes_103", "externalReferences" : [{ "referenceId": "doi:10.155454/5555", "referenceSource" : "DOI" } ], "additionalInfo" : { "year" : "2011" } }}';
169 #it need same variable and unit, only updates values or collector
170 $resp = $ua->put("http://localhost:3010/brapi/v2/observations/", Content => $data);
171 $response = decode_json $resp->{_content};
173 # 19 Test will be fixed when repeted and modified obsverations are allowed
174 is_deeply($response, {'metadata' => {'pagination' => {'currentPage' => 0,'totalCount' => 1,'pageSize' => 10,'totalPages' => 1},'datafiles' => [],'status' => [{'message' => 'BrAPI base call found with page=0, pageSize=10','messageType' => 'INFO'},{'message' => 'Loading CXGN::BrAPI::v2::Observations','messageType' => 'INFO'},{'messageType' => 'info','message' => 'Request structure is valid'},{'messageType' => 'info','message' => 'Request data is valid'},{'messageType' => 'info','message' => 'File for incoming brapi obserations saved in archive.'},{'messageType' => 'INFO','message' => 'All values in your file have been successfully processed!<br><br>0 new values stored<br>0 previously stored values skipped<br>1 previously stored values overwritten<br>0 previously stored values removed<br><br>'}]},'result' => {'data' => [{'germplasmName' => 'IITA-TMS-IBA980581','observationVariableName' => 'cass sink leaf|3-phosphoglyceric acid|ug/g|week 16','observationUnitName' => 'CASS_6Genotypes_103','observationTimeStamp' => '2020-01-01T14:47:23-07:00','germplasmDbId' => 41283,'collector' => 'Jane Doe','observationDbId' => 740336,'studyDbId' => 165,'observationLevel' => 'plot','observationUnitDbId' => 41284,'observationVariableDbId' => '77559','value' => 'value 5','uploadedBy' => 'Jane Doe', 'externalReferences' => [{ "referenceId" => "doi:10.155454/5555", "referenceSource" => "DOI" } ], "additionalInfo" => { "year" => "2011" }  }]}}, "PUT observations test");
176 $data = '{ "observationUnitDbId": 39548,  "collector": "John Doe", "observationTimeStamp": "2023-01-01T14:47:23-06:10", "observationVariableDbId":"70741", "season": "2011",  "value": "500", "externalReferences" : [{ "referenceId": "doi:10.155454/200" , "referenceSource" : "DOI" } ] }';
177 $resp = $ua->put("http://localhost:3010/brapi/v2/observations/737987", Content => $data);
178 $response = decode_json $resp->{_content};
179 #print STDERR "\n\n--update" . Dumper$response;
181 is_deeply($response, { 'result' => {'data' => [ { 'collector' => 'John Doe', 'observationVariableDbId' => '70741', 'germplasmName' => 'UG130133', 'additionalInfo' => undef, 'germplasmDbId' => '39243', 'observationDbId' => '737987', 'observationUnitDbId' => '39548', 'observationUnitName' => 'KASESE_TP2013_1012', 'observationVariableName' => 'dry matter content percentage', 'observationTimeStamp' => '2023-01-01T14:47:23-06:10', 'observationLevel' => 'plot', 'value' => '500', 'uploadedBy' => 'John Doe', 'externalReferences' => [     {         'referenceId' => 'doi:10.155454/200',           'referenceSource' => 'DOI'    } ], 'studyDbId' => '139' } ]}, 'metadata' => { 'status' => [ { 'messageType' => 'INFO', 'message' => 'BrAPI base call found with page=0, pageSize=10' }, { 'messageType' => 'INFO', 'message' => 'Loading CXGN::BrAPI::v2::Observations' }, { 'message' => 'Request structure is valid', 'messageType' => 'info' }, { 'messageType' => 'info', 'message' => 'Request data is valid' }, { 'messageType' => 'info', 'message' => 'File for incoming brapi obserations saved in archive.' }, { 'message' => 'All values in your file have been successfully processed!<br><br>0 new values stored<br>0 previously stored values skipped<br>1 previously stored values overwritten<br>0 previously stored values removed<br><br> The following previously uploaded files are now obsolete because all values from them were overwritten by your upload:  ', 'messageType' => 'INFO' } ], 'pagination' => { 'totalPages' => 1, 'pageSize' => 10, 'totalCount' => 1, 'currentPage' => 0 }, 'datafiles' => [] } } , "PUT observations detail test");
183 ####### Variables
184 $mech->get_ok('http://localhost:3010/brapi/v2/variables?pageSize=2');
185 $response = decode_json $mech->content;
186 #print STDERR "\n\n" . Dumper$response;
187 is_deeply($response,  {'metadata' => {'status' => [{'messageType' => 'INFO','message' => 'BrAPI base call found with page=0, pageSize=2'},{'message' => 'Loading CXGN::BrAPI::v2::ObservationVariables','messageType' => 'INFO'},{'message' => 'Observationvariable search result constructed','messageType' => 'INFO'}],'pagination' => {'totalCount' => 257,'pageSize' => 2,'totalPages' => 129,'currentPage' => 0},'datafiles' => []},'result' => {'data' => [ { 'documentationURL' => '', 'growthStage' => undef, 'institution' => undef, 'observationVariableDbId' => '70692', 'additionalInfo' => {}, 'observationVariableName' => 'abscisic acid content of leaf ug/g|CO_334:0000047', 'synonyms' => [ 'abscon', 'AbsCt_Meas_ugg' ], 'language' => 'eng', 'ontologyReference' => { 'ontologyName' => 'CO_334', 'documentationLinks' => undef, 'ontologyDbId' => '186', 'version' => undef }, 'commonCropName' => 'Cassava', 'contextOfUse' => undef, 'observationVariablePUI' => 'CO_334:0000047', 'method' => {}, 'scientist' => undef, 'trait' => { 'attribute' => undef, 'synonyms' => [ 'abscon', 'AbsCt_Meas_ugg' ], 'additionalInfo' => {}, 'alternativeAbbreviations' => undef, 'entity' => undef, 'traitDescription' => 'Abscisic acid content of leaf sample.', 'attributePUI' => undef, 'externalReferences' => [ { 'referenceId' => 'CO_334:0000047', 'referenceSource' => 'Crop Ontology' } ], 'entityPUI' => undef, 'status' => 'active', 'mainAbbreviation' => undef, 'traitPUI' => undef, 'traitClass' => undef, 'traitDbId' => '70692', 'traitName' => 'abscisic acid content of leaf ug/g', 'ontologyReference' => { 'documentationLinks' => undef, 'ontologyName' => 'CO_334', 'version' => undef, 'ontologyDbId' => '186' } }, 'defaultValue' => '', 'status' => 'active', 'externalReferences' => [ { 'referenceId' => 'CO_334:0000047', 'referenceSource' => 'Crop Ontology' } ], 'scale' => { 'dataType' => 'Text', 'decimalPlaces' => undef, 'scalePUI' => undef, 'ontologyReference' => undef, 'scaleDbId' => undef, 'scaleName' => undef, 'externalReferences' => undef, 'validValues' => { 'categories' => undef, 'maximumValue' => undef, 'minimumValue' => undef }, 'units' => undef, 'additionalInfo' => undef }, 'submissionTimestamp' => undef }, { 'defaultValue' => '', 'status' => 'active', 'scale' => { 'externalReferences' => undef, 'scaleDbId' => undef, 'scaleName' => undef, 'additionalInfo' => undef, 'units' => undef, 'validValues' => { 'categories' => undef, 'maximumValue' => undef, 'minimumValue' => undef }, 'dataType' => 'Text', 'ontologyReference' => undef, 'decimalPlaces' => undef, 'scalePUI' => undef }, 'externalReferences' => [ { 'referenceId' => 'CO_334:0000121', 'referenceSource' => 'Crop Ontology' } ], 'submissionTimestamp' => undef, 'ontologyReference' => { 'documentationLinks' => undef, 'ontologyName' => 'CO_334', 'version' => undef, 'ontologyDbId' => '186' }, 'commonCropName' => 'Cassava', 'observationVariablePUI' => 'CO_334:0000121', 'contextOfUse' => undef, 'method' => {}, 'scientist' => undef, 'trait' => { 'ontologyReference' => { 'documentationLinks' => undef, 'ontologyName' => 'CO_334', 'version' => undef, 'ontologyDbId' => '186' }, 'traitName' => 'amylopectin content ug/g in percentage', 'traitDbId' => '70761', 'traitClass' => undef, 'status' => 'active', 'traitPUI' => undef, 'mainAbbreviation' => undef, 'entityPUI' => undef, 'externalReferences' => [ { 'referenceSource' => 'Crop Ontology', 'referenceId' => 'CO_334:0000121' } ], 'entity' => undef, 'traitDescription' => 'Estimation of amylopectin content of cassava roots in percentage(%).', 'attributePUI' => undef, 'alternativeAbbreviations' => undef, 'additionalInfo' => {}, 'attribute' => undef, 'synonyms' => [ 'amylp', 'AmylPCt_Meas_pct' ] }, 'additionalInfo' => {}, 'observationVariableName' => 'amylopectin content ug/g in percentage|CO_334:0000121', 'synonyms' => [ 'amylp', 'AmylPCt_Meas_pct' ], 'language' => 'eng', 'documentationURL' => '', 'growthStage' => undef, 'institution' => undef, 'observationVariableDbId' => '70761'} ] }});
189 $mech->get_ok('http://localhost:3010/brapi/v2/variables/70752');
190 $response = decode_json $mech->content;
191 #print STDERR "\n\n" . Dumper$response;
192 is_deeply($response, {'metadata' => {'status' => [{'messageType' => 'INFO','message' => 'BrAPI base call found with page=0, pageSize=10'},{'message' => 'Loading CXGN::BrAPI::v2::ObservationVariables','messageType' => 'INFO'},{'message' => 'Observationvariable search result constructed','messageType' => 'INFO'}],'pagination' => {'totalPages' => 1,'pageSize' => 10,'currentPage' => 0,'totalCount' => 1},'datafiles' => []},'result' => { 'documentationURL' => '', 'growthStage' => undef, 'observationVariableDbId' => '70752', 'institution' => undef, 'observationVariableName' => 'amylose amylopectin root content ratio|CO_334:0000124', 'additionalInfo' => {}, 'language' => 'eng', 'synonyms' => [ 'amylrt', 'AmylR_Comp_r' ], 'commonCropName' => 'Cassava', 'observationVariablePUI' => 'CO_334:0000124', 'contextOfUse' => undef, 'ontologyReference' => { 'ontologyDbId' => '186', 'version' => undef, 'documentationLinks' => undef, 'ontologyName' => 'CO_334' }, 'trait' => { 'additionalInfo' => {}, 'synonyms' => [ 'amylrt', 'AmylR_Comp_r' ], 'attribute' => undef, 'attributePUI' => undef, 'entity' => undef, 'traitDescription' => 'The amylose content of a cassava root sample divided by the amylopectin content of the same sample.', 'alternativeAbbreviations' => undef, 'traitPUI' => undef, 'mainAbbreviation' => undef, 'status' => 'active', 'entityPUI' => undef, 'externalReferences' => [ { 'referenceSource' => 'Crop Ontology', 'referenceId' => 'CO_334:0000124' } ], 'ontologyReference' => { 'version' => undef, 'ontologyDbId' => '186', 'documentationLinks' => undef, 'ontologyName' => 'CO_334' }, 'traitName' => 'amylose amylopectin root content ratio', 'traitDbId' => '70752', 'traitClass' => undef }, 'method' => {}, 'scientist' => undef, 'status' => 'active', 'defaultValue' => '', 'submissionTimestamp' => undef, 'scale' => { 'ontologyReference' => undef, 'scalePUI' => undef, 'decimalPlaces' => undef, 'dataType' => 'Text', 'additionalInfo' => undef, 'validValues' => { 'maximumValue' => undef, 'minimumValue' => undef, 'categories' => undef }, 'units' => undef, 'externalReferences' => undef, 'scaleName' => undef, 'scaleDbId' => undef }, 'externalReferences' => [ { 'referenceSource' => 'Crop Ontology', 'referenceId' => 'CO_334:0000124' } ] }});
194 $mech->post_ok('http://localhost:3010/brapi/v2/search/variables', ['pageSize'=>'1', 'observationVariableDbIds' => ['70761']]);
195 $response = decode_json $mech->content;
196 $searchId = $response->{result} ->{searchResultsDbId};
197 #print STDERR "\n\n" . Dumper$response;
198 $mech->get_ok('http://localhost:3010/brapi/v2/search/variables/'. $searchId);
199 $response = decode_json $mech->content;
200 #print STDERR "\n\n" . Dumper$response;
201 is_deeply($response, {'result' => {'data' => [ { 'commonCropName' => 'Cassava', 'contextOfUse' => undef, 'trait' => { 'externalReferences' => [ { 'referenceId' => 'CO_334:0000121', 'referenceSource' => 'Crop Ontology' } ], 'traitClass' => undef, 'traitName' => 'amylopectin content ug/g in percentage', 'synonyms' => [ 'amylp', 'AmylPCt_Meas_pct' ], 'status' => 'active', 'additionalInfo' => {}, 'ontologyReference' => { 'documentationLinks' => undef, 'ontologyDbId' => '186', 'ontologyName' => 'CO_334', 'version' => undef }, 'traitPUI' => undef, 'traitDescription' => 'Estimation of amylopectin content of cassava roots in percentage(%).', 'entityPUI' => undef, 'attributePUI' => undef, 'attribute' => undef, 'alternativeAbbreviations' => undef, 'entity' => undef, 'mainAbbreviation' => undef, 'traitDbId' => '70761' }, 'institution' => undef, 'submissionTimestamp' => undef, 'language' => 'eng', 'scientist' => undef, 'observationVariableDbId' => '70761', 'observationVariableName' => 'amylopectin content ug/g in percentage|CO_334:0000121', 'defaultValue' => '', 'ontologyReference' => { 'ontologyDbId' => '186', 'ontologyName' => 'CO_334', 'documentationLinks' => undef, 'version' => undef }, 'documentationURL' => '', 'synonyms' => [ 'amylp', 'AmylPCt_Meas_pct' ], 'additionalInfo' => {}, 'growthStage' => undef, 'status' => 'active', 'scale' => { 'units' => undef, 'validValues' => { 'minimumValue' => undef, 'maximumValue' => undef, 'categories' => undef }, 'scalePUI' => undef, 'externalReferences' => undef, 'scaleDbId' => undef, 'additionalInfo' => undef, 'scaleName' => undef, 'dataType' => 'Text', 'ontologyReference' => undef, 'decimalPlaces' => undef }, 'observationVariablePUI' => 'CO_334:0000121', 'externalReferences' => [ { 'referenceId' => 'CO_334:0000121', 'referenceSource' => 'Crop Ontology' } ], 'method' => {}
202  }]},'metadata' => {'datafiles' => [],'pagination' => {'totalCount' => 1,'pageSize' => 10,'currentPage' => 0,'totalPages' => 1},'status' => [{'message' => 'BrAPI base call found with page=0, pageSize=10','messageType' => 'INFO'},{'messageType' => 'INFO','message' => 'Loading CXGN::BrAPI::v2::Results'},{'message' => 'search result constructed','messageType' => 'INFO'}]}});
205 ####### Traits
206 $mech->get_ok('http://localhost:3010/brapi/v2/traits?pageSize=1&page=1');
207 $response = decode_json $mech->content;
208 #print STDERR "\n\n" . Dumper$response;
209 is_deeply($response,  {
210   'metadata' => {
211     'datafiles' => [],
212     'status' => [
213       {
214         'messageType' => 'INFO',
215         'message' => 'BrAPI base call found with page=1, pageSize=1'
216       },
217       {
218         'messageType' => 'INFO',
219         'message' => 'Loading CXGN::BrAPI::v2::Traits'
220       },
221       {
222         'message' => 'Traits list result constructed',
223         'messageType' => 'INFO'
224       }
225     ],
226     'pagination' => {
227       'pageSize' => 1,
228       'currentPage' => 1,
229       'totalPages' => 7024,
230       'totalCount' => 7024
231     }
232   },
233   'result' => {
234     'data' => [
235       {
236         'status' => 'active',
237         'attribute' => undef,
238         'traitClass' => undef,
239         'traitDbId' => '68621',
240         'traitPUI' => undef,
241         'attributePUI' => undef,
242         'entityPUI' => undef,
243         'entity' => undef,
244         'traitName' => '1,3-beta-D-glucan synthase complex',
245         'ontologyReference' => {
246           'version' => undef,
247           'documentationLinks' => undef,
248           'ontologyName' => 'GO',
249           'ontologyDbId' => 5
250         },
251         'alternativeAbbreviations' => undef,
252         'synonyms' => [],
253         'mainAbbreviation' => undef,
254         'externalReferences' => [
255           {
256             'referenceSource' => 'EC',
257             'referenceId' => '2.4.1.34'
258           },
259           {
260             'referenceId' => 'http://www.cropontology.org/terms/GO:0000148/',
261             'referenceSource' => 'Crop Ontology'
262           }
263         ],
264         'additionalInfo' => {},
265         'traitDescription' => 'A protein complex that catalyzes the transfer of a glucose group from UDP-glucose to a 1,3-beta-D-glucan chain.'
266       }
267     ]
268   }
271 $mech->get_ok('http://localhost:3010/brapi/v2/traits/77216');
272 $response = decode_json $mech->content;
273 #print STDERR "\n\n" . Dumper$response;
274 is_deeply($response, {'metadata' => {'pagination' => {'totalPages' => 1,'pageSize' => 10,'totalCount' => 1,'currentPage' => 0},'datafiles' => [],'status' => [{'messageType' => 'INFO','message' => 'BrAPI base call found with page=0, pageSize=10'},{'messageType' => 'INFO','message' => 'Loading CXGN::BrAPI::v2::Traits'},{'message' => 'Trait detail result constructed','messageType' => 'INFO'}]},'result' => {'additionalInfo' => {},'traitName' => '3-phosphoglyceric acid','traitPUI' => undef,'entity' => undef,'attributePUI' => undef, 'entityPUI' => undef,'externalReferences' => [{'referenceId' => '40016','referenceSource' => 'CHEBI'},{'referenceSource' => 'CHEBI','referenceId' => '11882'},{'referenceId' => '1659','referenceSource' => 'CHEBI'},{'referenceId' => '24345','referenceSource' => 'CHEBI'},{'referenceId' => '22735334 "PubMed citation"','referenceSource' => 'CiteXplore'},{'referenceSource' => 'CiteXplore','referenceId' => '17439666 "PubMed citation"'},{'referenceSource' => 'CiteXplore','referenceId' => '19212411 "PubMed citation"'},{'referenceSource' => 'CiteXplore','referenceId' => '2490073 "PubMed citation"'},{'referenceId' => 'HMDB00807 "HMDB"','referenceSource' => 'HMDB'},{'referenceSource' => 'CiteXplore','referenceId' => '7602787 "PubMed citation"'},{'referenceId' => '3-Phosphoglycerate "Wikipedia"','referenceSource' => 'Wikipedia'},{'referenceId' => 'C00007286 "KNApSAcK"','referenceSource' => 'KNApSAcK'},{'referenceId' => '1726829 "Reaxys Registry Number"','referenceSource' => 'Reaxys'},{'referenceSource' => 'CiteXplore','referenceId' => '10937433 "PubMed citation"'},{'referenceId' => '2153800 "PubMed citation"','referenceSource' => 'CiteXplore'},{'referenceSource' => 'CiteXplore','referenceId' => '183226 "PubMed citation"'},{'referenceId' => '7664478 "PubMed citation"','referenceSource' => 'CiteXplore'},{'referenceSource' => 'DrugBank','referenceId' => 'DB04510 "DrugBank"'},{'referenceId' => '23857558 "PubMed citation"','referenceSource' => 'CiteXplore'},{'referenceSource' => 'CiteXplore','referenceId' => '15882454 "PubMed citation"'},{'referenceId' => '36399 "PubMed citation"','referenceSource' => 'CiteXplore'},{'referenceSource' => 'ChemIDplus','referenceId' => '820-11-1 "CAS Registry Number"'},{'referenceSource' => 'CiteXplore','referenceId' => '9055056 "PubMed citation"'},{'referenceSource' => 'Wikipedia','referenceId' => '3-Phosphoglyceric_acid "Wikipedia"'},{'referenceSource' => 'CiteXplore','referenceId' => '8412001 "PubMed citation"'},{'referenceId' => 'C00597 "KEGG COMPOUND"','referenceSource' => 'KEGG COMPOUND'},{'referenceSource' => 'Crop Ontology','referenceId' => 'http://www.cropontology.org/terms/CHEBI:17050/'}],'mainAbbreviation' => undef,'traitDbId' => '77216','ontologyReference' => {'ontologyName' => 'CHEBI','documentationLinks' => undef,'ontologyDbId' => 88,'version' => undef},'status' => 'active','attribute' => undef,'synonyms' => ['G3P','3-Pg','3-PGA','C3H7O7P','Glycerate-3-P','3-P-Glycerate','3-P-D-Glycerate','Phosphoglycerate','3-Phosphoglycerate','3-Phospho-glycerate','3-Glycerophosphorate','3-Phospho-D-glycerate','Glycerate 3-phosphate','OC(COP(O)(O)=O)C(O)=O','3-phosphoglyceric acid','glycerate 3-phosphates','3-Phospho-(R)-glycerate','3-Phospho-glyceric acid','D-Glycerate 3-phosphate','DL-Glycerate 3-phosphate','3-Glycerophosphoric acid','Glyceric acid 3-phosphate','OSJPPGNTCRNQQC-UHFFFAOYSA-N','D-(-)-3-Phosphoglyceric acid','3-(dihydrogen phosphate)Glycerate','3-(dihydrogen phosphate)Glyceric acid','2-hydroxy-3-(phosphonooxy)propanoic acid','InChI=1S/C3H7O7P/c4-2(3(5)6)1-10-11(7,8)9/h2,4H,1H2,(H,5,6)(H2,7,8,9)'],'traitDescription' => 'A monophosphoglyceric acid having the phospho group at the 3-position. It is an intermediate in metabolic pathways like glycolysis and calvin cycle.','traitClass' => undef,'alternativeAbbreviations' => undef}});
277 ####### Images
278 $data = '[  {"additionalInfo": {},"copyright": "Copyright 2018 Bob","description": "Tomatoes","descriptiveOntologyTerms": [],"externalReferences": [],"imageFileName": "image_00G00231a.jpg","imageFileSize": 50000,"imageHeight": 550,"imageLocation": {  "geometry": {"coordinates": [  -76.506042,  42.417373,  9],"type": "Point"  },  "type": "Feature"},"imageName": "Tomato Imag-10","imageTimeStamp": "2020-06-17T16:20:00.217Z","imageURL": "https://breedbase.org/images/tomato","imageWidth": 700,"mimeType": "image/jpeg","observationDbIds": [],"observationUnitDbId": "38842"  }]';
280 $mech->post('http://localhost:3010/brapi/v2/images', Content => $data);
282 $response = decode_json $mech->content;
283 #print STDERR "\n\n" . Dumper $response;
284 is_deeply($response->{metadata}, {'status' => [{'message' => 'BrAPI base call found with page=0, pageSize=10','messageType' => 'INFO'},{'messageType' => 'INFO','message' => 'Loading CXGN::BrAPI::v2::Images'},{'message' => 'Image metadata stored','messageType' => 'INFO'}],'datafiles' => undef,'pagination' => {'pageSize' => 10,'totalPages' => 1,'currentPage' => 0,'totalCount' => 1}});
286 $data = '{  "additionalInfo": {},  "copyright": "Copyright 2019 Bob",  "description": "picture of a tomato",  "descriptiveOntologyTerms": [],  "externalReferences": [],  "imageFileName": "image_0AA0231.jpg",  "imageFileSize": 50000,  "imageHeight": 550,  "imageLocation": {"geometry": {  "coordinates": [-76.506042,42.417373,123  ],  "type": "Point"},"type": "Feature"  },  "imageName": "Tomato Image-x1",  "imageTimeStamp": "2020-06-17T16:08:42.015Z",  "imageURL": "https://breedbase.org/images/tomato",  "imageWidth": 700,  "mimeType": "image/jpeg",  "observationDbIds": [],  "observationUnitDbId": "38843"}';
288 $resp = $ua->put("http://localhost:3010/brapi/v2/images/2425", Content => $data);
289 $response = decode_json $resp->{_content};
290 #print STDERR "\n\n" . Dumper$response;
291 is_deeply($response->{result}->{observationUnitDbId} , '38843');
292 my $image_timestamp = $response->{result}->{imageTimeStamp} ;
294 $mech->get_ok('http://localhost:3010/brapi/v2/images');
295 $response = decode_json $mech->content;
296 #print STDERR "\n\n" . Dumper$response;
297 is_deeply($response, {'result' => {'data' => [{'descriptiveOntologyTerms' => [],'imageWidth' => undef,'imageLocation' => undef,'imageFileName' => 'image_0AA0231.jpg','imageFileSize' => undef,'imageURL' => 'localhost/data/images/image_files/XX/XX/XX/XX/XXXXXXXXXXXXXXXXXXXXXXXX/medium.jpg','description' => 'picture of a tomato','copyright' => 'janedoe '.DateTime->now->year,'imageDbId' => '2425','imageTimeStamp' => $image_timestamp,'mimeType' => 'image/jpeg','additionalInfo' => {'observationLevel' => 'accession','tags' => [],'observationUnitName' => 'test_accession4'},'imageHeight' => undef,'observationUnitDbId' => '38843','observationDbIds' => [],'imageName' => 'Tomato Image-x1','externalReferences' => []}]},'metadata' => {'datafiles' => [],'status' => [{'messageType' => 'INFO','message' => 'BrAPI base call found with page=0, pageSize=10'},{'message' => 'Loading CXGN::BrAPI::v2::Images','messageType' => 'INFO'},{'messageType' => 'INFO','message' => 'Image search result constructed'}],'pagination' => {'currentPage' => 0,'totalCount' => 1,'totalPages' => 1,'pageSize' => 10}}} );
299 ####### ObsverationUnits
300 # Test OU plant creation
301 $data = '[{"germplasmDbId":"41281","locationDbId":"23","observationUnitName":"Testing Plant","programDbId":"134","studyDbId":"165","trialDbId":"165","observationUnitPosition":{"observationLevel":{"levelName":"plant","levelCode":"plant_1"},"observationLevelRelationships":[{"levelCode":"' . $stock_id. '","levelName":"plot"}],"positionCoordinateX":"74","positionCoordinateXType":"GRID_COL","positionCoordinateY":"03","positionCoordinateYType":"GRID_ROW"}, "additionalInfo" : {"observationUnitParent":"' . $stock_id. '"} }]';
302 $mech->post('http://localhost:3010/brapi/v2/observationunits/', Content => $data);
303 $response = decode_json $mech->content;
304 #print STDERR "\n\n Observation Unit Response is : " . $stock_id . Dumper($response);
306 my $rs = $f->bcs_schema()->resultset('Stock::Stock')->search( undef, { columns => [ { stock_id => { max => "stock_id" }} ]} );
307 my $row = $rs->next();
309 my $plant_id = $row->stock_id();
310 my $expected = {'metadata' => {'pagination' => {'currentPage' => 0,'totalPages' => 1,'pageSize' => 1,'totalCount' => 1},'status' => [{'message' => 'BrAPI base call found with page=0, pageSize=10','messageType' => 'INFO'},{'message' => 'Loading CXGN::BrAPI::v2::ObservationUnits','messageType' => 'INFO'},{'messageType' => 'INFO','message' => 'Observation Units search result constructed'}],'datafiles' => []},'result' => {'data' => [ { 'observationUnitDbId' => $plant_id, 'germplasmDbId' => '41281','crossDbId'=>undef,'crossName'=>undef,'germplasmName' => 'IITA-TMS-IBA011412', 'observationUnitPUI' => 'http://localhost:3010/stock/'. $plant_id .'/view', 'externalReferences' => [], 'trialDbId' => '165', 'studyName' => 'CASS_6Genotypes_Sampling_2015', 'observations' => [], 'seedLotName' => undef, 'observationUnitPosition' => { 'positionCoordinateYType' => 'GRID_ROW', 'positionCoordinateX' => 74, 'geoCoordinates' => undef, 'observationLevel' => { 'levelName' => 'plant', 'levelOrder' => 4, 'levelCode' => '1' }, 'entryType' => 'test', 'positionCoordinateXType' => 'GRID_COL', 'observationLevelRelationships' => [ { 'levelCode' => '1', 'levelName' => 'rep', 'levelOrder' => 0 }, { 'levelName' => 'block', 'levelOrder' => 1, 'levelCode' => '1' }, { 'levelCode' => '10', 'levelName' => 'plot', 'levelOrder' => 2 }, { 'levelName' => 'plant', 'levelOrder' => 4, 'levelCode' => '1' } ], 'positionCoordinateY' => 3 }, 'programName' => 'test', 'trialName' => 'CASS_6Genotypes_Sampling_2015', 'seedLotDbId' => undef, 'programDbId' => '134', 'studyDbId' => '165', 'locationName' => 'test_location', 'treatments' => [ { 'factor' => 'No ManagementFactor', 'modality' => undef } ], 'plotImageDbIds' => [], 'observationUnitName' => 'Testing Plant', 'locationDbId' => '23', 'additionalInfo' => { 'observationUnitParent' => $stock_id } } ]}};
312 #print STDERR "\n\n Observation Unit Expected is :  " . Dumper($expected);
313 is_deeply($response, $expected, "POST observationunits test" );
316 #Test observationunits put
317 $data = '{ "'.$stock_id.'":  { "observationUnitName":"Testing Plot", "studyDbId": "165","studyName": "CASS_6Genotypes_Sampling_2015", "germplasmDbId": "41281", "germplasmName": "IITA-TMS-IBA011412", "externalReferences" :[], "observationUnitPosition": {"entryType": "TEST", "geoCoordinates": { "geometry": { "coordinates": [ -76.506042, 42.417373, 10 ], "type": "Point" }, "type": "Feature" }, "observationLevel": { "levelName": "plot", "levelOrder": 2, "levelCode": "Plot_123" }, "observationLevelRelationships": [ { "levelCode": "Rep_1", "levelName": "rep", "levelOrder": 0 }, { "levelCode": "Block_12", "levelName": "block", "levelOrder": 1 }, { "levelCode": "Plot_123", "levelName": "plot", "levelOrder": 2 } ], "positionCoordinateX": "74", "positionCoordinateXType": "GRID_COL", "positionCoordinateY": "03", "positionCoordinateYType": "GRID_ROW" }} }';
319 $resp = $ua->put("http://localhost:3010/brapi/v2/observationunits/", Content => $data);
320 $response = decode_json $resp->{_content};
321 is_deeply($response, {'metadata' => {'pagination' => {'totalCount' => 1,'currentPage' => 0,'pageSize' => 10,'totalPages' => 1},'datafiles' => [],'status' => [{'messageType' => 'INFO','message' => 'BrAPI base call found with page=0, pageSize=10'},{'message' => 'Loading CXGN::BrAPI::v2::ObservationUnits','messageType' => 'INFO'},{'message' => 'Observation Units search result constructed','messageType' => 'INFO'}]},'result' => {'data' => [{'observationUnitDbId' => $stock_id, 'observationUnitPUI' => 'http://localhost:3010/stock/'. $stock_id .'/view', 'locationDbId' => '23','programDbId' => '134','observationUnitName' => 'Testing Plot','locationName' => 'test_location','trialDbId' => '165','studyDbId' => '165','germplasmDbId' => '41281','crossDbId'=>undef,'crossName'=>undef,'observationUnitPosition' => {'positionCoordinateYType' => 'GRID_ROW','observationLevel' => {'levelOrder' => 2,'levelCode' => 'Plot_123','levelName' => 'plot'},'positionCoordinateY' => 3,'observationLevelRelationships' => [{'levelName' => 'rep','levelCode' => 'Rep_1','levelOrder' => 0}, {'levelCode' => 'Block_12','levelOrder' => 1,'levelName' =>'block'},{'levelCode' => 'Plot_123','levelOrder' => 2,'levelName' => 'plot'}],'positionCoordinateX' => 74,'entryType' => 'test','positionCoordinateXType' => 'GRID_COL','geoCoordinates' => {'type' => 'Feature','geometry' => {'coordinates' => ['-76.506042','42.417373',10],'type' => 'Point'}}},'trialName' => 'CASS_6Genotypes_Sampling_2015','studyName' => 'CASS_6Genotypes_Sampling_2015','germplasmName' => 'IITA-TMS-IBA011412','programName' => 'test','treatments' => [{'factor' => 'No ManagementFactor','modality' => undef}],'externalReferences' => [],'observations' => [],'additionalInfo' =>  {'field' => 'Field2'},'seedLotDbId' => undef, 'seedLotName' => undef,'plotImageDbIds' => []}]}}, "observationunits put test");
324 $mech->post_ok('http://localhost:3010/brapi/v2/search/observationunits', ['observationUnitDbIds'=>['41300','41301']]);
325 $response = decode_json $mech->content;
326 $searchId = $response->{result} ->{searchResultsDbId};
327 $mech->get_ok('http://localhost:3010/brapi/v2/search/observationunits/'. $searchId);
328 $response = decode_json $mech->content;
329 #print STDERR "\n\n" . Dumper $response;
330 is_deeply($response,  {'metadata' => {'status' => [{'messageType' => 'INFO','message' => 'BrAPI base call found with page=0, pageSize=10'},{'message' => 'Loading CXGN::BrAPI::v2::Results','messageType' => 'INFO'},{'message' => 'search result constructed','messageType' => 'INFO'}],'pagination' => {'totalPages' => 1,'totalCount' => 2,'currentPage' => 0,'pageSize' => 10},'datafiles' => []},'result' => {'data' => [{'additionalInfo' => undef,'observationUnitName' => 'CASS_6Genotypes_202', 'seedLotDbId' => undef, 'seedLotName' => undef , 'locationDbId' => '23','trialDbId' => '165','germplasmName' => 'TMEB693','observationUnitDbId' => '41300','observationUnitPUI' => 'http://localhost:3010/stock/41300/view', 'studyDbId' => '165','externalReferences' => [],'programDbId' => '134','observations' => [],'plotImageDbIds' => [], 'germplasmDbId' => '41280','crossDbId'=>undef,'crossName'=>undef,'programName' => 'test','observationUnitPosition' => {'positionCoordinateY' => undef,'positionCoordinateXType' => 'GRID_COL','positionCoordinateYType' => 'GRID_ROW','positionCoordinateX' => undef,'geoCoordinates' => undef,'entryType' => 'test','observationLevelRelationships' => [{'levelCode' => '1','levelOrder' => 0,'levelName' => 'rep'},{'levelCode' => '2','levelName' => 'block','levelOrder' => 1},{'levelCode' => '202','levelOrder' => 2,'levelName' => 'plot'}],'observationLevel' => {'levelName' => 'plot','levelOrder' => 2,'levelCode' => '202'}},'treatments' => [{'factor' => 'No ManagementFactor','modality' => undef}],'locationName' => 'test_location','trialName' => 'CASS_6Genotypes_Sampling_2015','studyName' => 'CASS_6Genotypes_Sampling_2015'},{'studyName' => 'CASS_6Genotypes_Sampling_2015','treatments' => [{'factor' => 'No ManagementFactor','modality' => undef}],'locationName' => 'test_location','trialName' => 'CASS_6Genotypes_Sampling_2015','observations' => [],'seedLotDbId' => undef, 'seedLotName' => undef , 'germplasmDbId' => '41282','crossDbId'=>undef,'crossName'=>undef,'programName' => 'test','observationUnitPosition' => {'observationLevel' => {'levelCode' => '203','levelName' => 'plot','levelOrder' => 2},'observationLevelRelationships' => [{'levelCode' => '1','levelOrder' => 0,'levelName' => 'rep'},{'levelOrder' => 1,'levelName' => 'block','levelCode' => '2'},{'levelCode' => '203','levelOrder' => 2,'levelName' => 'plot'}],'positionCoordinateXType' => 'GRID_COL','positionCoordinateY' => undef,'entryType' => 'test','geoCoordinates' => undef,'positionCoordinateYType' => 'GRID_ROW','positionCoordinateX' => undef},'programDbId' => '134','observationUnitDbId' => '41301','observationUnitPUI' => 'http://localhost:3010/stock/41301/view','studyDbId' => '165','externalReferences' => [],'locationDbId' => '23','trialDbId' => '165','germplasmName' => 'IITA-TMS-IBA980002','plotImageDbIds' => [], 'additionalInfo' => undef,'observationUnitName' => 'CASS_6Genotypes_203'}]}});
334 $data = '{ "additionalInfo": { "control": 1 }, "germplasmDbId": "41280", "germplasmName": "TMEB693", "locationDbId": "23", "locationName": "test_location", "observationUnitName": "CASS_6Genotypes_202", "observationUnitPUI": "10", "programDbId": "134", "programName": "test", "seedLotDbId": "", "studyDbId": "165", "studyName": "CASS_6Genotypes_Sampling_2015", "treatments": [], "trialDbId": "165", "trialName": "", "observationUnitPosition": {"entryType": "test", "geoCoordinates": { "geometry": { "coordinates": [   -76.506042,   42.417373,   157 ], "type": "Point" }, "type": "Feature" }, "observationLevel": { "levelName": "plot", "levelOrder": 2, "levelCode": "10" }, "observationLevelRelationships": [ { "levelCode": "Rep_2", "levelName": "rep", "levelOrder": 0 }, { "levelCode": "Block_12", "levelName": "block", "levelOrder": 1 }, { "levelCode": "10", "levelName": "plot", "levelOrder": 2 } ], "positionCoordinateX": "75", "positionCoordinateXType": "GRID_COL", "positionCoordinateY": "30", "positionCoordinateYType": "GRID_ROW" }, "externalReferences": [{ "referenceID": "doi:10.155454/12341234", "referenceSource": "DOI" }] }';
335 $resp = $ua->put("http://localhost:3010/brapi/v2/observationunits/41300", Content => $data);
336 $response = decode_json $resp->{_content};
337 #print STDERR "\n\n Observation Unit Response is : " . Dumper $response;
338 my $expected = {'metadata' => {'pagination' => {'totalCount' => 1,'pageSize' => 10,'currentPage' => 0,'totalPages' => 1},'status' => [{'messageType' => 'INFO','message' => 'BrAPI base call found with page=0, pageSize=10'},{'message' => 'Loading CXGN::BrAPI::v2::ObservationUnits','messageType' => 'INFO'},{'messageType' => 'INFO','message' => 'Observation Units search result constructed'}],'datafiles' => []},'result' => {'data' => [{'treatments' => [{'factor' => 'No ManagementFactor','modality' => undef}],'studyName' => 'CASS_6Genotypes_Sampling_2015','trialName' => 'CASS_6Genotypes_Sampling_2015','plotImageDbIds' => [],'observationUnitPosition' => {'observationLevel' => {'levelCode' => '10','levelName' => 'plot','levelOrder' => 2},'positionCoordinateX' => 75,'entryType' => 'test','positionCoordinateY' => 30,'geoCoordinates' => {'geometry' => {'coordinates' => ['-76.506042','42.417373',157],'type' => 'Point'},'type' => 'Feature'},'positionCoordinateXType' => 'GRID_COL','observationLevelRelationships' => [{'levelName' => 'rep','levelCode' => 'Rep_2','levelOrder' => 0}, {'levelOrder' => 1,'levelCode' => 'Block_12','levelName' => 'block'},{'levelCode' => '10','levelName' => 'plot','levelOrder' => 2}],'positionCoordinateYType' => 'GRID_ROW'},'locationDbId' => '23','seedLotDbId' => undef,'studyDbId' => '165','observationUnitPUI' => 'http://localhost:3010/stock/41300/view','additionalInfo' => undef,'externalReferences' => [{ 'referenceId'=> 'doi:10.155454/12341234', 'referenceSource'=> 'DOI' }],'observations' => [],'programName' => 'test','trialDbId' => '165','germplasmName' => 'TMEB693','germplasmDbId' => '41280','crossDbId'=>undef,'crossName'=>undef,'programDbId' => '134','locationName' => 'test_location','seedLotName' => undef,'observationUnitName' => 'CASS_6Genotypes_202','observationUnitDbId' => '41300'}]}};
340 #print STDERR "\n\n Observation Unit Expected is :  " . Dumper($expected);
341 is_deeply($response,  $expected, "PUT OU 41300 test" );
342 print STDERR "\n\n   DONE with phenotyping tests.\n\n";
344 $f->clean_up_db();
346 done_testing();