import org.junit.rules.MethodRule;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.Statement;
+import org.opendaylight.infrautils.inject.PostFullSystemInjectionListener;
/**
* JUnit Rule which initializes Guice {@link Injector} for tests.
* {@literal @}Inject SomeClass someClass;
* </pre>
*
- * @author Michael Vorburger
+ * @author Michael Vorburger.ch
*/
public class GuiceRule implements MethodRule {
protected void setUpGuice(Object target) {
injector = Guice.createInjector(stage, modules);
injector.injectMembers(target);
+
+ try {
+ injector.getInstance(PostFullSystemInjectionListener.class).onFullSystemInjected();
+ } catch (ConfigurationException e) {
+ // It's OK if we didn't bind a PostFullSystemInjectionListener.
+ }
}
protected void tearDownGuice() {
--- /dev/null
+<!--
+ Copyright (c) 2018 Red Hat, Inc. and others. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ and is available at http://www.eclipse.org/legal/epl-v10.html
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.opendaylight.infrautils</groupId>
+ <artifactId>parent</artifactId>
+ <version>1.5.0-SNAPSHOT</version>
+ <relativePath>../../common/parent</relativePath>
+ </parent>
+
+ <artifactId>inject.guice</artifactId>
+ <packaging>bundle</packaging>
+ <!-- <name> formatting is used by autorelease to parse and notify projects on
+ build failure. Please do not modify this unless you have a good reason. -->
+ <name>ODL :: infrautils :: ${project.artifactId}</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>javax.inject</groupId>
+ <artifactId>javax.inject</artifactId>
+ <!-- Important to enforce false because in odlparent it's true (see gerrit/c/56723) -->
+ <optional>false</optional>
+ </dependency>
+ <dependency>
+ <groupId>com.mycila.guice.extensions</groupId>
+ <artifactId>mycila-guice-jsr250</artifactId>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.google.inject</groupId>
+ <artifactId>guice</artifactId>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.infrautils</groupId>
+ <artifactId>inject</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.opendaylight.infrautils</groupId>
+ <artifactId>inject.guice.testutils</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
--- /dev/null
+/*
+ * Copyright (c) 2019 Red Hat, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.infrautils.inject;
+
+/**
+ * Callback invoked when dependency injection is fully complete.
+ *
+ * @author Michael Vorburger.ch
+ */
+public interface PostFullSystemInjectionListener {
+
+ void onFullSystemInjected();
+
+}
<modules>
<module>inject</module>
+ <module>inject-guice</module>
<module>inject-guice-testutils</module>
</modules>
-
- <!--
- Maven Site Configuration
-
- The following configuration is necessary for maven-site-plugin to
- correctly identify the correct deployment path for OpenDaylight Maven
- sites.
- -->
- <url>${odl.site.url}/${project.groupId}/${stream}/${project.artifactId}/</url>
-
- <distributionManagement>
- <site>
- <id>opendaylight-site</id>
- <url>${nexus.site.url}/${project.artifactId}/</url>
- </site>
- </distributionManagement>
</project>