<commit_before># encoding: utf-8
require_relative 'spec_helper'
require 'rspec/matchers'
require 'equivalent-xml'
require 'libis/tools/mets_file'
require 'libis/tools/xml_document'

describe 'METS File' do

  before(:all) do
    ::Libis::Tools::Config << {appname: 'LIBIS Default'}
  end

  subject(:mets_file) { ::Libis::Tools::MetsFile.new }

  context 'without data' do

    let(:skeleton) {
      ::Libis::Tools::XmlDocument.build do |xml|
        # noinspection RubyResolve
        xml[:mets].mets 'xmlns:mets' => 'http://www.loc.gov/METS/' do
          xml[:mets].amdSec 'ID' => 'ie-amd'
          xml[:mets].fileSec
        end
      end.document
    }

    it 'generates skeleton XML' do
      expect(mets_file.xml_doc.root).to be_equivalent_to skeleton.root
    end

  end

  context 'with IE AMD' do

    let(:dc_record) {
      record = Libis::Tools::Metadata::DublinCoreRecord.new
      record.title = 'Title'
      record.author = 'Author'
      record.subject = 'Subject'
      record
    }

    let(:marc_record) {
      Libis::Tools::XmlDocument.parse <<-STR
        <?xml version="1.0" encoding="UTF-8"?>
        <record xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd"
          xmlns="http://www.loc.gov/MARC21/slim" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
          <leader>abcdefghiljklmnopqrstuvwxyz</leader>
          <controlfield tag="001">1234567890</controlfield>
          <datafield tag="010" ind1="a" ind2="b">
            <subfield code="a">abc</subfield>
            <subfield code="b">xyz</subfield>
          </datafield>
        </record>
        STR
    }

    let(:src_record) {
      Libis::Tools::XmlDocument.parse <<-STR
        <my_description xmlns="http://www.libis.be/description/">
          <title>Title</title>
          <importance>high</importance>
          <location>here</location>
        </my_description><commit_msg>Removed dependency on Metadata classes from tests.<commit_after># encoding: utf-8
require_relative 'spec_helper'
require 'rspec/matchers'
require 'equivalent-xml'
require 'libis/tools/mets_file'
require 'libis/tools/xml_document'

describe 'METS File' do

  before(:all) do
    ::Libis::Tools::Config << {appname: 'LIBIS Default'}
  end

  subject(:mets_file) { ::Libis::Tools::MetsFile.new }

  context 'without data' do

    let(:skeleton) {
      ::Libis::Tools::XmlDocument.build do |xml|
        # noinspection RubyResolve
        xml[:mets].mets 'xmlns:mets' => 'http://www.loc.gov/METS/' do
          xml[:mets].amdSec 'ID' => 'ie-amd'
          xml[:mets].fileSec
        end
      end.document
    }

    it 'generates skeleton XML' do
      expect(mets_file.xml_doc.root).to be_equivalent_to skeleton.root
    end

  end

  context 'with IE AMD' do

    let(:dc_record) {
      Libis::Tools::XmlDocument.parse <<-STR
        <?xml version="1.0" encoding="UTF-8"?>
        <record xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xmlns:dc="http://purl.org/dc/elements/1.1/"
                xmlns:dcterms="http://purl.org/dc/terms/">
          <dc:title>Title</dc:title>
          <dc:author>Author</dc:author>
          <dc:subject>Subject</dc:subject>
        </record>
      STR
    }

    let(:marc_record) {
      Libis::Tools::XmlDocument.parse <<-STR
        <?xml version="1.0" encoding="UTF-8"?>
        <record xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd"
          xmlns="http://www.loc.gov/MARC21/slim" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
          <leader>abcdefghiljklmnopqrstuvwxyz</leader>
          <controlfield tag="001">1234567890</controlfield>
          <datafield tag="010" ind1="a" ind2="b">
            <subfield code="a">abc</subfield>
            <subfield code="b">xyz</subfield>
          </datafield>
        </record>
        STR
    }

    let(:src_record) {
      Libis::Tools::XmlDocument.parse <<-STR
        <my_description xmlns="http://www.libis.be/description/">
          <title>Title</title>
          <importance>high</importance>
          <location>here</location>
        </my_description>
{'fraction_non_alphanumeric': 0.15610104861773116, 'fraction_numerical': 0.01811248808388942, 'mean_word_length': 2.68804920913884, 'pattern_counts': {'":': 0, '<': 68, '<?xml version=': 3, '>': 58, 'https://': 0, 'lorem ipsum': 0, 'www.': 13, 'xml': 30}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7449985', 'n_tokens_mistral': 1504, 'n_tokens_neox': 1405, 'n_words': 220}