]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/sql/Pg/t/marc_merge.pg
LP2061136 - Stamping 1405 DB upgrade script
[Evergreen.git] / Open-ILS / src / sql / Pg / t / marc_merge.pg
1 BEGIN;
2
3 SELECT plan(4);
4
5 CREATE OR REPLACE FUNCTION test_marc_merges() RETURNS SETOF TEXT AS $func$
6 DECLARE
7     incoming_marc TEXT;
8     existing_marc TEXT;
9     merge_profile_1 BIGINT;
10     merge_profile_2 BIGINT;
11     merge_profile_3 BIGINT;
12     merge_profile_4 BIGINT;
13 BEGIN
14     incoming_marc := $$<record    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd"    xmlns="http://www.loc.gov/MARC21/slim">
15   <leader>00531nam a2200157 a 4500</leader>
16   <controlfield tag="005">20080729170300.0</controlfield>
17   <controlfield tag="008">      t19981999enka              0 eng  </controlfield>
18   <datafield tag="245" ind1="1" ind2="4">
19     <subfield code="a">merge-example-incoming</subfield>
20   </datafield>
21   <datafield tag="505" ind1="1" ind2="4">
22     <subfield code="a">contents-notes-incoming</subfield>
23   </datafield>
24   <datafield tag="856" ind1="1" ind2="4">
25     <subfield code="u">https://example.org/page-incoming</subfield>
26   </datafield>
27 </record>$$;
28     existing_marc := $$<record    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd"    xmlns="http://www.loc.gov/MARC21/slim">
29   <leader>00531nam a2200157 a 4500</leader>
30   <controlfield tag="005">20080729170300.0</controlfield>
31   <controlfield tag="008">      t19981999enka              0 eng  </controlfield>
32   <datafield tag="245" ind1="1" ind2="4">
33     <subfield code="a">merge-example-existing</subfield>
34   </datafield>
35   <datafield tag="505" ind1="1" ind2="4">
36     <subfield code="a">contents-notes-existing</subfield>
37   </datafield>
38   <datafield tag="856" ind1="1" ind2="4">
39     <subfield code="u">https://example.org/page-existing</subfield>
40   </datafield>
41 </record>$$;
42
43     INSERT INTO vandelay.merge_profile (owner, name, add_spec, replace_spec, strip_spec, preserve_spec)
44         VALUES (1, 'Test MP 1', '505', NULL, NULL, NULL);
45     SELECT CURRVAL('vandelay.merge_profile_id_seq') INTO merge_profile_1;
46     INSERT INTO vandelay.merge_profile (owner, name, add_spec, replace_spec, strip_spec, preserve_spec)
47         VALUES (1, 'Test MP 2', NULL, '505', NULL, NULL);
48     SELECT CURRVAL('vandelay.merge_profile_id_seq') INTO merge_profile_2;
49     INSERT INTO vandelay.merge_profile (owner, name, add_spec, replace_spec, strip_spec, preserve_spec)
50         VALUES (1, 'Test MP 3', NULL, NULL, NULL, '505');
51     SELECT CURRVAL('vandelay.merge_profile_id_seq') INTO merge_profile_3;
52     INSERT INTO vandelay.merge_profile (owner, name, add_spec, replace_spec, strip_spec, preserve_spec)
53         VALUES (1, 'Test MP 4', '856', '505', NULL, NULL);
54     SELECT CURRVAL('vandelay.merge_profile_id_seq') INTO merge_profile_4;
55
56     -- using evergreen.xml_pretty_print(textval::XML)::TEXT to normalize the
57     -- values we're comparing
58     RETURN NEXT is(evergreen.xml_pretty_print(vandelay.merge_record_xml_using_profile(incoming_marc, existing_marc, merge_profile_1)::XML)::TEXT, evergreen.xml_pretty_print($$<record    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd"    xmlns="http://www.loc.gov/MARC21/slim">
59   <leader>00531nam a2200157 a 4500</leader>
60   <controlfield tag="005">20080729170300.0</controlfield>
61   <controlfield tag="008">      t19981999enka              0 eng  </controlfield>
62   <datafield tag="245" ind1="1" ind2="4">
63     <subfield code="a">merge-example-existing</subfield>
64   </datafield>
65   <datafield tag="505" ind1="1" ind2="4">
66     <subfield code="a">contents-notes-incoming</subfield>
67   </datafield>
68   <datafield tag="505" ind1="1" ind2="4">
69     <subfield code="a">contents-notes-existing</subfield>
70   </datafield>
71   <datafield tag="856" ind1="1" ind2="4">
72     <subfield code="u">https://example.org/page-existing</subfield>
73   </datafield>
74 </record>$$::XML)::TEXT, 'merge with add 505 rule');
75
76     RETURN NEXT is(evergreen.xml_pretty_print(vandelay.merge_record_xml_using_profile(incoming_marc, existing_marc, merge_profile_2)::XML)::TEXT, evergreen.xml_pretty_print($$<record    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd"    xmlns="http://www.loc.gov/MARC21/slim">
77   <leader>00531nam a2200157 a 4500</leader>
78   <controlfield tag="005">20080729170300.0</controlfield>
79   <controlfield tag="008">      t19981999enka              0 eng  </controlfield>
80   <datafield tag="245" ind1="1" ind2="4">
81     <subfield code="a">merge-example-existing</subfield>
82   </datafield>
83   <datafield tag="505" ind1="1" ind2="4">
84     <subfield code="a">contents-notes-incoming</subfield>
85   </datafield>
86   <datafield tag="856" ind1="1" ind2="4">
87     <subfield code="u">https://example.org/page-existing</subfield>
88   </datafield>
89 </record>$$::XML)::TEXT, 'merge with replace 505 rule');
90
91     RETURN NEXT is(evergreen.xml_pretty_print(vandelay.merge_record_xml_using_profile(incoming_marc, existing_marc, merge_profile_3)::XML)::TEXT, evergreen.xml_pretty_print($$<record    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd"    xmlns="http://www.loc.gov/MARC21/slim">
92   <leader>00531nam a2200157 a 4500</leader>
93   <controlfield tag="005">20080729170300.0</controlfield>
94   <controlfield tag="008">      t19981999enka              0 eng  </controlfield>
95   <datafield tag="245" ind1="1" ind2="4">
96     <subfield code="a">merge-example-incoming</subfield>
97   </datafield>
98   <datafield tag="505" ind1="1" ind2="4">
99     <subfield code="a">contents-notes-existing</subfield>
100   </datafield>
101   <datafield tag="856" ind1="1" ind2="4">
102     <subfield code="u">https://example.org/page-incoming</subfield>
103   </datafield>
104 </record>$$::XML)::TEXT, 'merge with preserve 505 rule');
105
106     RETURN NEXT is(evergreen.xml_pretty_print(vandelay.merge_record_xml_using_profile(incoming_marc, existing_marc, merge_profile_4)::XML)::TEXT, evergreen.xml_pretty_print($$<record    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd"    xmlns="http://www.loc.gov/MARC21/slim">
107   <leader>00531nam a2200157 a 4500</leader>
108   <controlfield tag="005">20080729170300.0</controlfield>
109   <controlfield tag="008">      t19981999enka              0 eng  </controlfield>
110   <datafield tag="245" ind1="1" ind2="4">
111     <subfield code="a">merge-example-existing</subfield>
112   </datafield>
113   <datafield tag="505" ind1="1" ind2="4">
114     <subfield code="a">contents-notes-incoming</subfield>
115   </datafield>
116   <datafield tag="856" ind1="1" ind2="4">
117     <subfield code="u">https://example.org/page-incoming</subfield>
118   </datafield>
119   <datafield tag="856" ind1="1" ind2="4">
120     <subfield code="u">https://example.org/page-existing</subfield>
121   </datafield>
122 </record>$$::XML)::TEXT, 'merge with add 856 and replace 505 rule');
123 END;
124 $func$ LANGUAGE plpgsql;
125
126 SELECT * FROM test_marc_merges();
127
128 ROLLBACK;