-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Increase code coverage in swatch producer aws
- Loading branch information
Showing
14 changed files
with
212 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
swatch-producer-aws/src/main/java/com/redhat/swatch/aws/files/ProfileFileConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright Red Hat, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
* | ||
* Red Hat trademarks are not licensed under GPLv3. No permission is | ||
* granted to use or replicate Red Hat trademarks that are incorporated | ||
* in this software or its documentation. | ||
*/ | ||
package com.redhat.swatch.aws.files; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.enterprise.context.Dependent; | ||
import jakarta.enterprise.inject.Produces; | ||
import software.amazon.awssdk.profiles.ProfileFile; | ||
|
||
@Dependent | ||
public class ProfileFileConfiguration { | ||
@ApplicationScoped | ||
@Produces | ||
public ProfileFile defaultProfileFile() { | ||
return ProfileFile.defaultProfileFile(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
swatch-producer-aws/src/test/java/com/redhat/swatch/aws/KafkaResourceIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright Red Hat, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
* | ||
* Red Hat trademarks are not licensed under GPLv3. No permission is | ||
* granted to use or replicate Red Hat trademarks that are incorporated | ||
* in this software or its documentation. | ||
*/ | ||
package com.redhat.swatch.aws; | ||
|
||
import static io.restassured.RestAssured.post; | ||
|
||
import com.redhat.swatch.aws.openapi.model.KafkaSeekPosition; | ||
import io.quarkus.test.common.QuarkusTestResource; | ||
import io.quarkus.test.junit.QuarkusTest; | ||
import java.time.OffsetDateTime; | ||
import org.apache.http.HttpStatus; | ||
import org.junit.jupiter.api.Tag; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.EnumSource; | ||
|
||
@QuarkusTest | ||
@QuarkusTestResource(value = PostgresResource.class, restrictToAnnotatedClass = true) | ||
@QuarkusTestResource(value = KafkaResource.class, restrictToAnnotatedClass = true) | ||
@Tag("integration") | ||
class KafkaResourceIT { | ||
|
||
@ParameterizedTest | ||
@EnumSource(KafkaSeekPosition.class) | ||
void testKafkaSeekPosition(KafkaSeekPosition position) { | ||
post(basePath() + "/kafka_seek_position?position=" + position.toString()) | ||
.then() | ||
.statusCode(HttpStatus.SC_NO_CONTENT); | ||
} | ||
|
||
@Test | ||
void testKafkaSeekTimestamp() { | ||
post(basePath() + "/kafka_seek_timestamp?timestamp=" + OffsetDateTime.now()) | ||
.then() | ||
.statusCode(HttpStatus.SC_NO_CONTENT); | ||
} | ||
|
||
private String basePath() { | ||
return "/api/swatch-producer-aws/internal"; | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
swatch-producer-aws/src/test/java/com/redhat/swatch/aws/files/AwsCredentialsLookupTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright Red Hat, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
* | ||
* Red Hat trademarks are not licensed under GPLv3. No permission is | ||
* granted to use or replicate Red Hat trademarks that are incorporated | ||
* in this software or its documentation. | ||
*/ | ||
package com.redhat.swatch.aws.files; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.mockito.Mockito.when; | ||
|
||
import com.redhat.swatch.aws.exception.AwsMissingCredentialsException; | ||
import io.quarkus.test.InjectMock; | ||
import io.quarkus.test.junit.QuarkusTest; | ||
import jakarta.inject.Inject; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import org.junit.jupiter.api.Test; | ||
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider; | ||
import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider; | ||
import software.amazon.awssdk.profiles.Profile; | ||
import software.amazon.awssdk.profiles.ProfileFile; | ||
|
||
@QuarkusTest | ||
class AwsCredentialsLookupTest { | ||
private static final String AWS_SELLER_ACCOUNT = "123"; | ||
|
||
@InjectMock ProfileFile mockProfileFile; | ||
@Inject AwsCredentialsLookup lookup; | ||
|
||
@Test | ||
void testGetCredentialsProviderShouldThrowAwsMissingCredentialsException() { | ||
givenUnknownAwsSellerAccount(); | ||
assertThrows(AwsMissingCredentialsException.class, this::whenGetCredentialsProvider); | ||
} | ||
|
||
@Test | ||
void testGetCredentialsProviderShouldReturnProvider() { | ||
givenKnownAwsSellerAccount(); | ||
AwsCredentialsProvider provider = whenGetCredentialsProvider(); | ||
assertTrue(provider instanceof ProfileCredentialsProvider); | ||
} | ||
|
||
private void givenUnknownAwsSellerAccount() { | ||
when(mockProfileFile.profile(AWS_SELLER_ACCOUNT)).thenReturn(Optional.empty()); | ||
} | ||
|
||
private void givenKnownAwsSellerAccount() { | ||
when(mockProfileFile.profile(AWS_SELLER_ACCOUNT)) | ||
.thenReturn(Optional.of(Profile.builder().name("any").properties(Map.of()).build())); | ||
} | ||
|
||
private AwsCredentialsProvider whenGetCredentialsProvider() { | ||
return lookup.getCredentialsProvider(AWS_SELLER_ACCOUNT); | ||
} | ||
} |