44import static org .junit .Assert .assertTrue ;
55
66import java .io .IOException ;
7+ import java .time .LocalDate ;
8+ import java .time .LocalDateTime ;
79
810import ca .bc .gov .open .jrccaccess .libs .TransactionInfo ;
911import org .junit .Before ;
2123import ca .bc .gov .open .jrccaccess .libs .services .exceptions .ServiceUnavailableException ;
2224
2325public class DocumentControllerTester {
24-
25-
26+
2627 private static final String SERVICE_UNAVAILABLE = "service_unavailable" ;
2728
2829 private static final String VALID = "valid" ;
@@ -33,45 +34,47 @@ public class DocumentControllerTester {
3334 private DocumentReadyHandler documentReadyHandler ;
3435
3536 @ Mock
36- private TransactionInfo transactionInfo ;
37- @ Mock
38- private Resource resource ;
37+ private TransactionInfo transactionInfoMock ;
3938
4039 @ Mock
41- private Resource resourceWithException ;
42-
40+ private Resource resourceWithException ;
4341
4442 @ Before
4543 public void init () throws Exception {
4644
4745 MockitoAnnotations .initMocks (this );
48- Mockito .doNothing ().when (this .documentReadyHandler ).handle ("message" , this .transactionInfo );
49- Mockito .doThrow (new ServiceUnavailableException (SERVICE_UNAVAILABLE )).when (this .documentReadyHandler ).handle ("message" , this .transactionInfo );
46+ Mockito .doNothing ().when (this .documentReadyHandler ).handle ("message" , this .transactionInfoMock );
47+ Mockito .doThrow (new ServiceUnavailableException (SERVICE_UNAVAILABLE )).when (this .documentReadyHandler ).handle (Mockito .eq (SERVICE_UNAVAILABLE ), Mockito .any ());
48+ Mockito .doReturn ("filename.txt" ).when (this .resourceWithException ).getFilename ();
5049 Mockito .when (this .resourceWithException .getInputStream ()).thenThrow (IOException .class );
5150 sut = new DocumentController (this .documentReadyHandler );
5251 }
5352
5453 @ Test
5554 public void post_with_valid_input_should_return_valid_response () {
5655 ByteArrayResource bytes = new ByteArrayResource ("awesome content" .getBytes ()){
57- @ Override
58- public String getFilename (){
59- return "documentController.txt" ;
60- }
61- };
62- ResponseEntity <DocumentReceivedResponse > response = sut .postDocument (VALID , null , null , null , null , null , bytes );
63-
64- assertEquals (HttpStatus .OK , response .getStatusCode ());
65- assertTrue (response .getBody ().getAcknowledge ());
56+ @ Override
57+ public String getFilename (){
58+ return "documentController.txt" ;
59+ }
60+ };
61+ ResponseEntity <DocumentReceivedResponse > response = sut .postDocument (VALID , null , null , null , null , null , bytes );
6662
67- }
63+ assertEquals (HttpStatus .OK , response .getStatusCode ());
64+ assertTrue (response .getBody ().getAcknowledge ());
65+ }
6866
6967 @ Test
7068 public void post_with_sevice_unavailable_input_should_return_503_response () {
71-
69+ ByteArrayResource bytes = new ByteArrayResource (SERVICE_UNAVAILABLE .getBytes ()){
70+ @ Override
71+ public String getFilename (){
72+ return "documentController.txt" ;
73+ }
74+ };
7275 @ SuppressWarnings ("rawtypes" )
73- ResponseEntity response = sut .postDocument (SERVICE_UNAVAILABLE , null , null , null , null , null , new ByteArrayResource ( "awesome content" . getBytes ()) );
74-
76+ ResponseEntity response = sut .postDocument (SERVICE_UNAVAILABLE , null , null , null , null , null , bytes );
77+
7578 assertEquals (HttpStatus .SERVICE_UNAVAILABLE , response .getStatusCode ());
7679 assertEquals (SERVICE_UNAVAILABLE , ((ca .bc .gov .open .api .model .Error )response .getBody ()).getMessage ());
7780 assertEquals (Integer .toString (HttpStatus .SERVICE_UNAVAILABLE .value ()), ((ca .bc .gov .open .api .model .Error )response .getBody ()).getCode ());
@@ -80,7 +83,6 @@ public void post_with_sevice_unavailable_input_should_return_503_response() {
8083
8184 @ Test
8285 public void post_with_io_exception_input_should_return_500_response () {
83-
8486 @ SuppressWarnings ("rawtypes" )
8587 ResponseEntity response = sut .postDocument (VALID , null , null , null , null , null , this .resourceWithException );
8688
0 commit comments