Search in sources :

Example 1 with TypeRef

use of io.restassured.common.mapper.TypeRef in project quarkus by quarkusio.

the class Utils method callTheEndpoint.

static void callTheEndpoint(String endpoint) {
    List<Book> list = get(endpoint).as(new TypeRef<List<Book>>() {
    });
    Assertions.assertEquals(0, list.size());
    Book book1 = new Book().setAuthor("Victor Hugo").setTitle("Les Misérables").setCategories(Arrays.asList("long", "very long")).setDetails(new BookDetail().setRating(3).setSummary("A very long book"));
    Response response = RestAssured.given().header("Content-Type", "application/json").body(book1).post(endpoint).andReturn();
    Assertions.assertEquals(202, response.statusCode());
    Book book2 = new Book().setAuthor("Victor Hugo").setTitle("Notre-Dame de Paris").setCategories(Arrays.asList("long", "quasimodo")).setDetails(new BookDetail().setRating(4).setSummary("quasimodo and esmeralda"));
    response = RestAssured.given().header("Content-Type", "application/json").body(book2).post(endpoint).andReturn();
    Assertions.assertEquals(202, response.statusCode());
    list = get(endpoint).as(new TypeRef<List<Book>>() {
    });
    Assertions.assertEquals(2, list.size());
    Book book3 = new Book().setAuthor("Charles Baudelaire").setTitle("Les fleurs du mal").setCategories(Collections.singletonList("poem")).setDetails(new BookDetail().setRating(2).setSummary("Les Fleurs du mal is a volume of poetry."));
    response = RestAssured.given().header("Content-Type", "application/json").body(book3).post(endpoint).andReturn();
    Assertions.assertEquals(202, response.statusCode());
    list = get(endpoint).as(new TypeRef<List<Book>>() {
    });
    Assertions.assertEquals(3, list.size());
    list = get(endpoint + "/Victor Hugo").as(new TypeRef<List<Book>>() {
    });
    Assertions.assertEquals(2, list.size());
}
Also used : Response(io.restassured.response.Response) TypeRef(io.restassured.common.mapper.TypeRef) List(java.util.List)

Example 2 with TypeRef

use of io.restassured.common.mapper.TypeRef in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ShardBridgesSyncAPITest method testGetBridgesToDeploy.

@Test
@TestSecurity(user = TestConstants.DEFAULT_CUSTOMER_ID)
public void testGetBridgesToDeploy() {
    TestUtils.createBridge(new BridgeRequest(TestConstants.DEFAULT_BRIDGE_NAME));
    List<BridgeDTO> response = TestUtils.getBridgesToDeployOrDelete().as(new TypeRef<List<BridgeDTO>>() {
    });
    assertThat(response.stream().filter(x -> x.getStatus().equals(ManagedResourceStatus.ACCEPTED)).count()).isEqualTo(1);
    BridgeDTO bridge = response.get(0);
    assertThat(bridge.getName()).isEqualTo(TestConstants.DEFAULT_BRIDGE_NAME);
    assertThat(bridge.getCustomerId()).isEqualTo(TestConstants.DEFAULT_CUSTOMER_ID);
    assertThat(bridge.getStatus()).isEqualTo(ManagedResourceStatus.ACCEPTED);
    assertThat(bridge.getEndpoint()).isNull();
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) StringEquals(com.redhat.service.bridge.infra.models.filters.StringEquals) BaseFilter(com.redhat.service.bridge.infra.models.filters.BaseFilter) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) BridgeRequest(com.redhat.service.bridge.manager.api.models.requests.BridgeRequest) RhoasService(com.redhat.service.bridge.manager.RhoasService) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Inject(javax.inject.Inject) DatabaseManagerUtils(com.redhat.service.bridge.manager.utils.DatabaseManagerUtils) BaseAction(com.redhat.service.bridge.infra.models.actions.BaseAction) KafkaTopicAction(com.redhat.service.bridge.actions.kafkatopic.KafkaTopicAction) WebhookAction(com.redhat.service.bridge.actions.webhook.WebhookAction) TypeRef(io.restassured.common.mapper.TypeRef) TestConstants(com.redhat.service.bridge.manager.TestConstants) InjectMock(io.quarkus.test.junit.mockito.InjectMock) ResponseLoggingFilter(io.restassured.filter.log.ResponseLoggingFilter) ContentType(io.restassured.http.ContentType) Set(java.util.Set) Mockito.when(org.mockito.Mockito.when) BridgeResponse(com.redhat.service.bridge.manager.api.models.responses.BridgeResponse) BridgeDTO(com.redhat.service.bridge.infra.models.dto.BridgeDTO) Test(org.junit.jupiter.api.Test) List(java.util.List) ProcessorRequest(com.redhat.service.bridge.manager.api.models.requests.ProcessorRequest) ManagedResourceStatus(com.redhat.service.bridge.infra.models.dto.ManagedResourceStatus) JsonWebToken(org.eclipse.microprofile.jwt.JsonWebToken) ProcessorDTO(com.redhat.service.bridge.infra.models.dto.ProcessorDTO) SendToBridgeAction(com.redhat.service.bridge.manager.actions.sendtobridge.SendToBridgeAction) TestUtils(com.redhat.service.bridge.manager.utils.TestUtils) RestAssured.given(io.restassured.RestAssured.given) KafkaConnectionDTO(com.redhat.service.bridge.infra.models.dto.KafkaConnectionDTO) TestSecurity(io.quarkus.test.security.TestSecurity) Collections(java.util.Collections) Mockito.reset(org.mockito.Mockito.reset) APIConstants(com.redhat.service.bridge.infra.api.APIConstants) BridgeRequest(com.redhat.service.bridge.manager.api.models.requests.BridgeRequest) BridgeDTO(com.redhat.service.bridge.infra.models.dto.BridgeDTO) List(java.util.List) TestSecurity(io.quarkus.test.security.TestSecurity) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 3 with TypeRef

use of io.restassured.common.mapper.TypeRef in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ShardBridgesSyncAPITest method testNotifyDeployment.

@Test
@TestSecurity(user = TestConstants.DEFAULT_CUSTOMER_ID)
public void testNotifyDeployment() {
    TestUtils.createBridge(new BridgeRequest(TestConstants.DEFAULT_BRIDGE_NAME));
    List<BridgeDTO> bridgesToDeployOrDelete = TestUtils.getBridgesToDeployOrDelete().as(new TypeRef<List<BridgeDTO>>() {
    });
    assertThat(bridgesToDeployOrDelete.stream().filter(x -> x.getStatus().equals(ManagedResourceStatus.ACCEPTED)).count()).isEqualTo(1);
    BridgeDTO bridge = bridgesToDeployOrDelete.get(0);
    bridge.setStatus(ManagedResourceStatus.PROVISIONING);
    TestUtils.updateBridge(bridge).then().statusCode(200);
    bridgesToDeployOrDelete = TestUtils.getBridgesToDeployOrDelete().as(new TypeRef<List<BridgeDTO>>() {
    });
    assertThat(bridgesToDeployOrDelete.size()).isZero();
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) StringEquals(com.redhat.service.bridge.infra.models.filters.StringEquals) BaseFilter(com.redhat.service.bridge.infra.models.filters.BaseFilter) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) BridgeRequest(com.redhat.service.bridge.manager.api.models.requests.BridgeRequest) RhoasService(com.redhat.service.bridge.manager.RhoasService) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Inject(javax.inject.Inject) DatabaseManagerUtils(com.redhat.service.bridge.manager.utils.DatabaseManagerUtils) BaseAction(com.redhat.service.bridge.infra.models.actions.BaseAction) KafkaTopicAction(com.redhat.service.bridge.actions.kafkatopic.KafkaTopicAction) WebhookAction(com.redhat.service.bridge.actions.webhook.WebhookAction) TypeRef(io.restassured.common.mapper.TypeRef) TestConstants(com.redhat.service.bridge.manager.TestConstants) InjectMock(io.quarkus.test.junit.mockito.InjectMock) ResponseLoggingFilter(io.restassured.filter.log.ResponseLoggingFilter) ContentType(io.restassured.http.ContentType) Set(java.util.Set) Mockito.when(org.mockito.Mockito.when) BridgeResponse(com.redhat.service.bridge.manager.api.models.responses.BridgeResponse) BridgeDTO(com.redhat.service.bridge.infra.models.dto.BridgeDTO) Test(org.junit.jupiter.api.Test) List(java.util.List) ProcessorRequest(com.redhat.service.bridge.manager.api.models.requests.ProcessorRequest) ManagedResourceStatus(com.redhat.service.bridge.infra.models.dto.ManagedResourceStatus) JsonWebToken(org.eclipse.microprofile.jwt.JsonWebToken) ProcessorDTO(com.redhat.service.bridge.infra.models.dto.ProcessorDTO) SendToBridgeAction(com.redhat.service.bridge.manager.actions.sendtobridge.SendToBridgeAction) TestUtils(com.redhat.service.bridge.manager.utils.TestUtils) RestAssured.given(io.restassured.RestAssured.given) KafkaConnectionDTO(com.redhat.service.bridge.infra.models.dto.KafkaConnectionDTO) TestSecurity(io.quarkus.test.security.TestSecurity) Collections(java.util.Collections) Mockito.reset(org.mockito.Mockito.reset) APIConstants(com.redhat.service.bridge.infra.api.APIConstants) BridgeRequest(com.redhat.service.bridge.manager.api.models.requests.BridgeRequest) BridgeDTO(com.redhat.service.bridge.infra.models.dto.BridgeDTO) TypeRef(io.restassured.common.mapper.TypeRef) List(java.util.List) TestSecurity(io.quarkus.test.security.TestSecurity) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 4 with TypeRef

use of io.restassured.common.mapper.TypeRef in project quarkus-quickstarts by quarkusio.

the class PriceTest method test.

@Test
public void test() {
    // Check we don't have any prices
    List<Price> prices = RestAssured.get("/prices/all").as(new TypeRef<List<Price>>() {
    });
    Assertions.assertTrue(prices.isEmpty());
    // Stream the prices
    Client client = ClientBuilder.newClient();
    WebTarget target = client.target(PRICES_SSE_ENDPOINT);
    List<Double> received = new CopyOnWriteArrayList<>();
    SseEventSource source = SseEventSource.target(target).build();
    source.register(inboundSseEvent -> received.add(Double.valueOf(inboundSseEvent.readData())));
    source.open();
    // Send the prices
    Price p1 = new Price();
    p1.value = 1.0;
    Price p2 = new Price();
    p2.value = 4.0;
    Price p3 = new Price();
    p3.value = 2.0;
    RestAssured.given().header("Content-Type", "application/json").body(p1).post("/").then().statusCode(204);
    RestAssured.given().header("Content-Type", "application/json").body(p2).post("/").then().statusCode(204);
    RestAssured.given().header("Content-Type", "application/json").body(p3).post("/").then().statusCode(204);
    await().atMost(100000, MILLISECONDS).until(() -> received.size() == 3);
    source.close();
    Assertions.assertTrue(received.contains(p1.value));
    Assertions.assertTrue(received.contains(p2.value));
    Assertions.assertTrue(received.contains(p3.value));
    prices = RestAssured.get("/prices/all").as(new TypeRef<List<Price>>() {
    });
    Assertions.assertEquals(prices.size(), 3);
}
Also used : SseEventSource(javax.ws.rs.sse.SseEventSource) Price(org.acme.context.Price) TypeRef(io.restassured.common.mapper.TypeRef) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 5 with TypeRef

use of io.restassured.common.mapper.TypeRef in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ShardBridgesSyncAPITest method testNotifyDeletion.

@Test
@TestSecurity(user = DEFAULT_CUSTOMER_ID)
public void testNotifyDeletion() {
    TestUtils.createBridge(new BridgeRequest(DEFAULT_BRIDGE_NAME));
    final List<BridgeDTO> bridgesToDeployOrDelete = new ArrayList<>();
    await().atMost(5, SECONDS).untilAsserted(() -> {
        bridgesToDeployOrDelete.clear();
        bridgesToDeployOrDelete.addAll(TestUtils.getBridgesToDeployOrDelete().as(new TypeRef<List<BridgeDTO>>() {
        }));
        assertThat(bridgesToDeployOrDelete.size()).isEqualTo(1);
    });
    BridgeDTO bridge = bridgesToDeployOrDelete.get(0);
    bridge.setStatus(READY);
    TestUtils.updateBridge(bridge).then().statusCode(200);
    TestUtils.deleteBridge(bridge.getId()).then().statusCode(202);
    BridgeResponse bridgeResponse = TestUtils.getBridge(bridge.getId()).as(BridgeResponse.class);
    assertThat(bridgeResponse.getStatus()).isEqualTo(DEPROVISION);
    bridge.setStatus(DELETED);
    TestUtils.updateBridge(bridge).then().statusCode(200);
    TestUtils.getBridge(bridge.getId()).then().statusCode(404);
}
Also used : BridgeRequest(com.redhat.service.smartevents.manager.api.models.requests.BridgeRequest) BridgeDTO(com.redhat.service.smartevents.infra.models.dto.BridgeDTO) TypeRef(io.restassured.common.mapper.TypeRef) ArrayList(java.util.ArrayList) BridgeResponse(com.redhat.service.smartevents.manager.api.models.responses.BridgeResponse) TestSecurity(io.quarkus.test.security.TestSecurity) Test(org.junit.jupiter.api.Test) QuarkusTest(io.quarkus.test.junit.QuarkusTest)

Aggregations

TypeRef (io.restassured.common.mapper.TypeRef)20 QuarkusTest (io.quarkus.test.junit.QuarkusTest)18 Test (org.junit.jupiter.api.Test)18 TestSecurity (io.quarkus.test.security.TestSecurity)13 ArrayList (java.util.ArrayList)13 List (java.util.List)13 BridgeDTO (com.redhat.service.smartevents.infra.models.dto.BridgeDTO)10 RestAssured.given (io.restassured.RestAssured.given)10 BridgeRequest (com.redhat.service.smartevents.manager.api.models.requests.BridgeRequest)9 BridgeResponse (com.redhat.service.smartevents.manager.api.models.responses.BridgeResponse)9 InjectMock (io.quarkus.test.junit.mockito.InjectMock)9 ContentType (io.restassured.http.ContentType)9 Collections (java.util.Collections)9 Set (java.util.Set)9 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)9 KafkaConnectionDTO (com.redhat.service.smartevents.infra.models.dto.KafkaConnectionDTO)7 ProcessorDTO (com.redhat.service.smartevents.infra.models.dto.ProcessorDTO)7 ProcessorRequest (com.redhat.service.smartevents.manager.api.models.requests.ProcessorRequest)7 ResponseLoggingFilter (io.restassured.filter.log.ResponseLoggingFilter)7 Mockito.when (org.mockito.Mockito.when)7