package org.opengroupware.jope.eocontrol.tests;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import java.util.Map;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.opengroupware.jope.eocontrol.EOFetchSpecification;

public class FetchSpecification {

  @Before
  public void setUp() {
    
  }

  @After
  public void tearDown() {
    
  }

  @Test
  public void testBindPatternHints() {
    EOFetchSpecification fs = new EOFetchSpecification();
    fs.setHint("EOCustomQueryExpressionHintKeyBindPattern",
               "%%(tables)s WHERE id = %(id)s");
    
    EOFetchSpecification bfs = fs.fetchSpecificationWithQualifierBindings(this);
    Map<String, Object> bhints = bfs.hints();
    assertNotNull("resolved fetchspec contains no hints!", bhints);
    assertNotNull("missing hint: EOCustomQueryExpressionHint",
                  bhints.get("EOCustomQueryExpressionHintKey"));
    assertEquals("pattern did not resolve",
                 "%(tables)s WHERE id = 10200",
                 bhints.get("EOCustomQueryExpressionHintKey"));
  }
  
  /* support */
  
  public int id() {
    return 10200;
  }
}
