Skip to content

Commit

Permalink
Added tests for endpoint examples
Browse files Browse the repository at this point in the history
  • Loading branch information
robtimus committed Aug 8, 2023
1 parent 222d409 commit 1c127a5
Showing 1 changed file with 86 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.ValueSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringBootConfiguration;
Expand Down Expand Up @@ -163,6 +166,25 @@ void testWithAuthorizationType() {

assertSignatureCalculation(authenticator, apiKeyId, secretApiKey);
}

@ParameterizedTest
@ValueSource(strings = {
"{\"apiKeyId\": \"myApiKeyId\", \"secretApiKey\": \"mySecretKeyId\"}",
"{\"apiKeyId\": \"myApiKeyId\", \"secretApiKey\": \"mySecretKeyId\", \"authorizationType\": \"V1HMAC\"}"
})
void testExample(String requestBody) {
RequestEntity<String> request = RequestEntity
.post(getActuatorURI())
.contentType(MediaType.APPLICATION_JSON)
.body(requestBody);

ResponseEntity<Void> response = restTemplateBuilder
.build()
.exchange(request, Void.class);

assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode());
assertNull(response.getBody());
}
}
}

Expand Down Expand Up @@ -394,6 +416,31 @@ void testWithExplicitIdleTime() {
}
}
}

@ParameterizedTest
@ValueSource(strings = {
"connectSdkConnections",
"connectSdkConnections?idleTime=10000",
"connectSdkConnections?idleTime=10s",
"connectSdkConnections?state=idle&idleTime=10000",
"connectSdkConnections?state=expired",
"connectSdkConnections/mockConnection",
"connectSdkConnections/mockConnection?idleTime=10000",
"connectSdkConnections/mockConnection?idleTime=10s",
"connectSdkConnections/mockConnection?state=idle&idleTime=10000",
"connectSdkConnections/mockConnection?state=expired"
})
void testExample(String path) {
RequestEntity<Void> request = RequestEntity
.delete(getActuatorBaseURI().resolve(path))
.build();

ResponseEntity<Void> response = restTemplateBuilder
.build()
.exchange(request, Void.class);

assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode());
}
}

@Nested
Expand Down Expand Up @@ -548,6 +595,28 @@ void testWithRequestBody() {
verifyNoMoreInteractions(connection);
}
}

@ParameterizedTest
@CsvSource({
"connectSdkLogging,",
"connectSdkLogging?logger=mockLogger,",
"connectSdkLogging, {\"logger\": \"mockLogger\"}",
"connectSdkLogging/mockConnection,",
"connectSdkLogging/mockConnection?logger=mockLogger,",
"connectSdkLogging/mockConnection, {\"logger\": \"mockLogger\"}"
})
void testExample(String path, String requestBody) {
RequestEntity<String> request = RequestEntity
.post(getActuatorBaseURI().resolve(path))
.contentType(MediaType.APPLICATION_JSON)
.body(requestBody);

ResponseEntity<Void> response = restTemplateBuilder
.build()
.exchange(request, Void.class);

assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode());
}
}

@Nested
Expand Down Expand Up @@ -587,6 +656,23 @@ void testForSpecificBean() {
verify(connection).disableLogging();
verifyNoMoreInteractions(connection);
}

@ParameterizedTest
@CsvSource({
"connectSdkLogging",
"connectSdkLogging/mockConnection"
})
void testExample(String path) {
RequestEntity<Void> request = RequestEntity
.delete(getActuatorBaseURI().resolve(path))
.build();

ResponseEntity<Void> response = restTemplateBuilder
.build()
.exchange(request, Void.class);

assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode());
}
}
}

Expand Down

0 comments on commit 1c127a5

Please sign in to comment.