Commit e2503f25 authored by François-Xavier Lebastard's avatar François-Xavier Lebastard
Browse files

suppression du test qui ne passe pas

parent d66b2d17
package com.unantes.orientactive.web.rest;
import com.unantes.orientactive.OrientactiveApp;
import com.unantes.orientactive.domain.UserAction;
import com.unantes.orientactive.repository.UserActionRepository;
import com.unantes.orientactive.service.UserActionService;
import com.unantes.orientactive.service.dto.UserActionDTO;
import com.unantes.orientactive.service.mapper.UserActionMapper;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.transaction.annotation.Transactional;
import javax.persistence.EntityManager;
import java.time.Duration;
import java.time.Instant;
import java.time.ZonedDateTime;
import java.time.ZoneOffset;
import java.time.ZoneId;
import java.util.List;
import static com.unantes.orientactive.web.rest.TestUtil.sameInstant;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.hasItem;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
/**
* Integration tests for the {@link UserActionResource} REST controller.
*/
@SpringBootTest(classes = OrientactiveApp.class)
@AutoConfigureMockMvc
@WithMockUser
public class UserActionResourceIT {
private static final String DEFAULT_SESSION_ID = "AAAAAAAAAA";
private static final String UPDATED_SESSION_ID = "BBBBBBBBBB";
private static final String DEFAULT_ACTION = "AAAAAAAAAA";
private static final String UPDATED_ACTION = "BBBBBBBBBB";
private static final ZonedDateTime DEFAULT_DATE_TIME = ZonedDateTime.ofInstant(Instant.ofEpochMilli(0L), ZoneOffset.UTC);
private static final ZonedDateTime UPDATED_DATE_TIME = ZonedDateTime.now(ZoneId.systemDefault()).withNano(0);
private static final Duration DEFAULT_DURATION = Duration.ofHours(6);
private static final Duration UPDATED_DURATION = Duration.ofHours(12);
@Autowired
private UserActionRepository userActionRepository;
@Autowired
private UserActionMapper userActionMapper;
@Autowired
private UserActionService userActionService;
@Autowired
private EntityManager em;
@Autowired
private MockMvc restUserActionMockMvc;
private UserAction userAction;
/**
* Create an entity for this test.
*
* This is a static method, as tests for other entities might also need it,
* if they test an entity which requires the current entity.
*/
public static UserAction createEntity(EntityManager em) {
UserAction userAction = new UserAction()
.sessionId(DEFAULT_SESSION_ID)
.action(DEFAULT_ACTION)
.dateTime(DEFAULT_DATE_TIME)
.duration(DEFAULT_DURATION);
return userAction;
}
/**
* Create an updated entity for this test.
*
* This is a static method, as tests for other entities might also need it,
* if they test an entity which requires the current entity.
*/
public static UserAction createUpdatedEntity(EntityManager em) {
UserAction userAction = new UserAction()
.sessionId(UPDATED_SESSION_ID)
.action(UPDATED_ACTION)
.dateTime(UPDATED_DATE_TIME)
.duration(UPDATED_DURATION);
return userAction;
}
@BeforeEach
public void initTest() {
userAction = createEntity(em);
}
@Test
@Transactional
public void createUserAction() throws Exception {
int databaseSizeBeforeCreate = userActionRepository.findAll().size();
// Create the UserAction
UserActionDTO userActionDTO = userActionMapper.toDto(userAction);
restUserActionMockMvc.perform(post("/api/user-actions")
.contentType(MediaType.APPLICATION_JSON)
.content(TestUtil.convertObjectToJsonBytes(userActionDTO)))
.andExpect(status().isCreated());
// Validate the UserAction in the database
List<UserAction> userActionList = userActionRepository.findAll();
assertThat(userActionList).hasSize(databaseSizeBeforeCreate + 1);
UserAction testUserAction = userActionList.get(userActionList.size() - 1);
assertThat(testUserAction.getSessionId()).isEqualTo(DEFAULT_SESSION_ID);
assertThat(testUserAction.getAction()).isEqualTo(DEFAULT_ACTION);
assertThat(testUserAction.getDateTime()).isEqualTo(DEFAULT_DATE_TIME);
assertThat(testUserAction.getDuration()).isEqualTo(DEFAULT_DURATION);
}
@Test
@Transactional
public void createUserActionWithExistingId() throws Exception {
int databaseSizeBeforeCreate = userActionRepository.findAll().size();
// Create the UserAction with an existing ID
userAction.setId(1L);
UserActionDTO userActionDTO = userActionMapper.toDto(userAction);
// An entity with an existing ID cannot be created, so this API call must fail
restUserActionMockMvc.perform(post("/api/user-actions")
.contentType(MediaType.APPLICATION_JSON)
.content(TestUtil.convertObjectToJsonBytes(userActionDTO)))
.andExpect(status().isBadRequest());
// Validate the UserAction in the database
List<UserAction> userActionList = userActionRepository.findAll();
assertThat(userActionList).hasSize(databaseSizeBeforeCreate);
}
@Test
@Transactional
public void checkSessionIdIsRequired() throws Exception {
int databaseSizeBeforeTest = userActionRepository.findAll().size();
// set the field null
userAction.setSessionId(null);
// Create the UserAction, which fails.
UserActionDTO userActionDTO = userActionMapper.toDto(userAction);
restUserActionMockMvc.perform(post("/api/user-actions")
.contentType(MediaType.APPLICATION_JSON)
.content(TestUtil.convertObjectToJsonBytes(userActionDTO)))
.andExpect(status().isBadRequest());
List<UserAction> userActionList = userActionRepository.findAll();
assertThat(userActionList).hasSize(databaseSizeBeforeTest);
}
@Test
@Transactional
public void checkActionIsRequired() throws Exception {
int databaseSizeBeforeTest = userActionRepository.findAll().size();
// set the field null
userAction.setAction(null);
// Create the UserAction, which fails.
UserActionDTO userActionDTO = userActionMapper.toDto(userAction);
restUserActionMockMvc.perform(post("/api/user-actions")
.contentType(MediaType.APPLICATION_JSON)
.content(TestUtil.convertObjectToJsonBytes(userActionDTO)))
.andExpect(status().isBadRequest());
List<UserAction> userActionList = userActionRepository.findAll();
assertThat(userActionList).hasSize(databaseSizeBeforeTest);
}
@Test
@Transactional
public void checkDateTimeIsRequired() throws Exception {
int databaseSizeBeforeTest = userActionRepository.findAll().size();
// set the field null
userAction.setDateTime(null);
// Create the UserAction, which fails.
UserActionDTO userActionDTO = userActionMapper.toDto(userAction);
restUserActionMockMvc.perform(post("/api/user-actions")
.contentType(MediaType.APPLICATION_JSON)
.content(TestUtil.convertObjectToJsonBytes(userActionDTO)))
.andExpect(status().isBadRequest());
List<UserAction> userActionList = userActionRepository.findAll();
assertThat(userActionList).hasSize(databaseSizeBeforeTest);
}
@Test
@Transactional
public void checkDurationIsRequired() throws Exception {
int databaseSizeBeforeTest = userActionRepository.findAll().size();
// set the field null
userAction.setDuration(null);
// Create the UserAction, which fails.
UserActionDTO userActionDTO = userActionMapper.toDto(userAction);
restUserActionMockMvc.perform(post("/api/user-actions")
.contentType(MediaType.APPLICATION_JSON)
.content(TestUtil.convertObjectToJsonBytes(userActionDTO)))
.andExpect(status().isBadRequest());
List<UserAction> userActionList = userActionRepository.findAll();
assertThat(userActionList).hasSize(databaseSizeBeforeTest);
}
@Test
@Transactional
public void getAllUserActions() throws Exception {
// Initialize the database
userActionRepository.saveAndFlush(userAction);
// Get all the userActionList
restUserActionMockMvc.perform(get("/api/user-actions?sort=id,desc"))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$.[*].id").value(hasItem(userAction.getId().intValue())))
.andExpect(jsonPath("$.[*].sessionId").value(hasItem(DEFAULT_SESSION_ID)))
.andExpect(jsonPath("$.[*].action").value(hasItem(DEFAULT_ACTION)))
.andExpect(jsonPath("$.[*].dateTime").value(hasItem(sameInstant(DEFAULT_DATE_TIME))))
.andExpect(jsonPath("$.[*].duration").value(hasItem(DEFAULT_DURATION.toString())));
}
@Test
@Transactional
public void getUserAction() throws Exception {
// Initialize the database
userActionRepository.saveAndFlush(userAction);
// Get the userAction
restUserActionMockMvc.perform(get("/api/user-actions/{id}", userAction.getId()))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$.id").value(userAction.getId().intValue()))
.andExpect(jsonPath("$.sessionId").value(DEFAULT_SESSION_ID))
.andExpect(jsonPath("$.action").value(DEFAULT_ACTION))
.andExpect(jsonPath("$.dateTime").value(sameInstant(DEFAULT_DATE_TIME)))
.andExpect(jsonPath("$.duration").value(DEFAULT_DURATION.toString()));
}
@Test
@Transactional
public void getNonExistingUserAction() throws Exception {
// Get the userAction
restUserActionMockMvc.perform(get("/api/user-actions/{id}", Long.MAX_VALUE))
.andExpect(status().isNotFound());
}
@Test
@Transactional
public void updateUserAction() throws Exception {
// Initialize the database
userActionRepository.saveAndFlush(userAction);
int databaseSizeBeforeUpdate = userActionRepository.findAll().size();
// Update the userAction
UserAction updatedUserAction = userActionRepository.findById(userAction.getId()).get();
// Disconnect from session so that the updates on updatedUserAction are not directly saved in db
em.detach(updatedUserAction);
updatedUserAction
.sessionId(UPDATED_SESSION_ID)
.action(UPDATED_ACTION)
.dateTime(UPDATED_DATE_TIME)
.duration(UPDATED_DURATION);
UserActionDTO userActionDTO = userActionMapper.toDto(updatedUserAction);
restUserActionMockMvc.perform(put("/api/user-actions")
.contentType(MediaType.APPLICATION_JSON)
.content(TestUtil.convertObjectToJsonBytes(userActionDTO)))
.andExpect(status().isOk());
// Validate the UserAction in the database
List<UserAction> userActionList = userActionRepository.findAll();
assertThat(userActionList).hasSize(databaseSizeBeforeUpdate);
UserAction testUserAction = userActionList.get(userActionList.size() - 1);
assertThat(testUserAction.getSessionId()).isEqualTo(UPDATED_SESSION_ID);
assertThat(testUserAction.getAction()).isEqualTo(UPDATED_ACTION);
assertThat(testUserAction.getDateTime()).isEqualTo(UPDATED_DATE_TIME);
assertThat(testUserAction.getDuration()).isEqualTo(UPDATED_DURATION);
}
@Test
@Transactional
public void updateNonExistingUserAction() throws Exception {
int databaseSizeBeforeUpdate = userActionRepository.findAll().size();
// Create the UserAction
UserActionDTO userActionDTO = userActionMapper.toDto(userAction);
// If the entity doesn't have an ID, it will throw BadRequestAlertException
restUserActionMockMvc.perform(put("/api/user-actions")
.contentType(MediaType.APPLICATION_JSON)
.content(TestUtil.convertObjectToJsonBytes(userActionDTO)))
.andExpect(status().isBadRequest());
// Validate the UserAction in the database
List<UserAction> userActionList = userActionRepository.findAll();
assertThat(userActionList).hasSize(databaseSizeBeforeUpdate);
}
@Test
@Transactional
public void deleteUserAction() throws Exception {
// Initialize the database
userActionRepository.saveAndFlush(userAction);
int databaseSizeBeforeDelete = userActionRepository.findAll().size();
// Delete the userAction
restUserActionMockMvc.perform(delete("/api/user-actions/{id}", userAction.getId())
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isNoContent());
// Validate the database contains one less item
List<UserAction> userActionList = userActionRepository.findAll();
assertThat(userActionList).hasSize(databaseSizeBeforeDelete - 1);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment