view m-toolbox/classes/tests/database/@ltpda_ao_table/test_ao_data_id.m @ 25:79dc7091dbbc database-connection-manager

Update tests
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Mon, 05 Dec 2011 16:20:06 +0100
parents f0afece42f48
children 3aef676a1b20
line wrap: on
line source

%
% DESCRIPTION: Tests the 'ao' table of the database.
%
% ATTENTION:   This test assumes that we have committed only one AO with
%              each data-type.
%
% CHECKS:      - Check that the 'data_id' contains the correct ID from the
%                data table. --> check that the data_id of the 'ao' table
%                is the same as the last entry in the data table
%                (e.g. fsdata table).
%
% VERSION:     $Id: test_ao_data_id.m,v 1.2 2011/05/25 16:25:30 ingo Exp $
%
function varargout = test_ao_data_id(varargin)
  
  utp = varargin{1};
  
  if ~utp.testRunner.skipRepoTests()
    
    % For this UTP it is necessary that we just commit the object befor we
    % can check the ID.
    utp.init();
    
    dbTable    = 'ao';
    tableField = 'data_id';
    
    % Check that the metadata was set with a submit PLIST
    try
      for nn = 1:numel(utp.objIds)
        
        dataID1 = getDataIdFromAoTable(utp, utp.objIds(nn));
        
        % Create query to get the field 'id' from the data table (e.g. 'fsdata')
        query = sprintf('SELECT id FROM %s ORDER BY id DESC LIMIT 0,1', class(utp.testData(nn).data));
        dataID2 = utils.mysql.execute(utp.conn, query);
        
        % ATTENTION: This test assumes that we have committed only one AO
        %            with each data-type.
        % Check that we got the same IDs
        assert(dataID1{1} == dataID2{1})
        
      end
    catch Me
      throw(Me);
    end
    
    varargout{1} = sprintf('Test the field ''%s'' of the database table ''%s'' with the database %s ', tableField, dbTable, utp.testRunner.repositoryPlist.find('database'));
  else
    varargout{1} = 'Skip database test';
  end
end