extract HomeboxItemClient for reuse between search and sync

HomeboxSearchProvider used to own the RestClient call and item mapping
directly; pulling it into a shared HomeboxItemClient lets the upcoming
sync pipeline page through the same Homebox items without duplicating
the fetch/mapping logic. ConnectionIdentifiable lets both SearchRequest
and SyncRequest be resolved to a connection by the same client.
This commit is contained in:
2026-07-04 01:08:26 +02:00
parent 43b6d227db
commit 48d120fbff
6 changed files with 136 additions and 69 deletions
@@ -10,8 +10,8 @@ import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import com.vaessl.app.connection.ConnectionRepository;
import com.vaessl.app.exception.ConnectionNotFoundException;
import com.vaessl.app.homebox.HomeboxItemClient;
import static com.vaessl.app.shared.ServiceType.HOMEBOX;
@@ -19,7 +19,7 @@ import static com.vaessl.app.shared.ServiceType.HOMEBOX;
class HomeboxSearchProviderTest {
@Mock
private ConnectionRepository mockRepo;
private HomeboxItemClient client;
@InjectMocks
private HomeboxSearchProvider provider;
@@ -27,11 +27,11 @@ class HomeboxSearchProviderTest {
@Test
void shouldReturnConnectionNotFoundException() {
when(mockRepo.findByAppUrlAndUsername(MOCK_URL, MOCK_USER)).thenReturn(null);
SearchRequest request =
new SearchRequest(MOCK_URL, MOCK_USER, "test query", HOMEBOX, false);
Pageable pageable = PageRequest.of(0, 10);
SearchRequest request = new SearchRequest(MOCK_URL, MOCK_USER, "", HOMEBOX, false);
when(client.hbResponse(request, "", pageable)).thenThrow(new ConnectionNotFoundException());
assertThrows(ConnectionNotFoundException.class,
() -> provider.getSearchResults(request, pageable));
}
@@ -93,7 +93,7 @@ class SearchControllerTest {
.andExpect(status().isOk())
.andExpect(jsonPath("$.content[0].title").value("MacBook Pro A1398"))
.andExpect(jsonPath("$.totalElements").value(1))
.andExpect(jsonPath("$.content[0].extraData.parent.name").value("Server Schrank Ikea weiß"));
.andExpect(jsonPath("$.content[0].extraData.locationName").value("Server Schrank Ikea weiß"));
}
@Test