Skip to content

Commit fc437f5

Browse files
rogintonygermano
authored andcommitted
Add DestinationSetTest.java
This adds several tests for the DestinationSet.removeAllExcept(Object) method, and confirms a bug exists. Signed-off-by: Richard Ogin <[email protected]> Issue: nextgenhealthcare/connect#5875
1 parent 7178846 commit fc437f5

File tree

1 file changed

+104
-0
lines changed

1 file changed

+104
-0
lines changed
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
// SPDX-License-Identifier: MPL-2.0
2+
// SPDX-FileCopyrightText: 2025 Richard Ogin
3+
4+
package com.mirth.connect.server.userutil;
5+
6+
import static org.junit.Assert.assertFalse;
7+
import static org.junit.Assert.assertTrue;
8+
9+
import java.util.HashMap;
10+
import java.util.HashSet;
11+
import java.util.Map;
12+
import java.util.Set;
13+
14+
import org.junit.Test;
15+
16+
import com.mirth.connect.donkey.model.message.ConnectorMessage;
17+
import com.mirth.connect.donkey.server.Constants;
18+
import com.mirth.connect.userutil.ImmutableConnectorMessage;
19+
20+
public class DestinationSetTest {
21+
private Set<Integer> createMetadataIds() {
22+
Set<Integer> metaDataIds = new HashSet<>();
23+
metaDataIds.add(1);
24+
metaDataIds.add(3);
25+
metaDataIds.add(5);
26+
metaDataIds.add(7);
27+
metaDataIds.add(9);
28+
29+
return metaDataIds;
30+
}
31+
32+
private Map<String, Integer> createDestinationIdMap() {
33+
Map<String, Integer> destinationIdMap = new HashMap<>();
34+
destinationIdMap.put("One", 1);
35+
destinationIdMap.put("Three", 3);
36+
destinationIdMap.put("Five", 5);
37+
destinationIdMap.put("Seven", 7);
38+
destinationIdMap.put("Nine", 9);
39+
40+
return destinationIdMap;
41+
}
42+
43+
private ImmutableConnectorMessage createMessage(Map<String, Integer> destinationIdMap, Set<Integer> metadataIds) {
44+
ConnectorMessage cm = new ConnectorMessage();
45+
46+
if(metadataIds != null) {
47+
cm.getSourceMap().put(Constants.DESTINATION_SET_KEY, metadataIds);
48+
}
49+
50+
if(destinationIdMap != null) {
51+
return new ImmutableConnectorMessage(cm,true, destinationIdMap);
52+
} else {
53+
return new ImmutableConnectorMessage(cm, true);
54+
}
55+
}
56+
57+
@Test
58+
public void test_removeAllExceptObject_withSourceMap_removeAllForMetadataIdWhichDoesNotExist() throws Exception {
59+
Set<Integer> metaDataIds = createMetadataIds();
60+
DestinationSet destinationSet = new DestinationSet(createMessage(createDestinationIdMap(), metaDataIds));
61+
62+
assertTrue(destinationSet.removeAllExcept("I_DONT_EXIST"));
63+
assertTrue(metaDataIds.isEmpty());
64+
}
65+
66+
@Test
67+
public void test_removeAllExceptObject_withSourceMap_removeForMatchingMetadataId() throws Exception {
68+
Set<Integer> metaDataIds = createMetadataIds();
69+
DestinationSet destinationSet = new DestinationSet(createMessage(createDestinationIdMap(), metaDataIds));
70+
71+
assertTrue(destinationSet.removeAllExcept(3));
72+
assertTrue(metaDataIds.size() == 1);
73+
}
74+
75+
@Test
76+
public void test_removeAllExceptObject_withSourceMap_removeForMatchingConnectorName() throws Exception {
77+
Set<Integer> metaDataIds = createMetadataIds();
78+
DestinationSet destinationSet = new DestinationSet(createMessage(createDestinationIdMap(), metaDataIds));
79+
80+
assertTrue(destinationSet.removeAllExcept("Seven"));
81+
assertTrue(metaDataIds.size() == 1);
82+
}
83+
84+
@Test
85+
public void test_removeAllExceptObject_noSourceMap_noRemovalForMetadataIdWhichDoesNotExist() throws Exception {
86+
DestinationSet destinationSet = new DestinationSet(createMessage(createDestinationIdMap(), null));
87+
88+
assertFalse(destinationSet.removeAllExcept("I_DONT_EXIST"));
89+
}
90+
91+
@Test
92+
public void test_removeAllExceptObject_noSourceMap_noRemovalForMatchingMetadataId() throws Exception {
93+
DestinationSet destinationSet = new DestinationSet(createMessage(createDestinationIdMap(), null));
94+
95+
assertFalse(destinationSet.removeAllExcept(3));
96+
}
97+
98+
@Test
99+
public void test_removeAllExceptObject_noSourceMap_noRemovalForMatchingConnectorName() throws Exception {
100+
DestinationSet destinationSet = new DestinationSet(createMessage(createDestinationIdMap(), null));
101+
102+
assertFalse(destinationSet.removeAllExcept("Seven"));
103+
}
104+
}

0 commit comments

Comments
 (0)