Skip to content

Conversation

@redrezo
Copy link

@redrezo redrezo commented Apr 9, 2014

patched HttpJUnitRunner to support this
added @HttpConfig annotation and RuleStrategy enum to configure behavior
default behavior is unchanged

example:

@RunWith(HttpJUnitRunner.class)
@HttpConfig(ruleStrategy=RuleStrategy.HTTP_CALL_AFTER_BEFORE)
public class MyTest {
    @Rule
    public Destination destination = new Destination(this, "http://localhost:" + System.getProperty( "org.osgi.service.http.port" ));

    @Context
    private Response response;

    @Before
    public void before() {
        System.err.println("Test#before()");
        Bundle bundle = FrameworkUtil.getBundle(Test.class);
        BundleContext bundleContext = bundle.getBundleContext();
        ServiceReference<WebService> serviceReference = bundleContext.getServiceReference(WebService.class);
        WebService service = bundleContext.getService(serviceReference);
        service.setName("Foo");
    }

    @org.junit.Test
    @HttpTest(method=Method.GET, path="/services/hello")
    public void testServiceCall() {
        System.err.println("Test#testServiceCall()");
        assertOk(response);
        assertEquals("Hello Foo", response.getBody());
    }
}


@Path("/")
public class WebService {

    private String name = "World";

    @GET
    @Path("/hello")
    public String helloWorld() {
        System.err.println("WebService#helloWorld()");
        return "Hello " + name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

before rest services are executed. configurable via a new @HttpConfig
annotation. default behavior unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant