001/* 
002 * Copyright (C) 2016 Hobrasoft s.r.o.
003 *
004 * This program is free software: you can redistribute it and/or modify
005 * it under the terms of the GNU Affero General Public License as published by
006 * the Free Software Foundation, either version 3 of the License, or
007 * (at your option) any later version.
008 *
009 * This program is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012 * GNU Affero General Public License for more details.
013 *
014 * You should have received a copy of the GNU Affero General Public License
015 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
016 */
017package cz.hobrasoft.pdfmu;
018
019import java.io.File;
020import java.io.IOException;
021import java.util.ArrayList;
022import java.util.List;
023import org.junit.Assert;
024import org.junit.Test;
025import org.junit.contrib.java.lang.system.Assertion;
026
027/**
028 * Since {@link cz.hobrasoft.pdfmu.operation.OperationInspect} does not inspect
029 * the attachments, we cannot test the {@code attach} operation properly. We
030 * cannot compare the result bit-by-bit either because it differs in ModDate. We
031 * only test whether a single basic call succeeds.
032 *
033 * @author Filip Bartek
034 */
035public class MainAttachTest extends MainTest {
036
037    @Test
038    public void testAttach() throws IOException {
039        List<String> argsList = new ArrayList<>();
040        argsList.add("attach");
041        final File inputFile = BLANK_12_PDF.getFile(folder);
042        argsList.add(inputFile.getAbsolutePath());
043        FileResource attachmentFileResource = new FileResource("blank.txt");
044        File attachmentFile = attachmentFileResource.getFile(folder);
045        argsList.add(attachmentFile.getAbsolutePath());
046        argsList.add("--out");
047        final File outFile = newFile("out.pdf", false);
048        argsList.add(outFile.getAbsolutePath());
049        exit.expectSystemExitWithStatus(0);
050        exit.checkAssertionAfterwards(new Assertion() {
051            @Override
052            public void checkAssertion() {
053                Assert.assertTrue(outFile.exists());
054                Assert.assertTrue(outFile.length() > inputFile.length());
055            }
056        });
057        Main.main(argsList.toArray(new String[]{}));
058        assert false;
059    }
060}