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
Branches
Tags
No related merge requests found
......@@ -39,17 +39,16 @@ public class M012_MigrationUserId {// NOSONAR
private MongoTemplate template;
private RestTemplate restTemplate;
private RestTemplate restTemplate = new RestTemplate();
private String userManagerUrlTemplate;
@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);
if (Objects.nonNull(userManagerUrl)) {
this.template = template;
this.restTemplate = restTemplate;
this.userManagerUrlTemplate = userManagerUrl + "/%s";
migrate();
......
......@@ -15,12 +15,12 @@ import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
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.core.env.Environment;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestTemplate;
......@@ -40,7 +40,7 @@ class M012_MigrationUserIdITCase {
@Autowired
private MongoTemplate template;
@MockBean
@Mock
private RestTemplate restTemplate;
@DisplayName("Migrate")
......@@ -50,18 +50,23 @@ class M012_MigrationUserIdITCase {
@Mock
private Environment env;
@BeforeEach
void init() {
ReflectionTestUtils.setField(migration, "restTemplate", restTemplate);
}
@Test
void shouldInitMigration() {
when(env.getProperty(anyString())).thenReturn(USER_MANAGER_URL);
migration.doMigration(template, restTemplate, env);
migration.doMigration(template, env);
verify(migration, never()).logUrlIsNotConfigured();
}
@Test
void shouldNotInitMigration() {
migration.doMigration(template, restTemplate, env);
migration.doMigration(template, env);
verify(migration).logUrlIsNotConfigured();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment