aldettinger commented on code in PR #4474: URL: https://github.com/apache/camel-quarkus/pull/4474#discussion_r1094581880
########## integration-tests-support/aws2/src/main/java/org/apache/camel/quarkus/test/support/aws2/BaseAws2Resource.java: ########## @@ -0,0 +1,96 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.quarkus.test.support.aws2; + +import javax.enterprise.event.Observes; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import io.quarkus.runtime.ShutdownEvent; +import org.eclipse.microprofile.config.ConfigProvider; +import org.jboss.logging.Logger; + +/** + * Parent for testing resources for aws2 extensions. + * + * This class adds endpoints to force default credentials to be used + provides protected varialbe useDefaultCredentials Review Comment: protected variable ? ########## integration-tests-support/aws2/src/test/java/org/apache/camel/quarkus/test/support/aws2/BaseAWs2TestSupport.java: ########## @@ -0,0 +1,108 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.quarkus.test.support.aws2; + +import io.restassured.RestAssured; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +/** + * Parent for aws test classes which should cover default credentials test case. + * Parent adds two test methods {@link #successfulDefaultCredentialsProviderTest()} and + * {@link #failingDefaultCredentialsProviderTest()} + * + * Test expects that test resource extends {@link BaseAws2Resource}. + * + */ +public abstract class BaseAWs2TestSupport { + + //Rest path to connect to rest resource. Path differs for different aws2 extensions (like "/aws2-ddb" or "/aws2-s3" Review Comment: We may close the ")" ? ########## integration-tests-support/aws2/src/main/java/org/apache/camel/quarkus/test/support/aws2/BaseAws2Resource.java: ########## @@ -0,0 +1,96 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.quarkus.test.support.aws2; + +import javax.enterprise.event.Observes; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import io.quarkus.runtime.ShutdownEvent; +import org.eclipse.microprofile.config.ConfigProvider; +import org.jboss.logging.Logger; + +/** + * Parent for testing resources for aws2 extensions. + * + * This class adds endpoints to force default credentials to be used + provides protected varialbe useDefaultCredentials + * to be used in inherited classes. + * + * Rest endpoints are expected by test classes. + */ +public class BaseAws2Resource { + + private static final Logger LOG = Logger.getLogger(BaseAws2Resource.class); + + protected boolean useDefaultCredentials; + + private final String serviceName; + + private boolean clearAwsredentials; + + public BaseAws2Resource(String serviceName) { + this.serviceName = serviceName; + } + + @Path("/setUseDefaultCredentialsProvider") + @POST + public Response setUseDefaultCredentials(boolean useDefaultCredentialsProvider) throws Exception { + this.useDefaultCredentials = useDefaultCredentialsProvider; + return Response.ok().build(); + } + + @Path("/initializeDefaultCredentials") + @POST + @Produces(MediaType.TEXT_PLAIN) + public Response initializeDefaultCredentials(boolean initialize) throws Exception { + if (initialize) { + //set flag to clear at the end + clearAwsredentials = true; + LOG.debug( + "Setting both System.properties `aws.secretAccessKey` and `aws.accessKeyId` to cover defaultCredentialsProviderTest."); + //defaultCredentials provider gets the credentials from fixed location. One of them is system.properties, + //therefore to succeed the test, system.properties has to be initialized with the values from the configuration + Aws2Helper.setAwsSystemCredentials( + ConfigProvider.getConfig().getValue("camel.component.aws2-" + serviceName + ".access-key", String.class), + ConfigProvider.getConfig().getValue("camel.component.aws2-" + serviceName + ".secret-key", String.class)); + + } else { + LOG.debug("Clearing both System.properties `aws.secretAccessKey` and `aws.accessKeyId`."); + Aws2Helper.clearAwsSystemCredentials(); + clearAwsredentials = false; + } + + return Response.ok().build(); + } + + /** + * Listeners ensures, that system credentials are cleared at the end of the lifecycle. + * Tests are clearing them by itself, this is just a precaution. + */ Review Comment: Are we also clearing the properties when an unexpected exception is thrown during a test ? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@camel.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org