Fix replaceAll regex to handle spaces correctly

This commit is contained in:
Jeremy Daggett 2014-06-16 09:02:22 -07:00 committed by Jeremy Daggett
parent 235092e517
commit 1982626cd6
1 changed files with 9 additions and 2 deletions

View File

@ -28,6 +28,7 @@ import java.util.Properties;
import java.util.Set; import java.util.Set;
import java.util.concurrent.BlockingQueue; import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.LinkedBlockingQueue;
import java.util.regex.Pattern;
import org.jclouds.ContextBuilder; import org.jclouds.ContextBuilder;
import org.jclouds.concurrent.config.ExecutorServiceModule; import org.jclouds.concurrent.config.ExecutorServiceModule;
@ -58,6 +59,11 @@ public class BaseOpenStackMockTest<A extends Closeable> {
private final Set<Module> modules = ImmutableSet.<Module> of( private final Set<Module> modules = ImmutableSet.<Module> of(
new ExecutorServiceModule(sameThreadExecutor(), sameThreadExecutor())); new ExecutorServiceModule(sameThreadExecutor(), sameThreadExecutor()));
/**
* Pattern for replacing the URL token with the correct local address.
*/
private static final Pattern urlTokenPattern = Pattern.compile(":\\s*\"\\s*URL");
@SuppressWarnings("serial") @SuppressWarnings("serial")
public A api(String uri, String provider, Properties overrides) { public A api(String uri, String provider, Properties overrides) {
if (!overrides.containsKey(PROPERTY_MAX_RETRIES)) { if (!overrides.containsKey(PROPERTY_MAX_RETRIES)) {
@ -98,10 +104,11 @@ public class BaseOpenStackMockTest<A extends Closeable> {
if (response.getBody() != null) { if (response.getBody() != null) {
/* /*
* "URL" must be used in the service catalog sample (such as * "URL" must be used in the service catalog sample (such as
* access.json or accessRackspace) for the declared service * access.json or accessRackspace.json) for the declared service
* endpoints. * endpoints.
*/ */
String newBody = new String(response.getBody()).replace(":\"URL", ":\"" + url.toString()); String newBody = urlTokenPattern.matcher(new String(response.getBody())).replaceAll(": \"" + url.toString());
response = response.setBody(newBody); response = response.setBody(newBody);
} }
return response; return response;