@Test public void testGetChildCategories() throws IOException { Page page = spy(context.currentPage("/content/pageA")); Resource pageContent = spy(page.getContentResource()); when(page.getContentResource()).thenReturn(pageContent); when(pageContent.adaptTo(GraphqlClient.class)).thenReturn(graphqlClient); when(pageContent.adaptTo(ComponentsConfiguration.class)).thenReturn(MOCK_CONFIGURATION_OBJECT); GraphQLCategoryProvider categoryProvider = new GraphQLCategoryProvider(page .getContentResource(), null); Assert.assertTrue(categoryProvider.getChildCategories(null, 5).isEmpty()); List<CategoryTree> categories = categoryProvider.getChildCategories(2, 5); Assert.assertEquals(6, categories.size()); }
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);   }