2012-02-28 2 views
1

나는 다음과 같은 방법으로 내장 된 글래스 피쉬를 사용했습니다 :글래스 피시 내장 +를 받는다는 cobertura 플러그인

public static void createContainer() throws IOException {   
    File target = new File("target/classes");  
    Map<String, Object> properties = new HashMap<String, Object>(); 
    properties.put(EJBContainer.MODULES, target); 
    properties.put("org.glassfish.ejb.embedded.glassfish.installation.root", 
      "/opt/glassfish3/glassfish"); 
    container = EJBContainer.createEJBContainer(properties); 
    context = container.getContext(); 
} 

@AfterSuite(alwaysRun = true) 
public static void closeContainer() throws NamingException { 
    // close container 
} 

// I use this method to lookup 
public static <T> T lookupBy(Class<T> type) { 
    try { 
     return (T) context.lookup("java:global/classes/" + type.getSimpleName()); 
    } catch (NamingException ex) { 
     throw new RuntimeException(ex); 
    } 
} 

문제는 내장 된 글래스 피쉬는 "목표/수업"의 클래스를 사용하여 받는다는 cobertura이 사용한다는 것입니다 "목표/생성 -classes/cobertura "라고합니다. 그런 다음 테스트를 처음 실행하면 ok이지만 두 번째로 cobertura가 실행될 때 java.lang.RuntimeException : javax.naming.NamingException이 발생합니다 (cobertura가 "target/generated-classes/cobertura" "글래스 피시는"목표/클래스 "에서 작업 중).

이 문제를 해결할 수있는 아이디어가 있습니까 ???

답변

0

나는 cobertura와 glassfish가 포함 된 동일한 문제를 실험했다. 여기에 그것을 해결하기 위해 내 설정입니다.

난 그냥 글래스 피쉬가 내장 모두 받는다는 종속성에서cobertura을 특정 옵션없이 포함되어 있습니다. EJBContainer 속성 EJBContainer.MODULES을 사용하지 않고 glassfish-embedded는 정상 또는 cobertura 단계에서 ejb 클래스를 찾습니다.

그러나 JNDI 이식 가능한 이름은 일반 및 cobertura 경우간에 변경됩니다. 그래서 lookupBy 메서드를 사용하여이 두 가지 사례를 관리했습니다.

public static void createContainer() throws IOException {   
    container = EJBContainer.createEJBContainer(); 
    context = container.getContext(); 
    MyServiceLocal ejb = lookupBy(MyServiceLocal.class,MyServiceImpl.class); 
} 

public static <T> T lookupBy(Class<T> type, Class service) { 
    try { 
     return (T) context.lookup("java:global/classes/" + service.getSimpleName()); 
    } catch (NamingException ex) { 
     // lookup with cobertura 
     return (T) context.lookup("java:global/cobertura/" + service.getSimpleName() + "!" + type.getName()); 
    } 
} 
: 마지막으로 여기

내 코드입니다