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.core.provisioning.api.job;
20  
21  import static org.junit.jupiter.api.Assertions.assertEquals;
22  import static org.junit.jupiter.api.Assertions.assertNull;
23  import static org.junit.jupiter.api.Assertions.assertTrue;
24  import static org.mockito.Mockito.when;
25  
26  import java.util.UUID;
27  import org.apache.commons.lang3.builder.EqualsBuilder;
28  import org.apache.syncope.core.persistence.api.entity.Report;
29  import org.apache.syncope.core.persistence.api.entity.task.Task;
30  import org.apache.syncope.core.provisioning.api.AbstractTest;
31  import org.junit.jupiter.api.Test;
32  import org.mockito.Mock;
33  import org.quartz.JobKey;
34  import org.quartz.Scheduler;
35  
36  public class JobNamerTest extends AbstractTest {
37  
38      private String name;
39  
40      @Test
41      public void getTaskKeyFromJobName() {
42          name = "testName";
43          assertNull(JobNamer.getTaskKeyFromJobName(name));
44  
45          String uuid = UUID.randomUUID().toString();
46          name = String.format("taskJob%s", uuid);
47          assertEquals(uuid, JobNamer.getTaskKeyFromJobName(name));
48      }
49  
50      @Test
51      public void getReportKeyFromJobName() {
52          name = "testName";
53          assertNull(JobNamer.getTaskKeyFromJobName(name));
54  
55          String uuid = UUID.randomUUID().toString();
56          name = String.format("reportJob%s", uuid);
57          assertEquals(uuid, JobNamer.getReportKeyFromJobName(name));
58      }
59  
60      @Test
61      public void getJobKey(final @Mock Task<?> task) {
62          String uuid = UUID.randomUUID().toString();
63          when(task.getKey()).thenReturn(uuid);
64          assertTrue(EqualsBuilder.reflectionEquals(new JobKey("taskJob" + task.getKey(), Scheduler.DEFAULT_GROUP),
65                  JobNamer.getJobKey(task)));
66      }
67  
68      @Test
69      public void getJobKey(final @Mock Report report) {
70          String uuid = UUID.randomUUID().toString();
71          when(report.getKey()).thenReturn(uuid);
72          assertTrue(EqualsBuilder.reflectionEquals(new JobKey("reportJob" + report.getKey(), Scheduler.DEFAULT_GROUP),
73                  JobNamer.getJobKey(report)));
74      }
75  
76      @Test
77      public void getTriggerName() {
78          String jobName = "testJobName";
79          assertEquals("Trigger_" + jobName, JobNamer.getTriggerName(jobName));
80      }
81  }