-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add EzyConfigurationAfterApplicationReady (#56)
- Loading branch information
Showing
18 changed files
with
156 additions
and
23 deletions.
There are no files selected for viewing
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
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
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
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
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
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
13 changes: 13 additions & 0 deletions
13
.../java/com/tvd12/ezyhttp/server/core/annotation/EzyConfigurationAfterApplicationReady.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,13 @@ | ||
package com.tvd12.ezyhttp.server.core.annotation; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ElementType.TYPE}) | ||
public @interface EzyConfigurationAfterApplicationReady { | ||
|
||
int priority() default 0; | ||
} |
45 changes: 45 additions & 0 deletions
45
.../com/tvd12/ezyhttp/server/core/util/EzyConfigurationAfterApplicationReadyAnnotations.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,45 @@ | ||
package com.tvd12.ezyhttp.server.core.util; | ||
|
||
import com.tvd12.ezyhttp.server.core.annotation.EzyConfigurationAfterApplicationReady; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.Comparator; | ||
import java.util.List; | ||
|
||
public class EzyConfigurationAfterApplicationReadyAnnotations { | ||
|
||
private EzyConfigurationAfterApplicationReadyAnnotations() {} | ||
|
||
public static List<Object> sortConfigurationAfterApplicationReadyObjects( | ||
Collection<Object> objects | ||
) { | ||
List<Object> list = new ArrayList<>(objects); | ||
list.sort(newConfigurationAfterApplicationReadyComparator()); | ||
return list; | ||
} | ||
|
||
private static Comparator<Object> newConfigurationAfterApplicationReadyComparator() { | ||
return Comparator.comparingInt( | ||
EzyConfigurationAfterApplicationReadyAnnotations::getPriority | ||
); | ||
} | ||
|
||
private static int getPriority(Object object) { | ||
return getPriority( | ||
object | ||
.getClass() | ||
.getAnnotation(EzyConfigurationAfterApplicationReady.class) | ||
); | ||
} | ||
|
||
private static int getPriority( | ||
EzyConfigurationAfterApplicationReady annotation | ||
) { | ||
int priority = 0; | ||
if (annotation != null) { | ||
priority = annotation.priority(); | ||
} | ||
return priority; | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...rver-core/src/test/java/com/tvd12/ezyhttp/server/core/test/config/ServerReadyConfig1.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,6 @@ | ||
package com.tvd12.ezyhttp.server.core.test.config; | ||
|
||
import com.tvd12.ezyhttp.server.core.annotation.EzyConfigurationAfterApplicationReady; | ||
|
||
@EzyConfigurationAfterApplicationReady | ||
public class ServerReadyConfig1 {} |
11 changes: 11 additions & 0 deletions
11
...rver-core/src/test/java/com/tvd12/ezyhttp/server/core/test/config/ServerReadyConfig2.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 com.tvd12.ezyhttp.server.core.test.config; | ||
|
||
import com.tvd12.ezyfox.bean.EzyBeanConfig; | ||
import com.tvd12.ezyhttp.server.core.annotation.EzyConfigurationAfterApplicationReady; | ||
|
||
@EzyConfigurationAfterApplicationReady(priority = Integer.MAX_VALUE) | ||
public class ServerReadyConfig2 implements EzyBeanConfig { | ||
|
||
@Override | ||
public void config() {} | ||
} |
11 changes: 11 additions & 0 deletions
11
...rver-core/src/test/java/com/tvd12/ezyhttp/server/core/test/config/ServerReadyConfig3.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 com.tvd12.ezyhttp.server.core.test.config; | ||
|
||
import com.tvd12.ezyfox.bean.EzyBeanConfig; | ||
import com.tvd12.ezyhttp.server.core.annotation.EzyConfigurationAfterApplicationReady; | ||
|
||
@EzyConfigurationAfterApplicationReady(priority = Integer.MIN_VALUE) | ||
public class ServerReadyConfig3 implements EzyBeanConfig { | ||
|
||
@Override | ||
public void config() {} | ||
} |
24 changes: 24 additions & 0 deletions
24
...2/ezyhttp/server/core/test/util/EzyConfigurationAfterApplicationReadyAnnotationsTest.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 com.tvd12.ezyhttp.server.core.test.util; | ||
|
||
import com.tvd12.ezyhttp.server.core.util.EzyConfigurationAfterApplicationReadyAnnotations; | ||
import com.tvd12.test.assertion.Asserts; | ||
import com.tvd12.test.reflect.MethodInvoker; | ||
import org.testng.annotations.Test; | ||
|
||
public class EzyConfigurationAfterApplicationReadyAnnotationsTest { | ||
|
||
@Test | ||
public void getPriorityTest() { | ||
// given | ||
// when | ||
int priority = (int) MethodInvoker | ||
.create() | ||
.staticClass(EzyConfigurationAfterApplicationReadyAnnotations.class) | ||
.method("getPriority") | ||
.param(Object.class, this) | ||
.invoke(); | ||
|
||
// then | ||
Asserts.assertZero(priority); | ||
} | ||
} |
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
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
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
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
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
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