“Assert Your Architecture”

Architecture Rules Tutorial: 101

Written by MikeNereson

April 2nd, 2008 at 7:55 pm

Posted in Uncategorized

Tagged with

With 2 comments

How about a short, sweet introduction to Architecture Rules.

The Basics

  • Java.
  • Open Source.
  • Asserts architectural rules via unit tests.
  • Write your rules in XML.
  • Run your tests with junit, ant, or a continuous integration server.

Your Rules

You define your rules. For example, if you are developing n-tiered software, you probably have three layers. A DAO/integration layer, a service/business layer, and a presentation layer. Generally, the presentation layer does not interact directly with the integration layer. You could describe this rule as: com.company.project.presentation can not depend on the com.company.project.integration package. Its that easy.

The XML

The XML is in architecture-rules.xml and contains two section: <configuration> and <rules>. Configuration describes where your files are, and the rules simply describe a package, and one or more packages that it can not depend on.

<architecture>

<configuration>
<sources>
<source>targetclasses</source>
</sources>
</configuration>

<rules>

<rule id="dao">
<packages>
<package>
com.company.project.presentation
</package>
</packages>
<violations>
<violation>
com.company.project.integration
</violation>
</violations>
</rule>

</rules>

</architecture>

Thats it. You have a simple architecture-rules.xml.

The Unit Test

Just extend and run your tests.

public class SimpleArchitectureTest
extends AbstractArchitectureRulesConfigurationTest {

public String getConfigurationFileName() {
return "architecture-rules.xml";
}

public void testArchitecture() {
assertTrue(doTests());
}
}

More Features

In Architecture Rules 201, we’ll show you how to check for cycles (cyclic dependencies), write more action-packed rules, and describe how to handle source paths that can’t be found. We can also take a gander at the various Exceptions that can be thrown when rules are broken.

Go Get It

The next thing to do, is to go get it and try it out. Download, svn checkout, or put it in your pom.xml. Just add this repository:

<repository>
<id>architect-rules-repo</id>
<name>
architecture-rules hosted by code.google.com
</name>
<layout>default</layout>
<url>

http://architecturerules.googlecode.com/svn/maven2/

</url>
<releases>
<checksumPolicy>ignore</checksumPolicy>
</releases>
<snapshots>
<checksumPolicy>ignore</checksumPolicy>
</snapshots>
</repository>

And this dependency:

<dependency>
<groupId>com.seventytwomiles</groupId>
<artifactId>architecture-rules</artifactId>
<version>2.0.3</version>
</dependency>

architecture rules xml architecture rules java

Related Posts

2 Responses to 'Architecture Rules Tutorial: 101'

Subscribe to comments with RSS or TrackBack to 'Architecture Rules Tutorial: 101'.

  1. Keep up the good work.

    Ros

    29 Oct 08 at 4:37 am

  2. [...] decision explanations in a simple blog post. For my project, Architecture Rules, we recently posted Architecture Rules 101 and Architecture Rules 102 which provided simple tutorials for creating easy configurations. These [...]

Leave a Reply

Modified Journalist Template   • Last Updated Sep-2010 © 2007 - 2010