View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
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.fail;
25  
26  import java.util.List;
27  import javax.ws.rs.core.Response;
28  import org.apache.syncope.common.lib.SyncopeClientException;
29  import org.apache.syncope.common.lib.to.RelationshipTypeTO;
30  import org.apache.syncope.common.lib.types.ClientExceptionType;
31  import org.apache.syncope.common.rest.api.service.RelationshipTypeService;
32  import org.apache.syncope.fit.AbstractITCase;
33  import org.junit.jupiter.api.Test;
34  
35  public class RelationshipTypeITCase extends AbstractITCase {
36  
37      @Test
38      public void read() {
39          RelationshipTypeTO otherType = RELATIONSHIP_TYPE_SERVICE.read("inclusion");
40          assertNotNull(otherType);
41          assertEquals("inclusion", otherType.getKey());
42      }
43  
44      @Test
45      public void list() {
46          List<RelationshipTypeTO> list = RELATIONSHIP_TYPE_SERVICE.list();
47          assertFalse(list.isEmpty());
48      }
49  
50      @Test
51      public void crud() {
52          RelationshipTypeTO newType = new RelationshipTypeTO();
53          newType.setKey("new type");
54          newType.setDescription("description");
55  
56          Response response = RELATIONSHIP_TYPE_SERVICE.create(newType);
57          assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatusInfo().getStatusCode());
58  
59          newType = getObject(response.getLocation(), RelationshipTypeService.class, RelationshipTypeTO.class);
60          assertNotNull(newType);
61          assertEquals("description", newType.getDescription());
62  
63          newType.setDescription("new description");
64          RELATIONSHIP_TYPE_SERVICE.update(newType);
65  
66          newType = RELATIONSHIP_TYPE_SERVICE.read(newType.getKey());
67          assertNotNull(newType);
68          assertEquals("new description", newType.getDescription());
69  
70          RELATIONSHIP_TYPE_SERVICE.delete(newType.getKey());
71  
72          try {
73              RELATIONSHIP_TYPE_SERVICE.read(newType.getKey());
74              fail("This should not happen");
75          } catch (SyncopeClientException e) {
76              assertEquals(ClientExceptionType.NotFound, e.getType());
77          }
78      }
79  
80      @Test
81      public void createInvalidName() {
82          RelationshipTypeTO newType = new RelationshipTypeTO();
83          newType.setKey("membership");
84          try {
85              RELATIONSHIP_TYPE_SERVICE.create(newType);
86              fail("This should not happen");
87          } catch (SyncopeClientException e) {
88              assertEquals(ClientExceptionType.InvalidRelationshipType, e.getType());
89          }
90      }
91  }