管道故障org.hibernate.exception.jdbcconnectionexception

7eumitmz  于 2021-06-29  发布在  Java
关注(0)|答案(0)|浏览(312)

我有一个jersey 2.+后端,我使用gitlab ci/cd。我在phpmyadmin中使用一个远程mysql数据库,我通过cisco使用vpn连接到该数据库。另外,我使用mockito进行测试。当我在本地测试时,所有的测试都通过了,但是当推到git时,管道失败了:

package razvan.sem3.project.service;    
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import razvan.sem3.project.data.UserRepository;
import razvan.sem3.project.model.User;    
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;    
import static org.mockito.Mockito.lenient;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

@ExtendWith(MockitoExtension.class)
class UserManagementTest {

    @Mock
    private EntityManager em;
    @Mock
    private UserRepository userRepository;
    @Mock
    private EntityTransaction transaction;
    @InjectMocks
    private UserManagement userManagement;
    @BeforeEach
    public void init(){
        lenient().when(userManagement.em.getTransaction()).thenReturn(transaction);}

    @Test
    void When_createIsCalledWithValidUser_Expect_ReturnUserWithId(){
        Long id = Long.valueOf(11);
        User user = new User("user1.me", "1234", "user1@gmail.com", "User", "NewUser");
        User userSaved = new User("user1.me", "1234", "user1@gmail.com", "User", "NewUser");

        userSaved.setId(id);
        when(userRepository.save(user)).thenReturn(userSaved);

        User created = userManagement.create(user);

        verify(userRepository).save(user);
        assertNotNull(created.getId());
        assertEquals(id, created.getId());
    }
}

此测试在本地通过,当推送到gitlab时,管道将失败,并在添加的图片中显示先前的错误。我确信远程推送时连接有问题。我怎样才能克服这种情况?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题