Skip to content

Commit

Permalink
WELD-2387 Configurator defining a custom bean with no callback will f…
Browse files Browse the repository at this point in the history
…ail with ISE during deployment.
  • Loading branch information
manovotn authored and mkouba committed May 23, 2017
1 parent c7ce37a commit 5f426d6
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ public class BeanAttributesConfiguratorImpl<T> implements BeanAttributesConfigur

private String name;

private final Set<Annotation> qualifiers;
final Set<Annotation> qualifiers;

private Class<? extends Annotation> scope;

private final Set<Class<? extends Annotation>> stereotypes;

private Set<Type> types;
final Set<Type> types;

private boolean isAlternative;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,12 @@ public BeanConfigurator<T> alternative(boolean alternative) {
}

public Bean<T> complete() {
if (createCallback == null) {
// not callback specified, Weld does not know how to instantiate this new custom bean
throw BeanLogger.LOG.noCallbackSpecifiedForCustomBean("bean [" + beanClass.toString()
+ ", with types: " + Formats.formatTypes(attributes.types)
+ ", and qualifiers: " + Formats.formatAnnotations(attributes.qualifiers) + "]");
}
return new ImmutableBean<>(this);
}

Expand Down Expand Up @@ -513,7 +519,7 @@ public String getId() {
@Override
public String toString() {
return "Configurator Bean [" + getBeanClass().toString() + ", types: " + Formats.formatTypes(getTypes()) + ", qualifiers: "
+ Formats.formatAnnotations(getQualifiers()) + "]";
+ Formats.formatAnnotations(getQualifiers()) + "]";
}

}
Expand Down
7 changes: 5 additions & 2 deletions impl/src/main/java/org/jboss/weld/logging/BeanLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public interface BeanLogger extends WeldLogger {
@Message(id = 39, value = "@Typed class {0} not present in the set of bean types of {1} [{2}]", format = Format.MESSAGE_FORMAT)
DefinitionException typedClassNotInHierarchy(Object param1, Object param2, Object types);

@SuppressWarnings({"weldlog:method-sig","weldlog:msg-value"})
@SuppressWarnings({ "weldlog:method-sig", "weldlog:msg-value" })
@Message(id = 40, value = "All stereotypes must specify the same scope or the bean must declare a scope - declared on {0}, declared stereotypes [{1}], possible scopes {2}{3}", format = Format.MESSAGE_FORMAT)
DefinitionException multipleScopesFoundFromStereotypes(Object declaredOn, Object stereotypes, Object possibleScopes, String stack);

Expand Down Expand Up @@ -519,4 +519,7 @@ public interface BeanLogger extends WeldLogger {
@Message(id = 1569, value = "Cannot inject injection point metadata in a non @Dependent bean: {0}", format = Format.MESSAGE_FORMAT)
IllegalArgumentException cannotInjectInjectionPointMetadataIntoNonDependent(Object bean);

}
@Message(id = 1570, value = "Invalid BeanConfigurator setup - no callback was specified for {0}", format = Format.MESSAGE_FORMAT)
IllegalStateException noCallbackSpecifiedForCustomBean(Object bean);

}
7 changes: 7 additions & 0 deletions jboss-tck-runner/src/test/tck20/tck-tests.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@
<!-- Issues in the spec -->

<!-- Issues in the TCK -->

<!-- CDITCK-573 -->
<class name="org.jboss.cdi.tck.tests.extensions.configurators.bean.BeanConfiguratorTest">
<methods>
<exclude name=".*"/>
</methods>
</class>

<!-- Issues in Weld (the RI) -->

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2017, Red Hat, Inc., 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.weld.tests.extensions.custombeans;

import javax.enterprise.inject.spi.DeploymentException;
import javax.enterprise.inject.spi.Extension;

import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.ShouldThrowException;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.jboss.weld.test.util.Utils;
import org.junit.Test;
import org.junit.runner.RunWith;

/**
* Verify that extension which defines custom bean with no callback fails during deployment.
* @author <a href="mailto:manovotn@redhat.com">Matej Novotny</a>
*/
@RunWith(Arquillian.class)
public class BeanConfiguratorWithNoCallbackTest {

@Deployment
@ShouldThrowException(DeploymentException.class)
public static WebArchive createTestArchive() {
return ShrinkWrap.create(WebArchive.class, Utils.getDeploymentNameAsHash(BeanConfiguratorWithNoCallbackTest.class, Utils.ARCHIVE_TYPE.WAR))
.addPackage(BeanConfiguratorFailureTest.class.getPackage()).addAsServiceProvider(Extension.class, IncorrectCustomBeanExtension.class)
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
}

@Test
public void testFailure() throws Exception {
// throws exception, just verify this doesn't pass the deployment
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2017, Red Hat, Inc., 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.weld.tests.extensions.custombeans;

import javax.enterprise.inject.Vetoed;

/**
*
* @author <a href="mailto:manovotn@redhat.com">Matej Novotny</a>
*/
@Vetoed
public class Charlie {

public void ping() {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2017, Red Hat, Inc., 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.weld.tests.extensions.custombeans;

import javax.enterprise.event.Observes;
import javax.enterprise.inject.spi.AfterBeanDiscovery;
import javax.enterprise.inject.spi.Extension;

/**
*
* @author <a href="mailto:manovotn@redhat.com">Matej Novotny</a>
*/
public class IncorrectCustomBeanExtension implements Extension {

public void registerBeanWithNoCallback(@Observes AfterBeanDiscovery abd) {
//register a new bean with no callback
abd.addBean()
.beanClass(Charlie.class)
.addTransitiveTypeClosure(Charlie.class);
}

}

0 comments on commit 5f426d6

Please sign in to comment.