@Test
  public void testDataEnums3() {
    String pkg =
        "package org.test\n import org.drools.ide.common.client.modeldriven.SuggestionCompletionEngineTest.NestedClass";

    SuggestionCompletionLoader loader = new SuggestionCompletionLoader();

    List<String> enums = new ArrayList<String>();

    enums.add(
        "'Fact.f1' : ['a1', 'a2'] \n 'Fact.f2' : ['def1', 'def2', 'def3'] \n 'Fact.f2[f1=a2]' : ['c1', 'c2']");

    SuggestionCompletionEngine engine =
        loader.getSuggestionEngine(
            pkg, new ArrayList<JarInputStream>(), new ArrayList<DSLTokenizedMappingFile>(), enums);
    assertEquals(
        "String", engine.getFieldType("SuggestionCompletionEngineTest$NestedClass", "name"));

    FactPattern pat = new FactPattern("Fact");
    SingleFieldConstraint f1 = new SingleFieldConstraint("f1");
    f1.setValue("a1");
    pat.addConstraint(f1);
    pat.addConstraint(new SingleFieldConstraint("f2"));

    DropDownData data = engine.getEnums(pat.getFactType(), pat.constraintList, "f2");

    assertNotNull(data);
    assertEquals(3, data.fixedList.length);
  }
  @Test
  public void testSmarterLookupEnumsDifferentOrder() {
    final SuggestionCompletionEngine sce = new SuggestionCompletionEngine();
    sce.setDataEnumLists(new HashMap<String, String[]>());
    sce.putDataEnumList("Fact.type", new String[] {"sex", "colour"});
    sce.putDataEnumList(
        "Fact.value[e1, e2]",
        new String[] {"select something from database where x=@{e1} and y=@{e2}"});
    sce.putDataEnumList(
        "Fact.value[f1, f2]",
        new String[] {"select something from database where x=@{f1} and y=@{f2}"});

    FactPattern fp = new FactPattern("Fact");
    String[] drops = sce.getEnums(fp.getFactType(), fp.constraintList, "type").fixedList;
    assertEquals(2, drops.length);
    assertEquals("sex", drops[0]);
    assertEquals("colour", drops[1]);

    Map<String, Object> lookupFields = sce.loadDataEnumLookupFields();
    assertEquals(1, lookupFields.size());
    String[] flds = (String[]) lookupFields.get("Fact.value");
    assertEquals(2, flds.length);
    assertEquals("f1", flds[0]);
    assertEquals("f2", flds[1]);

    FactPattern pat = new FactPattern("Fact");
    SingleFieldConstraint sfc = new SingleFieldConstraint("f1");
    sfc.setValue("f1val");
    pat.addConstraint(sfc);
    sfc = new SingleFieldConstraint("f2");
    sfc.setValue("f2val");
    pat.addConstraint(sfc);

    DropDownData dd = sce.getEnums(pat.getFactType(), pat.constraintList, "value");
    assertNull(dd.fixedList);
    assertNotNull(dd.queryExpression);
    assertNotNull(dd.valuePairs);

    assertEquals(2, dd.valuePairs.length);
    assertEquals("select something from database where x=@{f1} and y=@{f2}", dd.queryExpression);
    assertEquals("f1=f1val", dd.valuePairs[0]);
    assertEquals("f2=f2val", dd.valuePairs[1]);

    // and now for the RHS
    ActionFieldValue[] vals = new ActionFieldValue[2];
    vals[0] = new ActionFieldValue("f1", "f1val", "blah");
    vals[1] = new ActionFieldValue("f2", "f2val", "blah");
    dd = sce.getEnums("Fact", "value", vals);
    assertNull(dd.fixedList);
    assertNotNull(dd.queryExpression);
    assertNotNull(dd.valuePairs);
    assertEquals(2, dd.valuePairs.length);
    assertEquals("select something from database where x=@{f1} and y=@{f2}", dd.queryExpression);
    assertEquals("f1=f1val", dd.valuePairs[0]);
    assertEquals("f2=f2val", dd.valuePairs[1]);
  }
  @Test
  public void testSmartEnums() {
    final SuggestionCompletionEngine sce = new SuggestionCompletionEngine();
    sce.setDataEnumLists(new HashMap<String, String[]>());
    sce.putDataEnumList("Fact.type", new String[] {"sex", "colour"});
    sce.putDataEnumList("Fact.value[type=sex]", new String[] {"M", "F"});
    sce.putDataEnumList("Fact.value[type=colour]", new String[] {"RED", "WHITE", "BLUE"});

    FactPattern pat = new FactPattern("Fact");
    SingleFieldConstraint sfc = new SingleFieldConstraint("type");
    sfc.setValue("sex");
    pat.addConstraint(sfc);
    String[] result = sce.getEnums(pat.getFactType(), pat.constraintList, "value").fixedList;
    assertEquals(2, result.length);
    assertEquals("M", result[0]);
    assertEquals("F", result[1]);

    pat = new FactPattern("Fact");
    sfc = new SingleFieldConstraint("type");
    sfc.setValue("colour");
    pat.addConstraint(sfc);

    result = sce.getEnums(pat.getFactType(), pat.constraintList, "value").fixedList;
    assertEquals(3, result.length);
    assertEquals("RED", result[0]);
    assertEquals("WHITE", result[1]);
    assertEquals("BLUE", result[2]);

    result = sce.getEnums(pat.getFactType(), pat.constraintList, "type").fixedList;
    assertEquals(2, result.length);
    assertEquals("sex", result[0]);
    assertEquals("colour", result[1]);

    ActionFieldValue[] vals = new ActionFieldValue[2];
    vals[0] = new ActionFieldValue("type", "sex", "blah");
    vals[1] = new ActionFieldValue("value", null, "blah");
    result = sce.getEnums("Fact", "value", vals).fixedList;
    assertNotNull(result);
    assertEquals(2, result.length);
    assertEquals("M", result[0]);
    assertEquals("F", result[1]);

    assertNull(sce.getEnums("Nothing", "value", vals));
  }
  @Test
  public void testSmartEnumsDependingOfSeveralFieldsFive() {
    final SuggestionCompletionEngine sce = new SuggestionCompletionEngine();
    sce.setDataEnumLists(new HashMap<String, String[]>());
    sce.putDataEnumList("Fact.field1", new String[] {"a1", "a2"});
    sce.putDataEnumList("Fact.field2", new String[] {"b1", "b2"});
    sce.putDataEnumList("Fact.field3", new String[] {"c1", "c2", "c3"});
    sce.putDataEnumList("Fact.longerField4", new String[] {"d1", "d2"});
    sce.putDataEnumList("Fact.field5", new String[] {"e1", "e2"});
    sce.putDataEnumList(
        "Fact.field6[field1=a1, field2=b2, field3=c3,longerField4=d1,field5=e2]",
        new String[] {"f1", "f2"});

    FactPattern pat = new FactPattern("Fact");
    SingleFieldConstraint sfc = new SingleFieldConstraint("field1");
    sfc.setValue("a1");
    pat.addConstraint(sfc);
    SingleFieldConstraint sfc2 = new SingleFieldConstraint("field2");
    sfc2.setValue("b2");
    pat.addConstraint(sfc2);
    SingleFieldConstraint sfc3 = new SingleFieldConstraint("field3");
    sfc3.setValue("c3");
    pat.addConstraint(sfc3);
    SingleFieldConstraint sfc4 = new SingleFieldConstraint("longerField4");
    sfc4.setValue("d1");
    pat.addConstraint(sfc4);

    assertNull(sce.getEnums(pat.getFactType(), pat.constraintList, "field6"));

    SingleFieldConstraint sfc5 = new SingleFieldConstraint("field5");
    sfc5.setValue("e2");
    pat.addConstraint(sfc5);

    String[] result2 = sce.getEnums(pat.getFactType(), pat.constraintList, "field6").fixedList;
    assertEquals(2, result2.length);
    assertEquals("f1", result2[0]);
    assertEquals("f2", result2[1]);
  }
  @Test
  public void testSmartEnumsDependingOfSeveralFieldsTwo() {
    final SuggestionCompletionEngine sce = new SuggestionCompletionEngine();
    sce.setDataEnumLists(new HashMap<String, String[]>());
    sce.putDataEnumList("Fact.field1", new String[] {"a1", "a2"});
    sce.putDataEnumList("Fact.field2", new String[] {"b1", "b2"});
    sce.putDataEnumList("Fact.field3[field1=a1,field2=b1]", new String[] {"c1", "c2", "c3"});
    sce.putDataEnumList("Fact.field4[field1=a1]", new String[] {"d1", "d2"});

    FactPattern pat = new FactPattern("Fact");
    SingleFieldConstraint sfc = new SingleFieldConstraint("field1");
    sfc.setValue("a1");
    pat.addConstraint(sfc);
    SingleFieldConstraint sfc2 = new SingleFieldConstraint("field2");
    sfc2.setValue("b1");
    pat.addConstraint(sfc2);

    String[] result = sce.getEnums(pat.getFactType(), pat.constraintList, "field3").fixedList;
    assertEquals(3, result.length);
    assertEquals("c1", result[0]);
    assertEquals("c2", result[1]);
    assertEquals("c3", result[2]);
  }