/** * ============================================================================= * * ORCID (R) Open Source * http://orcid.org * * Copyright (c) 2012-2014 ORCID, Inc. * Licensed under an MIT-Style License (MIT) * http://orcid.org/open-source-license * * This copyright and license information (including a link to the full license) * shall be included in its entirety in all copies or substantial portion of * the software. * * ============================================================================= */ package org.orcid.core.manager.impl; import static org.junit.Assert.assertEquals; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Date; import java.util.List; import javax.annotation.Resource; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.orcid.core.manager.WebhookManager; import org.orcid.persistence.dao.WebhookDao; import org.orcid.persistence.jpa.entities.WebhookEntity; import org.orcid.test.DBUnitTest; import org.orcid.test.OrcidJUnit4ClassRunner; import org.springframework.test.context.ContextConfiguration; /** * @author Will Simpson */ @RunWith(OrcidJUnit4ClassRunner.class) @ContextConfiguration(locations = { "classpath:orcid-core-context.xml" }) public class WebhookManagerMultiThreadedTest extends DBUnitTest { @Resource private WebhookManager webhookManager; @Resource private WebhookDao webhookDao; private static final List<String> DATA_FILES = Arrays.asList("/data/SecurityQuestionEntityData.xml", "/data/SourceClientDetailsEntityData.xml", "/data/ProfileEntityData.xml", "/data/WorksEntityData.xml", "/data/ClientDetailsEntityData.xml", "/data/Oauth2TokenDetailsData.xml", "/data/WebhookEntityData.xml"); @BeforeClass public static void initDBUnitData() throws Exception { initDBUnitData(DATA_FILES); } @AfterClass public static void removeDBUnitData() throws Exception { List<String> reversedDataFiles = new ArrayList<String>(DATA_FILES); Collections.reverse(reversedDataFiles); removeDBUnitData(reversedDataFiles); } @Test public void testProcessWebhooks() { Date now = new Date(); List<WebhookEntity> webhooks = webhookDao.findWebhooksReadyToProcess(now, 5, 10); assertEquals(1, webhooks.size()); webhookManager.processWebhooks(); webhooks = webhookDao.findWebhooksReadyToProcess(now, 5, 10); assertEquals(0, webhooks.size()); } }