Skip to content

Commit

Permalink
WELD-2354 Provide a toString() for ContainerInitialized/Shutdown even…
Browse files Browse the repository at this point in the history
…ts with container ID.
  • Loading branch information
manovotn authored and mkouba committed Mar 24, 2017
1 parent 6ec9318 commit a44b091
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
Expand Up @@ -33,4 +33,8 @@ public String getContainerId() {
return containerId;
}

@Override
public String toString() {
return getClass().getSimpleName() + " event for container with ID: " + getContainerId();
}
}
@@ -0,0 +1,40 @@
/*
* 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.environment.se.test.container.events;

import javax.enterprise.event.Observes;

import org.jboss.weld.environment.se.events.ContainerInitialized;
import org.jboss.weld.environment.se.events.ContainerShutdown;

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

public static String containerInitializedToString;
public static String containerShutdownToString;

public void onContainerInit(@Observes ContainerInitialized event) {
containerInitializedToString = event.toString();
}

public void onContainerShutdown(@Observes ContainerShutdown event) {
containerShutdownToString = event.toString();
}
}
Expand Up @@ -23,6 +23,7 @@
import java.util.List;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Instance;

import org.jboss.weld.environment.se.Weld;
import org.jboss.weld.environment.se.WeldContainer;
Expand Down Expand Up @@ -61,4 +62,18 @@ public void testEventsFired() {
assertTrue(sequenceData.get(2).equals(ContainerShutdown.class.getName() + ApplicationScoped.class.getName()));
}

@Test
public void testContainerEventsToString() {
String id = "007";
ActionSequence.reset();
try (WeldContainer container = new Weld(id).disableDiscovery().beanClasses(ContainerEventToStringObserver.class).initialize()) {
assertFalse(container.select(ContainerEventToStringObserver.class).isUnsatisfied());
}
assertEquals(expectedToStringResult("ContainerInitialized", id), ContainerEventToStringObserver.containerInitializedToString);
assertEquals(expectedToStringResult("ContainerShutdown", id), ContainerEventToStringObserver.containerShutdownToString);
}

private String expectedToStringResult(String eventClass, String id) {
return eventClass + " event for container with ID: " + id;
}
}

0 comments on commit a44b091

Please sign in to comment.