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

Merge branch 'OZG-7615-Leitfaden-link' into 'main'

Ozg 7615 leitfaden link

See merge request !6
parents 2f5e4cf5 b2fb30f0
Branches
Tags
1 merge request!6Ozg 7615 leitfaden link
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
<parent> <parent>
<groupId>de.ozgcloud.common</groupId> <groupId>de.ozgcloud.common</groupId>
<artifactId>ozgcloud-common-parent</artifactId> <artifactId>ozgcloud-common-parent</artifactId>
<version>4.9.0</version> <version>4.11.0-SNAPSHOT</version>
<relativePath /> <relativePath />
</parent> </parent>
......
...@@ -70,6 +70,10 @@ spec: ...@@ -70,6 +70,10 @@ spec:
value: {{ include "app.ssoClientName" . }} value: {{ include "app.ssoClientName" . }}
- name: ozgcloud_oauth2_auth-server-url - name: ozgcloud_oauth2_auth-server-url
value: {{ include "app.ssoServerUrl" . }} value: {{ include "app.ssoServerUrl" . }}
{{- if (((.Values.ozgcloud).user_assistance).documentation).url }}
- name: ozgcloud_user-assistance_documentation_url
value: {{ .Values.ozgcloud.user_assistance.documentation.url }}
{{- end }}
{{- if not (.Values.database).useExternal }} {{- if not (.Values.database).useExternal }}
- name: spring_data_mongodb_uri - name: spring_data_mongodb_uri
valueFrom: valueFrom:
......
package de.ozgcloud.admin;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import lombok.Getter;
import lombok.Setter;
@Setter
@Getter
@Configuration
@ConfigurationProperties(prefix = DocumentationProperties.DOCUMENTATION_PROPERTIES_PREFIX)
public class DocumentationProperties {
static final String DOCUMENTATION_PROPERTIES_PREFIX = "ozgcloud.user-assistance.documentation";
/*
* Url pointing to the documentation (Benutzerleitfaden fuer die
* Administration).
*/
private String url;
}
...@@ -23,8 +23,7 @@ ...@@ -23,8 +23,7 @@
*/ */
package de.ozgcloud.admin; package de.ozgcloud.admin;
import java.util.ArrayList; import java.util.Objects;
import java.util.List;
import org.springframework.boot.autoconfigure.data.rest.RepositoryRestProperties; import org.springframework.boot.autoconfigure.data.rest.RepositoryRestProperties;
import org.springframework.hateoas.EntityModel; import org.springframework.hateoas.EntityModel;
...@@ -40,24 +39,23 @@ import lombok.RequiredArgsConstructor; ...@@ -40,24 +39,23 @@ import lombok.RequiredArgsConstructor;
@RequiredArgsConstructor @RequiredArgsConstructor
public class RootModelAssembler implements RepresentationModelAssembler<Root, EntityModel<Root>> { public class RootModelAssembler implements RepresentationModelAssembler<Root, EntityModel<Root>> {
static final String REL_CONFIGURATION = "configuration"; static final String REL_CONFIGURATION = "configuration";
static final String REL_DOCUMENTATIONS = "documentations";
private final RepositoryRestProperties restProperties; private final RepositoryRestProperties restProperties;
private final CurrentUserService currentUserService; private final CurrentUserService currentUserService;
private final DocumentationProperties documentationProperties;
@Override @Override
public EntityModel<Root> toModel(Root root) { public EntityModel<Root> toModel(Root root) {
List<Link> links = buildRootModelLinks(); var rootModel = EntityModel.of(root);
return EntityModel.of(root, links); addLinks(rootModel);
return rootModel;
} }
List<Link> buildRootModelLinks() { private void addLinks(EntityModel<Root> rootModel) {
List<Link> links = new ArrayList<>(); rootModel.add(WebMvcLinkBuilder.linkTo(RootController.class).withSelfRel());
var rootLinkBuilder = WebMvcLinkBuilder.linkTo(RootController.class); rootModel.addIf(currentUserService.hasConfigurationPermission(), this::buildConfigLink);
links.add(rootLinkBuilder.withSelfRel()); rootModel.addIf(Objects.nonNull(documentationProperties.getUrl()), () -> Link.of(documentationProperties.getUrl(), REL_DOCUMENTATIONS));
if (currentUserService.hasConfigurationPermission()) {
links.add(buildConfigLink());
}
return links;
} }
private Link buildConfigLink() { private Link buildConfigLink() {
......
...@@ -54,5 +54,15 @@ tests: ...@@ -54,5 +54,15 @@ tests:
content: content:
name: ozgcloud_administration_sync_organisationseinheiten_cron name: ozgcloud_administration_sync_organisationseinheiten_cron
value: "*/15 * * * *" value: "*/15 * * * *"
- it: should have user assistance documentation url
set:
ozgcloud:
user_assistance:
documentation:
url: http://hier/geht/es/zum/benutzerleitfaden.de
asserts:
- contains:
path: spec.template.spec.containers[0].env
content:
name: ozgcloud_user-assistance_documentation_url
value: http://hier/geht/es/zum/benutzerleitfaden.de
...@@ -27,8 +27,6 @@ import static de.ozgcloud.admin.RootModelAssembler.*; ...@@ -27,8 +27,6 @@ import static de.ozgcloud.admin.RootModelAssembler.*;
import static org.assertj.core.api.Assertions.*; import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
import java.util.List;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Nested;
...@@ -37,8 +35,11 @@ import org.mockito.InjectMocks; ...@@ -37,8 +35,11 @@ import org.mockito.InjectMocks;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.Spy; import org.mockito.Spy;
import org.springframework.boot.autoconfigure.data.rest.RepositoryRestProperties; import org.springframework.boot.autoconfigure.data.rest.RepositoryRestProperties;
import org.springframework.hateoas.IanaLinkRelations;
import org.springframework.hateoas.Link; import org.springframework.hateoas.Link;
import com.thedeanda.lorem.LoremIpsum;
import de.ozgcloud.admin.common.user.CurrentUserService; import de.ozgcloud.admin.common.user.CurrentUserService;
class RootModelAssemblerTest { class RootModelAssemblerTest {
...@@ -53,82 +54,116 @@ class RootModelAssemblerTest { ...@@ -53,82 +54,116 @@ class RootModelAssemblerTest {
private RepositoryRestProperties restProperties; private RepositoryRestProperties restProperties;
@Mock @Mock
private CurrentUserService currentUserService; private CurrentUserService currentUserService;
@Mock
private DocumentationProperties documentationProperties;
@DisplayName("Entity Model") @DisplayName("Entity Model")
@Nested @Nested
class TestEntityModel { class TestToModel {
private final List<Link> links = List.of(Link.of(RootController.PATH));
@BeforeEach private final Root root = RootTestFactory.create();
void beforeEach() {
doReturn(links).when(modelAssembler).buildRootModelLinks();
}
@Test @Test
void shouldHaveRoot() { void shouldHaveRootContent() {
var givenRoot = RootTestFactory.create(); var resultRoot = modelAssembler.toModel(root).getContent();
var resultRoot = modelAssembler.toModel(givenRoot).getContent();
assertThat(resultRoot).isEqualTo(givenRoot); assertThat(resultRoot).isEqualTo(root);
} }
@Test @Test
void shouldHaveLinks() { void shouldHaveSelfLink() {
var modelLinks = modelAssembler.toModel(RootTestFactory.create()).getLinks(); var model = modelAssembler.toModel(root);
assertThat(modelLinks).containsAll(links); assertThat(model.getLink(IanaLinkRelations.SELF)).get().extracting(Link::getHref).isEqualTo(RootController.PATH);
} }
}
@DisplayName("Root Model Links") @Nested
@Nested class TestConfigurationLink {
class TestBuildRootModelLinks {
@Test @Test
void shouldCheckConfigurationPermission() { void shouldCallHasConfigurationPermission() {
modelAssembler.buildRootModelLinks(); modelAssembler.toModel(root);
verify(currentUserService).hasConfigurationPermission(); verify(currentUserService).hasConfigurationPermission();
} }
@Nested @Nested
class TestOnHasConfigurationPermission { class TestOnHasConfigurationPermission {
@BeforeEach
void mock() {
when(currentUserService.hasConfigurationPermission()).thenReturn(true);
when(restProperties.getBasePath()).thenReturn(BASE_PATH);
}
@Test
void shouldHaveHrefToConfiguration() {
var model = modelAssembler.toModel(root);
@BeforeEach assertThat(model.getLink(REL_CONFIGURATION)).get().extracting(Link::getHref).isEqualTo(BASE_PATH);
void hasConfigurationPermission() { }
when(currentUserService.hasConfigurationPermission()).thenReturn(true);
when(restProperties.getBasePath()).thenReturn(BASE_PATH);
} }
@Test @Nested
void shouldHaveHrefToConfiguration() { class TestOnHasNotConfigurationPermission {
var links = modelAssembler.buildRootModelLinks();
@BeforeEach
void mock() {
when(currentUserService.hasConfigurationPermission()).thenReturn(false);
}
assertThat(links).containsExactly( @Test
Link.of(RootController.PATH), void shouldNotHaveConfigurationLink() {
Link.of(BASE_PATH, REL_CONFIGURATION)); var model = modelAssembler.toModel(root);
assertThat(model.getLink(REL_CONFIGURATION)).isEmpty();
}
} }
} }
@Nested @Nested
class TestOnNotHasConfigurationPermission { class TestDocumentationLink {
@Test
void shouldGetDocumentationUrl() {
modelAssembler.toModel(root);
@BeforeEach verify(documentationProperties).getUrl();
void hasNotConfigurationPermission() {
when(currentUserService.hasConfigurationPermission()).thenReturn(false);
} }
@Test @Nested
void shouldHaveOnlySelfLink() { class TestOnDocumentationUrlGiven {
var links = modelAssembler.buildRootModelLinks();
private final String documentationUrl = LoremIpsum.getInstance().getUrl();
@BeforeEach
void mock() {
when(documentationProperties.getUrl()).thenReturn(documentationUrl);
}
assertThat(links).containsExactly( @Test
Link.of(RootController.PATH)); void shouldHaveDocumentationLink() {
var model = modelAssembler.toModel(root);
assertThat(model.getLink(REL_DOCUMENTATIONS)).get().extracting(Link::getHref).isEqualTo(documentationUrl);
}
} }
}
} @Nested
class TestOnDocumentationUrlNotGiven {
@BeforeEach
void mock() {
when(documentationProperties.getUrl()).thenReturn(null);
}
@Test
void shouldNotHaveDocumentationLink() {
var model = modelAssembler.toModel(root);
assertThat(model.getLink(REL_DOCUMENTATIONS)).isEmpty();
}
}
}
}
} }
\ 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