4
4
import static org .junit .Assert .assertTrue ;
5
5
6
6
import java .io .IOException ;
7
+ import java .time .LocalDate ;
8
+ import java .time .LocalDateTime ;
7
9
8
10
import ca .bc .gov .open .jrccaccess .libs .TransactionInfo ;
9
11
import org .junit .Before ;
21
23
import ca .bc .gov .open .jrccaccess .libs .services .exceptions .ServiceUnavailableException ;
22
24
23
25
public class DocumentControllerTester {
24
-
25
-
26
+
26
27
private static final String SERVICE_UNAVAILABLE = "service_unavailable" ;
27
28
28
29
private static final String VALID = "valid" ;
@@ -33,45 +34,47 @@ public class DocumentControllerTester {
33
34
private DocumentReadyHandler documentReadyHandler ;
34
35
35
36
@ Mock
36
- private TransactionInfo transactionInfo ;
37
- @ Mock
38
- private Resource resource ;
37
+ private TransactionInfo transactionInfoMock ;
39
38
40
39
@ Mock
41
- private Resource resourceWithException ;
42
-
40
+ private Resource resourceWithException ;
43
41
44
42
@ Before
45
43
public void init () throws Exception {
46
44
47
45
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 ();
50
49
Mockito .when (this .resourceWithException .getInputStream ()).thenThrow (IOException .class );
51
50
sut = new DocumentController (this .documentReadyHandler );
52
51
}
53
52
54
53
@ Test
55
54
public void post_with_valid_input_should_return_valid_response () {
56
55
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 );
66
62
67
- }
63
+ assertEquals (HttpStatus .OK , response .getStatusCode ());
64
+ assertTrue (response .getBody ().getAcknowledge ());
65
+ }
68
66
69
67
@ Test
70
68
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
+ };
72
75
@ 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
+
75
78
assertEquals (HttpStatus .SERVICE_UNAVAILABLE , response .getStatusCode ());
76
79
assertEquals (SERVICE_UNAVAILABLE , ((ca .bc .gov .open .api .model .Error )response .getBody ()).getMessage ());
77
80
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() {
80
83
81
84
@ Test
82
85
public void post_with_io_exception_input_should_return_500_response () {
83
-
84
86
@ SuppressWarnings ("rawtypes" )
85
87
ResponseEntity response = sut .postDocument (VALID , null , null , null , null , null , this .resourceWithException );
86
88
0 commit comments