package alien4cloud.suggestions.services;

import java.util.Arrays;
import java.util.HashSet;

import lombok.extern.slf4j.Slf4j;

import org.junit.Assert;
import org.junit.Test;
import org.mockito.Mockito;

import alien4cloud.dao.IGenericSearchDAO;
import alien4cloud.model.common.SuggestionEntry;
import alien4cloud.suggestions.services.SuggestionService;

@Slf4j
public class SuggestionServicesTest {

    @Test
    public void testSuggestionMatching() {
        SuggestionService suggestionService = new SuggestionService();
        IGenericSearchDAO alienDAO = Mockito.mock(IGenericSearchDAO.class);
        suggestionService.setAlienDAO(alienDAO);
        SuggestionEntry suggestionEntry = new SuggestionEntry();
        suggestionEntry.setSuggestions(new HashSet<>(Arrays.asList("ubuntu", "windows xp", "kubuntu", "windows 2000", "gentoo", "mint", "debian")));
        Mockito.when(alienDAO.findById(SuggestionEntry.class, "")).thenReturn(suggestionEntry);

        String[] matches = suggestionService.getJaroWinklerMatchedSuggestions("", "u", Integer.MAX_VALUE);
        Assert.assertEquals(1, matches.length);
        Assert.assertEquals("ubuntu", matches[0]);
        log.info("Matches for 'u': {}", Arrays.asList(matches));

        matches = suggestionService.getJaroWinklerMatchedSuggestions("", "ub", 2);
        Assert.assertEquals(2, matches.length);
        Assert.assertEquals("ubuntu", matches[0]);
        Assert.assertEquals("kubuntu", matches[1]);
        log.info("Matches for 'ub': {}", Arrays.asList(matches));

        matches = suggestionService.getJaroWinklerMatchedSuggestions("", "wtn d ow spp", Integer.MAX_VALUE);
        log.info("Matches for 'wtn d ow spp': {}", Arrays.asList(matches));
        Assert.assertEquals("windows xp", matches[0]);

        matches = suggestionService.getJaroWinklerMatchedSuggestions("", "guntoo", Integer.MAX_VALUE);
        log.info("Matches for 'guntoo': {}", Arrays.asList(matches));
        Assert.assertEquals("gentoo", matches[0]);

        matches = suggestionService.getJaroWinklerMatchedSuggestions("", "mt", Integer.MAX_VALUE);
        log.info("Matches for 'mt': {}", Arrays.asList(matches));
        Assert.assertEquals("mint", matches[0]);

        matches = suggestionService.getJaroWinklerMatchedSuggestions("", "Windows", Integer.MAX_VALUE);
        log.info("Matches for 'Windows': {}", Arrays.asList(matches));
        Assert.assertEquals(7, matches.length);
        Assert.assertEquals("windows xp", matches[0]);
        Assert.assertEquals("windows 2000", matches[1]);

        matches = suggestionService.getJaroWinklerMatchedSuggestions("", "", 5);
        log.info("Matches for blank: {}", Arrays.asList(matches));
        Assert.assertEquals(5, matches.length);
    }
    //
    // private void printDistance(String left, String right) {
    // StringUtils.getJaroWinklerDistance(left, right);
    // System.out.println("Distance between '" + left + "' and right '" + right + "' is " + StringUtils.getJaroWinklerDistance(left, right));
    // }
    //
    // @Test
    // public void testJarowinkler() {
    // printDistance("x86_32", "x86_3");
    // }
}

@@ -88,16 +88,73 @@
 shSet;%0A%0A
+import alien4cloud.model.common.AbstractSuggestionEntry;%0A
 import l
@@ -956,16 +956,24 @@
 indById(
+Abstract
 Suggesti
@@ -2818,392 +2818,6 @@
   %7D%0A
-    //%0A    // private void printDistance(String left, String right) %7B%0A    // StringUtils.getJaroWinklerDistance(left, right);%0A    // System.out.println(%22Distance between '%22 + left + %22' and right '%22 + right + %22' is %22 + StringUtils.getJaroWinklerDistance(left, right));%0A    // %7D%0A    //%0A    // @Test%0A    // public void testJarowinkler() %7B%0A    // printDistance(%22x86_32%22, %22x86_3%22);%0A    // %7D%0A
 %7D%0A

Fix suggestion test.