/************************************************************************* * * * SignServer: The OpenSource Automated Signing Server * * * * This software is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or any later version. * * * * See terms of license at gnu.org. * * * *************************************************************************/ package org.signserver.client.cli; import java.io.*; import org.apache.log4j.Logger; import org.junit.After; import org.junit.Before; import org.junit.FixMethodOrder; import org.junit.runners.MethodSorters; import org.signserver.cli.spi.CommandFailureException; import org.signserver.cli.spi.IllegalCommandArgumentsException; import org.signserver.client.cli.defaultimpl.SignDocumentCommand; import org.signserver.common.ServiceLocator; import org.signserver.common.SignServerUtil; import org.signserver.ejb.interfaces.IWorkerSession; import org.signserver.testutils.ModulesTestCase; import org.signserver.testutils.TestingSecurityManager; import static org.junit.Assert.*; import org.junit.Test; /** * Tests for the signdocument command of Client CLI. * * @author Markus KilÄs * @version $Id: DocumentSignerTest.java 3465 2013-05-01 10:24:46Z netmackan $ */ @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class DocumentSignerTest extends ModulesTestCase { /** Logger for this class. */ private static final Logger LOG = Logger.getLogger(DocumentSignerTest.class); /** WORKERID used in this test case as defined in * junittest-part-config.properties for XMLSigner. */ private static final int WORKERID = 5676; /** WORKERID used in this test case as defined in * junittest-part-config.properties for PDFSigner. */ private static final int WORKERID2 = 5675; private static final int[] WORKERS = new int[] {5676, 5679, 5681, 5682, 5683, 5802, 5803}; private static String signserverhome; @Before public void setUp() throws Exception { SignServerUtil.installBCProvider(); workerSession = ServiceLocator.getInstance().lookupRemote( IWorkerSession.IRemote.class); TestingSecurityManager.install(); signserverhome = System.getenv("SIGNSERVER_HOME"); LOG.info("HOME:"+signserverhome); assertNotNull("Please set SIGNSERVER_HOME environment variable", signserverhome); setupSSLKeystores(); } @After public void tearDown() throws Exception { TestingSecurityManager.remove(); } @Test public void test00SetupDatabase() throws Exception { // Worker 1 setProperties(new File(signserverhome, "modules/SignServer-Module-XMLSigner/src/conf/junittest-part-config.properties")); workerSession.reloadConfiguration(WORKERID); // Worker 2 setProperties(new File(signserverhome, "modules/SignServer-Module-PDFSigner/src/conf/junittest-part-config.properties")); workerSession.reloadConfiguration(WORKERID2); } @Test public void test01missingArguments() throws Exception { try { execute("signdocument"); fail("Should have thrown exception about missing arguments"); } catch (IllegalCommandArgumentsException expected) {} // NOPMD } /** * Tests the sample use case a from the documentation. *
* a) signdocument -workername XMLSigner -data "<root/>" ** @throws Exception */ @Test public void test02signDocumentFromParameter() throws Exception { try { String res = new String(execute("signdocument", "-workername", "TestXMLSigner", "-data", "