use of com.graphql_java_generator.samples.forum.client.graphql.forum.client.Member in project graphql-maven-plugin-project by graphql-java-generator.
the class AbstractIT method testTopicAuthorPostAuthor.
@Test
void testTopicAuthorPostAuthor() throws GraphQLRequestExecutionException, GraphQLRequestPreparationException {
// return queryType.topics(
// "{id date author{name email alias id type} nbPosts title content posts{id date author{name email alias} title
// content}}",
// "Board name 2");
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> topics = queries.topicAuthorPostAuthor("Board name 2", cal.getTime());
assertTrue(topics.size() >= 5);
Topic topic12 = topics.get(1);
//
assertEquals("The content of the topic <12>", topic12.getContent());
assertEquals(new GregorianCalendar(2018, 12 - 1, 20).getTime(), topic12.getDate());
assertEquals(12, (int) topic12.getNbPosts());
assertEquals("The title of <12>", topic12.getTitle());
assertEquals("12", topic12.getId());
//
// All its fields have been loaded
Member author12 = topic12.getAuthor();
assertNotNull(author12);
assertEquals("12", author12.getId());
assertEquals("[BL] Name 12", author12.getName());
assertEquals("Alias of Name 12", author12.getAlias());
assertEquals("name.12@graphql-java.com", author12.getEmail());
assertEquals(MemberType.STANDARD, author12.getType());
// Let's check for one post
List<Post> posts12 = topic12.getPosts();
assertEquals(8, posts12.size());
//
Post post232 = posts12.get(5);
assertEquals(new GregorianCalendar(2018, 05 - 1, 13).getTime(), post232.getDate());
assertEquals("232", post232.getId());
assertEquals("The content of the post <232>", post232.getContent());
// Not queried
assertEquals(null, post232.getPubliclyAvailable());
assertEquals("The title of <232>", post232.getTitle());
//
// This one is partially loaded: author{name email alias}
Member author12bis = post232.getAuthor();
assertNotNull(author12bis);
assertEquals(null, author12bis.getId());
assertEquals("[BL] Name 12", author12bis.getName());
assertEquals("Alias of Name 12", author12bis.getAlias());
assertEquals("name.12@graphql-java.com", author12bis.getEmail());
assertEquals(null, author12bis.getType());
}
use of com.graphql_java_generator.samples.forum.client.graphql.forum.client.Member 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.Member 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.Member 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.Member in project graphql-maven-plugin-project by graphql-java-generator.
the class AbstractIT method test_createMember.
@Test
void test_createMember() throws GraphQLRequestExecutionException, GraphQLRequestPreparationException {
// Preparation
MemberInput input = new MemberInput();
input.setAlias("an alias");
input.setEmail("an.email@my.domain.com");
input.setName("a member name");
input.setType(MemberType.MODERATOR);
// Go, go, go
Member member = queries.createMember(input);
// Verification
assertNotNull(member.getId());
assertEquals("an alias", member.getAlias());
assertEquals("an.email@my.domain.com", member.getEmail());
assertEquals("a member name", member.getName());
assertEquals(MemberType.MODERATOR, member.getType());
}
Aggregations