Skip to content
Snippets Groups Projects
Select Git revision
  • c435bcfc7107cbae3783c0f2e8ea51f9c36ddfaa
  • main default protected
  • OZG-8073-date-component
  • OZG-7856_schadcode_scanner
  • OZG-7985-Statistik-Datenfreigabe
  • OZG-8305-Create-webpack-sbom
  • tooltip-improvements
  • ods-remove-class-inputs
  • release-info
  • release-administration
  • release
  • OZG-7714-UpgradeKeycloakDependencyTo25
  • OZG-8086-Admin-Datenanfrage-erstellen
  • OZG-8086-Datenanfrage-Umbenennung
  • mongodb-7-0-16-e2e
  • OZG-6220-Bescheid-speichern-ohne-Postfach
  • OZG-7922-KeycloakOperatorExceptions
  • OZG-8142-poc-cards
  • OZG-8086-E2E
  • OZG-8086-E2E2
  • OZG-8142-ProjectionStuff
  • 1.11.0-info
  • 1.11.0-administration
  • 2.26.0-alfa
  • 1.10.0-info
  • 1.10.0-administration
  • 2.25.0-alfa
  • 1.9.0-info
  • 1.9.0-administration
  • 2.24.0-alfa
  • 1.8.0-info
  • 1.8.0-administration
  • 2.23.0-alfa
  • 1.7.0-info
  • 1.7.0-administration
  • 2.22.0-alfa
  • 1.6.0-info
  • 1.6.0-administration
  • 2.21.0-alfa
  • 1.5.0-info
  • 1.5.0-administration
41 results

vorgang.model.ts

Blame
  • XtaClientTest.java 4.91 KiB
    package de.ozgcloud.xta.client;
    
    import static de.ozgcloud.xta.client.factory.MessageMetaDataTestFactory.*;
    import static de.ozgcloud.xta.client.factory.XtaClientConfigTestFactory.*;
    import static org.assertj.core.api.Assertions.*;
    import static org.mockito.Mockito.*;
    
    import java.util.List;
    
    import org.junit.jupiter.api.BeforeEach;
    import org.junit.jupiter.api.DisplayName;
    import org.junit.jupiter.api.Nested;
    import org.junit.jupiter.api.Test;
    import org.junit.jupiter.api.extension.ExtendWith;
    import org.mockito.InjectMocks;
    import org.mockito.Mock;
    import org.mockito.Spy;
    import org.mockito.junit.jupiter.MockitoExtension;
    
    import de.ozgcloud.xta.client.config.XtaClientConfig;
    import de.ozgcloud.xta.client.core.WrappedXtaService;
    import de.ozgcloud.xta.client.model.XtaMessage;
    import de.ozgcloud.xta.client.model.XtaMessageMetaDataListing;
    import de.ozgcloud.xta.client.model.XtaTransportReport;
    import lombok.SneakyThrows;
    
    @ExtendWith(MockitoExtension.class)
    class XtaClientTest {
    
    	@Mock
    	private WrappedXtaService service;
    
    	@Mock
    	private XtaClientConfig config;
    
    	@Spy
    	@InjectMocks
    	private XtaClient client;
    
    	@DisplayName("get messages metadata")
    	@Nested
    	class TestGetMessagesMetadata {
    
    		@Mock
    		XtaMessageMetaDataListing xtaMessageMetaDataListing;
    
    		@BeforeEach
    		@SneakyThrows
    		void mock() {
    			doReturn(SELF_IDENTIFIER).when(client).deriveIdentifier(SELF_IDENTIFIER_VALUE);
    			when(service.getStatusList(SELF_IDENTIFIER, MAX_LIST_ITEMS)).thenReturn(xtaMessageMetaDataListing);
    			when(config.getMaxListItems()).thenReturn(MAX_LIST_ITEMS);
    		}
    
    		@DisplayName("should call checkAccountActive")
    		@Test
    		@SneakyThrows
    		void shouldCallCheckAccountActive() {
    			client.getMessagesMetadata(SELF_IDENTIFIER_VALUE);
    
    			verify(service).checkAccountActive(SELF_IDENTIFIER);
    		}
    
    		@DisplayName("should return get status list response")
    		@Test
    		@SneakyThrows
    		void shouldReturnGetStatusListResponse() {
    			var result = client.getMessagesMetadata(SELF_IDENTIFIER_VALUE);
    
    			assertThat(result).isEqualTo(xtaMessageMetaDataListing);
    		}
    
    	}
    
    	@DisplayName("get next messages meta data")
    	@Nested
    	class TestGetNextMessagesMetaData {
    
    		@Mock
    		XtaMessageMetaDataListing xtaMessageMetaDataListing;
    
    		@BeforeEach
    		@SneakyThrows
    		void mock() {
    			doReturn(SELF_IDENTIFIER).when(client).deriveIdentifier(SELF_IDENTIFIER_VALUE);
    			when(service.getStatusList(SELF_IDENTIFIER, MAX_LIST_ITEMS)).thenReturn(xtaMessageMetaDataListing);
    			when(config.getMaxListItems()).thenReturn(MAX_LIST_ITEMS);
    		}
    
    		@DisplayName("should return get status list response")
    		@Test
    		@SneakyThrows
    		void shouldReturnGetStatusListResponse() {
    			var result = client.getNextMessagesMetadata(SELF_IDENTIFIER_VALUE);
    
    			assertThat(result).isEqualTo(xtaMessageMetaDataListing);
    		}
    	}
    
    	@DisplayName("derive identifier")
    	@Nested
    	class TestDeriveIdentifier {
    
    		@DisplayName("should use value")
    		@Test
    		void shouldUseValue() {
    			when(config.getClientIdentifiers()).thenReturn(List.of(SELF_IDENTIFIER2, SELF_IDENTIFIER));
    
    			var result = client.deriveIdentifier(SELF_IDENTIFIER_VALUE);
    
    			assertThat(result.value()).isEqualTo(SELF_IDENTIFIER_VALUE);
    		}
    
    		@DisplayName("should throw when unknown")
    		@Test
    		void shouldThrowWhenUnknown() {
    			when(config.getClientIdentifiers()).thenReturn(List.of(SELF_IDENTIFIER2));
    
    			assertThatThrownBy(() -> client.deriveIdentifier(SELF_IDENTIFIER_VALUE))
    					.isInstanceOf(IllegalArgumentException.class)
    					.hasMessage("Unknown identifier: " + SELF_IDENTIFIER_VALUE);
    		}
    	}
    
    	@DisplayName("get message")
    	@Nested
    	class TestGetMessage {
    
    		@Mock
    		XtaMessage xtaMessage;
    
    		@Mock
    		XtaTransportReport xtaTransportReport;
    
    		@BeforeEach
    		@SneakyThrows
    		void mock() {
    			doReturn(SELF_IDENTIFIER).when(client).deriveIdentifier(SELF_IDENTIFIER_VALUE);
    			when(service.getMessage(MESSAGE_ID, SELF_IDENTIFIER)).thenReturn(xtaMessage);
    			when(service.getTransportReport(MESSAGE_ID, SELF_IDENTIFIER)).thenReturn(xtaTransportReport);
    		}
    
    		@DisplayName("should call close")
    		@Test
    		@SneakyThrows
    		void shouldCallClose() {
    			client.getMessage(SELF_IDENTIFIER_VALUE, MESSAGE_ID);
    
    			verify(service).close(MESSAGE_ID, SELF_IDENTIFIER);
    		}
    
    		@DisplayName("should return with message")
    		@Test
    		@SneakyThrows
    		void shouldReturn() {
    			var result = client.getMessage(SELF_IDENTIFIER_VALUE, MESSAGE_ID);
    
    			assertThat(result.message()).isEqualTo(xtaMessage);
    		}
    
    		@DisplayName("should return with transport report")
    		@Test
    		@SneakyThrows
    		void shouldReturnWithTransportReport() {
    			var result = client.getMessage(SELF_IDENTIFIER_VALUE, MESSAGE_ID);
    
    			assertThat(result.transportReport()).isEqualTo(xtaTransportReport);
    		}
    	}
    
    	@DisplayName("close")
    	@Nested
    	class TestClose {
    
    		@DisplayName("should call close")
    		@Test
    		@SneakyThrows
    		void shouldCallClose() {
    			doReturn(SELF_IDENTIFIER).when(client).deriveIdentifier(SELF_IDENTIFIER_VALUE);
    
    			client.close(SELF_IDENTIFIER_VALUE, MESSAGE_ID);
    
    			verify(service).close(MESSAGE_ID, SELF_IDENTIFIER);
    		}
    	}
    
    }