Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
dschadow committed Oct 28, 2023
1 parent 642a95e commit 22d2460
Show file tree
Hide file tree
Showing 12 changed files with 23 additions and 52 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 Dominik Schadow, dominikschadow@gmail.com
* Copyright (C) 2023 Dominik Schadow, dominikschadow@gmail.com
*
* This file is part of the Cloud Security project.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 Dominik Schadow, dominikschadow@gmail.com
* Copyright (C) 2023 Dominik Schadow, dominikschadow@gmail.com
*
* This file is part of the Cloud Security project.
*
Expand All @@ -17,8 +17,6 @@
*/
package de.dominikschadow.configclient;

import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;

/**
Expand All @@ -27,18 +25,7 @@
* @author Dominik Schadow
*/
@ConfigurationProperties(prefix = "config.client")
@Getter
@Setter
public class ConfigClientProperties {
private Application application;

/**
* Basic application information.
*/
@Getter
@Setter
public static class Application {
private String name;
private String profile;
public record ConfigClientProperties (Application application) {
public record Application (String name, String profile) {
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 Dominik Schadow, dominikschadow@gmail.com
* Copyright (C) 2023 Dominik Schadow, dominikschadow@gmail.com
*
* This file is part of the Cloud Security project.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 Dominik Schadow, dominikschadow@gmail.com
* Copyright (C) 2023 Dominik Schadow, dominikschadow@gmail.com
*
* This file is part of the Cloud Security project.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 Dominik Schadow, dominikschadow@gmail.com
* Copyright (C) 2023 Dominik Schadow, dominikschadow@gmail.com
*
* This file is part of the Cloud Security project.
*
Expand Down Expand Up @@ -50,9 +50,9 @@ public class AboutController {
public ResponseEntity<ApplicationInformation> about() {
String about = "Application properties are not set";

if (properties.getApplication() != null) {
about = String.format("%s with profile %s", properties.getApplication().getName(),
properties.getApplication().getProfile());
if (properties.application() != null) {
about = String.format("%s with profile %s", properties.application().name(),
properties.application().profile());
}

ApplicationInformation info = new ApplicationInformation(about);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 Dominik Schadow, dominikschadow@gmail.com
* Copyright (C) 2023 Dominik Schadow, dominikschadow@gmail.com
*
* This file is part of the Cloud Security project.
*
Expand All @@ -17,16 +17,12 @@
*/
package de.dominikschadow.configclient.info;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.springframework.hateoas.RepresentationModel;

@Getter
@RequiredArgsConstructor
public class ApplicationInformation extends RepresentationModel<ApplicationInformation> {
private final String info;

public ApplicationInformation(String info) {
this.info = info;
}

public String getInfo() {
return info;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 Dominik Schadow, dominikschadow@gmail.com
* Copyright (C) 2023 Dominik Schadow, dominikschadow@gmail.com
*
* This file is part of the Cloud Security project.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 Dominik Schadow, dominikschadow@gmail.com
* Copyright (C) 2023 Dominik Schadow, dominikschadow@gmail.com
*
* This file is part of the Cloud Security project.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 Dominik Schadow, dominikschadow@gmail.com
* Copyright (C) 2023 Dominik Schadow, dominikschadow@gmail.com
*
* This file is part of the Cloud Security project.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 Dominik Schadow, dominikschadow@gmail.com
* Copyright (C) 2023 Dominik Schadow, dominikschadow@gmail.com
*
* This file is part of the Cloud Security project.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 Dominik Schadow, dominikschadow@gmail.com
* Copyright (C) 2023 Dominik Schadow, dominikschadow@gmail.com
*
* This file is part of the Cloud Security project.
*
Expand All @@ -17,16 +17,15 @@
*/
package de.dominikschadow.configclient.info;

import de.dominikschadow.configclient.ConfigClientProperties;
import de.dominikschadow.configclient.credential.CredentialRepository;
import de.dominikschadow.configclient.user.UserRepository;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.data.rest.webmvc.support.RepositoryEntityLinks;
import org.springframework.hateoas.Link;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
Expand All @@ -39,27 +38,16 @@
* @author Dominik Schadow
*/
@WebMvcTest(AboutController.class)
@TestPropertySource(properties = {"config.client.application.name=Config Client", "config.client.application.profile=test"})
class AboutControllerTest {
@Autowired
private MockMvc mvc;

@MockBean
private ConfigClientProperties properties;
@MockBean
private RepositoryEntityLinks entityLinks;

private ConfigClientProperties.Application application;

@BeforeEach
void setup() {
application = new ConfigClientProperties.Application();
application.setName("Config Client");
application.setProfile("test");
}

@Test
void givenGetRequestWhenUsingRootUrlThenReturnStartPage() throws Exception {
given(properties.getApplication()).willReturn(application);
given(entityLinks.linkToCollectionResource(UserRepository.class)).willReturn(Link.of("/users"));
given(entityLinks.linkToCollectionResource(CredentialRepository.class)).willReturn(Link.of("/credentials"));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 Dominik Schadow, dominikschadow@gmail.com
* Copyright (C) 2023 Dominik Schadow, dominikschadow@gmail.com
*
* This file is part of the Cloud Security project.
*
Expand Down

0 comments on commit 22d2460

Please sign in to comment.