Design test examples
From DesignWizardWiki
The tests described here are some examples that we apply in OurGrid project.
[edit]
Rule: Classes that implement Command interface are inside org.ourgrid.mygrid.ui.command package
public class CommandDesignTest extends TestCase {
public void testCommonPackage() throws IOException, InexistentEntityException, NotAnInterfaceException {
DesignWizard dw = new DesignWizard("ourgrid.jar");
ClassNode commonInterface = dw.getClass("org.ourgrid.mygrid.ui.command.Command");
for (ClassNode c : commonInterface.getEntitiesThatImplements()) {
assertTrue(c.getPackage().equals(dw.getPackage("org.ourgrid.mygrid.ui.command")));
}
}
}
[edit]
Rule: Only org.ourgrid.peer.controller package shall access org.ourgrid.peer.dao package
public class DaoControllerDesignTest extends TestCase {
public void testCommunication() throws IOException, InexistentEntityException {
DesignWizard dw = new DesignWizard("ourgrid.jar");
PackageNode dao = dw.getPackage("org.ourgrid.peer.dao");
PackageNode controller = dw.getPackage("org.ourgrid.peer.controler");
Set<PackageNode> callers = dao.getCallerPackages();
if (callers.isEmpty()) {
assertEquals(1,callers.size());
assertTrue(callers.contains(controller));
}
}
}
