1919import java .util .Arrays ;
2020import java .util .HashSet ;
2121
22+ import org .geotools .geometry .jts .ReferencedEnvelope ;
23+ import org .geotools .referencing .crs .DefaultGeographicCRS ;
2224import org .junit .Test ;
2325import org .junit .runner .RunWith ;
26+ import org .locationtech .jts .geom .Envelope ;
2427import org .locationtech .udig .catalog .IGeoResource ;
2528import org .locationtech .udig .catalog .IGeoResourceInfo ;
2629import org .locationtech .udig .catalog .IService ;
@@ -39,6 +42,8 @@ public class CatalogImplTest {
3942
4043 private static final String NOT_MATCHING_TEXT = "whatever" ;
4144
45+ private static final Envelope ENVELOPE = new Envelope (15 , 17 , -5 , 5 );
46+
4247 private static final String MATCHING_TEXT = "test" ;
4348
4449 private final AST testAST = ASTFactory .parse (MATCHING_TEXT );
@@ -75,14 +80,59 @@ public void checkIsTrueIfResourceInfoTitleMatch() throws Exception {
7580 }
7681
7782 @ Test
78- public void checkIsTrueIfResourceInfoNameMatch () throws Exception {
83+ public void checkWithEnvelopeIsTrueIfResourceInfoNameMatch () throws Exception {
7984 when (geoResourceInfo .getTitle ()).thenReturn (NOT_MATCHING_TEXT );
8085 when (geoResourceInfo .getName ()).thenReturn (MATCHING_TEXT );
8186 when (geoResource .getInfo (any ())).thenReturn (geoResourceInfo );
8287
8388 assertTrue (CatalogImpl .check (geoResource , testAST ));
8489 }
8590
91+ @ Test
92+ public void checkWithEnvelopeIsTrueIfResourceInfoNameMatchAndEnvelopeIsNull () throws Exception {
93+ when (geoResourceInfo .getTitle ()).thenReturn (NOT_MATCHING_TEXT );
94+ when (geoResourceInfo .getName ()).thenReturn (MATCHING_TEXT );
95+ when (geoResource .getInfo (any ())).thenReturn (geoResourceInfo );
96+
97+ assertTrue (CatalogImpl .check (geoResource , testAST , null ));
98+ }
99+
100+ @ Test
101+ public void checkWithEnvelopeIsTrueIfResourceInfoNameMatchAndInfoBoundsisNull ()
102+ throws Exception {
103+ when (geoResourceInfo .getTitle ()).thenReturn (MATCHING_TEXT );
104+ when (geoResourceInfo .getBounds ()).thenReturn (null );
105+ when (geoResource .getInfo (any ())).thenReturn (geoResourceInfo );
106+
107+ assertTrue (CatalogImpl .check (geoResource , testAST , ENVELOPE ));
108+ }
109+
110+ @ Test
111+ public void checkWithEnvelopeIsTrueIfResourceInfoNameMatchAndInfoWithBounds () throws Exception {
112+ when (geoResourceInfo .getTitle ()).thenReturn (MATCHING_TEXT );
113+ when (geoResourceInfo .getBounds ())
114+ .thenReturn (new ReferencedEnvelope (10 , 20 , -10 , 10 , DefaultGeographicCRS .WGS84 ));
115+ when (geoResource .getInfo (any ())).thenReturn (geoResourceInfo );
116+
117+ assertTrue (CatalogImpl .check (geoResource , testAST , ENVELOPE ));
118+ }
119+
120+ @ Test
121+ public void checkWithEnvelopeIsFalseWithGeoResource () {
122+ IGeoResource nullGeoResource = null ;
123+ assertFalse (CatalogImpl .check (nullGeoResource , testAST , null ));
124+ }
125+
126+ @ Test
127+ public void checkIsTrueIfResourceInfoNameMatchAndEnvelopeIsNullCheck () throws Exception {
128+ Envelope envelope = new Envelope ();
129+ when (geoResourceInfo .getTitle ()).thenReturn (NOT_MATCHING_TEXT );
130+ when (geoResourceInfo .getName ()).thenReturn (MATCHING_TEXT );
131+ when (geoResource .getInfo (any ())).thenReturn (geoResourceInfo );
132+
133+ assertTrue (CatalogImpl .check (geoResource , testAST , envelope ));
134+ }
135+
86136 @ Test
87137 public void checkIsTrueIfResourceInfoAtLeastOneKeywordMatch () throws Exception {
88138 when (geoResourceInfo .getTitle ()).thenReturn (NOT_MATCHING_TEXT );
@@ -185,8 +235,7 @@ public void checkIsTrueIfServiceInfoAbstractMatch() throws Exception {
185235 @ Test
186236 public void checkIsTrueIfServiceInfoDescriptionMatch () throws Exception {
187237 when (serviceInfo .getTitle ()).thenReturn (NOT_MATCHING_TEXT );
188- when (serviceInfo .getDescription ())
189- .thenReturn (MATCHING_TEXT );
238+ when (serviceInfo .getDescription ()).thenReturn (MATCHING_TEXT );
190239 when (serviceMock .getInfo (null )).thenReturn (serviceInfo );
191240
192241 assertTrue (CatalogImpl .check (serviceMock , testAST ));
@@ -195,8 +244,7 @@ public void checkIsTrueIfServiceInfoDescriptionMatch() throws Exception {
195244 @ Test
196245 public void checkIsFalseIfServiceNotMatchAnything () throws Exception {
197246 when (serviceInfo .getTitle ()).thenReturn (NOT_MATCHING_TEXT );
198- when (serviceInfo .getDescription ())
199- .thenReturn (NOT_MATCHING_TEXT );
247+ when (serviceInfo .getDescription ()).thenReturn (NOT_MATCHING_TEXT );
200248 when (serviceMock .getInfo (null )).thenReturn (serviceInfo );
201249
202250 assertFalse (CatalogImpl .check (serviceMock , testAST ));
0 commit comments