-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[closes #433] Replace Service interface with an abstract class
- Loading branch information
Showing
133 changed files
with
576 additions
and
759 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
10 changes: 10 additions & 0 deletions
10
system-x/common/src/main/java/software/tnb/common/account/NoAccount.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,10 @@ | ||
package software.tnb.common.account; | ||
|
||
import java.util.Properties; | ||
|
||
public class NoAccount implements Account { | ||
@Override | ||
public Properties toProperties() { | ||
throw new RuntimeException("This account shouldn't be used, as the service doesn't require an account"); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
system-x/common/src/main/java/software/tnb/common/client/NoClient.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,4 @@ | ||
package software.tnb.common.client; | ||
|
||
public class NoClient { | ||
} |
25 changes: 9 additions & 16 deletions
25
system-x/common/src/main/java/software/tnb/common/service/ConfigurableService.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
5 changes: 0 additions & 5 deletions
5
system-x/common/src/main/java/software/tnb/common/service/Restartable.java
This file was deleted.
Oops, something went wrong.
26 changes: 25 additions & 1 deletion
26
system-x/common/src/main/java/software/tnb/common/service/Service.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 |
---|---|---|
@@ -1,7 +1,31 @@ | ||
package software.tnb.common.service; | ||
|
||
import software.tnb.common.account.Account; | ||
import software.tnb.common.account.AccountFactory; | ||
import software.tnb.common.util.ReflectionUtil; | ||
import software.tnb.common.validation.Validation; | ||
|
||
import org.junit.jupiter.api.extension.AfterAllCallback; | ||
import org.junit.jupiter.api.extension.BeforeAllCallback; | ||
|
||
public interface Service extends BeforeAllCallback, AfterAllCallback { | ||
public abstract class Service<A extends Account, C, V extends Validation> implements BeforeAllCallback, AfterAllCallback { | ||
protected A account; | ||
protected C client; | ||
protected V validation; | ||
|
||
public A account() { | ||
if (account == null) { | ||
Class<A> accountClass = (Class<A>) ReflectionUtil.getGenericTypesOf(Service.class, this.getClass())[0]; | ||
account = AccountFactory.create(accountClass); | ||
} | ||
return account; | ||
} | ||
|
||
protected C client() { | ||
return client; | ||
} | ||
|
||
public V validation() { | ||
return validation; | ||
} | ||
} |
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
4 changes: 0 additions & 4 deletions
4
system-x/common/src/main/java/software/tnb/common/service/Validation.java
This file was deleted.
Oops, something went wrong.
31 changes: 31 additions & 0 deletions
31
system-x/common/src/main/java/software/tnb/common/util/ReflectionUtil.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,31 @@ | ||
package software.tnb.common.util; | ||
|
||
import java.lang.reflect.ParameterizedType; | ||
import java.lang.reflect.Type; | ||
|
||
public final class ReflectionUtil { | ||
private ReflectionUtil() { | ||
} | ||
|
||
/** | ||
* This method walks though parent classes until the parent class is equal to the first argument of the method. Then it returns an array of | ||
* generic types of the class. | ||
* | ||
* @param parent parent class that is generic | ||
* @param clazz current class | ||
* @return an array of generic types of the parent class | ||
*/ | ||
public static Type[] getGenericTypesOf(Class<?> parent, Class<?> clazz) { | ||
Class<?> current = clazz; | ||
while (true) { | ||
Type superClass = current.getGenericSuperclass(); | ||
if (superClass instanceof ParameterizedType && ((ParameterizedType) superClass).getRawType().equals(parent)) { | ||
break; | ||
} else { | ||
current = current.getSuperclass(); | ||
} | ||
} | ||
|
||
return ((ParameterizedType) (current.getGenericSuperclass())).getActualTypeArguments(); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
system-x/common/src/main/java/software/tnb/common/validation/NoValidation.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,4 @@ | ||
package software.tnb.common.validation; | ||
|
||
public class NoValidation implements Validation { | ||
} |
4 changes: 4 additions & 0 deletions
4
system-x/common/src/main/java/software/tnb/common/validation/Validation.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,4 @@ | ||
package software.tnb.common.validation; | ||
|
||
public interface Validation { | ||
} |
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
2 changes: 1 addition & 1 deletion
2
...cloudwatch/src/main/java/software/tnb/aws/cloudwatch/validation/CloudwatchValidation.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
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
6 changes: 5 additions & 1 deletion
6
system-x/services/aws/common/src/main/java/software/tnb/aws/common/service/LocalStack.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
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
2 changes: 1 addition & 1 deletion
2
.../aws/dynamo-db/src/main/java/software/tnb/aws/dynamodb/validation/DynamoDBValidation.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
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
2 changes: 1 addition & 1 deletion
2
system-x/services/aws/iam/src/main/java/software/tnb/aws/iam/validation/IAMValidation.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
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
2 changes: 1 addition & 1 deletion
2
...ices/aws/kinesis/src/main/java/software/tnb/aws/kinesis/validation/KinesisValidation.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
Oops, something went wrong.