Search in sources :

Example 1 with SuggestionEntry

use of alien4cloud.model.common.SuggestionEntry in project alien4cloud by alien4cloud.

the class SuggestionServicesTest method testSuggestionMatching.

@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(AbstractSuggestionEntry.class, "")).thenReturn(suggestionEntry);
    String[] matches = suggestionService.getJaroWinklerMatchedSuggestions("", "u", Integer.MAX_VALUE);
    Assert.assertEquals(2, matches.length);
    Assert.assertEquals("ubuntu", matches[0]);
    Assert.assertEquals("kubuntu", matches[1]);
    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);
}
Also used : SuggestionService(alien4cloud.suggestions.services.SuggestionService) IGenericSearchDAO(alien4cloud.dao.IGenericSearchDAO) AbstractSuggestionEntry(alien4cloud.model.common.AbstractSuggestionEntry) SuggestionEntry(alien4cloud.model.common.SuggestionEntry) Test(org.junit.Test)

Example 2 with SuggestionEntry

use of alien4cloud.model.common.SuggestionEntry in project alien4cloud by alien4cloud.

the class SuggestionService method createSuggestionEntry.

/**
 * Create a new suggestion entry
 *
 * @param type the targeted type
 * @param initialValues the initial values
 * @param elementId element id
 * @param propertyName property's name
 */
public void createSuggestionEntry(String index, String type, Set<String> initialValues, String elementId, String propertyName) {
    SuggestionEntry suggestionEntry = new SuggestionEntry();
    suggestionEntry.setEsIndex(index);
    suggestionEntry.setEsType(type);
    suggestionEntry.setSuggestions(initialValues);
    suggestionEntry.setTargetElementId(elementId);
    suggestionEntry.setTargetProperty(propertyName);
    alienDAO.save(suggestionEntry);
    setSuggestionIdOnPropertyDefinition(suggestionEntry);
}
Also used : AbstractSuggestionEntry(alien4cloud.model.common.AbstractSuggestionEntry) SuggestionEntry(alien4cloud.model.common.SuggestionEntry) SimpleSuggestionEntry(alien4cloud.model.common.SimpleSuggestionEntry)

Aggregations

AbstractSuggestionEntry (alien4cloud.model.common.AbstractSuggestionEntry)2 SuggestionEntry (alien4cloud.model.common.SuggestionEntry)2 IGenericSearchDAO (alien4cloud.dao.IGenericSearchDAO)1 SimpleSuggestionEntry (alien4cloud.model.common.SimpleSuggestionEntry)1 SuggestionService (alien4cloud.suggestions.services.SuggestionService)1 Test (org.junit.Test)1