@Test public void testMissingMagentoGraphqlClient() throws IOException { Page page = Mockito.spy(context.currentPage("/content/pageA")); GraphQLCategoryProvider categoryProvider = new GraphQLCategoryProvider(page .getContentResource(), null); Assert.assertNull(Whitebox.getInternalState(categoryProvider, "magentoGraphqlClient")); Assert.assertTrue(categoryProvider.getChildCategories(10, 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);   }