Skip to content

Commit

Permalink
Add test for adding a custom response header for SSE resource method
Browse files Browse the repository at this point in the history
  • Loading branch information
dastrobu authored and geoand committed Dec 4, 2024
1 parent 8334aa1 commit 5653246
Showing 1 changed file with 64 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package io.quarkus.resteasy.reactive.server.test.customproviders;

import static io.restassured.RestAssured.when;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.stringContainsInOrder;

import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;

import org.jboss.resteasy.reactive.RestMulti;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.test.QuarkusUnitTest;
import io.smallrye.mutiny.Multi;

public class MultiResponseHeadersTest {

@RegisterExtension
static QuarkusUnitTest test = new QuarkusUnitTest()
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class).addClasses(Resource.class));

@Test
public void headerAddedOnMulti() {
when()
.post("/multi")
.then()
.statusCode(200)
.header("Foo", equalTo("Bar"))
.body(stringContainsInOrder("hello", "world"));

}

@Test
public void headerAddedOnSseMulti() {
when()
.post("/sse-multi")
.then()
.statusCode(200)
.header("Foo", equalTo("Bar"))
.body(stringContainsInOrder("hello", "world"));

}

@Path("")
public static class Resource {
@POST
@Path("multi")
public Multi<String> multi() {
return RestMulti.fromMultiData(Multi.createFrom().items("hello", "world")).header("Foo", "Bar").build();
}

@POST
@Path("sse-multi")
@Produces(MediaType.SERVER_SENT_EVENTS)
public Multi<String> sseMulti() {
return RestMulti.fromMultiData(Multi.createFrom().items("hello", "world")).header("Foo", "Bar").build();
}
}
}

0 comments on commit 5653246

Please sign in to comment.