### Question:
RestBackendImpl implements RestBackend { @Override public void scaleCluster(String domainUid, String cluster, int managedServerCount) { LOGGER.entering(domainUid, cluster, managedServerCount); if (managedServerCount < 0) { throw createWebApplicationException( Status.BAD_REQUEST, MessageKeys.INVALID_MANAGE_SERVER_COUNT, managedServerCount); } authorize(domainUid, Operation.update); forDomainDo(domainUid, d -> performScaling(d, cluster, managedServerCount)); LOGGER.exiting(); } RestBackendImpl(String principal, String accessToken, Collection<String> targetNamespaces); @Override Set<String> getDomainUids(); @Override boolean isDomainUid(String domainUid); @Override void performDomainAction(String domainUid, DomainAction params); @Override Set<String> getClusters(String domainUid); @Override boolean isCluster(String domainUid, String cluster); @Override void scaleCluster(String domainUid, String cluster, int managedServerCount); static final String INITIAL_VERSION; }### Answer:
@Test(expected = WebApplicationException.class) public void whenNegativeScaleSpecified_throwException() { restBackend.scaleCluster(NAME1, "cluster1", -1); }
@Test public void whenPerClusterReplicaSettingMatchesScaleRequest_doNothing() { configureCluster("cluster1").withReplicas(5); restBackend.scaleCluster(NAME1, "cluster1", 5); assertThat(getUpdatedDomain(), nullValue()); }
@Test public void whenPerClusterReplicaSetting_scaleClusterUpdatesSetting() { configureCluster("cluster1").withReplicas(1); restBackend.scaleCluster(NAME1, "cluster1", 5); assertThat(getUpdatedDomain().getReplicaCount("cluster1"), equalTo(5)); }
@Test @Ignore public void whenNoPerClusterReplicaSetting_scaleClusterCreatesOne() { restBackend.scaleCluster(NAME1, "cluster1", 5); assertThat(getUpdatedDomain().getReplicaCount("cluster1"), equalTo(5)); }
@Test public void whenNoPerClusterReplicaSettingAndDefaultMatchesRequest_doNothing() { configureDomain().withDefaultReplicaCount(REPLICA_LIMIT); restBackend.scaleCluster(NAME1, "cluster1", REPLICA_LIMIT); assertThat(getUpdatedDomain(), nullValue()); }
@Test(expected = WebApplicationException.class) public void whenReplaceDomainReturnsError_scaleClusterThrowsException() { testSupport.failOnResource(DOMAIN, NAME2, NS, HTTP_CONFLICT); DomainConfiguratorFactory.forDomain(domain2).configureCluster("cluster1").withReplicas(2); restBackend.scaleCluster(NAME2, "cluster1", 3); }