Не удалось найти «класс объявления аннотации» для модульных тестов - PullRequest
0 голосов
/ 19 октября 2018

Я устанавливаю загрузочное приложение Spring на Jenkins.Для юнит-тестов я получаю ошибку ниже.Эта ошибка не относится к одному тесту.Каждый раз, когда я запускаю, это выдает ошибку для другого теста.Я не уверен, что не так.Тот же проект работает нормально (сборка и модульные тесты) на локальных и других средах, таких как (разработка, этап).Любая идея с ошибками ниже?

00:49:42.836 [main] DEBUG org.springframework.test.context.support.ActiveProfilesUtils - Could not find an 'annotation declaring class' for annotation type [org.springframework.test.context.ActiveProfiles] and class [com.abc.services.tokens.crypto.aws.AesGcmDynamoCryptoCipherProviderTest]
00:49:42.836 [main] INFO org.springframework.test.context.support.DefaultTestContextBootstrapper - Using TestExecutionListeners: [org.springframework.test.context.web.ServletTestExecutionListener@43195e57, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@333291e3, org.springframework.test.context.support.DependencyInjectionTestExecutionListener@479d31f3, org.springframework.test.context.support.DirtiesContextTestExecutionListener@40ef3420]

Вот тестовый класс

@SuppressWarnings("unchecked")
public class AesGcmDynamoCryptoCipherProviderTest extends AbstractTestNGBeanMockingTests {
    @MockBean
    AwsCrypto awsCrypto;
    @MockBean
    DynamoDBProvider dynamoDBProvider;
    @MockBean
    MasterKeyProvider masterKeyProvider;
    @MockBean
    Table table;

    private static Item mockCipherItem(UUID cipherId) {
        Item item = mock(Item.class);
        return item;
    }

    private static <T> CryptoResult<T, ?> mockCryptoResult(T result) {
        // do something
        return cryptoResult;
    }

    @BeforeMethod
    private void init() {
        CryptoResult<String, ?> decryptoResult = mockCryptoResult(Base64.getEncoder().encodeToString("*decrypted*".getBytes()));
        CryptoResult<String, ?> encryptoResult = mockCryptoResult("*encrypted*");
    }

    @Test
    public void testGetCipher() {
        AesGcmDynamoCryptoCipherProvider provider = new AesGcmDynamoCryptoCipherProvider("table", awsCrypto, dynamoDBProvider, masterKeyProvider);
        UUID cipherId = UUID.randomUUID();
        Item cipherItem = mockCipherItem(cipherId);
        AesGcmCipher cipher = provider.getCipher(cipherId);
        assertNotNull(cipher);
        assertEquals(cipher.getCipherId(), cipherId);
    }


}

Базовый класс

@ContextConfiguration(classes = { //...
        AbstractTestNGBeanMockingTests.MockBeanConfiguration.class //...
})
@DirtiesContext
public class AbstractTestNGBeanMockingTests extends AbstractTestNGSpringContextTests {
    private static ThreadLocal<Class<? extends AbstractTestNGBeanMockingTests>> currentTestClass = new ThreadLocal<>();
    @AfterClass(alwaysRun = true)
    @Override
    protected void springTestContextAfterTestClass() throws Exception {
        super.springTestContextAfterTestClass();
    }
    @BeforeClass(alwaysRun = true, dependsOnMethods = { "springTestContextBeforeTestClass" })
    @Override
    protected void springTestContextPrepareTestInstance() throws Exception {
        currentTestClass.set(this.getClass());
        super.springTestContextPrepareTestInstance();
        currentTestClass.set(null);
    }
    @BeforeMethod
    public void initializeMockedBeans() {
        MockBeanRegistration.initializeMockedBeans(this);
    }
    protected static class MockBeanConfiguration {
        MockBeanConfiguration(ApplicationContext context) {
            MockBeanRegistration.registerMocks((BeanDefinitionRegistry) context, currentTestClass.get());
        }
    }
}
...