Search in sources :

Example 46 with GenericType

use of javax.ws.rs.core.GenericType in project engine by Lumeer.

the class ViewServiceIT method testGetAllViews.

@Test
public void testGetAllViews() {
    createView(CODE);
    createView(CODE2);
    Response response = client.target(VIEWS_URL).request(MediaType.APPLICATION_JSON).buildGet().invoke();
    assertThat(response).isNotNull();
    assertThat(response.getStatusInfo()).isEqualTo(Response.Status.OK);
    List<JsonView> views = response.readEntity(new GenericType<List<JsonView>>() {
    });
    assertThat(views).extracting(Resource::getCode).containsOnly(CODE, CODE2);
    Permissions permissions1 = views.get(0).getPermissions();
    assertThat(permissions1).extracting(Permissions::getUserPermissions).containsOnly(Collections.singleton(USER_PERMISSION));
    assertThat(permissions1).extracting(p -> p.getUserPermissions().iterator().next().getRoles()).containsOnly(USER_ROLES);
    assertThat(permissions1).extracting(Permissions::getGroupPermissions).containsOnly(Collections.emptySet());
    Permissions permissions2 = views.get(1).getPermissions();
    assertThat(permissions2).extracting(Permissions::getUserPermissions).containsOnly(Collections.singleton(USER_PERMISSION));
    assertThat(permissions2).extracting(p -> p.getUserPermissions().iterator().next().getRoles()).containsOnly(USER_ROLES);
    assertThat(permissions2).extracting(Permissions::getGroupPermissions).containsOnly(Collections.emptySet());
}
Also used : Response(javax.ws.rs.core.Response) JsonView(io.lumeer.api.dto.JsonView) UserDao(io.lumeer.storage.api.dao.UserDao) Arrays(java.util.Arrays) SoftAssertions(org.assertj.core.api.SoftAssertions) ProjectDao(io.lumeer.storage.api.dao.ProjectDao) Arquillian(org.jboss.arquillian.junit.Arquillian) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) JsonPermission(io.lumeer.api.dto.JsonPermission) User(io.lumeer.api.model.User) RunWith(org.junit.runner.RunWith) LumeerAssertions.assertPermissions(io.lumeer.test.util.LumeerAssertions.assertPermissions) JsonQuery(io.lumeer.api.dto.JsonQuery) Resource(io.lumeer.api.model.Resource) JsonPermissions(io.lumeer.api.dto.JsonPermissions) HashSet(java.util.HashSet) Inject(javax.inject.Inject) OrganizationDao(io.lumeer.storage.api.dao.OrganizationDao) MediaType(javax.ws.rs.core.MediaType) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Role(io.lumeer.api.model.Role) ViewDao(io.lumeer.storage.api.dao.ViewDao) SimplePermission(io.lumeer.core.model.SimplePermission) UriBuilder(javax.ws.rs.core.UriBuilder) MorphiaPermissions(io.lumeer.storage.mongodb.model.embedded.MorphiaPermissions) Organization(io.lumeer.api.model.Organization) Before(org.junit.Before) Permission(io.lumeer.api.model.Permission) View(io.lumeer.api.model.View) ResourceNotFoundException(io.lumeer.storage.api.exception.ResourceNotFoundException) Permissions(io.lumeer.api.model.Permissions) MorphiaProject(io.lumeer.storage.mongodb.model.MorphiaProject) AuthenticatedUser(io.lumeer.core.AuthenticatedUser) Set(java.util.Set) Test(org.junit.Test) Entity(javax.ws.rs.client.Entity) GenericType(javax.ws.rs.core.GenericType) Project(io.lumeer.api.model.Project) MorphiaOrganization(io.lumeer.storage.mongodb.model.MorphiaOrganization) List(java.util.List) Response(javax.ws.rs.core.Response) Collections(java.util.Collections) Link(javax.ws.rs.core.Link) LumeerAssertions.assertPermissions(io.lumeer.test.util.LumeerAssertions.assertPermissions) JsonPermissions(io.lumeer.api.dto.JsonPermissions) MorphiaPermissions(io.lumeer.storage.mongodb.model.embedded.MorphiaPermissions) Permissions(io.lumeer.api.model.Permissions) JsonView(io.lumeer.api.dto.JsonView) List(java.util.List) Test(org.junit.Test)

Example 47 with GenericType

use of javax.ws.rs.core.GenericType in project engine by Lumeer.

the class CollectionServiceIT method testGetAllCollections.

@Test
public void testGetAllCollections() {
    createCollection(CODE);
    createCollection(CODE2);
    Response response = client.target(COLLECTIONS_URL).request(MediaType.APPLICATION_JSON).buildGet().invoke();
    assertThat(response).isNotNull();
    assertThat(response.getStatusInfo()).isEqualTo(Response.Status.OK);
    List<JsonCollection> collections = response.readEntity(new GenericType<List<JsonCollection>>() {
    });
    assertThat(collections).extracting(Resource::getCode).containsOnly(CODE, CODE2);
    Permissions permissions1 = collections.get(0).getPermissions();
    assertThat(permissions1).extracting(Permissions::getUserPermissions).containsOnly(Collections.singleton(USER_PERMISSION));
    assertThat(permissions1).extracting(p -> p.getUserPermissions().iterator().next().getRoles()).containsOnly(USER_ROLES);
    assertThat(permissions1).extracting(Permissions::getGroupPermissions).containsOnly(Collections.emptySet());
    Permissions permissions2 = collections.get(1).getPermissions();
    assertThat(permissions2).extracting(Permissions::getUserPermissions).containsOnly(Collections.singleton(USER_PERMISSION));
    assertThat(permissions2).extracting(p -> p.getUserPermissions().iterator().next().getRoles()).containsOnly(USER_ROLES);
    assertThat(permissions2).extracting(Permissions::getGroupPermissions).containsOnly(Collections.emptySet());
}
Also used : Response(javax.ws.rs.core.Response) UserDao(io.lumeer.storage.api.dao.UserDao) Arrays(java.util.Arrays) SoftAssertions(org.assertj.core.api.SoftAssertions) ProjectDao(io.lumeer.storage.api.dao.ProjectDao) Arquillian(org.jboss.arquillian.junit.Arquillian) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) JsonPermission(io.lumeer.api.dto.JsonPermission) User(io.lumeer.api.model.User) RunWith(org.junit.runner.RunWith) LumeerAssertions.assertPermissions(io.lumeer.test.util.LumeerAssertions.assertPermissions) JsonCollection(io.lumeer.api.dto.JsonCollection) Resource(io.lumeer.api.model.Resource) JsonPermissions(io.lumeer.api.dto.JsonPermissions) HashSet(java.util.HashSet) Inject(javax.inject.Inject) OrganizationDao(io.lumeer.storage.api.dao.OrganizationDao) MediaType(javax.ws.rs.core.MediaType) CollectionDao(io.lumeer.storage.api.dao.CollectionDao) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Role(io.lumeer.api.model.Role) JsonAttribute(io.lumeer.api.dto.JsonAttribute) JsonProject(io.lumeer.api.dto.JsonProject) SimplePermission(io.lumeer.core.model.SimplePermission) UriBuilder(javax.ws.rs.core.UriBuilder) Organization(io.lumeer.api.model.Organization) Before(org.junit.Before) Permission(io.lumeer.api.model.Permission) View(io.lumeer.api.model.View) ResourceNotFoundException(io.lumeer.storage.api.exception.ResourceNotFoundException) Permissions(io.lumeer.api.model.Permissions) JsonOrganization(io.lumeer.api.dto.JsonOrganization) AuthenticatedUser(io.lumeer.core.AuthenticatedUser) Set(java.util.Set) Test(org.junit.Test) Collectors(java.util.stream.Collectors) Entity(javax.ws.rs.client.Entity) GenericType(javax.ws.rs.core.GenericType) Project(io.lumeer.api.model.Project) List(java.util.List) Response(javax.ws.rs.core.Response) Attribute(io.lumeer.api.model.Attribute) Collections(java.util.Collections) Collection(io.lumeer.api.model.Collection) Link(javax.ws.rs.core.Link) LumeerAssertions.assertPermissions(io.lumeer.test.util.LumeerAssertions.assertPermissions) JsonPermissions(io.lumeer.api.dto.JsonPermissions) Permissions(io.lumeer.api.model.Permissions) List(java.util.List) JsonCollection(io.lumeer.api.dto.JsonCollection) Test(org.junit.Test)

Example 48 with GenericType

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

the class JAXRSClientServerBookTest method testPostGetCollectionGenericEntityAndType.

@Test
public void testPostGetCollectionGenericEntityAndType() throws Exception {
    String endpointAddress = "http://localhost:" + PORT + "/bookstore/collections";
    WebClient wc = WebClient.create(endpointAddress);
    wc.accept("application/xml").type("application/xml");
    Book b1 = new Book("CXF in Action", 123L);
    Book b2 = new Book("CXF Rocks", 124L);
    List<Book> books = new ArrayList<>();
    books.add(b1);
    books.add(b2);
    GenericEntity<List<Book>> genericCollectionEntity = new GenericEntity<List<Book>>(books) {
    };
    GenericType<List<Book>> genericResponseType = new GenericType<List<Book>>() {
    };
    List<Book> books2 = wc.post(genericCollectionEntity, genericResponseType);
    assertNotNull(books2);
    assertNotSame(books, books2);
    assertEquals(2, books2.size());
    Book b11 = books.get(0);
    assertEquals(123L, b11.getId());
    assertEquals("CXF in Action", b11.getName());
    Book b22 = books.get(1);
    assertEquals(124L, b22.getId());
    assertEquals("CXF Rocks", b22.getName());
    assertEquals(200, wc.getResponse().getStatus());
}
Also used : GenericType(javax.ws.rs.core.GenericType) GenericEntity(javax.ws.rs.core.GenericEntity) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.junit.Test)

Example 49 with GenericType

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

the class JAXRS20ClientServerBookTest method testPostGetCollectionGenericEntityAndType3.

@Test
public void testPostGetCollectionGenericEntityAndType3() throws Exception {
    String endpointAddress = "http://localhost:" + PORT + "/bookstore/collections";
    WebClient wc = WebClient.create(endpointAddress);
    wc.accept("application/xml").type("application/xml");
    GenericEntity<List<Book>> collectionEntity = createGenericEntity();
    GenericType<List<Book>> genericResponseType = new GenericType<List<Book>>() {
    };
    Future<Response> future = wc.async().post(Entity.entity(collectionEntity, "application/xml"));
    Response r = future.get();
    List<Book> books2 = r.readEntity(genericResponseType);
    assertNotNull(books2);
    List<Book> books = collectionEntity.getEntity();
    assertNotSame(books, books2);
    assertEquals(2, books2.size());
    Book b11 = books.get(0);
    assertEquals(123L, b11.getId());
    assertEquals("CXF in Action", b11.getName());
    Book b22 = books.get(1);
    assertEquals(124L, b22.getId());
    assertEquals("CXF Rocks", b22.getName());
    assertEquals(200, wc.getResponse().getStatus());
}
Also used : Response(javax.ws.rs.core.Response) GenericType(javax.ws.rs.core.GenericType) List(java.util.List) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.junit.Test)

Example 50 with GenericType

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

the class JAXRS20ClientServerBookTest method testPostGetCollectionGenericEntityAndType2.

@Test
public void testPostGetCollectionGenericEntityAndType2() throws Exception {
    String endpointAddress = "http://localhost:" + PORT + "/bookstore/collections";
    WebClient wc = WebClient.create(endpointAddress);
    wc.accept("application/xml").type("application/xml");
    GenericEntity<List<Book>> collectionEntity = createGenericEntity();
    GenericType<List<Book>> genericResponseType = new GenericType<List<Book>>() {
    };
    Future<List<Book>> future = wc.async().post(Entity.entity(collectionEntity, "application/xml"), genericResponseType);
    List<Book> books2 = future.get();
    assertNotNull(books2);
    List<Book> books = collectionEntity.getEntity();
    assertNotSame(books, books2);
    assertEquals(2, books2.size());
    Book b11 = books.get(0);
    assertEquals(123L, b11.getId());
    assertEquals("CXF in Action", b11.getName());
    Book b22 = books.get(1);
    assertEquals(124L, b22.getId());
    assertEquals("CXF Rocks", b22.getName());
    assertEquals(200, wc.getResponse().getStatus());
}
Also used : GenericType(javax.ws.rs.core.GenericType) List(java.util.List) WebClient(org.apache.cxf.jaxrs.client.WebClient) 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