-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
commit 6ab7e69 Author: Markus Perndorfer <mpern@users.noreply.github.com> Date: Mon Mar 15 11:58:35 2021 +0100 validate solrVersion
- Loading branch information
Showing
9 changed files
with
115 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
28 changes: 28 additions & 0 deletions
28
...integrationTest/groovy/mpern/sap/commerce/ccv2/validation/SolrVersionValidatorSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package mpern.sap.commerce.ccv2.validation | ||
|
||
import groovy.json.JsonSlurper | ||
import spock.lang.Specification | ||
|
||
import mpern.sap.commerce.ccv2.model.Manifest | ||
import mpern.sap.commerce.ccv2.validation.impl.SolrVersionValidator | ||
|
||
class SolrVersionValidatorSpec extends Specification { | ||
def "solrVersion version must a valid Solr major.minor version"() { | ||
given: | ||
def rawManifest = new JsonSlurper().parseText(''' | ||
{ | ||
"commerceSuiteVersion": "2011", | ||
"solrVersion": "8.6.3" | ||
} | ||
''') as Map<String, Object> | ||
Manifest manifest = Manifest.fromMap(rawManifest) | ||
def validator = new SolrVersionValidator(); | ||
|
||
when: | ||
def faultySolr = validator.validate(manifest) | ||
|
||
then: | ||
faultySolr.size() == 1 | ||
faultySolr.any{ it.location == "solrVersion" && it.level == Level.ERROR } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/main/java/mpern/sap/commerce/ccv2/validation/impl/SolrVersionValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package mpern.sap.commerce.ccv2.validation.impl; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
import mpern.sap.commerce.ccv2.model.Manifest; | ||
import mpern.sap.commerce.ccv2.validation.Error; | ||
import mpern.sap.commerce.ccv2.validation.Validator; | ||
|
||
public class SolrVersionValidator implements Validator { | ||
private static final Pattern SOLR_VERSION = Pattern.compile("^\\d+\\.\\d+$"); | ||
|
||
@Override | ||
public List<Error> validate(Manifest manifest) throws Exception { | ||
if (!manifest.solrVersion.isEmpty()) { | ||
final Matcher matcher = SOLR_VERSION.matcher(manifest.solrVersion); | ||
if (!matcher.matches()) { | ||
return Collections.singletonList(new Error.Builder().setLocation("solrVersion").setCode("E-018") | ||
.setMessage("Invalid Solr version").createError()); | ||
} | ||
} | ||
return Collections.emptyList(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters