-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix off-by-one issue caused by ObservabilityIntegrationRecorder using…
… its own method for getting path without prefix
- Loading branch information
1 parent
7f3bd55
commit a669db3
Showing
5 changed files
with
75 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...va/io/quarkus/resteasy/reactive/runtime/mapping/ObservabilityIntegrationRecorderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package io.quarkus.resteasy.reactive.runtime.mapping; | ||
|
||
import io.quarkus.resteasy.reactive.server.runtime.observability.ObservabilityIntegrationRecorder; | ||
import io.vertx.ext.web.RoutingContext; | ||
import org.jboss.resteasy.reactive.server.core.Deployment; | ||
import org.jboss.resteasy.reactive.server.handlers.RestInitialHandler; | ||
import org.jboss.resteasy.reactive.server.mapping.RequestMapper; | ||
import org.jboss.resteasy.reactive.server.mapping.URITemplate; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.ArrayList; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class ObservabilityIntegrationRecorderTest { | ||
|
||
private static RoutingContext rc; | ||
private static Deployment deployment; | ||
|
||
@BeforeAll | ||
public static void setup() { | ||
rc = mock(RoutingContext.class); | ||
deployment = mock(Deployment.class); | ||
when(rc.normalizedPath()).thenReturn("/foo"); | ||
when(deployment.getClassMappers()).thenReturn(getRequestPaths()); | ||
} | ||
|
||
@Test | ||
public void testSetTemplatePathWithoutPathPrefixDoesNotThrow() { | ||
when(deployment.getPrefix()).thenReturn(""); | ||
assertDoesNotThrow(() -> ObservabilityIntegrationRecorder.setTemplatePath(rc, deployment), "Should not throw exception when prefix is not set"); | ||
} | ||
|
||
@Test | ||
public void testSetTemplatePathWithPathPrefixDoesNotThrow() { | ||
when(deployment.getPrefix()).thenReturn("/foo"); | ||
assertDoesNotThrow(() -> ObservabilityIntegrationRecorder.setTemplatePath(rc, deployment), "Should not throw exception when prefix is set"); | ||
} | ||
|
||
private static ArrayList<RequestMapper.RequestPath<RestInitialHandler.InitialMatch>> getRequestPaths() { | ||
RestInitialHandler.InitialMatch initialMatch = mock(RestInitialHandler.InitialMatch.class); | ||
ArrayList<RequestMapper.RequestPath<RestInitialHandler.InitialMatch>> classMappers = new ArrayList<>(); | ||
classMappers.add(new RequestMapper.RequestPath<>(true, new URITemplate("/", true), initialMatch)); | ||
classMappers.add(new RequestMapper.RequestPath<>(true, new URITemplate("{param}/bar", true), initialMatch)); | ||
return classMappers; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters