Skip to content

Instantly share code, notes, and snippets.

@os890
os890 / CustomKeyFormatAwareConfigSource.java
Last active March 12, 2016 17:57
Support a custom/additional key-format
//add the fully qualified class name to META-INF/services/org.apache.deltaspike.core.spi.config.ConfigSource
public class CustomKeyFormatAwareConfigSource implements ConfigSource {
private final static int ordinal = 1000;
@Override
public int getOrdinal() {
return ordinal;
}
@Override
@os890
os890 / AppConfig.java
Created October 26, 2015 16:36
type-safe config without producer
@TypeSafeConfig
public interface AppConfig {
String name();
ApplicationVersion version();
}
@os890
os890 / AppConfig2.java
Created October 26, 2015 16:30
type-safe config with producer
@TypeSafeConfig
public interface AppConfig2 {
String name();
@Produces //since ds v1.5.1
ApplicationVersion version();
}
@os890
os890 / AppConfig.java
Last active October 3, 2015 12:41
@TypeSafeConfig - Usage
//example #1 for a custom type-safe config
@TypeSafeConfig
public interface AppConfig {
String name();
ApplicationVersion version();
}
@os890
os890 / TypeSafeConfig.java
Last active October 3, 2015 12:39
@TypeSafeConfig - Implementation
@PartialBeanBinding
@Retention(RUNTIME)
@Target(TYPE)
public @interface TypeSafeConfig {
}
@SessionScoped
@JsfPhaseListener
public class WindowQuotaHandler implements PhaseListener
{
@Inject
private WindowContext windowContext;
private Stack<String> windowIdStack = new Stack<String>();
@Override
public class DefaultEventBroadcastingTest
{
@Inject
private AsynchronousEvent<MyEvent> myAsyncEvent;
public void fireAsyncEvent()
{
this.myAsyncEvent.fire(new MyEvent(/*...*/));
}
}
@ApplicationScoped
public class AsyncObserver
{
public void onEvent(@ObservesAsynchronous MyEvent event)
{
//...
}
}
@RunWith(CdiTestRunner.class)
public class MockitoMockedCdiBeanTest
{
@Inject
private MyCdiBean myCdiBean;
@Inject
private DynamicMockContext mockContext;
@Test
@RequestScoped
public class MyCdiBean
{
private int count = 0;
public int getCount()
{
return count;
}