Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ARQ-438 @DeploymentName and @OperatesOnDeployment could be made typesafe #16

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2009, Red Hat Middleware LLC, and individual contributors
* by the @authors tag. 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.container.test.api;

import static java.lang.annotation.RetentionPolicy.RUNTIME;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

/**
* Identify an annotation as a name for a deployment.
*
* @author Davide D'Alto
*/
@Documented
@Retention(RUNTIME)
@Target(ElementType.ANNOTATION_TYPE)
public @interface DeploymentName {
/**
* The name of the deployment
*/
String value();
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
package org.jboss.arquillian.container.test.impl.client;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

import org.jboss.arquillian.container.spi.Container;
Expand All @@ -35,6 +36,7 @@
import org.jboss.arquillian.container.spi.event.StopSuiteContainers;
import org.jboss.arquillian.container.spi.event.StopManualContainers;
import org.jboss.arquillian.container.spi.event.UnDeployManagedDeployments;
import org.jboss.arquillian.container.test.api.DeploymentName;
import org.jboss.arquillian.container.test.api.OperateOnDeployment;
import org.jboss.arquillian.container.test.impl.client.deployment.event.GenerateDeployment;
import org.jboss.arquillian.core.api.Event;
Expand Down Expand Up @@ -187,10 +189,27 @@ private DeploymentTargetDescription locateDeployment(Method method)
}
else
{
target = DeploymentTargetDescription.DEFAULT;
String name = deploymentName(method);
if (name == null)
target = DeploymentTargetDescription.DEFAULT;
else
target = new DeploymentTargetDescription(name);
}
return target;
}

private String deploymentName(Method deploymentMethod)
{
for (Annotation methodAnnotation : deploymentMethod.getAnnotations())
{
Class<? extends Annotation> annotationType = methodAnnotation.annotationType();
if (annotationType.isAnnotationPresent(DeploymentName.class))
{
return annotationType.getAnnotation(DeploymentName.class).value();
}
}
return null;
}

private abstract class ResultCallback
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.jboss.arquillian.container.test.impl.client.deployment;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
Expand All @@ -26,6 +27,7 @@
import org.jboss.arquillian.container.spi.client.deployment.TargetDescription;
import org.jboss.arquillian.container.spi.client.protocol.ProtocolDescription;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.DeploymentName;
import org.jboss.arquillian.container.test.api.OverProtocol;
import org.jboss.arquillian.container.test.api.ShouldThrowException;
import org.jboss.arquillian.container.test.api.TargetsContainer;
Expand Down Expand Up @@ -91,12 +93,12 @@ private DeploymentDescription generateDeployment(Method deploymentMethod)
DeploymentDescription deployment = null;
if(Archive.class.isAssignableFrom(deploymentMethod.getReturnType()))
{
deployment = new DeploymentDescription(deploymentAnnotation.name(), invoke(Archive.class, deploymentMethod));
deployment = new DeploymentDescription(deploymentName(deploymentMethod), invoke(Archive.class, deploymentMethod));
deployment.shouldBeTestable(deploymentAnnotation.testable());
}
else if(Descriptor.class.isAssignableFrom(deploymentMethod.getReturnType()))
{
deployment = new DeploymentDescription(deploymentAnnotation.name(), invoke(Descriptor.class, deploymentMethod));
deployment = new DeploymentDescription(deploymentName(deploymentMethod), invoke(Descriptor.class, deploymentMethod));
//deployment.shouldBeTestable(false);
}
deployment.shouldBeManaged(deploymentAnnotation.managed());
Expand All @@ -119,6 +121,20 @@ else if(Descriptor.class.isAssignableFrom(deploymentMethod.getReturnType()))
return deployment;
}

private String deploymentName(Method deploymentMethod)
{
for (Annotation methodAnnotation : deploymentMethod.getAnnotations())
{
Class<? extends Annotation> annotationType = methodAnnotation.annotationType();
if (annotationType.isAnnotationPresent(DeploymentName.class))
{
return annotationType.getAnnotation(DeploymentName.class).value();
}
}

return deploymentMethod.getAnnotation(Deployment.class).name();
}

/**
* @param deploymentMethod
* @return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@
*/
package org.jboss.arquillian.container.test.impl.client.deployment;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.List;

import org.jboss.arquillian.container.spi.client.deployment.DeploymentDescription;
import org.jboss.arquillian.container.spi.client.deployment.TargetDescription;
import org.jboss.arquillian.container.spi.client.protocol.ProtocolDescription;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.DeploymentName;
import org.jboss.arquillian.container.test.api.OverProtocol;
import org.jboss.arquillian.container.test.api.ShouldThrowException;
import org.jboss.arquillian.container.test.api.TargetsContainer;
Expand Down Expand Up @@ -70,6 +75,24 @@ public void shouldHandleMultipleDeploymentsAllDefault() throws Exception
}
}

@Test
public void shouldHandleDeploymentsWithDeploymentName() throws Exception
{
List<DeploymentDescription> scenario = generate(DeploymentsWithDeploymentName.class);

Assert.assertNotNull(scenario);
Assert.assertEquals("Verify all deployments were found",
1, scenario.size());

for (DeploymentDescription deployment : scenario)
{
Assert.assertEquals(
"Should be able to assign a name using annotations",
MyExtraDeployment.NAME,
deployment.getName());
}
}

@Test
public void shouldHandleMultipleDeploymentsAllSet() throws Exception
{
Expand Down Expand Up @@ -172,6 +195,25 @@ public static Archive<?> deploymentTwo()
}
}

@SuppressWarnings("unused")
private static class DeploymentsWithDeploymentName
{
@Deployment
@MyExtraDeployment
public static Archive<?> deployment()
{
return ShrinkWrap.create(JavaArchive.class);
}

}

@DeploymentName(MyExtraDeployment.NAME)
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
private static @interface MyExtraDeployment {
static final String NAME = "DEPLOYMENT_NAME";
}

@SuppressWarnings("unused")
private static class MultiDeploymentsSet
{
Expand Down