Skip to content

Commit

Permalink
Protocol tests generation stub and cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyRyabinin committed Jan 27, 2025
1 parent 9f269b4 commit fa7096d
Show file tree
Hide file tree
Showing 20 changed files with 843 additions and 33 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ if (LEGACY_BUILD)
option(USE_TLS_V1_2 "Set http client to enforce TLS 1.2" ON)
option(USE_TLS_V1_3 "Set http client to enforce TLS 1.3" OFF)
option(ENABLE_SMOKE_TESTS "Enable smoke tests" OFF)
option(ENABLE_PROTOCOL_TESTS "Enable protocol tests" OFF)
option(DISABLE_DNS_REQUIRED_TESTS "Disable unit tests that require DNS lookup to succeed, useful when using a http client that does not perform DNS lookup" OFF)


Expand Down Expand Up @@ -267,7 +268,6 @@ if (LEGACY_BUILD)
set_msvc_warnings()

include(sdks)

include(utilities)

if (ENABLE_OPENSSL_ENCRYPTION)
Expand Down Expand Up @@ -338,6 +338,7 @@ if (LEGACY_BUILD)
add_definitions("-DAWS_TEST_REGION=${AWS_TEST_REGION}")

add_sdks()
include(tests)

# for user friendly cmake usage
include(setup_cmake_find_module)
Expand Down
35 changes: 35 additions & 0 deletions cmake/tests.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0.
#

function(add_protocol_tests)
set(PROTOCOL_TESTS_LOG "")
# Add test clients, which are just like a regular SDK client, but must not be installed.
file(GLOB subdirs LIST_DIRECTORIES true "${CMAKE_SOURCE_DIR}/generated/protocol-tests/test-clients/*")
foreach(subdir ${subdirs})
if(EXISTS "${subdir}/CMakeLists.txt")
add_subdirectory(${subdir} EXCLUDE_FROM_ALL)
endif()
endforeach()

# Add tests
file(GLOB protoTestTypes LIST_DIRECTORIES true "${CMAKE_SOURCE_DIR}/generated/protocol-tests/tests/*")
foreach(protoTestType ${protoTestTypes})
file(GLOB subdirs LIST_DIRECTORIES true ${protoTestType}/*)
foreach(subdir ${subdirs})
if(EXISTS "${subdir}/CMakeLists.txt")
add_subdirectory(${subdir})

get_filename_component(testGroup ${protoTestType} NAME)
get_filename_component(testName ${subdir} NAME)
list(APPEND PROTOCOL_TESTS_LOG "${testGroup}/${testName}")
endif()
endforeach()
endforeach()

message(STATUS "Protocol tests: ${PROTOCOL_TESTS_LOG}")
endfunction()

if (ENABLE_PROTOCOL_TESTS)
add_protocol_tests()
endif ()
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/

package com.amazonaws.util.awsclientgenerator.domainmodels.c2j_protocol_test;

import lombok.Data;

@Data
public class C2jGiven {
@Data
public static class C2jGivenHttp {
private String method;
private String requestUri;
}

@Data
public static class C2jGivenInput {
private String shape;
private String locationName;
}

@Data
public static class C2jGivenEndpoint {
private String hostPrefix;
}

private String name;
private C2jGivenHttp http;
private C2jGivenInput input;
private C2jGivenEndpoint endpoint;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/

package com.amazonaws.util.awsclientgenerator.domainmodels.c2j_protocol_test;

import lombok.Data;

import java.util.List;
import java.util.Map;

@Data
public class C2jInputSerialized {
/**
* The HTTP method.
*/
private String method;
/**
* The HTTP body as a string.
*/
private String body;
/**
* The uri path and querystring of the request.
*/
private String uri;
/**
* The URL host of the request.
*/
private String host;
/**
* Any HTTP headers for the HTTP request.
*/
private Map<String, String> headers;
/**
* A list of header names that must not exist in the HTTP Request.
*/
private List<String> forbidHeaders;
/**
* A list of header names that must exist in the HTTP Request.
*/
private List<String> requireHeaders;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/

package com.amazonaws.util.awsclientgenerator.domainmodels.c2j_protocol_test;

import com.fasterxml.jackson.databind.JsonNode;
import lombok.Data;

@Data
public class C2jInputTestCase {
/**
* A test case id.
*/
private String id;
/**
* A test case description.
*/
private String description;
/**
* This corresponds to the JSON object that would define an operation in the service's JSON model.
* Valid keys include http, input, endpoint, and name.
*/
private C2jGiven given;
/**
* The input parameters a user would provide.
*/
private JsonNode params;

/**
* The expected serialized HTTP request.
*/
private C2jInputSerialized serialized;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/

package com.amazonaws.util.awsclientgenerator.domainmodels.c2j_protocol_test;


import com.amazonaws.util.awsclientgenerator.domainmodels.c2j.C2jMetadata;
import com.amazonaws.util.awsclientgenerator.domainmodels.c2j.C2jShape;
import lombok.Data;

import java.util.List;
import java.util.Map;

@Data
public class C2jInputTestSuite {
/**
* A description of the tests
*/
private String description;
/**
* The top level metadata that would correspond to the metadata key in the service's JSON model.
*/
private C2jMetadata metadata;
/**
* An URL string the test cases must use when constructing the request's URL endpoint.
*/
private String clientEndpoint;
/**
* A JSON object of shapes. This would correspond to the top level shapes key in the service's JSON model.
*/
private Map<String, C2jShape> shapes;
/**
* a JSON list of test cases.
*/
private List<C2jInputTestCase> cases;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/

package com.amazonaws.util.awsclientgenerator.domainmodels.c2j_protocol_test;

import lombok.Data;

import java.util.Map;

@Data
public class C2jOutputResponse {
int status_code;
private Map<String, String> headers;
private String body;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/

package com.amazonaws.util.awsclientgenerator.domainmodels.c2j_protocol_test;

import com.fasterxml.jackson.databind.JsonNode;
import lombok.Data;

@Data
public class C2jOutputTestCase {
/**
* A test case id.
*/
private String id;
/**
* A test case description.
*/
private String description;
/**
* This corresponds to the JSON object that would define an operation in the service's JSON model.
* Valid keys include http, input, endpoint, and name.
*/
private C2jGiven given;
/**
* A JSON hash representing the structure of the parsed response. Either this or error (not both) must appear in the test case.
*/
private JsonNode result;
/**
* A JSON hash representing the structure of the parsed error response. Either this or result (not both) must appear in the test case.
*/
private JsonNode error;
/**
* A string specifying the AWS error code extracted from the response. Corresponds to the error shape to be unmarshalled and
* should always be set, even when the shape can not be found. Must be present when the error key is present.
*/
private String errorCode;
/**
* A string specifying the error message extracted from the response.
* Should be able to be extracted even when an error shape is not unmarshalled. May only be present when the error key is present.
*/
private String errorMessage;
/**
* The HTTP response to be parsed
*/
private C2jOutputResponse response;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/

package com.amazonaws.util.awsclientgenerator.domainmodels.c2j_protocol_test;

import com.amazonaws.util.awsclientgenerator.domainmodels.c2j.C2jMetadata;
import com.amazonaws.util.awsclientgenerator.domainmodels.c2j.C2jShape;
import lombok.Data;

import java.util.List;
import java.util.Map;

@Data
public class C2jOutputTestSuite {
/**
* A description of the tests
*/
private String description;
/**
* The top level metadata that would correspond to the metadata key in the service's JSON model.
*/
private C2jMetadata metadata;
/**
* A URL string the test cases must use when constructing the request's URL endpoint.
*/
private String clientEndpoint;
/**
* A JSON object of C2jShapes. This would correspond to the top level C2jShapes key in the service's JSON model.
*/
private Map<String, C2jShape> shapes;
/**
* a JSON list of test cases.
*/
private List<C2jOutputTestCase> cases;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/

package com.amazonaws.util.awsclientgenerator.domainmodels.c2j_protocol_test;

import com.amazonaws.util.awsclientgenerator.domainmodels.c2j.C2jMetadata;
import com.amazonaws.util.awsclientgenerator.domainmodels.c2j.C2jShape;
import lombok.Data;

import java.util.List;
import java.util.Map;

@Data
public class C2jTestSuite {
private String name;
private String serviceToUse;
public enum TestSuiteType {
INPUT,
OUTPUT
}
TestSuiteType type; // only can be present.
private List<C2jInputTestSuite> inputTestSuites;
private List<C2jOutputTestSuite> outputTestSuites;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/

package com.amazonaws.util.awsclientgenerator.domainmodels.c2j;


import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;

import java.lang.reflect.Type;

/**
* A helper for gson parser to deserialize raw JSON entry in the protocol test definition to a "Jackson.JsonNode"
*/
public class JsonNodeDeserializer implements JsonDeserializer<JsonNode> {
@Override
public JsonNode deserialize(JsonElement jsonElement, Type type,
JsonDeserializationContext context) throws JsonParseException {
ObjectMapper objectMapper = new ObjectMapper();
JsonNode jsonNode = null;
try {
jsonNode = objectMapper.readValue(jsonElement.getAsJsonObject().toString(), JsonNode.class);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
return jsonNode;
}
}
Loading

0 comments on commit fa7096d

Please sign in to comment.