From 90fb0b25f5ab1f40921e92d640fae80e40da6174 Mon Sep 17 00:00:00 2001 From: "John D. Ament" Date: Wed, 7 Sep 2016 19:04:14 -0400 Subject: [PATCH] #26 Switch URI look up to be based on the container's value, not HTTPContext. Fixed shrinkwrap version. --- pom.xml | 16 ++++---- .../client/ArquillianResourceLiteral.java | 35 ++++++++++++++++ .../rest/client/BaseRestEnricher.java | 41 +++++++++---------- warp-rest/ftest/ftest-jersey/pom.xml | 2 +- warp-rest/ftest/ftest-resteasy/pom.xml | 2 +- 5 files changed, 64 insertions(+), 32 deletions(-) create mode 100644 rest-client/impl/impl-base/src/main/java/org/jboss/arquillian/extension/rest/client/ArquillianResourceLiteral.java diff --git a/pom.xml b/pom.xml index 3864bd5..78f20e0 100644 --- a/pom.xml +++ b/pom.xml @@ -61,7 +61,7 @@ 4.11 1.10.19 1.4 - 2.2.3 + 2.2.4 3.0.0.Final 7.1.1.Final 3.1.2 @@ -120,13 +120,13 @@ pom - - org.jboss.shrinkwrap.resolver - shrinkwrap-resolver-depchain - ${version.shrinkwrap.resolvers} - test - pom - + + org.jboss.shrinkwrap.resolver + shrinkwrap-resolver-depchain + ${version.shrinkwrap.resolver} + test + pom + org.jboss.arquillian.test diff --git a/rest-client/impl/impl-base/src/main/java/org/jboss/arquillian/extension/rest/client/ArquillianResourceLiteral.java b/rest-client/impl/impl-base/src/main/java/org/jboss/arquillian/extension/rest/client/ArquillianResourceLiteral.java new file mode 100644 index 0000000..12a4b8a --- /dev/null +++ b/rest-client/impl/impl-base/src/main/java/org/jboss/arquillian/extension/rest/client/ArquillianResourceLiteral.java @@ -0,0 +1,35 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2011 Red Hat Inc. and/or its affiliates and other contributors + * as indicated by the @authors tag. All rights reserved. + * See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * 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 org.jboss.arquillian.extension.rest.client; + +import org.jboss.arquillian.test.api.ArquillianResource; + +import java.lang.annotation.Annotation; + +public final class ArquillianResourceLiteral implements ArquillianResource { + static final ArquillianResource INSTANCE = new ArquillianResourceLiteral(); + @Override + public Class value() { + return ArquillianResource.class; + } + + @Override + public Class annotationType() { + return ArquillianResource.class; + } +} \ No newline at end of file diff --git a/rest-client/impl/impl-base/src/main/java/org/jboss/arquillian/extension/rest/client/BaseRestEnricher.java b/rest-client/impl/impl-base/src/main/java/org/jboss/arquillian/extension/rest/client/BaseRestEnricher.java index dc77759..268ca9e 100644 --- a/rest-client/impl/impl-base/src/main/java/org/jboss/arquillian/extension/rest/client/BaseRestEnricher.java +++ b/rest-client/impl/impl-base/src/main/java/org/jboss/arquillian/extension/rest/client/BaseRestEnricher.java @@ -17,12 +17,11 @@ */ package org.jboss.arquillian.extension.rest.client; -import org.jboss.arquillian.container.spi.client.protocol.metadata.HTTPContext; -import org.jboss.arquillian.container.spi.client.protocol.metadata.ProtocolMetaData; -import org.jboss.arquillian.container.spi.client.protocol.metadata.Servlet; import org.jboss.arquillian.core.api.Instance; import org.jboss.arquillian.core.api.annotation.Inject; +import org.jboss.arquillian.core.spi.ServiceLoader; import org.jboss.arquillian.test.spi.TestEnricher; +import org.jboss.arquillian.test.spi.enricher.resource.ResourceProvider; import javax.ws.rs.Consumes; import javax.ws.rs.Produces; @@ -31,19 +30,17 @@ import java.lang.reflect.AnnotatedElement; import java.lang.reflect.Method; import java.net.URI; +import java.util.Collection; import java.util.HashMap; -import java.util.HashSet; -import java.util.List; import java.util.Map; -import java.util.Set; public abstract class BaseRestEnricher implements TestEnricher { @Inject - private Instance metaDataInst; + private Instance responseInst; @Inject - private Instance responseInst; + private Instance loader; @Override public void enrich(Object testCase) @@ -89,25 +86,25 @@ private void addHeaders(Map headersMap, Header annotation) } } - protected boolean allInSameContext(List servlets) - { - Set context = new HashSet(); - for (Servlet servlet : servlets) { - context.add(servlet.getContextRoot()); - } - return context.size() == 1; - } - protected abstract Object enrichByType(Class clazz, Method method, ArquillianResteasyResource annotation, Consumes consumes, Produces produces); - // Currently no way to share @ArquillianResource URL (URLResourceProvider) logic internally, copied logic + // Currently no way to request value of URI, need to manually invoke the lookup protected URI getBaseURL() { - HTTPContext context = metaDataInst.get().getContext(HTTPContext.class); - if (allInSameContext(context.getServlets())) { - return context.getServlets().get(0).getBaseURI(); + Collection resourceProviders = loader.get().all(ResourceProvider.class); + for(ResourceProvider resourceProvider: resourceProviders) + { + if(resourceProvider.canProvide(URI.class)) + { + Object value = resourceProvider.lookup(ArquillianResourceLiteral.INSTANCE); + if(value == null) + { + throw new RuntimeException("Provider for type URI returned a null value: " + resourceProvider); + } + return (URI)value; + } } - throw new IllegalStateException("No baseURL found in HTTPContext"); + throw new IllegalArgumentException("No ResourceProvider found for URI"); } protected Map getHeaders(Class clazz, Method method) diff --git a/warp-rest/ftest/ftest-jersey/pom.xml b/warp-rest/ftest/ftest-jersey/pom.xml index 4b76f7c..f660ab2 100644 --- a/warp-rest/ftest/ftest-jersey/pom.xml +++ b/warp-rest/ftest/ftest-jersey/pom.xml @@ -84,7 +84,7 @@ org.jboss.shrinkwrap.resolver shrinkwrap-resolver-impl-maven - ${version.shrinkwrap.resolvers} + ${version.shrinkwrap.resolver} test diff --git a/warp-rest/ftest/ftest-resteasy/pom.xml b/warp-rest/ftest/ftest-resteasy/pom.xml index 0c8de6d..b906cde 100644 --- a/warp-rest/ftest/ftest-resteasy/pom.xml +++ b/warp-rest/ftest/ftest-resteasy/pom.xml @@ -89,7 +89,7 @@ org.jboss.shrinkwrap.resolver shrinkwrap-resolver-impl-maven - ${version.shrinkwrap.resolvers} + ${version.shrinkwrap.resolver} test