Fix HostMetricsResponse unit test (#5713)

Co-authored-by: José Flauzino <jose@scclouds.com.br>
This commit is contained in:
José Flauzino 2021-11-25 10:42:31 -03:00 committed by GitHub
parent 9c9de74966
commit 6e04f8711b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 4 deletions

View File

@ -17,6 +17,8 @@
package org.apache.cloudstack.response;
import java.text.DecimalFormat;
import org.junit.Assert;
import org.junit.Test;
@ -24,11 +26,13 @@ import com.cloud.utils.exception.CloudRuntimeException;
public class HostMetricsResponseTest {
final char decimalSeparator = ((DecimalFormat) DecimalFormat.getInstance()).getDecimalFormatSymbols().getDecimalSeparator();
@Test
public void testSetCpuAllocatedWithZeroCpu() {
final HostMetricsResponse hostResponse = new HostMetricsResponse();
hostResponse.setCpuAllocated("50.25%", 0, 1000L);
Assert.assertEquals("0.00 Ghz", hostResponse.getCpuAllocatedGhz());
hostResponse.setCpuAllocated(String.format("50%s25%%", decimalSeparator), 0, 1000L);
Assert.assertEquals(String.format("0%s00 Ghz", decimalSeparator), hostResponse.getCpuAllocatedGhz());
}
@Test
@ -46,9 +50,10 @@ public class HostMetricsResponseTest {
@Test
public void testSetCpuAllocatedWithValidCpu() {
String expected = String.format("5%s03 Ghz", decimalSeparator);
final HostMetricsResponse hostResponse = new HostMetricsResponse();
hostResponse.setCpuAllocated("50.25%", 10, 1000L);
Assert.assertEquals("5.03 Ghz", hostResponse.getCpuAllocatedGhz());
hostResponse.setCpuAllocated(String.format("50%s25%%", decimalSeparator), 10, 1000L);
Assert.assertEquals(expected, hostResponse.getCpuAllocatedGhz());
}
}