Skip to content

Commit 78fb486

Browse files
committed
✅ Add test for MongoRequest with path template mount with trailing *
1 parent 77e745b commit 78fb486

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

commons/src/test/java/org/restheart/exchange/MongoRequestTest.java

+28
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,34 @@ public void testPathTemplatedMappedRequest() {
245245
assertEquals("acme_coll", request.getCollectionName());
246246
}
247247

248+
/**
249+
*
250+
*/
251+
@Test
252+
public void testPathTemplatedMappedRequestWithWildcard() {
253+
var requestPath = "/acme/coll/docid";
254+
255+
// Here mimic MongoService that attach PathTemplateMatch to the exchange
256+
PathTemplateMatcher<MongoMount> templateMongoMounts = new PathTemplateMatcher<>();
257+
String whatUri = "/restheart/{tenant}_{coll}";
258+
String whereUri = "/{tenant}/{coll}/*";
259+
var mongoMount = new MongoMount(whatUri,whereUri);
260+
templateMongoMounts.add(mongoMount.uri, mongoMount);
261+
262+
var tmm = templateMongoMounts.match(requestPath);
263+
264+
HttpServerExchange ex = mock(HttpServerExchange.class);
265+
when(ex.getRequestPath()).thenReturn(requestPath);
266+
when(ex.getRequestMethod()).thenReturn(HttpString.EMPTY);
267+
when(ex.getAttachment(PathTemplateMatch.ATTACHMENT_KEY)).thenReturn(tmm);
268+
269+
MongoRequest request = MongoRequest.init(ex, whereUri, whatUri);
270+
271+
assertEquals("/restheart/acme_coll/docid", request.getUnmappedRequestUri());
272+
assertEquals("restheart", request.getDBName());
273+
assertEquals("acme_coll", request.getCollectionName());
274+
}
275+
248276
/**
249277
* helper class to store mongo mounts info
250278
*/

0 commit comments

Comments
 (0)