|
| 1 | +set verify off |
| 2 | +create or replace package &&cwms_schema..test_cwms_water_supply as |
| 3 | +--%suite(Test cwms units conversions for water supply accounting) |
| 4 | + |
| 5 | +--%beforeall(setup) |
| 6 | +--%afterall(teardown) |
| 7 | +--%rollback(manual) |
| 8 | + |
| 9 | +procedure setup; |
| 10 | +procedure teardown; |
| 11 | + |
| 12 | +--%test(Roundtrip store/retrieve of pump accounting with per-record units) |
| 13 | +procedure test_roundtrip_pump_accounting_units; |
| 14 | + |
| 15 | +end test_cwms_water_supply; |
| 16 | +/ |
| 17 | +show errors; |
| 18 | + |
| 19 | +create or replace package body &&cwms_schema..test_cwms_water_supply as |
| 20 | + |
| 21 | + c_office_id varchar2(16) := '&&office_id'; |
| 22 | + c_project_loc_id varchar2(57) := 'WSUnitsProj'; |
| 23 | + c_pump_loc_id varchar2(57) := 'WSUnitsPump'; |
| 24 | + c_water_user_name varchar2(64) := 'WS Units User'; |
| 25 | + c_contract_name varchar2(64) := 'WS Units Contract'; |
| 26 | + |
| 27 | +procedure setup |
| 28 | +is |
| 29 | +begin |
| 30 | + -- Ensure clean state |
| 31 | + begin |
| 32 | + cwms_water_supply.delete_contract( |
| 33 | + p_contract_ref => water_user_contract_ref_t( |
| 34 | + water_user_obj_t( |
| 35 | + location_ref_t(c_project_loc_id, c_office_id), |
| 36 | + c_water_user_name, |
| 37 | + null), |
| 38 | + c_contract_name), |
| 39 | + p_delete_action => cwms_util.delete_all); |
| 40 | + exception when others then null; end; |
| 41 | + begin |
| 42 | + cwms_water_supply.delete_water_user( |
| 43 | + p_project_location_ref => location_ref_t(c_project_loc_id, c_office_id), |
| 44 | + p_entity_name => c_water_user_name, |
| 45 | + p_delete_action => cwms_util.delete_all); |
| 46 | + exception when others then null; end; |
| 47 | + begin |
| 48 | + cwms_loc.delete_location(c_pump_loc_id, cwms_util.delete_all, c_office_id); |
| 49 | + exception when others then null; end; |
| 50 | + begin |
| 51 | + cwms_loc.delete_location(c_project_loc_id, cwms_util.delete_all, c_office_id); |
| 52 | + exception when others then null; end; |
| 53 | + |
| 54 | + -- Create needed locations |
| 55 | + cwms_loc.store_location( |
| 56 | + p_location_id => c_project_loc_id, |
| 57 | + p_time_zone_id => 'UTC', |
| 58 | + p_vertical_datum => null, |
| 59 | + p_db_office_id => c_office_id); |
| 60 | + |
| 61 | + cwms_loc.store_location( |
| 62 | + p_location_id => c_pump_loc_id, |
| 63 | + p_time_zone_id => 'UTC', |
| 64 | + p_vertical_datum => null, |
| 65 | + p_db_office_id => c_office_id); |
| 66 | + |
| 67 | + -- Create water user |
| 68 | + cwms_water_supply.store_water_user( |
| 69 | + p_water_user => water_user_obj_t( |
| 70 | + location_ref_t(c_project_loc_id, c_office_id), |
| 71 | + c_water_user_name, |
| 72 | + 'TEST RIGHT'), |
| 73 | + p_fail_if_exists => 'F'); |
| 74 | + |
| 75 | + -- Create a simple contract |
| 76 | + cwms_water_supply.store_contracts( |
| 77 | + p_contracts => water_user_contract_tab_t( |
| 78 | + water_user_contract_obj_t( |
| 79 | + water_user_contract_ref_t( |
| 80 | + water_user_obj_t( |
| 81 | + location_ref_t(c_project_loc_id, c_office_id), |
| 82 | + c_water_user_name, |
| 83 | + 'TEST RIGHT'), |
| 84 | + c_contract_name), |
| 85 | + lookup_type_obj_t('CWMS','Storage','', 'T'), |
| 86 | + null, -- effective |
| 87 | + null, -- expiration |
| 88 | + 0, -- contracted_storage |
| 89 | + 0, -- initial_use_allocation |
| 90 | + 0, -- future_use_allocation |
| 91 | + 'ac-ft', -- storage units |
| 92 | + null, -- future_use_percent_activated |
| 93 | + null, -- total_alloc_percent_activated |
| 94 | + null, -- pump_out_location |
| 95 | + null, -- pump_out_below_location |
| 96 | + null -- pump_in_location |
| 97 | + ) |
| 98 | + ), |
| 99 | + p_fail_if_exists => 'F'); |
| 100 | + |
| 101 | + commit; |
| 102 | +end setup; |
| 103 | + |
| 104 | +procedure teardown |
| 105 | +is |
| 106 | +begin |
| 107 | + begin |
| 108 | + cwms_water_supply.delete_contract( |
| 109 | + p_contract_ref => water_user_contract_ref_t( |
| 110 | + water_user_obj_t( |
| 111 | + location_ref_t(c_project_loc_id, c_office_id), |
| 112 | + c_water_user_name, |
| 113 | + 'TEST RIGHT'), |
| 114 | + c_contract_name), |
| 115 | + p_delete_action => cwms_util.delete_all); |
| 116 | + exception when others then null; end; |
| 117 | + begin |
| 118 | + cwms_water_supply.delete_water_user( |
| 119 | + p_project_location_ref => location_ref_t(c_project_loc_id, c_office_id), |
| 120 | + p_entity_name => c_water_user_name, |
| 121 | + p_delete_action => cwms_util.delete_all); |
| 122 | + exception when others then null; end; |
| 123 | + begin |
| 124 | + cwms_loc.delete_location(c_pump_loc_id, cwms_util.delete_all, c_office_id); |
| 125 | + exception when others then null; end; |
| 126 | + begin |
| 127 | + cwms_loc.delete_location(c_project_loc_id, cwms_util.delete_all, c_office_id); |
| 128 | + exception when others then null; end; |
| 129 | + commit; |
| 130 | +end teardown; |
| 131 | + |
| 132 | +procedure test_roundtrip_pump_accounting_units |
| 133 | +is |
| 134 | + l_contract_ref water_user_contract_ref_t := water_user_contract_ref_t( |
| 135 | + water_user_obj_t(location_ref_t(c_project_loc_id, c_office_id), c_water_user_name, 'TEST RIGHT'), |
| 136 | + c_contract_name); |
| 137 | + l_tz varchar2(28) := 'UTC'; |
| 138 | + l_start_time date := to_date('2025-01-01 00:00','yyyy-mm-dd hh24:mi'); |
| 139 | + l_end_time date := to_date('2025-01-01 01:00','yyyy-mm-dd hh24:mi'); |
| 140 | + l_flow_cfs binary_double := 100; |
| 141 | + l_expected_cms binary_double; |
| 142 | + l_set wat_usr_contract_acct_tab_t; |
| 143 | +begin |
| 144 | + -- Compute expected cms via database conversion logic to avoid hard-coding factors |
| 145 | + l_expected_cms := cwms_util.convert_units(l_flow_cfs, 'cfs', 'cms'); |
| 146 | + |
| 147 | + -- Store one accounting record with cfs unit |
| 148 | + cwms_water_supply.store_accounting_set( |
| 149 | + p_accounting_tab => wat_usr_contract_acct_tab_t( |
| 150 | + wat_usr_contract_acct_obj_t( |
| 151 | + l_contract_ref, |
| 152 | + location_ref_t(c_pump_loc_id, c_office_id), |
| 153 | + lookup_type_obj_t('CWMS','Pipeline','', 'T'), |
| 154 | + l_flow_cfs, |
| 155 | + 'cfs', |
| 156 | + l_start_time, |
| 157 | + 'Roundtrip units test') |
| 158 | + ), |
| 159 | + p_contract_ref => l_contract_ref, |
| 160 | + p_pump_time_window_tab => loc_ref_time_window_tab_t( |
| 161 | + loc_ref_time_window_obj_t(location_ref_t(c_pump_loc_id, c_office_id), l_start_time, l_end_time) |
| 162 | + ), |
| 163 | + p_time_zone => l_tz, |
| 164 | + p_flow_unit_id => null, |
| 165 | + p_store_rule => null, |
| 166 | + p_override_prot => 'F'); |
| 167 | + |
| 168 | + -- Retrieve in cfs and validate |
| 169 | + cwms_water_supply.retrieve_accounting_set( |
| 170 | + p_accounting_set => l_set, |
| 171 | + p_contract_ref => l_contract_ref, |
| 172 | + p_units => 'cfs', |
| 173 | + p_start_time => l_start_time, |
| 174 | + p_end_time => l_end_time, |
| 175 | + p_time_zone => l_tz, |
| 176 | + p_start_inclusive => 'T', |
| 177 | + p_end_inclusive => 'T', |
| 178 | + p_ascending_flag => 'T', |
| 179 | + p_row_limit => 10, |
| 180 | + p_transfer_type => null); |
| 181 | + |
| 182 | + ut.expect(l_set.count).to_equal(1); |
| 183 | + ut.expect(abs(l_set(1).pump_flow - l_flow_cfs) < 1e-6).to_be_true(); |
| 184 | + ut.expect(upper(l_set(1).pump_flow_unit)).to_equal('CFS'); |
| 185 | + |
| 186 | + -- Retrieve in cms and validate conversion |
| 187 | + cwms_water_supply.retrieve_accounting_set( |
| 188 | + p_accounting_set => l_set, |
| 189 | + p_contract_ref => l_contract_ref, |
| 190 | + p_units => 'cms', |
| 191 | + p_start_time => l_start_time, |
| 192 | + p_end_time => l_end_time, |
| 193 | + p_time_zone => l_tz, |
| 194 | + p_start_inclusive => 'T', |
| 195 | + p_end_inclusive => 'T', |
| 196 | + p_ascending_flag => 'T', |
| 197 | + p_row_limit => 10, |
| 198 | + p_transfer_type => null); |
| 199 | + |
| 200 | + ut.expect(l_set.count).to_equal(1); |
| 201 | + ut.expect(abs(l_set(1).pump_flow - l_expected_cms) < 1e-6).to_be_true(); |
| 202 | + ut.expect(upper(l_set(1).pump_flow_unit)).to_equal('CMS'); |
| 203 | + |
| 204 | +end test_roundtrip_pump_accounting_units; |
| 205 | + |
| 206 | +end test_cwms_water_supply; |
| 207 | +/ |
| 208 | +show errors; |
0 commit comments