Skip to content

Commit 829e1ca

Browse files
committed
Fixed: Test run was unsuccessful because of failing solr tests (OFBIZ-12595)
The previous commit for OFBIZ-12594 was only working on Windows. On *nix OSs there is no way to reliably get "--test" String from java.class.path property. Also the previous fix was brittle because relying only on 1 space separating words. This fix puts in the SolrDispatchFilter system property at the beginning of the 4 Solr tests and removes it at end of them. That presence can reliably be tested in ControlFilter that is called before SolrDispatchFilter. It allows to bypass SecurityUtil::containsFreemarkerInterpolation that would else change the parameters content type that must be application/x-www-form-urlencoded. content Thanks: Tom Pietsch for report and Mart Naum for confirmation Conflicts handled by hand
1 parent fae9da9 commit 829e1ca

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

solr/src/main/java/org/apache/ofbiz/solr/test/SolrTests.java

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ Licensed to the Apache Software Foundation (ASF) under one
2020

2121
package org.apache.ofbiz.solr.test;
2222

23-
import java.util.HashMap;
24-
import java.util.Map;
2523
import java.util.ArrayList;
24+
import java.util.HashMap;
2625
import java.util.List;
26+
import java.util.Map;
2727

2828
import org.apache.ofbiz.entity.GenericValue;
2929
import org.apache.ofbiz.entity.util.EntityQuery;
@@ -75,11 +75,14 @@ public void testAddProductToIndex() throws Exception {
7575
throw new Exception(errorMessage);
7676
}
7777
assertTrue("Could not query search index", ServiceUtil.isSuccess(sresp));
78-
79-
8078
}
8179

82-
public void testAddToSolrIndex() throws Exception{
80+
/**
81+
* Test add to solr index.
82+
* @throws Exception the exception
83+
*/
84+
public void testAddToSolrIndex() throws Exception {
85+
System.setProperty("SolrDispatchFilter", "runsAfterControlFilter");
8386
context = new HashMap<>();
8487
context.put("productId", validTestProductId);
8588
response = dispatcher.runSync("addToSolrIndex", context);
@@ -89,9 +92,15 @@ public void testAddToSolrIndex() throws Exception{
8992
}
9093
assertTrue("Could not add Product to Index", ServiceUtil.isSuccess(
9194
response));
95+
System.clearProperty("SolrDispatchFilter");
9296
}
9397

94-
public void testAddToSolrIndex_invalidProduct() throws Exception {
98+
/**
99+
* Test add to solr index invalid product.
100+
* @throws Exception the exception
101+
*/
102+
public void testAddToSolrIndexInvalidProduct() throws Exception {
103+
System.setProperty("SolrDispatchFilter", "runsAfterControlFilter");
95104
context = new HashMap<>();
96105
context.put("productId", invalidTestProductId);
97106
response = dispatcher.runSync("addToSolrIndex", context);
@@ -101,9 +110,11 @@ public void testAddToSolrIndex_invalidProduct() throws Exception {
101110
}
102111
assertTrue("Could not test the addition of an invalid product to the Solr index", ServiceUtil.isSuccess(
103112
response));
113+
System.clearProperty("SolrDispatchFilter");
104114
}
105115

106116
public void testAddListToSolrIndex() throws Exception {
117+
System.setProperty("SolrDispatchFilter", "runsAfterControlFilter");
107118
List<Map<String, Object>> products = new ArrayList<>();
108119
Map<String, Object> product_1 = new HashMap<>();
109120
Map<String, Object> product_2 = new HashMap<>();
@@ -124,10 +135,15 @@ public void testAddListToSolrIndex() throws Exception {
124135
throw new Exception(errorMessage);
125136
}
126137
assertTrue("Could not add products to index", ServiceUtil.isSuccess(response));
127-
138+
System.clearProperty("SolrDispatchFilter");
128139
}
129140

130-
public void testAddListToSolrIndex_invalidProducts() throws Exception {
141+
/**
142+
* Test add list to solr index invalid products.
143+
* @throws Exception the exception
144+
*/
145+
public void testAddListToSolrIndexInvalidProducts() throws Exception {
146+
System.setProperty("SolrDispatchFilter", "runsAfterControlFilter");
131147
List<Map<String, Object>> products = new ArrayList<>();
132148
Map<String, Object> product_1 = new HashMap<>();
133149
Map<String, Object> product_2 = new HashMap<>();
@@ -151,7 +167,7 @@ public void testAddListToSolrIndex_invalidProducts() throws Exception {
151167
throw new Exception(errorMessage);
152168
}
153169
assertTrue("Could not test adding invalid products to index", ServiceUtil.isSuccess(response));
154-
170+
System.clearProperty("SolrDispatchFilter");
155171
}
156172
}
157173

0 commit comments

Comments
 (0)