首页 > 解决方案 > 从 SoapUI 项目执行 Java 方法

问题描述

我有一个Java 项目和一个带有方法的测试类,应该GroovySoapUI. 要执行的方法:

@Test
public void testPkcs12() throws IOException {
    try (Pkcs12SignatureToken signatureToken = new Pkcs12SignatureToken("src/test/resources/user_a_rsa.p12",
            new PasswordProtection("password".toCharArray()))) {
        assertNotNull(signatureToken);

        List<DSSPrivateKeyEntry> keys = signatureToken.getKeys();
        assertFalse(keys.isEmpty());

        KSPrivateKeyEntry dssPrivateKeyEntry = (KSPrivateKeyEntry) keys.get(0);
        assertNotNull(dssPrivateKeyEntry);
        assertNotNull(dssPrivateKeyEntry.getAlias());

        DSSPrivateKeyEntry entry = signatureToken.getKey(dssPrivateKeyEntry.getAlias(), new PasswordProtection("password".toCharArray()));
        assertNotNull(entry);
        assertNotNull(entry.getCertificate());
        assertNotNull(entry.getCertificateChain());
        assertNotNull(entry.getEncryptionAlgorithm());

        ToBeSigned toBeSigned = new ToBeSigned("Hello world".getBytes("UTF-8"));
        SignatureValue signValue = signatureToken.sign(toBeSigned, DigestAlgorithm.SHA256, entry);
        assertNotNull(signValue);
        assertNotNull(signValue.getAlgorithm());
        assertNotNull(signValue.getValue());

  System.out.println(DatatypeConverter.printBase64Binary(signValue.getValue()));
    }
}

jar我使用以下插件生成了文件。

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <version>3.1.1</version>
    <executions>
      <execution>
        <goals>
          <goal>test-jar</goal>
        </goals>
      </execution>
    </executions>
  </plugin>

我叫它SoapUI

import eu.europa.esig.dss.token.Pkcs12SignatureTokenTest;
log.info Pkcs12SignatureTokenTest.testPkcs12();

我收到以下错误消息:

groovy.lang.MissingMethodException:没有方法签名:静态 eu.europa.esig.dss.token.Pkcs12SignatureTokenTest.testPkcs12() 适用于参数类型:() 值:[] 可能的解决方案:testPkcs12() 行错误:3

标签: javagroovyjarsoapuimaven-plugin

解决方案


你试图打电话testPkcs12,好像它是静态的,但显然不是。试试看嘛:

import eu.europa.esig.dss.token.Pkcs12SignatureTokenTest
new Pkcs12SignatureTokenTest().testPkcs12()

推荐阅读