You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CommandLineOptions2TestCase.java 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. package org.apache.fop.cli;
  18. import java.io.File;
  19. import java.io.IOException;
  20. import org.junit.Rule;
  21. import org.junit.Test;
  22. import org.junit.rules.ExpectedException;
  23. import static org.junit.Assert.assertTrue;
  24. import static org.mockito.Mockito.mock;
  25. import static org.mockito.Mockito.verify;
  26. import org.apache.fop.apps.FOPException;
  27. public class CommandLineOptions2TestCase {
  28. @Rule
  29. public ExpectedException exceptionRule = ExpectedException.none();
  30. /**
  31. * Check that the parser detects the case where the -xsl switch has been omitted.
  32. * This detection prevents the XSL file being deleted.
  33. * @throws FOPException
  34. * @throws IOException
  35. */
  36. @Test
  37. public void testXslSwitchMissing() throws FOPException, IOException {
  38. final String xslFilename = "../fop/examples/embedding/xml/xslt/projectteam2fo.xsl";
  39. final String outputFilename = "out.pdf";
  40. exceptionRule.expect(FOPException.class);
  41. exceptionRule.expectMessage("Don't know what to do with " + outputFilename);
  42. // -xsl switch omitted.
  43. String cmdLine = "-xml ../fop/examples/embedding/xml/xml/projectteam.xml " + xslFilename + " " + outputFilename;
  44. String[] args = cmdLine.split(" ");
  45. CommandLineOptions clo = new CommandLineOptions();
  46. clo.parse(args);
  47. }
  48. /**
  49. * Check that the XSL file is not deleted in the case where the -xsl switch has been omitted.
  50. * @throws FOPException
  51. * @throws IOException
  52. */
  53. @Test
  54. public void testXslFileNotDeleted() {
  55. Main.SystemWrapper mockSystemWrapper = mock(Main.SystemWrapper.class);
  56. final String xslFilename = "../fop/examples/embedding/xml/xslt/projectteam2fo.xsl";
  57. // -xsl switch omitted.
  58. String cmdLine = "-xml ../fop/examples/embedding/xml/xml/projectteam.xml " + xslFilename + " out.pdf";
  59. String[] args = cmdLine.split(" ");
  60. Main.startFOP(args, mockSystemWrapper);
  61. verify(mockSystemWrapper).exit(1);
  62. File file = new File(xslFilename);
  63. assertTrue(file.exists());
  64. }
  65. }