|
| 1 | +/* |
| 2 | + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"). |
| 5 | + * You may not use this file except in compliance with the License. |
| 6 | + * A copy of the License is located at |
| 7 | + * |
| 8 | + * http://aws.amazon.com/apache2.0 |
| 9 | + * |
| 10 | + * or in the "license" file accompanying this file. This file is distributed |
| 11 | + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
| 12 | + * express or implied. See the License for the specific language governing |
| 13 | + * permissions and limitations under the License. |
| 14 | + */ |
| 15 | + |
| 16 | +package software.amazon.awssdk.codegen.customization.processors; |
| 17 | + |
| 18 | +import static org.assertj.core.api.Assertions.assertThatThrownBy; |
| 19 | + |
| 20 | +import java.util.Collections; |
| 21 | +import java.util.HashMap; |
| 22 | +import java.util.List; |
| 23 | +import java.util.Map; |
| 24 | +import java.util.stream.Stream; |
| 25 | +import org.junit.jupiter.api.Test; |
| 26 | +import org.junit.jupiter.params.ParameterizedTest; |
| 27 | +import org.junit.jupiter.params.provider.MethodSource; |
| 28 | +import software.amazon.awssdk.codegen.C2jModels; |
| 29 | +import software.amazon.awssdk.codegen.IntermediateModelBuilder; |
| 30 | +import software.amazon.awssdk.codegen.model.intermediate.IntermediateModel; |
| 31 | +import software.amazon.awssdk.codegen.model.intermediate.Protocol; |
| 32 | +import software.amazon.awssdk.codegen.model.service.ServiceMetadata; |
| 33 | +import software.amazon.awssdk.codegen.poet.ClientTestModels; |
| 34 | + |
| 35 | +public class LongPollingOperationProcessTest { |
| 36 | + |
| 37 | + @ParameterizedTest |
| 38 | + @MethodSource("nonJsonProtocols") |
| 39 | + void postprocess_serviceInMap_serviceNotJson_throws(Protocol protocol) { |
| 40 | + C2jModels c2jModels = ClientTestModels.awsJsonServiceC2jModels(); |
| 41 | + |
| 42 | + ServiceMetadata metadata = c2jModels.serviceModel().getMetadata(); |
| 43 | + metadata.setProtocols(Collections.singletonList(protocol.getValue())); |
| 44 | + |
| 45 | + IntermediateModel intermediateModel = new IntermediateModelBuilder(c2jModels).build(); |
| 46 | + |
| 47 | + Map<String, List<String>> serviceToOperations = new HashMap<>(); |
| 48 | + serviceToOperations.put(metadata.getServiceId(), Collections.emptyList()); |
| 49 | + LongPollingOperationProcessor processor = new LongPollingOperationProcessor(serviceToOperations); |
| 50 | + |
| 51 | + assertThatThrownBy(() -> processor.postprocess(intermediateModel)) |
| 52 | + .hasMessage("Currently only AWS-JSON services can use the longPoll trait"); |
| 53 | + } |
| 54 | + |
| 55 | + @Test |
| 56 | + void postprocess_operationNotFound_throws() { |
| 57 | + IntermediateModel intermediateModel = ClientTestModels.awsJsonServiceModels(); |
| 58 | + |
| 59 | + Map<String, List<String>> serviceToOperations = new HashMap<>(); |
| 60 | + serviceToOperations.put(intermediateModel.getMetadata().getServiceId(), Collections.singletonList("SomeOperation")); |
| 61 | + LongPollingOperationProcessor processor = new LongPollingOperationProcessor(serviceToOperations); |
| 62 | + |
| 63 | + assertThatThrownBy(() -> processor.postprocess(intermediateModel)) |
| 64 | + .hasMessage("Operation SomeOperation not found for service Json Service"); |
| 65 | + } |
| 66 | + |
| 67 | + private static Stream<Protocol> nonJsonProtocols() { |
| 68 | + return Stream.of(Protocol.values()).filter(p -> p != Protocol.AWS_JSON); |
| 69 | + } |
| 70 | +} |
0 commit comments