Search in sources :

Example 1 with SearchBox

use of org.corpus_tools.annis.gui.flatquerybuilder.SearchBox in project ANNIS by korpling.

the class FlatQueryBuilderTest method valueFieldTextChange.

@Test
void valueFieldTextChange() {
    initQueryBuilder(0);
    // Add a pos annotation
    queryBuilder.addLinguisticSequenceBox("pos");
    SearchBox searchBox = _get(queryBuilder, SearchBox.class);
    ValueField valueField = _get(queryBuilder, ValueField.class);
    SensitiveComboBox cb = _get(searchBox, SensitiveComboBox.class);
    @SuppressWarnings("unchecked") List<String> oldItemIds = new ArrayList<>((Collection<String>) cb.getItemIds());
    assertNotEquals("VAFIN", oldItemIds.get(0));
    assertNotEquals("VMFIN", oldItemIds.get(1));
    assertNotEquals("VVFIN", oldItemIds.get(2));
    // Mock a text change event
    TextChangeEvent eventVFIN = mock(TextChangeEvent.class);
    when(eventVFIN.getText()).thenReturn("VFIN");
    valueField.textChange(eventVFIN);
    MockVaadin.INSTANCE.clientRoundtrip();
    // Check that the order has changed to include the nearest values first
    @SuppressWarnings("unchecked") List<String> newItemIds = new ArrayList<>((Collection<String>) cb.getItemIds());
    assertEquals("VAFIN", newItemIds.get(0));
    assertEquals("VMFIN", newItemIds.get(1));
    assertEquals("VVFIN", newItemIds.get(2));
    // Test with an empty and null value, the suggestions should stay the same
    TextChangeEvent eventEmpty = mock(TextChangeEvent.class);
    when(eventEmpty.getText()).thenReturn("");
    valueField.textChange(eventEmpty);
    MockVaadin.INSTANCE.clientRoundtrip();
    newItemIds = new ArrayList<>((Collection<String>) cb.getItemIds());
    assertEquals("VAFIN", newItemIds.get(0));
    assertEquals("VMFIN", newItemIds.get(1));
    assertEquals("VVFIN", newItemIds.get(2));
    TextChangeEvent eventNull = mock(TextChangeEvent.class);
    when(eventNull.getText()).thenReturn(null);
    valueField.textChange(eventNull);
    MockVaadin.INSTANCE.clientRoundtrip();
    newItemIds = new ArrayList<>((Collection<String>) cb.getItemIds());
    assertEquals("VAFIN", newItemIds.get(0));
    assertEquals("VMFIN", newItemIds.get(1));
    assertEquals("VVFIN", newItemIds.get(2));
}
Also used : SensitiveComboBox(org.corpus_tools.annis.gui.flatquerybuilder.SensitiveComboBox) TextChangeEvent(com.vaadin.v7.event.FieldEvents.TextChangeEvent) ArrayList(java.util.ArrayList) Collection(java.util.Collection) SearchBox(org.corpus_tools.annis.gui.flatquerybuilder.SearchBox) ValueField(org.corpus_tools.annis.gui.flatquerybuilder.ValueField) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with SearchBox

use of org.corpus_tools.annis.gui.flatquerybuilder.SearchBox in project ANNIS by korpling.

the class FlatQueryBuilderTest method twoTokenInSentence.

@Test
void twoTokenInSentence() throws InterruptedException {
    initQueryBuilder(0);
    // Add a two tokens
    queryBuilder.addLinguisticSequenceBox("tok");
    queryBuilder.addLinguisticSequenceBox("tok");
    List<SearchBox> searchBoxes = _find(queryBuilder, SearchBox.class);
    assertEquals(2, searchBoxes.size());
    _get(searchBoxes.get(0), ComboBox.class).setValue("Feigenblatt");
    _get(searchBoxes.get(1), ComboBox.class).setValue("Die");
    // Add a scope
    queryBuilder.addSpanBox("Sent");
    SpanBox spanBox = _get(queryBuilder, SpanBox.class);
    _get(spanBox, ComboBox.class).setValue("s");
    // Create the AQL query
    _click(_get(queryBuilder, Button.class, spec -> spec.withCaption("Create AQL Query")));
    assertEquals("tok=/Feigenblatt/ & tok=/Die/\n& Sent = \"s\"\n& #1 . #2\n" + "& #3_i_#1\n" + "& #3_i_#2", ui.getQueryState().getAql().getValue());
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) MenuItem(com.vaadin.ui.MenuBar.MenuItem) CheckBox(com.vaadin.v7.ui.CheckBox) EdgeBox(org.corpus_tools.annis.gui.flatquerybuilder.EdgeBox) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) QueryBuilderChooser(org.corpus_tools.annis.gui.querybuilder.QueryBuilderChooser) Autowired(org.springframework.beans.factory.annotation.Autowired) FlatQueryBuilder(org.corpus_tools.annis.gui.flatquerybuilder.FlatQueryBuilder) ActiveProfiles(org.springframework.test.context.ActiveProfiles) LocatorJ._find(com.github.mvysny.kaributesting.v8.LocatorJ._find) ArrayList(java.util.ArrayList) SpanBox(org.corpus_tools.annis.gui.flatquerybuilder.SpanBox) SingletonBeanStoreRetrievalStrategy(org.corpus_tools.annis.gui.SingletonBeanStoreRetrievalStrategy) MockVaadin(com.github.mvysny.kaributesting.v8.MockVaadin) Sets(org.mockito.internal.util.collections.Sets) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) UIScopeImpl(com.vaadin.spring.internal.UIScopeImpl) LocatorJ._get(com.github.mvysny.kaributesting.v8.LocatorJ._get) MetaBox(org.corpus_tools.annis.gui.flatquerybuilder.MetaBox) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) WebAppConfiguration(org.springframework.test.context.web.WebAppConfiguration) SearchBox(org.corpus_tools.annis.gui.flatquerybuilder.SearchBox) MenuBar(com.vaadin.ui.MenuBar) TextChangeEvent(com.vaadin.v7.event.FieldEvents.TextChangeEvent) AnnisUI(org.corpus_tools.annis.gui.AnnisUI) ComboBox(com.vaadin.v7.ui.ComboBox) Collection(java.util.Collection) LocatorJ._click(com.github.mvysny.kaributesting.v8.LocatorJ._click) Mockito.when(org.mockito.Mockito.when) ValueField(org.corpus_tools.annis.gui.flatquerybuilder.ValueField) SensitiveComboBox(org.corpus_tools.annis.gui.flatquerybuilder.SensitiveComboBox) Test(org.junit.jupiter.api.Test) Button(com.vaadin.ui.Button) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) VerticalNode(org.corpus_tools.annis.gui.flatquerybuilder.VerticalNode) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) BeanFactory(org.springframework.beans.factory.BeanFactory) Mockito.mock(org.mockito.Mockito.mock) Button(com.vaadin.ui.Button) ComboBox(com.vaadin.v7.ui.ComboBox) SensitiveComboBox(org.corpus_tools.annis.gui.flatquerybuilder.SensitiveComboBox) SpanBox(org.corpus_tools.annis.gui.flatquerybuilder.SpanBox) SearchBox(org.corpus_tools.annis.gui.flatquerybuilder.SearchBox) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

TextChangeEvent (com.vaadin.v7.event.FieldEvents.TextChangeEvent)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 SearchBox (org.corpus_tools.annis.gui.flatquerybuilder.SearchBox)2 SensitiveComboBox (org.corpus_tools.annis.gui.flatquerybuilder.SensitiveComboBox)2 ValueField (org.corpus_tools.annis.gui.flatquerybuilder.ValueField)2 Test (org.junit.jupiter.api.Test)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 LocatorJ._click (com.github.mvysny.kaributesting.v8.LocatorJ._click)1 LocatorJ._find (com.github.mvysny.kaributesting.v8.LocatorJ._find)1 LocatorJ._get (com.github.mvysny.kaributesting.v8.LocatorJ._get)1 MockVaadin (com.github.mvysny.kaributesting.v8.MockVaadin)1 UIScopeImpl (com.vaadin.spring.internal.UIScopeImpl)1 Button (com.vaadin.ui.Button)1 MenuBar (com.vaadin.ui.MenuBar)1 MenuItem (com.vaadin.ui.MenuBar.MenuItem)1 CheckBox (com.vaadin.v7.ui.CheckBox)1 ComboBox (com.vaadin.v7.ui.ComboBox)1 List (java.util.List)1 AnnisUI (org.corpus_tools.annis.gui.AnnisUI)1