Skip to content

Instantly share code, notes, and snippets.

View MemoAlfa's full-sized avatar

Memo Alaloush MemoAlfa

View GitHub Profile
@MemoAlfa
MemoAlfa / Identity
Created March 1, 2020 16:10
Keybase_ID
### Keybase proof
I hereby claim:
* I am memoalfa on github.
* I am memoalfa (https://keybase.io/memoalfa) on keybase.
* I have a public key ASB6bF5kjvBbYvc9m5K2cbCkkXyTDjNrhW-HbCDbUd8lPQo
To claim this, I am signing this object:
public void givenResponseToGetUserInfo(UUID userUuid, UserInfoResponseDto userInfoResponseDto) {
mockServerClient.when(HttpRequest.request()
.withPath(String.format(USER_INFO_ENDPOINT, userUuid.toString()))
.withMethod(HttpMethod.GET.name()), Times.exactly(1))
.respond(jsonResponse()
.withStatusCode(200)
.withBody(json(userInfoResponseDto)));
}
@MemoAlfa
MemoAlfa / AwsTestResourcesConfig.java
Created October 3, 2019 11:44
Override the Lazy initialized beans by the ones that are pointing to localstack
@Bean(destroyMethod = "shutdown")
@Primary
public AmazonSQS getSqsClient(@Value("${localstack.host}") String sqsHost, @Value("${localstack.tcp.4576}") String port) {
final AmazonSQSAsync sqsClient =
AmazonSQSAsyncClientBuilder.standard()
.withEndpointConfiguration(
new AwsClientBuilder.EndpointConfiguration(sqsHost + ":" + port, "cn-north-1"))
.withClientConfiguration(new ClientConfiguration().withProtocol(Protocol.HTTP)).build();
return sqsClient;
}
private void givenOperatorAcceptedAllDocuments(List<UUID> userDocumentUploadIds) {
userDocumentUploadIds.forEach(documentId ->
httpRequestHelper.whenPutVerifyDocumentAccepted(operatorUser(UUID.randomUUID()), documentId).then()
.statusCode(HttpStatus.ACCEPTED.value()));
}
private void givenUserSuccessFullyUploadedRequiredDocuments(List<UUID> documentIds) throws IOException {
final UploadDocumentRequestDto uploadDocumentRequestDto = new UploadDocumentRequestDto(
Base64.getEncoder().encodeToString(ByteStreams.toByteArray(testDocumentPdf.getInputStream())));
documentIds.forEach(documentId -> {
httpRequestHelper.whenPutUploadRequest(tenantUser(testUserCreatedMessage.getUserUuid()), documentId, uploadDocumentRequestDto)
.then()
.statusCode(HttpStatus.ACCEPTED.value());
});
}
@MemoAlfa
MemoAlfa / givenUploadTasksOnUserCreation.java
Created October 1, 2019 16:16
Integration Test Demo givenUploadTasksOnUserCreation
private List<UUID> givenUploadTasksOnUserCreation() {
sqsTestHelper.givenAPublishedUserCreatedMessageAwaitedToBeConsumed(testUserCreatedMessage);
final UserDocumentUploadTaskDto[] response = httpRequestHelper.whenGetUploadTasksForUser(tenantUser(testUserCreatedMessage.getUserUuid()))
.then()
.statusCode(HttpStatus.OK.value())
.extract().body().as(UserDocumentUploadTaskDto[].class);
final List<NotificationMessageDto> notificationMessageDtos = sqsTestHelper.retrieveNotificationMessages();
assertThat(notificationMessageDtos).hasSize(1);
@MemoAlfa
MemoAlfa / application-test.yaml
Created October 1, 2019 16:12
Integration Test Demo Test profile config
spring:
datasource:
url: jdbc:postgresql://${psql.host}:${psql.tcp.5432}/fake
username: postgres
password: fake
jpa:
flyway:
enabled: true
cloud:
@MemoAlfa
MemoAlfa / testing.gradle
Last active October 1, 2019 16:01
Integration Test Demo customized plugin
apply plugin: 'docker-compose'
apply plugin: 'com.adarshr.test-logger'
// ====== integration tests config
task integrationTest(type: Test) {
// injecting thoes as fake secrets whic is just one way to stop aws from failing on application startup
environment "AWS_ACCESS_KEY_ID", "fake"
environment "AWS_SECRET_ACCESS_KEY", "fake"
useJUnitPlatform {
// tagging our tests is a new way of distinguishing between tests in Junit5 Jupiters engine.
@MemoAlfa
MemoAlfa / build.gradle
Created October 1, 2019 15:51
Integration Test Demo build.gradle file
buildscript {
ext {
springBootVersion = '2.1.4.RELEASE'
junitJupiterVersion = '5.3.2'
}
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
mavenCentral()
@MemoAlfa
MemoAlfa / docker-compose.yaml
Created October 1, 2019 15:47
Docker Compose File
version: '3'
services:
mockServer:
image: jamesdbloom/mockserver:mockserver-5.6.0
ports:
- 1080
environment:
- LOG_LEVEL=DEBUG # INFO
psql: