### Question:
RemoteClusterResourceProvider extends AbstractAuthorizedResourceProvider { protected Resource toResource(Set<String> requestedIds, RemoteAmbariClusterEntity cluster) { Resource resource = new ResourceImpl(Resource.Type.RemoteCluster); setResourceProperty(resource, CLUSTER_NAME_PROPERTY_ID, cluster.getName(), requestedIds); setResourceProperty(resource, CLUSTER_ID_PROPERTY_ID, cluster.getId(), requestedIds); setResourceProperty(resource, CLUSTER_URL_PROPERTY_ID, cluster.getUrl(), requestedIds); setResourceProperty(resource, USERNAME_PROPERTY_ID, cluster.getUsername(), requestedIds); ArrayList<String> services = new ArrayList<>(); for (RemoteAmbariClusterServiceEntity remoteClusterServiceEntity : cluster.getServices()) { services.add(remoteClusterServiceEntity.getServiceName()); } setResourceProperty(resource, SERVICES_PROPERTY_ID,services, requestedIds); return resource; } protected  RemoteClusterResourceProvider(); @Override Map<Resource.Type, String> getKeyPropertyIds(); @Override RequestStatus createResourcesAuthorized(Request request); @Override Set<Resource> getResources(Request request, Predicate predicate); @Override RequestStatus updateResourcesAuthorized(Request request, Predicate predicate); static final String CLUSTER_NAME_PROPERTY_ID; static final String CLUSTER_ID_PROPERTY_ID; static final String CLUSTER_URL_PROPERTY_ID; static final String USERNAME_PROPERTY_ID; static final String PASSWORD_PROPERTY_ID; static final String SERVICES_PROPERTY_ID; }### Answer:
@Test public void testToResource() throws Exception { RemoteClusterResourceProvider provider = new RemoteClusterResourceProvider(); Set<String> propertyIds = new HashSet<>(); propertyIds.add(RemoteClusterResourceProvider.CLUSTER_NAME_PROPERTY_ID); propertyIds.add(RemoteClusterResourceProvider.CLUSTER_URL_PROPERTY_ID); propertyIds.add(RemoteClusterResourceProvider.USERNAME_PROPERTY_ID); propertyIds.add(RemoteClusterResourceProvider.PASSWORD_PROPERTY_ID); propertyIds.add(RemoteClusterResourceProvider.SERVICES_PROPERTY_ID); RemoteAmbariClusterServiceEntity service1 = createNiceMock(RemoteAmbariClusterServiceEntity.class); expect(service1.getServiceName()).andReturn("service1").once(); RemoteAmbariClusterServiceEntity service2 = createNiceMock(RemoteAmbariClusterServiceEntity.class); expect(service2.getServiceName()).andReturn("service2").once(); List<RemoteAmbariClusterServiceEntity> serviceList = new ArrayList<>(); serviceList.add(service1); serviceList.add(service2); RemoteAmbariClusterEntity entity = createNiceMock(RemoteAmbariClusterEntity.class); expect(entity.getName()).andReturn("test").once(); expect(entity.getUrl()).andReturn("url").once(); expect(entity.getUsername()).andReturn("user").once(); expect(entity.getServices()).andReturn(serviceList).once(); replay(service1, service2, entity); List<String> services = new ArrayList<>(); services.add("service1"); services.add("service2"); Resource resource = provider.toResource(propertyIds, entity); assertEquals(resource.getPropertyValue(RemoteClusterResourceProvider.CLUSTER_NAME_PROPERTY_ID), "test"); assertEquals(resource.getPropertyValue(RemoteClusterResourceProvider.CLUSTER_URL_PROPERTY_ID), "url"); assertEquals(resource.getPropertyValue(RemoteClusterResourceProvider.USERNAME_PROPERTY_ID), "user"); assertEquals(resource.getPropertyValue(RemoteClusterResourceProvider.SERVICES_PROPERTY_ID), services); verify(service1, service2, entity); }