Skip to content

Instantly share code, notes, and snippets.

@saw303
Created November 19, 2014 15:24
Show Gist options
  • Save saw303/28dd667f5d344615c01c to your computer and use it in GitHub Desktop.
Save saw303/28dd667f5d344615c01c to your computer and use it in GitHub Desktop.
@ContextConfiguration("classpath:applicationContextRestIntegrationTest.xml")
@ActiveProfiles(['local', 'compliance'])
@TestExecutionListeners([DependencyInjectionTestExecutionListener.class, DirtiesContextTestExecutionListener.class])
class RestSpec extends Specification implements JaxrsInterceptorRegistryListener {
@Autowired
ApplicationContext applicationContext
@Autowired
KsdApiSchemaRequestFilter filter
@Override
void registryUpdated(JaxrsInterceptorRegistry registry) {
println "XXXX"
}
void "test the rest api"() {
given:
EmbeddedJaxrsServer server = new TJWSEmbeddedJaxrsServer()
server.port = 9999
server.start()
def dispatcher = server.getDeployment().getDispatcher()
//dispatcher.registry.getResourceInvoker()
dispatcher.providerFactory.clientRequestFilters.listeners.add(this)
dispatcher.providerFactory.clientRequestFilters.registerSingleton(filter)
dispatcher.registry.addResourceFactory(new SpringResourceFactory('complianceTestResource', applicationContext, ComplianceTestResource.class))
def url = 'http://localhost:9999//v1/compliancetest'
def client = ClientBuilder.newBuilder().property('connection.timeout', 1).register(JacksonJsonProvider.class).build()
when:
Response response = client.target(url).request(APPLICATION_JSON_VALUE).options()
then:
response.status == 200
cleanup:
server.stop()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment