Skip to content

Commit 6afffe1

Browse files
Fix JSON string comparision fin tests (#8183)
1 parent a7c6599 commit 6afffe1

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

server/src/test/java/com/cloud/server/StatsCollectorTest.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
import java.util.List;
6363
import java.util.Map;
6464
import java.util.Properties;
65+
import java.util.TreeMap;
6566
import java.util.concurrent.TimeUnit;
6667

6768
import static org.mockito.Mockito.when;
@@ -330,7 +331,7 @@ public void persistVirtualMachineStatsTestPersistsSuccessfully() {
330331
VmStatsVO actual = vmStatsVOCaptor.getAllValues().get(0);
331332
Assert.assertEquals(Long.valueOf(2L), actual.getVmId());
332333
Assert.assertEquals(Long.valueOf(1L), actual.getMgmtServerId());
333-
Assert.assertEquals(expectedVmStatsStr, actual.getVmStatsData());
334+
Assert.assertEquals(convertJsonToOrderedMap(expectedVmStatsStr), convertJsonToOrderedMap(actual.getVmStatsData()));
334335
Assert.assertEquals(timestamp, actual.getTimestamp());
335336
}
336337

@@ -511,4 +512,14 @@ public void testPersistVolumeStatsKVM() {
511512
public void testPersistVolumeStatsVmware() {
512513
performPersistVolumeStatsTest(Hypervisor.HypervisorType.VMware);
513514
}
515+
516+
private Map<String, String> convertJsonToOrderedMap(String json) {
517+
Map<String, String> jsonMap = new TreeMap<String, String>();
518+
String[] keyValuePairs = json.replace("{", "").replace("}","").split(",");
519+
for (String pair: keyValuePairs) {
520+
String[] keyValue = pair.split(":");
521+
jsonMap.put(keyValue[0], keyValue[1]);
522+
}
523+
return jsonMap;
524+
}
514525
}

0 commit comments

Comments
 (0)