title: Writing Integration Test of ExpressionVisitor with Olingo / ODATA 4
body: <p>I'm implementing a web service respecting version 4 of the OData standard in Java language with the framework Olingo. I need to customize the response of <code>$filter</code>. I've implemented a Visitor <a href="https://olingo.apache.org/doc/odata4/tutorials/sqo_f/tutorial_sqo_f.html" rel="nofollow noreferrer">as documented in the quick start</a>. I need to implement an integration Test to try a different kind of grammar and to prevent regression bug in case of future maintenance.</p>
  
  <p>For the V2, I found <a href="https://olingo.apache.org/doc/odata2/tutorials/Olingo_Tutorial_AdvancedRead_FilterVisitor.html" rel="nofollow noreferrer">the following tutorial</a> and the following code : </p>
  
  <pre><code>@Test
  public void printExpressionWithProperty() throws Exception {
    //Use a mocked edmProvider for this tutorial
    TestEdmProvider provider = new TestEdmProvider();
    Edm edm = RuntimeDelegate.createEdm(provider);
    EdmEntityType entityType = edm.getEntityType(TestEdmProvider.NAMESPACE_1, TestEdmProvider.ENTITY_TYPE_1_1.getName());
  
    String rawExpression = "EmployeeId eq '1'";
    FilterExpression expression = UriParser.parseFilter (null, entityType, rawExpression);
    String whereClause = (String) expression.accept(new JdbcSimpleStringVisitor());
    System.out.println("Raw: " + rawExpression + " ------&gt; Whereclause: " + whereClause);
    System.out.println();
  }
  </code></pre>
  
  <p>Unfortunately, <code>UriParser.parseFilter</code> doesn't exist in the v4. </p>
  
  <p>I tried this : </p>
  
  <pre><code>public class MyVisitorTest {
  
      private final FullQualifiedName NAME1 = new FullQualifiedName("testNamespace1", "myfield");
      private final OData odata = OData.newInstance();
  
      public EdmEntityType createEntityType(final FullQualifiedName fqn) {
          if (NAME1.equals(fqn)) {
              EdmEntityType entityType = mock(EdmEntityType.class);
              when(entityType.getNamespace()).thenReturn(fqn.getNamespace());
              when(entityType.getName()).thenReturn(fqn.getName());
              return entityType;
          }
          return null;
      }
  
  
      private Expression parseExpression(final String expressionString)
              throws UriParserException, UriValidationException {
  
          UriTokenizer tokenizer = new UriTokenizer(expressionString);
  
          EdmEntityType entityType = createEntityType(NAME1);
  
          Edm edm = mock(Edm.class);
          when(edm.getEntityType(NAME1)).thenReturn(entityType);
  
          final Expression expression = new ExpressionParser(edm, odata).parse(tokenizer, null, null, null);
          assertNotNull(expression);
          assertTrue(tokenizer.next(UriTokenizer.TokenKind.EOF));
          return expression;
      }
  
      @Test
      public void simpleTest() throws UriParserException, UriValidationException, ODataApplicationException, ExpressionVisitException {
  
          String exp = "myfield gt 2019-01-01T00:00:00Z";
          Expression e = parseExpression(exp);
  
          MyVisitor myVisitor = new MyVisitor();
          String result = (String) e.accept(startEndMeasureVisitor);
          assertEquals(result.toString(), "MyResult");
      }
  }
  </code></pre>
  
  <p>And it doesn't work, it sends me the following message :</p>
  
  <blockquote>
    <p>Property paths must follow a structured type.</p>
  </blockquote>
  
  <p>So I'm looking for any ideas to make my unit test to work or if you've got working example to share...</p>