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

Merge pull request 'OZG-2737 do not inject RestTemplate' (#76) from...

Merge pull request 'OZG-2737 do not inject RestTemplate' (#76) from OZG-2737_fix_userId_migration into master

Reviewed-on: https://git.ozg-sh.de/mgm/pluto/pulls/76
parents 0979b058 b21f15ac
No related branches found
No related tags found
No related merge requests found
...@@ -39,17 +39,16 @@ public class M012_MigrationUserId {// NOSONAR ...@@ -39,17 +39,16 @@ public class M012_MigrationUserId {// NOSONAR
private MongoTemplate template; private MongoTemplate template;
private RestTemplate restTemplate; private RestTemplate restTemplate = new RestTemplate();
private String userManagerUrlTemplate; private String userManagerUrlTemplate;
@Execution @Execution
public void doMigration(MongoTemplate template, RestTemplate restTemplate, Environment environment) { public void doMigration(MongoTemplate template, Environment environment) {
var userManagerUrl = environment.getProperty(KOP_USERMANAGER_URL_KEY); var userManagerUrl = environment.getProperty(KOP_USERMANAGER_URL_KEY);
if (Objects.nonNull(userManagerUrl)) { if (Objects.nonNull(userManagerUrl)) {
this.template = template; this.template = template;
this.restTemplate = restTemplate;
this.userManagerUrlTemplate = userManagerUrl + "/%s"; this.userManagerUrlTemplate = userManagerUrl + "/%s";
migrate(); migrate();
......
...@@ -15,12 +15,12 @@ import org.junit.jupiter.api.Nested; ...@@ -15,12 +15,12 @@ import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.mockito.Mock; import org.mockito.Mock;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.boot.test.mock.mockito.SpyBean; import org.springframework.boot.test.mock.mockito.SpyBean;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.web.client.HttpClientErrorException; import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
...@@ -40,7 +40,7 @@ class M012_MigrationUserIdITCase { ...@@ -40,7 +40,7 @@ class M012_MigrationUserIdITCase {
@Autowired @Autowired
private MongoTemplate template; private MongoTemplate template;
@MockBean @Mock
private RestTemplate restTemplate; private RestTemplate restTemplate;
@DisplayName("Migrate") @DisplayName("Migrate")
...@@ -50,18 +50,23 @@ class M012_MigrationUserIdITCase { ...@@ -50,18 +50,23 @@ class M012_MigrationUserIdITCase {
@Mock @Mock
private Environment env; private Environment env;
@BeforeEach
void init() {
ReflectionTestUtils.setField(migration, "restTemplate", restTemplate);
}
@Test @Test
void shouldInitMigration() { void shouldInitMigration() {
when(env.getProperty(anyString())).thenReturn(USER_MANAGER_URL); when(env.getProperty(anyString())).thenReturn(USER_MANAGER_URL);
migration.doMigration(template, restTemplate, env); migration.doMigration(template, env);
verify(migration, never()).logUrlIsNotConfigured(); verify(migration, never()).logUrlIsNotConfigured();
} }
@Test @Test
void shouldNotInitMigration() { void shouldNotInitMigration() {
migration.doMigration(template, restTemplate, env); migration.doMigration(template, env);
verify(migration).logUrlIsNotConfigured(); verify(migration).logUrlIsNotConfigured();
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment