<commit_before>package alien4cloud.it.cloud;

import java.util.List;
import java.util.Set;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.junit.Assert;

import alien4cloud.it.Context;
import alien4cloud.model.cloud.MatchedStorageTemplate;
import alien4cloud.model.cloud.StorageTemplate;
import alien4cloud.rest.cloud.CloudDTO;
import alien4cloud.rest.utils.JsonUtil;

import com.google.common.collect.Lists;
import com.google.common.collect.Sets;

import cucumber.api.DataTable;
import cucumber.api.java.en.And;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;

public class CloudStorageStepDefinitions {

    @When("^I add the storage with id \"([^\"]*)\" and device \"([^\"]*)\" and size (\\d+) to the cloud \"([^\"]*)\"$")
    public void I_add_the_storage_with_id_and_device_and_size_to_the_cloud(String id, String device, long size,
            String cloudName) throws Throwable {
        String cloudId = Context.getInstance().getCloudId(cloudName);
        StorageTemplate storage = new StorageTemplate();
        storage.setId(id);
        storage.setDevice(device);
        storage.setSize(size);
        Context.getInstance().registerRestResponse(
                Context.getRestClientInstance().postJSon("/rest/clouds/" + cloudId + "/storages", JsonUtil.toString(storage)));
    }

    @And("^The cloud with name \"([^\"]*)\" should have (\\d+) storages as resources:$")
    public void The_cloud_with_name_should_have_storage_as_resources(String cloudName, int numberOfStorage, DataTable expectedStorageTable) throws Throwable {
        String cloudId = Context.getInstance().getCloudId(cloudName);
        CloudDTO cloudDTO = JsonUtil.read(Context.getRestClientInstance().get("/rest/clouds/" + cloudId), CloudDTO.class).getData();
        assertStorages(numberOfStorage, cloudDTO.getCloud().getStorages(), expectedStorageTable);
    }

    public static void assertStorages(int numberOfStorage, Set<StorageTemplate> storages, DataTable expectedStorageTable) {
        Assert.assertEquals(numberOfStorage, storages.size());
        Set<StorageTemplate> expectedStorages = Sets.newHashSet();
        if (expectedStorageTable != null) {<commit_msg>Device can be set to null in test<commit_after>package alien4cloud.it.cloud;

import java.util.List;
import java.util.Set;

import org.apache.commons.lang3.StringUtils;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.junit.Assert;

import alien4cloud.it.Context;
import alien4cloud.model.cloud.MatchedStorageTemplate;
import alien4cloud.model.cloud.StorageTemplate;
import alien4cloud.rest.cloud.CloudDTO;
import alien4cloud.rest.utils.JsonUtil;

import com.google.common.collect.Lists;
import com.google.common.collect.Sets;

import cucumber.api.DataTable;
import cucumber.api.java.en.And;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;

public class CloudStorageStepDefinitions {

    @When("^I add the storage with id \"([^\"]*)\" and device \"([^\"]*)\" and size (\\d+) to the cloud \"([^\"]*)\"$")
    public void I_add_the_storage_with_id_and_device_and_size_to_the_cloud(String id, String device, long size,
            String cloudName) throws Throwable {
        String cloudId = Context.getInstance().getCloudId(cloudName);
        StorageTemplate storage = new StorageTemplate();
        storage.setId(id);
        if (StringUtils.isNotBlank(device)) {
            storage.setDevice(device);
        }
        storage.setSize(size);
        Context.getInstance().registerRestResponse(
                Context.getRestClientInstance().postJSon("/rest/clouds/" + cloudId + "/storages", JsonUtil.toString(storage)));
    }

    @And("^The cloud with name \"([^\"]*)\" should have (\\d+) storages as resources:$")
    public void The_cloud_with_name_should_have_storage_as_resources(String cloudName, int numberOfStorage, DataTable expectedStorageTable) throws Throwable {
        String cloudId = Context.getInstance().getCloudId(cloudName);
        CloudDTO cloudDTO = JsonUtil.read(Context.getRestClientInstance().get("/rest/clouds/" + cloudId), CloudDTO.class).getData();
        assertStorages(numberOfStorage, cloudDTO.getCloud().getStorages(), expectedStorageTable);
    }

    public static void assertStorages(int numberOfStorage, Set<StorageTemplate> storages, DataTable expectedStorageTable) {
        Assert.assertEquals(numberOfStorage, storages.size());
        Set<StorageTemplate> expectedStorages = Sets.newHashSet();
        if (expectedStorageTable != null) {
{'fraction_non_alphanumeric': 0.12333841795598169, 'fraction_numerical': 0.0028328611898017, 'mean_word_length': 4.444839857651245, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '4559656', 'n_tokens_mistral': 1342, 'n_tokens_neox': 1335, 'n_words': 263}