Skip to content

Commit

Permalink
fix: sonar issues
Browse files Browse the repository at this point in the history
  • Loading branch information
BettyB979 committed Aug 7, 2024
1 parent ba51614 commit 258700f
Show file tree
Hide file tree
Showing 15 changed files with 92 additions and 93 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</parent>
<groupId>fr.insee.survey</groupId>
<artifactId>platine-management</artifactId>
<version>2.5.0</version>
<version>2.6.0</version>
<name>platine-management</name>
<description>REST API for communication between DB and Platine-Management UI and Platine-My-Surveys UI</description>
<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@
public class AuthConstants {

public static final String OIDC = "OIDC";

private AuthConstants() {
throw new IllegalStateException("Utility class");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,13 @@ public class AddressController {

private final ContactEventService contactEventService;

/**
* @deprecated
*/
@Operation(summary = "Search for a contact address by the contact id")
@GetMapping(value = Constants.API_CONTACTS_ID_ADDRESS, produces = "application/json")
@PreAuthorize(AuthorityPrivileges.HAS_MANAGEMENT_PRIVILEGES + " || " + AuthorityPrivileges.HAS_REPONDENT_LIMITATED_PRIVILEGES)
@Deprecated
@Deprecated(since="2.6.0", forRemoval=true)
public ResponseEntity<AddressDto> getContactAddress(@PathVariable("id") String id) {
Contact contact = contactService.findByIdentifier(id);
if (contact.getAddress() != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,12 @@ public class ContactController {

private final ModelMapper modelMapper;

/**
* @deprecated
*/
@Operation(summary = "Search for contacts, paginated")
@GetMapping(value = Constants.API_CONTACTS_ALL, produces = "application/json")
@Deprecated
@Deprecated(since = "2.6.0", forRemoval = true)
public ContactPage getContacts(
@RequestParam(defaultValue = "0") Integer page,
@RequestParam(defaultValue = "20") Integer size,
Expand Down Expand Up @@ -119,10 +122,13 @@ public ResponseEntity<ContactDto> putContact(@PathVariable("id") String id,
}


/**
* @deprecated
*/
@Operation(summary = "Delete a contact, its address, its contactEvents")
@DeleteMapping(value = Constants.API_CONTACTS_ID)
@ResponseStatus(HttpStatus.NO_CONTENT)
@Deprecated
@Deprecated(since = "2.6.0", forRemoval = true)
public void deleteContact(@PathVariable("id") String id) {

if (!questioningAccreditationService.findByContactIdentifier(id).isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@ public class ContactEventController {

private final ModelMapper modelMapper;

/**
* @deprecated
*/
@Operation(summary = "Search for contactEvents by the contact id")
@GetMapping(value = Constants.API_CONTACTS_ID_CONTACTEVENTS, produces = "application/json")
@Deprecated
@Deprecated(since = "2.6.0", forRemoval = true)
public ResponseEntity<List<ContactEventDto>> getContactContactEvents(@PathVariable("id") String identifier) {
Contact contact = contactService.findByIdentifier(identifier);
return ResponseEntity.status(HttpStatus.OK)
Expand All @@ -51,9 +54,13 @@ public ResponseEntity<List<ContactEventDto>> getContactContactEvents(@PathVariab

}


/**
* @deprecated
*/
@Operation(summary = "Create a contactEvent")
@PostMapping(value = Constants.API_CONTACTEVENTS, produces = "application/json", consumes = "application/json")
@Deprecated
@Deprecated(since = "2.6.0", forRemoval = true)
public ResponseEntity<ContactEventDto> postContactEvent(@RequestBody @Valid ContactEventDto contactEventDto) {

Contact contact = contactService.findByIdentifier(contactEventDto.getIdentifier());
Expand All @@ -72,10 +79,14 @@ public ResponseEntity<ContactEventDto> postContactEvent(@RequestBody @Valid Cont
}



/**
* @deprecated
*/
@Operation(summary = "Delete a contact event")
@DeleteMapping(value = Constants.API_CONTACTEVENTS_ID, produces = "application/json")
@ResponseStatus(HttpStatus.NO_CONTENT)
@Deprecated
@Deprecated(since = "2.6.0", forRemoval = true)
public void deleteContactEvent(@PathVariable("id") Long id) {
ContactEvent contactEvent = contactEventService.findById(id);
Contact contact = contactEvent.getContact();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,11 @@ public void deleteAddressById(Long id) {
}

public AddressDto convertToDto(Address address) {
AddressDto adressDto = modelMapper.map(address, AddressDto.class);

return adressDto;
return modelMapper.map(address, AddressDto.class);
}

public Address convertToEntity(AddressDto addressDto) {
Address address = modelMapper.map(addressDto, Address.class);
return address;
return modelMapper.map(addressDto, Address.class);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public void putParams(@PathVariable("id") String id, @RequestBody @Valid ParamsD
if (paramsDto.getParamId().equalsIgnoreCase(Parameters.ParameterEnum.URL_TYPE.name())
&& Arrays.stream(values()).noneMatch(p -> p.name().equals(paramsDto.getParamValue()))) {

throw new NotMatchException(String.format("Only %s are valid values for URL_TYPE", Arrays.stream(values()).map(item -> item.name())
throw new NotMatchException(String.format("Only %s are valid values for URL_TYPE", Arrays.stream(values()).map(Enum::name)
.collect(joining(" "))));
}
if (paramsDto.getParamId().equalsIgnoreCase(Parameters.ParameterEnum.MAIL_ASSISTANCE.name())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ public interface MoogService {

Collection<MoogExtractionRowDto> getSurveyUnitsToFollowUp(String idCampaign);

public String getReadOnlyUrl(String idCampaign, String surveyUnitId) throws NotFoundException;
String getReadOnlyUrl(String idCampaign, String surveyUnitId) throws NotFoundException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
@SpringBootTest
@ActiveProfiles("test")
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD)
public class AddressControllerTest {
class AddressControllerTest {

@Autowired
MockMvc mockMvc;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
@SpringBootTest
@ActiveProfiles("test")
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD)
public class ContactControllerTest {
class ContactControllerTest {

@Autowired
MockMvc mockMvc;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
@SpringBootTest
@ActiveProfiles("test")
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD)
public class ContactEventControllerTest {
class ContactEventControllerTest {

@Autowired
MockMvc mockMvc;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class CampaignControllerTest {
void init() {
SecurityContextHolder.getContext().setAuthentication(AuthenticationUserProvider.getAuthenticatedUser("test", AuthorityRoleEnum.ADMIN));
}

@Test
void getCampaignNotFound() throws Exception {
String identifier = "CAMPAIGNNOTFOUND";
Expand Down Expand Up @@ -82,9 +83,9 @@ void isCampaignOnGoing() throws Exception {
initCampaignAndPartitionings(identifier, campaign);

this.mockMvc.perform(get(Constants.CAMPAIGNS_ID_ONGOING, identifier)).andDo(print()).andExpect(status().isOk())
.andExpect(content().json("{\n" +
" \"ongoing\": true\n" +
"}", false));
.andExpect(content().json("""
{"ongoing": true}
""", false));

}

Expand All @@ -95,9 +96,9 @@ void isCampaignOnGoingClose() throws Exception {
initCampaignAndPartitionings(identifier, campaign);

this.mockMvc.perform(get(Constants.CAMPAIGNS_ID_ONGOING, identifier)).andDo(print()).andExpect(status().isOk())
.andExpect(content().json("{\n" +
" \"ongoing\": false\n" +
"}", false));
.andExpect(content().json("""
{"ongoing": false}
""", false));

}

Expand All @@ -109,9 +110,9 @@ void isCampaignOnGoingFutureCampaignFalse() throws Exception {


this.mockMvc.perform(get(Constants.CAMPAIGNS_ID_ONGOING, identifier)).andDo(print()).andExpect(status().isOk())
.andExpect(content().json("{\n" +
" \"ongoing\": false\n" +
"}", false));
.andExpect(content().json("""
{"ongoing": false}
""", false));

}

Expand All @@ -129,9 +130,9 @@ void isCampaignOnGoingEmptyCampaignFalse() throws Exception {


this.mockMvc.perform(get(Constants.CAMPAIGNS_ID_ONGOING, identifier)).andDo(print()).andExpect(status().isOk())
.andExpect(content().json("{\n" +
" \"ongoing\": false\n" +
"}", false));
.andExpect(content().json("""
{"ongoing": false}
""", false));

}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,6 @@ class MyQuestioningsControllerTest {
@MockBean
private CheckHabilitationService checkAccreditationService;

// @Test
// void myQuestionings() throws Exception {
// String identifier = "CONT2";
//
// MvcResult result = this.mockMvc.perform(get(Constants.API_MY_QUESTIONINGS_ID, identifier)).andDo(print())
// .andExpect(status().isOk()).andReturn();
// String json = result.getResponse().getContentAsString();
// MyQuestioningDto[] myQuestionings = new ObjectMapper().readValue(json, MyQuestioningDto[].class);
// System.out.println(json);
// assertEquals(10, myQuestionings.length);
// Stream.of(myQuestionings).forEach(q -> {
// assertFalse(q.isMandatoryMySurveys());
// assertNotNull(q.getClosingDate());
// assertNotNull(q.getOpeningDate());
// assertNotNull(q.getReturnDate());
// assertNotNull(q.getIdentificationCode());
// });
//
// }

@Test
void myQuestioningsContactNotExist() throws Exception {
Expand Down
41 changes: 41 additions & 0 deletions src/test/resources/integration/query/search_contact.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
Feature: search for a contact

I am searching for a specific contact

Background: Contact

| Nom | Prénom | Idep | Adresse mél |
|--------|--------|--------|--------------------|
| Doe | John | JD2024 | john.doe@gmail.com |
| Durant | Doeris | DD1234 | dd1995@orange.fr |
| DOEDOE | johnny | ABCD12 | jojodu94@yahoo.fr |
| | | DOE203 | |
| BOOP | Betty | COCO54 | betty.boop@free.fr |

Scenario: search for John Doe
Given I am a survey manager who's searching for "John Doe"
When i type "Joh" in the name and surname searching area
Then i found "Johnny"
And i found "John"

Scenario: search for a contact who has a name or surname beginning by Doe
Given I am a survey manager who's searching for "Doe"
When i type "Doe" in the name and surname searching area
Then i found "Johnny"
And i found "John"
And i found "Doeris"

Scenario: search for a contact who does not exist
Given I am a survey manager who's searching for "Camille"
When i type "Cam" in the name and surname searching area
Then i found nothing

Scenario: search for betty boop
Given I am a survey manager who's searching for "Betty Boop"
When i type "bet" in the email searching area
Then i found "betty.boop@free.fr"

Scenario: search for John Doe by his "idep"
Given I am a survey manager who's searching for "John Doe"
When i type "JD2" in the idep searching area
Then i found "JD2024"

0 comments on commit 258700f

Please sign in to comment.