use of com.vmware.vim.binding.vim.ElementDescription in project flowgate by vmware.
the class VCDataServiceTest method testFeedHostUsageData.
@Test
public void testFeedHostUsageData() {
Asset hostMappingAsset = Mockito.mock(Asset.class);
HostSystem host = Mockito.mock(HostSystem.class);
when(hostMappingAsset.getId()).thenReturn("hostid");
PerformanceManager performanceManager = Mockito.mock(PerformanceManager.class);
when(vsphereClient.getPerformanceManager()).thenReturn(performanceManager);
CounterInfo[] counterInfos = new CounterInfo[4];
counterInfos[0] = Mockito.mock(CounterInfo.class);
when(counterInfos[0].getKey()).thenReturn(1);
ElementDescription edGroup = Mockito.mock(ElementDescription.class);
when(counterInfos[0].getGroupInfo()).thenReturn(edGroup);
when(edGroup.getKey()).thenReturn(VCConstants.HOST_CPU_GROUP);
ElementDescription edName = Mockito.mock(ElementDescription.class);
when(counterInfos[0].getNameInfo()).thenReturn(edName);
when(edName.getKey()).thenReturn(VCConstants.HOST_METRIC_USAGE);
counterInfos[1] = Mockito.mock(CounterInfo.class);
when(counterInfos[1].getKey()).thenReturn(2);
ElementDescription edGroup1 = Mockito.mock(ElementDescription.class);
when(counterInfos[1].getGroupInfo()).thenReturn(edGroup1);
when(edGroup1.getKey()).thenReturn(VCConstants.HOST_MEMORY_GROUP);
ElementDescription edName1 = Mockito.mock(ElementDescription.class);
when(counterInfos[1].getNameInfo()).thenReturn(edName1);
when(edName1.getKey()).thenReturn(VCConstants.HOST_METRIC_USAGE);
counterInfos[2] = Mockito.mock(CounterInfo.class);
when(counterInfos[2].getKey()).thenReturn(3);
ElementDescription edGroup2 = Mockito.mock(ElementDescription.class);
when(counterInfos[2].getGroupInfo()).thenReturn(edGroup2);
when(edGroup2.getKey()).thenReturn(VCConstants.HOST_POWER_GROUP);
ElementDescription edName2 = Mockito.mock(ElementDescription.class);
when(counterInfos[2].getNameInfo()).thenReturn(edName2);
when(edName2.getKey()).thenReturn(VCConstants.HOST_METRIC_POWER_ENERGY);
counterInfos[3] = Mockito.mock(CounterInfo.class);
when(counterInfos[3].getKey()).thenReturn(4);
ElementDescription edGroup3 = Mockito.mock(ElementDescription.class);
when(counterInfos[3].getGroupInfo()).thenReturn(edGroup3);
when(edGroup3.getKey()).thenReturn(VCConstants.HOST_POWER_GROUP);
ElementDescription edName3 = Mockito.mock(ElementDescription.class);
when(counterInfos[3].getNameInfo()).thenReturn(edName3);
when(edName3.getKey()).thenReturn(VCConstants.HOST_METRIC_POWER_POWER);
when(performanceManager.getPerfCounter()).thenReturn(counterInfos);
MetricId[] metrics = new MetricId[4];
metrics[0] = Mockito.mock(MetricId.class);
metrics[1] = Mockito.mock(MetricId.class);
metrics[2] = Mockito.mock(MetricId.class);
metrics[3] = Mockito.mock(MetricId.class);
when(metrics[0].getCounterId()).thenReturn(1);
when(metrics[1].getCounterId()).thenReturn(2);
when(metrics[2].getCounterId()).thenReturn(3);
when(metrics[3].getCounterId()).thenReturn(4);
when(metrics[0].getInstance()).thenReturn(null);
when(metrics[1].getInstance()).thenReturn(null);
when(metrics[2].getInstance()).thenReturn(null);
when(metrics[3].getInstance()).thenReturn(null);
when(performanceManager.queryAvailableMetric(host._getRef(), null, null, new Integer(20))).thenReturn(metrics);
ProviderSummary summary = Mockito.mock(ProviderSummary.class);
when(summary.getRefreshRate()).thenReturn(1);
when(performanceManager.queryProviderSummary(host._getRef())).thenReturn(summary);
EntityMetric[] metricBase = new EntityMetric[4];
metricBase[0] = Mockito.mock(EntityMetric.class);
long[] values = { 1L, 2L, 3L, 4L };
IntSeries[] metricSerieses1 = new IntSeries[4];
metricSerieses1[0] = Mockito.mock(IntSeries.class);
MetricId metricID = Mockito.mock(MetricId.class);
when(metricSerieses1[0].getId()).thenReturn(metricID);
when(metricID.getCounterId()).thenReturn(1);
IntSeries intSeries1 = Mockito.mock(IntSeries.class);
intSeries1 = metricSerieses1[0];
when((intSeries1.getValue())).thenReturn(values);
when(metricID.getCounterId()).thenReturn(1);
metricSerieses1[1] = Mockito.mock(IntSeries.class);
when(metricSerieses1[1].getId()).thenReturn(metricID);
when(metricID.getCounterId()).thenReturn(1);
IntSeries intSeries2 = Mockito.mock(IntSeries.class);
intSeries2 = metricSerieses1[1];
when(intSeries2.getValue()).thenReturn(values);
MetricId metricID2 = Mockito.mock(MetricId.class);
metricSerieses1[2] = Mockito.mock(IntSeries.class);
when(metricSerieses1[2].getId()).thenReturn(metricID2);
when(metricID2.getCounterId()).thenReturn(3);
IntSeries intSeries3 = Mockito.mock(IntSeries.class);
intSeries3 = metricSerieses1[2];
when(intSeries3.getValue()).thenReturn(values);
MetricId metricID3 = Mockito.mock(MetricId.class);
metricSerieses1[3] = Mockito.mock(IntSeries.class);
when(metricSerieses1[3].getId()).thenReturn(metricID3);
when(metricID3.getCounterId()).thenReturn(4);
IntSeries intSeries4 = Mockito.mock(IntSeries.class);
intSeries4 = metricSerieses1[3];
when(intSeries4.getValue()).thenReturn(values);
when(metricBase[0].getValue()).thenReturn(metricSerieses1);
SampleInfo[] sampleInfos1 = new SampleInfo[4];
sampleInfos1[0] = Mockito.mock(SampleInfo.class);
Calendar time = Calendar.getInstance();
when(sampleInfos1[0].getTimestamp()).thenReturn(time);
sampleInfos1[1] = Mockito.mock(SampleInfo.class);
when(sampleInfos1[1].getTimestamp()).thenReturn(time);
sampleInfos1[2] = Mockito.mock(SampleInfo.class);
when(sampleInfos1[2].getTimestamp()).thenReturn(time);
sampleInfos1[3] = Mockito.mock(SampleInfo.class);
when(sampleInfos1[3].getTimestamp()).thenReturn(time);
when(metricBase[0].getSampleInfo()).thenReturn(sampleInfos1);
metricBase[1] = Mockito.mock(EntityMetric.class);
when(metricBase[1].getValue()).thenReturn(metricSerieses1);
when(metricBase[1].getSampleInfo()).thenReturn(sampleInfos1);
metricBase[2] = Mockito.mock(EntityMetric.class);
when(metricBase[2].getValue()).thenReturn(metricSerieses1);
when(metricBase[2].getSampleInfo()).thenReturn(sampleInfos1);
metricBase[3] = Mockito.mock(EntityMetric.class);
when(metricBase[3].getValue()).thenReturn(metricSerieses1);
when(metricBase[3].getSampleInfo()).thenReturn(sampleInfos1);
when(performanceManager.queryStats(any())).thenReturn(metricBase);
service.feedHostUsageData(vsphereClient, hostMappingAsset.getId(), host._getRef());
}
use of com.vmware.vim.binding.vim.ElementDescription in project flowgate by vmware.
the class VCDataServiceTest method testFeedHostUsageDataNotAvailableMetricId.
@Test
public void testFeedHostUsageDataNotAvailableMetricId() {
PerformanceManager performanceManager = Mockito.mock(PerformanceManager.class);
when(vsphereClient.getPerformanceManager()).thenReturn(performanceManager);
CounterInfo[] counterInfos = new CounterInfo[4];
counterInfos[0] = Mockito.mock(CounterInfo.class);
when(counterInfos[0].getKey()).thenReturn(1);
ElementDescription edGroup = Mockito.mock(ElementDescription.class);
when(counterInfos[0].getGroupInfo()).thenReturn(edGroup);
when(edGroup.getKey()).thenReturn(VCConstants.HOST_CPU_GROUP);
ElementDescription edName = Mockito.mock(ElementDescription.class);
when(counterInfos[0].getNameInfo()).thenReturn(edName);
when(edName.getKey()).thenReturn(VCConstants.HOST_METRIC_USAGE);
counterInfos[1] = Mockito.mock(CounterInfo.class);
when(counterInfos[1].getKey()).thenReturn(2);
ElementDescription edGroup1 = Mockito.mock(ElementDescription.class);
when(counterInfos[1].getGroupInfo()).thenReturn(edGroup1);
when(edGroup1.getKey()).thenReturn(VCConstants.HOST_MEMORY_GROUP);
ElementDescription edName1 = Mockito.mock(ElementDescription.class);
when(counterInfos[1].getNameInfo()).thenReturn(edName1);
when(edName1.getKey()).thenReturn(VCConstants.HOST_METRIC_USAGE);
counterInfos[2] = Mockito.mock(CounterInfo.class);
when(counterInfos[2].getKey()).thenReturn(3);
ElementDescription edGroup2 = Mockito.mock(ElementDescription.class);
when(counterInfos[2].getGroupInfo()).thenReturn(edGroup2);
when(edGroup2.getKey()).thenReturn(VCConstants.HOST_POWER_GROUP);
ElementDescription edName2 = Mockito.mock(ElementDescription.class);
when(counterInfos[2].getNameInfo()).thenReturn(edName2);
when(edName2.getKey()).thenReturn(VCConstants.HOST_METRIC_POWER_ENERGY);
counterInfos[3] = Mockito.mock(CounterInfo.class);
when(counterInfos[3].getKey()).thenReturn(4);
ElementDescription edGroup3 = Mockito.mock(ElementDescription.class);
when(counterInfos[3].getGroupInfo()).thenReturn(edGroup3);
when(edGroup3.getKey()).thenReturn(VCConstants.HOST_POWER_GROUP);
ElementDescription edName3 = Mockito.mock(ElementDescription.class);
when(counterInfos[3].getNameInfo()).thenReturn(edName3);
when(edName3.getKey()).thenReturn(VCConstants.HOST_METRIC_POWER_POWER);
when(performanceManager.getPerfCounter()).thenReturn(counterInfos);
HostSystem host = Mockito.mock(HostSystem.class);
ManagedObjectReference managedObjectReference = host._getRef();
when(performanceManager.queryAvailableMetric(managedObjectReference, null, null, new Integer(20))).thenReturn(null);
service.feedHostUsageData(vsphereClient, "avbaebhqw9", managedObjectReference);
}
Aggregations