Search in sources :

Example 1 with TopicInput

use of com.graphql_java_generator.samples.forum.client.graphql.forum.client.TopicInput in project graphql-maven-plugin-project by graphql-java-generator.

the class Queries method getTopicInput.

/**
 * A utility method to create the TopicInput Type, from its values
 */
default TopicInput getTopicInput(Board board, Member author, Date date, boolean publiclyAvailable, String title, String content) {
    TopicInput input = new TopicInput();
    input.setBoardId(board.getId());
    input.setInput(getTopicPostInput(author, date, publiclyAvailable, title, content));
    return input;
}
Also used : TopicInput(com.graphql_java_generator.samples.forum.client.graphql.forum.client.TopicInput)

Example 2 with TopicInput

use of com.graphql_java_generator.samples.forum.client.graphql.forum.client.TopicInput 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"));
}
Also used : TopicInput(com.graphql_java_generator.samples.forum.client.graphql.forum.client.TopicInput) TopicPostInput(com.graphql_java_generator.samples.forum.client.graphql.forum.client.TopicPostInput) PostInput(com.graphql_java_generator.samples.forum.client.graphql.forum.client.PostInput) Post(com.graphql_java_generator.samples.forum.client.graphql.forum.client.Post) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) GregorianCalendar(java.util.GregorianCalendar) ArrayList(java.util.ArrayList) GraphQLRequestExecutionException(com.graphql_java_generator.exception.GraphQLRequestExecutionException) Topic(com.graphql_java_generator.samples.forum.client.graphql.forum.client.Topic) Test(org.junit.jupiter.api.Test)

Aggregations

TopicInput (com.graphql_java_generator.samples.forum.client.graphql.forum.client.TopicInput)2 GraphQLRequestExecutionException (com.graphql_java_generator.exception.GraphQLRequestExecutionException)1 Post (com.graphql_java_generator.samples.forum.client.graphql.forum.client.Post)1 PostInput (com.graphql_java_generator.samples.forum.client.graphql.forum.client.PostInput)1 Topic (com.graphql_java_generator.samples.forum.client.graphql.forum.client.Topic)1 TopicPostInput (com.graphql_java_generator.samples.forum.client.graphql.forum.client.TopicPostInput)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 GregorianCalendar (java.util.GregorianCalendar)1 Test (org.junit.jupiter.api.Test)1