Skip to content

Commit

Permalink
Merge pull request #322 from adobe/dev
Browse files Browse the repository at this point in the history
Sync dev to merge before release
  • Loading branch information
LSantha authored Nov 8, 2023
2 parents c191e60 + 4067b2a commit 8b9e70f
Show file tree
Hide file tree
Showing 17 changed files with 520 additions and 16 deletions.
5 changes: 3 additions & 2 deletions .circleci/ci/it-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,9 @@ try {

// Run integration tests
if (TYPE === 'integration') {
let excludedCategory = classifier === 'classic' ? 'com.venia.it.category.IgnoreOn65' : 'com.venia.it.category.IgnoreOnCloud';
ci.dir('it.tests', () => {
ci.sh(`mvn clean verify -U -B -Plocal`); // The -Plocal profile comes from the AEM archetype
ci.sh(`mvn clean verify -U -B -Plocal -Dexclude.category=${excludedCategory}`); // The -Plocal profile comes from the AEM archetype
});
}
if (TYPE === 'selenium') {
Expand All @@ -117,7 +118,7 @@ try {
chromedriver = chromedriver.length >= 2 ? chromedriver[1] : '';

ci.dir('ui.tests', () => {
ci.sh(`CHROMEDRIVER=${chromedriver} mvn test -U -B -Pui-tests-local-execution -DHEADLESS_BROWSER=true -DSELENIUM-BROWSER=${BROWSER} -DVENIA_ACCOUNT_EMAIL=${VENIA_ACCOUNT_EMAIL} -DVENIA_ACCOUNT_PASSWORD=${VENIA_ACCOUNT_PASSWORD}`);
ci.sh(`CHROMEDRIVER=${chromedriver} mvn test -U -B -Pui-tests-local-execution -DAEM_VERSION=${classifier} -DHEADLESS_BROWSER=true -DSELENIUM-BROWSER=${BROWSER} -DVENIA_ACCOUNT_EMAIL=${VENIA_ACCOUNT_EMAIL} -DVENIA_ACCOUNT_PASSWORD=${VENIA_ACCOUNT_PASSWORD}`);
});
}

Expand Down
7 changes: 4 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ common:
integration_test_steps: &integration_test_steps
steps:
- checkout
- browser-tools/install-browser-tools
- browser-tools/install-browser-tools:
chrome-version: 114.0.5735.90 # TODO: remove -> https://github.com/CircleCI-Public/browser-tools-orb/issues/75
- restore_cache:
keys:
- maven-repo-{{ .Environment.CACHE_VERSION }}-its-{{ arch }}-{{ .Branch }}-{{ checksum "pom.xml" }}
Expand Down Expand Up @@ -64,13 +65,13 @@ executors:
docker:
- image: docker-adobe-cif-release.dr-uw2.adobeitc.com/circleci-qp:6.4.6-openjdk11
<<: *docker_auth
- image: docker-adobe-cif-release.dr-uw2.adobeitc.com/circleci-aem-cloudready:6582-openjdk11
- image: docker-adobe-cif-release.dr-uw2.adobeitc.com/circleci-aem-cloudready:13804-openjdk11
<<: *docker_auth
test_executor_655:
docker:
- image: docker-adobe-cif-release.dr-uw2.adobeitc.com/circleci-qp:6.4.6-openjdk11
<<: *docker_auth
- image: docker-adobe-cif-release.dr-uw2.adobeitc.com/circleci-aem:6.5.11-openjdk11
- image: docker-adobe-cif-release.dr-uw2.adobeitc.com/circleci-aem:6.5.18.0-openjdk11
<<: *docker_auth

jobs:
Expand Down
14 changes: 14 additions & 0 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,20 @@ Import-Package: javax.annotation;version=0.0.0,*
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.12.4</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.12.7.1</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
/*******************************************************************************
*
* Copyright 2023 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*
******************************************************************************/
package com.venia.core.models.commerce;

import com.adobe.cq.commerce.core.components.models.common.ProductListItem;
import com.adobe.cq.commerce.core.components.models.searchresults.SearchResults;
import com.adobe.cq.commerce.core.components.storefrontcontext.SearchResultsStorefrontContext;
import com.adobe.cq.commerce.core.components.storefrontcontext.SearchStorefrontContext;
import com.adobe.cq.commerce.core.search.models.SearchResultsSet;
import com.adobe.cq.commerce.core.search.models.SorterKey;
import com.adobe.cq.commerce.magento.graphql.ProductAttributeFilterInput;
import com.adobe.cq.commerce.magento.graphql.ProductInterfaceQuery;
import com.adobe.cq.wcm.core.components.models.Component;
import com.adobe.cq.wcm.core.components.models.datalayer.ComponentData;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.Via;
import org.apache.sling.models.annotations.injectorspecific.Self;
import org.apache.sling.models.annotations.via.ResourceSuperType;

import javax.annotation.PostConstruct;
import java.lang.reflect.Proxy;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
import java.util.function.Function;

/**
* This class shows how to customize the sort fields of the product search results.
* As am example we remove the support for sorting by position.
* See the initModel() method for details.
*/
@Model(adaptables = SlingHttpServletRequest.class, adapters = SearchResults.class, resourceType = MySearchResultsImpl.RESOURCE_TYPE)
public class MySearchResultsImpl implements SearchResults , Component {
protected static final String RESOURCE_TYPE = "venia/components/commerce/searchresults";
@Self
@Via(type = ResourceSuperType.class)
SearchResults searchResults;

public MySearchResultsImpl() {
System.out.println("TEST");
}

@PostConstruct
public void initModel() {
// remove sort key with the name "position"
List<SorterKey> keys = searchResults.getSearchResultsSet().getSorter().getKeys();
if (keys != null) {
keys.removeIf(sorterKey -> sorterKey.getName().equals("position"));
}
}

@Override
public SearchStorefrontContext getSearchStorefrontContext() {
return searchResults.getSearchStorefrontContext();
}

@Override
public SearchResultsStorefrontContext getSearchResultsStorefrontContext() {
return searchResults.getSearchResultsStorefrontContext();
}

@Override
public void extendProductQueryWith(Consumer<ProductInterfaceQuery> consumer) {
searchResults.extendProductQueryWith(consumer);
}

@Override
public void extendProductFilterWith(Function<ProductAttributeFilterInput, ProductAttributeFilterInput> function) {
searchResults.extendProductFilterWith(function);
}

@Override
public Collection<ProductListItem> getProducts() {
return searchResults.getProducts();
}

@Override
public SearchResultsSet getSearchResultsSet() {
return searchResults.getSearchResultsSet();
}

@Override
public boolean loadClientPrice() {
return searchResults.loadClientPrice();
}

@Override
public String getPaginationType() {
return searchResults.getPaginationType();
}

@Override
public boolean isAddToCartEnabled() {
return searchResults.isAddToCartEnabled();
}

@Override
public boolean isAddToWishListEnabled() {
return searchResults.isAddToWishListEnabled();
}

@Override
public String getId() {
return ((Component)searchResults).getId();
}

@Override
public ComponentData getData() {
final ComponentData data = ((Component) searchResults).getData();
final AtomicReference<ComponentData> dataRef = new AtomicReference<>();
ComponentData componentData = (ComponentData) Proxy.newProxyInstance(this.getClass().getClassLoader(),
new Class[]{ComponentData.class}, (proxy, method, args) -> {
if (method.getName().equals("getJson")) {
return String.format("{\"%s\":%s}", getId(), new ObjectMapper().writeValueAsString(dataRef.get()));
} else if (method.getName().equals("getType")) {
return getExportedType();
}
return method.invoke(data, args);
});
dataRef.set(componentData);
return componentData;
}

@Override
public String getAppliedCssClasses() {
return ((Component)searchResults).getAppliedCssClasses();
}

@Override
public String getExportedType() {
return "venia/components/commerce/searchresults";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*******************************************************************************
*
* Copyright 2023 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*
******************************************************************************/
package com.venia.core.models.commerce;

import com.adobe.cq.commerce.core.components.models.searchresults.SearchResults;
import com.adobe.cq.commerce.core.components.services.urls.UrlProvider;
import com.adobe.cq.commerce.core.search.models.SearchResultsSet;
import com.adobe.cq.commerce.core.search.models.Sorter;
import com.adobe.cq.commerce.core.search.models.SorterKey;
import com.adobe.cq.commerce.core.search.services.SearchResultsService;
import com.adobe.cq.commerce.magento.graphql.ProductAttributeFilterInput;
import com.day.cq.wcm.api.Page;
import io.wcm.testing.mock.aem.junit5.AemContext;
import io.wcm.testing.mock.aem.junit5.AemContextExtension;
import org.apache.sling.testing.mock.sling.ResourceResolverType;
import org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.MockitoAnnotations;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

@ExtendWith(AemContextExtension.class)
public class MySearchResultsImplTest {
private static final String PAGE = "/content/page";
private final AemContext context = new AemContext(ResourceResolverType.JCR_MOCK);

private SearchResults underTest;

@BeforeEach
void beforeEach() {
MockitoAnnotations.initMocks(this);
Page page = context.create().page(PAGE);
Map<String, Object> props = new HashMap<>();
props.put("sling:resourceType", "venia/components/commerce/searchresults");
props.put("sling:resourceSuperType", "core/cif/components/commerce/searchresults/v1/searchresults");
context.create().resource(page, "test", props);
context.currentResource(PAGE + "/jcr:content/test");

SearchResultsService searchResultsService = mock(SearchResultsService.class);
SearchResultsSet searchResultsSet = mock(SearchResultsSet.class);
Function<ProductAttributeFilterInput, ProductAttributeFilterInput> a = any();
when(searchResultsService.performSearch(any(), any(), any(), any(), any(), a)).thenReturn(searchResultsSet);
Sorter sorter = mock(Sorter.class);
when(searchResultsSet.getSorter()).thenReturn(sorter);
SorterKey k1 = mock(SorterKey.class);
when(k1.getName()).thenReturn("k1");
SorterKey k2 = mock(SorterKey.class);
when(k2.getName()).thenReturn("k2");
SorterKey k3 = mock(SorterKey.class);
when(k3.getName()).thenReturn("position");
when(sorter.getKeys()).thenReturn(new ArrayList<>(Arrays.asList(k1, k2, k3)));

context.registerService(SearchResultsService.class, searchResultsService);
context.registerService(UrlProvider.class, mock(UrlProvider.class));
context.addModelsForClasses(MySearchResultsImpl.class);

MockSlingHttpServletRequest request = context.request();
request.addRequestParameter("search_query", "test");

underTest = request.adaptTo(MySearchResultsImpl.class);
Assertions.assertNotNull(underTest);
}

@Test
void testSorterKeys() {
List<SorterKey> keys = underTest.getSearchResultsSet().getSorter().getKeys();
assertFalse(keys.stream().anyMatch(sorterKey -> sorterKey.getName().equals("position")));
assertEquals(2, keys.size());
}
}
2 changes: 2 additions & 0 deletions it.tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<exclude.category></exclude.category>
</properties>


Expand Down Expand Up @@ -150,6 +151,7 @@
<sling.it.instance.adminPassword.2>${it.publish.password}
</sling.it.instance.adminPassword.2>
</systemPropertyVariables>
<excludedGroups>${exclude.category}</excludedGroups>
</configuration>
<executions>
<execution>
Expand Down
16 changes: 16 additions & 0 deletions it.tests/src/main/java/com/venia/it/category/IgnoreOn65.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*******************************************************************************
*
* Copyright 2023 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*
******************************************************************************/
package com.venia.it.category;

public interface IgnoreOn65 {}
16 changes: 16 additions & 0 deletions it.tests/src/main/java/com/venia/it/category/IgnoreOnCloud.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*******************************************************************************
*
* Copyright 2023 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*
******************************************************************************/
package com.venia.it.category;

public interface IgnoreOnCloud {}
Loading

0 comments on commit 8b9e70f

Please sign in to comment.