@@ -63,7 +63,7 @@ public void testFindByClassAndUser() throws ParseException {
6363
6464 unit .save ("tenant-1" ,"org-1" , risk , true );
6565
66- Collection <MongoRisk > found = unit .getRisksForUserAndClass ("tenant-1" ,"org-1" , "class-id" ,"user-id" , "" );
66+ Collection <MongoRisk > found = unit .getRisksForUserAndClass ("tenant-1" ,"org-1" , "class-id" ,"user-id" , "" , 0 );
6767 ArrayList <MongoRisk > list = new ArrayList <>(found );
6868
6969 assertThat (found , is (notNullValue ()));
@@ -74,7 +74,7 @@ public void testFindByClassAndUser() throws ParseException {
7474 @ Test
7575 public void testFindByClassAndUserAndDate () throws ParseException {
7676 SimpleDateFormat sdf = new SimpleDateFormat ("yyyy-MM-dd HH:mm" );
77- Instant date = sdf .parse ("2019-02-25 08:00" ).toInstant ();
77+ Instant date = sdf .parse ("2019-02-24 08:00" ).toInstant ();
7878
7979 MongoRisk risk = new MongoRisk .Builder ()
8080 .withClassSourcedId ("class-id" )
@@ -85,7 +85,7 @@ public void testFindByClassAndUserAndDate() throws ParseException {
8585 .build ();
8686 unit .save ("tenant-1" ,"org-1" , risk , true );
8787
88- date = sdf .parse ("2019-02-25 18:00" ).toInstant ();
88+ date = sdf .parse ("2019-02-26 18:00" ).toInstant ();
8989 risk = new MongoRisk .Builder ()
9090 .withClassSourcedId ("class-id" )
9191 .withUserSourcedId ("user-id" )
@@ -106,22 +106,21 @@ public void testFindByClassAndUserAndDate() throws ParseException {
106106 unit .save ("tenant-1" ,"org-1" , risk , true );
107107
108108
109- Collection <MongoRisk > found = unit .getRisksForUserAndClass ("tenant-1" , "org-1" , "class-id" , "user-id" , "" );
109+ Collection <MongoRisk > found = unit .getRisksForUserAndClass ("tenant-1" , "org-1" , "class-id" , "user-id" , "" , 0 );
110110 ArrayList <MongoRisk > list = new ArrayList <>(found );
111111
112112
113113 assertThat (found , is (notNullValue ()));
114114 assertThat (list .size (), is (4 ));
115115
116-
117- found = unit .getRisksForUserAndClass ("tenant-1" , "org-1" , "class-id" , "user-id" , "2019-02-25 05:00" );
118- list = new ArrayList <>(found );
116+ found = unit .getRisksForUserAndClass ("tenant-1" , "org-1" , "class-id" , "user-id" , "2019-02-25" , 0 );
117+ list = new ArrayList <>(found );
119118
120119 assertThat (found , is (notNullValue ()));
121120 assertThat (list .get (0 ).getName (), containsString ("5am" ));
122121 assertThat (list .size (), is (1 ));
123122
124- found = unit .getRisksForUserAndClass ("tenant-1" , "org-1" , "class-id" , "user-id" , "latest" );
123+ found = unit .getRisksForUserAndClass ("tenant-1" , "org-1" , "class-id" , "user-id" , "latest" , 0 );
125124
126125 list = new ArrayList <>(found );
127126
@@ -132,4 +131,48 @@ public void testFindByClassAndUserAndDate() throws ParseException {
132131 }
133132
134133
134+ @ Test
135+ public void testFindByClassLimit () throws ParseException {
136+ SimpleDateFormat sdf = new SimpleDateFormat ("yyyy-MM-dd HH:mm" );
137+ Instant date = sdf .parse ("2019-03-22 15:38" ).toInstant ();
138+
139+ MongoRisk risk = new MongoRisk .Builder ()
140+ .withClassSourcedId ("class-id" )
141+ .withUserSourcedId ("user-id" )
142+ .withScore ("80/100" )
143+ .withName ("First risk" )
144+ .withDateTime (date )
145+ .withVelocity ("-1" )
146+ .build ();
147+
148+ Instant date2 = sdf .parse ("2019-03-28 15:38" ).toInstant ();
149+ MongoRisk risk2 = new MongoRisk .Builder ()
150+ .withClassSourcedId ("class-id" )
151+ .withUserSourcedId ("user-id" )
152+ .withScore ("0.8" )
153+ .withName ("Second risk" )
154+ .withDateTime (date2 )
155+ .withVelocity ("1" )
156+ .build ();
157+
158+ Instant date3 = sdf .parse ("2020-03-28 15:38" ).toInstant ();
159+ MongoRisk risk3 = new MongoRisk .Builder ()
160+ .withClassSourcedId ("class-id" )
161+ .withUserSourcedId ("user-id" )
162+ .withName ("Third risk" )
163+ .withDateTime (date3 )
164+ .withVelocity ("0.5" )
165+ .build ();
166+
167+ unit .save ("tenant-1" ,"org-1" , risk , true );
168+ unit .save ("tenant-1" ,"org-1" , risk2 , true );
169+ unit .save ("tenant-1" ,"org-1" , risk3 , true );
170+
171+ Collection <MongoRisk > found = unit .getRisksForUserAndClass ("tenant-1" ,"org-1" , "class-id" ,"user-id" , "" ,2 );
172+ ArrayList <MongoRisk > list = new ArrayList <>(found );
173+
174+ assertThat (found , is (notNullValue ()));
175+ assertThat (list .size (), is (equalTo (2 )));
176+
177+ }
135178}
0 commit comments