Search in sources :

Example 1 with Droid

use of com.graphql_java_generator.domain.client.allGraphQLCases.Droid in project graphql-maven-plugin-project by graphql-java-generator.

the class SubscriptionClientWebSocket_allGraphQLCasesTest method testOnMessage.

@Test
void testOnMessage() throws GraphQLRequestExecutionException {
    // Go, go, go
    subscriptionClientWebSocket.onMessage(// 
    "" + // 
    "{" + // 
    "    \"subscribeNewHumanForEpisode\": {" + // 
    "      \"id\": \"7ecfeafa-98e0-4072-922d-f94fa7d07aa0\"," + // 
    "      \"name\": \"human's name\"," + // 
    "      \"homePlanet\": \"a planet\"," + // 
    "      \"__typename\": \"Human\"," + // 
    "      \"friends\": [" + // 
    "        {" + // 
    "          \"id\": \"7ecfeafa-98e0-4072-922d-f94fa7d07aa1\"," + // 
    "          \"name\": \"friends 1\"," + // 
    "          \"homePlanet\": \"planet1\"," + // 
    "          \"__typename\": \"Human\"" + // 
    "        }," + // 
    "        {" + // 
    "          \"id\": \"7ecfeafa-98e0-4072-922d-f94fa7d07aa2\"," + // 
    "          \"name\": \"friends 2\"," + // 
    "          \"primaryFunction\": \"function2\"," + // 
    "          \"__typename\": \"Droid\"" + // 
    "        }" + // 
    "      ]" + // 
    "    }" + "}");
    // Verification
    assertEquals(1, subscriptionCallback.messages.size());
    assertEquals(0, subscriptionCallback.closes.size());
    assertEquals(0, subscriptionCallback.errors.size());
    Human h = subscriptionCallback.messages.get(0);
    assertEquals("7ecfeafa-98e0-4072-922d-f94fa7d07aa0", h.getId());
    assertEquals("human's name", h.getName());
    assertEquals("a planet", h.getHomePlanet());
    assertEquals(2, h.getFriends().size());
    // 
    int i = 0;
    assertTrue(h.getFriends().get(i) instanceof Human);
    Human friend1 = (Human) h.getFriends().get(i);
    assertEquals("7ecfeafa-98e0-4072-922d-f94fa7d07aa1", friend1.getId());
    assertEquals("friends 1", friend1.getName());
    assertEquals("planet1", friend1.getHomePlanet());
    assertEquals(null, friend1.getFriends());
    // 
    i += 1;
    assertTrue(h.getFriends().get(i) instanceof Droid);
    Droid friend2 = (Droid) h.getFriends().get(i);
    assertEquals("7ecfeafa-98e0-4072-922d-f94fa7d07aa2", friend2.getId());
    assertEquals("friends 2", friend2.getName());
    assertEquals("function2", friend2.getPrimaryFunction());
    assertEquals(null, friend2.getFriends());
}
Also used : Human(com.graphql_java_generator.domain.client.allGraphQLCases.Human) Droid(com.graphql_java_generator.domain.client.allGraphQLCases.Droid) Test(org.junit.jupiter.api.Test)

Aggregations

Droid (com.graphql_java_generator.domain.client.allGraphQLCases.Droid)1 Human (com.graphql_java_generator.domain.client.allGraphQLCases.Human)1 Test (org.junit.jupiter.api.Test)1