refactor: consolidate test mock constants into shared Mockdata class
Moved Mockdata from the connection package to the root test package and extended it with MOCK_USER, MOCK_PASS, MOCK_TITLE, and MOCK_DESCRIPTION so all test modules share a single source of truth. Removed duplicate inline constants from ConnectionControllerTest, HomeboxIntegrationTest, and SearchControllerTest. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
package com.vaessl.app;
|
||||
|
||||
public final class Mockdata {
|
||||
|
||||
private Mockdata() {}
|
||||
|
||||
public static final String MOCK_URL = "http://localhost:1234";
|
||||
public static final String MOCK_SERVICE_TYPE = "SERVICE_TYPE";
|
||||
public static final String MOCK_USER = "user";
|
||||
public static final String MOCK_PASS = "pw";
|
||||
public static final String MOCK_TITLE = "title";
|
||||
public static final String MOCK_DESCRIPTION = "desc";
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.vaessl.app.connection;
|
||||
|
||||
import static com.vaessl.app.Mockdata.*;
|
||||
|
||||
import static com.vaessl.app.connection.Endpoint.*;
|
||||
import static com.vaessl.app.connection.ServiceType.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
@@ -27,8 +29,6 @@ class ConnectionControllerTest {
|
||||
@Autowired
|
||||
MockMvc mockMvc;
|
||||
|
||||
private static final String TEST_USER = "admin";
|
||||
private static final String TEST_PASS = "pw";
|
||||
private static final String LOGIN_PATH = LOGIN.getValue();
|
||||
private static final String STATUS_PATH = CONNECTION_STATUS.getValue();
|
||||
private static final String LOGOUT_PATH = "/connections/HOMEBOX";
|
||||
@@ -71,7 +71,7 @@ class ConnectionControllerTest {
|
||||
mockMvc.perform(get(STATUS_PATH).cookie(sessionCookie)).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.length()").value(1))
|
||||
.andExpect(jsonPath("$[0].serviceType").value(HOMEBOX.getValue()))
|
||||
.andExpect(jsonPath("$[0].username").value(TEST_USER))
|
||||
.andExpect(jsonPath("$[0].username").value(MOCK_USER))
|
||||
.andExpect(jsonPath("$[0].appUrl").value(wm.getHttpBaseUrl()))
|
||||
.andExpect(jsonPath("$[0].connected").value(true));
|
||||
}
|
||||
@@ -149,6 +149,6 @@ class ConnectionControllerTest {
|
||||
"username": "%s",
|
||||
"password": "%s"
|
||||
}
|
||||
""".formatted(wm.getHttpBaseUrl(), TEST_USER, TEST_PASS);
|
||||
""".formatted(wm.getHttpBaseUrl(), MOCK_USER, MOCK_PASS);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.vaessl.app.connection;
|
||||
|
||||
import static com.vaessl.app.Mockdata.*;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
@@ -17,8 +18,6 @@ import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import com.vaessl.app.exception.EmptyCredentialsException;
|
||||
|
||||
import static com.vaessl.app.connection.Mockdata.*;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class ConnectionServiceTest {
|
||||
|
||||
|
||||
@@ -5,9 +5,8 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.vaessl.app.exception.EmptyCredentialsException;
|
||||
|
||||
import static com.vaessl.app.Mockdata.*;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static com.vaessl.app.connection.Mockdata.*;
|
||||
|
||||
class HomeboxConnectionProviderTest {
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.vaessl.app.connection;
|
||||
|
||||
import static com.vaessl.app.Mockdata.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.resttestclient.TestRestTemplate;
|
||||
@@ -41,9 +42,6 @@ class HomeboxIntegrationTest {
|
||||
}
|
||||
""";
|
||||
|
||||
private static final String TEST_USER = "admin";
|
||||
private static final String TEST_PASS = "pw";
|
||||
|
||||
/**
|
||||
* Returns Token and status code OK when login is successful.
|
||||
*
|
||||
@@ -139,7 +137,7 @@ class HomeboxIntegrationTest {
|
||||
@Test
|
||||
void shouldReturnWrongServiceTypeException(WireMockRuntimeInfo wm) {
|
||||
ConnectionRequest wrongServiceTypeReq = new ConnectionRequest(wm.getHttpBaseUrl(),
|
||||
"wrong-service-type", TEST_USER, TEST_PASS, false);
|
||||
"wrong-service-type", MOCK_USER, MOCK_PASS, false);
|
||||
|
||||
ResponseEntity<String> response =
|
||||
restTemplate.postForEntity(LOGIN.getValue(), wrongServiceTypeReq, String.class);
|
||||
@@ -182,7 +180,7 @@ class HomeboxIntegrationTest {
|
||||
@Test
|
||||
void shouldReturnEmptyCredentialsExceptionWhenCredsAreMissing(WireMockRuntimeInfo wm) {
|
||||
ConnectionRequest missingCredentials = new ConnectionRequest(wm.getHttpBaseUrl(),
|
||||
HOMEBOX.getValue(), TEST_USER, null, false);
|
||||
HOMEBOX.getValue(), MOCK_USER, null, false);
|
||||
|
||||
ResponseEntity<String> response =
|
||||
restTemplate.postForEntity(LOGIN.getValue(), missingCredentials, String.class);
|
||||
@@ -198,7 +196,7 @@ class HomeboxIntegrationTest {
|
||||
* @return a mock api connection request.
|
||||
*/
|
||||
private ConnectionRequest connectionRequest(WireMockRuntimeInfo wm) {
|
||||
return new ConnectionRequest(wm.getHttpBaseUrl(), HOMEBOX.getValue(), TEST_USER, TEST_PASS,
|
||||
return new ConnectionRequest(wm.getHttpBaseUrl(), HOMEBOX.getValue(), MOCK_USER, MOCK_PASS,
|
||||
null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
package com.vaessl.app.connection;
|
||||
|
||||
public final class Mockdata {
|
||||
|
||||
private Mockdata() {}
|
||||
|
||||
public static final String MOCK_URL = "http://localhost:1234";
|
||||
public static final String MOCK_SERVICE_TYPE = "SERVICE_TYPE";
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.vaessl.app.search;
|
||||
|
||||
import static com.vaessl.app.Mockdata.MOCK_PASS;
|
||||
import static com.vaessl.app.Mockdata.MOCK_USER;
|
||||
import static com.vaessl.app.connection.Endpoint.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
@@ -24,10 +26,6 @@ class SearchControllerTest {
|
||||
@Autowired
|
||||
MockMvc mockMvc;
|
||||
|
||||
private static final String TEST_USER = "admin";
|
||||
|
||||
private static final String TEST_PASS = "pw";
|
||||
|
||||
private static final String QUERY_ALL_ITEMS = HOMEBOX_QUERY_ALL_ITEMS.getValue();
|
||||
|
||||
private static final String LOGIN_PATH = LOGIN.getValue();
|
||||
@@ -138,7 +136,7 @@ class SearchControllerTest {
|
||||
"serviceType": "%s",
|
||||
"username": "%s"
|
||||
}
|
||||
""".formatted(wm.getHttpBaseUrl(), serviceType, TEST_USER);
|
||||
""".formatted(wm.getHttpBaseUrl(), serviceType, MOCK_USER);
|
||||
}
|
||||
|
||||
private String connectionRequestBody(WireMockRuntimeInfo wm) {
|
||||
@@ -149,6 +147,6 @@ class SearchControllerTest {
|
||||
"username": "%s",
|
||||
"password": "%s"
|
||||
}
|
||||
""".formatted(wm.getHttpBaseUrl(), TEST_USER, TEST_PASS);
|
||||
""".formatted(wm.getHttpBaseUrl(), MOCK_USER, MOCK_PASS);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user