-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(#821): Allow direct access to path/jsonPath in variables
- Loading branch information
Showing
22 changed files
with
1,156 additions
and
236 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
22 changes: 22 additions & 0 deletions
22
core/citrus-api/src/main/java/com/consol/citrus/util/IsJsonPredicate.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,22 @@ | ||
package com.consol.citrus.util; | ||
|
||
import java.util.function.Predicate; | ||
|
||
/** | ||
* Tests if a string represents a Json. An empty string is considered to be a | ||
* valid Json. | ||
*/ | ||
public class IsJsonPredicate implements Predicate<String> { | ||
|
||
public static IsJsonPredicate INSTANCE = new IsJsonPredicate(); | ||
|
||
@Override | ||
public boolean test(String toTest) { | ||
|
||
if (toTest != null) { | ||
toTest = toTest.trim(); | ||
} | ||
|
||
return toTest != null && (toTest.length() == 0 || toTest.startsWith("{") || toTest.startsWith("[")); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
core/citrus-api/src/main/java/com/consol/citrus/util/IsXmlPredicate.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,19 @@ | ||
package com.consol.citrus.util; | ||
|
||
import java.util.function.Predicate; | ||
|
||
/** | ||
* Tests if a string represents a XML. An empty string is considered to be a valid XML. | ||
*/ | ||
public class IsXmlPredicate implements Predicate<String> { | ||
|
||
public static IsXmlPredicate INSTANCE = new IsXmlPredicate(); | ||
@Override | ||
public boolean test(String toTest) { | ||
|
||
if (toTest != null) { | ||
toTest = toTest.trim(); | ||
} | ||
return toTest!=null && (toTest.length() == 0 || toTest.startsWith("<")); | ||
} | ||
} |
200 changes: 0 additions & 200 deletions
200
core/citrus-api/src/main/java/com/consol/citrus/util/VariableExpressionIterator.java
This file was deleted.
Oops, something went wrong.
77 changes: 77 additions & 0 deletions
77
core/citrus-api/src/main/java/com/consol/citrus/variable/SegmentVariableExtractor.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,77 @@ | ||
/* | ||
* Copyright 2006-2010 the original author or authors. | ||
* | ||
* Licensed 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 CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.consol.citrus.variable; | ||
|
||
import com.consol.citrus.context.TestContext; | ||
import com.consol.citrus.exceptions.CitrusRuntimeException; | ||
import com.consol.citrus.spi.ResourcePathTypeResolver; | ||
import com.consol.citrus.spi.TypeResolver; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.Map; | ||
|
||
/** | ||
* Class extracting values of segments of VariableExpressions. | ||
* | ||
* @author Thorsten Schlathoelter | ||
*/ | ||
public interface SegmentVariableExtractor { | ||
|
||
/** Logger */ | ||
Logger LOG = LoggerFactory.getLogger(SegmentVariableExtractor.class); | ||
|
||
/** Segment variable extractor resource lookup path */ | ||
String RESOURCE_PATH = "META-INF/citrus/variable/extractor/segment"; | ||
|
||
/** Type resolver to find custom segment variable extractors on classpath via resource path lookup */ | ||
TypeResolver TYPE_RESOLVER = new ResourcePathTypeResolver(RESOURCE_PATH); | ||
|
||
/** | ||
* Resolves extractor from resource path lookup with given extractor resource name. Scans classpath for extractor meta information | ||
* with given name and returns instance of extractor. Returns optional instead of throwing exception when no extractor | ||
* could be found. | ||
* @return | ||
*/ | ||
static Collection<SegmentVariableExtractor> lookup() { | ||
try { | ||
Map<String, SegmentVariableExtractor> extractors = TYPE_RESOLVER.resolveAll(); | ||
return extractors.values(); | ||
} catch (CitrusRuntimeException e) { | ||
LOG.warn(String.format("Failed to resolve segment variable extractor from resource '%s'", RESOURCE_PATH)); | ||
} | ||
|
||
return Collections.emptyList(); | ||
} | ||
|
||
/** | ||
* Extract variables from given object. | ||
* @param object the object of which to extract the value | ||
* @param matcher | ||
*/ | ||
boolean canExtract(TestContext testContext, Object object, VariableExpressionSegmentMatcher matcher); | ||
|
||
/** | ||
* Extract variables from given object. Implementations should throw a CitrusRuntimeException | ||
* @param object the object of which to extract the value | ||
* @param matcher | ||
*/ | ||
Object extractValue(TestContext testContext, Object object, VariableExpressionSegmentMatcher matcher); | ||
|
||
} |
Oops, something went wrong.