Search in sources :

Example 6 with WebhookEntity

use of org.orcid.persistence.jpa.entities.WebhookEntity in project ORCID-Source by ORCID.

the class WebhookManagerMultiThreadedTest method testProcessWebhooks.

@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());
}
Also used : WebhookEntity(org.orcid.persistence.jpa.entities.WebhookEntity) Date(java.util.Date) Test(org.junit.Test) DBUnitTest(org.orcid.test.DBUnitTest)

Example 7 with WebhookEntity

use of org.orcid.persistence.jpa.entities.WebhookEntity in project ORCID-Source by ORCID.

the class WebhookManagerImplTest method testValidUriOnWebhook.

@Test
public void testValidUriOnWebhook() {
    WebhookEntity webhook = new WebhookEntity();
    webhook.setClientDetails(clientDetails);
    webhook.setUri("http://qa-1.orcid.org");
    webhook.setProfile(testProfile);
    webhookManager.processWebhook(webhook);
    assertEquals(webhook.getFailedAttemptCount(), 0);
    verify(mockWebhookDao, times(1)).merge(webhook);
}
Also used : WebhookEntity(org.orcid.persistence.jpa.entities.WebhookEntity) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 8 with WebhookEntity

use of org.orcid.persistence.jpa.entities.WebhookEntity in project ORCID-Source by ORCID.

the class WebhookManagerImplTest method testInvalidUriOnWebhook.

@Test
public void testInvalidUriOnWebhook() {
    WebhookEntity webhook = new WebhookEntity();
    webhook.setClientDetails(clientDetails);
    webhook.setUri("http://123.qa-1.orcid.org");
    webhook.setProfile(testProfile);
    webhookManager.processWebhook(webhook);
    assertEquals(webhook.getFailedAttemptCount(), 1);
    for (int i = 0; i < 3; i++) {
        webhookManager.processWebhook(webhook);
    }
    assertEquals(webhook.getFailedAttemptCount(), 4);
    verify(mockWebhookDao, times(4)).merge(webhook);
}
Also used : WebhookEntity(org.orcid.persistence.jpa.entities.WebhookEntity) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 9 with WebhookEntity

use of org.orcid.persistence.jpa.entities.WebhookEntity in project ORCID-Source by ORCID.

the class WebhookManagerImplTest method testUnexsistingUriOnWebhook.

@Test
public void testUnexsistingUriOnWebhook() {
    WebhookEntity webhook = new WebhookEntity();
    webhook.setClientDetails(clientDetails);
    webhook.setUri("http://unexisting.orcid.com");
    webhook.setProfile(testProfile);
    webhookManager.processWebhook(webhook);
    assertEquals(webhook.getFailedAttemptCount(), 1);
    for (int i = 0; i < 3; i++) {
        webhookManager.processWebhook(webhook);
    }
    assertEquals(webhook.getFailedAttemptCount(), 4);
    verify(mockWebhookDao, times(4)).merge(webhook);
}
Also used : WebhookEntity(org.orcid.persistence.jpa.entities.WebhookEntity) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 10 with WebhookEntity

use of org.orcid.persistence.jpa.entities.WebhookEntity in project ORCID-Source by ORCID.

the class WebhookDaoTest method testMergeFindAndRemove.

@Test
@Rollback(true)
public void testMergeFindAndRemove() {
    ProfileEntity profile = new ProfileEntity("1234-1234-1234-1234");
    profileDao.merge(profile);
    ProfileEntity clientProfile = new ProfileEntity("4444-4444-4444-4449");
    profileDao.merge(clientProfile);
    ClientDetailsEntity clientDetails = new ClientDetailsEntity();
    clientDetails.setGroupProfileId(clientProfile.getId());
    clientDetails.setId(clientProfile.getId());
    clientDetailsDao.merge(clientDetails);
    WebhookEntity webhook = new WebhookEntity();
    webhook.setProfile(profile);
    webhook.setUri("http://semantico.com/orcid/1234");
    webhook.setClientDetails(clientDetails);
    webhookDao.merge(webhook);
    WebhookEntityPk pk = new WebhookEntityPk();
    pk.setProfile(profile);
    pk.setUri("http://semantico.com/orcid/1234");
    WebhookEntity retrieved = webhookDao.find(pk);
    assertNotNull(retrieved);
    assertEquals("1234-1234-1234-1234", retrieved.getProfile().getId());
    assertEquals("http://semantico.com/orcid/1234", retrieved.getUri());
    assertEquals("4444-4444-4444-4449", retrieved.getClientDetails().getClientId());
    assertTrue(retrieved.isEnabled());
    assertEquals(0, retrieved.getFailedAttemptCount());
    assertNull(retrieved.getLastFailed());
    webhookDao.remove(pk);
    retrieved = webhookDao.find(pk);
    assertNull(retrieved);
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) WebhookEntityPk(org.orcid.persistence.jpa.entities.keys.WebhookEntityPk) WebhookEntity(org.orcid.persistence.jpa.entities.WebhookEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test) Rollback(org.springframework.test.annotation.Rollback)

Aggregations

WebhookEntity (org.orcid.persistence.jpa.entities.WebhookEntity)11 Test (org.junit.Test)8 Date (java.util.Date)5 WebhookEntityPk (org.orcid.persistence.jpa.entities.keys.WebhookEntityPk)5 BaseTest (org.orcid.core.BaseTest)4 DBUnitTest (org.orcid.test.DBUnitTest)4 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)3 Rollback (org.springframework.test.annotation.Rollback)3 HashMap (java.util.HashMap)2 OrcidNotFoundException (org.orcid.core.exception.OrcidNotFoundException)2 AccessControl (org.orcid.core.security.visibility.aop.AccessControl)2 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)2 Authentication (org.springframework.security.core.Authentication)2 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)2 OAuth2Request (org.springframework.security.oauth2.provider.OAuth2Request)2 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1