के साथ ड्रॉपविज़ार्ड एकीकृत परीक्षण क्या कोई जानता है कि कोई परीक्षण संसाधन कैसे जोड़ना है (यानी केवल परीक्षण उद्देश्यों के लिए है और ऐप के रन() विधि में नहीं जोड़ा गया है)?टेस्ट रिसोर्स
यहाँ एक उदाहरण है:
public class MyTest {
@ClassRule
public static final DropwizardAppRule<TestConfiguration> RULE =
new DropwizardAppRule<TestConfiguration>(MyApp.class, "my-app-config.yaml");
@BeforeClass
public static void setUpBeforeClass() throws Exception
{
MyTest.RULE.getEnvironment().jersey().register(new JustForTestingResource());
}
@Test
public final void testTestResource()
{
Client client = new Client();
ClientResponse response = client.resource(
String.format("http://localhost:%d/rest/v1/test", RULE.getLocalPort()))
.get(ClientResponse.class);
assertThat(response.getStatus(), is(200));
}
}
और
public class JustForTestingRessource {
@GET
@Path("test")
@Produces(MediaType.APPLICATION_JSON)
public Response getInTestResource()
{
return Response.status(Status.OK).type(MediaType.TEXT_PLAIN).entity("get @Path(\"test\") is ok").build();
}
}
मेरे समस्या यह है कि जोड़ा संसाधन नहीं जोड़ा है और मैं संसाधन नहीं मिला 404 त्रुटि प्रतिक्रिया मिल है। ऐसा लगता है कि मैं संसाधन प्रकाशन के बाद नया संसाधन पंजीकृत कर रहा हूं और शुरुआत के बाद ड्रॉपविज़ार्ड के अंदर कोई ताज़ा नहीं है।
मैं अपनी एप्लिकेशन कक्षा का विस्तार नहीं करना चाहता हूं और मैं अपने वास्तविक एप्लिकेशन कोड में टेस्ट कोड डालना नहीं चाहता हूं। क्या कोई जानता है कि आवेदन के रन() विधि में पंजीकरण किए बिना परीक्षण संसाधन को कैसे पंजीकृत किया जाए?
यह काम करता है, लेकिन एक नया वर्ग की जरूरत है:
public class TestService extends MyService{
@Override
public void run(
TestConfigurationconfiguration,
Environment environment) throws ClassNotFoundException
{
environment.jersey().register(new JustForTestingRessource());
super.run(configuration,environment);
}
}
JUnit में कॉल पहले से ही जाना जाता है:
@ClassRule
public static DropwizardAppRule<TestConfiguration> RULE =
new DropwizardAppRule<TestConfiguration>(TestService.class, "my-app-config.yaml");
कुछ RULE.addRessource (...) की तरह फैली होगी अच्छा ... – user3280180