Skip to content
Snippets Groups Projects
Commit 10e747b9 authored by OZGCloud's avatar OZGCloud
Browse files

OZG-4381 [refactor] do AntragsraumService optional

parent 08db61fe
No related branches found
No related tags found
No related merge requests found
...@@ -13,11 +13,13 @@ import lombok.Setter; ...@@ -13,11 +13,13 @@ import lombok.Setter;
@Getter @Getter
@Setter @Setter
@Configuration @Configuration
@ConditionalOnProperty("ozgcloud.antragsraum.url") @ConditionalOnProperty(AntragsraumProperties.PROPERTY_ANTRAGSRAUM_URL)
@ConfigurationProperties(prefix = "ozgcloud.antragsraum") @ConfigurationProperties(prefix = "ozgcloud.antragsraum")
@Validated @Validated
class AntragsraumProperties { class AntragsraumProperties {
static final String PROPERTY_ANTRAGSRAUM_URL = "ozgcloud.antragsraum.url";
@NotEmpty @NotEmpty
private String url; private String url;
} }
package de.ozgcloud.nachrichten.postfach.antragsraum; package de.ozgcloud.nachrichten.postfach.antragsraum;
import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@Service @Service
@ConditionalOnProperty(AntragsraumProperties.PROPERTY_ANTRAGSRAUM_URL)
public class AntragsraumService { public class AntragsraumService {
@Autowired(required = false) @Autowired
private AntragsraumProperties properties; private AntragsraumProperties properties;
public Optional<String> getAntragsraumUrl() { public String getAntragsraumUrl() {
return Optional.ofNullable(properties.getUrl()); return properties.getUrl();
} }
public boolean isConfigured() {
return getAntragsraumUrl().isPresent();
}
} }
package de.ozgcloud.nachrichten.postfach.bayernid; package de.ozgcloud.nachrichten.postfach.bayernid;
import static java.util.Objects.*;
import java.util.Objects;
import java.util.stream.Stream; import java.util.stream.Stream;
import jakarta.annotation.PostConstruct; import jakarta.annotation.PostConstruct;
...@@ -39,7 +42,7 @@ class BayernIdPostfachRemoteService extends WebServiceGatewaySupport implements ...@@ -39,7 +42,7 @@ class BayernIdPostfachRemoteService extends WebServiceGatewaySupport implements
private BayernIdPostfachResponseHandler responseHandler; private BayernIdPostfachResponseHandler responseHandler;
@Autowired @Autowired
private BayernIdPostfachNachrichtMapper mapper; private BayernIdPostfachNachrichtMapper mapper;
@Autowired @Autowired(required = false)
private AntragsraumService antragsraumService; private AntragsraumService antragsraumService;
@PostConstruct @PostConstruct
...@@ -93,6 +96,10 @@ class BayernIdPostfachRemoteService extends WebServiceGatewaySupport implements ...@@ -93,6 +96,10 @@ class BayernIdPostfachRemoteService extends WebServiceGatewaySupport implements
@Override @Override
public Postfach getPostfach() { public Postfach getPostfach() {
return BayernPostfach.builder().isReplyAllowed(antragsraumService.isConfigured()).build(); return BayernPostfach.builder().isReplyAllowed(isAntragsraumConfigured()).build();
}
boolean isAntragsraumConfigured() {
return nonNull(antragsraumService);
} }
} }
...@@ -27,30 +27,9 @@ class AntragsraumServiceTest { ...@@ -27,30 +27,9 @@ class AntragsraumServiceTest {
var url = service.getAntragsraumUrl(); var url = service.getAntragsraumUrl();
assertThat(url).isPresent().get().isEqualTo(URL); assertThat(url).isEqualTo(URL);
} }
@Test
void shouldReturnEmpty() {
var url = service.getAntragsraumUrl();
assertThat(url).isEmpty();
}
} }
@Nested
class TestIsConfigured {
@Test
void shouldReturnTrue() {
when(properties.getUrl()).thenReturn("url");
assertThat(service.isConfigured()).isTrue();
}
@Test
void shouldReturnFalse() {
assertThat(service.isConfigured()).isFalse();
}
}
} }
\ No newline at end of file
...@@ -48,6 +48,7 @@ import jakarta.xml.bind.JAXBElement; ...@@ -48,6 +48,7 @@ import jakarta.xml.bind.JAXBElement;
class BayernIdPostfachRemoteServiceTest { class BayernIdPostfachRemoteServiceTest {
@Spy
@InjectMocks @InjectMocks
private BayernIdPostfachRemoteService service; private BayernIdPostfachRemoteService service;
...@@ -164,7 +165,6 @@ class BayernIdPostfachRemoteServiceTest { ...@@ -164,7 +165,6 @@ class BayernIdPostfachRemoteServiceTest {
@Nested @Nested
class TestGetPostfach { class TestGetPostfach {
private static final String ANTRAGSRAUM_URL = "https://antragsraum.url";
@Test @Test
void shouldHasTyp() { void shouldHasTyp() {
var postfach = service.getPostfach(); var postfach = service.getPostfach();
...@@ -174,11 +174,18 @@ class BayernIdPostfachRemoteServiceTest { ...@@ -174,11 +174,18 @@ class BayernIdPostfachRemoteServiceTest {
@Test @Test
void shouldAllowReplys() { void shouldAllowReplys() {
when(antragsraumService.isConfigured()).thenReturn(true);
var postfach = service.getPostfach(); var postfach = service.getPostfach();
assertThat(postfach.isReplyAllowed()).isTrue(); assertThat(postfach.isReplyAllowed()).isTrue();
} }
@Test
void shouldSetReplyNotAllowed() {
doReturn(false).when(service).isAntragsraumConfigured();
var postfach = service.getPostfach();
assertThat(postfach.isReplyAllowed()).isFalse();
}
} }
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment