@RunAsClient && access to server for bootstrap
oehmsmith Oct 3, 2013 1:49 AMHi All,
I need to configure the service that is run in a JAX-RS test run with @RunAsClient.
I inject the Service and set values in a @Before but the service that is being used in the client test is a different instance. Is there a way to have a reference to the service that is used?
Thanks,
Brooke
@RunWith(Arquillian.class) public class RestTest() { @Inject HistoricalAlertService historicalAlertServiceSUT; @Deployment public static Archive<?> createDeployment() { return new BaseDeployment(ProjectType.WAR) { { jar.addClasses(AlertPersistService.class, HistoricalAlertService.class); jar.addClasses(AlertHistQueryParams.class); jar.addClasses(AllAlert.class); jar.addClasses(ApplicationConfig.class); } }.build(); } @Before public void init() { // For the @RunAsClient, the server-based variables will be NULL if (historicalAlertServiceSUT != null) { // force it to use the JPA @NamedQuery instead of the @NamedNativeQuery historicalAlertServiceSUT.setFindRangeQuery(AllAlert.findRange); } } @Test @RunAsClient public void test02Service_01_parameterArgCorrect(@ArquillianResource URL deploymentUrl) { DateUtils dateUtils = new DateUtils(); AllAlertTemplate aat = new AllAlertData02(dateUtils); String queryString = String.format("queryType=range&from=%s&to=%s", dateUtils.UTC_DATE_ARG_FORMAT.format(aat.getFromDate()), dateUtils.UTC_DATE_ARG_FORMAT.format(aat.getToDate())); String target = deploymentUrl.toString() + RESOURCE_PREFIX + "alertHist/json?" + queryString; System.out.println(" test target:" + target); Client client = ClientBuilder.newBuilder().register(JsonProcessingFeature.class).property(JsonGenerator.PRETTY_PRINTING, true).build(); WebTarget path = client.target(target); Response response = path.request().get(); JsonObject json = path.request().get(JsonObject.class); assertNotNull(json); System.out.println("Json:" + json); System.out.println("Response: " + response.getStatus()); assertEquals(2, json.getJsonArray("alerts").size()); assertEquals(200, response.getStatus()); preventDBCleanup = true; } }