@Test public void testCategoryNotOrNoChildren() throws IOException { Page page = mock(Page.class); Resource pageContent = mock(Resource.class); when(page.getContentResource()).thenReturn(pageContent); GraphQLCategoryProvider categoryProvider = new GraphQLCategoryProvider(page .getContentResource(), null); MagentoGraphqlClient graphqlClient = mock(MagentoGraphqlClient.class); Whitebox.setInternalState(categoryProvider, "magentoGraphqlClient", graphqlClient); GraphqlResponse<Query, Error> response = mock(GraphqlResponse.class); when(graphqlClient.execute(anyString())).thenReturn(response); Query rootQuery = mock(Query.class); when(response.getData()).thenReturn(rootQuery); Assert.assertNull(rootQuery.getCategory()); Assert.assertTrue(categoryProvider.getChildCategories(-10, 10).isEmpty()); CategoryTree category = mock(CategoryTree.class); when(rootQuery.getCategory()).thenReturn(category); when(category.getChildren()).thenReturn(null); Assert.assertNull(category.getChildren()); Assert.assertTrue(categoryProvider.getChildCategories(13, 10).isEmpty()); }
List<CategoryTree> getChildCategories(Integer categoryId, Integer depth) { if (magentoGraphqlClient == null || categoryId == null) { LOGGER.debug("No Graphql client present, cannot retrieve top categories"); return Collections.emptyList(); } QueryQuery.CategoryArgumentsDefinition searchArgs = q -> q.id(categoryId); String queryString = Operations.query(query -> query.category(searchArgs, defineCategoriesQuery(depth))).toString(); GraphqlResponse<Query, Error> response = magentoGraphqlClient.execute(queryString); Query rootQuery = response.getData(); CategoryTree category = rootQuery.getCategory(); if (category == null) { LOGGER.warn("Magento category not found for id: " + categoryId); return Collections.emptyList(); } List<CategoryTree> children = category.getChildren(); if (children == null) { return Collections.emptyList(); } return children; }
GraphQLCategoryProvider { List<CategoryTree> getChildCategories(Integer categoryId, Integer depth) { if (magentoGraphqlClient == null || categoryId == null) { LOGGER.debug("No Graphql client present, cannot retrieve top categories"); return Collections.emptyList(); } QueryQuery.CategoryArgumentsDefinition searchArgs = q -> q.id(categoryId); String queryString = Operations.query(query -> query.category(searchArgs, defineCategoriesQuery(depth))).toString(); GraphqlResponse<Query, Error> response = magentoGraphqlClient.execute(queryString); Query rootQuery = response.getData(); CategoryTree category = rootQuery.getCategory(); if (category == null) { LOGGER.warn("Magento category not found for id: " + categoryId); return Collections.emptyList(); } List<CategoryTree> children = category.getChildren(); if (children == null) { return Collections.emptyList(); } return children; } }
GraphQLCategoryProvider { List<CategoryTree> getChildCategories(Integer categoryId, Integer depth) { if (magentoGraphqlClient == null || categoryId == null) { LOGGER.debug("No Graphql client present, cannot retrieve top categories"); return Collections.emptyList(); } QueryQuery.CategoryArgumentsDefinition searchArgs = q -> q.id(categoryId); String queryString = Operations.query(query -> query.category(searchArgs, defineCategoriesQuery(depth))).toString(); GraphqlResponse<Query, Error> response = magentoGraphqlClient.execute(queryString); Query rootQuery = response.getData(); CategoryTree category = rootQuery.getCategory(); if (category == null) { LOGGER.warn("Magento category not found for id: " + categoryId); return Collections.emptyList(); } List<CategoryTree> children = category.getChildren(); if (children == null) { return Collections.emptyList(); } return children; } GraphQLCategoryProvider(Resource resource, Page page); }
GraphQLCategoryProvider { List<CategoryTree> getChildCategories(Integer categoryId, Integer depth) { if (magentoGraphqlClient == null || categoryId == null) { LOGGER.debug("No Graphql client present, cannot retrieve top categories"); return Collections.emptyList(); } QueryQuery.CategoryArgumentsDefinition searchArgs = q -> q.id(categoryId); String queryString = Operations.query(query -> query.category(searchArgs, defineCategoriesQuery(depth))).toString(); GraphqlResponse<Query, Error> response = magentoGraphqlClient.execute(queryString); Query rootQuery = response.getData(); CategoryTree category = rootQuery.getCategory(); if (category == null) { LOGGER.warn("Magento category not found for id: " + categoryId); return Collections.emptyList(); } List<CategoryTree> children = category.getChildren(); if (children == null) { return Collections.emptyList(); } return children; } GraphQLCategoryProvider(Resource resource, Page page);  }
GraphQLCategoryProvider { List<CategoryTree> getChildCategories(Integer categoryId, Integer depth) { if (magentoGraphqlClient == null || categoryId == null) { LOGGER.debug("No Graphql client present, cannot retrieve top categories"); return Collections.emptyList(); } QueryQuery.CategoryArgumentsDefinition searchArgs = q -> q.id(categoryId); String queryString = Operations.query(query -> query.category(searchArgs, defineCategoriesQuery(depth))).toString(); GraphqlResponse<Query, Error> response = magentoGraphqlClient.execute(queryString); Query rootQuery = response.getData(); CategoryTree category = rootQuery.getCategory(); if (category == null) { LOGGER.warn("Magento category not found for id: " + categoryId); return Collections.emptyList(); } List<CategoryTree> children = category.getChildren(); if (children == null) { return Collections.emptyList(); } return children; } GraphQLCategoryProvider(Resource resource, Page page);   }