mirror of
https://github.com/valitydev/fraudbusters-management.git
synced 2024-11-06 16:35:20 +00:00
Check empty
This commit is contained in:
parent
eabdc8dfb0
commit
3531a1d38a
@ -16,6 +16,7 @@ import org.springframework.web.client.HttpClientErrorException;
|
||||
public class ErrorController {
|
||||
|
||||
public static final String FORMAT_DATA_EXCEPTION = "formatDataException";
|
||||
public static final String INVALID_PARAMETERS = "invalidParameters";
|
||||
public static final String DATA_BASE_INVOCATION_EXCEPTION = "dataBaseInvocationException";
|
||||
|
||||
@ExceptionHandler(HttpClientErrorException.Unauthorized.class)
|
||||
@ -45,4 +46,14 @@ public class ErrorController {
|
||||
.build();
|
||||
}
|
||||
|
||||
@ExceptionHandler({HttpClientErrorException.BadRequest.class})
|
||||
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||
@ResponseBody
|
||||
public ErrorResponse handleBadRequest(HttpClientErrorException.BadRequest e) {
|
||||
return ErrorResponse.builder()
|
||||
.code(INVALID_PARAMETERS)
|
||||
.message(e.getMessage())
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
@ -1,13 +1,20 @@
|
||||
package com.rbkmoney.fraudbusters.management.domain;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@Data
|
||||
public class ListRecord {
|
||||
|
||||
@NotNull
|
||||
private String partyId;
|
||||
@NotNull
|
||||
private String shopId;
|
||||
@NotNull
|
||||
private String listName;
|
||||
@NotNull
|
||||
private String value;
|
||||
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
@ -30,7 +31,7 @@ public class WbListResource {
|
||||
private final CommandService commandService;
|
||||
|
||||
@PostMapping(value = "/whiteList")
|
||||
public ResponseEntity<String> insertRowToWhite(@RequestBody ListRecord record) throws ExecutionException, InterruptedException {
|
||||
public ResponseEntity<String> insertRowToWhite(@Validated @RequestBody ListRecord record) throws ExecutionException, InterruptedException {
|
||||
Row row = listRecordToRowConverter.destinationToSource(record);
|
||||
log.info("WbListResource whiteList add record {}", record);
|
||||
String idMessage = commandService.sendCommandSync(row, ListType.white, Command.CREATE);
|
||||
@ -38,7 +39,7 @@ public class WbListResource {
|
||||
}
|
||||
|
||||
@DeleteMapping(value = "/whiteList")
|
||||
public ResponseEntity<String> removeRowFromWhiteList(@RequestBody ListRecord record) throws ExecutionException, InterruptedException {
|
||||
public ResponseEntity<String> removeRowFromWhiteList(@Validated @RequestBody ListRecord record) throws ExecutionException, InterruptedException {
|
||||
Row row = listRecordToRowConverter.destinationToSource(record);
|
||||
log.info("WbListResource whiteList remove record {}", record);
|
||||
String idMessage = commandService.sendCommandSync(row, ListType.white, Command.DELETE);
|
||||
|
@ -1,7 +1,5 @@
|
||||
package com.rbkmoney.fraudbusters.management;
|
||||
|
||||
import com.rbkmoney.damsel.wb_list.ListType;
|
||||
import com.rbkmoney.damsel.wb_list.Row;
|
||||
import com.rbkmoney.fraudbusters.management.controller.ErrorController;
|
||||
import com.rbkmoney.fraudbusters.management.converter.ListRecordToRowConverter;
|
||||
import com.rbkmoney.fraudbusters.management.converter.WbListRecordsToListRecordConverter;
|
||||
@ -30,9 +28,12 @@ import org.springframework.boot.web.server.LocalServerPort;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.web.client.HttpClientErrorException;
|
||||
import org.springframework.web.client.HttpServerErrorException;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
@ -75,14 +76,25 @@ public class ExceptionApplicationTest {
|
||||
private static String SERVICE_URL = "http://localhost:%s";
|
||||
|
||||
@NotNull
|
||||
private Row createRow(ListType listType) {
|
||||
Row row = new Row();
|
||||
row.setShopId(SHOP_ID);
|
||||
row.setPartyId(PARTY_ID);
|
||||
row.setListName(LIST_NAME);
|
||||
row.setListType(listType);
|
||||
row.setValue(VALUE);
|
||||
return row;
|
||||
private ListRecord createRow() {
|
||||
ListRecord listRecord = new ListRecord();
|
||||
listRecord.setShopId(SHOP_ID);
|
||||
listRecord.setPartyId(PARTY_ID);
|
||||
listRecord.setListName(LIST_NAME);
|
||||
listRecord.setValue(VALUE);
|
||||
return listRecord;
|
||||
}
|
||||
|
||||
@Test(expected = HttpClientErrorException.BadRequest.class)
|
||||
public void executionRestTestBadRequest() throws ExecutionException, InterruptedException {
|
||||
RestTemplate restTemplate = restTemplateBuilder.build();
|
||||
Mockito.when(commandService.sendCommandSync(any(), any(), any())).thenReturn(ID_TEST);
|
||||
|
||||
ListRecord listRecord = new ListRecord();
|
||||
String format = String.format(SERVICE_URL, serverPort);
|
||||
ResponseEntity<String> response = restTemplate.postForEntity(format + "/whiteList", listRecord, String.class);
|
||||
Assert.assertEquals(HttpStatus.OK, response.getStatusCode());
|
||||
Assert.assertEquals(response.getBody(), ID_TEST);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -90,7 +102,7 @@ public class ExceptionApplicationTest {
|
||||
RestTemplate restTemplate = restTemplateBuilder.build();
|
||||
Mockito.when(commandService.sendCommandSync(any(), any(), any())).thenReturn(ID_TEST);
|
||||
|
||||
ListRecord listRecord = new ListRecord();
|
||||
ListRecord listRecord = createRow();
|
||||
String format = String.format(SERVICE_URL, serverPort);
|
||||
ResponseEntity<String> response = restTemplate.postForEntity(format + "/whiteList", listRecord, String.class);
|
||||
Assert.assertEquals(HttpStatus.OK, response.getStatusCode());
|
||||
@ -102,7 +114,7 @@ public class ExceptionApplicationTest {
|
||||
RestTemplate restTemplate = restTemplateBuilder.build();
|
||||
Mockito.when(commandService.sendCommandSync(any(), any(), any())).thenThrow(new DaoException(TEST_MESSAGE));
|
||||
|
||||
ListRecord listRecord = new ListRecord();
|
||||
ListRecord listRecord = createRow();
|
||||
String format = String.format(SERVICE_URL, serverPort);
|
||||
restTemplate.postForEntity(format + "/whiteList", listRecord, ErrorResponse.class);
|
||||
}
|
||||
@ -112,8 +124,22 @@ public class ExceptionApplicationTest {
|
||||
RestTemplate restTemplate = restTemplateBuilder.build();
|
||||
Mockito.when(commandService.sendCommandSync(any(), any(), any())).thenThrow(new KafkaSerializationException(TEST_MESSAGE));
|
||||
|
||||
ListRecord listRecord = new ListRecord();
|
||||
ListRecord listRecord = createRow();
|
||||
String format = String.format(SERVICE_URL, serverPort);
|
||||
restTemplate.postForEntity(format + "/whiteList", listRecord, ErrorResponse.class);
|
||||
}
|
||||
|
||||
@Test(expected = HttpClientErrorException.BadRequest.class)
|
||||
public void getRestTestBadRequest() throws ExecutionException, InterruptedException {
|
||||
RestTemplate restTemplate = restTemplateBuilder.build();
|
||||
Mockito.when(commandService.sendCommandSync(any(), any(), any())).thenThrow(new KafkaSerializationException(TEST_MESSAGE));
|
||||
HashMap<String, Object> uriVariables = new HashMap<>();
|
||||
UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(String.format(SERVICE_URL, serverPort) + "/whiteList")
|
||||
.queryParam("partyId", PARTY_ID)
|
||||
.queryParam("shopId", SHOP_ID)
|
||||
;
|
||||
uriVariables.put("partyId", PARTY_ID);
|
||||
uriVariables.put("shopId", SHOP_ID);
|
||||
restTemplate.getForEntity(builder.buildAndExpand(uriVariables).toUri(), ErrorResponse.class);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user