<commit_before>package org.ow2.choreos.deployment.services.update;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.ow2.choreos.deployment.services.preparer.PrepareDeploymentFailedException;
import org.ow2.choreos.deployment.services.preparer.ServiceDeploymentPreparer;
import org.ow2.choreos.deployment.services.preparer.ServiceDeploymentPreparerFactory;
import org.ow2.choreos.nodes.datamodel.CloudNode;
import org.ow2.choreos.services.datamodel.DeployableService;
import org.ow2.choreos.services.datamodel.DeployableServiceSpec;
import org.ow2.choreos.services.datamodel.PackageType;
import org.ow2.choreos.services.datamodel.ServiceType;
import org.ow2.choreos.tests.ModelsForTest;

import com.google.common.collect.Sets;

public class IncreaseNumberOfReplicasTest {

    private ServiceDeploymentPreparer deploymentPreparer;
    private CloudNode node;
    private DeployableService airlineService;

    @Before
    public void setUp() throws Exception {
	setNode();
	setPreparer();
	setModels();
    }

    private void setNode() {
	node = new CloudNode();
	node.setId("unik");
	node.setIp("192.168.56.101");
	node.setUser("ubuntu");
	node.setPrivateKey("ubuntu.pem");
    }

    private void setPreparer() throws PrepareDeploymentFailedException {
	deploymentPreparer = mock(ServiceDeploymentPreparer.class);
	when(deploymentPreparer.prepareDeployment()).thenReturn(Sets.newHashSet(node));
	ServiceDeploymentPreparerFactory.preparerForTest = deploymentPreparer;
	ServiceDeploymentPreparerFactory.testing = true;
    }

    private void setModels() {
	ModelsForTest models = new ModelsForTest(ServiceType.SOAP, PackageType.COMMAND_LINE);
	airlineService = models.getAirlineService();
    }

    @After
    private void tearDown() {
	ServiceDeploymentPreparerFactory.testing = false;
    }

    @Test
    public void test() throws UpdateActionFailedException {

	DeployableServiceSpec newSpec = airlineService.getSpec().clone();
	newSpec.setNumberOfInstances(2);

	assertEquals(1, airlineService.getSelectedNodes().size());
	CloudNode originalNode = airlineService.getSelectedNodes().iterator().next();

	IncreaseNumberOfReplicas action = new IncreaseNumberOfReplicas(airlineService, newSpec);
	action.applyUpdate();

	assertEquals(newSpec, airlineService.getSpec());
	assertEquals(2, airlineService.getSelectedNodes().size());
	int foundEquals = 0;
	int foundDifferent = 0;
	for (CloudNode node : airlineService.getSelectedNodes()) {
	    if (node.equals(originalNode))
		foundEquals++;
	    else
		foundDifferent++;
	}
	assertEquals(1, foundEquals);<commit_msg>fixing test that did not pass<commit_after>package org.ow2.choreos.deployment.services.update;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.ow2.choreos.deployment.services.preparer.PrepareDeploymentFailedException;
import org.ow2.choreos.deployment.services.preparer.ServiceDeploymentPreparer;
import org.ow2.choreos.deployment.services.preparer.ServiceDeploymentPreparerFactory;
import org.ow2.choreos.nodes.datamodel.CloudNode;
import org.ow2.choreos.services.datamodel.DeployableService;
import org.ow2.choreos.services.datamodel.DeployableServiceSpec;
import org.ow2.choreos.services.datamodel.PackageType;
import org.ow2.choreos.services.datamodel.ServiceType;
import org.ow2.choreos.tests.ModelsForTest;

import com.google.common.collect.Sets;

public class IncreaseNumberOfReplicasTest {

    private ServiceDeploymentPreparer deploymentPreparer;
    private CloudNode node;
    private DeployableService airlineService;

    @Before
    public void setUp() throws Exception {
	setNode();
	setPreparer();
	setModels();
    }

    private void setNode() {
	node = new CloudNode();
	node.setId("unik");
	node.setIp("192.168.56.101");
	node.setUser("ubuntu");
	node.setPrivateKey("ubuntu.pem");
    }

    private void setPreparer() throws PrepareDeploymentFailedException {
	deploymentPreparer = mock(ServiceDeploymentPreparer.class);
	when(deploymentPreparer.prepareDeployment()).thenReturn(Sets.newHashSet(node));
	ServiceDeploymentPreparerFactory.preparerForTest = deploymentPreparer;
	ServiceDeploymentPreparerFactory.testing = true;
    }

    private void setModels() {
	ModelsForTest models = new ModelsForTest(ServiceType.SOAP, PackageType.COMMAND_LINE);
	airlineService = models.getAirlineService();
    }

    @After
    public void tearDown() {
	ServiceDeploymentPreparerFactory.testing = false;
    }

    @Test
    public void test() throws UpdateActionFailedException {

	DeployableServiceSpec newSpec = airlineService.getSpec().clone();
	newSpec.setNumberOfInstances(2);

	assertEquals(1, airlineService.getSelectedNodes().size());
	CloudNode originalNode = airlineService.getSelectedNodes().iterator().next();

	IncreaseNumberOfReplicas action = new IncreaseNumberOfReplicas(airlineService, newSpec);
	action.applyUpdate();

	assertEquals(newSpec, airlineService.getSpec());
	assertEquals(2, airlineService.getSelectedNodes().size());
	int foundEquals = 0;
	int foundDifferent = 0;
	for (CloudNode node : airlineService.getSelectedNodes()) {
	    if (node.equals(originalNode))
		foundEquals++;
	    else
		foundDifferent++;
	}
	assertEquals(1, foundEquals);
{'fraction_non_alphanumeric': 0.10451306413301663, 'fraction_numerical': 0.009866617942627444, 'mean_word_length': 5.9291139240506325, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5457498', 'n_tokens_mistral': 1767, 'n_tokens_neox': 1642, 'n_words': 280}