Search in sources :

Example 1 with Topic

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

Example 2 with Topic

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

the class AbstractIT method testFindTopics.

@Test
void testFindTopics() throws GraphQLRequestExecutionException, GraphQLRequestPreparationException {
    // Preparation
    String boardName = "Board name 3";
    List<String> keyword = new ArrayList<>(Arrays.asList("3", "content"));
    // Go, go, go
    List<Topic> topics = queries.findTopics(boardName, keyword);
    // Verification
    assertEquals(5, topics.size());
    Topic topic = topics.get(3);
    assertEquals("The title of <33>", topic.getTitle());
    assertEquals("The content of the topic <33>", topic.getContent());
}
Also used : ArrayList(java.util.ArrayList) Topic(com.graphql_java_generator.samples.forum.client.graphql.forum.client.Topic) Test(org.junit.jupiter.api.Test)

Example 3 with Topic

use of com.graphql_java_generator.samples.forum.client.graphql.forum.client.Topic 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)

Example 4 with Topic

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

the class BatchLoaderIT method test_authorLoadedByBatchLoader.

@Test
public void test_authorLoadedByBatchLoader() throws GraphQLRequestPreparationException, GraphQLRequestExecutionException {
    // Go, go, go
    List<Topic> topics = directQueriesWithFieldInputParameters.topics_since(boardName, since);
    assertTrue(topics.size() >= 5);
    for (Topic t : topics) {
        Member m = t.getAuthor();
        assertNotNull(m);
        checkNameLoadedByBatchLoader(m.getName());
        for (Post p : t.getPosts()) {
            assertNotNull(p.getAuthor());
            checkNameLoadedByBatchLoader(p.getAuthor().getName());
        }
    }
}
Also used : Post(com.graphql_java_generator.samples.forum.client.graphql.forum.client.Post) Topic(com.graphql_java_generator.samples.forum.client.graphql.forum.client.Topic) Member(com.graphql_java_generator.samples.forum.client.graphql.forum.client.Member) Test(org.junit.jupiter.api.Test)

Example 5 with Topic

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

the class DirectQueriesWithFieldInputParametersIT method topics_memberId_since.

@Test
public void topics_memberId_since() throws GraphQLRequestPreparationException, GraphQLRequestExecutionException {
    // Preparation
    UUID uuid = UUID.fromString("00000000-0000-0000-0000-000000000012");
    // Go, go, go
    List<Topic> topics = directQueriesWithFieldInputParameters.topics_memberId_since(boardName, uuid, since);
    // Verifications
    assertTrue(topics.size() >= 5);
    assertEquals(0, topics.get(0).getPosts().size());
}
Also used : UUID(java.util.UUID) Topic(com.graphql_java_generator.samples.forum.client.graphql.forum.client.Topic) Test(org.junit.jupiter.api.Test)

Aggregations

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