Skip to content

Commit

Permalink
WELD-2432 Probe - fix wrongly recognized alternative bean NPE.
Browse files Browse the repository at this point in the history
  • Loading branch information
manovotn authored and mkouba committed Oct 17, 2017
1 parent 59bbe27 commit 538ea0a
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 9 deletions.
21 changes: 12 additions & 9 deletions probe/core/src/main/java/org/jboss/weld/probe/JsonObjects.java
Original file line number Diff line number Diff line change
Expand Up @@ -315,17 +315,20 @@ static String createDeploymentJson(BeanManagerImpl beanManager, Probe probe) {
enablementBuilder.add(DECORATORS, decorators);
JsonArrayBuilder alternatives = Json.arrayBuilder();
for (Class<?> clazz : Sets.union(enablement.getAlternativeClasses(), enablement.getGlobalAlternatives())) {
JsonObjectBuilder builder = createSimpleBeanJson(findAlternativeBean(clazz, probe), probe);
if (enablement.getAlternativeClasses().contains(clazz)) {
builder.add(BEANS_XML, true);
}
if (enablement.getGlobalAlternatives().contains(clazz)) {
Object priority = clazz.getAnnotation(annotationApi.PRIORITY_ANNOTATION_CLASS);
if (priority != null) {
builder.add(PRIORITY, annotationApi.getPriority(priority));
Bean<?> alternativeBean = findAlternativeBean(clazz, probe);
if (alternativeBean != null) {
JsonObjectBuilder builder = createSimpleBeanJson(alternativeBean, probe);
if (enablement.getAlternativeClasses().contains(clazz)) {
builder.add(BEANS_XML, true);
}
if (enablement.getGlobalAlternatives().contains(clazz)) {
Object priority = clazz.getAnnotation(annotationApi.PRIORITY_ANNOTATION_CLASS);
if (priority != null) {
builder.add(PRIORITY, annotationApi.getPriority(priority));
}
}
alternatives.add(builder);
}
alternatives.add(builder);
}
for (Class<? extends Annotation> stereotype : enablement.getAlternativeStereotypes()) {
Set<Bean<?>> beans = findAlternativeStereotypeBeans(stereotype, probe);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* 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.probe.tests.integration.deployment.beans.almostAlternative;

import javax.annotation.Priority;
import javax.enterprise.context.ApplicationScoped;

/**
* WELD-2432 this bean was wrongly picked up by Probe as an alternative
* @author <a href="mailto:manovotn@redhat.com">Matej Novotny</a>
*/
@ApplicationScoped
@Priority(1)
public class AlmostAlternativeBean {

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@
import javax.json.JsonObject;

import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;

import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.OperateOnDeployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.jboss.weld.bootstrap.spi.BeanDiscoveryMode;
import org.jboss.weld.probe.tests.integration.deployment.beans.almostAlternative.AlmostAlternativeBean;
import org.jboss.weld.probe.tests.integration.deployment.beans.ModelBean;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -52,9 +54,11 @@ public class ProbeDeploymentsTest extends ProbeIntegrationTest {
private static final String TEST_ARCHIVE_NAME = "probe-deployments-test-explicit";
private static final String TEST_IMPLICIT_ARCHIVE_NAME = "probe-deployments-test-implicit";
private static final String NOT_BEAN_ARCHIVE_NAME = "probe-deployments-test-none";
private static final String PRIORITY_NON_ALTERNATIVE_BEAN_ARCHIVE_NAME = "probe-deployments-test-priority";
private static final String EXPLICIT_ARCHIVE = "explicit-archive";
private static final String IMPLICIT_ARCHIVE = "implicit-archive";
private static final String NON_BEAN_ARCHIVE = "not-bean-archive";
private static final String PRIORITY_NON_ALTERNATIVE_BEAN_ARCHIVE = "priority-non-alternative-bean-archive";

@Deployment(testable = false, name = EXPLICIT_ARCHIVE)
public static WebArchive deployExplicitArchive() {
Expand All @@ -77,6 +81,13 @@ public static WebArchive deployImplicitArchive() {
.addPackage(ModelBean.class.getPackage());
}

@Deployment(testable = false, name = PRIORITY_NON_ALTERNATIVE_BEAN_ARCHIVE)
public static WebArchive deployArchiveWithPriorityNonAlternativeBean() {
return ShrinkWrap.create(WebArchive.class, PRIORITY_NON_ALTERNATIVE_BEAN_ARCHIVE_NAME + ".war")
.addAsWebInfResource(ProbeDeploymentsTest.class.getPackage(), "web.xml", "web.xml")
.addClass(AlmostAlternativeBean.class);
}

@Test
@OperateOnDeployment(EXPLICIT_ARCHIVE)
public void testDeploymentEndpointWithExplicitBeanArchive() throws IOException {
Expand Down Expand Up @@ -105,4 +116,11 @@ public void testDeploymentEndpointWithNonBeanArchive() throws IOException {
}
}

@Test
@OperateOnDeployment(PRIORITY_NON_ALTERNATIVE_BEAN_ARCHIVE)
public void testDeploymentWithPriorityNonAlternativeBean() throws IOException {
JsonObject testArchive = getDeploymentByName(DEPLOYMENT_PATH, PRIORITY_NON_ALTERNATIVE_BEAN_ARCHIVE_NAME, url);
// this should not crash, bean with @Priority and no other annotation is correct
assertNotNull("Cannot find test archive in Probe deployments!", testArchive);
}
}

0 comments on commit 538ea0a

Please sign in to comment.