Search in sources :

Example 36 with SyncopeClientException

use of org.apache.syncope.common.lib.SyncopeClientException in project syncope by apache.

the class ReportTemplateITCase method issueSYNCOPE866.

@Test
public void issueSYNCOPE866() {
    ReportTemplateTO reportTemplateTO = new ReportTemplateTO();
    reportTemplateTO.setKey("empty");
    try {
        reportTemplateService.create(reportTemplateTO);
        fail("This should not happen");
    } catch (SyncopeClientException e) {
        assertEquals(ClientExceptionType.EntityExists, e.getType());
    }
}
Also used : ReportTemplateTO(org.apache.syncope.common.lib.to.ReportTemplateTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) Test(org.junit.jupiter.api.Test)

Example 37 with SyncopeClientException

use of org.apache.syncope.common.lib.SyncopeClientException in project syncope by apache.

the class ReportTemplateITCase method crud.

@Test
public void crud() throws IOException {
    final String key = getUUIDString();
    // 1. create (empty) report template
    ReportTemplateTO reportTemplateTO = new ReportTemplateTO();
    reportTemplateTO.setKey(key);
    Response response = reportTemplateService.create(reportTemplateTO);
    assertEquals(201, response.getStatus());
    // 2. attempt to read HTML and CSV -> fail
    try {
        reportTemplateService.getFormat(key, ReportTemplateFormat.HTML);
        fail("This should not happen");
    } catch (SyncopeClientException e) {
        assertEquals(ClientExceptionType.NotFound, e.getType());
    }
    try {
        reportTemplateService.getFormat(key, ReportTemplateFormat.CSV);
        fail("This should not happen");
    } catch (SyncopeClientException e) {
        assertEquals(ClientExceptionType.NotFound, e.getType());
    }
    // 3. set CSV
    String csvTemplate = "<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'></xsl:stylesheet>";
    reportTemplateService.setFormat(key, ReportTemplateFormat.CSV, IOUtils.toInputStream(csvTemplate, StandardCharsets.UTF_8));
    response = reportTemplateService.getFormat(key, ReportTemplateFormat.CSV);
    assertEquals(200, response.getStatus());
    assertTrue(response.getMediaType().toString().startsWith(MediaType.APPLICATION_XML));
    assertTrue(response.getEntity() instanceof InputStream);
    assertEquals(csvTemplate, IOUtils.toString((InputStream) response.getEntity(), StandardCharsets.UTF_8));
    // 3. set HTML
    String htmlTemplate = "<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'></xsl:stylesheet>";
    reportTemplateService.setFormat(key, ReportTemplateFormat.HTML, IOUtils.toInputStream(htmlTemplate, StandardCharsets.UTF_8));
    response = reportTemplateService.getFormat(key, ReportTemplateFormat.HTML);
    assertEquals(200, response.getStatus());
    assertTrue(response.getMediaType().toString().startsWith(MediaType.APPLICATION_XML));
    assertTrue(response.getEntity() instanceof InputStream);
    assertEquals(htmlTemplate, IOUtils.toString((InputStream) response.getEntity(), StandardCharsets.UTF_8));
    // 4. remove HTML
    reportTemplateService.removeFormat(key, ReportTemplateFormat.HTML);
    try {
        reportTemplateService.getFormat(key, ReportTemplateFormat.HTML);
        fail("This should not happen");
    } catch (SyncopeClientException e) {
        assertEquals(ClientExceptionType.NotFound, e.getType());
    }
    response = reportTemplateService.getFormat(key, ReportTemplateFormat.CSV);
    assertEquals(200, response.getStatus());
    assertTrue(response.getMediaType().toString().startsWith(MediaType.APPLICATION_XML));
    assertTrue(response.getEntity() instanceof InputStream);
    assertEquals(csvTemplate, IOUtils.toString((InputStream) response.getEntity(), StandardCharsets.UTF_8));
    // 5. remove report template
    reportTemplateService.delete(key);
    try {
        reportTemplateService.read(key);
        fail("This should not happen");
    } catch (SyncopeClientException e) {
        assertEquals(ClientExceptionType.NotFound, e.getType());
    }
    try {
        reportTemplateService.getFormat(key, ReportTemplateFormat.HTML);
        fail("This should not happen");
    } catch (SyncopeClientException e) {
        assertEquals(ClientExceptionType.NotFound, e.getType());
    }
    try {
        reportTemplateService.getFormat(key, ReportTemplateFormat.CSV);
        fail("This should not happen");
    } catch (SyncopeClientException e) {
        assertEquals(ClientExceptionType.NotFound, e.getType());
    }
}
Also used : Response(javax.ws.rs.core.Response) ReportTemplateTO(org.apache.syncope.common.lib.to.ReportTemplateTO) InputStream(java.io.InputStream) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) Test(org.junit.jupiter.api.Test)

Example 38 with SyncopeClientException

use of org.apache.syncope.common.lib.SyncopeClientException in project syncope by apache.

the class ResourceITCase method listConnObjects.

@Test
public void listConnObjects() {
    List<String> groupKeys = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        GroupTO group = GroupITCase.getSampleTO("group");
        group.getResources().add(RESOURCE_NAME_LDAP);
        group = createGroup(group).getEntity();
        groupKeys.add(group.getKey());
    }
    int totalRead = 0;
    Set<String> read = new HashSet<>();
    try {
        ConnObjectTOListQuery.Builder builder = new ConnObjectTOListQuery.Builder().size(10);
        PagedConnObjectTOResult list;
        do {
            list = null;
            boolean succeeded = false;
            // needed because ApacheDS seems to randomly fail when searching with cookie
            for (int i = 0; i < 5 && !succeeded; i++) {
                try {
                    list = resourceService.listConnObjects(RESOURCE_NAME_LDAP, AnyTypeKind.GROUP.name(), builder.build());
                    succeeded = true;
                } catch (SyncopeClientException e) {
                    assertEquals(ClientExceptionType.ConnectorException, e.getType());
                }
            }
            assertNotNull(list);
            totalRead += list.getResult().size();
            read.addAll(list.getResult().stream().map(input -> input.getAttr(ConnIdSpecialName.NAME).get().getValues().get(0)).collect(Collectors.toList()));
            if (list.getPagedResultsCookie() != null) {
                builder.pagedResultsCookie(list.getPagedResultsCookie());
            }
        } while (list.getPagedResultsCookie() != null);
        assertEquals(totalRead, read.size());
        assertTrue(totalRead >= 10);
    } finally {
        groupKeys.forEach(key -> {
            groupService.delete(key);
        });
    }
}
Also used : ArrayList(java.util.ArrayList) ConnObjectTOListQuery(org.apache.syncope.common.rest.api.beans.ConnObjectTOListQuery) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) PagedConnObjectTOResult(org.apache.syncope.common.lib.to.PagedConnObjectTOResult) GroupTO(org.apache.syncope.common.lib.to.GroupTO) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 39 with SyncopeClientException

use of org.apache.syncope.common.lib.SyncopeClientException in project syncope by apache.

the class ResourceITCase method delete.

@Test
public void delete() {
    String resourceKey = "tobedeleted";
    ResourceTO resource = buildResourceTO(resourceKey);
    Response response = resourceService.create(resource);
    ResourceTO actual = getObject(response.getLocation(), ResourceService.class, ResourceTO.class);
    assertNotNull(actual);
    resourceService.delete(resourceKey);
    try {
        resourceService.read(resourceKey);
        fail("This should not happen");
    } catch (SyncopeClientException e) {
        assertEquals(Response.Status.NOT_FOUND, e.getType().getResponseStatus());
    }
}
Also used : Response(javax.ws.rs.core.Response) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) Test(org.junit.jupiter.api.Test)

Example 40 with SyncopeClientException

use of org.apache.syncope.common.lib.SyncopeClientException in project syncope by apache.

the class ResourceITCase method createWithInvalidMapping.

@Test
public void createWithInvalidMapping() {
    String resourceKey = RESOURCE_NAME_CREATE_WRONG;
    ResourceTO resourceTO = new ResourceTO();
    resourceTO.setKey(resourceKey);
    resourceTO.setConnector("5ffbb4ac-a8c3-4b44-b699-11b398a1ba08");
    ProvisionTO provisionTO = new ProvisionTO();
    provisionTO.setAnyType(AnyTypeKind.USER.name());
    provisionTO.setObjectClass(ObjectClass.ACCOUNT_NAME);
    resourceTO.getProvisions().add(provisionTO);
    MappingTO mapping = new MappingTO();
    provisionTO.setMapping(mapping);
    ItemTO item = new ItemTO();
    item.setIntAttrName("key");
    item.setExtAttrName("userId");
    item.setConnObjectKey(true);
    mapping.setConnObjectKeyItem(item);
    item = new ItemTO();
    item.setExtAttrName("email");
    // missing intAttrName ...
    mapping.add(item);
    try {
        createResource(resourceTO);
        fail("Create should not have worked");
    } catch (SyncopeClientException e) {
        assertEquals(ClientExceptionType.RequiredValuesMissing, e.getType());
        assertEquals("intAttrName", e.getElements().iterator().next());
    }
}
Also used : MappingTO(org.apache.syncope.common.lib.to.MappingTO) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO) ItemTO(org.apache.syncope.common.lib.to.ItemTO) Test(org.junit.jupiter.api.Test)

Aggregations

SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)240 Test (org.junit.jupiter.api.Test)105 UserTO (org.apache.syncope.common.lib.to.UserTO)50 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)42 NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)40 Response (javax.ws.rs.core.Response)34 ResourceTO (org.apache.syncope.common.lib.to.ResourceTO)20 PlainSchemaTO (org.apache.syncope.common.lib.to.PlainSchemaTO)19 MembershipTO (org.apache.syncope.common.lib.to.MembershipTO)18 Realm (org.apache.syncope.core.persistence.api.entity.Realm)18 GroupTO (org.apache.syncope.common.lib.to.GroupTO)17 ClientExceptionType (org.apache.syncope.common.lib.types.ClientExceptionType)16 AttrTO (org.apache.syncope.common.lib.to.AttrTO)15 Map (java.util.Map)14 SyncopeClientCompositeException (org.apache.syncope.common.lib.SyncopeClientCompositeException)14 ArrayList (java.util.ArrayList)12 List (java.util.List)12 ItemTO (org.apache.syncope.common.lib.to.ItemTO)12 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)12 AnyObjectTO (org.apache.syncope.common.lib.to.AnyObjectTO)11