2013-12-23 4 views
4

도와주세요. 나는 휴식 앱 예제를 시작하기 위해 오랜 시간 동안 노력했지만, 나는 이것을 할 수 없다.저지 사용자 안내서를 시작할 수 없습니다

package com.example; 

import javax.ws.rs.client.Client; 
import javax.ws.rs.client.ClientBuilder; 
import javax.ws.rs.client.WebTarget; 

import org.glassfish.grizzly.http.server.HttpServer; 

... 

public class MyResourceTest { 

    private HttpServer server; 
    private WebTarget target; 

    @Before 
    public void setUp() throws Exception { 
     server = Main.startServer(); 

     Client c = ClientBuilder.newClient(); 
     target = c.target(Main.BASE_URI); 
    } 

    @After 
    public void tearDown() throws Exception { 
     server.stop(); 
    } 

    /** 
    * Test to see that the message "Got it!" is sent in the response. 
    */ 
    @Test 
    public void testGetIt() { 
     String responseMsg = target.path("myresource").request().get(String.class); 
     assertEquals("Got it!", responseMsg); 
    } 
} 

하지만 난 깨닫지 수 있으며, startserver는() 메소드를 메인 클래스가 무엇 : 내가 it.Here에 집착하고있어 jersey user guide를 사용하여 예입니다? 다음은이 클래스에 대한 가져 오기가 아닙니다.

답변

3

는 메인 클래스의 link입니다 :/테스트/자바 SRC (특정 코드 주석과의 JUnit 수입은 간결 제외 되었습니다) 받는다는 프로젝트 테스트 소스 디렉토리에 배치. Main.startServer()는 다음과 같습니다.

/** 
* Starts Grizzly HTTP server exposing JAX-RS resources defined in this application. 
* @return Grizzly HTTP server. 
*/ 
public static HttpServer startServer() { 
    // create a resource config that scans for JAX-RS resources and providers 
    // in $package package 
    final ResourceConfig rc = new ResourceConfig().packages("$package"); 

    // create and start a new instance of grizzly http server 
    // exposing the Jersey application at BASE_URI 
    return GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URI), rc); 
} 
1

가이드의이 코드 위의 단락을 읽으면 가이드의 예에서 실제 코드의 일부만 강조 표시됩니다. 전체 코드는 com.example 패키지에서 MyResource 클래스로 찾을 수 있습니다.

뼈대 프로젝트에서 생성 된 코드의 마지막 부분은에서는 MyResource 클래스와 동일한 com.example 패키지에 위치한 MyResourceTest 단위 테스트 클래스는, 그러나,이 장치 테스트 클래스이다

다음