Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.sitmun.proxy.middleware.protocols.http;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.lenient;
import static org.mockito.Mockito.when;

import org.junit.jupiter.api.BeforeEach;
Expand All @@ -27,63 +28,50 @@ void setUp() {

@Test
@DisplayName("Should accept when context is payload with POST method and non-null body")
void shouldAcceptWhenContextIsWmsPayloadDtoWithPostMethodAndNonNullBody() {
// Given
void shouldAcceptWhenContextIsHttpContextWithPostMethodAndNonNullBody() {
when(httpContext.getMethod()).thenReturn("POST");
when(httpContext.getBody()).thenReturn("<request>data</request>");

// When
boolean result = decorator.accept(requestExecutor, httpContext);

// Then
assertThat(result).isTrue();
}

@Test
@DisplayName("Should not accept when context is payload with GET method")
void shouldNotAcceptWhenContextIsWmsPayloadDtoWithGetMethod() {
// Given
void shouldNotAcceptWhenContextIsHttpContextWithGetMethod() {
when(httpContext.getMethod()).thenReturn("GET");

// When
boolean result = decorator.accept(requestExecutor, httpContext);

// Then
assertThat(result).isFalse();
}

@Test
@DisplayName("Should not accept when context is payload with POST method but null body")
void shouldNotAcceptWhenContextIsWmsPayloadDtoWithPostMethodButNullBody() {
// Given
void shouldNotAcceptWhenContextIsHttpContextWithPostMethodButNullBody() {
when(httpContext.getMethod()).thenReturn("POST");
when(httpContext.getBody()).thenReturn(null);

// When
boolean result = decorator.accept(requestExecutor, httpContext);

// Then
assertThat(result).isFalse();
}

@Test
@DisplayName("Should accept when context is payload with POST method and empty body")
void shouldAcceptWhenContextIsWmsPayloadDtoWithPostMethodAndEmptyBody() {
// Given
void shouldAcceptWhenContextIsHttpContextWithPostMethodAndEmptyBody() {
when(httpContext.getMethod()).thenReturn("POST");
when(httpContext.getBody()).thenReturn("");

// When
boolean result = decorator.accept(requestExecutor, httpContext);

// Then
assertThat(result).isTrue(); // Implementation only checks for != null, not empty
assertThat(result).isTrue();
}

@Test
@DisplayName("Should handle XML body with complex structure")
void shouldHandleXmlBodyWithComplexStructure() {
// Given
String body =
"""
<?xml version="1.0" encoding="UTF-8"?>
Expand All @@ -109,62 +97,20 @@ void shouldHandleXmlBodyWithComplexStructure() {

when(httpContext.getBody()).thenReturn(body);

// When
decorator.addBehavior(requestExecutor, httpContext);

// Then
assertThat(requestExecutor.getHeader("Content-Type")).isEqualTo("application/xml");
assertThat(requestExecutor).extracting("body").isEqualTo(body);
}

@Test
@DisplayName("Should handle XML body with CDATA sections")
void shouldHandleXmlBodyWithCdataSections() {
// Given
String body =
"<request><data><![CDATA[<html><body>This is HTML content</body></html>]]></data></request>";
when(httpContext.getBody()).thenReturn(body);
@DisplayName("Should reject a lowercase post method")
void shouldRejectLowercasePostMethod() {
when(httpContext.getMethod()).thenReturn("post");
lenient().when(httpContext.getBody()).thenReturn("<request>data</request>");

// When
decorator.addBehavior(requestExecutor, httpContext);

// Then
assertThat(requestExecutor.getHeader("Content-Type")).isEqualTo("application/xml");
}

@Test
@DisplayName("Should handle XML body with namespaces")
void shouldHandleXmlBodyWithNamespaces() {
// Given
String body =
"""
<wms:GetMap xmlns:wms="http://www.opengis.net/wms" xmlns:ogc="http://www.opengis.net/ogc">
<wms:Layer>test-layer</wms:Layer>
<ogc:Filter>
<ogc:PropertyIsEqualTo>
<ogc:PropertyName>status</ogc:PropertyName>
<ogc:Literal>active</ogc:Literal>
</ogc:PropertyIsEqualTo>
</ogc:Filter>
</wms:GetMap>""";
when(httpContext.getBody()).thenReturn(body);

// When
decorator.addBehavior(requestExecutor, httpContext);

// Then
assertThat(requestExecutor.getHeader("Content-Type")).isEqualTo("application/xml");
}

@Test
@DisplayName("Should handle case-insensitive method comparison")
void shouldHandleCaseInsensitiveMethodComparison() {
// Given
when(httpContext.getMethod()).thenReturn("post"); // lowercase

// When
boolean result = decorator.accept(requestExecutor, httpContext);

// Then
assertThat(result).isFalse(); // Should be false because it's case-sensitive
assertThat(result).isFalse();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,4 @@ void jdbcAccess() {
Object body = response.getBody();
assertThat(body).isNotNull().asInstanceOf(InstanceOfAssertFactories.LIST).hasSize(35);
}

/** Public user access to a relational service filtered. */
@Test
@DisplayName("Request to a JDBC service with filters")
@Disabled(
"Redundant test: the test is identical to jdbcAccess because the SQL query is built on the Configuration and Authorization API")
void jdbcAccessWithFilters() {
ResponseEntity<Object> response =
requestExecutorService.executeRequest("", inMemoryH2Database(false));
assertThat(response.getStatusCode().value()).isEqualTo(200);
assertThat(Objects.requireNonNull(response.getHeaders().get("Content-Type")).get(0))
.isEqualTo("application/json");
Object body = response.getBody();
assertThat(body).isNotNull().asInstanceOf(InstanceOfAssertFactories.LIST).hasSize(35);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,19 +128,4 @@ void jdbcAccess() {
Object body = response.getBody();
assertThat(body).isNotNull().asInstanceOf(InstanceOfAssertFactories.LIST).hasSize(35);
}

/** Public user access to a relational service filtered. */
@Test
@DisplayName("Request to a JDBC service with filters")
@Disabled(
"Redundant test: the test is identical to jdbcAccess because the SQL query is built on the Configuration and Authorization API")
void jdbcAccessWithFilters() {
ResponseEntity<Object> response =
requestExecutorService.executeRequest("", inMemoryH2Database(false));
assertThat(response.getStatusCode().value()).isEqualTo(200);
assertThat(Objects.requireNonNull(response.getHeaders().get("Content-Type")).get(0))
.isEqualTo("application/json");
Object body = response.getBody();
assertThat(body).isNotNull().asInstanceOf(InstanceOfAssertFactories.LIST).hasSize(35);
}
}
Loading