Search in sources :

Example 1 with CorrelationId

use of io.imunity.furms.domain.site_agent.CorrelationId in project furms by unity-idm.

the class SiteAgentConnectionServiceImplTest method shouldNotDeleteWhenSiteIdAndSiteExternalIdAreNotRelated.

@Test
void shouldNotDeleteWhenSiteIdAndSiteExternalIdAreNotRelated() {
    SiteId id = new SiteId("id");
    SiteExternalId externalId = new SiteExternalId("externalId");
    CorrelationId correlationId = CorrelationId.randomID();
    String json = "json";
    SiteAgentPendingMessage message = SiteAgentPendingMessage.builder().siteExternalId(new SiteExternalId("externalId1")).jsonContent(json).build();
    when(repository.find(correlationId)).thenReturn(Optional.of(message));
    when(siteRepository.findById(id.id)).thenReturn(Optional.of(Site.builder().externalId(externalId).build()));
    assertThrows(IllegalArgumentException.class, () -> service.delete(id, correlationId));
    verify(siteAgentPendingMessageRemoverConnector, times(0)).remove(correlationId, json);
    verify(repository, times(0)).delete(correlationId);
}
Also used : SiteId(io.imunity.furms.domain.sites.SiteId) SiteAgentPendingMessage(io.imunity.furms.domain.site_agent_pending_messages.SiteAgentPendingMessage) CorrelationId(io.imunity.furms.domain.site_agent.CorrelationId) SiteExternalId(io.imunity.furms.domain.sites.SiteExternalId) Test(org.junit.jupiter.api.Test)

Example 2 with CorrelationId

use of io.imunity.furms.domain.site_agent.CorrelationId in project furms by unity-idm.

the class SiteAgentConnectionServiceImplTest method shouldNotRetryWhenSiteIdAndSiteExternalIdAreNotRelated.

@Test
void shouldNotRetryWhenSiteIdAndSiteExternalIdAreNotRelated() {
    SiteId id = new SiteId("id");
    SiteExternalId externalId = new SiteExternalId("externalId");
    CorrelationId correlationId = CorrelationId.randomID();
    String json = "json";
    SiteAgentPendingMessage message = SiteAgentPendingMessage.builder().siteExternalId(new SiteExternalId("externalId1")).jsonContent(json).build();
    when(repository.find(correlationId)).thenReturn(Optional.of(message));
    when(siteRepository.findById(id.id)).thenReturn(Optional.of(Site.builder().externalId(externalId).build()));
    assertThrows(IllegalArgumentException.class, () -> service.retry(id, correlationId));
    verify(siteAgentRetryService, times(0)).retry(externalId, json);
    verify(repository, times(0)).overwriteSentTime(correlationId, ZonedDateTime.now(clock).toLocalDateTime());
}
Also used : SiteId(io.imunity.furms.domain.sites.SiteId) SiteAgentPendingMessage(io.imunity.furms.domain.site_agent_pending_messages.SiteAgentPendingMessage) CorrelationId(io.imunity.furms.domain.site_agent.CorrelationId) SiteExternalId(io.imunity.furms.domain.sites.SiteExternalId) Test(org.junit.jupiter.api.Test)

Example 3 with CorrelationId

use of io.imunity.furms.domain.site_agent.CorrelationId in project furms by unity-idm.

the class SSHKeyOperationServiceTest method shouldUpdateAndRemoveKey.

@Test
void shouldUpdateAndRemoveKey() {
    CorrelationId correlationId = CorrelationId.randomID();
    SSHKey key = SSHKey.builder().id("key").value("ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDvFdnmjLkBdvUqojB/fWMGol4PyhUHgRCn6/Hiaz/pnedck" + "Spgh+RvDor7UsU8bkOQBYc0Yr1ETL1wUR1vIFxqTm23JmmJsyO5EJgUw92nVIc0gj1u5q6xRKg3ONnxEXhJD/78OSp/Z" + "Y8dJw4fnEYl22LfvGXIuCZbvtKNv1Az19y9LU57kDBi3B2ZBDn6rjI6sTeO2jDzb0m0HR1jbLzBO43sxqnVHC7yf9DM7Tp" + "bbgd1Q2km5eySfit/5E3EJBYY4PvankHzGts1NCblK8rX6w+MlV5L1pVZkstVF6hn9gMSM0fInvpJobhQ5KzcL8sJTKO5AL" + "mb9xUkdFjZk9bL demo@demo.pl").ownerId(new PersistentId("id")).sites(Sets.newHashSet("site")).build();
    when(sshKeysRepository.findById("key")).thenReturn(Optional.of(key));
    when(sshKeyOperationRepository.findByCorrelationId(correlationId)).thenReturn(SSHKeyOperationJob.builder().id("id").correlationId(correlationId).operation(SSHKeyOperation.REMOVE).status(SSHKeyOperationStatus.ACK).sshkeyId("key").siteId("site").build());
    service.updateStatus(correlationId, new SSHKeyOperationResult(SSHKeyOperationStatus.DONE, new SSHKeyOperationError(null, null)));
    verify(sshKeyOperationRepository, times(1)).update(eq("id"), eq(SSHKeyOperationStatus.DONE), eq(Optional.empty()), any());
    verify(sshKeysRepository).delete("key");
}
Also used : SSHKeyOperationResult(io.imunity.furms.domain.ssh_keys.SSHKeyOperationResult) SSHKey(io.imunity.furms.domain.ssh_keys.SSHKey) InstalledSSHKey(io.imunity.furms.domain.ssh_keys.InstalledSSHKey) SSHKeyOperationError(io.imunity.furms.domain.ssh_keys.SSHKeyOperationError) CorrelationId(io.imunity.furms.domain.site_agent.CorrelationId) PersistentId(io.imunity.furms.domain.users.PersistentId) Test(org.junit.jupiter.api.Test)

Example 4 with CorrelationId

use of io.imunity.furms.domain.site_agent.CorrelationId in project furms by unity-idm.

the class SSHKeyOperationServiceTest method shouldUpdateStatusAndAddHistoryWhenUpdateKey.

@Test
void shouldUpdateStatusAndAddHistoryWhenUpdateKey() {
    CorrelationId correlationId = CorrelationId.randomID();
    SSHKey key = SSHKey.builder().id("key").value("ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDvFdnmjLkBdvUqojB/fWMGol4PyhUHgRCn6/Hiaz/pnedck" + "Spgh+RvDor7UsU8bkOQBYc0Yr1ETL1wUR1vIFxqTm23JmmJsyO5EJgUw92nVIc0gj1u5q6xRKg3ONnxEXhJD/78OSp/Z" + "Y8dJw4fnEYl22LfvGXIuCZbvtKNv1Az19y9LU57kDBi3B2ZBDn6rjI6sTeO2jDzb0m0HR1jbLzBO43sxqnVHC7yf9DM7Tp" + "bbgd1Q2km5eySfit/5E3EJBYY4PvankHzGts1NCblK8rX6w+MlV5L1pVZkstVF6hn9gMSM0fInvpJobhQ5KzcL8sJTKO5AL" + "mb9xUkdFjZk9bL demo@demo.pl").ownerId(new PersistentId("id")).sites(Sets.newHashSet("site")).build();
    when(sshKeyOperationRepository.findByCorrelationId(correlationId)).thenReturn(SSHKeyOperationJob.builder().id("id").correlationId(correlationId).operation(SSHKeyOperation.UPDATE).status(SSHKeyOperationStatus.ACK).sshkeyId("key").siteId("site").build());
    when(sshKeysRepository.findById("key")).thenReturn(Optional.of(key));
    when(sshKeyHistoryRepository.findBySiteIdAndOwnerIdLimitTo("site", "id", 1)).thenReturn(Collections.singletonList(SSHKeyHistory.builder().sshkeyFingerprint("xxx").build()));
    service.updateStatus(correlationId, new SSHKeyOperationResult(SSHKeyOperationStatus.DONE, new SSHKeyOperationError(null, null)));
    verify(sshKeyOperationRepository, times(1)).update(eq("id"), eq(SSHKeyOperationStatus.DONE), eq(Optional.empty()), any());
    ArgumentCaptor<SSHKeyHistory> history = ArgumentCaptor.forClass(SSHKeyHistory.class);
    verify(sshKeyHistoryRepository, times(1)).create(history.capture());
    assertThat(history.getValue().sshkeyFingerprint).isEqualTo(key.getFingerprint());
    assertThat(history.getValue().siteId).isEqualTo("site");
}
Also used : SSHKeyOperationResult(io.imunity.furms.domain.ssh_keys.SSHKeyOperationResult) SSHKey(io.imunity.furms.domain.ssh_keys.SSHKey) InstalledSSHKey(io.imunity.furms.domain.ssh_keys.InstalledSSHKey) SSHKeyOperationError(io.imunity.furms.domain.ssh_keys.SSHKeyOperationError) CorrelationId(io.imunity.furms.domain.site_agent.CorrelationId) SSHKeyHistory(io.imunity.furms.domain.ssh_keys.SSHKeyHistory) PersistentId(io.imunity.furms.domain.users.PersistentId) Test(org.junit.jupiter.api.Test)

Example 5 with CorrelationId

use of io.imunity.furms.domain.site_agent.CorrelationId in project furms by unity-idm.

the class ProjectAllocationInstallationStatusUpdaterTest method shouldUpdateProjectDeallocation.

@Test
void shouldUpdateProjectDeallocation() {
    // given
    CorrelationId id = new CorrelationId("id");
    // when
    when(repository.findDeallocationByCorrelationId(id.id)).thenReturn(Optional.of(ProjectDeallocation.builder().status(ProjectDeallocationStatus.PENDING).build()));
    service.updateStatus(id, ProjectDeallocationStatus.PENDING, Optional.empty());
    // then
    orderVerifier.verify(repository).update(id.id, ProjectDeallocationStatus.PENDING, Optional.empty());
}
Also used : CorrelationId(io.imunity.furms.domain.site_agent.CorrelationId) Test(org.junit.jupiter.api.Test)

Aggregations

CorrelationId (io.imunity.furms.domain.site_agent.CorrelationId)132 Test (org.junit.jupiter.api.Test)78 DBIntegrationTest (io.imunity.furms.db.DBIntegrationTest)33 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)33 SiteExternalId (io.imunity.furms.domain.sites.SiteExternalId)28 SiteId (io.imunity.furms.domain.sites.SiteId)25 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)23 EnumSource (org.junit.jupiter.params.provider.EnumSource)19 FenixUserId (io.imunity.furms.domain.users.FenixUserId)17 SSHKeyOperationError (io.imunity.furms.domain.ssh_keys.SSHKeyOperationError)16 SSHKeyOperationResult (io.imunity.furms.domain.ssh_keys.SSHKeyOperationResult)16 SiteAgentException (io.imunity.furms.domain.site_agent.SiteAgentException)15 UserAddition (io.imunity.furms.domain.user_operation.UserAddition)15 AmqpConnectException (org.springframework.amqp.AmqpConnectException)15 EventListener (org.springframework.context.event.EventListener)15 Service (org.springframework.stereotype.Service)15 QueueNamesService.getFurmsPublishQueueName (io.imunity.furms.rabbitmq.site.client.QueueNamesService.getFurmsPublishQueueName)14 VERSION (io.imunity.furms.rabbitmq.site.models.consts.Protocol.VERSION)14 RabbitTemplate (org.springframework.amqp.rabbit.core.RabbitTemplate)14 Optional (java.util.Optional)11