### Question:
Solver { public void validateServicesToAdd(Cluster cluster, Set<String> servicesToAdd) throws IOException { EntityStoreView entityStore = entityStoreService.getView(cluster.getAccount()); Map<String, Service> serviceMap = getServiceMap(Sets.union(cluster.getServices(), servicesToAdd), entityStore); validateServicesToAdd(cluster, servicesToAdd, serviceMap); } @Inject private  Solver(EntityStoreService entityStoreService, ClusterLayoutUpdater updater); Set<Node> addServicesToCluster(Cluster cluster, Set<Node> clusterNodes,
                                        Set<String> servicesToAdd); void validateServicesToAdd(Cluster cluster, Set<String> servicesToAdd); Map<String, Node> solveClusterNodes(Cluster cluster, ClusterCreateRequest request);  }### Answer:
@Test(expected = IllegalArgumentException.class) public void testDependencyMissingThrowsException() throws Exception { solver.validateServicesToAdd(getExampleCluster(), ImmutableSet.of(nodemanager.getName())); }
@Test(expected = IllegalArgumentException.class) public void testInvalidServiceThrowsException() throws Exception { solver.validateServicesToAdd(getExampleCluster(), ImmutableSet.of("fakeservice")); }
@Test(expected = IllegalArgumentException.class) public void testIncompatibleServiceThrowsException() throws Exception { solver.validateServicesToAdd(getExampleCluster(), ImmutableSet.of(mysql.getName())); }
@Test(expected = IllegalArgumentException.class) public void testConflictingServicesThrowsException() throws Exception { Set<String> services = ImmutableSet.of("myapp-1"); ClusterTemplate template = ClusterTemplate.builder() .setName("name") .setClusterDefaults(ClusterDefaults.builder() .setServices(services) .setProvider("joyent") .setConfig(Entities.ClusterTemplateExample.clusterConf).build()) .setCompatibilities(Compatibilities.builder().setServices("myapp-1", "myapp-2").build()) .build(); Service myapp1 = Service.builder() .setName("myapp-1") .setDependencies(ServiceDependencies.builder().setProvides("myapp").setConflicts("myapp-2").build()) .build(); Service myapp2 = Service.builder() .setName("myapp-2") .setDependencies(ServiceDependencies.builder().setProvides("myapp").setConflicts("myapp-1").build()) .build(); entityStoreService.getView(account).writeService(myapp1); entityStoreService.getView(account).writeService(myapp2); Cluster cluster = getBaseBuilder() .setClusterTemplate(template) .setServices(ImmutableSet.of(myapp1.getName())) .build(); solver.validateServicesToAdd(cluster, ImmutableSet.of(myapp2.getName())); }
@Test public void testUsesDoesNotForceDependencyOnCluster() throws Exception { Set<String> services = ImmutableSet.of("service1"); ClusterTemplate template = ClusterTemplate.builder() .setName("name") .setClusterDefaults(ClusterDefaults.builder() .setServices(services) .setProvider("joyent") .setConfig(Entities.ClusterTemplateExample.clusterConf).build()) .setCompatibilities(Compatibilities.builder().setServices("service1", "service2", "service3").build()) .build(); Service service1 = Service.builder().setName("service1").build(); Service service2 = Service.builder() .setName("service2") .setDependencies( ServiceDependencies.builder() .setInstallDependencies(new ServiceStageDependencies(null, ImmutableSet.<String>of("service1"))) .build()) .build(); Service service3 = Service.builder() .setName("service3") .setDependencies( ServiceDependencies.builder() .setRuntimeDependencies(new ServiceStageDependencies(null, ImmutableSet.<String>of("service1"))) .build()) .build(); entityStoreService.getView(account).writeService(service1); entityStoreService.getView(account).writeService(service2); entityStoreService.getView(account).writeService(service3); Cluster cluster = getBaseBuilder() .setClusterTemplate(template) .setServices(ImmutableSet.of(service1.getName())) .build(); solver.validateServicesToAdd(cluster, ImmutableSet.of(service2.getName(), service3.getName())); }