-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[native clouds] add support for setup task
- Loading branch information
Showing
10 changed files
with
247 additions
and
0 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
clouds/clouds-core/src/main/java/sunstone/api/AbstractSetupTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package sunstone.api; | ||
|
||
|
||
public abstract class AbstractSetupTask { | ||
public abstract void setup() throws Exception; | ||
public abstract void cleanup() throws Exception; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package sunstone.api; | ||
|
||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import sunstone.core.SunstoneExtension; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Inherited; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* Define {@link AbstractSetupTask} that configure environment right after Cloud resources are deployed and before. | ||
* | ||
* The class may inject static/non-static resources using annotations annotated by {@link SunstoneInjectionAnnotation} | ||
* that are brought bu modules like sunstone-clouds-aws or sunstone-clouds-azure. | ||
*/ | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ElementType.TYPE}) | ||
@ExtendWith(SunstoneExtension.class) | ||
@Inherited | ||
public @interface Setup { | ||
Class<? extends AbstractSetupTask> [] value(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
clouds/clouds-core/src/test/java/sunstone/core/di/AbstractStaticDITask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package sunstone.core.di; | ||
|
||
|
||
import sunstone.api.AbstractSetupTask; | ||
|
||
abstract class AbstractStaticDITask extends AbstractSetupTask { | ||
@DirectlyAnnotatedInject | ||
static String directStaticInjectInAbstract; | ||
|
||
@DirectlyAnnotatedInject | ||
String directNonStaticInjectInAbstract; | ||
|
||
@IndirectlyAnnotatedInject | ||
static String indirectStaticInjectInAbstract; | ||
|
||
@IndirectlyAnnotatedInject | ||
String indirectNonStaticInjectInAbstract; | ||
} |
23 changes: 23 additions & 0 deletions
23
clouds/clouds-core/src/test/java/sunstone/core/di/SetupTaskDITest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package sunstone.core.di; | ||
|
||
|
||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.Test; | ||
import sunstone.api.Setup; | ||
|
||
@Setup({StaticDITask.class}) | ||
public class SetupTaskDITest { | ||
|
||
@AfterAll | ||
public static void reset() { | ||
StaticDITask.reset(); | ||
TestSunstoneResourceInjector.reset(); | ||
} | ||
|
||
@Test | ||
public void test() { | ||
Assertions.assertThat(StaticDITask.setupCalled).isTrue(); | ||
} | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
clouds/clouds-core/src/test/java/sunstone/core/di/StaticDITask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package sunstone.core.di; | ||
|
||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class StaticDITask extends AbstractStaticDITask { | ||
|
||
@DirectlyAnnotatedInject | ||
static String directStaticInject; | ||
|
||
@DirectlyAnnotatedInject | ||
String directNonStaticInject; | ||
|
||
@IndirectlyAnnotatedInject | ||
static String indirectStaticInject; | ||
|
||
@IndirectlyAnnotatedInject | ||
String indirectNonStaticInject; | ||
static boolean setupCalled = false; | ||
static boolean cleanupCalled = false; | ||
|
||
@Override | ||
public void setup() throws Exception { | ||
setupCalled = true; | ||
} | ||
|
||
@Override | ||
public void cleanup() throws Exception { | ||
assertThat(directStaticInject).isEqualTo("set"); | ||
assertThat(directStaticInjectInAbstract).isEqualTo("set"); | ||
assertThat(indirectStaticInject).isEqualTo("set"); | ||
assertThat(indirectStaticInjectInAbstract).isEqualTo("set"); | ||
assertThat(directNonStaticInject).isEqualTo("set"); | ||
assertThat(directNonStaticInjectInAbstract).isEqualTo("set"); | ||
assertThat(indirectNonStaticInject).isEqualTo("set"); | ||
assertThat(indirectNonStaticInjectInAbstract).isEqualTo("set"); | ||
cleanupCalled = true; | ||
} | ||
|
||
public static void reset() { | ||
setupCalled = false; | ||
cleanupCalled = false; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
clouds/clouds-core/src/test/java/sunstone/core/setup/SetupSuite.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package sunstone.core.setup; | ||
|
||
import org.junit.platform.suite.api.SelectClasses; | ||
import org.junit.platform.suite.api.Suite; | ||
import sunstone.core.setup.suitetests.SetupCleanupSecondTest; | ||
import sunstone.core.setup.suitetests.SetupFirstTest; | ||
|
||
@Suite | ||
@SelectClasses({SetupFirstTest.class, SetupCleanupSecondTest.class}) | ||
public class SetupSuite { | ||
} |
24 changes: 24 additions & 0 deletions
24
clouds/clouds-core/src/test/java/sunstone/core/setup/suitetests/RegularClassTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package sunstone.core.setup.suitetests; | ||
|
||
|
||
import sunstone.api.AbstractSetupTask; | ||
|
||
class RegularClassTask extends AbstractSetupTask { | ||
static boolean setupCalled = false; | ||
static boolean cleanupCalled = false; | ||
|
||
@Override | ||
public void setup() throws Exception { | ||
setupCalled = true; | ||
} | ||
|
||
@Override | ||
public void cleanup() throws Exception { | ||
cleanupCalled = true; | ||
} | ||
|
||
public static void reset() { | ||
setupCalled = false; | ||
cleanupCalled = false; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
clouds/clouds-core/src/test/java/sunstone/core/setup/suitetests/SetupCleanupSecondTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package sunstone.core.setup.suitetests; | ||
|
||
|
||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class SetupCleanupSecondTest { | ||
|
||
@Test | ||
public void test() { | ||
Assertions.assertThat(SetupFirstTest.StaticClassTask.cleanupCalled).isTrue(); | ||
Assertions.assertThat(RegularClassTask.cleanupCalled).isTrue(); | ||
} | ||
|
||
@AfterAll | ||
public static void reset() { | ||
RegularClassTask.reset(); | ||
SetupFirstTest.StaticClassTask.reset(); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
clouds/clouds-core/src/test/java/sunstone/core/setup/suitetests/SetupFirstTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package sunstone.core.setup.suitetests; | ||
|
||
|
||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import sunstone.api.AbstractSetupTask; | ||
import sunstone.api.Setup; | ||
|
||
@Setup({SetupFirstTest.StaticClassTask.class, RegularClassTask.class}) | ||
public class SetupFirstTest { | ||
|
||
@Test | ||
public void test() { | ||
Assertions.assertThat(StaticClassTask.setupCalled).isTrue(); | ||
Assertions.assertThat(RegularClassTask.setupCalled).isTrue(); | ||
} | ||
|
||
static class StaticClassTask extends AbstractSetupTask { | ||
static boolean setupCalled = false; | ||
static boolean cleanupCalled = false; | ||
|
||
@Override | ||
public void setup() throws Exception { | ||
setupCalled = true; | ||
} | ||
|
||
@Override | ||
public void cleanup() throws Exception { | ||
cleanupCalled = true; | ||
} | ||
|
||
public static void reset() { | ||
setupCalled = false; | ||
cleanupCalled = false; | ||
} | ||
} | ||
|
||
} |