import 'http://www.etsi.org/spec/TDL/1.4.1'
import 'http://www.etsi.org/spec/TDL/1.3.1/structured'

package structuredobjectives

context PICSReference
  -- Combining Multiple 'PICSReference's 
  inv MultiplePICS ('A \'Comment\' with body containing an \'and\' or \'or\' shall be attached to the \'PICSReference\' as a Boolean operand if there are two or more \'PICSReference\'s and it is not the first \'PICSReference\'.' + self.toString()):
    self.getTestObjective().picsReference->size() < 2 
      or self.getTestObjective().picsReference->forAll(p | 
        self.getTestObjective().picsReference->at(0) = p
        or (not p.comment->isEmpty()
            and (p.comment->first()._'body' = 'and'
                or p.comment->first()._'body' = 'or')))
  



context RepeatedEventSequence
  -- Either 'repetitions', or 'interval' or neither shall be specified
  inv RepetitionOrInterval ('At most one of the optional properties \'repetitions\' or \'interval\' shall be defined.' + self.toString()):
        self.repetitions.oclIsUndefined() or self.interval.oclIsUndefined()
  

  -- The 'repetitions' 'Value' shall be countable and positive
  inv RepetitionCount ('The expression assigned to the \'repetitions\' property shall evaluate to a positive and countable \'Value\'.' + self.toString()):
        true --This constraint cannot be expressed in OCL
  

  -- The 'interval' 'Value' shall be countable and positive
  inv RepetitionInterval ('The expression assigned to the \'repetitions\' property shall evaluate to a positive and countable \'Value\'' + self.toString()):
        true --This constraint cannot be expressed in OCL
  



--context EventOccurrence
--  -- Combining Multiple 'EventOccurrence's
--  inv MultipleEventOccurrences ('A \'Comment\' with body containing an \'and\' or \'or\' shall be attached to the \'EventOccurrence\' as an operand if there are two or more \'EventOccurrence\'s and it is not the first \'EventOccurrence\'.' + self.toString()):
--    self.container().oclIsTypeOf(EventSpecificationTemplate)
--      or self.container().events->size() < 2 
--      or self.container().events->forAll(o | 
--      self.container().events->at(0) = o
--      or (not o.comment->isEmpty()
--      and (o.comment->first()._'body' = 'and'
--      or o.comment->first()._'body' = 'or')))
  



context EntityReference
  -- An 'Entity' or a 'ComponentInstance' shall be referenced.
  inv EntityOrComponentInstance ('There shall be a reference to an \'Entity\' or a \'ComponentInstance\' but not both.' + self.toString()):
    (not self.entity.oclIsUndefined() and self.component.oclIsUndefined())
      or (self.entity.oclIsUndefined() and not self.component.oclIsUndefined())
  



context Content
  -- No nested 'Content's if 'Value' is provided 
  inv ContentOrValue ('Either nested \'Content\'s or \'Value\' may be specified within \'Content\', but not both.' + self.toString()):
        self.content->isEmpty() or self.value.oclIsUndefined()
  



context LiteralValueReference
  -- Referenced 'LiteralValue' visibility
  inv VisibleValue ('Only \'LiteralValue\'s defined within previous \'EventOccurrence\'s of the containing \'StructuredTestObjective\' may be referenced.' + self.toString()):
    self.getTestObjective().contains(self.content) 
      and self.getTestObjective().indexOf(self.content) < self.getTestObjective().indexOf(self)
  



context ContentReference
  -- Referenced 'Content' visibility
  inv VisibleContent ('Only \'Content\' defined within previous \'EventOccurrence\'s of the containing \'StructuredTestObjective\' may be referenced.' + self.toString()):
    self.getTestObjective().contains(self.content) 
      and self.getTestObjective().indexOf(self.content) < self.getTestObjective().indexOf(self)
  



context DataReference
  -- 'DataUse' restrictions within 'DataReference'
  inv DataReferenceContents ('Only \'StaticDataUse\' may be used directly or indirectly in \'ParameterBinding\'s of the \'StaticDataUse\' within a \'DataReference\'.' + self.toString()):
    self.content.oclIsTypeOf(StaticDataUse)
          and self.content.argument->forAll(a | a.dataUse.oclIsKindOf(StaticDataUse))
          and self.content.argument->closure(a | 
          a.dataUse.argument)->forAll(a|a.dataUse.oclIsKindOf(StaticDataUse))
  

  -- No 'reduction' within 'DataReference'
  inv DataReferenceReduction ('The \'reduction\' property of \'StaticDataUse\' inherited from \'DataUse\' shall not be used within a \'DataReference\'.' + self.toString()):
    self.content.reduction->isEmpty()
  



context EventTemplateOccurrence
  -- 'EntityReference' of referenced 'EventSpecificationTemplate'
  inv EntityTemplateOccurrenceConsistency ('If \'EntityBinding\'s are provided, the \'Entity\'s or \'ComponentInstance\'s referenced in the \'templateEntity\' properties shall also be referenced by one of the \'EntityReferences\' in the \'EventOccurrenceSpecification\' of the \'EventSpecificationTemplate\' referenced in the \'EventTemplateOccurrence\'.' + self.toString()):
        self.entityBinding->forAll(b | 
              (not b.templateEntity.entity.oclIsUndefined() 
           and (b.templateEntity.entity = 
                    self.eventTemplate.eventSpecification.entityReference.entity))
           or (not b.templateEntity.component.oclIsUndefined() 
           and (b.templateEntity.component = 
                    self.eventTemplate.eventSpecification.entityReference.component)
           or self.eventTemplate.eventSpecification.oppositeEntityReference->exists(e | 
                  (not b.templateEntity.entity.oclIsUndefined() 
               and (e.entity = b.templateEntity.entity))
               or (not b.templateEntity.component.oclIsUndefined() 
               and (e.component = b.templateEntity.component)))))
  



context VariantBinding
  -- Referenced 'Value' of 'VariantBinding'
  inv VariantBindingValues ('If the \'value\' property references a \'LiteralValue\' or \'Content\' element, the referenced element shall be contained in the \'StructuredTestObjective\' containing the \'VariantBinding\'.' + self.toString()):
        self.value.oclIsTypeOf(LiteralValueReference) implies
          self.value.oclAsType(LiteralValueReference).content.getTestObjective() = self.getTestObjective()
          and 
          self.value.oclIsKindOf(ContentReference) implies
          self.value.oclAsType(ContentReference).content.getTestObjective() = self.getTestObjective()
  




endpackage
