5 CREATE OR REPLACE FUNCTION test_marc_merges() RETURNS SETOF TEXT AS $func$
9 merge_profile_1 BIGINT;
10 merge_profile_2 BIGINT;
11 merge_profile_3 BIGINT;
12 merge_profile_4 BIGINT;
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>
21 <datafield tag="505" ind1="1" ind2="4">
22 <subfield code="a">contents-notes-incoming</subfield>
24 <datafield tag="856" ind1="1" ind2="4">
25 <subfield code="u">https://example.org/page-incoming</subfield>
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>
35 <datafield tag="505" ind1="1" ind2="4">
36 <subfield code="a">contents-notes-existing</subfield>
38 <datafield tag="856" ind1="1" ind2="4">
39 <subfield code="u">https://example.org/page-existing</subfield>
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;
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>
65 <datafield tag="505" ind1="1" ind2="4">
66 <subfield code="a">contents-notes-incoming</subfield>
68 <datafield tag="505" ind1="1" ind2="4">
69 <subfield code="a">contents-notes-existing</subfield>
71 <datafield tag="856" ind1="1" ind2="4">
72 <subfield code="u">https://example.org/page-existing</subfield>
74 </record>$$::XML)::TEXT, 'merge with add 505 rule');
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>
83 <datafield tag="505" ind1="1" ind2="4">
84 <subfield code="a">contents-notes-incoming</subfield>
86 <datafield tag="856" ind1="1" ind2="4">
87 <subfield code="u">https://example.org/page-existing</subfield>
89 </record>$$::XML)::TEXT, 'merge with replace 505 rule');
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>
98 <datafield tag="505" ind1="1" ind2="4">
99 <subfield code="a">contents-notes-existing</subfield>
101 <datafield tag="856" ind1="1" ind2="4">
102 <subfield code="u">https://example.org/page-incoming</subfield>
104 </record>$$::XML)::TEXT, 'merge with preserve 505 rule');
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>
113 <datafield tag="505" ind1="1" ind2="4">
114 <subfield code="a">contents-notes-incoming</subfield>
116 <datafield tag="856" ind1="1" ind2="4">
117 <subfield code="u">https://example.org/page-incoming</subfield>
119 <datafield tag="856" ind1="1" ind2="4">
120 <subfield code="u">https://example.org/page-existing</subfield>
122 </record>$$::XML)::TEXT, 'merge with add 856 and replace 505 rule');
124 $func$ LANGUAGE plpgsql;
126 SELECT * FROM test_marc_merges();