Skip to content

Commit abbfd3e

Browse files
committed
SITES-28169: Resolved the unit test cases issues
1 parent d144628 commit abbfd3e

28 files changed

+182
-28
lines changed

bundles/core/pom.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@
582582
<dependency>
583583
<groupId>com.adobe.aem</groupId>
584584
<artifactId>aem-cif-sdk-api</artifactId>
585-
<version>2022.08.02.00</version>
585+
<version>2023.11.23.00</version>
586586
<scope>provided</scope>
587587
</dependency>
588588
<dependency>
@@ -597,6 +597,12 @@
597597
<version>${magento.graphql.version}</version>
598598
<scope>provided</scope>
599599
</dependency>
600+
<dependency>
601+
<groupId>org.apache.httpcomponents</groupId>
602+
<artifactId>httpcore</artifactId>
603+
<version>4.4.16</version>
604+
<scope>test</scope>
605+
</dependency>
600606
</dependencies>
601607

602608
<developers>

bundles/core/src/test/java/com/adobe/cq/commerce/core/components/internal/models/v1/breadcrumb/BreadcrumbImplTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.stream.Collectors;
2222

2323
import org.apache.http.HttpStatus;
24+
import org.apache.http.client.HttpClient;
2425
import org.apache.http.impl.client.CloseableHttpClient;
2526
import org.apache.http.osgi.services.HttpClientBuilderFactory;
2627
import org.apache.sling.api.resource.ModifiableValueMap;
@@ -103,6 +104,10 @@ public void setUp() throws Exception {
103104
context.registerService(HttpClientBuilderFactory.class, new MockHttpClientBuilderFactory(httpClient));
104105

105106
graphqlClient = Mockito.spy(new GraphqlClientImpl());
107+
108+
// Mock and set the protected 'client' field
109+
Utils.setClientField(graphqlClient, mock(HttpClient.class));
110+
106111
// Activate the GraphqlClientImpl with configuration
107112
context.registerInjectActivateService(graphqlClient, ImmutableMap.<String, Object>builder()
108113
.put("httpMethod", "POST")

bundles/core/src/test/java/com/adobe/cq/commerce/core/components/internal/models/v1/button/ButtonImplTest.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
1616
package com.adobe.cq.commerce.core.components.internal.models.v1.button;
1717

18+
import org.apache.http.client.HttpClient;
1819
import org.apache.http.osgi.services.HttpClientBuilderFactory;
1920
import org.apache.sling.api.resource.Resource;
2021
import org.apache.sling.api.resource.ValueMap;
@@ -38,8 +39,7 @@
3839

3940
import static com.adobe.cq.commerce.core.testing.TestContext.newAemContext;
4041
import static org.junit.Assert.assertEquals;
41-
import static org.mockito.Mockito.spy;
42-
import static org.mockito.Mockito.when;
42+
import static org.mockito.Mockito.*;
4343

4444
public class ButtonImplTest {
4545

@@ -58,6 +58,9 @@ public void setUp() throws Exception {
5858
context.registerService(HttpClientBuilderFactory.class, new MockHttpClientBuilderFactory());
5959
GraphqlClient graphqlClient = new GraphqlClientImpl();
6060

61+
// Mock and set the protected 'client' field
62+
Utils.setClientField(graphqlClient, mock(HttpClient.class));
63+
6164
// Activate the GraphqlClientImpl with configuration
6265
context.registerInjectActivateService(graphqlClient, ImmutableMap.<String, Object>builder()
6366
.put("httpMethod", "POST")

bundles/core/src/test/java/com/adobe/cq/commerce/core/components/internal/models/v1/categorylist/FeaturedCategoryListImplTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.List;
2121

2222
import org.apache.http.HttpStatus;
23+
import org.apache.http.client.HttpClient;
2324
import org.apache.http.impl.client.CloseableHttpClient;
2425
import org.apache.http.osgi.services.HttpClientBuilderFactory;
2526
import org.apache.sling.api.resource.Resource;
@@ -101,6 +102,10 @@ private void setupTest(String componentPath, boolean withNullGraphqlClient) thro
101102
CloseableHttpClient httpClient = mock(CloseableHttpClient.class);
102103
context.registerService(HttpClientBuilderFactory.class, new MockHttpClientBuilderFactory(httpClient));
103104
GraphqlClient graphqlClient = new GraphqlClientImpl();
105+
106+
// Mock and set the protected 'client' field
107+
Utils.setClientField(graphqlClient, mock(HttpClient.class));
108+
104109
// Activate the GraphqlClientImpl with configuration
105110
context.registerInjectActivateService(graphqlClient, ImmutableMap.<String, Object>builder()
106111
.put("httpMethod", "POST")

bundles/core/src/test/java/com/adobe/cq/commerce/core/components/internal/models/v1/contentfragment/CommerceContentFragmentImplTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import org.apache.commons.lang3.StringUtils;
2323
import org.apache.http.HttpStatus;
24+
import org.apache.http.client.HttpClient;
2425
import org.apache.http.impl.client.CloseableHttpClient;
2526
import org.apache.http.osgi.services.HttpClientBuilderFactory;
2627
import org.apache.sling.api.resource.Resource;
@@ -110,6 +111,10 @@ public void setup() throws Exception {
110111
context.registerService(HttpClientBuilderFactory.class, new MockHttpClientBuilderFactory(httpClient));
111112

112113
GraphqlClient graphqlClient = Mockito.spy(new GraphqlClientImpl());
114+
115+
// Mock and set the protected 'client' field
116+
Utils.setClientField(graphqlClient, mock(HttpClient.class));
117+
113118
// Activate the GraphqlClientImpl with configuration
114119
context.registerInjectActivateService(graphqlClient, ImmutableMap.<String, Object>builder()
115120
.put("httpMethod", "POST")

bundles/core/src/test/java/com/adobe/cq/commerce/core/components/internal/models/v1/experiencefragment/CommerceExperienceFragmentImplTest.java

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.Collections;
2020

2121
import org.apache.http.HttpStatus;
22+
import org.apache.http.client.HttpClient;
2223
import org.apache.http.impl.client.CloseableHttpClient;
2324
import org.apache.http.osgi.services.HttpClientBuilderFactory;
2425
import org.apache.sling.api.resource.Resource;
@@ -91,7 +92,7 @@ public class CommerceExperienceFragmentImplTest {
9192
})
9293
.build();
9394

94-
private void setup(String pagePath, String resourcePath) throws IOException {
95+
private void setup(String pagePath, String resourcePath) throws IOException, NoSuchFieldException, IllegalAccessException {
9596
Page page = spy(context.currentPage(pagePath));
9697
Resource xfResource = context.resourceResolver().getResource(pagePath + resourcePath);
9798
context.currentResource(xfResource);
@@ -104,6 +105,10 @@ private void setup(String pagePath, String resourcePath) throws IOException {
104105
CloseableHttpClient httpClient = mock(CloseableHttpClient.class);
105106
context.registerService(HttpClientBuilderFactory.class, new MockHttpClientBuilderFactory(httpClient));
106107
GraphqlClient graphqlClient = Mockito.spy(new GraphqlClientImpl());
108+
109+
// Mock and set the protected 'client' field
110+
Utils.setClientField(graphqlClient, mock(HttpClient.class));
111+
107112
// Activate the GraphqlClientImpl with configuration
108113
context.registerInjectActivateService(graphqlClient, ImmutableMap.<String, Object>builder()
109114
.put("httpMethod", "POST")
@@ -133,7 +138,7 @@ private void setup(String pagePath, String resourcePath) throws IOException {
133138
}
134139

135140
@Test
136-
public void testFragmentOnProductPageWithoutLocationProperty() throws IOException {
141+
public void testFragmentOnProductPageWithoutLocationProperty() throws IOException, NoSuchFieldException, IllegalAccessException {
137142
setup(PRODUCT_PAGE, RESOURCE_XF1);
138143

139144
MockRequestPathInfo requestPathInfo = (MockRequestPathInfo) context.request().getRequestPathInfo();
@@ -144,7 +149,7 @@ public void testFragmentOnProductPageWithoutLocationProperty() throws IOExceptio
144149
}
145150

146151
@Test
147-
public void testFragmentOnProductPageWithLocationProperty() throws IOException {
152+
public void testFragmentOnProductPageWithLocationProperty() throws IOException, NoSuchFieldException, IllegalAccessException {
148153
setup(PRODUCT_PAGE, RESOURCE_XF2);
149154

150155
MockRequestPathInfo requestPathInfo = (MockRequestPathInfo) context.request().getRequestPathInfo();
@@ -155,7 +160,7 @@ public void testFragmentOnProductPageWithLocationProperty() throws IOException {
155160
}
156161

157162
@Test
158-
public void testFragmentOnProductPageWithoutMatchingSkus() throws IOException {
163+
public void testFragmentOnProductPageWithoutMatchingSkus() throws IOException, NoSuchFieldException, IllegalAccessException {
159164
setup(PRODUCT_PAGE, RESOURCE_XF2);
160165

161166
MockRequestPathInfo requestPathInfo = (MockRequestPathInfo) context.request().getRequestPathInfo();
@@ -165,7 +170,7 @@ public void testFragmentOnProductPageWithoutMatchingSkus() throws IOException {
165170
}
166171

167172
@Test
168-
public void testFragmentOnProductPageWhenProductNotFound() throws IOException {
173+
public void testFragmentOnProductPageWhenProductNotFound() throws IOException, NoSuchFieldException, IllegalAccessException {
169174
setup(PRODUCT_PAGE, RESOURCE_XF1);
170175

171176
CommerceExperienceFragmentImpl cxf = context.request().adaptTo(CommerceExperienceFragmentImpl.class);
@@ -174,7 +179,7 @@ public void testFragmentOnProductPageWhenProductNotFound() throws IOException {
174179
}
175180

176181
@Test
177-
public void testFragmentOnNonProductOrCategoryPage() throws IOException {
182+
public void testFragmentOnNonProductOrCategoryPage() throws IOException, NoSuchFieldException, IllegalAccessException {
178183
setup(ANOTHER_PAGE, RESOURCE_XF1);
179184

180185
MockRequestPathInfo requestPathInfo = (MockRequestPathInfo) context.request().getRequestPathInfo();
@@ -184,7 +189,7 @@ public void testFragmentOnNonProductOrCategoryPage() throws IOException {
184189
}
185190

186191
@Test
187-
public void testFragmentOnCategoryPageWithoutLocationProperty() throws IOException {
192+
public void testFragmentOnCategoryPageWithoutLocationProperty() throws IOException, NoSuchFieldException, IllegalAccessException {
188193
setup(CATEGORY_PAGE, RESOURCE_XF1);
189194

190195
MockRequestPathInfo requestPathInfo = (MockRequestPathInfo) context.request().getRequestPathInfo();
@@ -195,7 +200,7 @@ public void testFragmentOnCategoryPageWithoutLocationProperty() throws IOExcepti
195200
}
196201

197202
@Test
198-
public void testFragmentOnCategoryPageWithLocationProperty() throws IOException {
203+
public void testFragmentOnCategoryPageWithLocationProperty() throws IOException, NoSuchFieldException, IllegalAccessException {
199204
setup(CATEGORY_PAGE, RESOURCE_XF2);
200205

201206
MockRequestPathInfo requestPathInfo = (MockRequestPathInfo) context.request().getRequestPathInfo();
@@ -206,7 +211,7 @@ public void testFragmentOnCategoryPageWithLocationProperty() throws IOException
206211
}
207212

208213
@Test
209-
public void testFragmentOnCategoryPageWithoutMatchingUids() throws IOException {
214+
public void testFragmentOnCategoryPageWithoutMatchingUids() throws IOException, NoSuchFieldException, IllegalAccessException {
210215
setup(CATEGORY_PAGE, RESOURCE_XF2);
211216

212217
MockRequestPathInfo requestPathInfo = (MockRequestPathInfo) context.request().getRequestPathInfo();
@@ -216,14 +221,14 @@ public void testFragmentOnCategoryPageWithoutMatchingUids() throws IOException {
216221
}
217222

218223
@Test
219-
public void testFragmentOnCategoryPageWithInvalidUid() throws IOException {
224+
public void testFragmentOnCategoryPageWithInvalidUid() throws IOException, NoSuchFieldException, IllegalAccessException {
220225
setup(CATEGORY_PAGE, RESOURCE_XF2);
221226

222227
verifyFragmentResourceIsNull(null, null, null);
223228
}
224229

225230
@Test
226-
public void testUIDSupportWithURLPathSelector() throws IOException {
231+
public void testUIDSupportWithURLPathSelector() throws IOException, NoSuchFieldException, IllegalAccessException {
227232
setup(CATEGORY_PAGE, RESOURCE_XF2);
228233

229234
MockRequestPathInfo requestPathInfo = (MockRequestPathInfo) context.request().getRequestPathInfo();

bundles/core/src/test/java/com/adobe/cq/commerce/core/components/internal/models/v1/list/CommerceListImplTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.Collection;
2020

2121
import org.apache.http.HttpStatus;
22+
import org.apache.http.client.HttpClient;
2223
import org.apache.http.impl.client.CloseableHttpClient;
2324
import org.apache.http.osgi.services.HttpClientBuilderFactory;
2425
import org.apache.sling.api.resource.Resource;
@@ -112,6 +113,10 @@ public void setup() throws Exception {
112113
context.registerService(HttpClientBuilderFactory.class, new MockHttpClientBuilderFactory(httpClient));
113114

114115
GraphqlClient graphqlClient = Mockito.spy(new GraphqlClientImpl());
116+
117+
// Mock and set the protected 'client' field
118+
Utils.setClientField(graphqlClient, mock(HttpClient.class));
119+
115120
// Activate the GraphqlClientImpl with configuration
116121
context.registerInjectActivateService(graphqlClient, ImmutableMap.<String, Object>builder()
117122
.put("httpMethod", "POST")

bundles/core/src/test/java/com/adobe/cq/commerce/core/components/internal/models/v1/navigation/GraphQLCategoryProviderTest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.stream.Collectors;
2424

2525
import org.apache.commons.lang3.StringUtils;
26+
import org.apache.http.client.HttpClient;
2627
import org.apache.http.osgi.services.HttpClientBuilderFactory;
2728
import org.apache.sling.api.resource.Resource;
2829
import org.apache.sling.api.resource.ValueMap;
@@ -82,8 +83,12 @@ private static AemContext createContext(String contentPath) {
8283
private GraphqlClient graphqlClient;
8384

8485
@Before
85-
public void setup() throws IOException {
86+
public void setup() throws IOException, NoSuchFieldException, IllegalAccessException {
8687
graphqlClient = new GraphqlClientImpl();
88+
89+
// Mock and set the protected 'client' field
90+
Utils.setClientField(graphqlClient, mock(HttpClient.class));
91+
8792
// Activate the GraphqlClientImpl with configuration
8893
context.registerInjectActivateService(graphqlClient, ImmutableMap.<String, Object>builder()
8994
.put("httpMethod", "POST")

bundles/core/src/test/java/com/adobe/cq/commerce/core/components/internal/models/v1/page/PageMetadataImplTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import javax.script.SimpleBindings;
2222

2323
import org.apache.http.HttpStatus;
24+
import org.apache.http.client.HttpClient;
2425
import org.apache.http.impl.client.CloseableHttpClient;
2526
import org.apache.http.osgi.services.HttpClientBuilderFactory;
2627
import org.apache.sling.api.resource.Resource;
@@ -187,6 +188,10 @@ private void testPageMetadataModelOnProductPage(String pagePath) throws Exceptio
187188
CloseableHttpClient httpClient = Mockito.mock(CloseableHttpClient.class);
188189
context.registerService(HttpClientBuilderFactory.class, new MockHttpClientBuilderFactory(httpClient));
189190
graphqlClient = Mockito.spy(new GraphqlClientImpl());
191+
192+
// Mock and set the protected 'client' field
193+
Utils.setClientField(graphqlClient, mock(HttpClient.class));
194+
190195
// Activate the GraphqlClientImpl with configuration
191196
context.registerInjectActivateService(graphqlClient, ImmutableMap.<String, Object>builder()
192197
.put("httpMethod", "POST")
@@ -273,6 +278,10 @@ private void testPageMetadataModelOnCategoryPage(String pagePath) throws Excepti
273278
context.registerService(HttpClientBuilderFactory.class, new MockHttpClientBuilderFactory(httpClient));
274279

275280
graphqlClient = Mockito.spy(new GraphqlClientImpl());
281+
282+
// Mock and set the protected 'client' field
283+
Utils.setClientField(graphqlClient, mock(HttpClient.class));
284+
276285
// Activate the GraphqlClientImpl with configuration
277286
context.registerInjectActivateService(graphqlClient, ImmutableMap.<String, Object>builder()
278287
.put("httpMethod", "POST")

bundles/core/src/test/java/com/adobe/cq/commerce/core/components/internal/models/v1/product/ProductImplAssetsTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.io.IOException;
1919
import java.util.List;
2020

21+
import org.apache.http.client.HttpClient;
2122
import org.apache.http.impl.client.CloseableHttpClient;
2223
import org.apache.http.osgi.services.HttpClientBuilderFactory;
2324
import org.apache.sling.api.resource.Resource;
@@ -98,7 +99,7 @@ public void testProductIncompleteAssets() throws Exception {
9899
Assert.assertEquals("a4", assets.get(2).getLabel());
99100
}
100101

101-
private void setUp(String graphqlResponse) throws IOException {
102+
private void setUp(String graphqlResponse) throws IOException, NoSuchFieldException, IllegalAccessException {
102103
Page page = context.currentPage(PAGE);
103104
CloseableHttpClient httpClient = mock(CloseableHttpClient.class);
104105
context.registerService(HttpClientBuilderFactory.class, new MockHttpClientBuilderFactory(httpClient));
@@ -108,6 +109,9 @@ private void setUp(String graphqlResponse) throws IOException {
108109

109110
GraphqlClient graphqlClient = new GraphqlClientImpl();
110111

112+
// Mock and set the protected 'client' field
113+
Utils.setClientField(graphqlClient, mock(HttpClient.class));
114+
111115
// Activate the GraphqlClientImpl with configuration
112116
context.registerInjectActivateService(graphqlClient, ImmutableMap.<String, Object>builder()
113117
.put("httpMethod", "POST")

0 commit comments

Comments
 (0)