Search in sources :

Example 1 with GetSchemaVersionRequest

use of software.amazon.awssdk.services.glue.model.GetSchemaVersionRequest in project aws-glue-schema-registry by awslabs.

the class AWSSchemaRegistryClientTest method testWaitForSchemaEvolutionCheckToComplete_resultsAvailableResponse_returnsResponseWithSchemaId.

@Test
public void testWaitForSchemaEvolutionCheckToComplete_resultsAvailableResponse_returnsResponseWithSchemaId() throws NoSuchMethodException {
    GetSchemaVersionRequest getSchemaVersionRequest = GetSchemaVersionRequest.builder().schemaVersionId(SCHEMA_ID_FOR_TESTING.toString()).build();
    GetSchemaVersionResponse getSchemaVersionResponse = GetSchemaVersionResponse.builder().schemaVersionId(SCHEMA_ID_FOR_TESTING.toString()).schemaDefinition(userSchemaDefinition).status(AWSSchemaRegistryConstants.SchemaVersionStatus.AVAILABLE.toString()).build();
    when(mockGlueClient.getSchemaVersion(getSchemaVersionRequest)).thenReturn(getSchemaVersionResponse);
    Method waitForSchemaEvolutionCheckToCompleteMethod = AWSSchemaRegistryClient.class.getDeclaredMethod("waitForSchemaEvolutionCheckToComplete", GetSchemaVersionRequest.class);
    waitForSchemaEvolutionCheckToCompleteMethod.setAccessible(true);
    GetSchemaVersionResponse resultResponse = (GetSchemaVersionResponse) assertDoesNotThrow(() -> waitForSchemaEvolutionCheckToCompleteMethod.invoke(awsSchemaRegistryClient, getSchemaVersionRequest));
    assertEquals(SCHEMA_ID_FOR_TESTING.toString(), resultResponse.schemaVersionId());
}
Also used : GetSchemaVersionRequest(software.amazon.awssdk.services.glue.model.GetSchemaVersionRequest) Method(java.lang.reflect.Method) GetSchemaVersionResponse(software.amazon.awssdk.services.glue.model.GetSchemaVersionResponse) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with GetSchemaVersionRequest

use of software.amazon.awssdk.services.glue.model.GetSchemaVersionRequest in project aws-glue-schema-registry by awslabs.

the class UserAgentRequestInterceptorTest method test_UserAgentInterceptor_ReturnsSdkRequestWithUserAgent.

@ParameterizedTest
@MethodSource("getClientConfigTestCases")
void test_UserAgentInterceptor_ReturnsSdkRequestWithUserAgent(GlueSchemaRegistryConfiguration config, String expectedName) {
    AwsCredentialsProvider mockAwsCredentialsProvider = mock(AwsCredentialsProvider.class);
    AWSSchemaRegistryClient awsSchemaRegistryClient = new AWSSchemaRegistryClient(mockAwsCredentialsProvider, config);
    AWSSchemaRegistryClient.UserAgentRequestInterceptor userAgentRequestInterceptor = awsSchemaRegistryClient.new UserAgentRequestInterceptor();
    Context.ModifyRequest modifyRequest = mock(Context.ModifyRequest.class);
    GetSchemaVersionRequest glueRequest = GetSchemaVersionRequest.builder().build();
    doReturn(glueRequest).when(modifyRequest).request();
    SdkRequest sdkHttpRequest = userAgentRequestInterceptor.modifyRequest(modifyRequest, null);
    assertNotNull(sdkHttpRequest);
    assertTrue(sdkHttpRequest.overrideConfiguration().isPresent());
    ApiName actualApiName = sdkHttpRequest.overrideConfiguration().get().apiNames().get(0);
    assertEquals(MavenPackaging.VERSION, actualApiName.version());
    assertEquals(expectedName, actualApiName.name());
}
Also used : Context(software.amazon.awssdk.core.interceptor.Context) SdkRequest(software.amazon.awssdk.core.SdkRequest) ApiName(software.amazon.awssdk.core.ApiName) AwsCredentialsProvider(software.amazon.awssdk.auth.credentials.AwsCredentialsProvider) GetSchemaVersionRequest(software.amazon.awssdk.services.glue.model.GetSchemaVersionRequest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 3 with GetSchemaVersionRequest

use of software.amazon.awssdk.services.glue.model.GetSchemaVersionRequest in project aws-glue-schema-registry by awslabs.

the class AWSSchemaRegistryClientTest method testRegisterSchemaVersion_validParameters_returnsResponseWithSchemaVersionId.

@Test
public void testRegisterSchemaVersion_validParameters_returnsResponseWithSchemaVersionId() throws NoSuchFieldException, IllegalAccessException {
    awsSchemaRegistryClient = configureAWSSchemaRegistryClientWithSerdeConfig(awsSchemaRegistryClient, glueSchemaRegistryConfiguration);
    String schemaName = configs.get(AWSSchemaRegistryConstants.SCHEMA_NAME).toString();
    String registryName = configs.get(AWSSchemaRegistryConstants.REGISTRY_NAME).toString();
    String dataFormatName = DataFormat.AVRO.name();
    Long schemaVersionNumber = 1L;
    SchemaId requestSchemaId = SchemaId.builder().schemaName(schemaName).registryName(registryName).build();
    RegisterSchemaVersionRequest registerSchemaVersionRequest = RegisterSchemaVersionRequest.builder().schemaDefinition(userSchemaDefinition).schemaId(requestSchemaId).build();
    RegisterSchemaVersionResponse registerSchemaVersionResponse = RegisterSchemaVersionResponse.builder().schemaVersionId(SCHEMA_ID_FOR_TESTING.toString()).versionNumber(schemaVersionNumber).status(AWSSchemaRegistryConstants.SchemaVersionStatus.AVAILABLE.toString()).build();
    GetSchemaVersionRequest getSchemaVersionRequest = GetSchemaVersionRequest.builder().schemaVersionId(SCHEMA_ID_FOR_TESTING.toString()).build();
    when(mockGlueClient.registerSchemaVersion(registerSchemaVersionRequest)).thenReturn(registerSchemaVersionResponse);
    assertEquals(SCHEMA_ID_FOR_TESTING.toString(), awsSchemaRegistryClient.registerSchemaVersion(userSchemaDefinition, schemaName, dataFormatName).schemaVersionId());
    verify(mockGlueClient, times(0)).getSchemaVersion(getSchemaVersionRequest);
}
Also used : RegisterSchemaVersionRequest(software.amazon.awssdk.services.glue.model.RegisterSchemaVersionRequest) SchemaId(software.amazon.awssdk.services.glue.model.SchemaId) GetSchemaVersionRequest(software.amazon.awssdk.services.glue.model.GetSchemaVersionRequest) RegisterSchemaVersionResponse(software.amazon.awssdk.services.glue.model.RegisterSchemaVersionResponse) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with GetSchemaVersionRequest

use of software.amazon.awssdk.services.glue.model.GetSchemaVersionRequest in project aws-glue-schema-registry by awslabs.

the class AWSSchemaRegistryClientTest method testGetSchemaVersionResponse_setSchemaVersionId_returnsResponseSchemaVersionId.

@Test
public void testGetSchemaVersionResponse_setSchemaVersionId_returnsResponseSchemaVersionId() {
    GetSchemaVersionResponse getSchemaVersionResponse = GetSchemaVersionResponse.builder().schemaVersionId(SCHEMA_ID_FOR_TESTING.toString()).build();
    GetSchemaVersionRequest getSchemaVersionRequest = GetSchemaVersionRequest.builder().schemaVersionId(SCHEMA_ID_FOR_TESTING.toString()).build();
    when(mockGlueClient.getSchemaVersion(getSchemaVersionRequest)).thenReturn(getSchemaVersionResponse);
    assertEquals(SCHEMA_ID_FOR_TESTING.toString(), awsSchemaRegistryClient.getSchemaVersionResponse(SCHEMA_ID_FOR_TESTING.toString()).schemaVersionId());
}
Also used : GetSchemaVersionRequest(software.amazon.awssdk.services.glue.model.GetSchemaVersionRequest) GetSchemaVersionResponse(software.amazon.awssdk.services.glue.model.GetSchemaVersionResponse) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with GetSchemaVersionRequest

use of software.amazon.awssdk.services.glue.model.GetSchemaVersionRequest in project aws-glue-schema-registry by awslabs.

the class AWSSchemaRegistryClientTest method testGetSchemaVersionResponse_clientExceptionResponse_returnsAWSSchemaRegistryException.

@Test
public void testGetSchemaVersionResponse_clientExceptionResponse_returnsAWSSchemaRegistryException() {
    GetSchemaVersionRequest getSchemaVersionRequest = GetSchemaVersionRequest.builder().schemaVersionId(SCHEMA_ID_FOR_TESTING.toString()).build();
    when(mockGlueClient.getSchemaVersion(getSchemaVersionRequest)).thenThrow(EntityNotFoundException.class);
    try {
        awsSchemaRegistryClient.getSchemaVersionResponse(SCHEMA_ID_FOR_TESTING.toString());
    } catch (Exception e) {
        assertEquals(EntityNotFoundException.class, e.getCause().getClass());
        assertEquals(AWSSchemaRegistryException.class, e.getClass());
        String expectedErrorMessage = "Failed to get schema version Id = " + SCHEMA_ID_FOR_TESTING;
        assertEquals(expectedErrorMessage, e.getMessage());
    }
}
Also used : AWSSchemaRegistryException(com.amazonaws.services.schemaregistry.exception.AWSSchemaRegistryException) GetSchemaVersionRequest(software.amazon.awssdk.services.glue.model.GetSchemaVersionRequest) EntityNotFoundException(software.amazon.awssdk.services.glue.model.EntityNotFoundException) URISyntaxException(java.net.URISyntaxException) AWSSchemaRegistryException(com.amazonaws.services.schemaregistry.exception.AWSSchemaRegistryException) EntityNotFoundException(software.amazon.awssdk.services.glue.model.EntityNotFoundException) IOException(java.io.IOException) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

GetSchemaVersionRequest (software.amazon.awssdk.services.glue.model.GetSchemaVersionRequest)9 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)8 Test (org.junit.jupiter.api.Test)7 GetSchemaVersionResponse (software.amazon.awssdk.services.glue.model.GetSchemaVersionResponse)5 AWSSchemaRegistryException (com.amazonaws.services.schemaregistry.exception.AWSSchemaRegistryException)4 EntityNotFoundException (software.amazon.awssdk.services.glue.model.EntityNotFoundException)4 RegisterSchemaVersionRequest (software.amazon.awssdk.services.glue.model.RegisterSchemaVersionRequest)4 RegisterSchemaVersionResponse (software.amazon.awssdk.services.glue.model.RegisterSchemaVersionResponse)4 GlueSchemaRegistryConfiguration (com.amazonaws.services.schemaregistry.common.configs.GlueSchemaRegistryConfiguration)3 IOException (java.io.IOException)3 URISyntaxException (java.net.URISyntaxException)3 SchemaId (software.amazon.awssdk.services.glue.model.SchemaId)3 Method (java.lang.reflect.Method)2 UUID (java.util.UUID)1 EnumSource (org.junit.jupiter.params.provider.EnumSource)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1 AwsCredentialsProvider (software.amazon.awssdk.auth.credentials.AwsCredentialsProvider)1 ApiName (software.amazon.awssdk.core.ApiName)1 SdkRequest (software.amazon.awssdk.core.SdkRequest)1 Context (software.amazon.awssdk.core.interceptor.Context)1