package org.graphwalker.cli;

/*
 * #%L
 * GraphWalker Command Line Interface
 * %%
 * Copyright (C) 2005 - 2014 GraphWalker
 * %%
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 * #L%
 */

import org.junit.Test;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;


public class IncorrectModelsTest extends CLITestRoot {

  /**
   * wrong vertex syntax
   */
  @Test
  public void wrongVertexSyntax() {
    String args[] = {"offline", "-m", "graphml/IncorrectModels/wrongVertexSyntax.graphml", "random(edge_coverage(100))"};
    Result result = runCommand(args);
    assertThat(result.getError(),
                      is("An error occurred when running command: 'offline -m graphml/IncorrectModels/wrongVertexSyntax.graphml random(edge_coverage(100))'."
                         + System.lineSeparator()
                         + "The following syntax error occurred when parsing: 'graphml/IncorrectModels/wrongVertexSyntax.graphml'."
                         + System.lineSeparator()
                         + "Syntax Error: The string '1' did not conform to GraphWalker syntax rules." + System.lineSeparator() + System.lineSeparator()));
    assertThat(result.getOutput(), is(""));
  }

  /**
   * missing Start vertex
   */
  @Test
  public void onlyOneVertex() {
    String args[] = {"offline", "-m", "graphml/IncorrectModels/singleVertex.graphml", "random(edge_coverage(100))"};
    Result result = runCommand(args);
    assertThat(result.getError(), is("An error occurred when running command: 'offline -m graphml/IncorrectModels/singleVertex.graphml random(edge_coverage(100))'."
                                     + System.lineSeparator()
                                     + "No start context found" + System.lineSeparator() + System.lineSeparator()));
    assertThat(result.getOutput(), is(""));
  }

  /**
   * single [start] vertex
   */
  @Test
  public void singleStartVertex() {
    String args[] = {"offline", "-m", "graphml/IncorrectModels/singleStartVertex.graphml", "random(edge_coverage(100))"};
    Result result = runCommand(args);
    assertThat(result.getError(), is("An error occurred when running command: 'offline -m graphml/IncorrectModels/singleStartVertex.graphml random(edge_coverage(100))'."
                                     + System.lineSeparator()
                                     + "No start context found" + System.lineSeparator() + System.lineSeparator()));
    assertThat(result.getOutput(), is(""));
  }

  /**
   * bad edge name
   */
  @Test
  public void badEdgeName() {
    String args[] = {"offline", "-m", "graphml/IncorrectModels/badEdgeName.graphml", "random(edge_coverage(100))"};
    Result result = runCommand(args);
    assertThat(result.getError(),
                      is("An error occurred when running command: 'offline -m graphml/IncorrectModels/badEdgeName.graphml random(edge_coverage(100))'."
                         + System.lineSeparator()
                         + "The following syntax error occurred when parsing: 'graphml/IncorrectModels/badEdgeName.graphml'."
                         + System.lineSeparator()
                         + "Syntax Error: The string '1_badName' did not conform to GraphWalker syntax rules." + System.lineSeparator() + System.lineSeparator()));
    assertThat(result.getOutput(), is(""));
  }

  /**
   * bad vertex name
   */
  @Test
  public void badVertexName() {
    String args[] = {"offline", "-m", "graphml/IncorrectModels/badVertexName.graphml", "random(edge_coverage(100))"};
    Result result = runCommand(args);
    assertThat(result.getError(),
                      is("An error occurred when running command: 'offline -m graphml/IncorrectModels/badVertexName.graphml random(edge_coverage(100))'."
                         + System.lineSeparator()
                         + "The following syntax error occurred when parsing: 'graphml/IncorrectModels/badVertexName.graphml'."
                         + System.lineSeparator()
                         + "Syntax Error: The string '1_badName' did not conform to GraphWalker syntax rules." + System.lineSeparator() + System.lineSeparator()));
    assertThat(result.getOutput(), is(""));
  }
}

@@ -1664,39 +1664,32 @@
 %0A               
-       
 is(%22An error occ
@@ -1818,39 +1818,32 @@
                 
-       
 + System.lineSep
@@ -1861,39 +1861,32 @@
                 
-    
-   
 + %22The following
@@ -1986,39 +1986,32 @@
                 
-       
 + System.lineSep
@@ -2011,39 +2011,32 @@
 lineSeparator()%0A
-       
                 
@@ -3748,39 +3748,32 @@
 %0A               
-       
 is(%22An error occ
@@ -3896,39 +3896,32 @@
                 
-       
 + System.lineSep
@@ -3939,39 +3939,32 @@
                 
-    
-   
 + %22The following
@@ -4058,39 +4058,32 @@
                 
-       
 + System.lineSep
@@ -4083,39 +4083,32 @@
 lineSeparator()%0A
-       
                 
@@ -4567,39 +4567,32 @@
 %0A               
-       
 is(%22An error occ
@@ -4717,39 +4717,32 @@
                 
-       
 + System.lineSep
@@ -4760,39 +4760,32 @@
                 
-    
-   
 + %22The following
@@ -4881,39 +4881,32 @@
                 
-       
 + System.lineSep
@@ -4906,39 +4906,32 @@
 lineSeparator()%0A
-       
                 

Update unit tests