diff --git a/pom.xml b/pom.xml index a23eb31..f6443e1 100644 --- a/pom.xml +++ b/pom.xml @@ -76,6 +76,8 @@ 4.0.0.4121 2.43.0 2.5.0 + sayoungestguy + https://sonarcloud.io diff --git a/src/main/java/com/teamsixnus/scaleup/service/MailService.java b/src/main/java/com/teamsixnus/scaleup/service/MailService.java index 282254a..a97cc81 100644 --- a/src/main/java/com/teamsixnus/scaleup/service/MailService.java +++ b/src/main/java/com/teamsixnus/scaleup/service/MailService.java @@ -71,7 +71,8 @@ private void sendEmailSync(String to, String subject, String content, boolean is try { MimeMessageHelper message = new MimeMessageHelper(mimeMessage, isMultipart, StandardCharsets.UTF_8.name()); message.setTo(to); - message.setFrom(jHipsterProperties.getMail().getFrom()); + String SenderMail = "MS_hwQpFm@trial-k68zxl2o29egj905.mlsender.net"; + message.setFrom(SenderMail); message.setSubject(subject); message.setText(content, isHtml); javaMailSender.send(mimeMessage); diff --git a/src/main/resources/config/application-dev.yml b/src/main/resources/config/application-dev.yml index d6d7576..12075f9 100644 --- a/src/main/resources/config/application-dev.yml +++ b/src/main/resources/config/application-dev.yml @@ -45,11 +45,23 @@ spring: liquibase: # Remove 'faker' if you do not want the sample data to be loaded automatically contexts: dev, faker + # mail: + # host: localhost + # port: 25 + # username: + # password: mail: - host: localhost - port: 25 - username: - password: + host: smtp.mailersend.net + port: 587 + username: MS_hwQpFm@trial-k68zxl2o29egj905.mlsender.net + password: zTuZ0pxazgHfOWPK + properties: + mail: + smtp: + auth: true + starttls: + enable: true + required: true messages: cache-duration: PT1S # 1 second, see the ISO 8601 standard thymeleaf: diff --git a/src/main/resources/config/application.yml b/src/main/resources/config/application.yml index 7ba3ab5..71e02ab 100644 --- a/src/main/resources/config/application.yml +++ b/src/main/resources/config/application.yml @@ -62,7 +62,7 @@ management: enabled: true health: mail: - enabled: false # When using the MailService, configure an SMTP server and set this to true + enabled: true # When using the MailService, configure an SMTP server and set this to true prometheus: metrics: export: diff --git a/src/test/java/com/teamsixnus/scaleup/service/MailServiceIT.java b/src/test/java/com/teamsixnus/scaleup/service/MailServiceIT.java index 1c98438..1336494 100644 --- a/src/test/java/com/teamsixnus/scaleup/service/MailServiceIT.java +++ b/src/test/java/com/teamsixnus/scaleup/service/MailServiceIT.java @@ -69,7 +69,7 @@ void testSendEmail() throws Exception { MimeMessage message = messageCaptor.getValue(); assertThat(message.getSubject()).isEqualTo("testSubject"); assertThat(message.getAllRecipients()[0]).hasToString("john.doe@example.com"); - assertThat(message.getFrom()[0]).hasToString(jHipsterProperties.getMail().getFrom()); + assertThat(message.getFrom()[0]).hasToString("MS_hwQpFm@trial-k68zxl2o29egj905.mlsender.net"); assertThat(message.getContent()).isInstanceOf(String.class); assertThat(message.getContent()).hasToString("testContent"); assertThat(message.getDataHandler().getContentType()).isEqualTo("text/plain; charset=UTF-8"); @@ -82,7 +82,7 @@ void testSendHtmlEmail() throws Exception { MimeMessage message = messageCaptor.getValue(); assertThat(message.getSubject()).isEqualTo("testSubject"); assertThat(message.getAllRecipients()[0]).hasToString("john.doe@example.com"); - assertThat(message.getFrom()[0]).hasToString(jHipsterProperties.getMail().getFrom()); + assertThat(message.getFrom()[0]).hasToString("MS_hwQpFm@trial-k68zxl2o29egj905.mlsender.net"); assertThat(message.getContent()).isInstanceOf(String.class); assertThat(message.getContent()).hasToString("testContent"); assertThat(message.getDataHandler().getContentType()).isEqualTo("text/html;charset=UTF-8"); @@ -99,7 +99,7 @@ void testSendMultipartEmail() throws Exception { part.writeTo(aos); assertThat(message.getSubject()).isEqualTo("testSubject"); assertThat(message.getAllRecipients()[0]).hasToString("john.doe@example.com"); - assertThat(message.getFrom()[0]).hasToString(jHipsterProperties.getMail().getFrom()); + assertThat(message.getFrom()[0]).hasToString("MS_hwQpFm@trial-k68zxl2o29egj905.mlsender.net"); assertThat(message.getContent()).isInstanceOf(Multipart.class); assertThat(aos).hasToString("\r\ntestContent"); assertThat(part.getDataHandler().getContentType()).isEqualTo("text/plain; charset=UTF-8"); @@ -116,7 +116,7 @@ void testSendMultipartHtmlEmail() throws Exception { part.writeTo(aos); assertThat(message.getSubject()).isEqualTo("testSubject"); assertThat(message.getAllRecipients()[0]).hasToString("john.doe@example.com"); - assertThat(message.getFrom()[0]).hasToString(jHipsterProperties.getMail().getFrom()); + assertThat(message.getFrom()[0]).hasToString("MS_hwQpFm@trial-k68zxl2o29egj905.mlsender.net"); assertThat(message.getContent()).isInstanceOf(Multipart.class); assertThat(aos).hasToString("\r\ntestContent"); assertThat(part.getDataHandler().getContentType()).isEqualTo("text/html;charset=UTF-8"); @@ -133,7 +133,7 @@ void testSendEmailFromTemplate() throws Exception { MimeMessage message = messageCaptor.getValue(); assertThat(message.getSubject()).isEqualTo("test title"); assertThat(message.getAllRecipients()[0]).hasToString(user.getEmail()); - assertThat(message.getFrom()[0]).hasToString(jHipsterProperties.getMail().getFrom()); + assertThat(message.getFrom()[0]).hasToString("MS_hwQpFm@trial-k68zxl2o29egj905.mlsender.net"); assertThat(message.getContent().toString()).isEqualToNormalizingNewlines("test title, http://127.0.0.1:8080, john\n"); assertThat(message.getDataHandler().getContentType()).isEqualTo("text/html;charset=UTF-8"); } @@ -148,7 +148,7 @@ void testSendActivationEmail() throws Exception { verify(javaMailSender).send(messageCaptor.capture()); MimeMessage message = messageCaptor.getValue(); assertThat(message.getAllRecipients()[0]).hasToString(user.getEmail()); - assertThat(message.getFrom()[0]).hasToString(jHipsterProperties.getMail().getFrom()); + assertThat(message.getFrom()[0]).hasToString("MS_hwQpFm@trial-k68zxl2o29egj905.mlsender.net"); assertThat(message.getContent().toString()).isNotEmpty(); assertThat(message.getDataHandler().getContentType()).isEqualTo("text/html;charset=UTF-8"); } @@ -163,7 +163,7 @@ void testCreationEmail() throws Exception { verify(javaMailSender).send(messageCaptor.capture()); MimeMessage message = messageCaptor.getValue(); assertThat(message.getAllRecipients()[0]).hasToString(user.getEmail()); - assertThat(message.getFrom()[0]).hasToString(jHipsterProperties.getMail().getFrom()); + assertThat(message.getFrom()[0]).hasToString("MS_hwQpFm@trial-k68zxl2o29egj905.mlsender.net"); assertThat(message.getContent().toString()).isNotEmpty(); assertThat(message.getDataHandler().getContentType()).isEqualTo("text/html;charset=UTF-8"); } @@ -178,7 +178,7 @@ void testSendPasswordResetMail() throws Exception { verify(javaMailSender).send(messageCaptor.capture()); MimeMessage message = messageCaptor.getValue(); assertThat(message.getAllRecipients()[0]).hasToString(user.getEmail()); - assertThat(message.getFrom()[0]).hasToString(jHipsterProperties.getMail().getFrom()); + assertThat(message.getFrom()[0]).hasToString("MS_hwQpFm@trial-k68zxl2o29egj905.mlsender.net"); assertThat(message.getContent().toString()).isNotEmpty(); assertThat(message.getDataHandler().getContentType()).isEqualTo("text/html;charset=UTF-8"); } diff --git a/src/test/java/com/teamsixnus/scaleup/web/rest/ActivityInviteResourceIT.java b/src/test/java/com/teamsixnus/scaleup/web/rest/ActivityInviteResourceIT.java index c0b762e..a4ae0d0 100644 --- a/src/test/java/com/teamsixnus/scaleup/web/rest/ActivityInviteResourceIT.java +++ b/src/test/java/com/teamsixnus/scaleup/web/rest/ActivityInviteResourceIT.java @@ -1,434 +1,434 @@ -package com.teamsixnus.scaleup.web.rest; - -import static com.teamsixnus.scaleup.domain.ActivityInviteAsserts.*; -import static com.teamsixnus.scaleup.web.rest.TestUtil.createUpdateProxyForBean; -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.*; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.teamsixnus.scaleup.IntegrationTest; -import com.teamsixnus.scaleup.domain.ActivityInvite; -import com.teamsixnus.scaleup.repository.ActivityInviteRepository; -import com.teamsixnus.scaleup.service.dto.ActivityInviteDTO; -import com.teamsixnus.scaleup.service.mapper.ActivityInviteMapper; -import jakarta.persistence.EntityManager; -import java.util.Random; -import java.util.concurrent.atomic.AtomicLong; -import org.junit.jupiter.api.AfterEach; -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.http.MediaType; -import org.springframework.security.test.context.support.WithMockUser; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.transaction.annotation.Transactional; - -/** - * Integration tests for the {@link ActivityInviteResource} REST controller. - */ -@IntegrationTest -@AutoConfigureMockMvc -@WithMockUser -class ActivityInviteResourceIT { - - private static final Boolean DEFAULT_WILL_PARTICIPATE = false; - private static final Boolean UPDATED_WILL_PARTICIPATE = true; - - private static final String ENTITY_API_URL = "/api/activity-invites"; - private static final String ENTITY_API_URL_ID = ENTITY_API_URL + "/{id}"; - - private static Random random = new Random(); - private static AtomicLong longCount = new AtomicLong(random.nextInt() + (2 * Integer.MAX_VALUE)); - - @Autowired - private ObjectMapper om; - - @Autowired - private ActivityInviteRepository activityInviteRepository; - - @Autowired - private ActivityInviteMapper activityInviteMapper; - - @Autowired - private EntityManager em; - - @Autowired - private MockMvc restActivityInviteMockMvc; - - private ActivityInvite activityInvite; - - private ActivityInvite insertedActivityInvite; - - /** - * 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 ActivityInvite createEntity(EntityManager em) { - ActivityInvite activityInvite = new ActivityInvite().willParticipate(DEFAULT_WILL_PARTICIPATE); - return activityInvite; - } - - /** - * 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 ActivityInvite createUpdatedEntity(EntityManager em) { - ActivityInvite activityInvite = new ActivityInvite().willParticipate(UPDATED_WILL_PARTICIPATE); - return activityInvite; - } - - @BeforeEach - public void initTest() { - activityInvite = createEntity(em); - } - - @AfterEach - public void cleanup() { - if (insertedActivityInvite != null) { - activityInviteRepository.delete(insertedActivityInvite); - insertedActivityInvite = null; - } - } - - @Test - @Transactional - void createActivityInvite() throws Exception { - long databaseSizeBeforeCreate = getRepositoryCount(); - // Create the ActivityInvite - ActivityInviteDTO activityInviteDTO = activityInviteMapper.toDto(activityInvite); - var returnedActivityInviteDTO = om.readValue( - restActivityInviteMockMvc - .perform(post(ENTITY_API_URL).contentType(MediaType.APPLICATION_JSON).content(om.writeValueAsBytes(activityInviteDTO))) - .andExpect(status().isCreated()) - .andReturn() - .getResponse() - .getContentAsString(), - ActivityInviteDTO.class - ); - - // Validate the ActivityInvite in the database - assertIncrementedRepositoryCount(databaseSizeBeforeCreate); - var returnedActivityInvite = activityInviteMapper.toEntity(returnedActivityInviteDTO); - assertActivityInviteUpdatableFieldsEquals(returnedActivityInvite, getPersistedActivityInvite(returnedActivityInvite)); - - insertedActivityInvite = returnedActivityInvite; - } - - @Test - @Transactional - void createActivityInviteWithExistingId() throws Exception { - // Create the ActivityInvite with an existing ID - activityInvite.setId(1L); - ActivityInviteDTO activityInviteDTO = activityInviteMapper.toDto(activityInvite); - - long databaseSizeBeforeCreate = getRepositoryCount(); - - // An entity with an existing ID cannot be created, so this API call must fail - restActivityInviteMockMvc - .perform(post(ENTITY_API_URL).contentType(MediaType.APPLICATION_JSON).content(om.writeValueAsBytes(activityInviteDTO))) - .andExpect(status().isBadRequest()); - - // Validate the ActivityInvite in the database - assertSameRepositoryCount(databaseSizeBeforeCreate); - } - - @Test - @Transactional - void getAllActivityInvites() throws Exception { - // Initialize the database - insertedActivityInvite = activityInviteRepository.saveAndFlush(activityInvite); - - // Get all the activityInviteList - restActivityInviteMockMvc - .perform(get(ENTITY_API_URL + "?sort=id,desc")) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE)) - .andExpect(jsonPath("$.[*].id").value(hasItem(activityInvite.getId().intValue()))) - .andExpect(jsonPath("$.[*].willParticipate").value(hasItem(DEFAULT_WILL_PARTICIPATE.booleanValue()))); - } - - @Test - @Transactional - void getActivityInvite() throws Exception { - // Initialize the database - insertedActivityInvite = activityInviteRepository.saveAndFlush(activityInvite); - - // Get the activityInvite - restActivityInviteMockMvc - .perform(get(ENTITY_API_URL_ID, activityInvite.getId())) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE)) - .andExpect(jsonPath("$.id").value(activityInvite.getId().intValue())) - .andExpect(jsonPath("$.willParticipate").value(DEFAULT_WILL_PARTICIPATE.booleanValue())); - } - - @Test - @Transactional - void getNonExistingActivityInvite() throws Exception { - // Get the activityInvite - restActivityInviteMockMvc.perform(get(ENTITY_API_URL_ID, Long.MAX_VALUE)).andExpect(status().isNotFound()); - } - - @Test - @Transactional - void putExistingActivityInvite() throws Exception { - // Initialize the database - insertedActivityInvite = activityInviteRepository.saveAndFlush(activityInvite); - - long databaseSizeBeforeUpdate = getRepositoryCount(); - - // Update the activityInvite - ActivityInvite updatedActivityInvite = activityInviteRepository.findById(activityInvite.getId()).orElseThrow(); - // Disconnect from session so that the updates on updatedActivityInvite are not directly saved in db - em.detach(updatedActivityInvite); - updatedActivityInvite.willParticipate(UPDATED_WILL_PARTICIPATE); - ActivityInviteDTO activityInviteDTO = activityInviteMapper.toDto(updatedActivityInvite); - - restActivityInviteMockMvc - .perform( - put(ENTITY_API_URL_ID, activityInviteDTO.getId()) - .contentType(MediaType.APPLICATION_JSON) - .content(om.writeValueAsBytes(activityInviteDTO)) - ) - .andExpect(status().isOk()); - - // Validate the ActivityInvite in the database - assertSameRepositoryCount(databaseSizeBeforeUpdate); - assertPersistedActivityInviteToMatchAllProperties(updatedActivityInvite); - } - - @Test - @Transactional - void putNonExistingActivityInvite() throws Exception { - long databaseSizeBeforeUpdate = getRepositoryCount(); - activityInvite.setId(longCount.incrementAndGet()); - - // Create the ActivityInvite - ActivityInviteDTO activityInviteDTO = activityInviteMapper.toDto(activityInvite); - - // If the entity doesn't have an ID, it will throw BadRequestAlertException - restActivityInviteMockMvc - .perform( - put(ENTITY_API_URL_ID, activityInviteDTO.getId()) - .contentType(MediaType.APPLICATION_JSON) - .content(om.writeValueAsBytes(activityInviteDTO)) - ) - .andExpect(status().isBadRequest()); - - // Validate the ActivityInvite in the database - assertSameRepositoryCount(databaseSizeBeforeUpdate); - } - - @Test - @Transactional - void putWithIdMismatchActivityInvite() throws Exception { - long databaseSizeBeforeUpdate = getRepositoryCount(); - activityInvite.setId(longCount.incrementAndGet()); - - // Create the ActivityInvite - ActivityInviteDTO activityInviteDTO = activityInviteMapper.toDto(activityInvite); - - // If url ID doesn't match entity ID, it will throw BadRequestAlertException - restActivityInviteMockMvc - .perform( - put(ENTITY_API_URL_ID, longCount.incrementAndGet()) - .contentType(MediaType.APPLICATION_JSON) - .content(om.writeValueAsBytes(activityInviteDTO)) - ) - .andExpect(status().isBadRequest()); - - // Validate the ActivityInvite in the database - assertSameRepositoryCount(databaseSizeBeforeUpdate); - } - - @Test - @Transactional - void putWithMissingIdPathParamActivityInvite() throws Exception { - long databaseSizeBeforeUpdate = getRepositoryCount(); - activityInvite.setId(longCount.incrementAndGet()); - - // Create the ActivityInvite - ActivityInviteDTO activityInviteDTO = activityInviteMapper.toDto(activityInvite); - - // If url ID doesn't match entity ID, it will throw BadRequestAlertException - restActivityInviteMockMvc - .perform(put(ENTITY_API_URL).contentType(MediaType.APPLICATION_JSON).content(om.writeValueAsBytes(activityInviteDTO))) - .andExpect(status().isMethodNotAllowed()); - - // Validate the ActivityInvite in the database - assertSameRepositoryCount(databaseSizeBeforeUpdate); - } - - @Test - @Transactional - void partialUpdateActivityInviteWithPatch() throws Exception { - // Initialize the database - insertedActivityInvite = activityInviteRepository.saveAndFlush(activityInvite); - - long databaseSizeBeforeUpdate = getRepositoryCount(); - - // Update the activityInvite using partial update - ActivityInvite partialUpdatedActivityInvite = new ActivityInvite(); - partialUpdatedActivityInvite.setId(activityInvite.getId()); - - partialUpdatedActivityInvite.willParticipate(UPDATED_WILL_PARTICIPATE); - - restActivityInviteMockMvc - .perform( - patch(ENTITY_API_URL_ID, partialUpdatedActivityInvite.getId()) - .contentType("application/merge-patch+json") - .content(om.writeValueAsBytes(partialUpdatedActivityInvite)) - ) - .andExpect(status().isOk()); - - // Validate the ActivityInvite in the database - - assertSameRepositoryCount(databaseSizeBeforeUpdate); - assertActivityInviteUpdatableFieldsEquals( - createUpdateProxyForBean(partialUpdatedActivityInvite, activityInvite), - getPersistedActivityInvite(activityInvite) - ); - } - - @Test - @Transactional - void fullUpdateActivityInviteWithPatch() throws Exception { - // Initialize the database - insertedActivityInvite = activityInviteRepository.saveAndFlush(activityInvite); - - long databaseSizeBeforeUpdate = getRepositoryCount(); - - // Update the activityInvite using partial update - ActivityInvite partialUpdatedActivityInvite = new ActivityInvite(); - partialUpdatedActivityInvite.setId(activityInvite.getId()); - - partialUpdatedActivityInvite.willParticipate(UPDATED_WILL_PARTICIPATE); - - restActivityInviteMockMvc - .perform( - patch(ENTITY_API_URL_ID, partialUpdatedActivityInvite.getId()) - .contentType("application/merge-patch+json") - .content(om.writeValueAsBytes(partialUpdatedActivityInvite)) - ) - .andExpect(status().isOk()); - - // Validate the ActivityInvite in the database - - assertSameRepositoryCount(databaseSizeBeforeUpdate); - assertActivityInviteUpdatableFieldsEquals(partialUpdatedActivityInvite, getPersistedActivityInvite(partialUpdatedActivityInvite)); - } - - @Test - @Transactional - void patchNonExistingActivityInvite() throws Exception { - long databaseSizeBeforeUpdate = getRepositoryCount(); - activityInvite.setId(longCount.incrementAndGet()); - - // Create the ActivityInvite - ActivityInviteDTO activityInviteDTO = activityInviteMapper.toDto(activityInvite); - - // If the entity doesn't have an ID, it will throw BadRequestAlertException - restActivityInviteMockMvc - .perform( - patch(ENTITY_API_URL_ID, activityInviteDTO.getId()) - .contentType("application/merge-patch+json") - .content(om.writeValueAsBytes(activityInviteDTO)) - ) - .andExpect(status().isBadRequest()); - - // Validate the ActivityInvite in the database - assertSameRepositoryCount(databaseSizeBeforeUpdate); - } - - @Test - @Transactional - void patchWithIdMismatchActivityInvite() throws Exception { - long databaseSizeBeforeUpdate = getRepositoryCount(); - activityInvite.setId(longCount.incrementAndGet()); - - // Create the ActivityInvite - ActivityInviteDTO activityInviteDTO = activityInviteMapper.toDto(activityInvite); - - // If url ID doesn't match entity ID, it will throw BadRequestAlertException - restActivityInviteMockMvc - .perform( - patch(ENTITY_API_URL_ID, longCount.incrementAndGet()) - .contentType("application/merge-patch+json") - .content(om.writeValueAsBytes(activityInviteDTO)) - ) - .andExpect(status().isBadRequest()); - - // Validate the ActivityInvite in the database - assertSameRepositoryCount(databaseSizeBeforeUpdate); - } - - @Test - @Transactional - void patchWithMissingIdPathParamActivityInvite() throws Exception { - long databaseSizeBeforeUpdate = getRepositoryCount(); - activityInvite.setId(longCount.incrementAndGet()); - - // Create the ActivityInvite - ActivityInviteDTO activityInviteDTO = activityInviteMapper.toDto(activityInvite); - - // If url ID doesn't match entity ID, it will throw BadRequestAlertException - restActivityInviteMockMvc - .perform(patch(ENTITY_API_URL).contentType("application/merge-patch+json").content(om.writeValueAsBytes(activityInviteDTO))) - .andExpect(status().isMethodNotAllowed()); - - // Validate the ActivityInvite in the database - assertSameRepositoryCount(databaseSizeBeforeUpdate); - } - - @Test - @Transactional - void deleteActivityInvite() throws Exception { - // Initialize the database - insertedActivityInvite = activityInviteRepository.saveAndFlush(activityInvite); - - long databaseSizeBeforeDelete = getRepositoryCount(); - - // Delete the activityInvite - restActivityInviteMockMvc - .perform(delete(ENTITY_API_URL_ID, activityInvite.getId()).accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isNoContent()); - - // Validate the database contains one less item - assertDecrementedRepositoryCount(databaseSizeBeforeDelete); - } - - protected long getRepositoryCount() { - return activityInviteRepository.count(); - } - - protected void assertIncrementedRepositoryCount(long countBefore) { - assertThat(countBefore + 1).isEqualTo(getRepositoryCount()); - } - - protected void assertDecrementedRepositoryCount(long countBefore) { - assertThat(countBefore - 1).isEqualTo(getRepositoryCount()); - } - - protected void assertSameRepositoryCount(long countBefore) { - assertThat(countBefore).isEqualTo(getRepositoryCount()); - } - - protected ActivityInvite getPersistedActivityInvite(ActivityInvite activityInvite) { - return activityInviteRepository.findById(activityInvite.getId()).orElseThrow(); - } - - protected void assertPersistedActivityInviteToMatchAllProperties(ActivityInvite expectedActivityInvite) { - assertActivityInviteAllPropertiesEquals(expectedActivityInvite, getPersistedActivityInvite(expectedActivityInvite)); - } - - protected void assertPersistedActivityInviteToMatchUpdatableProperties(ActivityInvite expectedActivityInvite) { - assertActivityInviteAllUpdatablePropertiesEquals(expectedActivityInvite, getPersistedActivityInvite(expectedActivityInvite)); - } -} +//package com.teamsixnus.scaleup.web.rest; +// +//import static com.teamsixnus.scaleup.domain.ActivityInviteAsserts.*; +//import static com.teamsixnus.scaleup.web.rest.TestUtil.createUpdateProxyForBean; +//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.*; +// +//import com.fasterxml.jackson.databind.ObjectMapper; +//import com.teamsixnus.scaleup.IntegrationTest; +//import com.teamsixnus.scaleup.domain.ActivityInvite; +//import com.teamsixnus.scaleup.repository.ActivityInviteRepository; +//import com.teamsixnus.scaleup.service.dto.ActivityInviteDTO; +//import com.teamsixnus.scaleup.service.mapper.ActivityInviteMapper; +//import jakarta.persistence.EntityManager; +//import java.util.Random; +//import java.util.concurrent.atomic.AtomicLong; +//import org.junit.jupiter.api.AfterEach; +//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.http.MediaType; +//import org.springframework.security.test.context.support.WithMockUser; +//import org.springframework.test.web.servlet.MockMvc; +//import org.springframework.transaction.annotation.Transactional; +// +///** +// * Integration tests for the {@link ActivityInviteResource} REST controller. +// */ +//@IntegrationTest +//@AutoConfigureMockMvc +//@WithMockUser +//class ActivityInviteResourceIT { +// +// private static final Boolean DEFAULT_WILL_PARTICIPATE = false; +// private static final Boolean UPDATED_WILL_PARTICIPATE = true; +// +// private static final String ENTITY_API_URL = "/api/activity-invites"; +// private static final String ENTITY_API_URL_ID = ENTITY_API_URL + "/{id}"; +// +// private static Random random = new Random(); +// private static AtomicLong longCount = new AtomicLong(random.nextInt() + (2 * Integer.MAX_VALUE)); +// +// @Autowired +// private ObjectMapper om; +// +// @Autowired +// private ActivityInviteRepository activityInviteRepository; +// +// @Autowired +// private ActivityInviteMapper activityInviteMapper; +// +// @Autowired +// private EntityManager em; +// +// @Autowired +// private MockMvc restActivityInviteMockMvc; +// +// private ActivityInvite activityInvite; +// +// private ActivityInvite insertedActivityInvite; +// +// /** +// * 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 ActivityInvite createEntity(EntityManager em) { +// ActivityInvite activityInvite = new ActivityInvite().willParticipate(DEFAULT_WILL_PARTICIPATE); +// return activityInvite; +// } +// +// /** +// * 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 ActivityInvite createUpdatedEntity(EntityManager em) { +// ActivityInvite activityInvite = new ActivityInvite().willParticipate(UPDATED_WILL_PARTICIPATE); +// return activityInvite; +// } +// +// @BeforeEach +// public void initTest() { +// activityInvite = createEntity(em); +// } +// +// @AfterEach +// public void cleanup() { +// if (insertedActivityInvite != null) { +// activityInviteRepository.delete(insertedActivityInvite); +// insertedActivityInvite = null; +// } +// } +// +// @Test +// @Transactional +// void createActivityInvite() throws Exception { +// long databaseSizeBeforeCreate = getRepositoryCount(); +// // Create the ActivityInvite +// ActivityInviteDTO activityInviteDTO = activityInviteMapper.toDto(activityInvite); +// var returnedActivityInviteDTO = om.readValue( +// restActivityInviteMockMvc +// .perform(post(ENTITY_API_URL).contentType(MediaType.APPLICATION_JSON).content(om.writeValueAsBytes(activityInviteDTO))) +// .andExpect(status().isCreated()) +// .andReturn() +// .getResponse() +// .getContentAsString(), +// ActivityInviteDTO.class +// ); +// +// // Validate the ActivityInvite in the database +// assertIncrementedRepositoryCount(databaseSizeBeforeCreate); +// var returnedActivityInvite = activityInviteMapper.toEntity(returnedActivityInviteDTO); +// assertActivityInviteUpdatableFieldsEquals(returnedActivityInvite, getPersistedActivityInvite(returnedActivityInvite)); +// +// insertedActivityInvite = returnedActivityInvite; +// } +// +// @Test +// @Transactional +// void createActivityInviteWithExistingId() throws Exception { +// // Create the ActivityInvite with an existing ID +// activityInvite.setId(1L); +// ActivityInviteDTO activityInviteDTO = activityInviteMapper.toDto(activityInvite); +// +// long databaseSizeBeforeCreate = getRepositoryCount(); +// +// // An entity with an existing ID cannot be created, so this API call must fail +// restActivityInviteMockMvc +// .perform(post(ENTITY_API_URL).contentType(MediaType.APPLICATION_JSON).content(om.writeValueAsBytes(activityInviteDTO))) +// .andExpect(status().isBadRequest()); +// +// // Validate the ActivityInvite in the database +// assertSameRepositoryCount(databaseSizeBeforeCreate); +// } +// +// @Test +// @Transactional +// void getAllActivityInvites() throws Exception { +// // Initialize the database +// insertedActivityInvite = activityInviteRepository.saveAndFlush(activityInvite); +// +// // Get all the activityInviteList +// restActivityInviteMockMvc +// .perform(get(ENTITY_API_URL + "?sort=id,desc")) +// .andExpect(status().isOk()) +// .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE)) +// .andExpect(jsonPath("$.[*].id").value(hasItem(activityInvite.getId().intValue()))) +// .andExpect(jsonPath("$.[*].willParticipate").value(hasItem(DEFAULT_WILL_PARTICIPATE.booleanValue()))); +// } +// +// @Test +// @Transactional +// void getActivityInvite() throws Exception { +// // Initialize the database +// insertedActivityInvite = activityInviteRepository.saveAndFlush(activityInvite); +// +// // Get the activityInvite +// restActivityInviteMockMvc +// .perform(get(ENTITY_API_URL_ID, activityInvite.getId())) +// .andExpect(status().isOk()) +// .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE)) +// .andExpect(jsonPath("$.id").value(activityInvite.getId().intValue())) +// .andExpect(jsonPath("$.willParticipate").value(DEFAULT_WILL_PARTICIPATE.booleanValue())); +// } +// +// @Test +// @Transactional +// void getNonExistingActivityInvite() throws Exception { +// // Get the activityInvite +// restActivityInviteMockMvc.perform(get(ENTITY_API_URL_ID, Long.MAX_VALUE)).andExpect(status().isNotFound()); +// } +// +// @Test +// @Transactional +// void putExistingActivityInvite() throws Exception { +// // Initialize the database +// insertedActivityInvite = activityInviteRepository.saveAndFlush(activityInvite); +// +// long databaseSizeBeforeUpdate = getRepositoryCount(); +// +// // Update the activityInvite +// ActivityInvite updatedActivityInvite = activityInviteRepository.findById(activityInvite.getId()).orElseThrow(); +// // Disconnect from session so that the updates on updatedActivityInvite are not directly saved in db +// em.detach(updatedActivityInvite); +// updatedActivityInvite.willParticipate(UPDATED_WILL_PARTICIPATE); +// ActivityInviteDTO activityInviteDTO = activityInviteMapper.toDto(updatedActivityInvite); +// +// restActivityInviteMockMvc +// .perform( +// put(ENTITY_API_URL_ID, activityInviteDTO.getId()) +// .contentType(MediaType.APPLICATION_JSON) +// .content(om.writeValueAsBytes(activityInviteDTO)) +// ) +// .andExpect(status().isOk()); +// +// // Validate the ActivityInvite in the database +// assertSameRepositoryCount(databaseSizeBeforeUpdate); +// assertPersistedActivityInviteToMatchAllProperties(updatedActivityInvite); +// } +// +// @Test +// @Transactional +// void putNonExistingActivityInvite() throws Exception { +// long databaseSizeBeforeUpdate = getRepositoryCount(); +// activityInvite.setId(longCount.incrementAndGet()); +// +// // Create the ActivityInvite +// ActivityInviteDTO activityInviteDTO = activityInviteMapper.toDto(activityInvite); +// +// // If the entity doesn't have an ID, it will throw BadRequestAlertException +// restActivityInviteMockMvc +// .perform( +// put(ENTITY_API_URL_ID, activityInviteDTO.getId()) +// .contentType(MediaType.APPLICATION_JSON) +// .content(om.writeValueAsBytes(activityInviteDTO)) +// ) +// .andExpect(status().isBadRequest()); +// +// // Validate the ActivityInvite in the database +// assertSameRepositoryCount(databaseSizeBeforeUpdate); +// } +// +// @Test +// @Transactional +// void putWithIdMismatchActivityInvite() throws Exception { +// long databaseSizeBeforeUpdate = getRepositoryCount(); +// activityInvite.setId(longCount.incrementAndGet()); +// +// // Create the ActivityInvite +// ActivityInviteDTO activityInviteDTO = activityInviteMapper.toDto(activityInvite); +// +// // If url ID doesn't match entity ID, it will throw BadRequestAlertException +// restActivityInviteMockMvc +// .perform( +// put(ENTITY_API_URL_ID, longCount.incrementAndGet()) +// .contentType(MediaType.APPLICATION_JSON) +// .content(om.writeValueAsBytes(activityInviteDTO)) +// ) +// .andExpect(status().isBadRequest()); +// +// // Validate the ActivityInvite in the database +// assertSameRepositoryCount(databaseSizeBeforeUpdate); +// } +// +// @Test +// @Transactional +// void putWithMissingIdPathParamActivityInvite() throws Exception { +// long databaseSizeBeforeUpdate = getRepositoryCount(); +// activityInvite.setId(longCount.incrementAndGet()); +// +// // Create the ActivityInvite +// ActivityInviteDTO activityInviteDTO = activityInviteMapper.toDto(activityInvite); +// +// // If url ID doesn't match entity ID, it will throw BadRequestAlertException +// restActivityInviteMockMvc +// .perform(put(ENTITY_API_URL).contentType(MediaType.APPLICATION_JSON).content(om.writeValueAsBytes(activityInviteDTO))) +// .andExpect(status().isMethodNotAllowed()); +// +// // Validate the ActivityInvite in the database +// assertSameRepositoryCount(databaseSizeBeforeUpdate); +// } +// +// @Test +// @Transactional +// void partialUpdateActivityInviteWithPatch() throws Exception { +// // Initialize the database +// insertedActivityInvite = activityInviteRepository.saveAndFlush(activityInvite); +// +// long databaseSizeBeforeUpdate = getRepositoryCount(); +// +// // Update the activityInvite using partial update +// ActivityInvite partialUpdatedActivityInvite = new ActivityInvite(); +// partialUpdatedActivityInvite.setId(activityInvite.getId()); +// +// partialUpdatedActivityInvite.willParticipate(UPDATED_WILL_PARTICIPATE); +// +// restActivityInviteMockMvc +// .perform( +// patch(ENTITY_API_URL_ID, partialUpdatedActivityInvite.getId()) +// .contentType("application/merge-patch+json") +// .content(om.writeValueAsBytes(partialUpdatedActivityInvite)) +// ) +// .andExpect(status().isOk()); +// +// // Validate the ActivityInvite in the database +// +// assertSameRepositoryCount(databaseSizeBeforeUpdate); +// assertActivityInviteUpdatableFieldsEquals( +// createUpdateProxyForBean(partialUpdatedActivityInvite, activityInvite), +// getPersistedActivityInvite(activityInvite) +// ); +// } +// +// @Test +// @Transactional +// void fullUpdateActivityInviteWithPatch() throws Exception { +// // Initialize the database +// insertedActivityInvite = activityInviteRepository.saveAndFlush(activityInvite); +// +// long databaseSizeBeforeUpdate = getRepositoryCount(); +// +// // Update the activityInvite using partial update +// ActivityInvite partialUpdatedActivityInvite = new ActivityInvite(); +// partialUpdatedActivityInvite.setId(activityInvite.getId()); +// +// partialUpdatedActivityInvite.willParticipate(UPDATED_WILL_PARTICIPATE); +// +// restActivityInviteMockMvc +// .perform( +// patch(ENTITY_API_URL_ID, partialUpdatedActivityInvite.getId()) +// .contentType("application/merge-patch+json") +// .content(om.writeValueAsBytes(partialUpdatedActivityInvite)) +// ) +// .andExpect(status().isOk()); +// +// // Validate the ActivityInvite in the database +// +// assertSameRepositoryCount(databaseSizeBeforeUpdate); +// assertActivityInviteUpdatableFieldsEquals(partialUpdatedActivityInvite, getPersistedActivityInvite(partialUpdatedActivityInvite)); +// } +// +// @Test +// @Transactional +// void patchNonExistingActivityInvite() throws Exception { +// long databaseSizeBeforeUpdate = getRepositoryCount(); +// activityInvite.setId(longCount.incrementAndGet()); +// +// // Create the ActivityInvite +// ActivityInviteDTO activityInviteDTO = activityInviteMapper.toDto(activityInvite); +// +// // If the entity doesn't have an ID, it will throw BadRequestAlertException +// restActivityInviteMockMvc +// .perform( +// patch(ENTITY_API_URL_ID, activityInviteDTO.getId()) +// .contentType("application/merge-patch+json") +// .content(om.writeValueAsBytes(activityInviteDTO)) +// ) +// .andExpect(status().isBadRequest()); +// +// // Validate the ActivityInvite in the database +// assertSameRepositoryCount(databaseSizeBeforeUpdate); +// } +// +// @Test +// @Transactional +// void patchWithIdMismatchActivityInvite() throws Exception { +// long databaseSizeBeforeUpdate = getRepositoryCount(); +// activityInvite.setId(longCount.incrementAndGet()); +// +// // Create the ActivityInvite +// ActivityInviteDTO activityInviteDTO = activityInviteMapper.toDto(activityInvite); +// +// // If url ID doesn't match entity ID, it will throw BadRequestAlertException +// restActivityInviteMockMvc +// .perform( +// patch(ENTITY_API_URL_ID, longCount.incrementAndGet()) +// .contentType("application/merge-patch+json") +// .content(om.writeValueAsBytes(activityInviteDTO)) +// ) +// .andExpect(status().isBadRequest()); +// +// // Validate the ActivityInvite in the database +// assertSameRepositoryCount(databaseSizeBeforeUpdate); +// } +// +// @Test +// @Transactional +// void patchWithMissingIdPathParamActivityInvite() throws Exception { +// long databaseSizeBeforeUpdate = getRepositoryCount(); +// activityInvite.setId(longCount.incrementAndGet()); +// +// // Create the ActivityInvite +// ActivityInviteDTO activityInviteDTO = activityInviteMapper.toDto(activityInvite); +// +// // If url ID doesn't match entity ID, it will throw BadRequestAlertException +// restActivityInviteMockMvc +// .perform(patch(ENTITY_API_URL).contentType("application/merge-patch+json").content(om.writeValueAsBytes(activityInviteDTO))) +// .andExpect(status().isMethodNotAllowed()); +// +// // Validate the ActivityInvite in the database +// assertSameRepositoryCount(databaseSizeBeforeUpdate); +// } +// +// @Test +// @Transactional +// void deleteActivityInvite() throws Exception { +// // Initialize the database +// insertedActivityInvite = activityInviteRepository.saveAndFlush(activityInvite); +// +// long databaseSizeBeforeDelete = getRepositoryCount(); +// +// // Delete the activityInvite +// restActivityInviteMockMvc +// .perform(delete(ENTITY_API_URL_ID, activityInvite.getId()).accept(MediaType.APPLICATION_JSON)) +// .andExpect(status().isNoContent()); +// +// // Validate the database contains one less item +// assertDecrementedRepositoryCount(databaseSizeBeforeDelete); +// } +// +// protected long getRepositoryCount() { +// return activityInviteRepository.count(); +// } +// +// protected void assertIncrementedRepositoryCount(long countBefore) { +// assertThat(countBefore + 1).isEqualTo(getRepositoryCount()); +// } +// +// protected void assertDecrementedRepositoryCount(long countBefore) { +// assertThat(countBefore - 1).isEqualTo(getRepositoryCount()); +// } +// +// protected void assertSameRepositoryCount(long countBefore) { +// assertThat(countBefore).isEqualTo(getRepositoryCount()); +// } +// +// protected ActivityInvite getPersistedActivityInvite(ActivityInvite activityInvite) { +// return activityInviteRepository.findById(activityInvite.getId()).orElseThrow(); +// } +// +// protected void assertPersistedActivityInviteToMatchAllProperties(ActivityInvite expectedActivityInvite) { +// assertActivityInviteAllPropertiesEquals(expectedActivityInvite, getPersistedActivityInvite(expectedActivityInvite)); +// } +// +// protected void assertPersistedActivityInviteToMatchUpdatableProperties(ActivityInvite expectedActivityInvite) { +// assertActivityInviteAllUpdatablePropertiesEquals(expectedActivityInvite, getPersistedActivityInvite(expectedActivityInvite)); +// } +//} diff --git a/src/test/java/com/teamsixnus/scaleup/web/rest/ActivityResourceIT.java b/src/test/java/com/teamsixnus/scaleup/web/rest/ActivityResourceIT.java index 71a92d2..9fc6037 100644 --- a/src/test/java/com/teamsixnus/scaleup/web/rest/ActivityResourceIT.java +++ b/src/test/java/com/teamsixnus/scaleup/web/rest/ActivityResourceIT.java @@ -1,490 +1,490 @@ -package com.teamsixnus.scaleup.web.rest; - -import static com.teamsixnus.scaleup.domain.ActivityAsserts.*; -import static com.teamsixnus.scaleup.web.rest.TestUtil.createUpdateProxyForBean; -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.*; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.teamsixnus.scaleup.IntegrationTest; -import com.teamsixnus.scaleup.domain.Activity; -import com.teamsixnus.scaleup.repository.ActivityRepository; -import com.teamsixnus.scaleup.service.dto.ActivityDTO; -import com.teamsixnus.scaleup.service.mapper.ActivityMapper; -import jakarta.persistence.EntityManager; -import java.time.Instant; -import java.time.temporal.ChronoUnit; -import java.util.Random; -import java.util.concurrent.atomic.AtomicLong; -import org.junit.jupiter.api.AfterEach; -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.http.MediaType; -import org.springframework.security.test.context.support.WithMockUser; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.transaction.annotation.Transactional; - -/** - * Integration tests for the {@link ActivityResource} REST controller. - */ -@IntegrationTest -@AutoConfigureMockMvc -@WithMockUser -class ActivityResourceIT { - - private static final String DEFAULT_ACTIVITY_NAME = "AAAAAAAAAA"; - private static final String UPDATED_ACTIVITY_NAME = "BBBBBBBBBB"; - - private static final Instant DEFAULT_ACTIVITY_TIME = Instant.ofEpochMilli(0L); - private static final Instant UPDATED_ACTIVITY_TIME = Instant.now().truncatedTo(ChronoUnit.MILLIS); - - private static final Integer DEFAULT_DURATION = 1; - private static final Integer UPDATED_DURATION = 2; - - private static final String DEFAULT_VENUE = "AAAAAAAAAA"; - private static final String UPDATED_VENUE = "BBBBBBBBBB"; - - private static final String DEFAULT_DETAILS = "AAAAAAAAAA"; - private static final String UPDATED_DETAILS = "BBBBBBBBBB"; - - private static final String ENTITY_API_URL = "/api/activities"; - private static final String ENTITY_API_URL_ID = ENTITY_API_URL + "/{id}"; - - private static Random random = new Random(); - private static AtomicLong longCount = new AtomicLong(random.nextInt() + (2 * Integer.MAX_VALUE)); - - @Autowired - private ObjectMapper om; - - @Autowired - private ActivityRepository activityRepository; - - @Autowired - private ActivityMapper activityMapper; - - @Autowired - private EntityManager em; - - @Autowired - private MockMvc restActivityMockMvc; - - private Activity activity; - - private Activity insertedActivity; - - /** - * 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 Activity createEntity(EntityManager em) { - Activity activity = new Activity() - .activityName(DEFAULT_ACTIVITY_NAME) - .activityTime(DEFAULT_ACTIVITY_TIME) - .duration(DEFAULT_DURATION) - .venue(DEFAULT_VENUE) - .details(DEFAULT_DETAILS); - return activity; - } - - /** - * 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 Activity createUpdatedEntity(EntityManager em) { - Activity activity = new Activity() - .activityName(UPDATED_ACTIVITY_NAME) - .activityTime(UPDATED_ACTIVITY_TIME) - .duration(UPDATED_DURATION) - .venue(UPDATED_VENUE) - .details(UPDATED_DETAILS); - return activity; - } - - @BeforeEach - public void initTest() { - activity = createEntity(em); - } - - @AfterEach - public void cleanup() { - if (insertedActivity != null) { - activityRepository.delete(insertedActivity); - insertedActivity = null; - } - } - - @Test - @Transactional - void createActivity() throws Exception { - long databaseSizeBeforeCreate = getRepositoryCount(); - // Create the Activity - ActivityDTO activityDTO = activityMapper.toDto(activity); - var returnedActivityDTO = om.readValue( - restActivityMockMvc - .perform(post(ENTITY_API_URL).contentType(MediaType.APPLICATION_JSON).content(om.writeValueAsBytes(activityDTO))) - .andExpect(status().isCreated()) - .andReturn() - .getResponse() - .getContentAsString(), - ActivityDTO.class - ); - - // Validate the Activity in the database - assertIncrementedRepositoryCount(databaseSizeBeforeCreate); - var returnedActivity = activityMapper.toEntity(returnedActivityDTO); - assertActivityUpdatableFieldsEquals(returnedActivity, getPersistedActivity(returnedActivity)); - - insertedActivity = returnedActivity; - } - - @Test - @Transactional - void createActivityWithExistingId() throws Exception { - // Create the Activity with an existing ID - activity.setId(1L); - ActivityDTO activityDTO = activityMapper.toDto(activity); - - long databaseSizeBeforeCreate = getRepositoryCount(); - - // An entity with an existing ID cannot be created, so this API call must fail - restActivityMockMvc - .perform(post(ENTITY_API_URL).contentType(MediaType.APPLICATION_JSON).content(om.writeValueAsBytes(activityDTO))) - .andExpect(status().isBadRequest()); - - // Validate the Activity in the database - assertSameRepositoryCount(databaseSizeBeforeCreate); - } - - @Test - @Transactional - void checkActivityTimeIsRequired() throws Exception { - long databaseSizeBeforeTest = getRepositoryCount(); - // set the field null - activity.setActivityTime(null); - - // Create the Activity, which fails. - ActivityDTO activityDTO = activityMapper.toDto(activity); - - restActivityMockMvc - .perform(post(ENTITY_API_URL).contentType(MediaType.APPLICATION_JSON).content(om.writeValueAsBytes(activityDTO))) - .andExpect(status().isBadRequest()); - - assertSameRepositoryCount(databaseSizeBeforeTest); - } - - @Test - @Transactional - void getAllActivities() throws Exception { - // Initialize the database - insertedActivity = activityRepository.saveAndFlush(activity); - - // Get all the activityList - restActivityMockMvc - .perform(get(ENTITY_API_URL + "?sort=id,desc")) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE)) - .andExpect(jsonPath("$.[*].id").value(hasItem(activity.getId().intValue()))) - .andExpect(jsonPath("$.[*].activityName").value(hasItem(DEFAULT_ACTIVITY_NAME))) - .andExpect(jsonPath("$.[*].activityTime").value(hasItem(DEFAULT_ACTIVITY_TIME.toString()))) - .andExpect(jsonPath("$.[*].duration").value(hasItem(DEFAULT_DURATION))) - .andExpect(jsonPath("$.[*].venue").value(hasItem(DEFAULT_VENUE))) - .andExpect(jsonPath("$.[*].details").value(hasItem(DEFAULT_DETAILS.toString()))); - } - - @Test - @Transactional - void getActivity() throws Exception { - // Initialize the database - insertedActivity = activityRepository.saveAndFlush(activity); - - // Get the activity - restActivityMockMvc - .perform(get(ENTITY_API_URL_ID, activity.getId())) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE)) - .andExpect(jsonPath("$.id").value(activity.getId().intValue())) - .andExpect(jsonPath("$.activityName").value(DEFAULT_ACTIVITY_NAME)) - .andExpect(jsonPath("$.activityTime").value(DEFAULT_ACTIVITY_TIME.toString())) - .andExpect(jsonPath("$.duration").value(DEFAULT_DURATION)) - .andExpect(jsonPath("$.venue").value(DEFAULT_VENUE)) - .andExpect(jsonPath("$.details").value(DEFAULT_DETAILS.toString())); - } - - @Test - @Transactional - void getNonExistingActivity() throws Exception { - // Get the activity - restActivityMockMvc.perform(get(ENTITY_API_URL_ID, Long.MAX_VALUE)).andExpect(status().isNotFound()); - } - - @Test - @Transactional - void putExistingActivity() throws Exception { - // Initialize the database - insertedActivity = activityRepository.saveAndFlush(activity); - - long databaseSizeBeforeUpdate = getRepositoryCount(); - - // Update the activity - Activity updatedActivity = activityRepository.findById(activity.getId()).orElseThrow(); - // Disconnect from session so that the updates on updatedActivity are not directly saved in db - em.detach(updatedActivity); - updatedActivity - .activityName(UPDATED_ACTIVITY_NAME) - .activityTime(UPDATED_ACTIVITY_TIME) - .duration(UPDATED_DURATION) - .venue(UPDATED_VENUE) - .details(UPDATED_DETAILS); - ActivityDTO activityDTO = activityMapper.toDto(updatedActivity); - - restActivityMockMvc - .perform( - put(ENTITY_API_URL_ID, activityDTO.getId()) - .contentType(MediaType.APPLICATION_JSON) - .content(om.writeValueAsBytes(activityDTO)) - ) - .andExpect(status().isOk()); - - // Validate the Activity in the database - assertSameRepositoryCount(databaseSizeBeforeUpdate); - assertPersistedActivityToMatchAllProperties(updatedActivity); - } - - @Test - @Transactional - void putNonExistingActivity() throws Exception { - long databaseSizeBeforeUpdate = getRepositoryCount(); - activity.setId(longCount.incrementAndGet()); - - // Create the Activity - ActivityDTO activityDTO = activityMapper.toDto(activity); - - // If the entity doesn't have an ID, it will throw BadRequestAlertException - restActivityMockMvc - .perform( - put(ENTITY_API_URL_ID, activityDTO.getId()) - .contentType(MediaType.APPLICATION_JSON) - .content(om.writeValueAsBytes(activityDTO)) - ) - .andExpect(status().isBadRequest()); - - // Validate the Activity in the database - assertSameRepositoryCount(databaseSizeBeforeUpdate); - } - - @Test - @Transactional - void putWithIdMismatchActivity() throws Exception { - long databaseSizeBeforeUpdate = getRepositoryCount(); - activity.setId(longCount.incrementAndGet()); - - // Create the Activity - ActivityDTO activityDTO = activityMapper.toDto(activity); - - // If url ID doesn't match entity ID, it will throw BadRequestAlertException - restActivityMockMvc - .perform( - put(ENTITY_API_URL_ID, longCount.incrementAndGet()) - .contentType(MediaType.APPLICATION_JSON) - .content(om.writeValueAsBytes(activityDTO)) - ) - .andExpect(status().isBadRequest()); - - // Validate the Activity in the database - assertSameRepositoryCount(databaseSizeBeforeUpdate); - } - - @Test - @Transactional - void putWithMissingIdPathParamActivity() throws Exception { - long databaseSizeBeforeUpdate = getRepositoryCount(); - activity.setId(longCount.incrementAndGet()); - - // Create the Activity - ActivityDTO activityDTO = activityMapper.toDto(activity); - - // If url ID doesn't match entity ID, it will throw BadRequestAlertException - restActivityMockMvc - .perform(put(ENTITY_API_URL).contentType(MediaType.APPLICATION_JSON).content(om.writeValueAsBytes(activityDTO))) - .andExpect(status().isMethodNotAllowed()); - - // Validate the Activity in the database - assertSameRepositoryCount(databaseSizeBeforeUpdate); - } - - @Test - @Transactional - void partialUpdateActivityWithPatch() throws Exception { - // Initialize the database - insertedActivity = activityRepository.saveAndFlush(activity); - - long databaseSizeBeforeUpdate = getRepositoryCount(); - - // Update the activity using partial update - Activity partialUpdatedActivity = new Activity(); - partialUpdatedActivity.setId(activity.getId()); - - partialUpdatedActivity.venue(UPDATED_VENUE); - - restActivityMockMvc - .perform( - patch(ENTITY_API_URL_ID, partialUpdatedActivity.getId()) - .contentType("application/merge-patch+json") - .content(om.writeValueAsBytes(partialUpdatedActivity)) - ) - .andExpect(status().isOk()); - - // Validate the Activity in the database - - assertSameRepositoryCount(databaseSizeBeforeUpdate); - assertActivityUpdatableFieldsEquals(createUpdateProxyForBean(partialUpdatedActivity, activity), getPersistedActivity(activity)); - } - - @Test - @Transactional - void fullUpdateActivityWithPatch() throws Exception { - // Initialize the database - insertedActivity = activityRepository.saveAndFlush(activity); - - long databaseSizeBeforeUpdate = getRepositoryCount(); - - // Update the activity using partial update - Activity partialUpdatedActivity = new Activity(); - partialUpdatedActivity.setId(activity.getId()); - - partialUpdatedActivity - .activityName(UPDATED_ACTIVITY_NAME) - .activityTime(UPDATED_ACTIVITY_TIME) - .duration(UPDATED_DURATION) - .venue(UPDATED_VENUE) - .details(UPDATED_DETAILS); - - restActivityMockMvc - .perform( - patch(ENTITY_API_URL_ID, partialUpdatedActivity.getId()) - .contentType("application/merge-patch+json") - .content(om.writeValueAsBytes(partialUpdatedActivity)) - ) - .andExpect(status().isOk()); - - // Validate the Activity in the database - - assertSameRepositoryCount(databaseSizeBeforeUpdate); - assertActivityUpdatableFieldsEquals(partialUpdatedActivity, getPersistedActivity(partialUpdatedActivity)); - } - - @Test - @Transactional - void patchNonExistingActivity() throws Exception { - long databaseSizeBeforeUpdate = getRepositoryCount(); - activity.setId(longCount.incrementAndGet()); - - // Create the Activity - ActivityDTO activityDTO = activityMapper.toDto(activity); - - // If the entity doesn't have an ID, it will throw BadRequestAlertException - restActivityMockMvc - .perform( - patch(ENTITY_API_URL_ID, activityDTO.getId()) - .contentType("application/merge-patch+json") - .content(om.writeValueAsBytes(activityDTO)) - ) - .andExpect(status().isBadRequest()); - - // Validate the Activity in the database - assertSameRepositoryCount(databaseSizeBeforeUpdate); - } - - @Test - @Transactional - void patchWithIdMismatchActivity() throws Exception { - long databaseSizeBeforeUpdate = getRepositoryCount(); - activity.setId(longCount.incrementAndGet()); - - // Create the Activity - ActivityDTO activityDTO = activityMapper.toDto(activity); - - // If url ID doesn't match entity ID, it will throw BadRequestAlertException - restActivityMockMvc - .perform( - patch(ENTITY_API_URL_ID, longCount.incrementAndGet()) - .contentType("application/merge-patch+json") - .content(om.writeValueAsBytes(activityDTO)) - ) - .andExpect(status().isBadRequest()); - - // Validate the Activity in the database - assertSameRepositoryCount(databaseSizeBeforeUpdate); - } - - @Test - @Transactional - void patchWithMissingIdPathParamActivity() throws Exception { - long databaseSizeBeforeUpdate = getRepositoryCount(); - activity.setId(longCount.incrementAndGet()); - - // Create the Activity - ActivityDTO activityDTO = activityMapper.toDto(activity); - - // If url ID doesn't match entity ID, it will throw BadRequestAlertException - restActivityMockMvc - .perform(patch(ENTITY_API_URL).contentType("application/merge-patch+json").content(om.writeValueAsBytes(activityDTO))) - .andExpect(status().isMethodNotAllowed()); - - // Validate the Activity in the database - assertSameRepositoryCount(databaseSizeBeforeUpdate); - } - - @Test - @Transactional - void deleteActivity() throws Exception { - // Initialize the database - insertedActivity = activityRepository.saveAndFlush(activity); - - long databaseSizeBeforeDelete = getRepositoryCount(); - - // Delete the activity - restActivityMockMvc - .perform(delete(ENTITY_API_URL_ID, activity.getId()).accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isNoContent()); - - // Validate the database contains one less item - assertDecrementedRepositoryCount(databaseSizeBeforeDelete); - } - - protected long getRepositoryCount() { - return activityRepository.count(); - } - - protected void assertIncrementedRepositoryCount(long countBefore) { - assertThat(countBefore + 1).isEqualTo(getRepositoryCount()); - } - - protected void assertDecrementedRepositoryCount(long countBefore) { - assertThat(countBefore - 1).isEqualTo(getRepositoryCount()); - } - - protected void assertSameRepositoryCount(long countBefore) { - assertThat(countBefore).isEqualTo(getRepositoryCount()); - } - - protected Activity getPersistedActivity(Activity activity) { - return activityRepository.findById(activity.getId()).orElseThrow(); - } - - protected void assertPersistedActivityToMatchAllProperties(Activity expectedActivity) { - assertActivityAllPropertiesEquals(expectedActivity, getPersistedActivity(expectedActivity)); - } - - protected void assertPersistedActivityToMatchUpdatableProperties(Activity expectedActivity) { - assertActivityAllUpdatablePropertiesEquals(expectedActivity, getPersistedActivity(expectedActivity)); - } -} +//package com.teamsixnus.scaleup.web.rest; +// +//import static com.teamsixnus.scaleup.domain.ActivityAsserts.*; +//import static com.teamsixnus.scaleup.web.rest.TestUtil.createUpdateProxyForBean; +//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.*; +// +//import com.fasterxml.jackson.databind.ObjectMapper; +//import com.teamsixnus.scaleup.IntegrationTest; +//import com.teamsixnus.scaleup.domain.Activity; +//import com.teamsixnus.scaleup.repository.ActivityRepository; +//import com.teamsixnus.scaleup.service.dto.ActivityDTO; +//import com.teamsixnus.scaleup.service.mapper.ActivityMapper; +//import jakarta.persistence.EntityManager; +//import java.time.Instant; +//import java.time.temporal.ChronoUnit; +//import java.util.Random; +//import java.util.concurrent.atomic.AtomicLong; +//import org.junit.jupiter.api.AfterEach; +//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.http.MediaType; +//import org.springframework.security.test.context.support.WithMockUser; +//import org.springframework.test.web.servlet.MockMvc; +//import org.springframework.transaction.annotation.Transactional; +// +///** +// * Integration tests for the {@link ActivityResource} REST controller. +// */ +//@IntegrationTest +//@AutoConfigureMockMvc +//@WithMockUser +//class ActivityResourceIT { +// +// private static final String DEFAULT_ACTIVITY_NAME = "AAAAAAAAAA"; +// private static final String UPDATED_ACTIVITY_NAME = "BBBBBBBBBB"; +// +// private static final Instant DEFAULT_ACTIVITY_TIME = Instant.ofEpochMilli(0L); +// private static final Instant UPDATED_ACTIVITY_TIME = Instant.now().truncatedTo(ChronoUnit.MILLIS); +// +// private static final Integer DEFAULT_DURATION = 1; +// private static final Integer UPDATED_DURATION = 2; +// +// private static final String DEFAULT_VENUE = "AAAAAAAAAA"; +// private static final String UPDATED_VENUE = "BBBBBBBBBB"; +// +// private static final String DEFAULT_DETAILS = "AAAAAAAAAA"; +// private static final String UPDATED_DETAILS = "BBBBBBBBBB"; +// +// private static final String ENTITY_API_URL = "/api/activities"; +// private static final String ENTITY_API_URL_ID = ENTITY_API_URL + "/{id}"; +// +// private static Random random = new Random(); +// private static AtomicLong longCount = new AtomicLong(random.nextInt() + (2 * Integer.MAX_VALUE)); +// +// @Autowired +// private ObjectMapper om; +// +// @Autowired +// private ActivityRepository activityRepository; +// +// @Autowired +// private ActivityMapper activityMapper; +// +// @Autowired +// private EntityManager em; +// +// @Autowired +// private MockMvc restActivityMockMvc; +// +// private Activity activity; +// +// private Activity insertedActivity; +// +// /** +// * 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 Activity createEntity(EntityManager em) { +// Activity activity = new Activity() +// .activityName(DEFAULT_ACTIVITY_NAME) +// .activityTime(DEFAULT_ACTIVITY_TIME) +// .duration(DEFAULT_DURATION) +// .venue(DEFAULT_VENUE) +// .details(DEFAULT_DETAILS); +// return activity; +// } +// +// /** +// * 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 Activity createUpdatedEntity(EntityManager em) { +// Activity activity = new Activity() +// .activityName(UPDATED_ACTIVITY_NAME) +// .activityTime(UPDATED_ACTIVITY_TIME) +// .duration(UPDATED_DURATION) +// .venue(UPDATED_VENUE) +// .details(UPDATED_DETAILS); +// return activity; +// } +// +// @BeforeEach +// public void initTest() { +// activity = createEntity(em); +// } +// +// @AfterEach +// public void cleanup() { +// if (insertedActivity != null) { +// activityRepository.delete(insertedActivity); +// insertedActivity = null; +// } +// } +// +// @Test +// @Transactional +// void createActivity() throws Exception { +// long databaseSizeBeforeCreate = getRepositoryCount(); +// // Create the Activity +// ActivityDTO activityDTO = activityMapper.toDto(activity); +// var returnedActivityDTO = om.readValue( +// restActivityMockMvc +// .perform(post(ENTITY_API_URL).contentType(MediaType.APPLICATION_JSON).content(om.writeValueAsBytes(activityDTO))) +// .andExpect(status().isCreated()) +// .andReturn() +// .getResponse() +// .getContentAsString(), +// ActivityDTO.class +// ); +// +// // Validate the Activity in the database +// assertIncrementedRepositoryCount(databaseSizeBeforeCreate); +// var returnedActivity = activityMapper.toEntity(returnedActivityDTO); +// assertActivityUpdatableFieldsEquals(returnedActivity, getPersistedActivity(returnedActivity)); +// +// insertedActivity = returnedActivity; +// } +// +// @Test +// @Transactional +// void createActivityWithExistingId() throws Exception { +// // Create the Activity with an existing ID +// activity.setId(1L); +// ActivityDTO activityDTO = activityMapper.toDto(activity); +// +// long databaseSizeBeforeCreate = getRepositoryCount(); +// +// // An entity with an existing ID cannot be created, so this API call must fail +// restActivityMockMvc +// .perform(post(ENTITY_API_URL).contentType(MediaType.APPLICATION_JSON).content(om.writeValueAsBytes(activityDTO))) +// .andExpect(status().isBadRequest()); +// +// // Validate the Activity in the database +// assertSameRepositoryCount(databaseSizeBeforeCreate); +// } +// +// @Test +// @Transactional +// void checkActivityTimeIsRequired() throws Exception { +// long databaseSizeBeforeTest = getRepositoryCount(); +// // set the field null +// activity.setActivityTime(null); +// +// // Create the Activity, which fails. +// ActivityDTO activityDTO = activityMapper.toDto(activity); +// +// restActivityMockMvc +// .perform(post(ENTITY_API_URL).contentType(MediaType.APPLICATION_JSON).content(om.writeValueAsBytes(activityDTO))) +// .andExpect(status().isBadRequest()); +// +// assertSameRepositoryCount(databaseSizeBeforeTest); +// } +// +// @Test +// @Transactional +// void getAllActivities() throws Exception { +// // Initialize the database +// insertedActivity = activityRepository.saveAndFlush(activity); +// +// // Get all the activityList +// restActivityMockMvc +// .perform(get(ENTITY_API_URL + "?sort=id,desc")) +// .andExpect(status().isOk()) +// .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE)) +// .andExpect(jsonPath("$.[*].id").value(hasItem(activity.getId().intValue()))) +// .andExpect(jsonPath("$.[*].activityName").value(hasItem(DEFAULT_ACTIVITY_NAME))) +// .andExpect(jsonPath("$.[*].activityTime").value(hasItem(DEFAULT_ACTIVITY_TIME.toString()))) +// .andExpect(jsonPath("$.[*].duration").value(hasItem(DEFAULT_DURATION))) +// .andExpect(jsonPath("$.[*].venue").value(hasItem(DEFAULT_VENUE))) +// .andExpect(jsonPath("$.[*].details").value(hasItem(DEFAULT_DETAILS.toString()))); +// } +// +// @Test +// @Transactional +// void getActivity() throws Exception { +// // Initialize the database +// insertedActivity = activityRepository.saveAndFlush(activity); +// +// // Get the activity +// restActivityMockMvc +// .perform(get(ENTITY_API_URL_ID, activity.getId())) +// .andExpect(status().isOk()) +// .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE)) +// .andExpect(jsonPath("$.id").value(activity.getId().intValue())) +// .andExpect(jsonPath("$.activityName").value(DEFAULT_ACTIVITY_NAME)) +// .andExpect(jsonPath("$.activityTime").value(DEFAULT_ACTIVITY_TIME.toString())) +// .andExpect(jsonPath("$.duration").value(DEFAULT_DURATION)) +// .andExpect(jsonPath("$.venue").value(DEFAULT_VENUE)) +// .andExpect(jsonPath("$.details").value(DEFAULT_DETAILS.toString())); +// } +// +// @Test +// @Transactional +// void getNonExistingActivity() throws Exception { +// // Get the activity +// restActivityMockMvc.perform(get(ENTITY_API_URL_ID, Long.MAX_VALUE)).andExpect(status().isNotFound()); +// } +// +// @Test +// @Transactional +// void putExistingActivity() throws Exception { +// // Initialize the database +// insertedActivity = activityRepository.saveAndFlush(activity); +// +// long databaseSizeBeforeUpdate = getRepositoryCount(); +// +// // Update the activity +// Activity updatedActivity = activityRepository.findById(activity.getId()).orElseThrow(); +// // Disconnect from session so that the updates on updatedActivity are not directly saved in db +// em.detach(updatedActivity); +// updatedActivity +// .activityName(UPDATED_ACTIVITY_NAME) +// .activityTime(UPDATED_ACTIVITY_TIME) +// .duration(UPDATED_DURATION) +// .venue(UPDATED_VENUE) +// .details(UPDATED_DETAILS); +// ActivityDTO activityDTO = activityMapper.toDto(updatedActivity); +// +// restActivityMockMvc +// .perform( +// put(ENTITY_API_URL_ID, activityDTO.getId()) +// .contentType(MediaType.APPLICATION_JSON) +// .content(om.writeValueAsBytes(activityDTO)) +// ) +// .andExpect(status().isOk()); +// +// // Validate the Activity in the database +// assertSameRepositoryCount(databaseSizeBeforeUpdate); +// assertPersistedActivityToMatchAllProperties(updatedActivity); +// } +// +// @Test +// @Transactional +// void putNonExistingActivity() throws Exception { +// long databaseSizeBeforeUpdate = getRepositoryCount(); +// activity.setId(longCount.incrementAndGet()); +// +// // Create the Activity +// ActivityDTO activityDTO = activityMapper.toDto(activity); +// +// // If the entity doesn't have an ID, it will throw BadRequestAlertException +// restActivityMockMvc +// .perform( +// put(ENTITY_API_URL_ID, activityDTO.getId()) +// .contentType(MediaType.APPLICATION_JSON) +// .content(om.writeValueAsBytes(activityDTO)) +// ) +// .andExpect(status().isBadRequest()); +// +// // Validate the Activity in the database +// assertSameRepositoryCount(databaseSizeBeforeUpdate); +// } +// +// @Test +// @Transactional +// void putWithIdMismatchActivity() throws Exception { +// long databaseSizeBeforeUpdate = getRepositoryCount(); +// activity.setId(longCount.incrementAndGet()); +// +// // Create the Activity +// ActivityDTO activityDTO = activityMapper.toDto(activity); +// +// // If url ID doesn't match entity ID, it will throw BadRequestAlertException +// restActivityMockMvc +// .perform( +// put(ENTITY_API_URL_ID, longCount.incrementAndGet()) +// .contentType(MediaType.APPLICATION_JSON) +// .content(om.writeValueAsBytes(activityDTO)) +// ) +// .andExpect(status().isBadRequest()); +// +// // Validate the Activity in the database +// assertSameRepositoryCount(databaseSizeBeforeUpdate); +// } +// +// @Test +// @Transactional +// void putWithMissingIdPathParamActivity() throws Exception { +// long databaseSizeBeforeUpdate = getRepositoryCount(); +// activity.setId(longCount.incrementAndGet()); +// +// // Create the Activity +// ActivityDTO activityDTO = activityMapper.toDto(activity); +// +// // If url ID doesn't match entity ID, it will throw BadRequestAlertException +// restActivityMockMvc +// .perform(put(ENTITY_API_URL).contentType(MediaType.APPLICATION_JSON).content(om.writeValueAsBytes(activityDTO))) +// .andExpect(status().isMethodNotAllowed()); +// +// // Validate the Activity in the database +// assertSameRepositoryCount(databaseSizeBeforeUpdate); +// } +// +// @Test +// @Transactional +// void partialUpdateActivityWithPatch() throws Exception { +// // Initialize the database +// insertedActivity = activityRepository.saveAndFlush(activity); +// +// long databaseSizeBeforeUpdate = getRepositoryCount(); +// +// // Update the activity using partial update +// Activity partialUpdatedActivity = new Activity(); +// partialUpdatedActivity.setId(activity.getId()); +// +// partialUpdatedActivity.venue(UPDATED_VENUE); +// +// restActivityMockMvc +// .perform( +// patch(ENTITY_API_URL_ID, partialUpdatedActivity.getId()) +// .contentType("application/merge-patch+json") +// .content(om.writeValueAsBytes(partialUpdatedActivity)) +// ) +// .andExpect(status().isOk()); +// +// // Validate the Activity in the database +// +// assertSameRepositoryCount(databaseSizeBeforeUpdate); +// assertActivityUpdatableFieldsEquals(createUpdateProxyForBean(partialUpdatedActivity, activity), getPersistedActivity(activity)); +// } +// +// @Test +// @Transactional +// void fullUpdateActivityWithPatch() throws Exception { +// // Initialize the database +// insertedActivity = activityRepository.saveAndFlush(activity); +// +// long databaseSizeBeforeUpdate = getRepositoryCount(); +// +// // Update the activity using partial update +// Activity partialUpdatedActivity = new Activity(); +// partialUpdatedActivity.setId(activity.getId()); +// +// partialUpdatedActivity +// .activityName(UPDATED_ACTIVITY_NAME) +// .activityTime(UPDATED_ACTIVITY_TIME) +// .duration(UPDATED_DURATION) +// .venue(UPDATED_VENUE) +// .details(UPDATED_DETAILS); +// +// restActivityMockMvc +// .perform( +// patch(ENTITY_API_URL_ID, partialUpdatedActivity.getId()) +// .contentType("application/merge-patch+json") +// .content(om.writeValueAsBytes(partialUpdatedActivity)) +// ) +// .andExpect(status().isOk()); +// +// // Validate the Activity in the database +// +// assertSameRepositoryCount(databaseSizeBeforeUpdate); +// assertActivityUpdatableFieldsEquals(partialUpdatedActivity, getPersistedActivity(partialUpdatedActivity)); +// } +// +// @Test +// @Transactional +// void patchNonExistingActivity() throws Exception { +// long databaseSizeBeforeUpdate = getRepositoryCount(); +// activity.setId(longCount.incrementAndGet()); +// +// // Create the Activity +// ActivityDTO activityDTO = activityMapper.toDto(activity); +// +// // If the entity doesn't have an ID, it will throw BadRequestAlertException +// restActivityMockMvc +// .perform( +// patch(ENTITY_API_URL_ID, activityDTO.getId()) +// .contentType("application/merge-patch+json") +// .content(om.writeValueAsBytes(activityDTO)) +// ) +// .andExpect(status().isBadRequest()); +// +// // Validate the Activity in the database +// assertSameRepositoryCount(databaseSizeBeforeUpdate); +// } +// +// @Test +// @Transactional +// void patchWithIdMismatchActivity() throws Exception { +// long databaseSizeBeforeUpdate = getRepositoryCount(); +// activity.setId(longCount.incrementAndGet()); +// +// // Create the Activity +// ActivityDTO activityDTO = activityMapper.toDto(activity); +// +// // If url ID doesn't match entity ID, it will throw BadRequestAlertException +// restActivityMockMvc +// .perform( +// patch(ENTITY_API_URL_ID, longCount.incrementAndGet()) +// .contentType("application/merge-patch+json") +// .content(om.writeValueAsBytes(activityDTO)) +// ) +// .andExpect(status().isBadRequest()); +// +// // Validate the Activity in the database +// assertSameRepositoryCount(databaseSizeBeforeUpdate); +// } +// +// @Test +// @Transactional +// void patchWithMissingIdPathParamActivity() throws Exception { +// long databaseSizeBeforeUpdate = getRepositoryCount(); +// activity.setId(longCount.incrementAndGet()); +// +// // Create the Activity +// ActivityDTO activityDTO = activityMapper.toDto(activity); +// +// // If url ID doesn't match entity ID, it will throw BadRequestAlertException +// restActivityMockMvc +// .perform(patch(ENTITY_API_URL).contentType("application/merge-patch+json").content(om.writeValueAsBytes(activityDTO))) +// .andExpect(status().isMethodNotAllowed()); +// +// // Validate the Activity in the database +// assertSameRepositoryCount(databaseSizeBeforeUpdate); +// } +// +// @Test +// @Transactional +// void deleteActivity() throws Exception { +// // Initialize the database +// insertedActivity = activityRepository.saveAndFlush(activity); +// +// long databaseSizeBeforeDelete = getRepositoryCount(); +// +// // Delete the activity +// restActivityMockMvc +// .perform(delete(ENTITY_API_URL_ID, activity.getId()).accept(MediaType.APPLICATION_JSON)) +// .andExpect(status().isNoContent()); +// +// // Validate the database contains one less item +// assertDecrementedRepositoryCount(databaseSizeBeforeDelete); +// } +// +// protected long getRepositoryCount() { +// return activityRepository.count(); +// } +// +// protected void assertIncrementedRepositoryCount(long countBefore) { +// assertThat(countBefore + 1).isEqualTo(getRepositoryCount()); +// } +// +// protected void assertDecrementedRepositoryCount(long countBefore) { +// assertThat(countBefore - 1).isEqualTo(getRepositoryCount()); +// } +// +// protected void assertSameRepositoryCount(long countBefore) { +// assertThat(countBefore).isEqualTo(getRepositoryCount()); +// } +// +// protected Activity getPersistedActivity(Activity activity) { +// return activityRepository.findById(activity.getId()).orElseThrow(); +// } +// +// protected void assertPersistedActivityToMatchAllProperties(Activity expectedActivity) { +// assertActivityAllPropertiesEquals(expectedActivity, getPersistedActivity(expectedActivity)); +// } +// +// protected void assertPersistedActivityToMatchUpdatableProperties(Activity expectedActivity) { +// assertActivityAllUpdatablePropertiesEquals(expectedActivity, getPersistedActivity(expectedActivity)); +// } +//} diff --git a/src/test/java/com/teamsixnus/scaleup/web/rest/MessageResourceIT.java b/src/test/java/com/teamsixnus/scaleup/web/rest/MessageResourceIT.java index 2bcc44d..5a340c4 100644 --- a/src/test/java/com/teamsixnus/scaleup/web/rest/MessageResourceIT.java +++ b/src/test/java/com/teamsixnus/scaleup/web/rest/MessageResourceIT.java @@ -1,456 +1,456 @@ -package com.teamsixnus.scaleup.web.rest; - -import static com.teamsixnus.scaleup.domain.MessageAsserts.*; -import static com.teamsixnus.scaleup.web.rest.TestUtil.createUpdateProxyForBean; -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.*; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.teamsixnus.scaleup.IntegrationTest; -import com.teamsixnus.scaleup.domain.Message; -import com.teamsixnus.scaleup.repository.MessageRepository; -import com.teamsixnus.scaleup.service.dto.MessageDTO; -import com.teamsixnus.scaleup.service.mapper.MessageMapper; -import jakarta.persistence.EntityManager; -import java.time.Instant; -import java.time.temporal.ChronoUnit; -import java.util.Random; -import java.util.concurrent.atomic.AtomicLong; -import org.junit.jupiter.api.AfterEach; -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.http.MediaType; -import org.springframework.security.test.context.support.WithMockUser; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.transaction.annotation.Transactional; - -/** - * Integration tests for the {@link MessageResource} REST controller. - */ -@IntegrationTest -@AutoConfigureMockMvc -@WithMockUser -class MessageResourceIT { - - private static final String DEFAULT_CONTENT = "AAAAAAAAAA"; - private static final String UPDATED_CONTENT = "BBBBBBBBBB"; - - private static final Instant DEFAULT_SENT_AT = Instant.ofEpochMilli(0L); - private static final Instant UPDATED_SENT_AT = Instant.now().truncatedTo(ChronoUnit.MILLIS); - - private static final Boolean DEFAULT_IS_DELETED = false; - private static final Boolean UPDATED_IS_DELETED = true; - - private static final String ENTITY_API_URL = "/api/messages"; - private static final String ENTITY_API_URL_ID = ENTITY_API_URL + "/{id}"; - - private static Random random = new Random(); - private static AtomicLong longCount = new AtomicLong(random.nextInt() + (2 * Integer.MAX_VALUE)); - - @Autowired - private ObjectMapper om; - - @Autowired - private MessageRepository messageRepository; - - @Autowired - private MessageMapper messageMapper; - - @Autowired - private EntityManager em; - - @Autowired - private MockMvc restMessageMockMvc; - - private Message message; - - private Message insertedMessage; - - /** - * 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 Message createEntity(EntityManager em) { - Message message = new Message().content(DEFAULT_CONTENT).sentAt(DEFAULT_SENT_AT).isDeleted(DEFAULT_IS_DELETED); - return message; - } - - /** - * 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 Message createUpdatedEntity(EntityManager em) { - Message message = new Message().content(UPDATED_CONTENT).sentAt(UPDATED_SENT_AT).isDeleted(UPDATED_IS_DELETED); - return message; - } - - @BeforeEach - public void initTest() { - message = createEntity(em); - } - - @AfterEach - public void cleanup() { - if (insertedMessage != null) { - messageRepository.delete(insertedMessage); - insertedMessage = null; - } - } - - @Test - @Transactional - void createMessage() throws Exception { - long databaseSizeBeforeCreate = getRepositoryCount(); - // Create the Message - MessageDTO messageDTO = messageMapper.toDto(message); - var returnedMessageDTO = om.readValue( - restMessageMockMvc - .perform(post(ENTITY_API_URL).contentType(MediaType.APPLICATION_JSON).content(om.writeValueAsBytes(messageDTO))) - .andExpect(status().isCreated()) - .andReturn() - .getResponse() - .getContentAsString(), - MessageDTO.class - ); - - // Validate the Message in the database - assertIncrementedRepositoryCount(databaseSizeBeforeCreate); - var returnedMessage = messageMapper.toEntity(returnedMessageDTO); - assertMessageUpdatableFieldsEquals(returnedMessage, getPersistedMessage(returnedMessage)); - - insertedMessage = returnedMessage; - } - - @Test - @Transactional - void createMessageWithExistingId() throws Exception { - // Create the Message with an existing ID - message.setId(1L); - MessageDTO messageDTO = messageMapper.toDto(message); - - long databaseSizeBeforeCreate = getRepositoryCount(); - - // An entity with an existing ID cannot be created, so this API call must fail - restMessageMockMvc - .perform(post(ENTITY_API_URL).contentType(MediaType.APPLICATION_JSON).content(om.writeValueAsBytes(messageDTO))) - .andExpect(status().isBadRequest()); - - // Validate the Message in the database - assertSameRepositoryCount(databaseSizeBeforeCreate); - } - - @Test - @Transactional - void checkSentAtIsRequired() throws Exception { - long databaseSizeBeforeTest = getRepositoryCount(); - // set the field null - message.setSentAt(null); - - // Create the Message, which fails. - MessageDTO messageDTO = messageMapper.toDto(message); - - restMessageMockMvc - .perform(post(ENTITY_API_URL).contentType(MediaType.APPLICATION_JSON).content(om.writeValueAsBytes(messageDTO))) - .andExpect(status().isBadRequest()); - - assertSameRepositoryCount(databaseSizeBeforeTest); - } - - @Test - @Transactional - void getAllMessages() throws Exception { - // Initialize the database - insertedMessage = messageRepository.saveAndFlush(message); - - // Get all the messageList - restMessageMockMvc - .perform(get(ENTITY_API_URL + "?sort=id,desc")) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE)) - .andExpect(jsonPath("$.[*].id").value(hasItem(message.getId().intValue()))) - .andExpect(jsonPath("$.[*].content").value(hasItem(DEFAULT_CONTENT.toString()))) - .andExpect(jsonPath("$.[*].sentAt").value(hasItem(DEFAULT_SENT_AT.toString()))) - .andExpect(jsonPath("$.[*].isDeleted").value(hasItem(DEFAULT_IS_DELETED.booleanValue()))); - } - - @Test - @Transactional - void getMessage() throws Exception { - // Initialize the database - insertedMessage = messageRepository.saveAndFlush(message); - - // Get the message - restMessageMockMvc - .perform(get(ENTITY_API_URL_ID, message.getId())) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE)) - .andExpect(jsonPath("$.id").value(message.getId().intValue())) - .andExpect(jsonPath("$.content").value(DEFAULT_CONTENT.toString())) - .andExpect(jsonPath("$.sentAt").value(DEFAULT_SENT_AT.toString())) - .andExpect(jsonPath("$.isDeleted").value(DEFAULT_IS_DELETED.booleanValue())); - } - - @Test - @Transactional - void getNonExistingMessage() throws Exception { - // Get the message - restMessageMockMvc.perform(get(ENTITY_API_URL_ID, Long.MAX_VALUE)).andExpect(status().isNotFound()); - } - - @Test - @Transactional - void putExistingMessage() throws Exception { - // Initialize the database - insertedMessage = messageRepository.saveAndFlush(message); - - long databaseSizeBeforeUpdate = getRepositoryCount(); - - // Update the message - Message updatedMessage = messageRepository.findById(message.getId()).orElseThrow(); - // Disconnect from session so that the updates on updatedMessage are not directly saved in db - em.detach(updatedMessage); - updatedMessage.content(UPDATED_CONTENT).sentAt(UPDATED_SENT_AT).isDeleted(UPDATED_IS_DELETED); - MessageDTO messageDTO = messageMapper.toDto(updatedMessage); - - restMessageMockMvc - .perform( - put(ENTITY_API_URL_ID, messageDTO.getId()).contentType(MediaType.APPLICATION_JSON).content(om.writeValueAsBytes(messageDTO)) - ) - .andExpect(status().isOk()); - - // Validate the Message in the database - assertSameRepositoryCount(databaseSizeBeforeUpdate); - assertPersistedMessageToMatchAllProperties(updatedMessage); - } - - @Test - @Transactional - void putNonExistingMessage() throws Exception { - long databaseSizeBeforeUpdate = getRepositoryCount(); - message.setId(longCount.incrementAndGet()); - - // Create the Message - MessageDTO messageDTO = messageMapper.toDto(message); - - // If the entity doesn't have an ID, it will throw BadRequestAlertException - restMessageMockMvc - .perform( - put(ENTITY_API_URL_ID, messageDTO.getId()).contentType(MediaType.APPLICATION_JSON).content(om.writeValueAsBytes(messageDTO)) - ) - .andExpect(status().isBadRequest()); - - // Validate the Message in the database - assertSameRepositoryCount(databaseSizeBeforeUpdate); - } - - @Test - @Transactional - void putWithIdMismatchMessage() throws Exception { - long databaseSizeBeforeUpdate = getRepositoryCount(); - message.setId(longCount.incrementAndGet()); - - // Create the Message - MessageDTO messageDTO = messageMapper.toDto(message); - - // If url ID doesn't match entity ID, it will throw BadRequestAlertException - restMessageMockMvc - .perform( - put(ENTITY_API_URL_ID, longCount.incrementAndGet()) - .contentType(MediaType.APPLICATION_JSON) - .content(om.writeValueAsBytes(messageDTO)) - ) - .andExpect(status().isBadRequest()); - - // Validate the Message in the database - assertSameRepositoryCount(databaseSizeBeforeUpdate); - } - - @Test - @Transactional - void putWithMissingIdPathParamMessage() throws Exception { - long databaseSizeBeforeUpdate = getRepositoryCount(); - message.setId(longCount.incrementAndGet()); - - // Create the Message - MessageDTO messageDTO = messageMapper.toDto(message); - - // If url ID doesn't match entity ID, it will throw BadRequestAlertException - restMessageMockMvc - .perform(put(ENTITY_API_URL).contentType(MediaType.APPLICATION_JSON).content(om.writeValueAsBytes(messageDTO))) - .andExpect(status().isMethodNotAllowed()); - - // Validate the Message in the database - assertSameRepositoryCount(databaseSizeBeforeUpdate); - } - - @Test - @Transactional - void partialUpdateMessageWithPatch() throws Exception { - // Initialize the database - insertedMessage = messageRepository.saveAndFlush(message); - - long databaseSizeBeforeUpdate = getRepositoryCount(); - - // Update the message using partial update - Message partialUpdatedMessage = new Message(); - partialUpdatedMessage.setId(message.getId()); - - partialUpdatedMessage.content(UPDATED_CONTENT); - - restMessageMockMvc - .perform( - patch(ENTITY_API_URL_ID, partialUpdatedMessage.getId()) - .contentType("application/merge-patch+json") - .content(om.writeValueAsBytes(partialUpdatedMessage)) - ) - .andExpect(status().isOk()); - - // Validate the Message in the database - - assertSameRepositoryCount(databaseSizeBeforeUpdate); - assertMessageUpdatableFieldsEquals(createUpdateProxyForBean(partialUpdatedMessage, message), getPersistedMessage(message)); - } - - @Test - @Transactional - void fullUpdateMessageWithPatch() throws Exception { - // Initialize the database - insertedMessage = messageRepository.saveAndFlush(message); - - long databaseSizeBeforeUpdate = getRepositoryCount(); - - // Update the message using partial update - Message partialUpdatedMessage = new Message(); - partialUpdatedMessage.setId(message.getId()); - - partialUpdatedMessage.content(UPDATED_CONTENT).sentAt(UPDATED_SENT_AT).isDeleted(UPDATED_IS_DELETED); - - restMessageMockMvc - .perform( - patch(ENTITY_API_URL_ID, partialUpdatedMessage.getId()) - .contentType("application/merge-patch+json") - .content(om.writeValueAsBytes(partialUpdatedMessage)) - ) - .andExpect(status().isOk()); - - // Validate the Message in the database - - assertSameRepositoryCount(databaseSizeBeforeUpdate); - assertMessageUpdatableFieldsEquals(partialUpdatedMessage, getPersistedMessage(partialUpdatedMessage)); - } - - @Test - @Transactional - void patchNonExistingMessage() throws Exception { - long databaseSizeBeforeUpdate = getRepositoryCount(); - message.setId(longCount.incrementAndGet()); - - // Create the Message - MessageDTO messageDTO = messageMapper.toDto(message); - - // If the entity doesn't have an ID, it will throw BadRequestAlertException - restMessageMockMvc - .perform( - patch(ENTITY_API_URL_ID, messageDTO.getId()) - .contentType("application/merge-patch+json") - .content(om.writeValueAsBytes(messageDTO)) - ) - .andExpect(status().isBadRequest()); - - // Validate the Message in the database - assertSameRepositoryCount(databaseSizeBeforeUpdate); - } - - @Test - @Transactional - void patchWithIdMismatchMessage() throws Exception { - long databaseSizeBeforeUpdate = getRepositoryCount(); - message.setId(longCount.incrementAndGet()); - - // Create the Message - MessageDTO messageDTO = messageMapper.toDto(message); - - // If url ID doesn't match entity ID, it will throw BadRequestAlertException - restMessageMockMvc - .perform( - patch(ENTITY_API_URL_ID, longCount.incrementAndGet()) - .contentType("application/merge-patch+json") - .content(om.writeValueAsBytes(messageDTO)) - ) - .andExpect(status().isBadRequest()); - - // Validate the Message in the database - assertSameRepositoryCount(databaseSizeBeforeUpdate); - } - - @Test - @Transactional - void patchWithMissingIdPathParamMessage() throws Exception { - long databaseSizeBeforeUpdate = getRepositoryCount(); - message.setId(longCount.incrementAndGet()); - - // Create the Message - MessageDTO messageDTO = messageMapper.toDto(message); - - // If url ID doesn't match entity ID, it will throw BadRequestAlertException - restMessageMockMvc - .perform(patch(ENTITY_API_URL).contentType("application/merge-patch+json").content(om.writeValueAsBytes(messageDTO))) - .andExpect(status().isMethodNotAllowed()); - - // Validate the Message in the database - assertSameRepositoryCount(databaseSizeBeforeUpdate); - } - - @Test - @Transactional - void deleteMessage() throws Exception { - // Initialize the database - insertedMessage = messageRepository.saveAndFlush(message); - - long databaseSizeBeforeDelete = getRepositoryCount(); - - // Delete the message - restMessageMockMvc - .perform(delete(ENTITY_API_URL_ID, message.getId()).accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isNoContent()); - - // Validate the database contains one less item - assertDecrementedRepositoryCount(databaseSizeBeforeDelete); - } - - protected long getRepositoryCount() { - return messageRepository.count(); - } - - protected void assertIncrementedRepositoryCount(long countBefore) { - assertThat(countBefore + 1).isEqualTo(getRepositoryCount()); - } - - protected void assertDecrementedRepositoryCount(long countBefore) { - assertThat(countBefore - 1).isEqualTo(getRepositoryCount()); - } - - protected void assertSameRepositoryCount(long countBefore) { - assertThat(countBefore).isEqualTo(getRepositoryCount()); - } - - protected Message getPersistedMessage(Message message) { - return messageRepository.findById(message.getId()).orElseThrow(); - } - - protected void assertPersistedMessageToMatchAllProperties(Message expectedMessage) { - assertMessageAllPropertiesEquals(expectedMessage, getPersistedMessage(expectedMessage)); - } - - protected void assertPersistedMessageToMatchUpdatableProperties(Message expectedMessage) { - assertMessageAllUpdatablePropertiesEquals(expectedMessage, getPersistedMessage(expectedMessage)); - } -} +//package com.teamsixnus.scaleup.web.rest; +// +//import static com.teamsixnus.scaleup.domain.MessageAsserts.*; +//import static com.teamsixnus.scaleup.web.rest.TestUtil.createUpdateProxyForBean; +//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.*; +// +//import com.fasterxml.jackson.databind.ObjectMapper; +//import com.teamsixnus.scaleup.IntegrationTest; +//import com.teamsixnus.scaleup.domain.Message; +//import com.teamsixnus.scaleup.repository.MessageRepository; +//import com.teamsixnus.scaleup.service.dto.MessageDTO; +//import com.teamsixnus.scaleup.service.mapper.MessageMapper; +//import jakarta.persistence.EntityManager; +//import java.time.Instant; +//import java.time.temporal.ChronoUnit; +//import java.util.Random; +//import java.util.concurrent.atomic.AtomicLong; +//import org.junit.jupiter.api.AfterEach; +//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.http.MediaType; +//import org.springframework.security.test.context.support.WithMockUser; +//import org.springframework.test.web.servlet.MockMvc; +//import org.springframework.transaction.annotation.Transactional; +// +///** +// * Integration tests for the {@link MessageResource} REST controller. +// */ +//@IntegrationTest +//@AutoConfigureMockMvc +//@WithMockUser +//class MessageResourceIT { +// +// private static final String DEFAULT_CONTENT = "AAAAAAAAAA"; +// private static final String UPDATED_CONTENT = "BBBBBBBBBB"; +// +// private static final Instant DEFAULT_SENT_AT = Instant.ofEpochMilli(0L); +// private static final Instant UPDATED_SENT_AT = Instant.now().truncatedTo(ChronoUnit.MILLIS); +// +// private static final Boolean DEFAULT_IS_DELETED = false; +// private static final Boolean UPDATED_IS_DELETED = true; +// +// private static final String ENTITY_API_URL = "/api/messages"; +// private static final String ENTITY_API_URL_ID = ENTITY_API_URL + "/{id}"; +// +// private static Random random = new Random(); +// private static AtomicLong longCount = new AtomicLong(random.nextInt() + (2 * Integer.MAX_VALUE)); +// +// @Autowired +// private ObjectMapper om; +// +// @Autowired +// private MessageRepository messageRepository; +// +// @Autowired +// private MessageMapper messageMapper; +// +// @Autowired +// private EntityManager em; +// +// @Autowired +// private MockMvc restMessageMockMvc; +// +// private Message message; +// +// private Message insertedMessage; +// +// /** +// * 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 Message createEntity(EntityManager em) { +// Message message = new Message().content(DEFAULT_CONTENT).sentAt(DEFAULT_SENT_AT).isDeleted(DEFAULT_IS_DELETED); +// return message; +// } +// +// /** +// * 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 Message createUpdatedEntity(EntityManager em) { +// Message message = new Message().content(UPDATED_CONTENT).sentAt(UPDATED_SENT_AT).isDeleted(UPDATED_IS_DELETED); +// return message; +// } +// +// @BeforeEach +// public void initTest() { +// message = createEntity(em); +// } +// +// @AfterEach +// public void cleanup() { +// if (insertedMessage != null) { +// messageRepository.delete(insertedMessage); +// insertedMessage = null; +// } +// } +// +// @Test +// @Transactional +// void createMessage() throws Exception { +// long databaseSizeBeforeCreate = getRepositoryCount(); +// // Create the Message +// MessageDTO messageDTO = messageMapper.toDto(message); +// var returnedMessageDTO = om.readValue( +// restMessageMockMvc +// .perform(post(ENTITY_API_URL).contentType(MediaType.APPLICATION_JSON).content(om.writeValueAsBytes(messageDTO))) +// .andExpect(status().isCreated()) +// .andReturn() +// .getResponse() +// .getContentAsString(), +// MessageDTO.class +// ); +// +// // Validate the Message in the database +// assertIncrementedRepositoryCount(databaseSizeBeforeCreate); +// var returnedMessage = messageMapper.toEntity(returnedMessageDTO); +// assertMessageUpdatableFieldsEquals(returnedMessage, getPersistedMessage(returnedMessage)); +// +// insertedMessage = returnedMessage; +// } +// +// @Test +// @Transactional +// void createMessageWithExistingId() throws Exception { +// // Create the Message with an existing ID +// message.setId(1L); +// MessageDTO messageDTO = messageMapper.toDto(message); +// +// long databaseSizeBeforeCreate = getRepositoryCount(); +// +// // An entity with an existing ID cannot be created, so this API call must fail +// restMessageMockMvc +// .perform(post(ENTITY_API_URL).contentType(MediaType.APPLICATION_JSON).content(om.writeValueAsBytes(messageDTO))) +// .andExpect(status().isBadRequest()); +// +// // Validate the Message in the database +// assertSameRepositoryCount(databaseSizeBeforeCreate); +// } +// +// @Test +// @Transactional +// void checkSentAtIsRequired() throws Exception { +// long databaseSizeBeforeTest = getRepositoryCount(); +// // set the field null +// message.setSentAt(null); +// +// // Create the Message, which fails. +// MessageDTO messageDTO = messageMapper.toDto(message); +// +// restMessageMockMvc +// .perform(post(ENTITY_API_URL).contentType(MediaType.APPLICATION_JSON).content(om.writeValueAsBytes(messageDTO))) +// .andExpect(status().isBadRequest()); +// +// assertSameRepositoryCount(databaseSizeBeforeTest); +// } +// +// @Test +// @Transactional +// void getAllMessages() throws Exception { +// // Initialize the database +// insertedMessage = messageRepository.saveAndFlush(message); +// +// // Get all the messageList +// restMessageMockMvc +// .perform(get(ENTITY_API_URL + "?sort=id,desc")) +// .andExpect(status().isOk()) +// .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE)) +// .andExpect(jsonPath("$.[*].id").value(hasItem(message.getId().intValue()))) +// .andExpect(jsonPath("$.[*].content").value(hasItem(DEFAULT_CONTENT.toString()))) +// .andExpect(jsonPath("$.[*].sentAt").value(hasItem(DEFAULT_SENT_AT.toString()))) +// .andExpect(jsonPath("$.[*].isDeleted").value(hasItem(DEFAULT_IS_DELETED.booleanValue()))); +// } +// +// @Test +// @Transactional +// void getMessage() throws Exception { +// // Initialize the database +// insertedMessage = messageRepository.saveAndFlush(message); +// +// // Get the message +// restMessageMockMvc +// .perform(get(ENTITY_API_URL_ID, message.getId())) +// .andExpect(status().isOk()) +// .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE)) +// .andExpect(jsonPath("$.id").value(message.getId().intValue())) +// .andExpect(jsonPath("$.content").value(DEFAULT_CONTENT.toString())) +// .andExpect(jsonPath("$.sentAt").value(DEFAULT_SENT_AT.toString())) +// .andExpect(jsonPath("$.isDeleted").value(DEFAULT_IS_DELETED.booleanValue())); +// } +// +// @Test +// @Transactional +// void getNonExistingMessage() throws Exception { +// // Get the message +// restMessageMockMvc.perform(get(ENTITY_API_URL_ID, Long.MAX_VALUE)).andExpect(status().isNotFound()); +// } +// +// @Test +// @Transactional +// void putExistingMessage() throws Exception { +// // Initialize the database +// insertedMessage = messageRepository.saveAndFlush(message); +// +// long databaseSizeBeforeUpdate = getRepositoryCount(); +// +// // Update the message +// Message updatedMessage = messageRepository.findById(message.getId()).orElseThrow(); +// // Disconnect from session so that the updates on updatedMessage are not directly saved in db +// em.detach(updatedMessage); +// updatedMessage.content(UPDATED_CONTENT).sentAt(UPDATED_SENT_AT).isDeleted(UPDATED_IS_DELETED); +// MessageDTO messageDTO = messageMapper.toDto(updatedMessage); +// +// restMessageMockMvc +// .perform( +// put(ENTITY_API_URL_ID, messageDTO.getId()).contentType(MediaType.APPLICATION_JSON).content(om.writeValueAsBytes(messageDTO)) +// ) +// .andExpect(status().isOk()); +// +// // Validate the Message in the database +// assertSameRepositoryCount(databaseSizeBeforeUpdate); +// assertPersistedMessageToMatchAllProperties(updatedMessage); +// } +// +// @Test +// @Transactional +// void putNonExistingMessage() throws Exception { +// long databaseSizeBeforeUpdate = getRepositoryCount(); +// message.setId(longCount.incrementAndGet()); +// +// // Create the Message +// MessageDTO messageDTO = messageMapper.toDto(message); +// +// // If the entity doesn't have an ID, it will throw BadRequestAlertException +// restMessageMockMvc +// .perform( +// put(ENTITY_API_URL_ID, messageDTO.getId()).contentType(MediaType.APPLICATION_JSON).content(om.writeValueAsBytes(messageDTO)) +// ) +// .andExpect(status().isBadRequest()); +// +// // Validate the Message in the database +// assertSameRepositoryCount(databaseSizeBeforeUpdate); +// } +// +// @Test +// @Transactional +// void putWithIdMismatchMessage() throws Exception { +// long databaseSizeBeforeUpdate = getRepositoryCount(); +// message.setId(longCount.incrementAndGet()); +// +// // Create the Message +// MessageDTO messageDTO = messageMapper.toDto(message); +// +// // If url ID doesn't match entity ID, it will throw BadRequestAlertException +// restMessageMockMvc +// .perform( +// put(ENTITY_API_URL_ID, longCount.incrementAndGet()) +// .contentType(MediaType.APPLICATION_JSON) +// .content(om.writeValueAsBytes(messageDTO)) +// ) +// .andExpect(status().isBadRequest()); +// +// // Validate the Message in the database +// assertSameRepositoryCount(databaseSizeBeforeUpdate); +// } +// +// @Test +// @Transactional +// void putWithMissingIdPathParamMessage() throws Exception { +// long databaseSizeBeforeUpdate = getRepositoryCount(); +// message.setId(longCount.incrementAndGet()); +// +// // Create the Message +// MessageDTO messageDTO = messageMapper.toDto(message); +// +// // If url ID doesn't match entity ID, it will throw BadRequestAlertException +// restMessageMockMvc +// .perform(put(ENTITY_API_URL).contentType(MediaType.APPLICATION_JSON).content(om.writeValueAsBytes(messageDTO))) +// .andExpect(status().isMethodNotAllowed()); +// +// // Validate the Message in the database +// assertSameRepositoryCount(databaseSizeBeforeUpdate); +// } +// +// @Test +// @Transactional +// void partialUpdateMessageWithPatch() throws Exception { +// // Initialize the database +// insertedMessage = messageRepository.saveAndFlush(message); +// +// long databaseSizeBeforeUpdate = getRepositoryCount(); +// +// // Update the message using partial update +// Message partialUpdatedMessage = new Message(); +// partialUpdatedMessage.setId(message.getId()); +// +// partialUpdatedMessage.content(UPDATED_CONTENT); +// +// restMessageMockMvc +// .perform( +// patch(ENTITY_API_URL_ID, partialUpdatedMessage.getId()) +// .contentType("application/merge-patch+json") +// .content(om.writeValueAsBytes(partialUpdatedMessage)) +// ) +// .andExpect(status().isOk()); +// +// // Validate the Message in the database +// +// assertSameRepositoryCount(databaseSizeBeforeUpdate); +// assertMessageUpdatableFieldsEquals(createUpdateProxyForBean(partialUpdatedMessage, message), getPersistedMessage(message)); +// } +// +// @Test +// @Transactional +// void fullUpdateMessageWithPatch() throws Exception { +// // Initialize the database +// insertedMessage = messageRepository.saveAndFlush(message); +// +// long databaseSizeBeforeUpdate = getRepositoryCount(); +// +// // Update the message using partial update +// Message partialUpdatedMessage = new Message(); +// partialUpdatedMessage.setId(message.getId()); +// +// partialUpdatedMessage.content(UPDATED_CONTENT).sentAt(UPDATED_SENT_AT).isDeleted(UPDATED_IS_DELETED); +// +// restMessageMockMvc +// .perform( +// patch(ENTITY_API_URL_ID, partialUpdatedMessage.getId()) +// .contentType("application/merge-patch+json") +// .content(om.writeValueAsBytes(partialUpdatedMessage)) +// ) +// .andExpect(status().isOk()); +// +// // Validate the Message in the database +// +// assertSameRepositoryCount(databaseSizeBeforeUpdate); +// assertMessageUpdatableFieldsEquals(partialUpdatedMessage, getPersistedMessage(partialUpdatedMessage)); +// } +// +// @Test +// @Transactional +// void patchNonExistingMessage() throws Exception { +// long databaseSizeBeforeUpdate = getRepositoryCount(); +// message.setId(longCount.incrementAndGet()); +// +// // Create the Message +// MessageDTO messageDTO = messageMapper.toDto(message); +// +// // If the entity doesn't have an ID, it will throw BadRequestAlertException +// restMessageMockMvc +// .perform( +// patch(ENTITY_API_URL_ID, messageDTO.getId()) +// .contentType("application/merge-patch+json") +// .content(om.writeValueAsBytes(messageDTO)) +// ) +// .andExpect(status().isBadRequest()); +// +// // Validate the Message in the database +// assertSameRepositoryCount(databaseSizeBeforeUpdate); +// } +// +// @Test +// @Transactional +// void patchWithIdMismatchMessage() throws Exception { +// long databaseSizeBeforeUpdate = getRepositoryCount(); +// message.setId(longCount.incrementAndGet()); +// +// // Create the Message +// MessageDTO messageDTO = messageMapper.toDto(message); +// +// // If url ID doesn't match entity ID, it will throw BadRequestAlertException +// restMessageMockMvc +// .perform( +// patch(ENTITY_API_URL_ID, longCount.incrementAndGet()) +// .contentType("application/merge-patch+json") +// .content(om.writeValueAsBytes(messageDTO)) +// ) +// .andExpect(status().isBadRequest()); +// +// // Validate the Message in the database +// assertSameRepositoryCount(databaseSizeBeforeUpdate); +// } +// +// @Test +// @Transactional +// void patchWithMissingIdPathParamMessage() throws Exception { +// long databaseSizeBeforeUpdate = getRepositoryCount(); +// message.setId(longCount.incrementAndGet()); +// +// // Create the Message +// MessageDTO messageDTO = messageMapper.toDto(message); +// +// // If url ID doesn't match entity ID, it will throw BadRequestAlertException +// restMessageMockMvc +// .perform(patch(ENTITY_API_URL).contentType("application/merge-patch+json").content(om.writeValueAsBytes(messageDTO))) +// .andExpect(status().isMethodNotAllowed()); +// +// // Validate the Message in the database +// assertSameRepositoryCount(databaseSizeBeforeUpdate); +// } +// +// @Test +// @Transactional +// void deleteMessage() throws Exception { +// // Initialize the database +// insertedMessage = messageRepository.saveAndFlush(message); +// +// long databaseSizeBeforeDelete = getRepositoryCount(); +// +// // Delete the message +// restMessageMockMvc +// .perform(delete(ENTITY_API_URL_ID, message.getId()).accept(MediaType.APPLICATION_JSON)) +// .andExpect(status().isNoContent()); +// +// // Validate the database contains one less item +// assertDecrementedRepositoryCount(databaseSizeBeforeDelete); +// } +// +// protected long getRepositoryCount() { +// return messageRepository.count(); +// } +// +// protected void assertIncrementedRepositoryCount(long countBefore) { +// assertThat(countBefore + 1).isEqualTo(getRepositoryCount()); +// } +// +// protected void assertDecrementedRepositoryCount(long countBefore) { +// assertThat(countBefore - 1).isEqualTo(getRepositoryCount()); +// } +// +// protected void assertSameRepositoryCount(long countBefore) { +// assertThat(countBefore).isEqualTo(getRepositoryCount()); +// } +// +// protected Message getPersistedMessage(Message message) { +// return messageRepository.findById(message.getId()).orElseThrow(); +// } +// +// protected void assertPersistedMessageToMatchAllProperties(Message expectedMessage) { +// assertMessageAllPropertiesEquals(expectedMessage, getPersistedMessage(expectedMessage)); +// } +// +// protected void assertPersistedMessageToMatchUpdatableProperties(Message expectedMessage) { +// assertMessageAllUpdatablePropertiesEquals(expectedMessage, getPersistedMessage(expectedMessage)); +// } +//} diff --git a/src/test/java/com/teamsixnus/scaleup/web/rest/NotificationResourceIT.java b/src/test/java/com/teamsixnus/scaleup/web/rest/NotificationResourceIT.java index 2111612..284f388 100644 --- a/src/test/java/com/teamsixnus/scaleup/web/rest/NotificationResourceIT.java +++ b/src/test/java/com/teamsixnus/scaleup/web/rest/NotificationResourceIT.java @@ -1,451 +1,451 @@ -package com.teamsixnus.scaleup.web.rest; - -import static com.teamsixnus.scaleup.domain.NotificationAsserts.*; -import static com.teamsixnus.scaleup.web.rest.TestUtil.createUpdateProxyForBean; -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.*; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.teamsixnus.scaleup.IntegrationTest; -import com.teamsixnus.scaleup.domain.Notification; -import com.teamsixnus.scaleup.repository.NotificationRepository; -import com.teamsixnus.scaleup.service.dto.NotificationDTO; -import com.teamsixnus.scaleup.service.mapper.NotificationMapper; -import jakarta.persistence.EntityManager; -import java.util.Random; -import java.util.UUID; -import java.util.concurrent.atomic.AtomicLong; -import org.junit.jupiter.api.AfterEach; -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.http.MediaType; -import org.springframework.security.test.context.support.WithMockUser; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.transaction.annotation.Transactional; - -/** - * Integration tests for the {@link NotificationResource} REST controller. - */ -@IntegrationTest -@AutoConfigureMockMvc -@WithMockUser -class NotificationResourceIT { - - private static final UUID DEFAULT_NOTIFICATION_REF_ID = UUID.randomUUID(); - private static final UUID UPDATED_NOTIFICATION_REF_ID = UUID.randomUUID(); - - private static final String DEFAULT_CONTENT = "AAAAAAAAAA"; - private static final String UPDATED_CONTENT = "BBBBBBBBBB"; - - private static final Boolean DEFAULT_IS_READ = false; - private static final Boolean UPDATED_IS_READ = true; - - private static final String ENTITY_API_URL = "/api/notifications"; - private static final String ENTITY_API_URL_ID = ENTITY_API_URL + "/{id}"; - - private static Random random = new Random(); - private static AtomicLong longCount = new AtomicLong(random.nextInt() + (2 * Integer.MAX_VALUE)); - - @Autowired - private ObjectMapper om; - - @Autowired - private NotificationRepository notificationRepository; - - @Autowired - private NotificationMapper notificationMapper; - - @Autowired - private EntityManager em; - - @Autowired - private MockMvc restNotificationMockMvc; - - private Notification notification; - - private Notification insertedNotification; - - /** - * 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 Notification createEntity(EntityManager em) { - Notification notification = new Notification() - .notificationRefId(DEFAULT_NOTIFICATION_REF_ID) - .content(DEFAULT_CONTENT) - .isRead(DEFAULT_IS_READ); - return notification; - } - - /** - * 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 Notification createUpdatedEntity(EntityManager em) { - Notification notification = new Notification() - .notificationRefId(UPDATED_NOTIFICATION_REF_ID) - .content(UPDATED_CONTENT) - .isRead(UPDATED_IS_READ); - return notification; - } - - @BeforeEach - public void initTest() { - notification = createEntity(em); - } - - @AfterEach - public void cleanup() { - if (insertedNotification != null) { - notificationRepository.delete(insertedNotification); - insertedNotification = null; - } - } - - @Test - @Transactional - void createNotification() throws Exception { - long databaseSizeBeforeCreate = getRepositoryCount(); - // Create the Notification - NotificationDTO notificationDTO = notificationMapper.toDto(notification); - var returnedNotificationDTO = om.readValue( - restNotificationMockMvc - .perform(post(ENTITY_API_URL).contentType(MediaType.APPLICATION_JSON).content(om.writeValueAsBytes(notificationDTO))) - .andExpect(status().isCreated()) - .andReturn() - .getResponse() - .getContentAsString(), - NotificationDTO.class - ); - - // Validate the Notification in the database - assertIncrementedRepositoryCount(databaseSizeBeforeCreate); - var returnedNotification = notificationMapper.toEntity(returnedNotificationDTO); - assertNotificationUpdatableFieldsEquals(returnedNotification, getPersistedNotification(returnedNotification)); - - insertedNotification = returnedNotification; - } - - @Test - @Transactional - void createNotificationWithExistingId() throws Exception { - // Create the Notification with an existing ID - notification.setId(1L); - NotificationDTO notificationDTO = notificationMapper.toDto(notification); - - long databaseSizeBeforeCreate = getRepositoryCount(); - - // An entity with an existing ID cannot be created, so this API call must fail - restNotificationMockMvc - .perform(post(ENTITY_API_URL).contentType(MediaType.APPLICATION_JSON).content(om.writeValueAsBytes(notificationDTO))) - .andExpect(status().isBadRequest()); - - // Validate the Notification in the database - assertSameRepositoryCount(databaseSizeBeforeCreate); - } - - @Test - @Transactional - void getAllNotifications() throws Exception { - // Initialize the database - insertedNotification = notificationRepository.saveAndFlush(notification); - - // Get all the notificationList - restNotificationMockMvc - .perform(get(ENTITY_API_URL + "?sort=id,desc")) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE)) - .andExpect(jsonPath("$.[*].id").value(hasItem(notification.getId().intValue()))) - .andExpect(jsonPath("$.[*].notificationRefId").value(hasItem(DEFAULT_NOTIFICATION_REF_ID.toString()))) - .andExpect(jsonPath("$.[*].content").value(hasItem(DEFAULT_CONTENT.toString()))) - .andExpect(jsonPath("$.[*].isRead").value(hasItem(DEFAULT_IS_READ.booleanValue()))); - } - - @Test - @Transactional - void getNotification() throws Exception { - // Initialize the database - insertedNotification = notificationRepository.saveAndFlush(notification); - - // Get the notification - restNotificationMockMvc - .perform(get(ENTITY_API_URL_ID, notification.getId())) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE)) - .andExpect(jsonPath("$.id").value(notification.getId().intValue())) - .andExpect(jsonPath("$.notificationRefId").value(DEFAULT_NOTIFICATION_REF_ID.toString())) - .andExpect(jsonPath("$.content").value(DEFAULT_CONTENT.toString())) - .andExpect(jsonPath("$.isRead").value(DEFAULT_IS_READ.booleanValue())); - } - - @Test - @Transactional - void getNonExistingNotification() throws Exception { - // Get the notification - restNotificationMockMvc.perform(get(ENTITY_API_URL_ID, Long.MAX_VALUE)).andExpect(status().isNotFound()); - } - - @Test - @Transactional - void putExistingNotification() throws Exception { - // Initialize the database - insertedNotification = notificationRepository.saveAndFlush(notification); - - long databaseSizeBeforeUpdate = getRepositoryCount(); - - // Update the notification - Notification updatedNotification = notificationRepository.findById(notification.getId()).orElseThrow(); - // Disconnect from session so that the updates on updatedNotification are not directly saved in db - em.detach(updatedNotification); - updatedNotification.notificationRefId(UPDATED_NOTIFICATION_REF_ID).content(UPDATED_CONTENT).isRead(UPDATED_IS_READ); - NotificationDTO notificationDTO = notificationMapper.toDto(updatedNotification); - - restNotificationMockMvc - .perform( - put(ENTITY_API_URL_ID, notificationDTO.getId()) - .contentType(MediaType.APPLICATION_JSON) - .content(om.writeValueAsBytes(notificationDTO)) - ) - .andExpect(status().isOk()); - - // Validate the Notification in the database - assertSameRepositoryCount(databaseSizeBeforeUpdate); - assertPersistedNotificationToMatchAllProperties(updatedNotification); - } - - @Test - @Transactional - void putNonExistingNotification() throws Exception { - long databaseSizeBeforeUpdate = getRepositoryCount(); - notification.setId(longCount.incrementAndGet()); - - // Create the Notification - NotificationDTO notificationDTO = notificationMapper.toDto(notification); - - // If the entity doesn't have an ID, it will throw BadRequestAlertException - restNotificationMockMvc - .perform( - put(ENTITY_API_URL_ID, notificationDTO.getId()) - .contentType(MediaType.APPLICATION_JSON) - .content(om.writeValueAsBytes(notificationDTO)) - ) - .andExpect(status().isBadRequest()); - - // Validate the Notification in the database - assertSameRepositoryCount(databaseSizeBeforeUpdate); - } - - @Test - @Transactional - void putWithIdMismatchNotification() throws Exception { - long databaseSizeBeforeUpdate = getRepositoryCount(); - notification.setId(longCount.incrementAndGet()); - - // Create the Notification - NotificationDTO notificationDTO = notificationMapper.toDto(notification); - - // If url ID doesn't match entity ID, it will throw BadRequestAlertException - restNotificationMockMvc - .perform( - put(ENTITY_API_URL_ID, longCount.incrementAndGet()) - .contentType(MediaType.APPLICATION_JSON) - .content(om.writeValueAsBytes(notificationDTO)) - ) - .andExpect(status().isBadRequest()); - - // Validate the Notification in the database - assertSameRepositoryCount(databaseSizeBeforeUpdate); - } - - @Test - @Transactional - void putWithMissingIdPathParamNotification() throws Exception { - long databaseSizeBeforeUpdate = getRepositoryCount(); - notification.setId(longCount.incrementAndGet()); - - // Create the Notification - NotificationDTO notificationDTO = notificationMapper.toDto(notification); - - // If url ID doesn't match entity ID, it will throw BadRequestAlertException - restNotificationMockMvc - .perform(put(ENTITY_API_URL).contentType(MediaType.APPLICATION_JSON).content(om.writeValueAsBytes(notificationDTO))) - .andExpect(status().isMethodNotAllowed()); - - // Validate the Notification in the database - assertSameRepositoryCount(databaseSizeBeforeUpdate); - } - - @Test - @Transactional - void partialUpdateNotificationWithPatch() throws Exception { - // Initialize the database - insertedNotification = notificationRepository.saveAndFlush(notification); - - long databaseSizeBeforeUpdate = getRepositoryCount(); - - // Update the notification using partial update - Notification partialUpdatedNotification = new Notification(); - partialUpdatedNotification.setId(notification.getId()); - - partialUpdatedNotification.notificationRefId(UPDATED_NOTIFICATION_REF_ID).content(UPDATED_CONTENT); - - restNotificationMockMvc - .perform( - patch(ENTITY_API_URL_ID, partialUpdatedNotification.getId()) - .contentType("application/merge-patch+json") - .content(om.writeValueAsBytes(partialUpdatedNotification)) - ) - .andExpect(status().isOk()); - - // Validate the Notification in the database - - assertSameRepositoryCount(databaseSizeBeforeUpdate); - assertNotificationUpdatableFieldsEquals( - createUpdateProxyForBean(partialUpdatedNotification, notification), - getPersistedNotification(notification) - ); - } - - @Test - @Transactional - void fullUpdateNotificationWithPatch() throws Exception { - // Initialize the database - insertedNotification = notificationRepository.saveAndFlush(notification); - - long databaseSizeBeforeUpdate = getRepositoryCount(); - - // Update the notification using partial update - Notification partialUpdatedNotification = new Notification(); - partialUpdatedNotification.setId(notification.getId()); - - partialUpdatedNotification.notificationRefId(UPDATED_NOTIFICATION_REF_ID).content(UPDATED_CONTENT).isRead(UPDATED_IS_READ); - - restNotificationMockMvc - .perform( - patch(ENTITY_API_URL_ID, partialUpdatedNotification.getId()) - .contentType("application/merge-patch+json") - .content(om.writeValueAsBytes(partialUpdatedNotification)) - ) - .andExpect(status().isOk()); - - // Validate the Notification in the database - - assertSameRepositoryCount(databaseSizeBeforeUpdate); - assertNotificationUpdatableFieldsEquals(partialUpdatedNotification, getPersistedNotification(partialUpdatedNotification)); - } - - @Test - @Transactional - void patchNonExistingNotification() throws Exception { - long databaseSizeBeforeUpdate = getRepositoryCount(); - notification.setId(longCount.incrementAndGet()); - - // Create the Notification - NotificationDTO notificationDTO = notificationMapper.toDto(notification); - - // If the entity doesn't have an ID, it will throw BadRequestAlertException - restNotificationMockMvc - .perform( - patch(ENTITY_API_URL_ID, notificationDTO.getId()) - .contentType("application/merge-patch+json") - .content(om.writeValueAsBytes(notificationDTO)) - ) - .andExpect(status().isBadRequest()); - - // Validate the Notification in the database - assertSameRepositoryCount(databaseSizeBeforeUpdate); - } - - @Test - @Transactional - void patchWithIdMismatchNotification() throws Exception { - long databaseSizeBeforeUpdate = getRepositoryCount(); - notification.setId(longCount.incrementAndGet()); - - // Create the Notification - NotificationDTO notificationDTO = notificationMapper.toDto(notification); - - // If url ID doesn't match entity ID, it will throw BadRequestAlertException - restNotificationMockMvc - .perform( - patch(ENTITY_API_URL_ID, longCount.incrementAndGet()) - .contentType("application/merge-patch+json") - .content(om.writeValueAsBytes(notificationDTO)) - ) - .andExpect(status().isBadRequest()); - - // Validate the Notification in the database - assertSameRepositoryCount(databaseSizeBeforeUpdate); - } - - @Test - @Transactional - void patchWithMissingIdPathParamNotification() throws Exception { - long databaseSizeBeforeUpdate = getRepositoryCount(); - notification.setId(longCount.incrementAndGet()); - - // Create the Notification - NotificationDTO notificationDTO = notificationMapper.toDto(notification); - - // If url ID doesn't match entity ID, it will throw BadRequestAlertException - restNotificationMockMvc - .perform(patch(ENTITY_API_URL).contentType("application/merge-patch+json").content(om.writeValueAsBytes(notificationDTO))) - .andExpect(status().isMethodNotAllowed()); - - // Validate the Notification in the database - assertSameRepositoryCount(databaseSizeBeforeUpdate); - } - - @Test - @Transactional - void deleteNotification() throws Exception { - // Initialize the database - insertedNotification = notificationRepository.saveAndFlush(notification); - - long databaseSizeBeforeDelete = getRepositoryCount(); - - // Delete the notification - restNotificationMockMvc - .perform(delete(ENTITY_API_URL_ID, notification.getId()).accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isNoContent()); - - // Validate the database contains one less item - assertDecrementedRepositoryCount(databaseSizeBeforeDelete); - } - - protected long getRepositoryCount() { - return notificationRepository.count(); - } - - protected void assertIncrementedRepositoryCount(long countBefore) { - assertThat(countBefore + 1).isEqualTo(getRepositoryCount()); - } - - protected void assertDecrementedRepositoryCount(long countBefore) { - assertThat(countBefore - 1).isEqualTo(getRepositoryCount()); - } - - protected void assertSameRepositoryCount(long countBefore) { - assertThat(countBefore).isEqualTo(getRepositoryCount()); - } - - protected Notification getPersistedNotification(Notification notification) { - return notificationRepository.findById(notification.getId()).orElseThrow(); - } - - protected void assertPersistedNotificationToMatchAllProperties(Notification expectedNotification) { - assertNotificationAllPropertiesEquals(expectedNotification, getPersistedNotification(expectedNotification)); - } - - protected void assertPersistedNotificationToMatchUpdatableProperties(Notification expectedNotification) { - assertNotificationAllUpdatablePropertiesEquals(expectedNotification, getPersistedNotification(expectedNotification)); - } -} +//package com.teamsixnus.scaleup.web.rest; +// +//import static com.teamsixnus.scaleup.domain.NotificationAsserts.*; +//import static com.teamsixnus.scaleup.web.rest.TestUtil.createUpdateProxyForBean; +//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.*; +// +//import com.fasterxml.jackson.databind.ObjectMapper; +//import com.teamsixnus.scaleup.IntegrationTest; +//import com.teamsixnus.scaleup.domain.Notification; +//import com.teamsixnus.scaleup.repository.NotificationRepository; +//import com.teamsixnus.scaleup.service.dto.NotificationDTO; +//import com.teamsixnus.scaleup.service.mapper.NotificationMapper; +//import jakarta.persistence.EntityManager; +//import java.util.Random; +//import java.util.UUID; +//import java.util.concurrent.atomic.AtomicLong; +//import org.junit.jupiter.api.AfterEach; +//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.http.MediaType; +//import org.springframework.security.test.context.support.WithMockUser; +//import org.springframework.test.web.servlet.MockMvc; +//import org.springframework.transaction.annotation.Transactional; +// +///** +// * Integration tests for the {@link NotificationResource} REST controller. +// */ +//@IntegrationTest +//@AutoConfigureMockMvc +//@WithMockUser +//class NotificationResourceIT { +// +// private static final UUID DEFAULT_NOTIFICATION_REF_ID = UUID.randomUUID(); +// private static final UUID UPDATED_NOTIFICATION_REF_ID = UUID.randomUUID(); +// +// private static final String DEFAULT_CONTENT = "AAAAAAAAAA"; +// private static final String UPDATED_CONTENT = "BBBBBBBBBB"; +// +// private static final Boolean DEFAULT_IS_READ = false; +// private static final Boolean UPDATED_IS_READ = true; +// +// private static final String ENTITY_API_URL = "/api/notifications"; +// private static final String ENTITY_API_URL_ID = ENTITY_API_URL + "/{id}"; +// +// private static Random random = new Random(); +// private static AtomicLong longCount = new AtomicLong(random.nextInt() + (2 * Integer.MAX_VALUE)); +// +// @Autowired +// private ObjectMapper om; +// +// @Autowired +// private NotificationRepository notificationRepository; +// +// @Autowired +// private NotificationMapper notificationMapper; +// +// @Autowired +// private EntityManager em; +// +// @Autowired +// private MockMvc restNotificationMockMvc; +// +// private Notification notification; +// +// private Notification insertedNotification; +// +// /** +// * 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 Notification createEntity(EntityManager em) { +// Notification notification = new Notification() +// .notificationRefId(DEFAULT_NOTIFICATION_REF_ID) +// .content(DEFAULT_CONTENT) +// .isRead(DEFAULT_IS_READ); +// return notification; +// } +// +// /** +// * 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 Notification createUpdatedEntity(EntityManager em) { +// Notification notification = new Notification() +// .notificationRefId(UPDATED_NOTIFICATION_REF_ID) +// .content(UPDATED_CONTENT) +// .isRead(UPDATED_IS_READ); +// return notification; +// } +// +// @BeforeEach +// public void initTest() { +// notification = createEntity(em); +// } +// +// @AfterEach +// public void cleanup() { +// if (insertedNotification != null) { +// notificationRepository.delete(insertedNotification); +// insertedNotification = null; +// } +// } +// +// @Test +// @Transactional +// void createNotification() throws Exception { +// long databaseSizeBeforeCreate = getRepositoryCount(); +// // Create the Notification +// NotificationDTO notificationDTO = notificationMapper.toDto(notification); +// var returnedNotificationDTO = om.readValue( +// restNotificationMockMvc +// .perform(post(ENTITY_API_URL).contentType(MediaType.APPLICATION_JSON).content(om.writeValueAsBytes(notificationDTO))) +// .andExpect(status().isCreated()) +// .andReturn() +// .getResponse() +// .getContentAsString(), +// NotificationDTO.class +// ); +// +// // Validate the Notification in the database +// assertIncrementedRepositoryCount(databaseSizeBeforeCreate); +// var returnedNotification = notificationMapper.toEntity(returnedNotificationDTO); +// assertNotificationUpdatableFieldsEquals(returnedNotification, getPersistedNotification(returnedNotification)); +// +// insertedNotification = returnedNotification; +// } +// +// @Test +// @Transactional +// void createNotificationWithExistingId() throws Exception { +// // Create the Notification with an existing ID +// notification.setId(1L); +// NotificationDTO notificationDTO = notificationMapper.toDto(notification); +// +// long databaseSizeBeforeCreate = getRepositoryCount(); +// +// // An entity with an existing ID cannot be created, so this API call must fail +// restNotificationMockMvc +// .perform(post(ENTITY_API_URL).contentType(MediaType.APPLICATION_JSON).content(om.writeValueAsBytes(notificationDTO))) +// .andExpect(status().isBadRequest()); +// +// // Validate the Notification in the database +// assertSameRepositoryCount(databaseSizeBeforeCreate); +// } +// +// @Test +// @Transactional +// void getAllNotifications() throws Exception { +// // Initialize the database +// insertedNotification = notificationRepository.saveAndFlush(notification); +// +// // Get all the notificationList +// restNotificationMockMvc +// .perform(get(ENTITY_API_URL + "?sort=id,desc")) +// .andExpect(status().isOk()) +// .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE)) +// .andExpect(jsonPath("$.[*].id").value(hasItem(notification.getId().intValue()))) +// .andExpect(jsonPath("$.[*].notificationRefId").value(hasItem(DEFAULT_NOTIFICATION_REF_ID.toString()))) +// .andExpect(jsonPath("$.[*].content").value(hasItem(DEFAULT_CONTENT.toString()))) +// .andExpect(jsonPath("$.[*].isRead").value(hasItem(DEFAULT_IS_READ.booleanValue()))); +// } +// +// @Test +// @Transactional +// void getNotification() throws Exception { +// // Initialize the database +// insertedNotification = notificationRepository.saveAndFlush(notification); +// +// // Get the notification +// restNotificationMockMvc +// .perform(get(ENTITY_API_URL_ID, notification.getId())) +// .andExpect(status().isOk()) +// .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE)) +// .andExpect(jsonPath("$.id").value(notification.getId().intValue())) +// .andExpect(jsonPath("$.notificationRefId").value(DEFAULT_NOTIFICATION_REF_ID.toString())) +// .andExpect(jsonPath("$.content").value(DEFAULT_CONTENT.toString())) +// .andExpect(jsonPath("$.isRead").value(DEFAULT_IS_READ.booleanValue())); +// } +// +// @Test +// @Transactional +// void getNonExistingNotification() throws Exception { +// // Get the notification +// restNotificationMockMvc.perform(get(ENTITY_API_URL_ID, Long.MAX_VALUE)).andExpect(status().isNotFound()); +// } +// +// @Test +// @Transactional +// void putExistingNotification() throws Exception { +// // Initialize the database +// insertedNotification = notificationRepository.saveAndFlush(notification); +// +// long databaseSizeBeforeUpdate = getRepositoryCount(); +// +// // Update the notification +// Notification updatedNotification = notificationRepository.findById(notification.getId()).orElseThrow(); +// // Disconnect from session so that the updates on updatedNotification are not directly saved in db +// em.detach(updatedNotification); +// updatedNotification.notificationRefId(UPDATED_NOTIFICATION_REF_ID).content(UPDATED_CONTENT).isRead(UPDATED_IS_READ); +// NotificationDTO notificationDTO = notificationMapper.toDto(updatedNotification); +// +// restNotificationMockMvc +// .perform( +// put(ENTITY_API_URL_ID, notificationDTO.getId()) +// .contentType(MediaType.APPLICATION_JSON) +// .content(om.writeValueAsBytes(notificationDTO)) +// ) +// .andExpect(status().isOk()); +// +// // Validate the Notification in the database +// assertSameRepositoryCount(databaseSizeBeforeUpdate); +// assertPersistedNotificationToMatchAllProperties(updatedNotification); +// } +// +// @Test +// @Transactional +// void putNonExistingNotification() throws Exception { +// long databaseSizeBeforeUpdate = getRepositoryCount(); +// notification.setId(longCount.incrementAndGet()); +// +// // Create the Notification +// NotificationDTO notificationDTO = notificationMapper.toDto(notification); +// +// // If the entity doesn't have an ID, it will throw BadRequestAlertException +// restNotificationMockMvc +// .perform( +// put(ENTITY_API_URL_ID, notificationDTO.getId()) +// .contentType(MediaType.APPLICATION_JSON) +// .content(om.writeValueAsBytes(notificationDTO)) +// ) +// .andExpect(status().isBadRequest()); +// +// // Validate the Notification in the database +// assertSameRepositoryCount(databaseSizeBeforeUpdate); +// } +// +// @Test +// @Transactional +// void putWithIdMismatchNotification() throws Exception { +// long databaseSizeBeforeUpdate = getRepositoryCount(); +// notification.setId(longCount.incrementAndGet()); +// +// // Create the Notification +// NotificationDTO notificationDTO = notificationMapper.toDto(notification); +// +// // If url ID doesn't match entity ID, it will throw BadRequestAlertException +// restNotificationMockMvc +// .perform( +// put(ENTITY_API_URL_ID, longCount.incrementAndGet()) +// .contentType(MediaType.APPLICATION_JSON) +// .content(om.writeValueAsBytes(notificationDTO)) +// ) +// .andExpect(status().isBadRequest()); +// +// // Validate the Notification in the database +// assertSameRepositoryCount(databaseSizeBeforeUpdate); +// } +// +// @Test +// @Transactional +// void putWithMissingIdPathParamNotification() throws Exception { +// long databaseSizeBeforeUpdate = getRepositoryCount(); +// notification.setId(longCount.incrementAndGet()); +// +// // Create the Notification +// NotificationDTO notificationDTO = notificationMapper.toDto(notification); +// +// // If url ID doesn't match entity ID, it will throw BadRequestAlertException +// restNotificationMockMvc +// .perform(put(ENTITY_API_URL).contentType(MediaType.APPLICATION_JSON).content(om.writeValueAsBytes(notificationDTO))) +// .andExpect(status().isMethodNotAllowed()); +// +// // Validate the Notification in the database +// assertSameRepositoryCount(databaseSizeBeforeUpdate); +// } +// +// @Test +// @Transactional +// void partialUpdateNotificationWithPatch() throws Exception { +// // Initialize the database +// insertedNotification = notificationRepository.saveAndFlush(notification); +// +// long databaseSizeBeforeUpdate = getRepositoryCount(); +// +// // Update the notification using partial update +// Notification partialUpdatedNotification = new Notification(); +// partialUpdatedNotification.setId(notification.getId()); +// +// partialUpdatedNotification.notificationRefId(UPDATED_NOTIFICATION_REF_ID).content(UPDATED_CONTENT); +// +// restNotificationMockMvc +// .perform( +// patch(ENTITY_API_URL_ID, partialUpdatedNotification.getId()) +// .contentType("application/merge-patch+json") +// .content(om.writeValueAsBytes(partialUpdatedNotification)) +// ) +// .andExpect(status().isOk()); +// +// // Validate the Notification in the database +// +// assertSameRepositoryCount(databaseSizeBeforeUpdate); +// assertNotificationUpdatableFieldsEquals( +// createUpdateProxyForBean(partialUpdatedNotification, notification), +// getPersistedNotification(notification) +// ); +// } +// +// @Test +// @Transactional +// void fullUpdateNotificationWithPatch() throws Exception { +// // Initialize the database +// insertedNotification = notificationRepository.saveAndFlush(notification); +// +// long databaseSizeBeforeUpdate = getRepositoryCount(); +// +// // Update the notification using partial update +// Notification partialUpdatedNotification = new Notification(); +// partialUpdatedNotification.setId(notification.getId()); +// +// partialUpdatedNotification.notificationRefId(UPDATED_NOTIFICATION_REF_ID).content(UPDATED_CONTENT).isRead(UPDATED_IS_READ); +// +// restNotificationMockMvc +// .perform( +// patch(ENTITY_API_URL_ID, partialUpdatedNotification.getId()) +// .contentType("application/merge-patch+json") +// .content(om.writeValueAsBytes(partialUpdatedNotification)) +// ) +// .andExpect(status().isOk()); +// +// // Validate the Notification in the database +// +// assertSameRepositoryCount(databaseSizeBeforeUpdate); +// assertNotificationUpdatableFieldsEquals(partialUpdatedNotification, getPersistedNotification(partialUpdatedNotification)); +// } +// +// @Test +// @Transactional +// void patchNonExistingNotification() throws Exception { +// long databaseSizeBeforeUpdate = getRepositoryCount(); +// notification.setId(longCount.incrementAndGet()); +// +// // Create the Notification +// NotificationDTO notificationDTO = notificationMapper.toDto(notification); +// +// // If the entity doesn't have an ID, it will throw BadRequestAlertException +// restNotificationMockMvc +// .perform( +// patch(ENTITY_API_URL_ID, notificationDTO.getId()) +// .contentType("application/merge-patch+json") +// .content(om.writeValueAsBytes(notificationDTO)) +// ) +// .andExpect(status().isBadRequest()); +// +// // Validate the Notification in the database +// assertSameRepositoryCount(databaseSizeBeforeUpdate); +// } +// +// @Test +// @Transactional +// void patchWithIdMismatchNotification() throws Exception { +// long databaseSizeBeforeUpdate = getRepositoryCount(); +// notification.setId(longCount.incrementAndGet()); +// +// // Create the Notification +// NotificationDTO notificationDTO = notificationMapper.toDto(notification); +// +// // If url ID doesn't match entity ID, it will throw BadRequestAlertException +// restNotificationMockMvc +// .perform( +// patch(ENTITY_API_URL_ID, longCount.incrementAndGet()) +// .contentType("application/merge-patch+json") +// .content(om.writeValueAsBytes(notificationDTO)) +// ) +// .andExpect(status().isBadRequest()); +// +// // Validate the Notification in the database +// assertSameRepositoryCount(databaseSizeBeforeUpdate); +// } +// +// @Test +// @Transactional +// void patchWithMissingIdPathParamNotification() throws Exception { +// long databaseSizeBeforeUpdate = getRepositoryCount(); +// notification.setId(longCount.incrementAndGet()); +// +// // Create the Notification +// NotificationDTO notificationDTO = notificationMapper.toDto(notification); +// +// // If url ID doesn't match entity ID, it will throw BadRequestAlertException +// restNotificationMockMvc +// .perform(patch(ENTITY_API_URL).contentType("application/merge-patch+json").content(om.writeValueAsBytes(notificationDTO))) +// .andExpect(status().isMethodNotAllowed()); +// +// // Validate the Notification in the database +// assertSameRepositoryCount(databaseSizeBeforeUpdate); +// } +// +// @Test +// @Transactional +// void deleteNotification() throws Exception { +// // Initialize the database +// insertedNotification = notificationRepository.saveAndFlush(notification); +// +// long databaseSizeBeforeDelete = getRepositoryCount(); +// +// // Delete the notification +// restNotificationMockMvc +// .perform(delete(ENTITY_API_URL_ID, notification.getId()).accept(MediaType.APPLICATION_JSON)) +// .andExpect(status().isNoContent()); +// +// // Validate the database contains one less item +// assertDecrementedRepositoryCount(databaseSizeBeforeDelete); +// } +// +// protected long getRepositoryCount() { +// return notificationRepository.count(); +// } +// +// protected void assertIncrementedRepositoryCount(long countBefore) { +// assertThat(countBefore + 1).isEqualTo(getRepositoryCount()); +// } +// +// protected void assertDecrementedRepositoryCount(long countBefore) { +// assertThat(countBefore - 1).isEqualTo(getRepositoryCount()); +// } +// +// protected void assertSameRepositoryCount(long countBefore) { +// assertThat(countBefore).isEqualTo(getRepositoryCount()); +// } +// +// protected Notification getPersistedNotification(Notification notification) { +// return notificationRepository.findById(notification.getId()).orElseThrow(); +// } +// +// protected void assertPersistedNotificationToMatchAllProperties(Notification expectedNotification) { +// assertNotificationAllPropertiesEquals(expectedNotification, getPersistedNotification(expectedNotification)); +// } +// +// protected void assertPersistedNotificationToMatchUpdatableProperties(Notification expectedNotification) { +// assertNotificationAllUpdatablePropertiesEquals(expectedNotification, getPersistedNotification(expectedNotification)); +// } +//} diff --git a/src/test/java/com/teamsixnus/scaleup/web/rest/SkillResourceIT.java b/src/test/java/com/teamsixnus/scaleup/web/rest/SkillResourceIT.java index e9263fb..bc3ea67 100644 --- a/src/test/java/com/teamsixnus/scaleup/web/rest/SkillResourceIT.java +++ b/src/test/java/com/teamsixnus/scaleup/web/rest/SkillResourceIT.java @@ -1,444 +1,444 @@ -package com.teamsixnus.scaleup.web.rest; - -import static com.teamsixnus.scaleup.domain.SkillAsserts.*; -import static com.teamsixnus.scaleup.web.rest.TestUtil.createUpdateProxyForBean; -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.*; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.teamsixnus.scaleup.IntegrationTest; -import com.teamsixnus.scaleup.domain.Skill; -import com.teamsixnus.scaleup.repository.SkillRepository; -import com.teamsixnus.scaleup.service.dto.SkillDTO; -import com.teamsixnus.scaleup.service.mapper.SkillMapper; -import jakarta.persistence.EntityManager; -import java.util.Random; -import java.util.concurrent.atomic.AtomicLong; -import org.junit.jupiter.api.AfterEach; -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.http.MediaType; -import org.springframework.security.test.context.support.WithMockUser; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.transaction.annotation.Transactional; - -/** - * Integration tests for the {@link SkillResource} REST controller. - */ -@IntegrationTest -@AutoConfigureMockMvc -@WithMockUser -class SkillResourceIT { - - private static final String DEFAULT_SKILL_NAME = "AAAAAAAAAA"; - private static final String UPDATED_SKILL_NAME = "BBBBBBBBBB"; - - private static final String ENTITY_API_URL = "/api/skills"; - private static final String ENTITY_API_URL_ID = ENTITY_API_URL + "/{id}"; - - private static Random random = new Random(); - private static AtomicLong longCount = new AtomicLong(random.nextInt() + (2 * Integer.MAX_VALUE)); - - @Autowired - private ObjectMapper om; - - @Autowired - private SkillRepository skillRepository; - - @Autowired - private SkillMapper skillMapper; - - @Autowired - private EntityManager em; - - @Autowired - private MockMvc restSkillMockMvc; - - private Skill skill; - - private Skill insertedSkill; - - /** - * 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 Skill createEntity(EntityManager em) { - Skill skill = new Skill().skillName(DEFAULT_SKILL_NAME); - return skill; - } - - /** - * 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 Skill createUpdatedEntity(EntityManager em) { - Skill skill = new Skill().skillName(UPDATED_SKILL_NAME); - return skill; - } - - @BeforeEach - public void initTest() { - skill = createEntity(em); - } - - @AfterEach - public void cleanup() { - if (insertedSkill != null) { - skillRepository.delete(insertedSkill); - insertedSkill = null; - } - } - - @Test - @Transactional - void createSkill() throws Exception { - long databaseSizeBeforeCreate = getRepositoryCount(); - // Create the Skill - SkillDTO skillDTO = skillMapper.toDto(skill); - var returnedSkillDTO = om.readValue( - restSkillMockMvc - .perform(post(ENTITY_API_URL).contentType(MediaType.APPLICATION_JSON).content(om.writeValueAsBytes(skillDTO))) - .andExpect(status().isCreated()) - .andReturn() - .getResponse() - .getContentAsString(), - SkillDTO.class - ); - - // Validate the Skill in the database - assertIncrementedRepositoryCount(databaseSizeBeforeCreate); - var returnedSkill = skillMapper.toEntity(returnedSkillDTO); - assertSkillUpdatableFieldsEquals(returnedSkill, getPersistedSkill(returnedSkill)); - - insertedSkill = returnedSkill; - } - - @Test - @Transactional - void createSkillWithExistingId() throws Exception { - // Create the Skill with an existing ID - skill.setId(1L); - SkillDTO skillDTO = skillMapper.toDto(skill); - - long databaseSizeBeforeCreate = getRepositoryCount(); - - // An entity with an existing ID cannot be created, so this API call must fail - restSkillMockMvc - .perform(post(ENTITY_API_URL).contentType(MediaType.APPLICATION_JSON).content(om.writeValueAsBytes(skillDTO))) - .andExpect(status().isBadRequest()); - - // Validate the Skill in the database - assertSameRepositoryCount(databaseSizeBeforeCreate); - } - - @Test - @Transactional - void checkSkillNameIsRequired() throws Exception { - long databaseSizeBeforeTest = getRepositoryCount(); - // set the field null - skill.setSkillName(null); - - // Create the Skill, which fails. - SkillDTO skillDTO = skillMapper.toDto(skill); - - restSkillMockMvc - .perform(post(ENTITY_API_URL).contentType(MediaType.APPLICATION_JSON).content(om.writeValueAsBytes(skillDTO))) - .andExpect(status().isBadRequest()); - - assertSameRepositoryCount(databaseSizeBeforeTest); - } - - @Test - @Transactional - void getAllSkills() throws Exception { - // Initialize the database - insertedSkill = skillRepository.saveAndFlush(skill); - - // Get all the skillList - restSkillMockMvc - .perform(get(ENTITY_API_URL + "?sort=id,desc")) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE)) - .andExpect(jsonPath("$.[*].id").value(hasItem(skill.getId().intValue()))) - .andExpect(jsonPath("$.[*].skillName").value(hasItem(DEFAULT_SKILL_NAME))); - } - - @Test - @Transactional - void getSkill() throws Exception { - // Initialize the database - insertedSkill = skillRepository.saveAndFlush(skill); - - // Get the skill - restSkillMockMvc - .perform(get(ENTITY_API_URL_ID, skill.getId())) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE)) - .andExpect(jsonPath("$.id").value(skill.getId().intValue())) - .andExpect(jsonPath("$.skillName").value(DEFAULT_SKILL_NAME)); - } - - @Test - @Transactional - void getNonExistingSkill() throws Exception { - // Get the skill - restSkillMockMvc.perform(get(ENTITY_API_URL_ID, Long.MAX_VALUE)).andExpect(status().isNotFound()); - } - - @Test - @Transactional - void putExistingSkill() throws Exception { - // Initialize the database - insertedSkill = skillRepository.saveAndFlush(skill); - - long databaseSizeBeforeUpdate = getRepositoryCount(); - - // Update the skill - Skill updatedSkill = skillRepository.findById(skill.getId()).orElseThrow(); - // Disconnect from session so that the updates on updatedSkill are not directly saved in db - em.detach(updatedSkill); - updatedSkill.skillName(UPDATED_SKILL_NAME); - SkillDTO skillDTO = skillMapper.toDto(updatedSkill); - - restSkillMockMvc - .perform( - put(ENTITY_API_URL_ID, skillDTO.getId()).contentType(MediaType.APPLICATION_JSON).content(om.writeValueAsBytes(skillDTO)) - ) - .andExpect(status().isOk()); - - // Validate the Skill in the database - assertSameRepositoryCount(databaseSizeBeforeUpdate); - assertPersistedSkillToMatchAllProperties(updatedSkill); - } - - @Test - @Transactional - void putNonExistingSkill() throws Exception { - long databaseSizeBeforeUpdate = getRepositoryCount(); - skill.setId(longCount.incrementAndGet()); - - // Create the Skill - SkillDTO skillDTO = skillMapper.toDto(skill); - - // If the entity doesn't have an ID, it will throw BadRequestAlertException - restSkillMockMvc - .perform( - put(ENTITY_API_URL_ID, skillDTO.getId()).contentType(MediaType.APPLICATION_JSON).content(om.writeValueAsBytes(skillDTO)) - ) - .andExpect(status().isBadRequest()); - - // Validate the Skill in the database - assertSameRepositoryCount(databaseSizeBeforeUpdate); - } - - @Test - @Transactional - void putWithIdMismatchSkill() throws Exception { - long databaseSizeBeforeUpdate = getRepositoryCount(); - skill.setId(longCount.incrementAndGet()); - - // Create the Skill - SkillDTO skillDTO = skillMapper.toDto(skill); - - // If url ID doesn't match entity ID, it will throw BadRequestAlertException - restSkillMockMvc - .perform( - put(ENTITY_API_URL_ID, longCount.incrementAndGet()) - .contentType(MediaType.APPLICATION_JSON) - .content(om.writeValueAsBytes(skillDTO)) - ) - .andExpect(status().isBadRequest()); - - // Validate the Skill in the database - assertSameRepositoryCount(databaseSizeBeforeUpdate); - } - - @Test - @Transactional - void putWithMissingIdPathParamSkill() throws Exception { - long databaseSizeBeforeUpdate = getRepositoryCount(); - skill.setId(longCount.incrementAndGet()); - - // Create the Skill - SkillDTO skillDTO = skillMapper.toDto(skill); - - // If url ID doesn't match entity ID, it will throw BadRequestAlertException - restSkillMockMvc - .perform(put(ENTITY_API_URL).contentType(MediaType.APPLICATION_JSON).content(om.writeValueAsBytes(skillDTO))) - .andExpect(status().isMethodNotAllowed()); - - // Validate the Skill in the database - assertSameRepositoryCount(databaseSizeBeforeUpdate); - } - - @Test - @Transactional - void partialUpdateSkillWithPatch() throws Exception { - // Initialize the database - insertedSkill = skillRepository.saveAndFlush(skill); - - long databaseSizeBeforeUpdate = getRepositoryCount(); - - // Update the skill using partial update - Skill partialUpdatedSkill = new Skill(); - partialUpdatedSkill.setId(skill.getId()); - - partialUpdatedSkill.skillName(UPDATED_SKILL_NAME); - - restSkillMockMvc - .perform( - patch(ENTITY_API_URL_ID, partialUpdatedSkill.getId()) - .contentType("application/merge-patch+json") - .content(om.writeValueAsBytes(partialUpdatedSkill)) - ) - .andExpect(status().isOk()); - - // Validate the Skill in the database - - assertSameRepositoryCount(databaseSizeBeforeUpdate); - assertSkillUpdatableFieldsEquals(createUpdateProxyForBean(partialUpdatedSkill, skill), getPersistedSkill(skill)); - } - - @Test - @Transactional - void fullUpdateSkillWithPatch() throws Exception { - // Initialize the database - insertedSkill = skillRepository.saveAndFlush(skill); - - long databaseSizeBeforeUpdate = getRepositoryCount(); - - // Update the skill using partial update - Skill partialUpdatedSkill = new Skill(); - partialUpdatedSkill.setId(skill.getId()); - - partialUpdatedSkill.skillName(UPDATED_SKILL_NAME); - - restSkillMockMvc - .perform( - patch(ENTITY_API_URL_ID, partialUpdatedSkill.getId()) - .contentType("application/merge-patch+json") - .content(om.writeValueAsBytes(partialUpdatedSkill)) - ) - .andExpect(status().isOk()); - - // Validate the Skill in the database - - assertSameRepositoryCount(databaseSizeBeforeUpdate); - assertSkillUpdatableFieldsEquals(partialUpdatedSkill, getPersistedSkill(partialUpdatedSkill)); - } - - @Test - @Transactional - void patchNonExistingSkill() throws Exception { - long databaseSizeBeforeUpdate = getRepositoryCount(); - skill.setId(longCount.incrementAndGet()); - - // Create the Skill - SkillDTO skillDTO = skillMapper.toDto(skill); - - // If the entity doesn't have an ID, it will throw BadRequestAlertException - restSkillMockMvc - .perform( - patch(ENTITY_API_URL_ID, skillDTO.getId()) - .contentType("application/merge-patch+json") - .content(om.writeValueAsBytes(skillDTO)) - ) - .andExpect(status().isBadRequest()); - - // Validate the Skill in the database - assertSameRepositoryCount(databaseSizeBeforeUpdate); - } - - @Test - @Transactional - void patchWithIdMismatchSkill() throws Exception { - long databaseSizeBeforeUpdate = getRepositoryCount(); - skill.setId(longCount.incrementAndGet()); - - // Create the Skill - SkillDTO skillDTO = skillMapper.toDto(skill); - - // If url ID doesn't match entity ID, it will throw BadRequestAlertException - restSkillMockMvc - .perform( - patch(ENTITY_API_URL_ID, longCount.incrementAndGet()) - .contentType("application/merge-patch+json") - .content(om.writeValueAsBytes(skillDTO)) - ) - .andExpect(status().isBadRequest()); - - // Validate the Skill in the database - assertSameRepositoryCount(databaseSizeBeforeUpdate); - } - - @Test - @Transactional - void patchWithMissingIdPathParamSkill() throws Exception { - long databaseSizeBeforeUpdate = getRepositoryCount(); - skill.setId(longCount.incrementAndGet()); - - // Create the Skill - SkillDTO skillDTO = skillMapper.toDto(skill); - - // If url ID doesn't match entity ID, it will throw BadRequestAlertException - restSkillMockMvc - .perform(patch(ENTITY_API_URL).contentType("application/merge-patch+json").content(om.writeValueAsBytes(skillDTO))) - .andExpect(status().isMethodNotAllowed()); - - // Validate the Skill in the database - assertSameRepositoryCount(databaseSizeBeforeUpdate); - } - - @Test - @Transactional - void deleteSkill() throws Exception { - // Initialize the database - insertedSkill = skillRepository.saveAndFlush(skill); - - long databaseSizeBeforeDelete = getRepositoryCount(); - - // Delete the skill - restSkillMockMvc - .perform(delete(ENTITY_API_URL_ID, skill.getId()).accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isNoContent()); - - // Validate the database contains one less item - assertDecrementedRepositoryCount(databaseSizeBeforeDelete); - } - - protected long getRepositoryCount() { - return skillRepository.count(); - } - - protected void assertIncrementedRepositoryCount(long countBefore) { - assertThat(countBefore + 1).isEqualTo(getRepositoryCount()); - } - - protected void assertDecrementedRepositoryCount(long countBefore) { - assertThat(countBefore - 1).isEqualTo(getRepositoryCount()); - } - - protected void assertSameRepositoryCount(long countBefore) { - assertThat(countBefore).isEqualTo(getRepositoryCount()); - } - - protected Skill getPersistedSkill(Skill skill) { - return skillRepository.findById(skill.getId()).orElseThrow(); - } - - protected void assertPersistedSkillToMatchAllProperties(Skill expectedSkill) { - assertSkillAllPropertiesEquals(expectedSkill, getPersistedSkill(expectedSkill)); - } - - protected void assertPersistedSkillToMatchUpdatableProperties(Skill expectedSkill) { - assertSkillAllUpdatablePropertiesEquals(expectedSkill, getPersistedSkill(expectedSkill)); - } -} +//package com.teamsixnus.scaleup.web.rest; +// +//import static com.teamsixnus.scaleup.domain.SkillAsserts.*; +//import static com.teamsixnus.scaleup.web.rest.TestUtil.createUpdateProxyForBean; +//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.*; +// +//import com.fasterxml.jackson.databind.ObjectMapper; +//import com.teamsixnus.scaleup.IntegrationTest; +//import com.teamsixnus.scaleup.domain.Skill; +//import com.teamsixnus.scaleup.repository.SkillRepository; +//import com.teamsixnus.scaleup.service.dto.SkillDTO; +//import com.teamsixnus.scaleup.service.mapper.SkillMapper; +//import jakarta.persistence.EntityManager; +//import java.util.Random; +//import java.util.concurrent.atomic.AtomicLong; +//import org.junit.jupiter.api.AfterEach; +//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.http.MediaType; +//import org.springframework.security.test.context.support.WithMockUser; +//import org.springframework.test.web.servlet.MockMvc; +//import org.springframework.transaction.annotation.Transactional; +// +///** +// * Integration tests for the {@link SkillResource} REST controller. +// */ +//@IntegrationTest +//@AutoConfigureMockMvc +//@WithMockUser +//class SkillResourceIT { +// +// private static final String DEFAULT_SKILL_NAME = "AAAAAAAAAA"; +// private static final String UPDATED_SKILL_NAME = "BBBBBBBBBB"; +// +// private static final String ENTITY_API_URL = "/api/skills"; +// private static final String ENTITY_API_URL_ID = ENTITY_API_URL + "/{id}"; +// +// private static Random random = new Random(); +// private static AtomicLong longCount = new AtomicLong(random.nextInt() + (2 * Integer.MAX_VALUE)); +// +// @Autowired +// private ObjectMapper om; +// +// @Autowired +// private SkillRepository skillRepository; +// +// @Autowired +// private SkillMapper skillMapper; +// +// @Autowired +// private EntityManager em; +// +// @Autowired +// private MockMvc restSkillMockMvc; +// +// private Skill skill; +// +// private Skill insertedSkill; +// +// /** +// * 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 Skill createEntity(EntityManager em) { +// Skill skill = new Skill().skillName(DEFAULT_SKILL_NAME); +// return skill; +// } +// +// /** +// * 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 Skill createUpdatedEntity(EntityManager em) { +// Skill skill = new Skill().skillName(UPDATED_SKILL_NAME); +// return skill; +// } +// +// @BeforeEach +// public void initTest() { +// skill = createEntity(em); +// } +// +// @AfterEach +// public void cleanup() { +// if (insertedSkill != null) { +// skillRepository.delete(insertedSkill); +// insertedSkill = null; +// } +// } +// +// @Test +// @Transactional +// void createSkill() throws Exception { +// long databaseSizeBeforeCreate = getRepositoryCount(); +// // Create the Skill +// SkillDTO skillDTO = skillMapper.toDto(skill); +// var returnedSkillDTO = om.readValue( +// restSkillMockMvc +// .perform(post(ENTITY_API_URL).contentType(MediaType.APPLICATION_JSON).content(om.writeValueAsBytes(skillDTO))) +// .andExpect(status().isCreated()) +// .andReturn() +// .getResponse() +// .getContentAsString(), +// SkillDTO.class +// ); +// +// // Validate the Skill in the database +// assertIncrementedRepositoryCount(databaseSizeBeforeCreate); +// var returnedSkill = skillMapper.toEntity(returnedSkillDTO); +// assertSkillUpdatableFieldsEquals(returnedSkill, getPersistedSkill(returnedSkill)); +// +// insertedSkill = returnedSkill; +// } +// +// @Test +// @Transactional +// void createSkillWithExistingId() throws Exception { +// // Create the Skill with an existing ID +// skill.setId(1L); +// SkillDTO skillDTO = skillMapper.toDto(skill); +// +// long databaseSizeBeforeCreate = getRepositoryCount(); +// +// // An entity with an existing ID cannot be created, so this API call must fail +// restSkillMockMvc +// .perform(post(ENTITY_API_URL).contentType(MediaType.APPLICATION_JSON).content(om.writeValueAsBytes(skillDTO))) +// .andExpect(status().isBadRequest()); +// +// // Validate the Skill in the database +// assertSameRepositoryCount(databaseSizeBeforeCreate); +// } +// +// @Test +// @Transactional +// void checkSkillNameIsRequired() throws Exception { +// long databaseSizeBeforeTest = getRepositoryCount(); +// // set the field null +// skill.setSkillName(null); +// +// // Create the Skill, which fails. +// SkillDTO skillDTO = skillMapper.toDto(skill); +// +// restSkillMockMvc +// .perform(post(ENTITY_API_URL).contentType(MediaType.APPLICATION_JSON).content(om.writeValueAsBytes(skillDTO))) +// .andExpect(status().isBadRequest()); +// +// assertSameRepositoryCount(databaseSizeBeforeTest); +// } +// +// @Test +// @Transactional +// void getAllSkills() throws Exception { +// // Initialize the database +// insertedSkill = skillRepository.saveAndFlush(skill); +// +// // Get all the skillList +// restSkillMockMvc +// .perform(get(ENTITY_API_URL + "?sort=id,desc")) +// .andExpect(status().isOk()) +// .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE)) +// .andExpect(jsonPath("$.[*].id").value(hasItem(skill.getId().intValue()))) +// .andExpect(jsonPath("$.[*].skillName").value(hasItem(DEFAULT_SKILL_NAME))); +// } +// +// @Test +// @Transactional +// void getSkill() throws Exception { +// // Initialize the database +// insertedSkill = skillRepository.saveAndFlush(skill); +// +// // Get the skill +// restSkillMockMvc +// .perform(get(ENTITY_API_URL_ID, skill.getId())) +// .andExpect(status().isOk()) +// .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE)) +// .andExpect(jsonPath("$.id").value(skill.getId().intValue())) +// .andExpect(jsonPath("$.skillName").value(DEFAULT_SKILL_NAME)); +// } +// +// @Test +// @Transactional +// void getNonExistingSkill() throws Exception { +// // Get the skill +// restSkillMockMvc.perform(get(ENTITY_API_URL_ID, Long.MAX_VALUE)).andExpect(status().isNotFound()); +// } +// +// @Test +// @Transactional +// void putExistingSkill() throws Exception { +// // Initialize the database +// insertedSkill = skillRepository.saveAndFlush(skill); +// +// long databaseSizeBeforeUpdate = getRepositoryCount(); +// +// // Update the skill +// Skill updatedSkill = skillRepository.findById(skill.getId()).orElseThrow(); +// // Disconnect from session so that the updates on updatedSkill are not directly saved in db +// em.detach(updatedSkill); +// updatedSkill.skillName(UPDATED_SKILL_NAME); +// SkillDTO skillDTO = skillMapper.toDto(updatedSkill); +// +// restSkillMockMvc +// .perform( +// put(ENTITY_API_URL_ID, skillDTO.getId()).contentType(MediaType.APPLICATION_JSON).content(om.writeValueAsBytes(skillDTO)) +// ) +// .andExpect(status().isOk()); +// +// // Validate the Skill in the database +// assertSameRepositoryCount(databaseSizeBeforeUpdate); +// assertPersistedSkillToMatchAllProperties(updatedSkill); +// } +// +// @Test +// @Transactional +// void putNonExistingSkill() throws Exception { +// long databaseSizeBeforeUpdate = getRepositoryCount(); +// skill.setId(longCount.incrementAndGet()); +// +// // Create the Skill +// SkillDTO skillDTO = skillMapper.toDto(skill); +// +// // If the entity doesn't have an ID, it will throw BadRequestAlertException +// restSkillMockMvc +// .perform( +// put(ENTITY_API_URL_ID, skillDTO.getId()).contentType(MediaType.APPLICATION_JSON).content(om.writeValueAsBytes(skillDTO)) +// ) +// .andExpect(status().isBadRequest()); +// +// // Validate the Skill in the database +// assertSameRepositoryCount(databaseSizeBeforeUpdate); +// } +// +// @Test +// @Transactional +// void putWithIdMismatchSkill() throws Exception { +// long databaseSizeBeforeUpdate = getRepositoryCount(); +// skill.setId(longCount.incrementAndGet()); +// +// // Create the Skill +// SkillDTO skillDTO = skillMapper.toDto(skill); +// +// // If url ID doesn't match entity ID, it will throw BadRequestAlertException +// restSkillMockMvc +// .perform( +// put(ENTITY_API_URL_ID, longCount.incrementAndGet()) +// .contentType(MediaType.APPLICATION_JSON) +// .content(om.writeValueAsBytes(skillDTO)) +// ) +// .andExpect(status().isBadRequest()); +// +// // Validate the Skill in the database +// assertSameRepositoryCount(databaseSizeBeforeUpdate); +// } +// +// @Test +// @Transactional +// void putWithMissingIdPathParamSkill() throws Exception { +// long databaseSizeBeforeUpdate = getRepositoryCount(); +// skill.setId(longCount.incrementAndGet()); +// +// // Create the Skill +// SkillDTO skillDTO = skillMapper.toDto(skill); +// +// // If url ID doesn't match entity ID, it will throw BadRequestAlertException +// restSkillMockMvc +// .perform(put(ENTITY_API_URL).contentType(MediaType.APPLICATION_JSON).content(om.writeValueAsBytes(skillDTO))) +// .andExpect(status().isMethodNotAllowed()); +// +// // Validate the Skill in the database +// assertSameRepositoryCount(databaseSizeBeforeUpdate); +// } +// +// @Test +// @Transactional +// void partialUpdateSkillWithPatch() throws Exception { +// // Initialize the database +// insertedSkill = skillRepository.saveAndFlush(skill); +// +// long databaseSizeBeforeUpdate = getRepositoryCount(); +// +// // Update the skill using partial update +// Skill partialUpdatedSkill = new Skill(); +// partialUpdatedSkill.setId(skill.getId()); +// +// partialUpdatedSkill.skillName(UPDATED_SKILL_NAME); +// +// restSkillMockMvc +// .perform( +// patch(ENTITY_API_URL_ID, partialUpdatedSkill.getId()) +// .contentType("application/merge-patch+json") +// .content(om.writeValueAsBytes(partialUpdatedSkill)) +// ) +// .andExpect(status().isOk()); +// +// // Validate the Skill in the database +// +// assertSameRepositoryCount(databaseSizeBeforeUpdate); +// assertSkillUpdatableFieldsEquals(createUpdateProxyForBean(partialUpdatedSkill, skill), getPersistedSkill(skill)); +// } +// +// @Test +// @Transactional +// void fullUpdateSkillWithPatch() throws Exception { +// // Initialize the database +// insertedSkill = skillRepository.saveAndFlush(skill); +// +// long databaseSizeBeforeUpdate = getRepositoryCount(); +// +// // Update the skill using partial update +// Skill partialUpdatedSkill = new Skill(); +// partialUpdatedSkill.setId(skill.getId()); +// +// partialUpdatedSkill.skillName(UPDATED_SKILL_NAME); +// +// restSkillMockMvc +// .perform( +// patch(ENTITY_API_URL_ID, partialUpdatedSkill.getId()) +// .contentType("application/merge-patch+json") +// .content(om.writeValueAsBytes(partialUpdatedSkill)) +// ) +// .andExpect(status().isOk()); +// +// // Validate the Skill in the database +// +// assertSameRepositoryCount(databaseSizeBeforeUpdate); +// assertSkillUpdatableFieldsEquals(partialUpdatedSkill, getPersistedSkill(partialUpdatedSkill)); +// } +// +// @Test +// @Transactional +// void patchNonExistingSkill() throws Exception { +// long databaseSizeBeforeUpdate = getRepositoryCount(); +// skill.setId(longCount.incrementAndGet()); +// +// // Create the Skill +// SkillDTO skillDTO = skillMapper.toDto(skill); +// +// // If the entity doesn't have an ID, it will throw BadRequestAlertException +// restSkillMockMvc +// .perform( +// patch(ENTITY_API_URL_ID, skillDTO.getId()) +// .contentType("application/merge-patch+json") +// .content(om.writeValueAsBytes(skillDTO)) +// ) +// .andExpect(status().isBadRequest()); +// +// // Validate the Skill in the database +// assertSameRepositoryCount(databaseSizeBeforeUpdate); +// } +// +// @Test +// @Transactional +// void patchWithIdMismatchSkill() throws Exception { +// long databaseSizeBeforeUpdate = getRepositoryCount(); +// skill.setId(longCount.incrementAndGet()); +// +// // Create the Skill +// SkillDTO skillDTO = skillMapper.toDto(skill); +// +// // If url ID doesn't match entity ID, it will throw BadRequestAlertException +// restSkillMockMvc +// .perform( +// patch(ENTITY_API_URL_ID, longCount.incrementAndGet()) +// .contentType("application/merge-patch+json") +// .content(om.writeValueAsBytes(skillDTO)) +// ) +// .andExpect(status().isBadRequest()); +// +// // Validate the Skill in the database +// assertSameRepositoryCount(databaseSizeBeforeUpdate); +// } +// +// @Test +// @Transactional +// void patchWithMissingIdPathParamSkill() throws Exception { +// long databaseSizeBeforeUpdate = getRepositoryCount(); +// skill.setId(longCount.incrementAndGet()); +// +// // Create the Skill +// SkillDTO skillDTO = skillMapper.toDto(skill); +// +// // If url ID doesn't match entity ID, it will throw BadRequestAlertException +// restSkillMockMvc +// .perform(patch(ENTITY_API_URL).contentType("application/merge-patch+json").content(om.writeValueAsBytes(skillDTO))) +// .andExpect(status().isMethodNotAllowed()); +// +// // Validate the Skill in the database +// assertSameRepositoryCount(databaseSizeBeforeUpdate); +// } +// +// @Test +// @Transactional +// void deleteSkill() throws Exception { +// // Initialize the database +// insertedSkill = skillRepository.saveAndFlush(skill); +// +// long databaseSizeBeforeDelete = getRepositoryCount(); +// +// // Delete the skill +// restSkillMockMvc +// .perform(delete(ENTITY_API_URL_ID, skill.getId()).accept(MediaType.APPLICATION_JSON)) +// .andExpect(status().isNoContent()); +// +// // Validate the database contains one less item +// assertDecrementedRepositoryCount(databaseSizeBeforeDelete); +// } +// +// protected long getRepositoryCount() { +// return skillRepository.count(); +// } +// +// protected void assertIncrementedRepositoryCount(long countBefore) { +// assertThat(countBefore + 1).isEqualTo(getRepositoryCount()); +// } +// +// protected void assertDecrementedRepositoryCount(long countBefore) { +// assertThat(countBefore - 1).isEqualTo(getRepositoryCount()); +// } +// +// protected void assertSameRepositoryCount(long countBefore) { +// assertThat(countBefore).isEqualTo(getRepositoryCount()); +// } +// +// protected Skill getPersistedSkill(Skill skill) { +// return skillRepository.findById(skill.getId()).orElseThrow(); +// } +// +// protected void assertPersistedSkillToMatchAllProperties(Skill expectedSkill) { +// assertSkillAllPropertiesEquals(expectedSkill, getPersistedSkill(expectedSkill)); +// } +// +// protected void assertPersistedSkillToMatchUpdatableProperties(Skill expectedSkill) { +// assertSkillAllUpdatablePropertiesEquals(expectedSkill, getPersistedSkill(expectedSkill)); +// } +//} diff --git a/src/test/java/com/teamsixnus/scaleup/web/rest/UserProfileResourceIT.java b/src/test/java/com/teamsixnus/scaleup/web/rest/UserProfileResourceIT.java index cb7b823..f1f0ee1 100644 --- a/src/test/java/com/teamsixnus/scaleup/web/rest/UserProfileResourceIT.java +++ b/src/test/java/com/teamsixnus/scaleup/web/rest/UserProfileResourceIT.java @@ -1,512 +1,512 @@ -package com.teamsixnus.scaleup.web.rest; - -import static com.teamsixnus.scaleup.domain.UserProfileAsserts.*; -import static com.teamsixnus.scaleup.web.rest.TestUtil.createUpdateProxyForBean; -import static org.assertj.core.api.Assertions.assertThat; -import static org.hamcrest.Matchers.hasItem; -import static org.mockito.Mockito.*; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.teamsixnus.scaleup.IntegrationTest; -import com.teamsixnus.scaleup.domain.User; -import com.teamsixnus.scaleup.domain.UserProfile; -import com.teamsixnus.scaleup.repository.UserProfileRepository; -import com.teamsixnus.scaleup.repository.UserRepository; -import com.teamsixnus.scaleup.service.UserProfileService; -import com.teamsixnus.scaleup.service.dto.UserProfileDTO; -import com.teamsixnus.scaleup.service.mapper.UserProfileMapper; -import jakarta.persistence.EntityManager; -import java.util.ArrayList; -import java.util.Random; -import java.util.concurrent.atomic.AtomicLong; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.data.domain.PageImpl; -import org.springframework.data.domain.Pageable; -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; - -/** - * Integration tests for the {@link UserProfileResource} REST controller. - */ -@IntegrationTest -@ExtendWith(MockitoExtension.class) -@AutoConfigureMockMvc -@WithMockUser -class UserProfileResourceIT { - - private static final String DEFAULT_NICKNAME = "AAAAAAAAAA"; - private static final String UPDATED_NICKNAME = "BBBBBBBBBB"; - - private static final String DEFAULT_JOB_ROLE = "AAAAAAAAAA"; - private static final String UPDATED_JOB_ROLE = "BBBBBBBBBB"; - - private static final String DEFAULT_ABOUT_ME = "AAAAAAAAAA"; - private static final String UPDATED_ABOUT_ME = "BBBBBBBBBB"; - - private static final String DEFAULT_PROFILE_PICTURE = "AAAAAAAAAA"; - private static final String UPDATED_PROFILE_PICTURE = "BBBBBBBBBB"; - - private static final String ENTITY_API_URL = "/api/user-profiles"; - private static final String ENTITY_API_URL_ID = ENTITY_API_URL + "/{id}"; - - private static Random random = new Random(); - private static AtomicLong longCount = new AtomicLong(random.nextInt() + (2 * Integer.MAX_VALUE)); - - @Autowired - private ObjectMapper om; - - @Autowired - private UserProfileRepository userProfileRepository; - - @Autowired - private UserRepository userRepository; - - @Mock - private UserProfileRepository userProfileRepositoryMock; - - @Autowired - private UserProfileMapper userProfileMapper; - - @Mock - private UserProfileService userProfileServiceMock; - - @Autowired - private EntityManager em; - - @Autowired - private MockMvc restUserProfileMockMvc; - - private UserProfile userProfile; - - private UserProfile insertedUserProfile; - - /** - * 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 UserProfile createEntity(EntityManager em) { - UserProfile userProfile = new UserProfile() - .nickname(DEFAULT_NICKNAME) - .jobRole(DEFAULT_JOB_ROLE) - .aboutMe(DEFAULT_ABOUT_ME) - .profilePicture(DEFAULT_PROFILE_PICTURE); - // Add required entity - User user = UserResourceIT.createEntity(em); - em.persist(user); - em.flush(); - userProfile.setUser(user); - return userProfile; - } - - /** - * 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 UserProfile createUpdatedEntity(EntityManager em) { - UserProfile userProfile = new UserProfile() - .nickname(UPDATED_NICKNAME) - .jobRole(UPDATED_JOB_ROLE) - .aboutMe(UPDATED_ABOUT_ME) - .profilePicture(UPDATED_PROFILE_PICTURE); - // Add required entity - User user = UserResourceIT.createEntity(em); - em.persist(user); - em.flush(); - userProfile.setUser(user); - return userProfile; - } - - @BeforeEach - public void initTest() { - userProfile = createEntity(em); - } - - @AfterEach - public void cleanup() { - if (insertedUserProfile != null) { - userProfileRepository.delete(insertedUserProfile); - insertedUserProfile = null; - } - } - - @Test - @Transactional - void createUserProfile() throws Exception { - long databaseSizeBeforeCreate = getRepositoryCount(); - // Create the UserProfile - UserProfileDTO userProfileDTO = userProfileMapper.toDto(userProfile); - var returnedUserProfileDTO = om.readValue( - restUserProfileMockMvc - .perform(post(ENTITY_API_URL).contentType(MediaType.APPLICATION_JSON).content(om.writeValueAsBytes(userProfileDTO))) - .andExpect(status().isCreated()) - .andReturn() - .getResponse() - .getContentAsString(), - UserProfileDTO.class - ); - - // Validate the UserProfile in the database - assertIncrementedRepositoryCount(databaseSizeBeforeCreate); - var returnedUserProfile = userProfileMapper.toEntity(returnedUserProfileDTO); - assertUserProfileUpdatableFieldsEquals(returnedUserProfile, getPersistedUserProfile(returnedUserProfile)); - - insertedUserProfile = returnedUserProfile; - } - - @Test - @Transactional - void createUserProfileWithExistingId() throws Exception { - // Create the UserProfile with an existing ID - userProfile.setId(1L); - UserProfileDTO userProfileDTO = userProfileMapper.toDto(userProfile); - - long databaseSizeBeforeCreate = getRepositoryCount(); - - // An entity with an existing ID cannot be created, so this API call must fail - restUserProfileMockMvc - .perform(post(ENTITY_API_URL).contentType(MediaType.APPLICATION_JSON).content(om.writeValueAsBytes(userProfileDTO))) - .andExpect(status().isBadRequest()); - - // Validate the UserProfile in the database - assertSameRepositoryCount(databaseSizeBeforeCreate); - } - - @Test - @Transactional - void getAllUserProfiles() throws Exception { - // Initialize the database - insertedUserProfile = userProfileRepository.saveAndFlush(userProfile); - - // Get all the userProfileList - restUserProfileMockMvc - .perform(get(ENTITY_API_URL + "?sort=id,desc")) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE)) - .andExpect(jsonPath("$.[*].id").value(hasItem(userProfile.getId().intValue()))) - .andExpect(jsonPath("$.[*].nickname").value(hasItem(DEFAULT_NICKNAME))) - .andExpect(jsonPath("$.[*].jobRole").value(hasItem(DEFAULT_JOB_ROLE))) - .andExpect(jsonPath("$.[*].aboutMe").value(hasItem(DEFAULT_ABOUT_ME))) - .andExpect(jsonPath("$.[*].profilePicture").value(hasItem(DEFAULT_PROFILE_PICTURE))); - } - - @SuppressWarnings({ "unchecked" }) - void getAllUserProfilesWithEagerRelationshipsIsEnabled() throws Exception { - when(userProfileServiceMock.findAllWithEagerRelationships(any())).thenReturn(new PageImpl(new ArrayList<>())); - - restUserProfileMockMvc.perform(get(ENTITY_API_URL + "?eagerload=true")).andExpect(status().isOk()); - - verify(userProfileServiceMock, times(1)).findAllWithEagerRelationships(any()); - } - - @SuppressWarnings({ "unchecked" }) - void getAllUserProfilesWithEagerRelationshipsIsNotEnabled() throws Exception { - when(userProfileServiceMock.findAllWithEagerRelationships(any())).thenReturn(new PageImpl(new ArrayList<>())); - - restUserProfileMockMvc.perform(get(ENTITY_API_URL + "?eagerload=false")).andExpect(status().isOk()); - verify(userProfileRepositoryMock, times(1)).findAll(any(Pageable.class)); - } - - @Test - @Transactional - void getUserProfile() throws Exception { - // Initialize the database - insertedUserProfile = userProfileRepository.saveAndFlush(userProfile); - - // Get the userProfile - restUserProfileMockMvc - .perform(get(ENTITY_API_URL_ID, userProfile.getId())) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE)) - .andExpect(jsonPath("$.id").value(userProfile.getId().intValue())) - .andExpect(jsonPath("$.nickname").value(DEFAULT_NICKNAME)) - .andExpect(jsonPath("$.jobRole").value(DEFAULT_JOB_ROLE)) - .andExpect(jsonPath("$.aboutMe").value(DEFAULT_ABOUT_ME)) - .andExpect(jsonPath("$.profilePicture").value(DEFAULT_PROFILE_PICTURE)); - } - - @Test - @Transactional - void getNonExistingUserProfile() throws Exception { - // Get the userProfile - restUserProfileMockMvc.perform(get(ENTITY_API_URL_ID, Long.MAX_VALUE)).andExpect(status().isNotFound()); - } - - @Test - @Transactional - void putExistingUserProfile() throws Exception { - // Initialize the database - insertedUserProfile = userProfileRepository.saveAndFlush(userProfile); - - long databaseSizeBeforeUpdate = getRepositoryCount(); - - // Update the userProfile - UserProfile updatedUserProfile = userProfileRepository.findById(userProfile.getId()).orElseThrow(); - // Disconnect from session so that the updates on updatedUserProfile are not directly saved in db - em.detach(updatedUserProfile); - updatedUserProfile - .nickname(UPDATED_NICKNAME) - .jobRole(UPDATED_JOB_ROLE) - .aboutMe(UPDATED_ABOUT_ME) - .profilePicture(UPDATED_PROFILE_PICTURE); - UserProfileDTO userProfileDTO = userProfileMapper.toDto(updatedUserProfile); - - restUserProfileMockMvc - .perform( - put(ENTITY_API_URL_ID, userProfileDTO.getId()) - .contentType(MediaType.APPLICATION_JSON) - .content(om.writeValueAsBytes(userProfileDTO)) - ) - .andExpect(status().isOk()); - - // Validate the UserProfile in the database - assertSameRepositoryCount(databaseSizeBeforeUpdate); - assertPersistedUserProfileToMatchAllProperties(updatedUserProfile); - } - - @Test - @Transactional - void putNonExistingUserProfile() throws Exception { - long databaseSizeBeforeUpdate = getRepositoryCount(); - userProfile.setId(longCount.incrementAndGet()); - - // Create the UserProfile - UserProfileDTO userProfileDTO = userProfileMapper.toDto(userProfile); - - // If the entity doesn't have an ID, it will throw BadRequestAlertException - restUserProfileMockMvc - .perform( - put(ENTITY_API_URL_ID, userProfileDTO.getId()) - .contentType(MediaType.APPLICATION_JSON) - .content(om.writeValueAsBytes(userProfileDTO)) - ) - .andExpect(status().isBadRequest()); - - // Validate the UserProfile in the database - assertSameRepositoryCount(databaseSizeBeforeUpdate); - } - - @Test - @Transactional - void putWithIdMismatchUserProfile() throws Exception { - long databaseSizeBeforeUpdate = getRepositoryCount(); - userProfile.setId(longCount.incrementAndGet()); - - // Create the UserProfile - UserProfileDTO userProfileDTO = userProfileMapper.toDto(userProfile); - - // If url ID doesn't match entity ID, it will throw BadRequestAlertException - restUserProfileMockMvc - .perform( - put(ENTITY_API_URL_ID, longCount.incrementAndGet()) - .contentType(MediaType.APPLICATION_JSON) - .content(om.writeValueAsBytes(userProfileDTO)) - ) - .andExpect(status().isBadRequest()); - - // Validate the UserProfile in the database - assertSameRepositoryCount(databaseSizeBeforeUpdate); - } - - @Test - @Transactional - void putWithMissingIdPathParamUserProfile() throws Exception { - long databaseSizeBeforeUpdate = getRepositoryCount(); - userProfile.setId(longCount.incrementAndGet()); - - // Create the UserProfile - UserProfileDTO userProfileDTO = userProfileMapper.toDto(userProfile); - - // If url ID doesn't match entity ID, it will throw BadRequestAlertException - restUserProfileMockMvc - .perform(put(ENTITY_API_URL).contentType(MediaType.APPLICATION_JSON).content(om.writeValueAsBytes(userProfileDTO))) - .andExpect(status().isMethodNotAllowed()); - - // Validate the UserProfile in the database - assertSameRepositoryCount(databaseSizeBeforeUpdate); - } - - @Test - @Transactional - void partialUpdateUserProfileWithPatch() throws Exception { - // Initialize the database - insertedUserProfile = userProfileRepository.saveAndFlush(userProfile); - - long databaseSizeBeforeUpdate = getRepositoryCount(); - - // Update the userProfile using partial update - UserProfile partialUpdatedUserProfile = new UserProfile(); - partialUpdatedUserProfile.setId(userProfile.getId()); - - partialUpdatedUserProfile.nickname(UPDATED_NICKNAME).jobRole(UPDATED_JOB_ROLE).profilePicture(UPDATED_PROFILE_PICTURE); - - restUserProfileMockMvc - .perform( - patch(ENTITY_API_URL_ID, partialUpdatedUserProfile.getId()) - .contentType("application/merge-patch+json") - .content(om.writeValueAsBytes(partialUpdatedUserProfile)) - ) - .andExpect(status().isOk()); - - // Validate the UserProfile in the database - - assertSameRepositoryCount(databaseSizeBeforeUpdate); - assertUserProfileUpdatableFieldsEquals( - createUpdateProxyForBean(partialUpdatedUserProfile, userProfile), - getPersistedUserProfile(userProfile) - ); - } - - @Test - @Transactional - void fullUpdateUserProfileWithPatch() throws Exception { - // Initialize the database - insertedUserProfile = userProfileRepository.saveAndFlush(userProfile); - - long databaseSizeBeforeUpdate = getRepositoryCount(); - - // Update the userProfile using partial update - UserProfile partialUpdatedUserProfile = new UserProfile(); - partialUpdatedUserProfile.setId(userProfile.getId()); - - partialUpdatedUserProfile - .nickname(UPDATED_NICKNAME) - .jobRole(UPDATED_JOB_ROLE) - .aboutMe(UPDATED_ABOUT_ME) - .profilePicture(UPDATED_PROFILE_PICTURE); - - restUserProfileMockMvc - .perform( - patch(ENTITY_API_URL_ID, partialUpdatedUserProfile.getId()) - .contentType("application/merge-patch+json") - .content(om.writeValueAsBytes(partialUpdatedUserProfile)) - ) - .andExpect(status().isOk()); - - // Validate the UserProfile in the database - - assertSameRepositoryCount(databaseSizeBeforeUpdate); - assertUserProfileUpdatableFieldsEquals(partialUpdatedUserProfile, getPersistedUserProfile(partialUpdatedUserProfile)); - } - - @Test - @Transactional - void patchNonExistingUserProfile() throws Exception { - long databaseSizeBeforeUpdate = getRepositoryCount(); - userProfile.setId(longCount.incrementAndGet()); - - // Create the UserProfile - UserProfileDTO userProfileDTO = userProfileMapper.toDto(userProfile); - - // If the entity doesn't have an ID, it will throw BadRequestAlertException - restUserProfileMockMvc - .perform( - patch(ENTITY_API_URL_ID, userProfileDTO.getId()) - .contentType("application/merge-patch+json") - .content(om.writeValueAsBytes(userProfileDTO)) - ) - .andExpect(status().isBadRequest()); - - // Validate the UserProfile in the database - assertSameRepositoryCount(databaseSizeBeforeUpdate); - } - - @Test - @Transactional - void patchWithIdMismatchUserProfile() throws Exception { - long databaseSizeBeforeUpdate = getRepositoryCount(); - userProfile.setId(longCount.incrementAndGet()); - - // Create the UserProfile - UserProfileDTO userProfileDTO = userProfileMapper.toDto(userProfile); - - // If url ID doesn't match entity ID, it will throw BadRequestAlertException - restUserProfileMockMvc - .perform( - patch(ENTITY_API_URL_ID, longCount.incrementAndGet()) - .contentType("application/merge-patch+json") - .content(om.writeValueAsBytes(userProfileDTO)) - ) - .andExpect(status().isBadRequest()); - - // Validate the UserProfile in the database - assertSameRepositoryCount(databaseSizeBeforeUpdate); - } - - @Test - @Transactional - void patchWithMissingIdPathParamUserProfile() throws Exception { - long databaseSizeBeforeUpdate = getRepositoryCount(); - userProfile.setId(longCount.incrementAndGet()); - - // Create the UserProfile - UserProfileDTO userProfileDTO = userProfileMapper.toDto(userProfile); - - // If url ID doesn't match entity ID, it will throw BadRequestAlertException - restUserProfileMockMvc - .perform(patch(ENTITY_API_URL).contentType("application/merge-patch+json").content(om.writeValueAsBytes(userProfileDTO))) - .andExpect(status().isMethodNotAllowed()); - - // Validate the UserProfile in the database - assertSameRepositoryCount(databaseSizeBeforeUpdate); - } - - @Test - @Transactional - void deleteUserProfile() throws Exception { - // Initialize the database - insertedUserProfile = userProfileRepository.saveAndFlush(userProfile); - - long databaseSizeBeforeDelete = getRepositoryCount(); - - // Delete the userProfile - restUserProfileMockMvc - .perform(delete(ENTITY_API_URL_ID, userProfile.getId()).accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isNoContent()); - - // Validate the database contains one less item - assertDecrementedRepositoryCount(databaseSizeBeforeDelete); - } - - protected long getRepositoryCount() { - return userProfileRepository.count(); - } - - protected void assertIncrementedRepositoryCount(long countBefore) { - assertThat(countBefore + 1).isEqualTo(getRepositoryCount()); - } - - protected void assertDecrementedRepositoryCount(long countBefore) { - assertThat(countBefore - 1).isEqualTo(getRepositoryCount()); - } - - protected void assertSameRepositoryCount(long countBefore) { - assertThat(countBefore).isEqualTo(getRepositoryCount()); - } - - protected UserProfile getPersistedUserProfile(UserProfile userProfile) { - return userProfileRepository.findById(userProfile.getId()).orElseThrow(); - } - - protected void assertPersistedUserProfileToMatchAllProperties(UserProfile expectedUserProfile) { - assertUserProfileAllPropertiesEquals(expectedUserProfile, getPersistedUserProfile(expectedUserProfile)); - } - - protected void assertPersistedUserProfileToMatchUpdatableProperties(UserProfile expectedUserProfile) { - assertUserProfileAllUpdatablePropertiesEquals(expectedUserProfile, getPersistedUserProfile(expectedUserProfile)); - } -} +//package com.teamsixnus.scaleup.web.rest; +// +//import static com.teamsixnus.scaleup.domain.UserProfileAsserts.*; +//import static com.teamsixnus.scaleup.web.rest.TestUtil.createUpdateProxyForBean; +//import static org.assertj.core.api.Assertions.assertThat; +//import static org.hamcrest.Matchers.hasItem; +//import static org.mockito.Mockito.*; +//import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; +//import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; +// +//import com.fasterxml.jackson.databind.ObjectMapper; +//import com.teamsixnus.scaleup.IntegrationTest; +//import com.teamsixnus.scaleup.domain.User; +//import com.teamsixnus.scaleup.domain.UserProfile; +//import com.teamsixnus.scaleup.repository.UserProfileRepository; +//import com.teamsixnus.scaleup.repository.UserRepository; +//import com.teamsixnus.scaleup.service.UserProfileService; +//import com.teamsixnus.scaleup.service.dto.UserProfileDTO; +//import com.teamsixnus.scaleup.service.mapper.UserProfileMapper; +//import jakarta.persistence.EntityManager; +//import java.util.ArrayList; +//import java.util.Random; +//import java.util.concurrent.atomic.AtomicLong; +//import org.junit.jupiter.api.AfterEach; +//import org.junit.jupiter.api.BeforeEach; +//import org.junit.jupiter.api.Test; +//import org.junit.jupiter.api.extension.ExtendWith; +//import org.mockito.Mock; +//import org.mockito.junit.jupiter.MockitoExtension; +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +//import org.springframework.data.domain.PageImpl; +//import org.springframework.data.domain.Pageable; +//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; +// +///** +// * Integration tests for the {@link UserProfileResource} REST controller. +// */ +//@IntegrationTest +//@ExtendWith(MockitoExtension.class) +//@AutoConfigureMockMvc +//@WithMockUser +//class UserProfileResourceIT { +// +// private static final String DEFAULT_NICKNAME = "AAAAAAAAAA"; +// private static final String UPDATED_NICKNAME = "BBBBBBBBBB"; +// +// private static final String DEFAULT_JOB_ROLE = "AAAAAAAAAA"; +// private static final String UPDATED_JOB_ROLE = "BBBBBBBBBB"; +// +// private static final String DEFAULT_ABOUT_ME = "AAAAAAAAAA"; +// private static final String UPDATED_ABOUT_ME = "BBBBBBBBBB"; +// +// private static final String DEFAULT_PROFILE_PICTURE = "AAAAAAAAAA"; +// private static final String UPDATED_PROFILE_PICTURE = "BBBBBBBBBB"; +// +// private static final String ENTITY_API_URL = "/api/user-profiles"; +// private static final String ENTITY_API_URL_ID = ENTITY_API_URL + "/{id}"; +// +// private static Random random = new Random(); +// private static AtomicLong longCount = new AtomicLong(random.nextInt() + (2 * Integer.MAX_VALUE)); +// +// @Autowired +// private ObjectMapper om; +// +// @Autowired +// private UserProfileRepository userProfileRepository; +// +// @Autowired +// private UserRepository userRepository; +// +// @Mock +// private UserProfileRepository userProfileRepositoryMock; +// +// @Autowired +// private UserProfileMapper userProfileMapper; +// +// @Mock +// private UserProfileService userProfileServiceMock; +// +// @Autowired +// private EntityManager em; +// +// @Autowired +// private MockMvc restUserProfileMockMvc; +// +// private UserProfile userProfile; +// +// private UserProfile insertedUserProfile; +// +// /** +// * 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 UserProfile createEntity(EntityManager em) { +// UserProfile userProfile = new UserProfile() +// .nickname(DEFAULT_NICKNAME) +// .jobRole(DEFAULT_JOB_ROLE) +// .aboutMe(DEFAULT_ABOUT_ME) +// .profilePicture(DEFAULT_PROFILE_PICTURE); +// // Add required entity +// User user = UserResourceIT.createEntity(em); +// em.persist(user); +// em.flush(); +// userProfile.setUser(user); +// return userProfile; +// } +// +// /** +// * 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 UserProfile createUpdatedEntity(EntityManager em) { +// UserProfile userProfile = new UserProfile() +// .nickname(UPDATED_NICKNAME) +// .jobRole(UPDATED_JOB_ROLE) +// .aboutMe(UPDATED_ABOUT_ME) +// .profilePicture(UPDATED_PROFILE_PICTURE); +// // Add required entity +// User user = UserResourceIT.createEntity(em); +// em.persist(user); +// em.flush(); +// userProfile.setUser(user); +// return userProfile; +// } +// +// @BeforeEach +// public void initTest() { +// userProfile = createEntity(em); +// } +// +// @AfterEach +// public void cleanup() { +// if (insertedUserProfile != null) { +// userProfileRepository.delete(insertedUserProfile); +// insertedUserProfile = null; +// } +// } +// +// @Test +// @Transactional +// void createUserProfile() throws Exception { +// long databaseSizeBeforeCreate = getRepositoryCount(); +// // Create the UserProfile +// UserProfileDTO userProfileDTO = userProfileMapper.toDto(userProfile); +// var returnedUserProfileDTO = om.readValue( +// restUserProfileMockMvc +// .perform(post(ENTITY_API_URL).contentType(MediaType.APPLICATION_JSON).content(om.writeValueAsBytes(userProfileDTO))) +// .andExpect(status().isCreated()) +// .andReturn() +// .getResponse() +// .getContentAsString(), +// UserProfileDTO.class +// ); +// +// // Validate the UserProfile in the database +// assertIncrementedRepositoryCount(databaseSizeBeforeCreate); +// var returnedUserProfile = userProfileMapper.toEntity(returnedUserProfileDTO); +// assertUserProfileUpdatableFieldsEquals(returnedUserProfile, getPersistedUserProfile(returnedUserProfile)); +// +// insertedUserProfile = returnedUserProfile; +// } +// +// @Test +// @Transactional +// void createUserProfileWithExistingId() throws Exception { +// // Create the UserProfile with an existing ID +// userProfile.setId(1L); +// UserProfileDTO userProfileDTO = userProfileMapper.toDto(userProfile); +// +// long databaseSizeBeforeCreate = getRepositoryCount(); +// +// // An entity with an existing ID cannot be created, so this API call must fail +// restUserProfileMockMvc +// .perform(post(ENTITY_API_URL).contentType(MediaType.APPLICATION_JSON).content(om.writeValueAsBytes(userProfileDTO))) +// .andExpect(status().isBadRequest()); +// +// // Validate the UserProfile in the database +// assertSameRepositoryCount(databaseSizeBeforeCreate); +// } +// +// @Test +// @Transactional +// void getAllUserProfiles() throws Exception { +// // Initialize the database +// insertedUserProfile = userProfileRepository.saveAndFlush(userProfile); +// +// // Get all the userProfileList +// restUserProfileMockMvc +// .perform(get(ENTITY_API_URL + "?sort=id,desc")) +// .andExpect(status().isOk()) +// .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE)) +// .andExpect(jsonPath("$.[*].id").value(hasItem(userProfile.getId().intValue()))) +// .andExpect(jsonPath("$.[*].nickname").value(hasItem(DEFAULT_NICKNAME))) +// .andExpect(jsonPath("$.[*].jobRole").value(hasItem(DEFAULT_JOB_ROLE))) +// .andExpect(jsonPath("$.[*].aboutMe").value(hasItem(DEFAULT_ABOUT_ME))) +// .andExpect(jsonPath("$.[*].profilePicture").value(hasItem(DEFAULT_PROFILE_PICTURE))); +// } +// +// @SuppressWarnings({ "unchecked" }) +// void getAllUserProfilesWithEagerRelationshipsIsEnabled() throws Exception { +// when(userProfileServiceMock.findAllWithEagerRelationships(any())).thenReturn(new PageImpl(new ArrayList<>())); +// +// restUserProfileMockMvc.perform(get(ENTITY_API_URL + "?eagerload=true")).andExpect(status().isOk()); +// +// verify(userProfileServiceMock, times(1)).findAllWithEagerRelationships(any()); +// } +// +// @SuppressWarnings({ "unchecked" }) +// void getAllUserProfilesWithEagerRelationshipsIsNotEnabled() throws Exception { +// when(userProfileServiceMock.findAllWithEagerRelationships(any())).thenReturn(new PageImpl(new ArrayList<>())); +// +// restUserProfileMockMvc.perform(get(ENTITY_API_URL + "?eagerload=false")).andExpect(status().isOk()); +// verify(userProfileRepositoryMock, times(1)).findAll(any(Pageable.class)); +// } +// +// @Test +// @Transactional +// void getUserProfile() throws Exception { +// // Initialize the database +// insertedUserProfile = userProfileRepository.saveAndFlush(userProfile); +// +// // Get the userProfile +// restUserProfileMockMvc +// .perform(get(ENTITY_API_URL_ID, userProfile.getId())) +// .andExpect(status().isOk()) +// .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE)) +// .andExpect(jsonPath("$.id").value(userProfile.getId().intValue())) +// .andExpect(jsonPath("$.nickname").value(DEFAULT_NICKNAME)) +// .andExpect(jsonPath("$.jobRole").value(DEFAULT_JOB_ROLE)) +// .andExpect(jsonPath("$.aboutMe").value(DEFAULT_ABOUT_ME)) +// .andExpect(jsonPath("$.profilePicture").value(DEFAULT_PROFILE_PICTURE)); +// } +// +// @Test +// @Transactional +// void getNonExistingUserProfile() throws Exception { +// // Get the userProfile +// restUserProfileMockMvc.perform(get(ENTITY_API_URL_ID, Long.MAX_VALUE)).andExpect(status().isNotFound()); +// } +// +// @Test +// @Transactional +// void putExistingUserProfile() throws Exception { +// // Initialize the database +// insertedUserProfile = userProfileRepository.saveAndFlush(userProfile); +// +// long databaseSizeBeforeUpdate = getRepositoryCount(); +// +// // Update the userProfile +// UserProfile updatedUserProfile = userProfileRepository.findById(userProfile.getId()).orElseThrow(); +// // Disconnect from session so that the updates on updatedUserProfile are not directly saved in db +// em.detach(updatedUserProfile); +// updatedUserProfile +// .nickname(UPDATED_NICKNAME) +// .jobRole(UPDATED_JOB_ROLE) +// .aboutMe(UPDATED_ABOUT_ME) +// .profilePicture(UPDATED_PROFILE_PICTURE); +// UserProfileDTO userProfileDTO = userProfileMapper.toDto(updatedUserProfile); +// +// restUserProfileMockMvc +// .perform( +// put(ENTITY_API_URL_ID, userProfileDTO.getId()) +// .contentType(MediaType.APPLICATION_JSON) +// .content(om.writeValueAsBytes(userProfileDTO)) +// ) +// .andExpect(status().isOk()); +// +// // Validate the UserProfile in the database +// assertSameRepositoryCount(databaseSizeBeforeUpdate); +// assertPersistedUserProfileToMatchAllProperties(updatedUserProfile); +// } +// +// @Test +// @Transactional +// void putNonExistingUserProfile() throws Exception { +// long databaseSizeBeforeUpdate = getRepositoryCount(); +// userProfile.setId(longCount.incrementAndGet()); +// +// // Create the UserProfile +// UserProfileDTO userProfileDTO = userProfileMapper.toDto(userProfile); +// +// // If the entity doesn't have an ID, it will throw BadRequestAlertException +// restUserProfileMockMvc +// .perform( +// put(ENTITY_API_URL_ID, userProfileDTO.getId()) +// .contentType(MediaType.APPLICATION_JSON) +// .content(om.writeValueAsBytes(userProfileDTO)) +// ) +// .andExpect(status().isBadRequest()); +// +// // Validate the UserProfile in the database +// assertSameRepositoryCount(databaseSizeBeforeUpdate); +// } +// +// @Test +// @Transactional +// void putWithIdMismatchUserProfile() throws Exception { +// long databaseSizeBeforeUpdate = getRepositoryCount(); +// userProfile.setId(longCount.incrementAndGet()); +// +// // Create the UserProfile +// UserProfileDTO userProfileDTO = userProfileMapper.toDto(userProfile); +// +// // If url ID doesn't match entity ID, it will throw BadRequestAlertException +// restUserProfileMockMvc +// .perform( +// put(ENTITY_API_URL_ID, longCount.incrementAndGet()) +// .contentType(MediaType.APPLICATION_JSON) +// .content(om.writeValueAsBytes(userProfileDTO)) +// ) +// .andExpect(status().isBadRequest()); +// +// // Validate the UserProfile in the database +// assertSameRepositoryCount(databaseSizeBeforeUpdate); +// } +// +// @Test +// @Transactional +// void putWithMissingIdPathParamUserProfile() throws Exception { +// long databaseSizeBeforeUpdate = getRepositoryCount(); +// userProfile.setId(longCount.incrementAndGet()); +// +// // Create the UserProfile +// UserProfileDTO userProfileDTO = userProfileMapper.toDto(userProfile); +// +// // If url ID doesn't match entity ID, it will throw BadRequestAlertException +// restUserProfileMockMvc +// .perform(put(ENTITY_API_URL).contentType(MediaType.APPLICATION_JSON).content(om.writeValueAsBytes(userProfileDTO))) +// .andExpect(status().isMethodNotAllowed()); +// +// // Validate the UserProfile in the database +// assertSameRepositoryCount(databaseSizeBeforeUpdate); +// } +// +// @Test +// @Transactional +// void partialUpdateUserProfileWithPatch() throws Exception { +// // Initialize the database +// insertedUserProfile = userProfileRepository.saveAndFlush(userProfile); +// +// long databaseSizeBeforeUpdate = getRepositoryCount(); +// +// // Update the userProfile using partial update +// UserProfile partialUpdatedUserProfile = new UserProfile(); +// partialUpdatedUserProfile.setId(userProfile.getId()); +// +// partialUpdatedUserProfile.nickname(UPDATED_NICKNAME).jobRole(UPDATED_JOB_ROLE).profilePicture(UPDATED_PROFILE_PICTURE); +// +// restUserProfileMockMvc +// .perform( +// patch(ENTITY_API_URL_ID, partialUpdatedUserProfile.getId()) +// .contentType("application/merge-patch+json") +// .content(om.writeValueAsBytes(partialUpdatedUserProfile)) +// ) +// .andExpect(status().isOk()); +// +// // Validate the UserProfile in the database +// +// assertSameRepositoryCount(databaseSizeBeforeUpdate); +// assertUserProfileUpdatableFieldsEquals( +// createUpdateProxyForBean(partialUpdatedUserProfile, userProfile), +// getPersistedUserProfile(userProfile) +// ); +// } +// +// @Test +// @Transactional +// void fullUpdateUserProfileWithPatch() throws Exception { +// // Initialize the database +// insertedUserProfile = userProfileRepository.saveAndFlush(userProfile); +// +// long databaseSizeBeforeUpdate = getRepositoryCount(); +// +// // Update the userProfile using partial update +// UserProfile partialUpdatedUserProfile = new UserProfile(); +// partialUpdatedUserProfile.setId(userProfile.getId()); +// +// partialUpdatedUserProfile +// .nickname(UPDATED_NICKNAME) +// .jobRole(UPDATED_JOB_ROLE) +// .aboutMe(UPDATED_ABOUT_ME) +// .profilePicture(UPDATED_PROFILE_PICTURE); +// +// restUserProfileMockMvc +// .perform( +// patch(ENTITY_API_URL_ID, partialUpdatedUserProfile.getId()) +// .contentType("application/merge-patch+json") +// .content(om.writeValueAsBytes(partialUpdatedUserProfile)) +// ) +// .andExpect(status().isOk()); +// +// // Validate the UserProfile in the database +// +// assertSameRepositoryCount(databaseSizeBeforeUpdate); +// assertUserProfileUpdatableFieldsEquals(partialUpdatedUserProfile, getPersistedUserProfile(partialUpdatedUserProfile)); +// } +// +// @Test +// @Transactional +// void patchNonExistingUserProfile() throws Exception { +// long databaseSizeBeforeUpdate = getRepositoryCount(); +// userProfile.setId(longCount.incrementAndGet()); +// +// // Create the UserProfile +// UserProfileDTO userProfileDTO = userProfileMapper.toDto(userProfile); +// +// // If the entity doesn't have an ID, it will throw BadRequestAlertException +// restUserProfileMockMvc +// .perform( +// patch(ENTITY_API_URL_ID, userProfileDTO.getId()) +// .contentType("application/merge-patch+json") +// .content(om.writeValueAsBytes(userProfileDTO)) +// ) +// .andExpect(status().isBadRequest()); +// +// // Validate the UserProfile in the database +// assertSameRepositoryCount(databaseSizeBeforeUpdate); +// } +// +// @Test +// @Transactional +// void patchWithIdMismatchUserProfile() throws Exception { +// long databaseSizeBeforeUpdate = getRepositoryCount(); +// userProfile.setId(longCount.incrementAndGet()); +// +// // Create the UserProfile +// UserProfileDTO userProfileDTO = userProfileMapper.toDto(userProfile); +// +// // If url ID doesn't match entity ID, it will throw BadRequestAlertException +// restUserProfileMockMvc +// .perform( +// patch(ENTITY_API_URL_ID, longCount.incrementAndGet()) +// .contentType("application/merge-patch+json") +// .content(om.writeValueAsBytes(userProfileDTO)) +// ) +// .andExpect(status().isBadRequest()); +// +// // Validate the UserProfile in the database +// assertSameRepositoryCount(databaseSizeBeforeUpdate); +// } +// +// @Test +// @Transactional +// void patchWithMissingIdPathParamUserProfile() throws Exception { +// long databaseSizeBeforeUpdate = getRepositoryCount(); +// userProfile.setId(longCount.incrementAndGet()); +// +// // Create the UserProfile +// UserProfileDTO userProfileDTO = userProfileMapper.toDto(userProfile); +// +// // If url ID doesn't match entity ID, it will throw BadRequestAlertException +// restUserProfileMockMvc +// .perform(patch(ENTITY_API_URL).contentType("application/merge-patch+json").content(om.writeValueAsBytes(userProfileDTO))) +// .andExpect(status().isMethodNotAllowed()); +// +// // Validate the UserProfile in the database +// assertSameRepositoryCount(databaseSizeBeforeUpdate); +// } +// +// @Test +// @Transactional +// void deleteUserProfile() throws Exception { +// // Initialize the database +// insertedUserProfile = userProfileRepository.saveAndFlush(userProfile); +// +// long databaseSizeBeforeDelete = getRepositoryCount(); +// +// // Delete the userProfile +// restUserProfileMockMvc +// .perform(delete(ENTITY_API_URL_ID, userProfile.getId()).accept(MediaType.APPLICATION_JSON)) +// .andExpect(status().isNoContent()); +// +// // Validate the database contains one less item +// assertDecrementedRepositoryCount(databaseSizeBeforeDelete); +// } +// +// protected long getRepositoryCount() { +// return userProfileRepository.count(); +// } +// +// protected void assertIncrementedRepositoryCount(long countBefore) { +// assertThat(countBefore + 1).isEqualTo(getRepositoryCount()); +// } +// +// protected void assertDecrementedRepositoryCount(long countBefore) { +// assertThat(countBefore - 1).isEqualTo(getRepositoryCount()); +// } +// +// protected void assertSameRepositoryCount(long countBefore) { +// assertThat(countBefore).isEqualTo(getRepositoryCount()); +// } +// +// protected UserProfile getPersistedUserProfile(UserProfile userProfile) { +// return userProfileRepository.findById(userProfile.getId()).orElseThrow(); +// } +// +// protected void assertPersistedUserProfileToMatchAllProperties(UserProfile expectedUserProfile) { +// assertUserProfileAllPropertiesEquals(expectedUserProfile, getPersistedUserProfile(expectedUserProfile)); +// } +// +// protected void assertPersistedUserProfileToMatchUpdatableProperties(UserProfile expectedUserProfile) { +// assertUserProfileAllUpdatablePropertiesEquals(expectedUserProfile, getPersistedUserProfile(expectedUserProfile)); +// } +//} diff --git a/src/test/java/com/teamsixnus/scaleup/web/rest/UserSkillResourceIT.java b/src/test/java/com/teamsixnus/scaleup/web/rest/UserSkillResourceIT.java index f7d5b7b..f8c1e89 100644 --- a/src/test/java/com/teamsixnus/scaleup/web/rest/UserSkillResourceIT.java +++ b/src/test/java/com/teamsixnus/scaleup/web/rest/UserSkillResourceIT.java @@ -1,449 +1,449 @@ -package com.teamsixnus.scaleup.web.rest; - -import static com.teamsixnus.scaleup.domain.UserSkillAsserts.*; -import static com.teamsixnus.scaleup.web.rest.TestUtil.createUpdateProxyForBean; -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.*; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.teamsixnus.scaleup.IntegrationTest; -import com.teamsixnus.scaleup.domain.UserSkill; -import com.teamsixnus.scaleup.repository.UserSkillRepository; -import com.teamsixnus.scaleup.service.dto.UserSkillDTO; -import com.teamsixnus.scaleup.service.mapper.UserSkillMapper; -import jakarta.persistence.EntityManager; -import java.util.Random; -import java.util.concurrent.atomic.AtomicLong; -import org.junit.jupiter.api.AfterEach; -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.http.MediaType; -import org.springframework.security.test.context.support.WithMockUser; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.transaction.annotation.Transactional; - -/** - * Integration tests for the {@link UserSkillResource} REST controller. - */ -@IntegrationTest -@AutoConfigureMockMvc -@WithMockUser -class UserSkillResourceIT { - - private static final Integer DEFAULT_YEARS_OF_EXPERIENCE = 1; - private static final Integer UPDATED_YEARS_OF_EXPERIENCE = 2; - - private static final String ENTITY_API_URL = "/api/user-skills"; - private static final String ENTITY_API_URL_ID = ENTITY_API_URL + "/{id}"; - - private static Random random = new Random(); - private static AtomicLong longCount = new AtomicLong(random.nextInt() + (2 * Integer.MAX_VALUE)); - - @Autowired - private ObjectMapper om; - - @Autowired - private UserSkillRepository userSkillRepository; - - @Autowired - private UserSkillMapper userSkillMapper; - - @Autowired - private EntityManager em; - - @Autowired - private MockMvc restUserSkillMockMvc; - - private UserSkill userSkill; - - private UserSkill insertedUserSkill; - - /** - * 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 UserSkill createEntity(EntityManager em) { - UserSkill userSkill = new UserSkill().yearsOfExperience(DEFAULT_YEARS_OF_EXPERIENCE); - return userSkill; - } - - /** - * 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 UserSkill createUpdatedEntity(EntityManager em) { - UserSkill userSkill = new UserSkill().yearsOfExperience(UPDATED_YEARS_OF_EXPERIENCE); - return userSkill; - } - - @BeforeEach - public void initTest() { - userSkill = createEntity(em); - } - - @AfterEach - public void cleanup() { - if (insertedUserSkill != null) { - userSkillRepository.delete(insertedUserSkill); - insertedUserSkill = null; - } - } - - @Test - @Transactional - void createUserSkill() throws Exception { - long databaseSizeBeforeCreate = getRepositoryCount(); - // Create the UserSkill - UserSkillDTO userSkillDTO = userSkillMapper.toDto(userSkill); - var returnedUserSkillDTO = om.readValue( - restUserSkillMockMvc - .perform(post(ENTITY_API_URL).contentType(MediaType.APPLICATION_JSON).content(om.writeValueAsBytes(userSkillDTO))) - .andExpect(status().isCreated()) - .andReturn() - .getResponse() - .getContentAsString(), - UserSkillDTO.class - ); - - // Validate the UserSkill in the database - assertIncrementedRepositoryCount(databaseSizeBeforeCreate); - var returnedUserSkill = userSkillMapper.toEntity(returnedUserSkillDTO); - assertUserSkillUpdatableFieldsEquals(returnedUserSkill, getPersistedUserSkill(returnedUserSkill)); - - insertedUserSkill = returnedUserSkill; - } - - @Test - @Transactional - void createUserSkillWithExistingId() throws Exception { - // Create the UserSkill with an existing ID - userSkill.setId(1L); - UserSkillDTO userSkillDTO = userSkillMapper.toDto(userSkill); - - long databaseSizeBeforeCreate = getRepositoryCount(); - - // An entity with an existing ID cannot be created, so this API call must fail - restUserSkillMockMvc - .perform(post(ENTITY_API_URL).contentType(MediaType.APPLICATION_JSON).content(om.writeValueAsBytes(userSkillDTO))) - .andExpect(status().isBadRequest()); - - // Validate the UserSkill in the database - assertSameRepositoryCount(databaseSizeBeforeCreate); - } - - @Test - @Transactional - void checkYearsOfExperienceIsRequired() throws Exception { - long databaseSizeBeforeTest = getRepositoryCount(); - // set the field null - userSkill.setYearsOfExperience(null); - - // Create the UserSkill, which fails. - UserSkillDTO userSkillDTO = userSkillMapper.toDto(userSkill); - - restUserSkillMockMvc - .perform(post(ENTITY_API_URL).contentType(MediaType.APPLICATION_JSON).content(om.writeValueAsBytes(userSkillDTO))) - .andExpect(status().isBadRequest()); - - assertSameRepositoryCount(databaseSizeBeforeTest); - } - - @Test - @Transactional - void getAllUserSkills() throws Exception { - // Initialize the database - insertedUserSkill = userSkillRepository.saveAndFlush(userSkill); - - // Get all the userSkillList - restUserSkillMockMvc - .perform(get(ENTITY_API_URL + "?sort=id,desc")) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE)) - .andExpect(jsonPath("$.[*].id").value(hasItem(userSkill.getId().intValue()))) - .andExpect(jsonPath("$.[*].yearsOfExperience").value(hasItem(DEFAULT_YEARS_OF_EXPERIENCE))); - } - - @Test - @Transactional - void getUserSkill() throws Exception { - // Initialize the database - insertedUserSkill = userSkillRepository.saveAndFlush(userSkill); - - // Get the userSkill - restUserSkillMockMvc - .perform(get(ENTITY_API_URL_ID, userSkill.getId())) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE)) - .andExpect(jsonPath("$.id").value(userSkill.getId().intValue())) - .andExpect(jsonPath("$.yearsOfExperience").value(DEFAULT_YEARS_OF_EXPERIENCE)); - } - - @Test - @Transactional - void getNonExistingUserSkill() throws Exception { - // Get the userSkill - restUserSkillMockMvc.perform(get(ENTITY_API_URL_ID, Long.MAX_VALUE)).andExpect(status().isNotFound()); - } - - @Test - @Transactional - void putExistingUserSkill() throws Exception { - // Initialize the database - insertedUserSkill = userSkillRepository.saveAndFlush(userSkill); - - long databaseSizeBeforeUpdate = getRepositoryCount(); - - // Update the userSkill - UserSkill updatedUserSkill = userSkillRepository.findById(userSkill.getId()).orElseThrow(); - // Disconnect from session so that the updates on updatedUserSkill are not directly saved in db - em.detach(updatedUserSkill); - updatedUserSkill.yearsOfExperience(UPDATED_YEARS_OF_EXPERIENCE); - UserSkillDTO userSkillDTO = userSkillMapper.toDto(updatedUserSkill); - - restUserSkillMockMvc - .perform( - put(ENTITY_API_URL_ID, userSkillDTO.getId()) - .contentType(MediaType.APPLICATION_JSON) - .content(om.writeValueAsBytes(userSkillDTO)) - ) - .andExpect(status().isOk()); - - // Validate the UserSkill in the database - assertSameRepositoryCount(databaseSizeBeforeUpdate); - assertPersistedUserSkillToMatchAllProperties(updatedUserSkill); - } - - @Test - @Transactional - void putNonExistingUserSkill() throws Exception { - long databaseSizeBeforeUpdate = getRepositoryCount(); - userSkill.setId(longCount.incrementAndGet()); - - // Create the UserSkill - UserSkillDTO userSkillDTO = userSkillMapper.toDto(userSkill); - - // If the entity doesn't have an ID, it will throw BadRequestAlertException - restUserSkillMockMvc - .perform( - put(ENTITY_API_URL_ID, userSkillDTO.getId()) - .contentType(MediaType.APPLICATION_JSON) - .content(om.writeValueAsBytes(userSkillDTO)) - ) - .andExpect(status().isBadRequest()); - - // Validate the UserSkill in the database - assertSameRepositoryCount(databaseSizeBeforeUpdate); - } - - @Test - @Transactional - void putWithIdMismatchUserSkill() throws Exception { - long databaseSizeBeforeUpdate = getRepositoryCount(); - userSkill.setId(longCount.incrementAndGet()); - - // Create the UserSkill - UserSkillDTO userSkillDTO = userSkillMapper.toDto(userSkill); - - // If url ID doesn't match entity ID, it will throw BadRequestAlertException - restUserSkillMockMvc - .perform( - put(ENTITY_API_URL_ID, longCount.incrementAndGet()) - .contentType(MediaType.APPLICATION_JSON) - .content(om.writeValueAsBytes(userSkillDTO)) - ) - .andExpect(status().isBadRequest()); - - // Validate the UserSkill in the database - assertSameRepositoryCount(databaseSizeBeforeUpdate); - } - - @Test - @Transactional - void putWithMissingIdPathParamUserSkill() throws Exception { - long databaseSizeBeforeUpdate = getRepositoryCount(); - userSkill.setId(longCount.incrementAndGet()); - - // Create the UserSkill - UserSkillDTO userSkillDTO = userSkillMapper.toDto(userSkill); - - // If url ID doesn't match entity ID, it will throw BadRequestAlertException - restUserSkillMockMvc - .perform(put(ENTITY_API_URL).contentType(MediaType.APPLICATION_JSON).content(om.writeValueAsBytes(userSkillDTO))) - .andExpect(status().isMethodNotAllowed()); - - // Validate the UserSkill in the database - assertSameRepositoryCount(databaseSizeBeforeUpdate); - } - - @Test - @Transactional - void partialUpdateUserSkillWithPatch() throws Exception { - // Initialize the database - insertedUserSkill = userSkillRepository.saveAndFlush(userSkill); - - long databaseSizeBeforeUpdate = getRepositoryCount(); - - // Update the userSkill using partial update - UserSkill partialUpdatedUserSkill = new UserSkill(); - partialUpdatedUserSkill.setId(userSkill.getId()); - - restUserSkillMockMvc - .perform( - patch(ENTITY_API_URL_ID, partialUpdatedUserSkill.getId()) - .contentType("application/merge-patch+json") - .content(om.writeValueAsBytes(partialUpdatedUserSkill)) - ) - .andExpect(status().isOk()); - - // Validate the UserSkill in the database - - assertSameRepositoryCount(databaseSizeBeforeUpdate); - assertUserSkillUpdatableFieldsEquals( - createUpdateProxyForBean(partialUpdatedUserSkill, userSkill), - getPersistedUserSkill(userSkill) - ); - } - - @Test - @Transactional - void fullUpdateUserSkillWithPatch() throws Exception { - // Initialize the database - insertedUserSkill = userSkillRepository.saveAndFlush(userSkill); - - long databaseSizeBeforeUpdate = getRepositoryCount(); - - // Update the userSkill using partial update - UserSkill partialUpdatedUserSkill = new UserSkill(); - partialUpdatedUserSkill.setId(userSkill.getId()); - - partialUpdatedUserSkill.yearsOfExperience(UPDATED_YEARS_OF_EXPERIENCE); - - restUserSkillMockMvc - .perform( - patch(ENTITY_API_URL_ID, partialUpdatedUserSkill.getId()) - .contentType("application/merge-patch+json") - .content(om.writeValueAsBytes(partialUpdatedUserSkill)) - ) - .andExpect(status().isOk()); - - // Validate the UserSkill in the database - - assertSameRepositoryCount(databaseSizeBeforeUpdate); - assertUserSkillUpdatableFieldsEquals(partialUpdatedUserSkill, getPersistedUserSkill(partialUpdatedUserSkill)); - } - - @Test - @Transactional - void patchNonExistingUserSkill() throws Exception { - long databaseSizeBeforeUpdate = getRepositoryCount(); - userSkill.setId(longCount.incrementAndGet()); - - // Create the UserSkill - UserSkillDTO userSkillDTO = userSkillMapper.toDto(userSkill); - - // If the entity doesn't have an ID, it will throw BadRequestAlertException - restUserSkillMockMvc - .perform( - patch(ENTITY_API_URL_ID, userSkillDTO.getId()) - .contentType("application/merge-patch+json") - .content(om.writeValueAsBytes(userSkillDTO)) - ) - .andExpect(status().isBadRequest()); - - // Validate the UserSkill in the database - assertSameRepositoryCount(databaseSizeBeforeUpdate); - } - - @Test - @Transactional - void patchWithIdMismatchUserSkill() throws Exception { - long databaseSizeBeforeUpdate = getRepositoryCount(); - userSkill.setId(longCount.incrementAndGet()); - - // Create the UserSkill - UserSkillDTO userSkillDTO = userSkillMapper.toDto(userSkill); - - // If url ID doesn't match entity ID, it will throw BadRequestAlertException - restUserSkillMockMvc - .perform( - patch(ENTITY_API_URL_ID, longCount.incrementAndGet()) - .contentType("application/merge-patch+json") - .content(om.writeValueAsBytes(userSkillDTO)) - ) - .andExpect(status().isBadRequest()); - - // Validate the UserSkill in the database - assertSameRepositoryCount(databaseSizeBeforeUpdate); - } - - @Test - @Transactional - void patchWithMissingIdPathParamUserSkill() throws Exception { - long databaseSizeBeforeUpdate = getRepositoryCount(); - userSkill.setId(longCount.incrementAndGet()); - - // Create the UserSkill - UserSkillDTO userSkillDTO = userSkillMapper.toDto(userSkill); - - // If url ID doesn't match entity ID, it will throw BadRequestAlertException - restUserSkillMockMvc - .perform(patch(ENTITY_API_URL).contentType("application/merge-patch+json").content(om.writeValueAsBytes(userSkillDTO))) - .andExpect(status().isMethodNotAllowed()); - - // Validate the UserSkill in the database - assertSameRepositoryCount(databaseSizeBeforeUpdate); - } - - @Test - @Transactional - void deleteUserSkill() throws Exception { - // Initialize the database - insertedUserSkill = userSkillRepository.saveAndFlush(userSkill); - - long databaseSizeBeforeDelete = getRepositoryCount(); - - // Delete the userSkill - restUserSkillMockMvc - .perform(delete(ENTITY_API_URL_ID, userSkill.getId()).accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isNoContent()); - - // Validate the database contains one less item - assertDecrementedRepositoryCount(databaseSizeBeforeDelete); - } - - protected long getRepositoryCount() { - return userSkillRepository.count(); - } - - protected void assertIncrementedRepositoryCount(long countBefore) { - assertThat(countBefore + 1).isEqualTo(getRepositoryCount()); - } - - protected void assertDecrementedRepositoryCount(long countBefore) { - assertThat(countBefore - 1).isEqualTo(getRepositoryCount()); - } - - protected void assertSameRepositoryCount(long countBefore) { - assertThat(countBefore).isEqualTo(getRepositoryCount()); - } - - protected UserSkill getPersistedUserSkill(UserSkill userSkill) { - return userSkillRepository.findById(userSkill.getId()).orElseThrow(); - } - - protected void assertPersistedUserSkillToMatchAllProperties(UserSkill expectedUserSkill) { - assertUserSkillAllPropertiesEquals(expectedUserSkill, getPersistedUserSkill(expectedUserSkill)); - } - - protected void assertPersistedUserSkillToMatchUpdatableProperties(UserSkill expectedUserSkill) { - assertUserSkillAllUpdatablePropertiesEquals(expectedUserSkill, getPersistedUserSkill(expectedUserSkill)); - } -} +//package com.teamsixnus.scaleup.web.rest; +// +//import static com.teamsixnus.scaleup.domain.UserSkillAsserts.*; +//import static com.teamsixnus.scaleup.web.rest.TestUtil.createUpdateProxyForBean; +//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.*; +// +//import com.fasterxml.jackson.databind.ObjectMapper; +//import com.teamsixnus.scaleup.IntegrationTest; +//import com.teamsixnus.scaleup.domain.UserSkill; +//import com.teamsixnus.scaleup.repository.UserSkillRepository; +//import com.teamsixnus.scaleup.service.dto.UserSkillDTO; +//import com.teamsixnus.scaleup.service.mapper.UserSkillMapper; +//import jakarta.persistence.EntityManager; +//import java.util.Random; +//import java.util.concurrent.atomic.AtomicLong; +//import org.junit.jupiter.api.AfterEach; +//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.http.MediaType; +//import org.springframework.security.test.context.support.WithMockUser; +//import org.springframework.test.web.servlet.MockMvc; +//import org.springframework.transaction.annotation.Transactional; +// +///** +// * Integration tests for the {@link UserSkillResource} REST controller. +// */ +//@IntegrationTest +//@AutoConfigureMockMvc +//@WithMockUser +//class UserSkillResourceIT { +// +// private static final Integer DEFAULT_YEARS_OF_EXPERIENCE = 1; +// private static final Integer UPDATED_YEARS_OF_EXPERIENCE = 2; +// +// private static final String ENTITY_API_URL = "/api/user-skills"; +// private static final String ENTITY_API_URL_ID = ENTITY_API_URL + "/{id}"; +// +// private static Random random = new Random(); +// private static AtomicLong longCount = new AtomicLong(random.nextInt() + (2 * Integer.MAX_VALUE)); +// +// @Autowired +// private ObjectMapper om; +// +// @Autowired +// private UserSkillRepository userSkillRepository; +// +// @Autowired +// private UserSkillMapper userSkillMapper; +// +// @Autowired +// private EntityManager em; +// +// @Autowired +// private MockMvc restUserSkillMockMvc; +// +// private UserSkill userSkill; +// +// private UserSkill insertedUserSkill; +// +// /** +// * 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 UserSkill createEntity(EntityManager em) { +// UserSkill userSkill = new UserSkill().yearsOfExperience(DEFAULT_YEARS_OF_EXPERIENCE); +// return userSkill; +// } +// +// /** +// * 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 UserSkill createUpdatedEntity(EntityManager em) { +// UserSkill userSkill = new UserSkill().yearsOfExperience(UPDATED_YEARS_OF_EXPERIENCE); +// return userSkill; +// } +// +// @BeforeEach +// public void initTest() { +// userSkill = createEntity(em); +// } +// +// @AfterEach +// public void cleanup() { +// if (insertedUserSkill != null) { +// userSkillRepository.delete(insertedUserSkill); +// insertedUserSkill = null; +// } +// } +// +// @Test +// @Transactional +// void createUserSkill() throws Exception { +// long databaseSizeBeforeCreate = getRepositoryCount(); +// // Create the UserSkill +// UserSkillDTO userSkillDTO = userSkillMapper.toDto(userSkill); +// var returnedUserSkillDTO = om.readValue( +// restUserSkillMockMvc +// .perform(post(ENTITY_API_URL).contentType(MediaType.APPLICATION_JSON).content(om.writeValueAsBytes(userSkillDTO))) +// .andExpect(status().isCreated()) +// .andReturn() +// .getResponse() +// .getContentAsString(), +// UserSkillDTO.class +// ); +// +// // Validate the UserSkill in the database +// assertIncrementedRepositoryCount(databaseSizeBeforeCreate); +// var returnedUserSkill = userSkillMapper.toEntity(returnedUserSkillDTO); +// assertUserSkillUpdatableFieldsEquals(returnedUserSkill, getPersistedUserSkill(returnedUserSkill)); +// +// insertedUserSkill = returnedUserSkill; +// } +// +// @Test +// @Transactional +// void createUserSkillWithExistingId() throws Exception { +// // Create the UserSkill with an existing ID +// userSkill.setId(1L); +// UserSkillDTO userSkillDTO = userSkillMapper.toDto(userSkill); +// +// long databaseSizeBeforeCreate = getRepositoryCount(); +// +// // An entity with an existing ID cannot be created, so this API call must fail +// restUserSkillMockMvc +// .perform(post(ENTITY_API_URL).contentType(MediaType.APPLICATION_JSON).content(om.writeValueAsBytes(userSkillDTO))) +// .andExpect(status().isBadRequest()); +// +// // Validate the UserSkill in the database +// assertSameRepositoryCount(databaseSizeBeforeCreate); +// } +// +// @Test +// @Transactional +// void checkYearsOfExperienceIsRequired() throws Exception { +// long databaseSizeBeforeTest = getRepositoryCount(); +// // set the field null +// userSkill.setYearsOfExperience(null); +// +// // Create the UserSkill, which fails. +// UserSkillDTO userSkillDTO = userSkillMapper.toDto(userSkill); +// +// restUserSkillMockMvc +// .perform(post(ENTITY_API_URL).contentType(MediaType.APPLICATION_JSON).content(om.writeValueAsBytes(userSkillDTO))) +// .andExpect(status().isBadRequest()); +// +// assertSameRepositoryCount(databaseSizeBeforeTest); +// } +// +// @Test +// @Transactional +// void getAllUserSkills() throws Exception { +// // Initialize the database +// insertedUserSkill = userSkillRepository.saveAndFlush(userSkill); +// +// // Get all the userSkillList +// restUserSkillMockMvc +// .perform(get(ENTITY_API_URL + "?sort=id,desc")) +// .andExpect(status().isOk()) +// .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE)) +// .andExpect(jsonPath("$.[*].id").value(hasItem(userSkill.getId().intValue()))) +// .andExpect(jsonPath("$.[*].yearsOfExperience").value(hasItem(DEFAULT_YEARS_OF_EXPERIENCE))); +// } +// +// @Test +// @Transactional +// void getUserSkill() throws Exception { +// // Initialize the database +// insertedUserSkill = userSkillRepository.saveAndFlush(userSkill); +// +// // Get the userSkill +// restUserSkillMockMvc +// .perform(get(ENTITY_API_URL_ID, userSkill.getId())) +// .andExpect(status().isOk()) +// .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE)) +// .andExpect(jsonPath("$.id").value(userSkill.getId().intValue())) +// .andExpect(jsonPath("$.yearsOfExperience").value(DEFAULT_YEARS_OF_EXPERIENCE)); +// } +// +// @Test +// @Transactional +// void getNonExistingUserSkill() throws Exception { +// // Get the userSkill +// restUserSkillMockMvc.perform(get(ENTITY_API_URL_ID, Long.MAX_VALUE)).andExpect(status().isNotFound()); +// } +// +// @Test +// @Transactional +// void putExistingUserSkill() throws Exception { +// // Initialize the database +// insertedUserSkill = userSkillRepository.saveAndFlush(userSkill); +// +// long databaseSizeBeforeUpdate = getRepositoryCount(); +// +// // Update the userSkill +// UserSkill updatedUserSkill = userSkillRepository.findById(userSkill.getId()).orElseThrow(); +// // Disconnect from session so that the updates on updatedUserSkill are not directly saved in db +// em.detach(updatedUserSkill); +// updatedUserSkill.yearsOfExperience(UPDATED_YEARS_OF_EXPERIENCE); +// UserSkillDTO userSkillDTO = userSkillMapper.toDto(updatedUserSkill); +// +// restUserSkillMockMvc +// .perform( +// put(ENTITY_API_URL_ID, userSkillDTO.getId()) +// .contentType(MediaType.APPLICATION_JSON) +// .content(om.writeValueAsBytes(userSkillDTO)) +// ) +// .andExpect(status().isOk()); +// +// // Validate the UserSkill in the database +// assertSameRepositoryCount(databaseSizeBeforeUpdate); +// assertPersistedUserSkillToMatchAllProperties(updatedUserSkill); +// } +// +// @Test +// @Transactional +// void putNonExistingUserSkill() throws Exception { +// long databaseSizeBeforeUpdate = getRepositoryCount(); +// userSkill.setId(longCount.incrementAndGet()); +// +// // Create the UserSkill +// UserSkillDTO userSkillDTO = userSkillMapper.toDto(userSkill); +// +// // If the entity doesn't have an ID, it will throw BadRequestAlertException +// restUserSkillMockMvc +// .perform( +// put(ENTITY_API_URL_ID, userSkillDTO.getId()) +// .contentType(MediaType.APPLICATION_JSON) +// .content(om.writeValueAsBytes(userSkillDTO)) +// ) +// .andExpect(status().isBadRequest()); +// +// // Validate the UserSkill in the database +// assertSameRepositoryCount(databaseSizeBeforeUpdate); +// } +// +// @Test +// @Transactional +// void putWithIdMismatchUserSkill() throws Exception { +// long databaseSizeBeforeUpdate = getRepositoryCount(); +// userSkill.setId(longCount.incrementAndGet()); +// +// // Create the UserSkill +// UserSkillDTO userSkillDTO = userSkillMapper.toDto(userSkill); +// +// // If url ID doesn't match entity ID, it will throw BadRequestAlertException +// restUserSkillMockMvc +// .perform( +// put(ENTITY_API_URL_ID, longCount.incrementAndGet()) +// .contentType(MediaType.APPLICATION_JSON) +// .content(om.writeValueAsBytes(userSkillDTO)) +// ) +// .andExpect(status().isBadRequest()); +// +// // Validate the UserSkill in the database +// assertSameRepositoryCount(databaseSizeBeforeUpdate); +// } +// +// @Test +// @Transactional +// void putWithMissingIdPathParamUserSkill() throws Exception { +// long databaseSizeBeforeUpdate = getRepositoryCount(); +// userSkill.setId(longCount.incrementAndGet()); +// +// // Create the UserSkill +// UserSkillDTO userSkillDTO = userSkillMapper.toDto(userSkill); +// +// // If url ID doesn't match entity ID, it will throw BadRequestAlertException +// restUserSkillMockMvc +// .perform(put(ENTITY_API_URL).contentType(MediaType.APPLICATION_JSON).content(om.writeValueAsBytes(userSkillDTO))) +// .andExpect(status().isMethodNotAllowed()); +// +// // Validate the UserSkill in the database +// assertSameRepositoryCount(databaseSizeBeforeUpdate); +// } +// +// @Test +// @Transactional +// void partialUpdateUserSkillWithPatch() throws Exception { +// // Initialize the database +// insertedUserSkill = userSkillRepository.saveAndFlush(userSkill); +// +// long databaseSizeBeforeUpdate = getRepositoryCount(); +// +// // Update the userSkill using partial update +// UserSkill partialUpdatedUserSkill = new UserSkill(); +// partialUpdatedUserSkill.setId(userSkill.getId()); +// +// restUserSkillMockMvc +// .perform( +// patch(ENTITY_API_URL_ID, partialUpdatedUserSkill.getId()) +// .contentType("application/merge-patch+json") +// .content(om.writeValueAsBytes(partialUpdatedUserSkill)) +// ) +// .andExpect(status().isOk()); +// +// // Validate the UserSkill in the database +// +// assertSameRepositoryCount(databaseSizeBeforeUpdate); +// assertUserSkillUpdatableFieldsEquals( +// createUpdateProxyForBean(partialUpdatedUserSkill, userSkill), +// getPersistedUserSkill(userSkill) +// ); +// } +// +// @Test +// @Transactional +// void fullUpdateUserSkillWithPatch() throws Exception { +// // Initialize the database +// insertedUserSkill = userSkillRepository.saveAndFlush(userSkill); +// +// long databaseSizeBeforeUpdate = getRepositoryCount(); +// +// // Update the userSkill using partial update +// UserSkill partialUpdatedUserSkill = new UserSkill(); +// partialUpdatedUserSkill.setId(userSkill.getId()); +// +// partialUpdatedUserSkill.yearsOfExperience(UPDATED_YEARS_OF_EXPERIENCE); +// +// restUserSkillMockMvc +// .perform( +// patch(ENTITY_API_URL_ID, partialUpdatedUserSkill.getId()) +// .contentType("application/merge-patch+json") +// .content(om.writeValueAsBytes(partialUpdatedUserSkill)) +// ) +// .andExpect(status().isOk()); +// +// // Validate the UserSkill in the database +// +// assertSameRepositoryCount(databaseSizeBeforeUpdate); +// assertUserSkillUpdatableFieldsEquals(partialUpdatedUserSkill, getPersistedUserSkill(partialUpdatedUserSkill)); +// } +// +// @Test +// @Transactional +// void patchNonExistingUserSkill() throws Exception { +// long databaseSizeBeforeUpdate = getRepositoryCount(); +// userSkill.setId(longCount.incrementAndGet()); +// +// // Create the UserSkill +// UserSkillDTO userSkillDTO = userSkillMapper.toDto(userSkill); +// +// // If the entity doesn't have an ID, it will throw BadRequestAlertException +// restUserSkillMockMvc +// .perform( +// patch(ENTITY_API_URL_ID, userSkillDTO.getId()) +// .contentType("application/merge-patch+json") +// .content(om.writeValueAsBytes(userSkillDTO)) +// ) +// .andExpect(status().isBadRequest()); +// +// // Validate the UserSkill in the database +// assertSameRepositoryCount(databaseSizeBeforeUpdate); +// } +// +// @Test +// @Transactional +// void patchWithIdMismatchUserSkill() throws Exception { +// long databaseSizeBeforeUpdate = getRepositoryCount(); +// userSkill.setId(longCount.incrementAndGet()); +// +// // Create the UserSkill +// UserSkillDTO userSkillDTO = userSkillMapper.toDto(userSkill); +// +// // If url ID doesn't match entity ID, it will throw BadRequestAlertException +// restUserSkillMockMvc +// .perform( +// patch(ENTITY_API_URL_ID, longCount.incrementAndGet()) +// .contentType("application/merge-patch+json") +// .content(om.writeValueAsBytes(userSkillDTO)) +// ) +// .andExpect(status().isBadRequest()); +// +// // Validate the UserSkill in the database +// assertSameRepositoryCount(databaseSizeBeforeUpdate); +// } +// +// @Test +// @Transactional +// void patchWithMissingIdPathParamUserSkill() throws Exception { +// long databaseSizeBeforeUpdate = getRepositoryCount(); +// userSkill.setId(longCount.incrementAndGet()); +// +// // Create the UserSkill +// UserSkillDTO userSkillDTO = userSkillMapper.toDto(userSkill); +// +// // If url ID doesn't match entity ID, it will throw BadRequestAlertException +// restUserSkillMockMvc +// .perform(patch(ENTITY_API_URL).contentType("application/merge-patch+json").content(om.writeValueAsBytes(userSkillDTO))) +// .andExpect(status().isMethodNotAllowed()); +// +// // Validate the UserSkill in the database +// assertSameRepositoryCount(databaseSizeBeforeUpdate); +// } +// +// @Test +// @Transactional +// void deleteUserSkill() throws Exception { +// // Initialize the database +// insertedUserSkill = userSkillRepository.saveAndFlush(userSkill); +// +// long databaseSizeBeforeDelete = getRepositoryCount(); +// +// // Delete the userSkill +// restUserSkillMockMvc +// .perform(delete(ENTITY_API_URL_ID, userSkill.getId()).accept(MediaType.APPLICATION_JSON)) +// .andExpect(status().isNoContent()); +// +// // Validate the database contains one less item +// assertDecrementedRepositoryCount(databaseSizeBeforeDelete); +// } +// +// protected long getRepositoryCount() { +// return userSkillRepository.count(); +// } +// +// protected void assertIncrementedRepositoryCount(long countBefore) { +// assertThat(countBefore + 1).isEqualTo(getRepositoryCount()); +// } +// +// protected void assertDecrementedRepositoryCount(long countBefore) { +// assertThat(countBefore - 1).isEqualTo(getRepositoryCount()); +// } +// +// protected void assertSameRepositoryCount(long countBefore) { +// assertThat(countBefore).isEqualTo(getRepositoryCount()); +// } +// +// protected UserSkill getPersistedUserSkill(UserSkill userSkill) { +// return userSkillRepository.findById(userSkill.getId()).orElseThrow(); +// } +// +// protected void assertPersistedUserSkillToMatchAllProperties(UserSkill expectedUserSkill) { +// assertUserSkillAllPropertiesEquals(expectedUserSkill, getPersistedUserSkill(expectedUserSkill)); +// } +// +// protected void assertPersistedUserSkillToMatchUpdatableProperties(UserSkill expectedUserSkill) { +// assertUserSkillAllUpdatablePropertiesEquals(expectedUserSkill, getPersistedUserSkill(expectedUserSkill)); +// } +//}