InstancesRepositoryImpl implements InstancesRepository { @Override public List<FindInstancesResult> findInstances(FindInstancesRequest findInstancesRequest) { QueryResult instancesResult = queryRepository.query(findInstancesRequest.getPayload()); Data data = instancesResult.getData(); return data.getRows().stream() .map(r -> { ValueFormatter vf = new ValueFormatter(data , r); return new FindInstancesResult( vf.getString("instances.id"), vf.getString("instances.real_id"), vf.getString("instances.name"), vf.getString("projects.id"), vf.getString("projects.name"), vf.getString("instances.cloud_id"), vf.getString("instances.cloud_type"), vf.getString("images.name"), vf.getString("flavors.name"), vf.getString("instances.addresses"), vf.getString("instances.state"), vf.getString("instances.last_updated") ); }) .collect(Collectors.toList()); }  @Override List<FindInstancesResult> findInstances(FindInstancesRequest findInstancesRequest); @Override Map<String, Map<String, String>> getInstancesMetadata(FindInstancesRequest findInstancesRequest); @Override Set<String> addInstances(List<Instance> instances); @Override Set<String> startInstances(Collection<String> instanceIds); @Override Set<String> shutdownInstances(Collection<String> instanceIds); @Override Set<String> deleteInstances(Collection<String> instanceIds); @Override Set<String> renameInstances(Map<String, String> newNames); @Override Set<String> rebootInstances(Collection<String> instanceIds); @Override Set<String> rebuildInstances(String imageId, Collection<String> instanceIds); @Override Set<String> resizeInstances(String flavorId, Collection<String> instanceIds); @Override Set<String> pauseInstances(Collection<String> instanceIds); @Override Set<String> resumeInstances(Collection<String> instanceIds); @Override Set<String> suspendInstances(Collection<String> instanceIds); @Override Set<String> hardRebootInstances(Collection<String> instanceIds);  }
@Test public void testFindInstances() { Project project = EntityGenerator.getProject(); Instance instance = EntityGenerator.getInstance(); Image image = EntityGenerator.getImage(); Flavor flavor = EntityGenerator.getFlavor(); QueryResult queryResult = createMockInstancesResult(project, instance, image, flavor); mockQueryRepository.addQueryResult(queryResult); FindInstancesRequest findInstancesRequest = requestProvider.get(FindInstancesRequest.class); List<FindInstancesResult> instances = instancesRepository.findInstances(findInstancesRequest); assertThat(instances, hasSize(1)); FindInstancesResult result = instances.get(0); assertThat(result.getId(), equalTo(instance.getId())); assertThat(result.getRealId(), equalTo(instance.getRealId())); assertThat(result.getName(), equalTo(instance.getName())); assertThat(result.getProjectId(), equalTo(project.getId())); assertThat(result.getProjectName(), equalTo(project.getName())); assertThat(result.getCloudId(), equalTo(project.getCloudId())); assertThat(result.getCloudType(), equalTo(project.getCloudType())); assertThat(result.getImageName(), equalTo(image.getName())); assertThat(result.getFlavorName(), equalTo(flavor.getName())); assertThat(result.getAddresses(), equalTo(instance.getAddresses().get(0))); assertThat(result.getState(), equalTo(instance.getState().value())); assertThat(result.getLastUpdated(), is(notNullValue())); }