1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.openehealth.ipf.commons.ihe.core;
17
18 import lombok.AllArgsConstructor;
19 import lombok.Getter;
20 import org.junit.Test;
21 import org.openehealth.ipf.commons.core.config.SimpleRegistry;
22
23 import java.io.ByteArrayInputStream;
24 import java.io.ByteArrayOutputStream;
25 import java.io.IOException;
26 import java.io.ObjectInputStream;
27 import java.io.ObjectOutputStream;
28 import java.util.Arrays;
29 import java.util.List;
30
31 import static org.junit.Assert.assertFalse;
32 import static org.junit.Assert.assertSame;
33 import static org.junit.Assert.assertTrue;
34 import static org.openehealth.ipf.commons.ihe.core.InteractionIdTest.MyIntegrationProfile.Interactions.Interaction1;
35 import static org.openehealth.ipf.commons.ihe.core.InteractionIdTest.MyIntegrationProfile.Interactions.Interaction2;
36
37
38
39
40 public class InteractionIdTest {
41
42 @Test
43 public void testIsProfileFor() {
44 assertTrue(MY_INSTANCE.isProfileFor(Interaction1));
45 assertFalse(OTHER_INSTANCE.isProfileFor(Interaction1));
46 }
47
48 @Test
49 public void testGetInteractionIds() {
50 assertTrue(MY_INSTANCE.getInteractionIds().contains(Interaction1));
51 assertTrue(MY_INSTANCE.getInteractionIds().contains(Interaction2));
52 assertFalse(OTHER_INSTANCE.getInteractionIds().contains(Interaction1));
53 }
54
55 @Test
56 public void testReconstruct() throws IOException, ClassNotFoundException {
57
58 MyIntegrationProfile.Interactions original = Interaction1;
59 SerializableEnumInteractionId<?> serializableEnumInteractionId = SerializableEnumInteractionId.create(original);
60 ByteArrayOutputStream baos = new ByteArrayOutputStream();
61 ObjectOutputStream oos = new ObjectOutputStream(baos);
62 oos.writeObject(serializableEnumInteractionId);
63
64 ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
65 ObjectInputStream ois = new ObjectInputStream(bais);
66 SerializableEnumInteractionId<?> deserialized = (SerializableEnumInteractionId<?>) ois.readObject();
67
68 assertSame(original, deserialized.getInteractionId());
69 }
70
71 private static final MyIntegrationProfile MY_INSTANCE = new MyIntegrationProfile();
72 private static final SimpleRegistry SIMPLE_REGISTRY = new SimpleRegistry();
73
74
75 static class MyIntegrationProfile implements IntegrationProfile {
76
77 @AllArgsConstructor
78 enum Interactions implements InteractionId {
79
80 Interaction1("int1", "description1"),
81 Interaction2("int2", "description2");
82
83 @Getter
84 private String name;
85 @Getter
86 private String description;
87
88 }
89
90 @Override
91 public List<InteractionId> getInteractionIds() {
92 return Arrays.asList(Interactions.values());
93 }
94
95 }
96
97 private static final OtherIntegrationProfile OTHER_INSTANCE = new OtherIntegrationProfile();
98
99 static class OtherIntegrationProfile implements IntegrationProfile {
100
101 @AllArgsConstructor
102 enum Interactions implements InteractionId {
103
104 Interaction3("int3", "description3"),
105 Interaction4("int4", "description4");
106
107 @Getter
108 private String name;
109 @Getter
110 private String description;
111
112 }
113
114 @Override
115 public List<InteractionId> getInteractionIds() {
116 return Arrays.asList(Interactions.values());
117 }
118
119 }
120 }