Architecture Rules

Download 2.1.1

About

Assert Your Architecture! with this open source java library. Architecture Rules leverages an xml configuration file and optional programmatic configuration to assert your code's architecture via unit tests or ant tasks. This test is able to assert that specific packages do not depend on others and is able to check for and report on cyclic dependencies among your project's packages and classes. This project wraps a industry accepted JDepend to simplify the process of maintaining a solid software architecture.

License

Licensed under Apache License 2.0 - allows use of the source code for the development of free and open source software as well as proprietary and closed source software.

Do you Assert your Architecture? Please help out with our fund raising.
Checkout what we are raising funds for. Be sure to report issues.

Sample Test - Mixed Configuration

Back to Code By Example

Description

This is a mixed configuration test. That is, rules are defined in both the architecture-rules.xml configuration file, and then additional rules are added programmatically in the test. The getConfiguration() method returns the configuration instance, loaded up with the configuration provided in the XML file. From the test, you can now modify a rule, add new sources, turn off or on the cyclic dependency test, or clear the configuration and start over from scratch.

Code


/**
 * Copyright 2007 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * For more information visit
 *         http://72miles.com and
 *         http://architecturerules.googlecode.com/svn/docs/index.html
 */

package com.seventytwomiles.architecturerules;

import com.seventytwomiles.architecturerules.configuration.Configuration;
import com.seventytwomiles.architecturerules.domain.Rule;
import com.seventytwomiles.architecturerules.domain.SourceDirectory;

/**
 * <p>Architecture test example.</p>
 *
 * @author mikenereson
 * @see AbstractArchitectureRulesConfigurationTest
 */
public class SimpleProgrammaticArchitectureTest
        extends AbstractArchitectureRulesConfigurationTest {

    /**
     * Sets up the fixture, for example, open a network connection. This method
     * is called before a test is executed.
     */
    protected void setUp() throws Exception {

        super.setUp();

        /* get the configuration reference */
        final Configuration configuration = getConfiguration();

        /* add sources */
        configuration.addSource(
                new SourceDirectory("target\\test-classes", true));

        /* set options */
        configuration.setDoCyclicDependencyTest(false);
        configuration.setThrowExceptionWhenNoPackages(true);

        /* add Rules */
        final Rule daoRule = new Rule("dao");
        daoRule.setComment("dao may not access presentation.");
        daoRule.addPackage("test.com.seventytwomiles.dao.hibernate");
        daoRule.addViolation("test.com.seventytwomiles.web.spring");

        configuration.addRule(daoRule);
    }

    /**
     * @see AbstractArchitectureRulesConfigurationTest#testArchitecture()
     */
    public void testArchitecture() {

        /**
         * Run the test via doTest(). If any rules are broken, or if
         * the configuration can not be loaded properly, then the appropriate
         * Exception will be thrown.
         */
        assertTrue(doTests());
    }
}

Leave a Comment

Back to Code By Example

Start Here

Get Help

More Information

Architecture Propaganda

Schwag

If you assert your architecture, then let everyone know with this branded gear. architecture rules mug