Architecture Rules를 사용하여 코드 수준 초과 호출 확인

6318 단어
Architecture Rules를 사용하여 코드 수준 초과 호출 확인
J2EE의 소프트웨어 구조에서 프로그램의 직책에 따라 전시층, 업무층, 지구층을 추상적으로 구분하고 각 층의 자바류는 웹, 서비스,dao 패키지로 구성된다.디자인 원칙에 따르면 층과 층 사이에는 단방향으로만 의존할 수 있고 층을 뛰어넘을 수 없다. 예를 들어 웹->서비스->dao,->만 의존 방향을 표시하고 화살표는 의존한 쪽을 가리킨다.Architecture Rules는 XML 또는 구성 검사 규칙으로 변환하여 프로젝트 코드의 종속을 확인할 수 있는 JDepend 패키지를 기반으로 하는 가젯입니다.Architecture Rules는 JDepend에 비해 구성 가능한 유연한 검사 규칙을 제공합니다.XML 구성 규칙은 많은 설명 없이도 이해할 수 있습니다.
코드를 클립보드로 복사
1.         
2.         
3.             
4.         
5.                 
6.                     core"target"classes
7.                     web"target"classes
8.                     ws"target"classes
9.                 
10.     
11.             
12.     
13.         

14.     
15.         
16.     
17.             
18.                 
19.     
20.                 

21.                 
22.                     com.company.app.core.dao
23.                     com.company.app.core.dao.jdbc
24.                 

25.                 
26.                     com.co.app.core.services
27.                     com.co.app.web
28.                     com.co.app.web.spring
29.                 

30.              
31.     
32.              
33.                 
34.     
35.                 

36.                 
37.                     com.co.app.web
38.                     com.co.app.web.spring
39.                     com.co.app.web.decorators
40.                 

41.                 
42.                     com.co.app.core.dao
43.                     com.co.app.core.dao.jdbc
44.                     com.co.app.core.dao.ldap
45.                 

46.             
47.     
48.         

49.     
50.     

테스트 및 실행
코드를 클립보드로 복사
1.         public class SimpleArchitectureTest  
2.                 extends AbstractArchitectureRulesConfigurationTest {  
3.           
4.             /** 
5.              * @see AbstractArchitectureRulesConfigurationTest 
6.              */  
7.             public String getConfigurationFileName() {  
8.           
9.                 /** 
10.              * Provide the name of the rules configuration file. File file is 
11.              * loaded from the classpath. 
12.              */  
13.             return "architecture-rules.xml";  
14.         }  
15.       
16.         /** 
17.          * @see AbstractArchitectureRulesConfigurationTest#testArchitecture() 
18.          */  
19.         public void testArchitecture() {  
20.       
21.             /** 
22.              * Run the test via doTest(). If any rules are broken, or if 
23.              * the configuration can not be loaded properly, then the appropriate 
24.              * Exception will be thrown. 
25.              */  
26.             assertTrue(doTests());  
27.         }  
28.     }  
프로그래밍 설정과 테스트 실행.
코드를 클립보드로 복사
1.         public class SimpleProgrammaticArchitectureTest  
2.                 extends AbstractArchitectureRulesConfigurationTest {  
3.           
4.             /** 
5.              * Sets up the fixture, for example, open a network connection. This method 
6.              * is called before a test is executed. 
7.              */  
8.             protected void setUp() throws Exception {  
9.           
10.             super.setUp();  
11.       
12.             /* get the configuration reference */  
13.             final Configuration configuration = getConfiguration();  
14.       
15.             /* add sources */  
16.             configuration.addSource(  
17.                     new SourceDirectory("target""test-classes", true));  
18.       
19.             /* set options */  
20.             configuration.setDoCyclicDependencyTest(false);  
21.             configuration.setThrowExceptionWhenNoPackages(true);  
22.       
23.             /* add Rules */  
24.             final Rule daoRule = new Rule("dao");  
25.             daoRule.setComment("dao may not access presentation.");  
26.             daoRule.addPackage("test.com.seventytwomiles.dao.hibernate");  
27.             daoRule.addViolation("test.com.seventytwomiles.web.spring");  
28.       
29.             configuration.addRule(daoRule);  
30.         }  
31.       
32.         /** 
33.          * @see AbstractArchitectureRulesConfigurationTest#testArchitecture() 
34.          */  
35.         public void testArchitecture() {  
36.       
37.             /** 
38.              * Run the test via doTest(). If any rules are broken, or if 
39.              * the configuration can not be loaded properly, then the appropriate 
40.              * Exception will be thrown. 
41.              */  
42.             assertTrue(doTests());  
43.         }  
44.     }  
Architecture Rules는 Ant와 Maven을 모두 지원하므로 프로젝트의 컴파일링 및 테스트 환경에 손쉽게 통합할 수 있습니다.더 많은 정보: 간략한 아름다움, JQuery의 진도표 플러그인은 문서 개발을 자동화시킵니다.com
javaread.com

좋은 웹페이지 즐겨찾기