1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.syncope.fit.core;
20
21 import static org.junit.jupiter.api.Assertions.assertEquals;
22 import static org.junit.jupiter.api.Assertions.assertFalse;
23 import static org.junit.jupiter.api.Assertions.assertNotNull;
24 import static org.junit.jupiter.api.Assertions.assertTrue;
25 import static org.junit.jupiter.api.Assertions.fail;
26
27 import java.util.List;
28 import java.util.Locale;
29 import javax.ws.rs.core.Response;
30 import org.apache.syncope.common.lib.SyncopeClientException;
31 import org.apache.syncope.common.lib.to.ResourceTO;
32 import org.apache.syncope.common.lib.to.VirSchemaTO;
33 import org.apache.syncope.common.lib.types.ClientExceptionType;
34 import org.apache.syncope.common.lib.types.EntityViolationType;
35 import org.apache.syncope.common.lib.types.SchemaType;
36 import org.apache.syncope.common.rest.api.beans.SchemaQuery;
37 import org.apache.syncope.common.rest.api.service.SchemaService;
38 import org.apache.syncope.fit.AbstractITCase;
39 import org.junit.jupiter.api.Assertions;
40 import org.junit.jupiter.api.Test;
41
42 public class VirSchemaITCase extends AbstractITCase {
43
44 @Test
45 public void search() {
46 List<VirSchemaTO> schemas = SCHEMA_SERVICE.search(new SchemaQuery.Builder().type(SchemaType.VIRTUAL).build());
47 assertFalse(schemas.isEmpty());
48 schemas.forEach(Assertions::assertNotNull);
49
50 schemas = SCHEMA_SERVICE.search(
51 new SchemaQuery.Builder().type(SchemaType.VIRTUAL).keyword("rvirtual*").build());
52 assertFalse(schemas.isEmpty());
53 schemas.forEach(Assertions::assertNotNull);
54 }
55
56 @Test
57 public void crud() {
58 ResourceTO csv = RESOURCE_SERVICE.read(RESOURCE_NAME_CSV);
59 assertNotNull(csv);
60 assertEquals(1, csv.getProvisions().size());
61 assertTrue(csv.getProvisions().get(0).getVirSchemas().isEmpty());
62
63 VirSchemaTO schema = new VirSchemaTO();
64 schema.setKey("virtualTest" + getUUIDString());
65 schema.setExtAttrName("name");
66 schema.setResource(RESOURCE_NAME_CSV);
67 schema.setAnyType(csv.getProvisions().get(0).getAnyType());
68 schema.getLabels().put(Locale.ENGLISH, "Virtual");
69
70 schema = createSchema(SchemaType.VIRTUAL, schema);
71 assertNotNull(schema);
72 assertEquals(csv.getProvisions().get(0).getAnyType(), schema.getAnyType());
73 assertEquals(1, schema.getLabels().size());
74 assertEquals("Virtual", schema.getLabel(Locale.ENGLISH));
75 assertEquals(schema.getKey(), schema.getLabel(Locale.CHINESE));
76
77 csv = RESOURCE_SERVICE.read(RESOURCE_NAME_CSV);
78 assertNotNull(csv);
79 assertEquals(1, csv.getProvisions().size());
80 assertFalse(csv.getProvisions().get(0).getVirSchemas().isEmpty());
81
82 schema = SCHEMA_SERVICE.read(SchemaType.VIRTUAL, schema.getKey());
83 assertNotNull(schema);
84
85 SCHEMA_SERVICE.delete(SchemaType.VIRTUAL, schema.getKey());
86
87 try {
88 SCHEMA_SERVICE.read(SchemaType.VIRTUAL, schema.getKey());
89 fail("This should not happen");
90 } catch (SyncopeClientException e) {
91 assertEquals(ClientExceptionType.NotFound, e.getType());
92 }
93
94 csv = RESOURCE_SERVICE.read(RESOURCE_NAME_CSV);
95 assertNotNull(csv);
96 assertEquals(1, csv.getProvisions().size());
97 assertTrue(csv.getProvisions().get(0).getVirSchemas().isEmpty());
98 }
99
100 @Test
101 public void anonymous() {
102 SchemaService anonymous = ANONYMOUS_CLIENT.getService(SchemaService.class);
103 assertFalse(anonymous.search(new SchemaQuery.Builder().type(SchemaType.VIRTUAL).build()).isEmpty());
104 }
105
106 @Test
107 public void issueSYNCOPE323() {
108 VirSchemaTO actual = SCHEMA_SERVICE.read(SchemaType.VIRTUAL, "virtualdata");
109 assertNotNull(actual);
110
111 try {
112 createSchema(SchemaType.VIRTUAL, actual);
113 fail("This should not happen");
114 } catch (SyncopeClientException e) {
115 assertEquals(Response.Status.CONFLICT, e.getType().getResponseStatus());
116 assertEquals(ClientExceptionType.EntityExists, e.getType());
117 }
118
119 actual.setKey(null);
120 try {
121 createSchema(SchemaType.VIRTUAL, actual);
122 fail("This should not happen");
123 } catch (SyncopeClientException e) {
124 assertEquals(Response.Status.BAD_REQUEST, e.getType().getResponseStatus());
125 assertEquals(ClientExceptionType.RequiredValuesMissing, e.getType());
126 }
127 }
128
129 @Test
130 public void issueSYNCOPE418() {
131 ResourceTO ws1 = RESOURCE_SERVICE.read(RESOURCE_NAME_WS1);
132 assertNotNull(ws1);
133 assertEquals(1, ws1.getProvisions().size());
134 assertTrue(ws1.getProvisions().get(0).getVirSchemas().isEmpty());
135
136 VirSchemaTO schema = new VirSchemaTO();
137 schema.setKey("http://schemas.examples.org/security/authorization/organizationUnit");
138 schema.setExtAttrName("name");
139 schema.setResource(RESOURCE_NAME_WS1);
140 schema.setAnyType(ws1.getProvisions().get(0).getAnyType());
141
142 try {
143 createSchema(SchemaType.VIRTUAL, schema);
144 fail("This should not happen");
145 } catch (SyncopeClientException e) {
146 assertEquals(ClientExceptionType.InvalidVirSchema, e.getType());
147
148 assertTrue(e.getElements().iterator().next().contains(EntityViolationType.InvalidKey.name()));
149 }
150 }
151 }