Skip to content

Commit

Permalink
arquillian#26 Switch URI look up to be based on the container's value…
Browse files Browse the repository at this point in the history
…, not HTTPContext. Fixed shrinkwrap version.
  • Loading branch information
johnament committed Sep 7, 2016
1 parent 50e9351 commit 9ae940b
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 32 deletions.
16 changes: 8 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<version.junit>4.11</version.junit>
<version.mockito>1.10.19</version.mockito>
<version.fest.assert>1.4</version.fest.assert>
<version.shrinkwrap.resolvers>2.2.3</version.shrinkwrap.resolvers>
<version.shrinkwrap.resolver>2.2.4</version.shrinkwrap.resolver>
<version.jboss_spec>3.0.0.Final</version.jboss_spec>
<version.org.jboss.jbossas>7.1.1.Final</version.org.jboss.jbossas>
<version.org.glassfish>3.1.2</version.org.glassfish>
Expand Down Expand Up @@ -120,13 +120,13 @@
<type>pom</type>
</dependency>

<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-depchain</artifactId>
<version>${version.shrinkwrap.resolvers}</version>
<scope>test</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-depchain</artifactId>
<version>${version.shrinkwrap.resolver}</version>
<scope>test</scope>
<type>pom</type>
</dependency>

<dependency>
<groupId>org.jboss.arquillian.test</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* 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 javax.enterprise.util.AnnotationLiteral;

public final class ArquillianResourceLiteral extends AnnotationLiteral<ArquillianResource> implements ArquillianResource {
static final ArquillianResource INSTANCE = new ArquillianResourceLiteral();
@Override
public Class<?> value() {
return ArquillianResource.class;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<ProtocolMetaData> metaDataInst;
private Instance<Response> responseInst;

@Inject
private Instance<Response> responseInst;
private Instance<ServiceLoader> loader;

@Override
public void enrich(Object testCase)
Expand Down Expand Up @@ -89,25 +86,25 @@ private void addHeaders(Map<String, String> headersMap, Header annotation)
}
}

protected boolean allInSameContext(List<Servlet> servlets)
{
Set<String> context = new HashSet<String>();
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<ResourceProvider> 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<String, String> getHeaders(Class<?> clazz, Method method)
Expand Down
2 changes: 1 addition & 1 deletion warp-rest/ftest/ftest-jersey/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-impl-maven</artifactId>
<version>${version.shrinkwrap.resolvers}</version>
<version>${version.shrinkwrap.resolver}</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
2 changes: 1 addition & 1 deletion warp-rest/ftest/ftest-resteasy/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-impl-maven</artifactId>
<version>${version.shrinkwrap.resolvers}</version>
<version>${version.shrinkwrap.resolver}</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down

0 comments on commit 9ae940b

Please sign in to comment.