in tools/code-generation/generator/src/main/java/com/amazonaws/util/awsclientgenerator/transform/C2jProtocolTestToGeneratorModelTransformer.java [41:120]
public ProtocolTestModel convert(C2jTestSuite c2jTestSuite) {
ProtocolTestModel model = new ProtocolTestModel();
model.setName(c2jTestSuite.getName());
model.setServiceToUse(c2jTestSuite.getServiceToUse());
model.setType(c2jTestSuite.getType());
model.setTestSuites(new ArrayList<ProtocolTestSuite>());
if (c2jTestSuite.getInputTestSuites() != null) {
for (C2jInputTestSuite inputTestSuite : c2jTestSuite.getInputTestSuites()) {
ProtocolTestSuite protocolTestSuite = new ProtocolTestSuite();
protocolTestSuite.setName(getTestSuiteName(inputTestSuite.getDescription()));
protocolTestSuite.setDescription(inputTestSuite.getDescription());
protocolTestSuite.setMetadata(inputTestSuite.getMetadata());
protocolTestSuite.setClientEndpoint(inputTestSuite.getClientEndpoint());
protocolTestSuite.setShapes(inputTestSuite.getShapes());
protocolTestSuite.setCases(new ArrayList<>());
for (C2jInputTestCase inputTestCase : inputTestSuite.getCases()) {
ProtocolTestCase testCase = new ProtocolTestCase();
testCase.setId(inputTestCase.getId());
testCase.setDescription(inputTestCase.getDescription());
testCase.setGiven(inputTestCase.getGiven());
Optional<ProtocolTestCase.Input> input = Optional.of(new ProtocolTestCase.Input());
input.get().setParams(inputTestCase.getParams());
input.get().setSerialized(inputTestCase.getSerialized());
testCase.setInput(input);
protocolTestSuite.getCases().add(testCase);
}
model.getTestSuites().add(protocolTestSuite);
}
}
if (c2jTestSuite.getOutputTestSuites() != null) {
for (C2jOutputTestSuite outputTestSuite : c2jTestSuite.getOutputTestSuites()) {
ProtocolTestSuite protocolTestSuite = new ProtocolTestSuite();
protocolTestSuite.setName(getTestSuiteName(outputTestSuite.getDescription()));
protocolTestSuite.setDescription(outputTestSuite.getDescription());
protocolTestSuite.setMetadata(outputTestSuite.getMetadata());
protocolTestSuite.setClientEndpoint(outputTestSuite.getClientEndpoint());
protocolTestSuite.setShapes(outputTestSuite.getShapes());
protocolTestSuite.setCases(new ArrayList<>());
for (C2jOutputTestCase outputTestCase : outputTestSuite.getCases()) {
ProtocolTestCase testCase = new ProtocolTestCase();
testCase.setId(outputTestCase.getId());
testCase.setDescription(outputTestCase.getDescription());
testCase.setGiven(outputTestCase.getGiven());
Optional<ProtocolTestCase.Output> output = Optional.of(new ProtocolTestCase.Output());
if (outputTestCase.getError() != null && outputTestCase.getResult() != null) {
throw new RuntimeException("Protocol test for output contains both error and success expected result!");
}
output.get().setResponse(outputTestCase.getResponse());
if (outputTestCase.getError() != null) {
output.get().setError(true);
Optional<ProtocolTestCase.Output.ErrorResult> error = Optional.of(new ProtocolTestCase.Output.ErrorResult());
error.get().setError(Optional.of(outputTestCase.getError()));
error.get().setErrorMessage(outputTestCase.getErrorMessage());
error.get().setErrorCode(outputTestCase.getErrorCode());
} else {
output.get().setError(false);
Optional<ProtocolTestCase.Output.SuccessResult> success = Optional.of(new ProtocolTestCase.Output.SuccessResult());
success.get().setResult(Optional.of(outputTestCase.getResult()));
}
output.get().setResponse(outputTestCase.getResponse());
testCase.setOutput(output);
protocolTestSuite.getCases().add(testCase);
}
model.getTestSuites().add(protocolTestSuite);
}
}
return model;
}