Class: Ea::Qea::Verification::DocumentVerifier

Inherits:
Object
  • Object
show all
Defined in:
lib/ea/qea/verification/document_verifier.rb

Overview

Main orchestrator for document verification Verifies that QEA-parsed documents contain at least as much information as XMI-parsed equivalents

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDocumentVerifier

Returns a new instance of DocumentVerifier.



12
13
14
15
16
17
# File 'lib/ea/qea/verification/document_verifier.rb', line 12

def initialize
  @normalizer = DocumentNormalizer.new
  @matcher = StructureMatcher.new
  @comparator = ElementComparator.new
  @result = ComparisonResult.new
end

Instance Attribute Details

#comparatorObject (readonly)

Returns the value of attribute comparator.



10
11
12
# File 'lib/ea/qea/verification/document_verifier.rb', line 10

def comparator
  @comparator
end

#matcherObject (readonly)

Returns the value of attribute matcher.



10
11
12
# File 'lib/ea/qea/verification/document_verifier.rb', line 10

def matcher
  @matcher
end

#normalizerObject (readonly)

Returns the value of attribute normalizer.



10
11
12
# File 'lib/ea/qea/verification/document_verifier.rb', line 10

def normalizer
  @normalizer
end

#resultObject (readonly)

Returns the value of attribute result.



10
11
12
# File 'lib/ea/qea/verification/document_verifier.rb', line 10

def result
  @result
end

Instance Method Details

#reset_cacheObject

Reset cached match results (call between verifications)



62
63
64
65
# File 'lib/ea/qea/verification/document_verifier.rb', line 62

def reset_cache
  @cached_class_matches = nil
  @cached_package_matches = nil
end

#verify(xmi_path, qea_path) ⇒ ComparisonResult

Main verification method

Parameters:

  • xmi_path (String)

    Path to XMI file

  • qea_path (String)

    Path to QEA file

Returns:



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/ea/qea/verification/document_verifier.rb', line 24

def verify(xmi_path, qea_path) # rubocop:disable Metrics/MethodLength
  # Parse documents
  xmi_doc = parse_xmi(xmi_path)
  qea_doc = parse_qea(qea_path)

  # Normalize documents
  xmi_normalized = normalizer.normalize(xmi_doc)
  qea_normalized = normalizer.normalize(qea_doc)

  # Perform verification
  verify_structure(xmi_normalized, qea_normalized)
  verify_names(xmi_normalized, qea_normalized)
  verify_properties(xmi_normalized, qea_normalized)
  verify_relationships(xmi_normalized, qea_normalized)

  result
end

#verify_documents(xmi_doc, qea_doc) ⇒ ComparisonResult

Verify document with already loaded documents

Parameters:

  • xmi_doc (Lutaml::Uml::Document)

    XMI document

  • qea_doc (Lutaml::Uml::Document)

    QEA document

Returns:



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/ea/qea/verification/document_verifier.rb', line 47

def verify_documents(xmi_doc, qea_doc)
  # Normalize documents
  xmi_normalized = normalizer.normalize(xmi_doc)
  qea_normalized = normalizer.normalize(qea_doc)

  # Perform verification
  verify_structure(xmi_normalized, qea_normalized)
  verify_names(xmi_normalized, qea_normalized)
  verify_properties(xmi_normalized, qea_normalized)
  verify_relationships(xmi_normalized, qea_normalized)

  result
end

#verify_names(xmi_doc, qea_doc) ⇒ void

This method returns an undefined value.

Verify element names are preserved

Parameters:

  • xmi_doc (Lutaml::Uml::Document)

    XMI document

  • qea_doc (Lutaml::Uml::Document)

    QEA document



120
121
122
123
124
# File 'lib/ea/qea/verification/document_verifier.rb', line 120

def verify_names(xmi_doc, qea_doc)
  # Package names verified in match_packages
  # Class names verified in match_classes
  # Additional verification could be added here
end

#verify_properties(xmi_doc, qea_doc) ⇒ void

This method returns an undefined value.

Verify properties of matched elements

Parameters:

  • xmi_doc (Lutaml::Uml::Document)

    XMI document

  • qea_doc (Lutaml::Uml::Document)

    QEA document



131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/ea/qea/verification/document_verifier.rb', line 131

def verify_properties(xmi_doc, qea_doc)
  # Verify class properties (reuse cached matches from verify_structure)
  class_matches = @cached_class_matches || matcher.match_classes(
    xmi_doc, qea_doc
  )
  verify_class_properties(class_matches[:matches])

  # Verify package properties (reuse cached matches from verify_structure)
  package_matches = @cached_package_matches || matcher.match_packages(
    xmi_doc, qea_doc
  )
  verify_package_properties(package_matches[:matches])
end

#verify_relationships(xmi_doc, qea_doc) ⇒ void

This method returns an undefined value.

Verify relationships (associations, generalizations)

Parameters:

  • xmi_doc (Lutaml::Uml::Document)

    XMI document

  • qea_doc (Lutaml::Uml::Document)

    QEA document



150
151
152
153
# File 'lib/ea/qea/verification/document_verifier.rb', line 150

def verify_relationships(xmi_doc, qea_doc)
  # Verify associations are preserved
  verify_associations(xmi_doc, qea_doc)
end

#verify_structure(xmi_doc, qea_doc) ⇒ void

This method returns an undefined value.

Compare element counts

Parameters:

  • xmi_doc (Lutaml::Uml::Document)

    XMI document

  • qea_doc (Lutaml::Uml::Document)

    QEA document



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/ea/qea/verification/document_verifier.rb', line 72

def verify_structure(xmi_doc, qea_doc) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
  # Compare package counts (cache for reuse in verify_properties)
  @cached_package_matches = matcher.match_packages(xmi_doc, qea_doc)
  result.add_matches(:packages, @cached_package_matches[:matches].size)
  result.add_xmi_only(:packages, @cached_package_matches[:xmi_only])
  result.add_qea_only(:packages, @cached_package_matches[:qea_only])

  # Compare class counts (cache for reuse in verify_properties)
  @cached_class_matches = matcher.match_classes(xmi_doc, qea_doc)
  result.add_matches(:classes, @cached_class_matches[:matches].size)
  result.add_xmi_only(:classes, @cached_class_matches[:xmi_only])
  result.add_qea_only(:classes, @cached_class_matches[:qea_only])

  # Compare enum counts
  xmi_enums = count_all_enums(xmi_doc)
  qea_enums = count_all_enums(qea_doc)
  if qea_enums < xmi_enums
    result.add_difference(
      "Enums: #{xmi_enums} (XMI) vs #{qea_enums} (QEA) - QEA has fewer",
    )
  end

  # Compare data type counts
  xmi_dt = count_all_data_types(xmi_doc)
  qea_dt = count_all_data_types(qea_doc)
  if qea_dt < xmi_dt
    result.add_difference(
      "Data types: #{xmi_dt} (XMI) vs #{qea_dt} (QEA) - QEA has fewer",
    )
  end

  # Compare association counts
  xmi_assocs = count_all_associations(xmi_doc)
  qea_assocs = count_all_associations(qea_doc)
  result.add_matches(:associations, [xmi_assocs, qea_assocs].min)
  if qea_assocs < xmi_assocs
    result.add_difference(
      "Associations: #{xmi_assocs} (XMI) " \
      "vs #{qea_assocs} (QEA) - QEA has fewer",
    )
  end
end