6
6
import com .fasterxml .jackson .datatype .jsr310 .JavaTimeModule ;
7
7
import com .fingerprint .model .*;
8
8
import com .fingerprint .sdk .*;
9
- import org .junit .jupiter .api .Assertions ;
10
9
import org .junit .jupiter .api .BeforeAll ;
11
10
import org .junit .jupiter .api .Test ;
12
11
13
12
import java .io .IOException ;
14
13
import java .io .InputStream ;
15
- import java .util .LinkedHashMap ;
16
14
import java .util .Map ;
17
15
18
16
import org .junit .jupiter .api .TestInstance ;
29
27
public class FingerprintApiTest {
30
28
private FingerprintApi api ;
31
29
private static final String MOCK_REQUEST_ID = "0KSh65EnVoB85JBmloQK" ;
30
+ private static final String MOCK_REQUEST_FOR_UPDATE = "1722878691275.6RRrbn" ;
32
31
private static final String MOCK_REQUEST_WITH_EXTRA_FIELDS_ID = "EXTRA_FIELDS" ;
33
32
private static final String MOCK_REQUEST_WITH_ALL_FAILED_SIGNALS = "ALL_FAILED_SIGNALS" ;
34
33
private static final String MOCK_REQUEST_BOTD_FAILED = "MOCK_REQUEST_BOTD_FAILED" ;
@@ -40,6 +39,7 @@ public class FingerprintApiTest {
40
39
private static final String MOCK_WEBHOOK_VISITOR_ID = "3HNey93AkBW6CRbxV6xP" ;
41
40
private static final String MOCK_WEBHOOK_REQUEST_ID = "Px6VxbRC6WBkA39yeNH3" ;
42
41
42
+ private static final ObjectMapper MAPPER = getMapper ();
43
43
44
44
private InputStream getFileAsIOStream (final String fileName ) {
45
45
InputStream ioStream = this .getClass ()
@@ -56,6 +56,7 @@ private InputStream getFileAsIOStream(final String fileName) {
56
56
public void before () throws ApiException , IOException {
57
57
api = Mockito .mock (FingerprintApi .class );
58
58
when (api .getEvent (MOCK_REQUEST_ID )).thenReturn (fetchMockWithEventResponse ("mocks/get_event_200.json" ));
59
+ //when(api.getEvent(MOCK_REQUEST_ID)).thenReturn(fetchMockWithEventResponse("mocks/update_event_400_error.json"));
59
60
when (api .getEvent (MOCK_REQUEST_WITH_EXTRA_FIELDS_ID )).thenReturn (fetchMockWithEventResponse ("mocks/get_event_200_extra_fields.json" ));
60
61
when (api .getEvent (MOCK_REQUEST_WITH_ALL_FAILED_SIGNALS )).thenReturn (fetchMockWithEventResponse ("mocks/get_event_200_all_errors.json" ));
61
62
when (api .getEvent (MOCK_REQUEST_BOTD_FAILED )).thenReturn (fetchMockWithEventResponse ("mocks/get_event_200_botd_failed_error.json" ));
@@ -66,14 +67,21 @@ public void before() throws ApiException, IOException {
66
67
when (api .getVisits (MOCK_VISITOR_ID , MOCK_VISITOR_REQUEST_ID , null , 50 , "1683900801733.Ogvu1j" , null )).thenReturn (fetchMockVisit ());
67
68
}
68
69
69
- private EventResponse fetchMockWithEventResponse ( String fileName ) throws IOException {
70
+ private static ObjectMapper getMapper () {
70
71
ObjectMapper mapper = new ObjectMapper ().registerModule (new JavaTimeModule ());
71
72
mapper .setSerializationInclusion (JsonInclude .Include .NON_NULL );
72
73
mapper .configure (DeserializationFeature .FAIL_ON_UNKNOWN_PROPERTIES , false );
73
74
JsonNullableModule jnm = new JsonNullableModule ();
74
75
mapper .registerModule (jnm );
76
+ return mapper ;
77
+ }
78
+
79
+ private EventResponse fetchMockWithEventResponse (String fileName ) throws IOException {
80
+ return MAPPER .readValue (getFileAsIOStream (fileName ), EventResponse .class );
81
+ }
75
82
76
- return mapper .readValue (getFileAsIOStream (fileName ), EventResponse .class );
83
+ private <T > T fetchMock (String filename , Class <T > type ) throws IOException {
84
+ return MAPPER .readValue (getFileAsIOStream (filename ), type );
77
85
}
78
86
79
87
private Response fetchMockVisit () throws IOException {
@@ -119,6 +127,18 @@ public void getEventTest() throws ApiException {
119
127
assertEquals (true , signalResponseRawDeviceAttributes .getData ().get ("cookiesEnabled" ).getValue ());
120
128
}
121
129
130
+ @ Test
131
+ public void updateOneFieldEventRequest () throws ApiException , IOException {
132
+ EventUpdateRequest request = fetchMock ("mocks/update_event_one_field_request.json" , EventUpdateRequest .class );
133
+ api .updateEvent (MOCK_REQUEST_FOR_UPDATE , request );
134
+ }
135
+
136
+ @ Test
137
+ public void updateMultipleFieldsEventRequest () throws ApiException , IOException {
138
+ EventUpdateRequest request = fetchMock ("mocks/update_event_multiple_fields_request.json" , EventUpdateRequest .class );
139
+ api .updateEvent (MOCK_REQUEST_FOR_UPDATE , request );
140
+ }
141
+
122
142
/**
123
143
* Get event by requestId
124
144
* This endpoint allows you to get events with all the information from each activated product (Fingerprint Pro or Bot Detection). Use the requestId as a URL path :request_id parameter. This API method is scoped to a request, i.e. all returned information is by requestId.
0 commit comments