Search in sources :

Example 1 with DelegateNode

use of org.ligoj.app.model.DelegateNode in project ligoj-api by ligoj.

the class DelegateNodeResource method findAll.

/**
 * Retrieve all elements with pagination
 *
 * @param uriInfo
 *            pagination data.
 * @param criteria
 *            Optional text to match.
 * @return all elements with pagination.
 */
@GET
public TableItem<DelegateNode> findAll(@Context final UriInfo uriInfo, @QueryParam(DataTableAttributes.SEARCH) final String criteria) {
    final PageRequest pageRequest = paginationJson.getPageRequest(uriInfo, ORDERED_COLUMNS);
    final Page<DelegateNode> findAll = repository.findAll(securityHelper.getLogin(), StringUtils.trimToNull(criteria), pageRequest);
    // apply pagination and prevent lazy initialization issue
    return paginationJson.applyPagination(uriInfo, findAll, Function.identity());
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) DelegateNode(org.ligoj.app.model.DelegateNode) GET(javax.ws.rs.GET)

Example 2 with DelegateNode

use of org.ligoj.app.model.DelegateNode in project ligoj-api by ligoj.

the class DelegateNodeResourceTest method createNotExistsUser.

@Test
public void createNotExistsUser() {
    initSpringSecurityContext("any");
    final DelegateNode delegate = new DelegateNode();
    delegate.setNode("service");
    delegate.setReceiver("user1");
    Assertions.assertThrows(NotFoundException.class, () -> {
        resource.create(delegate);
    });
}
Also used : DelegateNode(org.ligoj.app.model.DelegateNode) AbstractJpaTest(org.ligoj.bootstrap.AbstractJpaTest) Test(org.junit.jupiter.api.Test)

Example 3 with DelegateNode

use of org.ligoj.app.model.DelegateNode in project ligoj-api by ligoj.

the class DelegateNodeResourceTest method createNoRightAtThisLevel2.

@Test
public void createNoRightAtThisLevel2() {
    initSpringSecurityContext("user1");
    final DelegateNode delegate = new DelegateNode();
    delegate.setNode("");
    delegate.setReceiver("user1");
    Assertions.assertThrows(NotFoundException.class, () -> {
        resource.create(delegate);
    });
}
Also used : DelegateNode(org.ligoj.app.model.DelegateNode) AbstractJpaTest(org.ligoj.bootstrap.AbstractJpaTest) Test(org.junit.jupiter.api.Test)

Example 4 with DelegateNode

use of org.ligoj.app.model.DelegateNode in project ligoj-api by ligoj.

the class DelegateNodeResourceTest method findAllCriteriaUser.

@Test
public void findAllCriteriaUser() {
    final TableItem<DelegateNode> items = resource.findAll(newUriInfo(), "junit");
    Assertions.assertEquals(1, items.getData().size());
    Assertions.assertEquals(1, items.getRecordsFiltered());
    Assertions.assertEquals(1, items.getRecordsTotal());
    final DelegateNode delegateNode = items.getData().get(0);
    Assertions.assertEquals("junit", delegateNode.getReceiver());
    Assertions.assertEquals(ReceiverType.USER, delegateNode.getReceiverType());
    Assertions.assertEquals("service", delegateNode.getName());
    Assertions.assertTrue(delegateNode.isCanAdmin());
    Assertions.assertTrue(delegateNode.isCanWrite());
    Assertions.assertTrue(delegateNode.isCanSubscribe());
}
Also used : DelegateNode(org.ligoj.app.model.DelegateNode) AbstractJpaTest(org.ligoj.bootstrap.AbstractJpaTest) Test(org.junit.jupiter.api.Test)

Example 5 with DelegateNode

use of org.ligoj.app.model.DelegateNode in project ligoj-api by ligoj.

the class DelegateNodeResourceTest method createNoRightAtThisLevel.

@Test
public void createNoRightAtThisLevel() {
    initSpringSecurityContext("user1");
    final DelegateNode delegate = new DelegateNode();
    delegate.setNode("service:build");
    delegate.setReceiver("user1");
    Assertions.assertThrows(NotFoundException.class, () -> {
        resource.create(delegate);
    });
}
Also used : DelegateNode(org.ligoj.app.model.DelegateNode) AbstractJpaTest(org.ligoj.bootstrap.AbstractJpaTest) Test(org.junit.jupiter.api.Test)

Aggregations

DelegateNode (org.ligoj.app.model.DelegateNode)15 Test (org.junit.jupiter.api.Test)14 AbstractJpaTest (org.ligoj.bootstrap.AbstractJpaTest)14 GET (javax.ws.rs.GET)1 UriInfo (javax.ws.rs.core.UriInfo)1 PageRequest (org.springframework.data.domain.PageRequest)1