Search in sources :

Example 91 with GenericType

use of javax.ws.rs.core.GenericType in project syncope by apache.

the class UserSelfITCase method updateWithoutApproval.

@Test
public void updateWithoutApproval() {
    // 1. create user as admin
    UserTO created = createUser(UserITCase.getUniqueSampleTO("anonymous@syncope.apache.org")).getEntity();
    assertNotNull(created);
    assertFalse(created.getUsername().endsWith("XX"));
    // 2. self-update (username) - works
    UserPatch userPatch = new UserPatch();
    userPatch.setKey(created.getKey());
    userPatch.setUsername(new StringReplacePatchItem.Builder().value(created.getUsername() + "XX").build());
    SyncopeClient authClient = clientFactory.create(created.getUsername(), "password123");
    UserTO updated = authClient.getService(UserSelfService.class).update(userPatch).readEntity(new GenericType<ProvisioningResult<UserTO>>() {
    }).getEntity();
    assertNotNull(updated);
    assertEquals(FlowableDetector.isFlowableEnabledForUsers(syncopeService) ? "active" : "created", updated.getStatus());
    assertTrue(updated.getUsername().endsWith("XX"));
}
Also used : GenericType(javax.ws.rs.core.GenericType) StringReplacePatchItem(org.apache.syncope.common.lib.patch.StringReplacePatchItem) UserSelfService(org.apache.syncope.common.rest.api.service.UserSelfService) UserTO(org.apache.syncope.common.lib.to.UserTO) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) SyncopeClient(org.apache.syncope.client.lib.SyncopeClient) Test(org.junit.jupiter.api.Test)

Example 92 with GenericType

use of javax.ws.rs.core.GenericType in project syncope by apache.

the class UserSelfITCase method create.

@Test
public void create() {
    assumeTrue(FlowableDetector.isFlowableEnabledForUsers(syncopeService));
    // 1. self-registration as admin: failure
    try {
        userSelfService.create(UserITCase.getUniqueSampleTO("anonymous@syncope.apache.org"), true);
        fail("This should not happen");
    } catch (ForbiddenException e) {
        assertNotNull(e);
    }
    // 2. self-registration as anonymous: works
    SyncopeClient anonClient = clientFactory.create();
    UserTO self = anonClient.getService(UserSelfService.class).create(UserITCase.getUniqueSampleTO("anonymous@syncope.apache.org"), true).readEntity(new GenericType<ProvisioningResult<UserTO>>() {
    }).getEntity();
    assertNotNull(self);
    assertEquals("createApproval", self.getStatus());
}
Also used : ForbiddenException(javax.ws.rs.ForbiddenException) GenericType(javax.ws.rs.core.GenericType) UserSelfService(org.apache.syncope.common.rest.api.service.UserSelfService) UserTO(org.apache.syncope.common.lib.to.UserTO) SyncopeClient(org.apache.syncope.client.lib.SyncopeClient) Test(org.junit.jupiter.api.Test)

Example 93 with GenericType

use of javax.ws.rs.core.GenericType in project syncope by apache.

the class UserSelfITCase method delete.

@Test
public void delete() {
    UserTO created = createUser(UserITCase.getUniqueSampleTO("anonymous@syncope.apache.org")).getEntity();
    assertNotNull(created);
    SyncopeClient authClient = clientFactory.create(created.getUsername(), "password123");
    UserTO deleted = authClient.getService(UserSelfService.class).delete().readEntity(new GenericType<ProvisioningResult<UserTO>>() {
    }).getEntity();
    assertNotNull(deleted);
    assertEquals(FlowableDetector.isFlowableEnabledForUsers(syncopeService) ? "deleteApproval" : null, deleted.getStatus());
}
Also used : GenericType(javax.ws.rs.core.GenericType) UserSelfService(org.apache.syncope.common.rest.api.service.UserSelfService) UserTO(org.apache.syncope.common.lib.to.UserTO) SyncopeClient(org.apache.syncope.client.lib.SyncopeClient) Test(org.junit.jupiter.api.Test)

Example 94 with GenericType

use of javax.ws.rs.core.GenericType in project kafka-streams-examples by confluentinc.

the class OrdersServiceTest method shouldGetOrderByIdWhenOnDifferentHost.

@Test
public void shouldGetOrderByIdWhenOnDifferentHost() {
    OrderBean order = new OrderBean(id(1L), 4L, OrderState.VALIDATED, Product.JUMPERS, 10, 100d);
    final Client client = ClientBuilder.newClient();
    // Given two rest servers on different ports
    rest = new OrdersService("localhost");
    rest.start(CLUSTER.bootstrapServers());
    Paths paths1 = new Paths("localhost", rest.port());
    rest2 = new OrdersService("localhost");
    rest2.start(CLUSTER.bootstrapServers());
    Paths paths2 = new Paths("localhost", rest2.port());
    // And one order
    client.target(paths1.urlPost()).request(APPLICATION_JSON_TYPE).post(Entity.json(order));
    // When GET to rest1
    OrderBean returnedOrder = client.target(paths1.urlGet(order.getId())).queryParam("timeout", MIN / 2).request(APPLICATION_JSON_TYPE).get(new GenericType<OrderBean>() {
    });
    // Then we should get the order back
    assertThat(returnedOrder).isEqualTo(order);
    // When GET to rest2
    returnedOrder = client.target(paths2.urlGet(order.getId())).queryParam("timeout", MIN / 2).request(APPLICATION_JSON_TYPE).get(new GenericType<OrderBean>() {
    });
    // Then we should get the order back also
    assertThat(returnedOrder).isEqualTo(order);
}
Also used : GenericType(javax.ws.rs.core.GenericType) Paths(io.confluent.examples.streams.microservices.util.Paths) OrderBean(io.confluent.examples.streams.microservices.domain.beans.OrderBean) Client(javax.ws.rs.client.Client) Test(org.junit.Test)

Example 95 with GenericType

use of javax.ws.rs.core.GenericType in project kafka-streams-examples by confluentinc.

the class OrdersServiceTest method shouldPostOrderAndGetItBack.

@Test
public void shouldPostOrderAndGetItBack() {
    OrderBean bean = new OrderBean(id(1L), 2L, OrderState.CREATED, Product.JUMPERS, 10, 100d);
    final Client client = ClientBuilder.newClient();
    // Given a rest service
    rest = new OrdersService("localhost");
    rest.start(CLUSTER.bootstrapServers());
    Paths paths = new Paths("localhost", rest.port());
    // When we POST an order
    Response response = client.target(paths.urlPost()).request(APPLICATION_JSON_TYPE).post(Entity.json(bean));
    // Then
    assertThat(response.getStatus()).isEqualTo(HttpURLConnection.HTTP_CREATED);
    // When GET the bean back via it's location
    OrderBean returnedBean = client.target(response.getLocation()).queryParam("timeout", MIN / 2).request(APPLICATION_JSON_TYPE).get(new GenericType<OrderBean>() {
    });
    // Then it should be the bean we PUT
    assertThat(returnedBean).isEqualTo(bean);
    // When GET the bean back explicitly
    returnedBean = client.target(paths.urlGet(1)).queryParam("timeout", MIN / 2).request(APPLICATION_JSON_TYPE).get(new GenericType<OrderBean>() {
    });
    // Then it should be the bean we PUT
    assertThat(returnedBean).isEqualTo(bean);
}
Also used : Response(javax.ws.rs.core.Response) GenericType(javax.ws.rs.core.GenericType) Paths(io.confluent.examples.streams.microservices.util.Paths) OrderBean(io.confluent.examples.streams.microservices.domain.beans.OrderBean) Client(javax.ws.rs.client.Client) Test(org.junit.Test)

Aggregations

GenericType (javax.ws.rs.core.GenericType)126 List (java.util.List)64 WebTarget (javax.ws.rs.client.WebTarget)64 Response (javax.ws.rs.core.Response)60 Test (org.junit.Test)51 Client (javax.ws.rs.client.Client)24 ArrayList (java.util.ArrayList)17 Message (com.remswork.project.alice.model.support.Message)16 WebClient (org.apache.cxf.jaxrs.client.WebClient)16 GenericEntity (javax.ws.rs.core.GenericEntity)15 MediaType (javax.ws.rs.core.MediaType)15 Collection (java.util.Collection)14 Set (java.util.Set)14 LinkedList (java.util.LinkedList)12 HashSet (java.util.HashSet)11 Test (org.junit.jupiter.api.Test)11 JerseyTest (org.glassfish.jersey.test.JerseyTest)10 JacksonJsonProvider (com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider)9 Collections (java.util.Collections)9 Entity (javax.ws.rs.client.Entity)9