This repository has been archived by the owner on Jun 7, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support @ArquillianResource URLs [SWARM-200]
This only works if the user is using the default bind address, port, and context path, or override them via `jboss.bind.address`, `jboss.http.port`, and `wildfly.swarm.context.path`, respectively. Overriding them via code won't affect the injected URL.
- Loading branch information
Showing
7 changed files
with
245 additions
and
19 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
...pi/src/main/java/org/wildfly/swarm/arquillian/adapter/WildFlySwarmDeploymentAppender.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,48 @@ | ||
/* | ||
* Copyright 2015 Red Hat, Inc, and 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.wildfly.swarm.arquillian.adapter; | ||
|
||
import org.jboss.arquillian.container.test.impl.RemoteExtensionLoader; | ||
import org.jboss.arquillian.container.test.spi.RemoteLoadableExtension; | ||
import org.jboss.arquillian.container.test.spi.client.deployment.CachedAuxilliaryArchiveAppender; | ||
import org.jboss.shrinkwrap.api.Archive; | ||
import org.jboss.shrinkwrap.api.ExtensionLoader; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
|
||
public class WildFlySwarmDeploymentAppender extends CachedAuxilliaryArchiveAppender { | ||
@Override | ||
protected Archive<?> buildArchive() { | ||
return ShrinkWrap.create(JavaArchive.class) | ||
.addPackages( | ||
true, | ||
// "org.jboss.arquillian.core", | ||
// "org.jboss.arquillian.container.spi", | ||
// "org.jboss.arquillian.container.impl", | ||
// "org.jboss.arquillian.container.test.api", | ||
"org.jboss.arquillian.container.test.spi", | ||
"org.wildfly.swarm.arquillian.resources" | ||
// "org.jboss.arquillian.container.test.impl", | ||
// "org.jboss.arquillian.config", | ||
// "org.jboss.arquillian.test", | ||
// "org.jboss.shrinkwrap.api", | ||
// "org.jboss.shrinkwrap.descriptor.api" | ||
) | ||
.addClass(WildFlySwarmRemoteExtension.class) | ||
.addAsServiceProvider(RemoteLoadableExtension.class, WildFlySwarmRemoteExtension.class) | ||
.addAsServiceProvider(ExtensionLoader.class, RemoteExtensionLoader.class); | ||
} | ||
} |
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
31 changes: 31 additions & 0 deletions
31
...n/api/src/main/java/org/wildfly/swarm/arquillian/adapter/WildFlySwarmRemoteExtension.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,31 @@ | ||
/** | ||
* Copyright 2015 Red Hat, Inc, and 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.wildfly.swarm.arquillian.adapter; | ||
|
||
import org.jboss.arquillian.container.test.impl.enricher.resource.URIResourceProvider; | ||
import org.jboss.arquillian.container.test.impl.enricher.resource.URLResourceProvider; | ||
import org.jboss.arquillian.container.test.spi.RemoteLoadableExtension; | ||
import org.jboss.arquillian.test.spi.enricher.resource.ResourceProvider; | ||
import org.wildfly.swarm.arquillian.resources.SwarmURIResourceProvider; | ||
import org.wildfly.swarm.arquillian.resources.SwarmURLResourceProvider; | ||
|
||
public class WildFlySwarmRemoteExtension implements RemoteLoadableExtension { | ||
@Override | ||
public void register(ExtensionBuilder builder) { | ||
builder.override(ResourceProvider.class, URLResourceProvider.class, SwarmURLResourceProvider.class) | ||
.override(ResourceProvider.class, URIResourceProvider.class, SwarmURIResourceProvider.class); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...an/api/src/main/java/org/wildfly/swarm/arquillian/resources/SwarmURIResourceProvider.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,43 @@ | ||
/* | ||
* Copyright 2015 Red Hat, Inc, and 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.wildfly.swarm.arquillian.resources; | ||
|
||
import org.jboss.arquillian.test.api.ArquillianResource; | ||
|
||
import java.lang.annotation.Annotation; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.net.URL; | ||
|
||
public class SwarmURIResourceProvider extends SwarmURLResourceProvider { | ||
@Override | ||
public Object lookup(ArquillianResource resource, Annotation... qualifiers) { | ||
Object object = super.lookup(resource, qualifiers); | ||
if (object == null) { | ||
return null; | ||
} | ||
try { | ||
return ((URL) object).toURI(); | ||
} catch (URISyntaxException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean canProvide(Class<?> type) { | ||
return URI.class.isAssignableFrom(type); | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
...an/api/src/main/java/org/wildfly/swarm/arquillian/resources/SwarmURLResourceProvider.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,60 @@ | ||
/** | ||
* Copyright 2015 Red Hat, Inc, and 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.wildfly.swarm.arquillian.resources; | ||
|
||
import org.jboss.arquillian.container.test.impl.enricher.resource.OperatesOnDeploymentAwareProvider; | ||
import org.jboss.arquillian.test.api.ArquillianResource; | ||
|
||
import java.lang.annotation.Annotation; | ||
import java.net.MalformedURLException; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.net.URL; | ||
|
||
public class SwarmURLResourceProvider extends OperatesOnDeploymentAwareProvider { | ||
@Override | ||
public boolean canProvide(Class<?> type) { | ||
return URL.class.isAssignableFrom(type); | ||
} | ||
|
||
@Override | ||
public Object doLookup(ArquillianResource resource, Annotation... __) { | ||
|
||
// first cut - try to get the data from the sysprops | ||
// this will fail if the user sets any of these via code | ||
String host = System.getProperty("jboss.bind.address"); | ||
if (host == null || host.equals("0.0.0.0")) { | ||
host = "localhost"; | ||
} | ||
|
||
int port = 8080; | ||
final String portString = System.getProperty("jboss.http.port"); | ||
if (portString != null) { | ||
port = Integer.parseInt(portString); | ||
} | ||
|
||
String contextPath = System.getProperty("wildfly.swarm.context.path"); | ||
if (contextPath == null) { | ||
contextPath = "/"; | ||
} | ||
|
||
try { | ||
return new URI("http", null, host, port, contextPath, null, null).toURL(); | ||
} catch (MalformedURLException | URISyntaxException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
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