Skip to content
Snippets Groups Projects
Commit 3b05075e authored by Felix Reichenbach's avatar Felix Reichenbach
Browse files

OZG-6741 add zufiSuche Link

parent b5566408
Branches
Tags
1 merge request!1Ozg 6741 organisationseinheit link
......@@ -32,9 +32,11 @@ import lombok.Setter;
@Setter
@Getter
@Configuration
@ConfigurationProperties(prefix = "ozgcloud.feature")
@ConfigurationProperties(prefix = FeatureToggleProperties.FEATURE_TOGGLE_PREFIX)
public class FeatureToggleProperties {
public static final String FEATURE_TOGGLE_PREFIX = "ozgcloud.feature";
private boolean postfach;
private boolean benutzerRollen;
private boolean organisationsEinheiten;
......
package de.ozgcloud.admin.organisationseinheit;
import jakarta.validation.constraints.NotBlank;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import de.ozgcloud.admin.common.FeatureToggleProperties;
import lombok.Getter;
import lombok.Setter;
@Setter
@Getter
@Configuration
@ConfigurationProperties(prefix = OrganisationsEinheitProperties.ORGANISATIONS_EINHEIT_PROPERTIES_PREFIX)
@ConditionalOnProperty(prefix = FeatureToggleProperties.FEATURE_TOGGLE_PREFIX, name = "organisationsEinheiten", havingValue = "true")
class OrganisationsEinheitProperties {
static final String ORGANISATIONS_EINHEIT_PROPERTIES_PREFIX = "ozgcloud.organisationsEinheit";
@NotBlank
private String zufiSucheUri;
}
......@@ -25,7 +25,10 @@ package de.ozgcloud.admin.organisationseinheit;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.*;
import java.util.List;
import org.springframework.hateoas.EntityModel;
import org.springframework.hateoas.Link;
import org.springframework.hateoas.server.RepresentationModelProcessor;
import org.springframework.stereotype.Component;
......@@ -38,12 +41,22 @@ import lombok.RequiredArgsConstructor;
class OrganisationsEinheitRootProcessor implements RepresentationModelProcessor<EntityModel<Root>> {
static final String REL_ORGANISATIONS_EINHEITEN = "organisationsEinheiten";
static final String REL_SEARCH_ORGANISATIONS_EINHEIT = "searchOrganisationsEinheit";
private final FeatureToggleProperties featureToggleProperties;
private final OrganisationsEinheitProperties organisationsEinheitProperties;
@Override
public EntityModel<Root> process(EntityModel<Root> model) {
return model.addIf(featureToggleProperties.isOrganisationsEinheiten(),
() -> linkTo(methodOn(OrganisationsEinheitController.class).getAll()).withRel(REL_ORGANISATIONS_EINHEITEN));
return model.addAllIf(featureToggleProperties.isOrganisationsEinheiten(),
() -> List.of(buildGetAllOrganisationsEinheitenLink(), buildSearchOrganisationsEinheitLink()));
}
private Link buildGetAllOrganisationsEinheitenLink() {
return linkTo(methodOn(OrganisationsEinheitController.class).getAll()).withRel(REL_ORGANISATIONS_EINHEITEN);
}
private Link buildSearchOrganisationsEinheitLink() {
return Link.of(organisationsEinheitProperties.getZufiSucheUri(), REL_SEARCH_ORGANISATIONS_EINHEIT);
}
}
......@@ -33,6 +33,8 @@ import org.mockito.Mock;
import org.springframework.hateoas.EntityModel;
import org.springframework.hateoas.Link;
import com.thedeanda.lorem.LoremIpsum;
import de.ozgcloud.admin.RootTestFactory;
import de.ozgcloud.admin.common.FeatureToggleProperties;
......@@ -42,10 +44,14 @@ class OrganisationsEinheitRootProcessorTest {
private OrganisationsEinheitRootProcessor organisationsEinheitRootProcessor;
@Mock
private FeatureToggleProperties featureToggleProperties;
@Mock
private OrganisationsEinheitProperties organisationsEinheitProperties;
@Nested
class TestProcess {
private final String zufiSucheUri = LoremIpsum.getInstance().getUrl() + "?searchBy={searchBy}";
@Nested
class OrganisationsEinheitenLinkRelation {
......@@ -78,15 +84,72 @@ class OrganisationsEinheitRootProcessorTest {
.extracting(Link::getHref)
.isEqualTo(OrganisationsEinheitController.PATH);
}
}
@Nested
class SearchOrganisationsEinheitenLink {
@Test
void shouldExistsIfFeatureEnabled() {
givenFeatureIsEnabled();
var model = organisationsEinheitRootProcessor.process(EntityModel.of(RootTestFactory.create()));
assertThat(model.getLink(OrganisationsEinheitRootProcessor.REL_SEARCH_ORGANISATIONS_EINHEIT)).isNotEmpty();
}
@Test
void shouldNotExistIfFeatureDisabled() {
givenFeatureIsDisabled();
var model = organisationsEinheitRootProcessor.process(EntityModel.of(RootTestFactory.create()));
assertThat(model.getLink(OrganisationsEinheitRootProcessor.REL_SEARCH_ORGANISATIONS_EINHEIT)).isEmpty();
}
@Test
void shouldGetZufiSucheUri() {
givenFeatureIsEnabled();
organisationsEinheitRootProcessor.process(EntityModel.of(RootTestFactory.create()));
verify(organisationsEinheitProperties).getZufiSucheUri();
}
@Test
void shouldHaveHref() {
givenFeatureIsEnabled();
var model = organisationsEinheitRootProcessor.process(EntityModel.of(RootTestFactory.create()));
assertThat(model.getLink(OrganisationsEinheitRootProcessor.REL_SEARCH_ORGANISATIONS_EINHEIT))
.get()
.extracting(Link::getHref)
.isEqualTo(zufiSucheUri);
}
@Test
void shouldBeTemplated() {
givenFeatureIsEnabled();
var model = organisationsEinheitRootProcessor.process(EntityModel.of(RootTestFactory.create()));
assertThat(model.getLink(OrganisationsEinheitRootProcessor.REL_SEARCH_ORGANISATIONS_EINHEIT))
.get()
.extracting(Link::isTemplated)
.isEqualTo(true);
}
}
private void givenFeatureIsEnabled() {
when(featureToggleProperties.isOrganisationsEinheiten()).thenReturn(true);
when(organisationsEinheitProperties.getZufiSucheUri()).thenReturn(zufiSucheUri);
}
private void givenFeatureIsDisabled() {
when(featureToggleProperties.isOrganisationsEinheiten()).thenReturn(false);
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment