let GuiceRule notify SystemReadyMonitor registered listeners
authorMichael Vorburger <vorburger@redhat.com>
Sat, 22 Dec 2018 02:33:14 +0000 (03:33 +0100)
committerTom Pantelis <tompantelis@gmail.com>
Tue, 8 Jan 2019 13:49:30 +0000 (13:49 +0000)
It lets tests which rely on a fully working (not stubbed)
SystemReadyMonitor implementation simply bind one by using the
ReadyModule.

This comes out of https://github.com/vorburger/opendaylight-simple

Change-Id: I64892b0fcb1bb5de4ba8689b73239781be189fef
Signed-off-by: Michael Vorburger <vorburger@redhat.com>
inject-guice-testutils/src/main/java/org/opendaylight/infrautils/inject/guice/testutils/GuiceRule.java
inject-guice/pom.xml [new file with mode: 0644]
inject/src/main/java/org/opendaylight/infrautils/inject/PostFullSystemInjectionListener.java [new file with mode: 0644]
pom.xml

index a98473b2dfd426f14b59ea98930e43eee8e42ddf..c9421a04e6788accd1b990ad0f021bfc1dbc99d3 100644 (file)
@@ -19,6 +19,7 @@ import java.util.stream.Collectors;
 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.
@@ -30,7 +31,7 @@ import org.junit.runners.model.Statement;
  *   {@literal @}Inject SomeClass someClass;
  * </pre>
  *
- * @author Michael Vorburger
+ * @author Michael Vorburger.ch
  */
 public class GuiceRule implements MethodRule {
 
@@ -92,6 +93,12 @@ 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() {
diff --git a/inject-guice/pom.xml b/inject-guice/pom.xml
new file mode 100644 (file)
index 0000000..9e07557
--- /dev/null
@@ -0,0 +1,55 @@
+<!--
+ 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>
diff --git a/inject/src/main/java/org/opendaylight/infrautils/inject/PostFullSystemInjectionListener.java b/inject/src/main/java/org/opendaylight/infrautils/inject/PostFullSystemInjectionListener.java
new file mode 100644 (file)
index 0000000..4698045
--- /dev/null
@@ -0,0 +1,19 @@
+/*
+ * 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();
+
+}
diff --git a/pom.xml b/pom.xml
index bf76f1b4a746296f5a5b8228f9c741fa1f0290ac..e594dbc8928fd801cf5558e57734b9d1d21b14cf 100644 (file)
--- a/pom.xml
+++ b/pom.xml
 
   <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>