blob: d968cb4570b677ccf017863ea16cfb25f43e9149 [file] [log] [blame]
/*
*******************************************************************************
* Copyright (c) 2019 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************
*/
package org.eclipse.openk.contactbasedata.service;
import org.eclipse.openk.contactbasedata.config.TestConfiguration;
import org.eclipse.openk.contactbasedata.model.VwDetailedContact;
import org.eclipse.openk.contactbasedata.repository.DetailedContactRepository;
import org.eclipse.openk.contactbasedata.service.util.SearchContactsFilterParams;
import org.eclipse.openk.contactbasedata.support.MockDataHelper;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.test.context.ContextConfiguration;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
//@RunWith(SpringRunner.class)
@DataJpaTest
@ContextConfiguration(classes = {TestConfiguration.class})
public class ContactServiceTest {
@Qualifier("myContactService")
@Autowired
private ContactService contactService;
@MockBean
private DetailedContactRepository detailedContactRepository;
@Test
public void shouldFindDetailedContactsProperly() {
Page<VwDetailedContact> mockPaged = MockDataHelper.mockVDetailedContactPage();
when(detailedContactRepository.findAll(any(Pageable.class))).thenReturn(mockPaged);
SearchContactsFilterParams filter = new SearchContactsFilterParams();
Page<VwDetailedContact> retPage = contactService.findDetailedContacts(
filter, PageRequest.of(0, 20));
assertEquals(mockPaged.getTotalElements(), retPage.getTotalElements());
}
}