11package io .getstream .client ;
22
3+ import com .google .common .collect .ImmutableMap ;
34import io .getstream .core .http .OKHTTPClientAdapter ;
45import io .getstream .core .models .Activity ;
56import io .getstream .core .models .FeedID ;
89import okhttp3 .OkHttpClient ;
910import org .junit .jupiter .api .Test ;
1011
11- import java .util .Date ;
12+ import java .text .SimpleDateFormat ;
13+ import java .util .*;
1214
1315import static org .junit .jupiter .api .Assertions .assertDoesNotThrow ;
1416
@@ -19,84 +21,105 @@ class BatchClientTest {
1921 @ Test
2022 void addToMany () {
2123 assertDoesNotThrow (() -> {
22- Client client = Client .builder (apiKey , secret )
23- .httpClient (new OKHTTPClientAdapter (new OkHttpClient ()))
24- .build ();
24+ Client client = Client .builder (apiKey , secret ).build ();
2525
2626 Activity activity = Activity .builder ()
2727 .actor ("test" )
2828 .verb ("test" )
2929 .object ("test" )
3030 .build ();
31+
3132 client .batch ().addToMany (activity , new FeedID []{
3233 new FeedID ("flat" , "1" ),
3334 new FeedID ("flat" , "2" )
34- });
35+ }). join () ;
3536 });
3637 }
3738
3839 @ Test
3940 void followMany () {
4041 assertDoesNotThrow (() -> {
41- BatchClient client = Client .builder (apiKey , secret )
42- .httpClient (new OKHTTPClientAdapter (new OkHttpClient ()))
43- .build ()
44- .batch ();
42+ BatchClient client = Client .builder (apiKey , secret ).build ().batch ();
4543
46- client .followMany (0 , new FollowRelation ("flat:1" , "flat:2" ), new FollowRelation ("aggregated:1" , "flat:1" ));
44+ client .followMany (0 , new FollowRelation []{
45+ new FollowRelation ("flat:1" , "flat:2" ),
46+ new FollowRelation ("aggregated:1" , "flat:1" )
47+ }).join ();
4748 });
4849 }
4950
5051 @ Test
5152 void unfollowMany () {
5253 assertDoesNotThrow (() -> {
53- BatchClient client = Client .builder (apiKey , secret )
54- .httpClient (new OKHTTPClientAdapter (new OkHttpClient ()))
55- .build ()
56- .batch ();
54+ BatchClient client = Client .builder (apiKey , secret ).build ().batch ();
5755
58- client .unfollowMany (new FollowRelation ("flat:1" , "flat:2" ), new FollowRelation ("aggregated:1" , "flat:1" ));
56+ client .unfollowMany (new FollowRelation []{
57+ new FollowRelation ("flat:1" , "flat:2" ),
58+ new FollowRelation ("aggregated:1" , "flat:1" )
59+ }).join ();
5960 });
6061 }
6162
6263 @ Test
6364 void updateActivities () {
6465 assertDoesNotThrow (() -> {
65- BatchClient client = Client .builder (apiKey , secret )
66- .httpClient (new OKHTTPClientAdapter (new OkHttpClient ()))
67- .build ()
68- .batch ();
66+ BatchClient client = Client .builder (apiKey , secret ).build ().batch ();
6967
7068 client .updateActivities (Activity .builder ()
71- .id ("54a60c1e-4ee3-494b-a1e3-50c06acb5ed4" )
7269 .actor ("test" )
7370 .verb ("test" )
7471 .object ("test" )
75- .build ());
72+ .foreignID ("foreignID" )
73+ .time (new Date ())
74+ .build ()).join ();
75+ });
76+ }
77+
78+ @ Test
79+ void partiallyUpdateActivityByID () {
80+ Activity [] result = new Activity [1 ];
81+ assertDoesNotThrow (() -> {
82+ Client client = Client .builder (apiKey , secret ).build ();
83+
84+ Map <String , Object > set = ImmutableMap .of ("value" , "message" );
85+ Iterable <String > unset = Collections .emptyList ();
86+ result [0 ] = client .updateActivityByID ("1657b300-a648-11d5-8080-800020fde6c3" , set , unset ).join ();
87+ });
88+ }
89+
90+ @ Test
91+ void partiallyUpdateActivityByForeignID () {
92+ Activity [] result = new Activity [1 ];
93+ assertDoesNotThrow (() -> {
94+ Client client = Client .builder (apiKey , secret ).build ();
95+
96+ SimpleDateFormat isoFormat = new SimpleDateFormat ("yyyy-MM-dd'T'HH:mm:ss.S" );
97+ isoFormat .setTimeZone (TimeZone .getTimeZone ("UTC" ));
98+ Date time = isoFormat .parse ("2001-09-11T00:01:02.000000" );
99+
100+ Map <String , Object > set = ImmutableMap .of ("value" , "message" );
101+ Iterable <String > unset = Collections .emptyList ();
102+ result [0 ] = client .updateActivityByForeignID (new ForeignIDTimePair ("foreignID" , time ), set , unset ).join ();
76103 });
77104 }
78105
79106 @ Test
80107 void getActivitiesByID () {
108+ List <Activity >[] result = new List [1 ];
81109 assertDoesNotThrow (() -> {
82- BatchClient client = Client .builder (apiKey , secret )
83- .httpClient (new OKHTTPClientAdapter (new OkHttpClient ()))
84- .build ()
85- .batch ();
110+ BatchClient client = Client .builder (apiKey , secret ).build ().batch ();
86111
87- client .getActivitiesByID ("54a60c1e-4ee3-494b-a1e3-50c06acb5ed4" );
112+ result [ 0 ] = client .getActivitiesByID ("1657b300-a648-11d5-8080-800020fde6c3" ). join ( );
88113 });
89114 }
90115
91116 @ Test
92117 void getActivitiesByForeignID () {
118+ List <Activity >[] result = new List [1 ];
93119 assertDoesNotThrow (() -> {
94- BatchClient client = Client .builder (apiKey , secret )
95- .httpClient (new OKHTTPClientAdapter (new OkHttpClient ()))
96- .build ()
97- .batch ();
120+ BatchClient client = Client .builder (apiKey , secret ).build ().batch ();
98121
99- client .getActivitiesByForeignID (new ForeignIDTimePair ("foreignID" , new Date ()));
122+ result [ 0 ] = client .getActivitiesByForeignID (new ForeignIDTimePair ("foreignID" , new Date ())). join ( );
100123 });
101124 }
102125}
0 commit comments