-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathJobDetailMixinTest.java
58 lines (48 loc) · 1.97 KB
/
JobDetailMixinTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package net.joelinn.quartz.mixin;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import net.joelinn.quartz.TestJob;
import net.joelinn.quartz.jobstore.mixin.JobDetailMixin;
import org.junit.Before;
import org.junit.Test;
import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.impl.JobDetailImpl;
import java.util.HashMap;
import java.util.Map;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.collection.IsMapContaining.hasKey;
import static org.junit.Assert.assertEquals;
/**
* Joe Linn
* 7/15/2014
*/
public class JobDetailMixinTest {
protected ObjectMapper mapper;
@Before
public void setUp(){
mapper = new ObjectMapper();
mapper.addMixIn(JobDetail.class, JobDetailMixin.class);
}
@Test
public void serializeJobDetail() throws Exception {
JobDetail testJob = JobBuilder.newJob(TestJob.class)
.withIdentity("testJob", "testGroup")
.usingJobData("timeout", 42)
.withDescription("I am describing a job!")
.build();
String json = mapper.writeValueAsString(testJob);
HashMap<String, String> jsonMap = mapper.readValue(json, new TypeReference<HashMap<String, String>>() {
});
assertThat(jsonMap, hasKey("name"));
assertEquals(testJob.getKey().getName(), jsonMap.get("name"));
assertThat(jsonMap, hasKey("group"));
assertEquals(testJob.getKey().getGroup(), jsonMap.get("group"));
assertThat(jsonMap, hasKey("jobClass"));
assertEquals(testJob.getJobClass().getName(), jsonMap.get("jobClass"));
JobDetailImpl jobDetail = mapper.readValue(json, JobDetailImpl.class);
assertEquals(testJob.getKey().getName(), jobDetail.getKey().getName());
assertEquals(testJob.getKey().getGroup(), jobDetail.getKey().getGroup());
assertEquals(testJob.getJobClass(), jobDetail.getJobClass());
}
}