1+ package cz .geek .gooddata .shell .commands ;
2+
3+ import com .gooddata .project .Project ;
4+ import cz .geek .gooddata .shell .AbstractShellIntegrationTest ;
5+ import cz .geek .gooddata .shell .components .GoodDataHolder ;
6+ import org .junit .Test ;
7+ import org .mockito .Mock ;
8+ import org .slf4j .Logger ;
9+ import org .slf4j .LoggerFactory ;
10+ import org .springframework .shell .core .CommandResult ;
11+
12+ import static java .util .Objects .requireNonNull ;
13+ import static org .hamcrest .CoreMatchers .instanceOf ;
14+ import static org .hamcrest .CoreMatchers .is ;
15+ import static org .hamcrest .MatcherAssert .assertThat ;
16+ import static org .hamcrest .Matchers .matchesPattern ;
17+
18+ public class MaqlCommandTest extends AbstractShellIntegrationTest {
19+
20+ private final Logger logger = LoggerFactory .getLogger (getClass ());
21+
22+ @ Mock
23+ Project project ;
24+
25+ @ Test
26+ public void maqlWithoutProjectToUse () {
27+ final CommandResult commandResult = getShell ().executeCommand ("maql ''" );
28+
29+ assertThat (commandResult .isSuccess (), is (false ));
30+ }
31+
32+ @ Test
33+ public void maqlWithNonexistentFile () {
34+ final GoodDataHolder holder = getContext ().getBean (GoodDataHolder .class );
35+ holder .setCurrentProject (project );
36+
37+ final CommandResult commandResult = getShell ().executeCommand ("maql --file nonexistent" );
38+
39+ final Throwable exception = commandResult .getException ();
40+ assertThat (exception , is (instanceOf (IllegalArgumentException .class )));
41+ assertThat (exception .getMessage (), matchesPattern ("file .* doesn't exist" ));
42+ }
43+
44+ @ Test
45+ public void maqlWithEmptyFile () {
46+ final GoodDataHolder holder = getContext ().getBean (GoodDataHolder .class );
47+ holder .setCurrentProject (project );
48+ final String emptyFilePath = requireNonNull (getClass ().getClassLoader ().getResource ("empty.file" )).getPath ();
49+
50+ logger .info ("maqlWithEmptyFile test is about to run: maql --file {}" , emptyFilePath );
51+ final CommandResult commandResult = getShell ().executeCommand ("maql --file " + emptyFilePath );
52+
53+ final Throwable exception = commandResult .getException ();
54+ assertThat (exception , is (instanceOf (IllegalArgumentException .class )));
55+ assertThat (exception .getMessage (), is ("maql file cannot be empty" ));
56+ }
57+ }
0 commit comments