ModelGenerator { public ServiceModel toServiceModel(List<ApplicationInfo> allApplicationInfos, ServiceStatusProvider serviceStatusProvider) { Map<ApplicationInstanceReference, ApplicationInstance> applicationInstances = allApplicationInfos.stream() .map(info -> new ApplicationInstanceGenerator(info, zone) .makeApplicationInstance(serviceStatusProvider)) .collect(Collectors.toMap(ApplicationInstance::reference, Function.identity())); return new ServiceModel(applicationInstances); } ModelGenerator(Zone zone); ServiceModel toServiceModel(List<ApplicationInfo> allApplicationInfos,
                                       ServiceStatusProvider serviceStatusProvider); Set<ApplicationInstanceReference> toApplicationInstanceReferenceSet(List<ApplicationInfo> infos); ApplicationInstance toApplicationInstance(ApplicationInfo applicationInfo,
                                                     ServiceStatusProvider serviceStatusProvider); ApplicationInstance toApplicationNarrowedToHost(ApplicationInfo applicationInfo,
                                                           HostName hostname,
                                                           ServiceStatusProvider serviceStatusProvider); ApplicationInstanceReference toApplicationInstanceReference(ApplicationId applicationId); static final String CLUSTER_ID_PROPERTY_NAME; }
@Test public void toApplicationModel() throws Exception { Zone zone = new Zone(Environment.from(ENVIRONMENT), RegionName.from(REGION)); ModelGenerator modelGenerator = new ModelGenerator(zone); SlobrokMonitorManagerImpl slobrokMonitorManager = mock(SlobrokMonitorManagerImpl.class); when(slobrokMonitorManager.getStatus(any(), any(), any(), any())) .thenReturn(new ServiceStatusInfo(ServiceStatus.UP)); ServiceModel serviceModel = modelGenerator.toServiceModel( getExampleApplicationInfos(), slobrokMonitorManager); Map<ApplicationInstanceReference, ApplicationInstance> applicationInstances = serviceModel.getAllApplicationInstances(); assertEquals(2, applicationInstances.size()); Iterator<Map.Entry<ApplicationInstanceReference, ApplicationInstance>> iterator = applicationInstances.entrySet().iterator(); ApplicationInstance applicationInstance1 = iterator.next().getValue(); ApplicationInstance applicationInstance2 = iterator.next().getValue(); if (applicationInstance1.applicationInstanceId().equals(configServerApplication.getApplicationInstanceId())) { verifyConfigServerApplication(applicationInstance1); verifyOtherApplication(applicationInstance2); } else { verifyConfigServerApplication(applicationInstance2); verifyOtherApplication(applicationInstance1); } }