Ejemplo n.º 1
0
  public void test01() throws Exception {
    List<ArchitecturalDrift> violations =
        this.validateSystem(
            "com.example.a.A519 cannot-useannotation com.example.b.B519"); // Define the constraint
                                                                           // to be validated

    assertEquals(
        1,
        violations
            .size()); // Check the number of violations (usually only one violation for constraint)
    ArchitecturalDrift ad = violations.get(0);

    assertEquals(
        DivergenceArchitecturalDrift.class,
        ad.getClass()); // Check the type of violation (divergence or absence)
    DivergenceArchitecturalDrift dad = (DivergenceArchitecturalDrift) ad;

    assertEquals(
        AnnotateFieldDependency.class,
        dad.getForbiddenDependency().getClass()); // Check the type of dependency
    AnnotateFieldDependency annotateFieldDependency =
        (AnnotateFieldDependency) dad.getForbiddenDependency();

    // Check each attribute of the violation
    assertEquals("com.example.a.A519", annotateFieldDependency.getClassNameA());
    assertEquals("com.example.b.B519", annotateFieldDependency.getClassNameB());
  }
Ejemplo n.º 2
0
  public void test01() throws Exception {
    List<ArchitecturalDrift> violations =
        this.validateSystem(
            "only com.example.c.C108 can-declare com.example.b.B108"); // Define the constraint to
                                                                       // be validated

    assertEquals(
        1,
        violations
            .size()); // Check the number of violations (usually only one violation for constraint)
    ArchitecturalDrift ad = violations.get(0);

    assertEquals(
        DivergenceArchitecturalDrift.class,
        ad.getClass()); // Check the type of violation (divergence or absence)
    DivergenceArchitecturalDrift dad = (DivergenceArchitecturalDrift) ad;

    assertEquals(
        DeclareFieldDependency.class,
        dad.getForbiddenDependency().getClass()); // Check the type of dependency
    DeclareFieldDependency declareFieldDependency =
        (DeclareFieldDependency) dad.getForbiddenDependency();

    // Check each attribute of the violation
    assertEquals("com.example.a.A108", declareFieldDependency.getClassNameA());
    assertEquals("com.example.b.B108", declareFieldDependency.getClassNameB());

    assertEquals("fieldA", declareFieldDependency.getFieldName());
  }
Ejemplo n.º 3
0
  public void test01() throws Exception {
    List<ArchitecturalDrift> violations =
        this.validateSystem(
            "com.example.a.A231 must-create com.example.b.B231"); // Define the constraint to be
    // validated

    assertEquals(
        1,
        violations
            .size()); // Check the number of violations (usually only one violation for constraint)
    ArchitecturalDrift ad = violations.get(0);

    assertEquals(
        AbsenceArchitecturalDrift.class,
        ad.getClass()); // Check the type of violation (divergence or absence)
    AbsenceArchitecturalDrift aad = (AbsenceArchitecturalDrift) ad;

    assertEquals(
        CreateDependency.class,
        aad.getViolatedConstraint()
            .getConstraint()
            .getDependencyType()
            .getDependencyClass()); // Check the type of dependency

    // Check each attribute of the violation
    assertEquals("com.example.a.A231", aad.getClassNameA());
    assertEquals("com.example.b.B231", aad.getModuleNameB());
  }