java-tutorials/aws-app-sync/src/test/java/com/baeldung/awsappsync/AwsAppSyncApplicationTests.java

73 lines
2.3 KiB
Java
Raw Normal View History

2020-04-16 09:55:40 -04:00
package com.baeldung.awsappsync;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
2020-04-17 19:50:36 -04:00
import org.springframework.web.reactive.function.client.WebClient;
import java.util.HashMap;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.*;
2020-04-16 09:55:40 -04:00
@SpringBootTest
class AwsAppSyncApplicationTests {
2020-05-01 19:48:38 -04:00
@Test
void givenGraphQuery_whenListEvents_thenReturnAllEvents() {
2020-04-17 19:50:36 -04:00
2020-05-01 19:48:38 -04:00
Map<String, Object> requestBody = new HashMap<>();
requestBody.put("query", "query ListEvents {" +
" listEvents {" +
" items {" +
" id" +
" name" +
" where" +
" when" +
" description" +
" }" +
" }" +
"}");
requestBody.put("variables", "");
requestBody.put("operationName", "ListEvents");
2020-04-17 19:50:36 -04:00
2020-05-01 19:48:38 -04:00
String bodyString = AppSyncClientHelper.getResponseBodySpec(requestBody)
.bodyToMono(String.class).block();
2020-04-17 19:50:36 -04:00
2020-05-01 19:48:38 -04:00
assertNotNull(bodyString);
assertTrue(bodyString.contains("My First Event"));
assertTrue(bodyString.contains("where"));
assertTrue(bodyString.contains("when"));
}
2020-04-16 09:55:40 -04:00
2020-05-01 19:48:38 -04:00
@Test
void givenGraphAdd_whenMutation_thenReturnIdNameDesc() {
2020-04-17 19:50:36 -04:00
2020-05-01 19:48:38 -04:00
String queryString = "mutation add {" +
" createEvent(" +
" name:\"My added GraphQL event\"" +
" where:\"Day 2\"" +
" when:\"Saturday night\"" +
" description:\"Studying GraphQL\"" +
" ){" +
" id" +
" name" +
" description" +
" }" +
"}";
2020-04-17 19:50:36 -04:00
2020-05-01 19:48:38 -04:00
Map<String, Object> requestBody = new HashMap<>();
requestBody.put("query", queryString);
requestBody.put("variables", "");
requestBody.put("operationName", "add");
2020-04-17 19:50:36 -04:00
2020-05-01 19:48:38 -04:00
WebClient.ResponseSpec response = AppSyncClientHelper.getResponseBodySpec(requestBody);
2020-04-17 19:50:36 -04:00
2020-05-01 19:48:38 -04:00
String bodyString = response.bodyToMono(String.class).block();
2020-04-17 19:50:36 -04:00
2020-05-01 19:48:38 -04:00
assertNotNull(bodyString);
assertTrue(bodyString.contains("My added GraphQL event"));
assertFalse(bodyString.contains("where"));
assertFalse(bodyString.contains("when"));
}
2020-04-16 09:55:40 -04:00
}