use of com.graphql_java_generator.samples.forum.client.graphql.forum.client.PostInput in project graphql-maven-plugin-project by graphql-java-generator.
the class AbstractIT method test_createPost.
@Test
void test_createPost() throws GraphQLRequestExecutionException, GraphQLRequestPreparationException {
// Preparation
Member author = new Member();
author.setId("12");
PostInput postInput = new PostInput();
postInput.setTopicId("22");
postInput.setInput(getTopicPostInput(author, "Some other content", new GregorianCalendar(1900, 11 - 1, 21).getTime(), false, "The good title for a post"));
// Go, go, go
Post post = queries.createPost(postInput);
// Verification
assertNotNull(post.getId());
assertEquals("Some other content", post.getContent());
assertEquals(new GregorianCalendar(1900, 11 - 1, 21).getTime(), post.getDate());
assertEquals(false, post.getPubliclyAvailable());
assertEquals("The good title for a post", post.getTitle());
}
use of com.graphql_java_generator.samples.forum.client.graphql.forum.client.PostInput in project graphql-maven-plugin-project by graphql-java-generator.
the class SubscriptionRequests method execSubscription.
public void execSubscription() throws GraphQLRequestPreparationException, GraphQLRequestExecutionException, IOException {
// Preparation
GraphQLRequest subscriptionRequest = subscriptionTypeExecutor.getSubscribeToNewPostGraphQLRequest("{id date author publiclyAvailable title content}");
GraphQLRequest createPostRequest = mutationTypeExecutor.getCreatePostGraphQLRequest("{id date author{id} title content publiclyAvailable}");
PostSubscriptionCallback postSubscriptionCallback = new PostSubscriptionCallback();
Member author = new Member();
author.setId("12");
PostInput postInput = new PostInput();
postInput.setTopicId("22");
postInput.setInput(getTopicPostInput(author, "Some other content", new GregorianCalendar(2020, 11 - 1, 21).getTime(), false, "The good title for a post"));
// Go, go, go
System.out.println("Submitting the 'subscribeToNewPostWithBindValues' GraphQL subscription");
SubscriptionClient subscriptionClient = subscriptionTypeExecutor.subscribeToNewPost(subscriptionRequest, postSubscriptionCallback, "Board name 1");
// For this test, we need to be sure that the subscription is active, before creating the post (that we will
// receive a notification about). 3s: that's long, but my PC is so slow from time to time... :(
final int TIMEOUT1 = 3000;
for (int i = 0; i < TIMEOUT1 / 10; i += 1) {
try {
Thread.sleep(10);
} catch (InterruptedException e) {
throw new RuntimeException(e.getMessage(), e);
}
if (postSubscriptionCallback.connected) {
break;
}
}
// Let's check that everything is ready
if (!postSubscriptionCallback.connected) {
throw new RuntimeException("The subscription should be active");
}
System.out.println("Creating a post (for which we expect a notification) from this postInput: " + postInput.toString());
mutationTypeExecutor.createPost(createPostRequest, postInput);
// ////////////////////////////////////////////////////////////////////////////////////
// Let's check that we've received the expected notification, for this post creation
// Let's wait 10 seconds max for the post creation notification (from the subscription). We'll get interrupted
// before, as soon as we receive the notification
// (see the callback implementation in the PostSubscriptionCallback class)
Post notifiedPost = null;
// Let's wait 10s max, until the connection is active
final int TIMEOUT2 = 10;
for (int i = 0; i < TIMEOUT2 * 1000 / 10; i += 1) {
try {
Thread.sleep(10);
} catch (InterruptedException e) {
throw new RuntimeException(e.getMessage(), e);
}
if ((notifiedPost = postSubscriptionCallback.lastReceivedMessage) != null) {
// Ok, we're connected. We're done
break;
}
}
if (notifiedPost == null) {
throw new RuntimeException("The notification for the post creation was not received");
}
// We need to free the server resources, at the end
subscriptionClient.unsubscribe();
}
use of com.graphql_java_generator.samples.forum.client.graphql.forum.client.PostInput in project graphql-maven-plugin-project by graphql-java-generator.
the class AbstractIT method testCreateTopicThenPostThenPosts.
@Test
void testCreateTopicThenPostThenPosts() throws GraphQLRequestPreparationException, GraphQLRequestExecutionException {
// Preparation
Calendar cal = Calendar.getInstance();
cal.clear();
// Month is 0-based, so this date is 2009, December the 20th
cal.set(2009, 11, 20);
List<Topic> before = queries.topicAuthorPostAuthor("Board name 3", cal.getTime());
TopicInput topicInput = new TopicInput();
topicInput.setBoardId(before.get(0).getId());
topicInput.setInput(getTopicPostInput(before.get(0).getAuthor(), "Some content", new GregorianCalendar(2009, 11 - 1, 20).getTime(), true, "The good title"));
// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// //////////////// CHECK OF TOPIC CREATION
Topic topic = queries.createTopic(topicInput);
// Verification
assertNotNull(topic.getId());
assertEquals("Some content", topic.getContent());
assertEquals(new GregorianCalendar(2009, 11 - 1, 20).getTime(), topic.getDate());
assertEquals(true, topic.getPubliclyAvailable());
assertEquals("The good title", topic.getTitle());
// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// //////////////// CHECK OF POST CREATION
// Preparation
PostInput postInput = new PostInput();
postInput.setTopicId(topic.getId());
postInput.setInput(getTopicPostInput(before.get(0).getAuthor(), "Some other content", new GregorianCalendar(2009, 11 - 1, 21).getTime(), false, "The good title for a post"));
// Go, go, go
Post post = queries.createPost(postInput);
// Verification
assertNotNull(post.getId());
assertEquals("Some other content", post.getContent());
assertEquals(new GregorianCalendar(2009, 11 - 1, 21).getTime(), post.getDate());
assertEquals(false, post.getPubliclyAvailable());
assertEquals("The good title for a post", post.getTitle());
// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// //////////////// CHECK OF POSTS (check the plural!) CREATION
// Preparation
List<PostInput> list = new ArrayList<>();
list.add(postInput);
// Go, go, go (the server always response with an exception: we'll check that this is the expected one)
GraphQLRequestExecutionException e = assertThrows(GraphQLRequestExecutionException.class, () -> queries.createPosts(list));
// Verification
assertTrue(e.getMessage().contains("Spamming is forbidden"));
}
use of com.graphql_java_generator.samples.forum.client.graphql.forum.client.PostInput in project graphql-maven-plugin-project by graphql-java-generator.
the class AbstractIT method test_createPosts.
@Test
void test_createPosts() {
// Preparation
Member author = new Member();
author.setId("12");
PostInput postInput = new PostInput();
postInput.setTopicId("22");
postInput.setInput(getTopicPostInput(author, "Some other content", new GregorianCalendar(1900, 11 - 1, 21).getTime(), false, "The good title for a post"));
List<PostInput> list = new ArrayList<>();
list.add(postInput);
// Go, go, go (the server always response with an exception: we'll check that this is the expected one)
GraphQLRequestExecutionException e = assertThrows(GraphQLRequestExecutionException.class, () -> queries.createPosts(list));
// Verification
assertTrue(e.getMessage().contains("Spamming is forbidden"));
}
use of com.graphql_java_generator.samples.forum.client.graphql.forum.client.PostInput in project graphql-maven-plugin-project by graphql-java-generator.
the class SubscriptionIT method testSubscription.
@Test
void testSubscription() throws GraphQLRequestExecutionException, InterruptedException, ExecutionException {
// Preparation
logger.debug("--------------------------------------------------------------------------------------------");
logger.info("Starting testSubscription");
PostSubscriptionCallback callback = new PostSubscriptionCallback();
Member author = new Member();
author.setId("12");
PostInput postInput = new PostInput();
postInput.setTopicId("22");
postInput.setInput(getTopicPostInput(author, "Some other content", new GregorianCalendar(2000, 11 - 1, 21).getTime(), false, "The good title for a post"));
// Go, go, go
logger.debug("Subscribing to the GraphQL subscription");
SubscriptionClient client = subscriptionType.subscribeToNewPost(subscriptionRequest, callback, "Board name 1");
// We wait a little, just to be sure that the subscription is active on server side
Thread.sleep(500);
Post createdPost = mutationType.createPost(createPostRequest, postInput);
// Let's wait for the notifications (my PC is really slow, thanks to a permanently full scanning antivirus)
// Time out of 20s: can be useful, when debugging
callback.latchNewMessage.await(20, TimeUnit.SECONDS);
// Verification
assertNull(callback.lastReceivedClose, "We should have received no close message (" + callback.lastReceivedClose + ")");
assertNull(callback.lastReceivedError, "We should have received no error (" + callback.lastReceivedError + ")");
assertEquals(1, callback.nbReceivedMessages, "We should have received exactly one notification");
assertNotNull(callback.lastReceivedMessage, "We should have received a post");
assertEquals(createdPost.getId(), callback.lastReceivedMessage.getId(), "Is it 'our' new Post?");
assertEquals(new GregorianCalendar(2000, 11 - 1, 21).getTime(), callback.lastReceivedMessage.getDate(), "Check of a custom scalar date");
// We must free the server resource at the end
client.unsubscribe();
logger.debug("Stopped listening");
}
Aggregations