From 9bc1db6987015640dff02f185d8dcaa9529913c4 Mon Sep 17 00:00:00 2001 From: Daniel Marin Date: Thu, 22 Aug 2024 17:16:10 +0200 Subject: [PATCH] tests(upsert): add arc and ve_arc --- test/upsert/ws/test_arc.sql | 58 +++++++++++++++++++++++++++++ test/upsert/ws/test_ve_arc.sql | 68 ++++++++++++++++++++++++++++++++++ 2 files changed, 126 insertions(+) create mode 100644 test/upsert/ws/test_arc.sql create mode 100644 test/upsert/ws/test_ve_arc.sql diff --git a/test/upsert/ws/test_arc.sql b/test/upsert/ws/test_arc.sql new file mode 100644 index 0000000000..51d33d2588 --- /dev/null +++ b/test/upsert/ws/test_arc.sql @@ -0,0 +1,58 @@ +/* +This file is part of Giswater 3 +The program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. +This version of Giswater is provided by Giswater Association +*/ +BEGIN; + +-- Suppress NOTICE messages +SET client_min_messages TO WARNING; + +SET search_path = "SCHEMA_NAME", public, pg_catalog; + +SELECT plan(6); + +-- arc -> pipe +-- initial data is prepared before proceeding with the test +INSERT INTO ve_node_air_valve +(node_id, code, elevation, "depth", node_type, sys_type, nodecat_id, cat_matcat_id, cat_pnom, cat_dnom, cat_dint, epa_type, state, state_type, expl_id, macroexpl_id, sector_id, sector_name, macrosector_id, sector_type, presszone_id, preszone_name, presszone_type, presszone_head, dma_id, dma_name, dma_type, macrodma_id, dqa_id, dqa_name, dqa_type, macrodqa_id, arc_id, parent_id, annotation, observ, "comment", staticpressure, soilcat_id, function_type, category_type, fluid_type, location_type, workcat_id, workcat_id_end, workcat_id_plan, builtdate, enddate, buildercat_id, ownercat_id, muni_id, postcode, district_id, streetname, postnumber, postcomplement, streetname2, postnumber2, postcomplement2, region_id, province_id, descript, svg, rotation, link, verified, undelete, "label", label_x, label_y, label_rotation, publish, inventory, hemisphere, num_value, adate, adescript, accessibility, dma_style, presszone_style, asset_id, om_state, conserv_state, access_type, placement_type, expl_id2, is_operative, brand_id, model_id, serial_number, minsector_id, macrominsector_id, demand_max, demand_min, demand_avg, press_max, press_min, press_avg, head_max, head_min, head_avg, quality_max, quality_min, quality_avg, tstamp, insert_user, lastupdate, lastupdate_user, the_geom, inp_type, closed, broken, buried, irrigation_indicator, pression_entry, pression_exit, depth_valveshaft, regulator_situation, regulator_location, regulator_observ, lin_meters, exit_type, exit_code, drive_type, cat_valve2, ordinarystatus, shutter, brand2, model2, valve_type, to_arc, active, airvalve_param_1, airvalve_param_2) +VALUES('-902', '-902', 32.8100, NULL, 'AIR_VALVE', 'VALVE', 'AIR VALVE DN50', 'FD', '16', '50', NULL, 'UNDEFINED', 1, 2, 2, 1, 5, 'sector2-1d', 2, 'DISTRIBUTION', '3', 'pzone1-1d', NULL, NULL, 3, 'dma2-1d', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'soil1', NULL, NULL, NULL, NULL, 'work1', NULL, NULL, '2024-08-22', NULL, NULL, 'owner1', 2, NULL, 1, NULL, NULL, NULL, NULL, NULL, NULL, 1, 1, NULL, NULL, NULL, '', '1', NULL, NULL, NULL, NULL, NULL, true, true, NULL, NULL, NULL, NULL, NULL, '204,235,197', '204,235,197', NULL, NULL, NULL, NULL, NULL, NULL, true, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '2024-08-22 17:00:13.000', 'postgres', '2024-08-22 17:00:13.000', 'postgres', 'SRID=25831;POINT (418474.19510507485 4577983.667174499)'::public.geometry, NULL, false, false, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, false, NULL, NULL); +INSERT INTO ve_node_air_valve +(node_id, code, elevation, "depth", node_type, sys_type, nodecat_id, cat_matcat_id, cat_pnom, cat_dnom, cat_dint, epa_type, state, state_type, expl_id, macroexpl_id, sector_id, sector_name, macrosector_id, sector_type, presszone_id, preszone_name, presszone_type, presszone_head, dma_id, dma_name, dma_type, macrodma_id, dqa_id, dqa_name, dqa_type, macrodqa_id, arc_id, parent_id, annotation, observ, "comment", staticpressure, soilcat_id, function_type, category_type, fluid_type, location_type, workcat_id, workcat_id_end, workcat_id_plan, builtdate, enddate, buildercat_id, ownercat_id, muni_id, postcode, district_id, streetname, postnumber, postcomplement, streetname2, postnumber2, postcomplement2, region_id, province_id, descript, svg, rotation, link, verified, undelete, "label", label_x, label_y, label_rotation, publish, inventory, hemisphere, num_value, adate, adescript, accessibility, dma_style, presszone_style, asset_id, om_state, conserv_state, access_type, placement_type, expl_id2, is_operative, brand_id, model_id, serial_number, minsector_id, macrominsector_id, demand_max, demand_min, demand_avg, press_max, press_min, press_avg, head_max, head_min, head_avg, quality_max, quality_min, quality_avg, tstamp, insert_user, lastupdate, lastupdate_user, the_geom, inp_type, closed, broken, buried, irrigation_indicator, pression_entry, pression_exit, depth_valveshaft, regulator_situation, regulator_location, regulator_observ, lin_meters, exit_type, exit_code, drive_type, cat_valve2, ordinarystatus, shutter, brand2, model2, valve_type, to_arc, active, airvalve_param_1, airvalve_param_2) +VALUES('-901', '-901', 32.8100, NULL, 'AIR_VALVE', 'VALVE', 'AIR VALVE DN50', 'FD', '16', '50', NULL, 'UNDEFINED', 1, 2, 2, 1, 5, 'sector2-1d', 2, 'DISTRIBUTION', '3', 'pzone1-1d', NULL, NULL, 3, 'dma2-1d', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'soil1', NULL, NULL, NULL, NULL, 'work1', NULL, NULL, '2024-08-22', NULL, NULL, 'owner1', 2, NULL, 1, NULL, NULL, NULL, NULL, NULL, NULL, 1, 1, NULL, NULL, NULL, '', '1', NULL, NULL, NULL, NULL, NULL, true, true, NULL, NULL, NULL, NULL, NULL, '204,235,197', '204,235,197', NULL, NULL, NULL, NULL, NULL, NULL, true, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '2024-08-22 17:00:02.000', 'postgres', '2024-08-22 17:00:02.000', 'postgres', 'SRID=25831;POINT (418473.00472849904 4577983.379842222)'::public.geometry, NULL, false, false, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, false, NULL, NULL); + +INSERT INTO arc +(arc_id, code, node_1, node_2, arccat_id, epa_type, sector_id, state, state_type, annotation, observ, "comment", "_sys_length", custom_length, dma_id, presszone_id, soilcat_id, function_type, category_type, fluid_type, location_type, workcat_id, workcat_id_end, buildercat_id, builtdate, enddate, ownercat_id, muni_id, postcode, streetaxis_id, postnumber, postcomplement, streetaxis2_id, postnumber2, postcomplement2, descript, link, verified, the_geom, undelete, label_x, label_y, label_rotation, publish, inventory, expl_id, num_value, feature_type, tstamp, lastupdate, lastupdate_user, insert_user, minsector_id, dqa_id, staticpressure, district_id, "depth", adate, adescript, workcat_id_plan, asset_id, pavcat_id, nodetype_1, elevation1, depth1, staticpress1, nodetype_2, elevation2, depth2, staticpress2, om_state, conserv_state, parent_id, expl_id2, brand_id, model_id, serial_number, macrominsector_id) +VALUES('-901', '-901', '-901', '-902', 'PVC63-PN10', 'PIPE', 5, 1, 2, NULL, NULL, NULL, NULL, NULL, 3, '3', 'soil1', NULL, NULL, NULL, NULL, 'work1', NULL, NULL, '2024-08-22', NULL, 'owner1', 2, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '', '1', 'SRID=25831;LINESTRING (418473.00472849904 4577983.379842222, 418474.19510507485 4577983.667174499)'::public.geometry, NULL, NULL, NULL, NULL, true, true, 2, NULL, 'ARC', '2024-08-22 17:05:32.365', '2024-08-22 17:05:32.436', 'postgres', 'postgres', NULL, NULL, NULL, 1, NULL, NULL, NULL, NULL, NULL, 'Asphalt', 'AIR_VALVE', 32.8100, NULL, NULL, 'AIR_VALVE', 32.8100, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); +SELECT is((SELECT count(*)::integer FROM arc WHERE arc_id = '-901'), 1, 'INSERT: arc:pipe "-901" was inserted'); + +UPDATE arc SET custom_length = 1.0000 WHERE arc_id = '-901'; +SELECT is((SELECT custom_length FROM arc WHERE arc_id = '-901'), 1.0000, 'UPDATE: arc:pipe "-901" was updated'); + +DELETE FROM arc WHERE arc_id = '-901'; +SELECT is((SELECT count(*)::integer FROM arc WHERE arc_id = '-901'), 0, 'DELETE: arc:pipe "-901" was deleted'); + +-- arc -> varc +-- initial data is prepared before proceeding with the test +INSERT INTO ve_node_check_valve +(node_id, code, elevation, "depth", node_type, sys_type, nodecat_id, cat_matcat_id, cat_pnom, cat_dnom, cat_dint, epa_type, state, state_type, expl_id, macroexpl_id, sector_id, sector_name, macrosector_id, sector_type, presszone_id, preszone_name, presszone_type, presszone_head, dma_id, dma_name, dma_type, macrodma_id, dqa_id, dqa_name, dqa_type, macrodqa_id, arc_id, parent_id, annotation, observ, "comment", staticpressure, soilcat_id, function_type, category_type, fluid_type, location_type, workcat_id, workcat_id_end, workcat_id_plan, builtdate, enddate, buildercat_id, ownercat_id, muni_id, postcode, district_id, streetname, postnumber, postcomplement, streetname2, postnumber2, postcomplement2, region_id, province_id, descript, svg, rotation, link, verified, undelete, "label", label_x, label_y, label_rotation, publish, inventory, hemisphere, num_value, adate, adescript, accessibility, dma_style, presszone_style, asset_id, om_state, conserv_state, access_type, placement_type, expl_id2, is_operative, brand_id, model_id, serial_number, minsector_id, macrominsector_id, demand_max, demand_min, demand_avg, press_max, press_min, press_avg, head_max, head_min, head_avg, quality_max, quality_min, quality_avg, tstamp, insert_user, lastupdate, lastupdate_user, the_geom, inp_type, closed, broken, buried, irrigation_indicator, pression_entry, pression_exit, depth_valveshaft, regulator_situation, regulator_location, regulator_observ, lin_meters, exit_type, exit_code, drive_type, cat_valve2, ordinarystatus, shutter, brand2, model2, valve_type, to_arc, active, checkvalve_param_1, checkvalve_param_2) +VALUES('-903', '-903', 32.8100, NULL, 'CHECK_VALVE', 'VALVE', 'CHK-VALVE63-PN16', 'FD', '16', '63', 65.00000, 'SHORTPIPE', 1, 2, 2, 1, 5, 'sector2-1d', 2, 'DISTRIBUTION', '3', 'pzone1-1d', NULL, NULL, 3, 'dma2-1d', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'soil1', NULL, NULL, NULL, NULL, 'work1', NULL, NULL, '2024-08-22', NULL, NULL, 'owner1', 2, NULL, 1, NULL, NULL, NULL, NULL, NULL, NULL, 1, 1, NULL, NULL, NULL, '', '1', NULL, NULL, NULL, NULL, NULL, true, true, NULL, NULL, NULL, NULL, NULL, '204,235,197', '204,235,197', NULL, NULL, NULL, NULL, NULL, NULL, true, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '2024-08-22 17:01:53.000', 'postgres', '2024-08-22 17:01:53.000', 'postgres', 'SRID=25831;POINT (418473.1278709034 4577982.640987795)'::public.geometry, 'SHORTPIPE', false, false, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, false, NULL, NULL); +INSERT INTO ve_node_check_valve +(node_id, code, elevation, "depth", node_type, sys_type, nodecat_id, cat_matcat_id, cat_pnom, cat_dnom, cat_dint, epa_type, state, state_type, expl_id, macroexpl_id, sector_id, sector_name, macrosector_id, sector_type, presszone_id, preszone_name, presszone_type, presszone_head, dma_id, dma_name, dma_type, macrodma_id, dqa_id, dqa_name, dqa_type, macrodqa_id, arc_id, parent_id, annotation, observ, "comment", staticpressure, soilcat_id, function_type, category_type, fluid_type, location_type, workcat_id, workcat_id_end, workcat_id_plan, builtdate, enddate, buildercat_id, ownercat_id, muni_id, postcode, district_id, streetname, postnumber, postcomplement, streetname2, postnumber2, postcomplement2, region_id, province_id, descript, svg, rotation, link, verified, undelete, "label", label_x, label_y, label_rotation, publish, inventory, hemisphere, num_value, adate, adescript, accessibility, dma_style, presszone_style, asset_id, om_state, conserv_state, access_type, placement_type, expl_id2, is_operative, brand_id, model_id, serial_number, minsector_id, macrominsector_id, demand_max, demand_min, demand_avg, press_max, press_min, press_avg, head_max, head_min, head_avg, quality_max, quality_min, quality_avg, tstamp, insert_user, lastupdate, lastupdate_user, the_geom, inp_type, closed, broken, buried, irrigation_indicator, pression_entry, pression_exit, depth_valveshaft, regulator_situation, regulator_location, regulator_observ, lin_meters, exit_type, exit_code, drive_type, cat_valve2, ordinarystatus, shutter, brand2, model2, valve_type, to_arc, active, checkvalve_param_1, checkvalve_param_2) +VALUES('-904', '-904', 32.8100, NULL, 'CHECK_VALVE', 'VALVE', 'CHK-VALVE63-PN16', 'FD', '16', '63', 65.00000, 'SHORTPIPE', 1, 2, 2, 1, 5, 'sector2-1d', 2, 'DISTRIBUTION', '3', 'pzone1-1d', NULL, NULL, 3, 'dma2-1d', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'soil1', NULL, NULL, NULL, NULL, 'work1', NULL, NULL, '2024-08-22', NULL, NULL, 'owner1', 2, NULL, 1, NULL, NULL, NULL, NULL, NULL, NULL, 1, 1, NULL, NULL, NULL, '', '1', NULL, NULL, NULL, NULL, NULL, true, true, NULL, NULL, NULL, NULL, NULL, '204,235,197', '204,235,197', NULL, NULL, NULL, NULL, NULL, NULL, true, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '2024-08-22 17:02:03.000', 'postgres', '2024-08-22 17:02:03.000', 'postgres', 'SRID=25831;POINT (418474.44138988364 4577982.928320073)'::public.geometry, 'SHORTPIPE', false, false, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, false, NULL, NULL); + +INSERT INTO arc +(arc_id, code, node_1, node_2, arccat_id, epa_type, sector_id, state, state_type, annotation, observ, "comment", "_sys_length", custom_length, dma_id, presszone_id, soilcat_id, function_type, category_type, fluid_type, location_type, workcat_id, workcat_id_end, buildercat_id, builtdate, enddate, ownercat_id, muni_id, postcode, streetaxis_id, postnumber, postcomplement, streetaxis2_id, postnumber2, postcomplement2, descript, link, verified, the_geom, undelete, label_x, label_y, label_rotation, publish, inventory, expl_id, num_value, feature_type, tstamp, lastupdate, lastupdate_user, insert_user, minsector_id, dqa_id, staticpressure, district_id, "depth", adate, adescript, workcat_id_plan, asset_id, pavcat_id, nodetype_1, elevation1, depth1, staticpress1, nodetype_2, elevation2, depth2, staticpress2, om_state, conserv_state, parent_id, expl_id2, brand_id, model_id, serial_number, macrominsector_id) +VALUES('-902', '-902', '-903', '-904', 'VIRTUAL', 'PIPE', 5, 1, 2, NULL, NULL, NULL, NULL, NULL, 3, '3', 'soil1', NULL, NULL, NULL, NULL, 'work1', NULL, NULL, '2024-08-22', NULL, 'owner1', 2, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '', '1', 'SRID=25831;LINESTRING (418473.1278709034 4577982.640987795, 418474.44138988364 4577982.928320073)'::public.geometry, NULL, NULL, NULL, NULL, true, true, 2, NULL, 'ARC', '2024-08-22 17:05:48.525', '2024-08-22 17:05:48.577', 'postgres', 'postgres', NULL, NULL, NULL, 1, NULL, NULL, NULL, NULL, NULL, 'Asphalt', 'CHECK_VALVE', 32.8100, NULL, NULL, 'CHECK_VALVE', 32.8100, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); +SELECT is((SELECT count(*)::integer FROM arc WHERE arc_id = '-902'), 1, 'INSERT: arc:varc "-902" was inserted'); + +UPDATE arc SET custom_length = 1.0000 WHERE arc_id = '-902'; +SELECT is((SELECT custom_length FROM arc WHERE arc_id = '-902'), 1.0000, 'UPDATE: arc:varc "-902" was updated'); + +DELETE FROM arc WHERE arc_id = '-902'; +SELECT is((SELECT count(*)::integer FROM arc WHERE arc_id = '-902'), 0, 'DELETE: arc:varc "-902" was deleted'); + + +SELECT * FROM finish(); + +ROLLBACK; diff --git a/test/upsert/ws/test_ve_arc.sql b/test/upsert/ws/test_ve_arc.sql new file mode 100644 index 0000000000..91af6eb3fe --- /dev/null +++ b/test/upsert/ws/test_ve_arc.sql @@ -0,0 +1,68 @@ +/* +This file is part of Giswater 3 +The program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. +This version of Giswater is provided by Giswater Association +*/ +BEGIN; + +-- Suppress NOTICE messages +SET client_min_messages TO WARNING; + +SET search_path = "SCHEMA_NAME", public, pg_catalog; + +SELECT plan(12); +-- IMPORTANT: In this test, we check for existence using the code, not the ID, +-- because we don't allow the user to change the code. +-- In test_node.sql, we test the `node` table and can check `node_id`, +-- but here we are testing the views. + +-- arc -> pipe +-- initial data is prepared before proceeding with the test +INSERT INTO ve_node_air_valve +(node_id, code, elevation, "depth", node_type, sys_type, nodecat_id, cat_matcat_id, cat_pnom, cat_dnom, cat_dint, epa_type, state, state_type, expl_id, macroexpl_id, sector_id, sector_name, macrosector_id, sector_type, presszone_id, preszone_name, presszone_type, presszone_head, dma_id, dma_name, dma_type, macrodma_id, dqa_id, dqa_name, dqa_type, macrodqa_id, arc_id, parent_id, annotation, observ, "comment", staticpressure, soilcat_id, function_type, category_type, fluid_type, location_type, workcat_id, workcat_id_end, workcat_id_plan, builtdate, enddate, buildercat_id, ownercat_id, muni_id, postcode, district_id, streetname, postnumber, postcomplement, streetname2, postnumber2, postcomplement2, region_id, province_id, descript, svg, rotation, link, verified, undelete, "label", label_x, label_y, label_rotation, publish, inventory, hemisphere, num_value, adate, adescript, accessibility, dma_style, presszone_style, asset_id, om_state, conserv_state, access_type, placement_type, expl_id2, is_operative, brand_id, model_id, serial_number, minsector_id, macrominsector_id, demand_max, demand_min, demand_avg, press_max, press_min, press_avg, head_max, head_min, head_avg, quality_max, quality_min, quality_avg, tstamp, insert_user, lastupdate, lastupdate_user, the_geom, inp_type, closed, broken, buried, irrigation_indicator, pression_entry, pression_exit, depth_valveshaft, regulator_situation, regulator_location, regulator_observ, lin_meters, exit_type, exit_code, drive_type, cat_valve2, ordinarystatus, shutter, brand2, model2, valve_type, to_arc, active, airvalve_param_1, airvalve_param_2) +VALUES('-902', '-902', 32.8100, NULL, 'AIR_VALVE', 'VALVE', 'AIR VALVE DN50', 'FD', '16', '50', NULL, 'UNDEFINED', 1, 2, 2, 1, 5, 'sector2-1d', 2, 'DISTRIBUTION', '3', 'pzone1-1d', NULL, NULL, 3, 'dma2-1d', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'soil1', NULL, NULL, NULL, NULL, 'work1', NULL, NULL, '2024-08-22', NULL, NULL, 'owner1', 2, NULL, 1, NULL, NULL, NULL, NULL, NULL, NULL, 1, 1, NULL, NULL, NULL, '', '1', NULL, NULL, NULL, NULL, NULL, true, true, NULL, NULL, NULL, NULL, NULL, '204,235,197', '204,235,197', NULL, NULL, NULL, NULL, NULL, NULL, true, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '2024-08-22 17:00:13.000', 'postgres', '2024-08-22 17:00:13.000', 'postgres', 'SRID=25831;POINT (418474.19510507485 4577983.667174499)'::public.geometry, NULL, false, false, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, false, NULL, NULL); +INSERT INTO ve_node_air_valve +(node_id, code, elevation, "depth", node_type, sys_type, nodecat_id, cat_matcat_id, cat_pnom, cat_dnom, cat_dint, epa_type, state, state_type, expl_id, macroexpl_id, sector_id, sector_name, macrosector_id, sector_type, presszone_id, preszone_name, presszone_type, presszone_head, dma_id, dma_name, dma_type, macrodma_id, dqa_id, dqa_name, dqa_type, macrodqa_id, arc_id, parent_id, annotation, observ, "comment", staticpressure, soilcat_id, function_type, category_type, fluid_type, location_type, workcat_id, workcat_id_end, workcat_id_plan, builtdate, enddate, buildercat_id, ownercat_id, muni_id, postcode, district_id, streetname, postnumber, postcomplement, streetname2, postnumber2, postcomplement2, region_id, province_id, descript, svg, rotation, link, verified, undelete, "label", label_x, label_y, label_rotation, publish, inventory, hemisphere, num_value, adate, adescript, accessibility, dma_style, presszone_style, asset_id, om_state, conserv_state, access_type, placement_type, expl_id2, is_operative, brand_id, model_id, serial_number, minsector_id, macrominsector_id, demand_max, demand_min, demand_avg, press_max, press_min, press_avg, head_max, head_min, head_avg, quality_max, quality_min, quality_avg, tstamp, insert_user, lastupdate, lastupdate_user, the_geom, inp_type, closed, broken, buried, irrigation_indicator, pression_entry, pression_exit, depth_valveshaft, regulator_situation, regulator_location, regulator_observ, lin_meters, exit_type, exit_code, drive_type, cat_valve2, ordinarystatus, shutter, brand2, model2, valve_type, to_arc, active, airvalve_param_1, airvalve_param_2) +VALUES('-901', '-901', 32.8100, NULL, 'AIR_VALVE', 'VALVE', 'AIR VALVE DN50', 'FD', '16', '50', NULL, 'UNDEFINED', 1, 2, 2, 1, 5, 'sector2-1d', 2, 'DISTRIBUTION', '3', 'pzone1-1d', NULL, NULL, 3, 'dma2-1d', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'soil1', NULL, NULL, NULL, NULL, 'work1', NULL, NULL, '2024-08-22', NULL, NULL, 'owner1', 2, NULL, 1, NULL, NULL, NULL, NULL, NULL, NULL, 1, 1, NULL, NULL, NULL, '', '1', NULL, NULL, NULL, NULL, NULL, true, true, NULL, NULL, NULL, NULL, NULL, '204,235,197', '204,235,197', NULL, NULL, NULL, NULL, NULL, NULL, true, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '2024-08-22 17:00:02.000', 'postgres', '2024-08-22 17:00:02.000', 'postgres', 'SRID=25831;POINT (418473.00472849904 4577983.379842222)'::public.geometry, NULL, false, false, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, false, NULL, NULL); + +INSERT INTO ve_arc_pipe +(arc_id, code, node_1, nodetype_1, elevation1, depth1, staticpress1, node_2, nodetype_2, staticpress2, elevation2, depth2, "depth", arccat_id, arc_type, sys_type, cat_matcat_id, cat_pnom, cat_dnom, cat_dint, epa_type, state, state_type, expl_id, macroexpl_id, sector_id, sector_name, macrosector_id, sector_type, presszone_id, preszone_name, presszone_type, presszone_head, dma_id, dma_name, dma_type, macrodma_id, dqa_id, dqa_name, dqa_type, macrodqa_id, annotation, observ, "comment", gis_length, custom_length, soilcat_id, function_type, category_type, fluid_type, location_type, workcat_id, workcat_id_end, workcat_id_plan, buildercat_id, builtdate, enddate, ownercat_id, muni_id, postcode, district_id, streetname, postnumber, postcomplement, streetname2, postnumber2, postcomplement2, region_id, province_id, descript, link, verified, undelete, "label", label_x, label_y, label_rotation, publish, inventory, num_value, adate, adescript, dma_style, presszone_style, asset_id, pavcat_id, om_state, conserv_state, parent_id, expl_id2, is_operative, brand_id, model_id, serial_number, minsector_id, macrominsector_id, flow_max, flow_min, flow_avg, vel_max, vel_min, vel_avg, tstamp, insert_user, lastupdate, lastupdate_user, the_geom, inp_type, pipe_param_1) +VALUES('-901', '-901', '-902', 'AIR_VALVE', 32.8100, NULL, NULL, '-901', 'AIR_VALVE', NULL, 32.8100, NULL, NULL, 'PVC63-PN10', 'PIPE', 'PIPE', 'PVC', '10', '63', 56.70000, 'PIPE', 1, 2, 2, 1, 5, 'sector2-1d', 2, 'DISTRIBUTION', '3', 'pzone1-1d', NULL, NULL, 3, 'dma2-1d', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1.22, NULL, 'soil1', NULL, NULL, NULL, NULL, 'work1', NULL, NULL, NULL, '2024-08-22', NULL, 'owner1', 2, NULL, 1, NULL, NULL, NULL, NULL, NULL, NULL, 1, 1, NULL, '', '1', NULL, NULL, NULL, NULL, NULL, true, true, NULL, NULL, NULL, '204,235,197', '204,235,197', NULL, 'Asphalt', NULL, NULL, NULL, NULL, true, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '2024-08-22 17:05:32.000', 'postgres', '2024-08-22 17:05:32.000', 'postgres', 'SRID=25831;LINESTRING (418473.00472849904 4577983.379842222, 418474.19510507485 4577983.667174499)'::public.geometry, 'PIPE', NULL); +SELECT is((SELECT count(*)::integer FROM ve_arc_pipe WHERE code = '-901'), 1, 'INSERT: ve_arc_pipe "-901" was inserted'); +SELECT is((SELECT count(*)::integer FROM arc WHERE code = '-901'), 1, 'INSERT: arc:pipe "-901" was inserted'); + +UPDATE ve_arc_pipe SET custom_length = 1.0000 WHERE code = '-901'; +SELECT is((SELECT custom_length FROM ve_arc_pipe WHERE code = '-901'), 1.0000, 'UPDATE: ve_arc_pipe "-901" was updated'); +SELECT is((SELECT custom_length FROM arc WHERE code = '-901'), 1.0000, 'UPDATE: arc:pipe "-901" was updated'); + +DELETE FROM ve_arc_pipe WHERE code = '-901'; +SELECT is((SELECT count(*)::integer FROM ve_arc_pipe WHERE code = '-901'), 0, 'DELETE: ve_arc_pipe "-901" was deleted'); +SELECT is((SELECT count(*)::integer FROM arc WHERE code = '-901'), 0, 'DELETE: arc:pipe "-901" was deleted'); + +-- arc -> varc +-- initial data is prepared before proceeding with the test +INSERT INTO ve_node_check_valve +(node_id, code, elevation, "depth", node_type, sys_type, nodecat_id, cat_matcat_id, cat_pnom, cat_dnom, cat_dint, epa_type, state, state_type, expl_id, macroexpl_id, sector_id, sector_name, macrosector_id, sector_type, presszone_id, preszone_name, presszone_type, presszone_head, dma_id, dma_name, dma_type, macrodma_id, dqa_id, dqa_name, dqa_type, macrodqa_id, arc_id, parent_id, annotation, observ, "comment", staticpressure, soilcat_id, function_type, category_type, fluid_type, location_type, workcat_id, workcat_id_end, workcat_id_plan, builtdate, enddate, buildercat_id, ownercat_id, muni_id, postcode, district_id, streetname, postnumber, postcomplement, streetname2, postnumber2, postcomplement2, region_id, province_id, descript, svg, rotation, link, verified, undelete, "label", label_x, label_y, label_rotation, publish, inventory, hemisphere, num_value, adate, adescript, accessibility, dma_style, presszone_style, asset_id, om_state, conserv_state, access_type, placement_type, expl_id2, is_operative, brand_id, model_id, serial_number, minsector_id, macrominsector_id, demand_max, demand_min, demand_avg, press_max, press_min, press_avg, head_max, head_min, head_avg, quality_max, quality_min, quality_avg, tstamp, insert_user, lastupdate, lastupdate_user, the_geom, inp_type, closed, broken, buried, irrigation_indicator, pression_entry, pression_exit, depth_valveshaft, regulator_situation, regulator_location, regulator_observ, lin_meters, exit_type, exit_code, drive_type, cat_valve2, ordinarystatus, shutter, brand2, model2, valve_type, to_arc, active, checkvalve_param_1, checkvalve_param_2) +VALUES('-903', '-903', 32.8100, NULL, 'CHECK_VALVE', 'VALVE', 'CHK-VALVE63-PN16', 'FD', '16', '63', 65.00000, 'SHORTPIPE', 1, 2, 2, 1, 5, 'sector2-1d', 2, 'DISTRIBUTION', '3', 'pzone1-1d', NULL, NULL, 3, 'dma2-1d', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'soil1', NULL, NULL, NULL, NULL, 'work1', NULL, NULL, '2024-08-22', NULL, NULL, 'owner1', 2, NULL, 1, NULL, NULL, NULL, NULL, NULL, NULL, 1, 1, NULL, NULL, NULL, '', '1', NULL, NULL, NULL, NULL, NULL, true, true, NULL, NULL, NULL, NULL, NULL, '204,235,197', '204,235,197', NULL, NULL, NULL, NULL, NULL, NULL, true, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '2024-08-22 17:01:53.000', 'postgres', '2024-08-22 17:01:53.000', 'postgres', 'SRID=25831;POINT (418473.1278709034 4577982.640987795)'::public.geometry, 'SHORTPIPE', false, false, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, false, NULL, NULL); +INSERT INTO ve_node_check_valve +(node_id, code, elevation, "depth", node_type, sys_type, nodecat_id, cat_matcat_id, cat_pnom, cat_dnom, cat_dint, epa_type, state, state_type, expl_id, macroexpl_id, sector_id, sector_name, macrosector_id, sector_type, presszone_id, preszone_name, presszone_type, presszone_head, dma_id, dma_name, dma_type, macrodma_id, dqa_id, dqa_name, dqa_type, macrodqa_id, arc_id, parent_id, annotation, observ, "comment", staticpressure, soilcat_id, function_type, category_type, fluid_type, location_type, workcat_id, workcat_id_end, workcat_id_plan, builtdate, enddate, buildercat_id, ownercat_id, muni_id, postcode, district_id, streetname, postnumber, postcomplement, streetname2, postnumber2, postcomplement2, region_id, province_id, descript, svg, rotation, link, verified, undelete, "label", label_x, label_y, label_rotation, publish, inventory, hemisphere, num_value, adate, adescript, accessibility, dma_style, presszone_style, asset_id, om_state, conserv_state, access_type, placement_type, expl_id2, is_operative, brand_id, model_id, serial_number, minsector_id, macrominsector_id, demand_max, demand_min, demand_avg, press_max, press_min, press_avg, head_max, head_min, head_avg, quality_max, quality_min, quality_avg, tstamp, insert_user, lastupdate, lastupdate_user, the_geom, inp_type, closed, broken, buried, irrigation_indicator, pression_entry, pression_exit, depth_valveshaft, regulator_situation, regulator_location, regulator_observ, lin_meters, exit_type, exit_code, drive_type, cat_valve2, ordinarystatus, shutter, brand2, model2, valve_type, to_arc, active, checkvalve_param_1, checkvalve_param_2) +VALUES('-904', '-904', 32.8100, NULL, 'CHECK_VALVE', 'VALVE', 'CHK-VALVE63-PN16', 'FD', '16', '63', 65.00000, 'SHORTPIPE', 1, 2, 2, 1, 5, 'sector2-1d', 2, 'DISTRIBUTION', '3', 'pzone1-1d', NULL, NULL, 3, 'dma2-1d', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'soil1', NULL, NULL, NULL, NULL, 'work1', NULL, NULL, '2024-08-22', NULL, NULL, 'owner1', 2, NULL, 1, NULL, NULL, NULL, NULL, NULL, NULL, 1, 1, NULL, NULL, NULL, '', '1', NULL, NULL, NULL, NULL, NULL, true, true, NULL, NULL, NULL, NULL, NULL, '204,235,197', '204,235,197', NULL, NULL, NULL, NULL, NULL, NULL, true, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '2024-08-22 17:02:03.000', 'postgres', '2024-08-22 17:02:03.000', 'postgres', 'SRID=25831;POINT (418474.44138988364 4577982.928320073)'::public.geometry, 'SHORTPIPE', false, false, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, false, NULL, NULL); + +INSERT INTO ve_arc_varc +(arc_id, code, node_1, nodetype_1, elevation1, depth1, staticpress1, node_2, nodetype_2, staticpress2, elevation2, depth2, "depth", arccat_id, arc_type, sys_type, cat_matcat_id, cat_pnom, cat_dnom, cat_dint, epa_type, state, state_type, expl_id, macroexpl_id, sector_id, sector_name, macrosector_id, sector_type, presszone_id, preszone_name, presszone_type, presszone_head, dma_id, dma_name, dma_type, macrodma_id, dqa_id, dqa_name, dqa_type, macrodqa_id, annotation, observ, "comment", gis_length, custom_length, soilcat_id, function_type, category_type, fluid_type, location_type, workcat_id, workcat_id_end, workcat_id_plan, buildercat_id, builtdate, enddate, ownercat_id, muni_id, postcode, district_id, streetname, postnumber, postcomplement, streetname2, postnumber2, postcomplement2, region_id, province_id, descript, link, verified, undelete, "label", label_x, label_y, label_rotation, publish, inventory, num_value, adate, adescript, dma_style, presszone_style, asset_id, pavcat_id, om_state, conserv_state, parent_id, expl_id2, is_operative, brand_id, model_id, serial_number, minsector_id, macrominsector_id, flow_max, flow_min, flow_avg, vel_max, vel_min, vel_avg, tstamp, insert_user, lastupdate, lastupdate_user, the_geom, inp_type) +VALUES('-902', '-902', '-903', 'CHECK_VALVE', 32.8100, NULL, NULL, '-904', 'CHECK_VALVE', NULL, 32.8100, NULL, NULL, 'VIRTUAL', 'VARC', 'VARC', 'PE-HD', NULL, NULL, 999.00000, 'PIPE', 1, 2, 2, 1, 5, 'sector2-1d', 2, 'DISTRIBUTION', '3', 'pzone1-1d', NULL, NULL, 3, 'dma2-1d', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1.34, NULL, 'soil1', NULL, NULL, NULL, NULL, 'work1', NULL, NULL, NULL, '2024-08-22', NULL, 'owner1', 2, NULL, 1, NULL, NULL, NULL, NULL, NULL, NULL, 1, 1, NULL, '', '1', NULL, NULL, NULL, NULL, NULL, true, true, NULL, NULL, NULL, '204,235,197', '204,235,197', NULL, 'Asphalt', NULL, NULL, NULL, NULL, true, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '2024-08-22 17:05:48.000', 'postgres', '2024-08-22 17:05:48.000', 'postgres', 'SRID=25831;LINESTRING (418473.1278709034 4577982.640987795, 418474.44138988364 4577982.928320073)'::public.geometry, 'PIPE'); +SELECT is((SELECT count(*)::integer FROM ve_arc_varc WHERE code = '-902'), 1, 'INSERT: ve_arc_varc "-902" was inserted'); +SELECT is((SELECT count(*)::integer FROM arc WHERE code = '-902'), 1, 'INSERT: arc:varc "-902" was inserted'); + +UPDATE ve_arc_varc SET custom_length = 1.0000 WHERE code = '-902'; +SELECT is((SELECT custom_length FROM ve_arc_varc WHERE code = '-902'), 1.0000, 'UPDATE: ve_arc_varc "-902" was updated'); +SELECT is((SELECT custom_length FROM arc WHERE code = '-902'), 1.0000, 'UPDATE: arc:varc "-902" was updated'); + +DELETE FROM ve_arc_varc WHERE code = '-902'; +SELECT is((SELECT count(*)::integer FROM ve_arc_varc WHERE code = '-902'), 0, 'DELETE: ve_arc_varc "-902" was deleted'); +SELECT is((SELECT count(*)::integer FROM arc WHERE code = '-902'), 0, 'DELETE: arc:varc "-902" was deleted'); + + +SELECT * FROM finish(); + +ROLLBACK;