5 use SGN::Test::Fixture;
7 use Test::WWW::Mechanize;
8 use SGN::Model::Cvterm;
14 my $f = SGN::Test::Fixture->new();
15 my $schema = $f->bcs_schema;
17 my $mech = Test::WWW::Mechanize->new(timeout=>30000);
20 my $plot_id1 = $schema->resultset('Stock::Stock')->find({uniquename=>'test_trial210'})->stock_id;
21 my $plot_id2 = $schema->resultset('Stock::Stock')->find({uniquename=>'test_trial214'})->stock_id;
23 $mech->post_ok('http://localhost:3010/brapi/v1/token', [ "username"=> "janedoe", "password"=> "secretpw", "grant_type"=> "password" ]);
24 $response = decode_json $mech->content;
25 print STDERR Dumper $response;
26 is($response->{'metadata'}->{'status'}->[2]->{'message'}, 'Login Successfull');
27 my $sgn_session_id = $response->{access_token};
33 observationDbId => '',
34 observationUnitDbId => $plot_id1,
35 observationVariableDbId => '70741',
36 collector => 'collector1',
37 observationTimeStamp => '2015-06-16T00:53:26Z',
41 observationDbId => '',
42 observationUnitDbId => $plot_id2,
43 observationVariableDbId => '70773',
44 collector => 'collector1',
45 observationTimeStamp => '2015-06-16T00:53:26Z',
50 my $j = encode_json $data;
52 my $req = HTTP::Request->new( "PUT" => "http://localhost:3010/brapi/v1/observations" );
53 $req->content_type( 'application/json' );
55 do { use bytes; length( $j ) }
59 my $ua = LWP::UserAgent->new();
60 my $res = $ua->request($req);
61 $response = decode_json $res->content;
62 print STDERR Dumper $response;
63 is_deeply($response, {
68 'messageType' => 'ERROR',
69 'message' => 'You must login and have permission to access this BrAPI call.'
82 my $trait_id1 = SGN::Model::Cvterm->get_cvterm_row_from_trait_name($schema, 'CO_334:0000092')->cvterm_id();
83 my $trait_id2 = SGN::Model::Cvterm->get_cvterm_row_from_trait_name($schema, 'CO_334:0000016')->cvterm_id();
86 access_token => $sgn_session_id,
89 observationDbId => '',
90 observationUnitDbId => $plot_id1,
91 observationVariableDbId => $trait_id1,
92 collector => 'collector1',
93 observationTimeStamp => '2015-06-16T00:53:26Z',
97 observationDbId => '',
98 observationUnitDbId => $plot_id2,
99 observationVariableDbId => $trait_id2,
100 collector => 'collector1',
101 observationTimeStamp => '2015-06-16T00:53:26Z',
106 $j = encode_json $data;
107 $req = HTTP::Request->new( "PUT" => "http://localhost:3010/brapi/v1/observations" );
108 $req->content_type( 'application/json' );
109 $req->content_length(
110 do { use bytes; length( $j ) }
114 $ua = LWP::UserAgent->new();
115 $res = $ua->request($req);
116 $response = decode_json $res->content;
117 print STDERR Dumper $response;
119 #Remove observationdbid from result because it is variable
120 foreach (@{$response->{result}->{observations}}){
121 delete $_->{observationDbId};
124 is_deeply($response, {
128 'observationLevel' => 'plot',
129 'observationTimeStamp' => '2015-06-16T00:53:26Z',
130 'germplasmName' => 'test_accession3',
131 'observationUnitName' => 'test_trial210',
132 'uploadedBy' => 'collector1',
133 'collector' => 'collector1',
134 'germplasmDbId' => 38842,
135 'observationUnitDbId' => 38866,
137 'observationVariableName' => 'dry matter content percentage',
138 'observationVariableDbId' => '70741',
140 'externalReferences' => undef,
141 'additionalInfo' => undef,
144 'observationLevel' => 'plot',
145 'observationTimeStamp' => '2015-06-16T00:53:26Z',
146 'germplasmName' => 'test_accession4',
147 'observationUnitName' => 'test_trial214',
148 'uploadedBy' => 'collector1',
149 'collector' => 'collector1',
150 'germplasmDbId' => 38843,
151 'observationUnitDbId' => 38870,
153 'observationVariableDbId' => '70773',
154 'observationVariableName' => 'fresh shoot weight measurement in kg',
156 'externalReferences' => undef,
157 'additionalInfo' => undef,
165 'message' => 'BrAPI base call found with page=0, pageSize=10',
166 'messageType' => 'INFO'
169 'messageType' => 'INFO',
170 'message' => 'Loading CXGN::BrAPI::v1::Observations'
173 'message' => 'Request structure is valid',
174 'messageType' => 'info'
177 'messageType' => 'info',
178 'message' => 'Request data is valid'
181 'message' => 'File for incoming brapi obserations saved in archive.',
182 'messageType' => 'info'
185 'messageType' => 'INFO',
186 'message' => 'All values in your file have been successfully processed!<br><br>2 new values stored<br>0 previously stored values skipped<br>0 previously stored values overwritten<br>0 previously stored values removed<br><br>'