Fixed Hashmap Key value comparision (#8238)

Co-authored-by: kavvya97 <kavvya.ramarathnam@gmail.com>
This commit is contained in:
Kavvya Ramarathnam 2023-11-17 02:05:58 -06:00 committed by GitHub
parent 6001772335
commit 6eb04a86a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -17,6 +17,7 @@
package com.cloud.network.as;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@ -42,14 +43,14 @@ public class AutoScaleVmProfileVOTest {
public void testCounterParamsForUpdate() {
AutoScaleVmProfileVO profile = new AutoScaleVmProfileVO();
Map<String, HashMap<String, String>> counterParamList = new HashMap<>();
counterParamList.put("0", new HashMap<>() {{ put("name", "snmpcommunity"); put("value", "public"); }});
counterParamList.put("1", new HashMap<>() {{ put("name", "snmpport"); put("value", "161"); }});
Map<String, LinkedHashMap<String, String>> counterParamList = new LinkedHashMap<>();
counterParamList.put("0", new LinkedHashMap<>() {{ put("name", "snmpcommunity"); put("value", "public"); }});
counterParamList.put("1", new LinkedHashMap<>() {{ put("name", "snmpport"); put("value", "161"); }});
profile.setCounterParamsForUpdate(counterParamList);
Assert.assertEquals("snmpcommunity=public&snmpport=161", profile.getCounterParamsString());
List<Pair<String, String>> counterParams = profile.getCounterParams();
List<Pair<String, String>> counterParams = profile.getCounterParams();
Assert.assertEquals(2, counterParams.size());
Assert.assertEquals("snmpcommunity", counterParams.get(0).first());
Assert.assertEquals("public", counterParams.get(0).second());
@ -69,10 +70,17 @@ public class AutoScaleVmProfileVOTest {
List<Pair<String, String>> otherDeployParamsList = profile.getOtherDeployParamsList();
Assert.assertEquals(2, otherDeployParamsList.size());
Assert.assertEquals("serviceofferingid", otherDeployParamsList.get(0).first());
Assert.assertEquals("a7fb50f6-01d9-11ed-8bc1-77f8f0228926", otherDeployParamsList.get(0).second());
Assert.assertEquals("rootdisksize", otherDeployParamsList.get(1).first());
Assert.assertEquals("10", otherDeployParamsList.get(1).second());
Assert.assertTrue(containsPair(otherDeployParamsList, "serviceofferingid", "a7fb50f6-01d9-11ed-8bc1-77f8f0228926"));
Assert.assertTrue(containsPair(otherDeployParamsList, "rootdisksize", "10"));
}
private boolean containsPair(List<Pair<String, String>> list, String key, String value) {
for (Pair<String, String> pair : list) {
if (key.equals(pair.first()) && value.equals(pair.second())) {
return true;
}
}
return false;
}
@Test