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.assertFalse;
22  import static org.junit.jupiter.api.Assertions.assertNotNull;
23  import static org.junit.jupiter.api.Assertions.assertTrue;
24  import static org.junit.jupiter.api.Assumptions.assumeFalse;
25  import static org.junit.jupiter.api.Assumptions.assumeTrue;
26  
27  import java.io.IOException;
28  import javax.ws.rs.core.Response;
29  import org.apache.syncope.client.lib.SyncopeClientFactoryBean;
30  import org.apache.syncope.common.lib.to.BpmnProcess;
31  import org.apache.syncope.fit.AbstractITCase;
32  import org.junit.jupiter.api.BeforeAll;
33  import org.junit.jupiter.api.BeforeEach;
34  import org.junit.jupiter.api.Test;
35  
36  public class BpmnProcessITCase extends AbstractITCase {
37  
38      private static String USER_WORKFLOW_KEY = null;
39  
40      @BeforeAll
41      public static void findDefault() {
42          assumeFalse(CLIENT_FACTORY.getContentType() == SyncopeClientFactoryBean.ContentType.YAML);
43          assumeTrue(IS_FLOWABLE_ENABLED);
44  
45          BPMN_PROCESS_SERVICE.list().stream().
46                  filter(BpmnProcess::isUserWorkflow).findAny().
47                  ifPresent(process -> USER_WORKFLOW_KEY = process.getKey());
48          assertNotNull(USER_WORKFLOW_KEY);
49      }
50  
51      @BeforeEach
52      public void check() {
53          assumeFalse(CLIENT_FACTORY.getContentType() == SyncopeClientFactoryBean.ContentType.YAML);
54          assumeTrue(IS_FLOWABLE_ENABLED);
55      }
56  
57      @Test
58      public void exportUserWorkflowProcess() throws IOException {
59          Response response = BPMN_PROCESS_SERVICE.get(USER_WORKFLOW_KEY);
60          assertTrue(response.getMediaType().toString().
61                  startsWith(CLIENT_FACTORY.getContentType().getMediaType().toString()));
62          String definition = response.readEntity(String.class);
63          assertNotNull(definition);
64          assertFalse(definition.isEmpty());
65      }
66  
67      @Test
68      public void updateUserWorkflowProcess() throws IOException {
69          Response response = BPMN_PROCESS_SERVICE.get(USER_WORKFLOW_KEY);
70          String definition = response.readEntity(String.class);
71  
72          BPMN_PROCESS_SERVICE.set(USER_WORKFLOW_KEY, definition);
73      }
74  }