Skip to content

4. Containercreationalgorithm

Andreas Schörk edited this page Nov 3, 2018 · 9 revisions

Try to achieve:

  • Testclass becomes managed bean in the container
    • must be included into beanClasses of the one BeanDeploymentArchive
  • Producers in the Testclass and helping classes should easily replace Producers or Beans from other site
    • Way to identify helping classes which should be able to override mocked classes by producers or by themselves? -> Alternative?
      • --> currently needs Annotation and! Activation by @ActivatedAlternatives or @ProducesAlternative except @Mock in Testclass
      • as @Mock replaces automatically if in Testclass, perhaps we need a annotation showing that mocks and producers of the annotated class should have prio in case of ambiguity.
    • to avoid analyzing of classes which are replaced by Alternatives these must not be included in beanClasses of the one BeanDeploymentArchive
  • Classes which are to be tested should be easily configured to be added to the container, or possibly found automatically.
    • Finding by matching the class (and qualifier) of the inject to existing classes or subclasses of managed beans or producers in @AdditionalPackages or @AdditionalClasspaths
    • @AdditionalClasses should explicitly define class to be added.
  • Helping classes for classes to be tested which are irrelevant should easily be mocked automatically
  • Everything the algorithm does automatically must be very transparent and understandable
    • Create a clear report showing where decision where not explicitly made by the user, but implicitly by automatic resolving.
  • Relevant helping classes for classes which are to be tested should easily be replaced so that testcases can bring these mocks to simulate behaviour.

Annotations at Testclasses

  • @TestClasses classes to be created, the classes themselves, producers and mocks have priority.
  • @TestPackages classes to be created, the classes themselves, producers and mocks have priority.
  • @TestClassPath classes to be created, the classes themselves, producers and mocks have priority.
  • @SuTClasses classes explicitly to add to beanClasses
  • @SuTPackages classes may implicitly added to beanClasses if they themselves help or producers in these classes help.
  • @SuTClasspath classes may implicitly added to beanClasses if they themselves help or producers in these classes help.
  • @ActivatedAlternatives classes to be added to enabledAlternatives
  • @ExcludedClasses classes removed from beanClasses before container creation

Find initial set of classes, activatedAlternatives, enabledAlternativeStereoTyoes used to start the Standalone-Weld-Container

Start of algorithm

Initial set of Classes IC

  • find explicitly to add classes ADD_EXPL (including their explicitly to add classes)
  • find managed beans MB in IC + ADD_EXPL
  • find injections IMB in MB
  • find produces PMB in MB

Result:

  • Injections not produced --> I_EMPTY
  • Injections ambiguously produced --> Error
  • find optionally to add classes ADD_OPTIONAL

if I_EMPTY empty: stop

Given

  • RC resolved managed classes
  • PRC producers in RC
  • D_ADDED directly to add classes
  • I_ADDED indirectly to add classes
  • SUPER super classes not yet in RC
  • UC an unresolved set of classes

Then

  • Identify Set of Managed Beans MB in UC --> This are to be created, assume all producer can be used, all these classes can be used
  • Find Producers PMB in MB
  • Find Injects INJ_MB in MB
  • Fill INJ_MB by RC, MB, PRC, PMB
    • ambiguus --> Error --> existing classes and producers should fill inject without extra prios
    • not filled yet: _EMPTYI_MB
  • Identify Not fillable Injects EMPTYI in INJ_MB
  • Identify Injects AMBIG_INJ in INJ_MB filled by more than one
  • Identify Set of Candidates to Add
    • Directly Added Elements D_ADDED_MB by @Additional* - Annotation with Producers P_D_ADDED_MB
    • Implicitly added Elements I_ADDED_MB by @AdditionalPackages, @AdditionalClasspath - Annotation with Producers P_I_ADDED_MB
    • Superclasses which could be managed beans SCMB in MB with Producers PSCMB
    • Elements EMPTYIMB of EMPTYI which can be managed Beans (not interfaces, not abstract)
  • For each I in EMPTYI
    • Find candidates to fill
      • if there is exactly one class in, which would fill add this to NEW_IC
      • if there is more than one
        • prefer D_ADDED_MB over I_ADDED_MB over SCMB over EMPTYIMB
        • if not unique producing yet --> Break