This repository has been archived by the owner on May 15, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add annotation for SQS producer (#36)
- Loading branch information
Showing
14 changed files
with
161 additions
and
12 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
24 changes: 24 additions & 0 deletions
24
src/main/java/com/hlag/tools/commvis/analyzer/annotation/VisualizeSqsProducer.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.hlag.tools.commvis.analyzer.annotation; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
import com.hlag.tools.commvis.analyzer.model.AbstractCommunicationModelVisitor; | ||
|
||
/** | ||
* Marks a producer for AWS SQS messages. | ||
*/ | ||
public @interface VisualizeSqsProducer { | ||
/** | ||
* @return name of the SQS queue messages are sent to | ||
*/ | ||
String queueName(); | ||
|
||
/** | ||
* @return the id of the project called, usually the Gitlab project id or similar | ||
*/ | ||
String projectId(); | ||
|
||
/** | ||
* @return the name of the project called. Just for a better visibility in the code. The value isn't used. | ||
*/ | ||
String projectName() default ""; | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/com/hlag/tools/commvis/analyzer/annotation/VisualizeSqsProducers.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 com.hlag.tools.commvis.analyzer.annotation; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* Used to group multiple {@link VisualizeSqsProducer} annotations on one element. | ||
*/ | ||
@Target(ElementType.METHOD) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface VisualizeSqsProducers { | ||
/** | ||
* @return all grouped {@link VisualizeSqsProducer} annotations | ||
*/ | ||
VisualizeSqsProducer[] 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
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
48 changes: 48 additions & 0 deletions
48
src/main/java/com/hlag/tools/commvis/analyzer/model/SqsProducer.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,48 @@ | ||
package com.hlag.tools.commvis.analyzer.model; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
import lombok.AccessLevel; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.Value; | ||
|
||
/** | ||
* A producer for SQS messages. | ||
*/ | ||
@Value | ||
@RequiredArgsConstructor(access = AccessLevel.PACKAGE) | ||
public class SqsProducer implements ISenderReceiverCommunication { | ||
/** | ||
* the class name where the producer was found. | ||
*/ | ||
@SerializedName(value="class_name") | ||
String className; | ||
|
||
/** | ||
* the method name were the producer was found. | ||
*/ | ||
@SerializedName(value="method_name") | ||
String methodName; | ||
|
||
/** | ||
* the queue the messages are sent to. | ||
*/ | ||
@SerializedName(value="queue_name") | ||
String queueName; | ||
|
||
/** | ||
* The project id of the referenced project. | ||
*/ | ||
@SerializedName(value="destination_project_id") | ||
String destinationProjectId; | ||
|
||
/** | ||
* internal id of this node | ||
*/ | ||
@SerializedName(value="id") | ||
String id; | ||
|
||
@Override | ||
public void visit(AbstractCommunicationModelVisitor visitor) { | ||
visitor.visit(this); | ||
} | ||
} |
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
21 changes: 21 additions & 0 deletions
21
src/test/java/com/hlag/tools/commvis/analyzer/model/SqsProducerTest.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 com.hlag.tools.commvis.analyzer.model; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.lang.reflect.Field; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class SqsProducerTest { | ||
@Test | ||
void shouldHaveSerializedNameAnnotationOnFiled_toDecoupleTheFieldNameFromJson() { | ||
Field[] declaredFields = SqsProducer.class.getDeclaredFields(); | ||
|
||
for (Field f : declaredFields) { | ||
SerializedName actualAnnotation = f.getAnnotation(SerializedName.class); | ||
|
||
assertThat(actualAnnotation).withFailMessage(() -> String.format("Field %s has no @SerializedName annotation.", f.getName())).isNotNull(); | ||
} | ||
} | ||
} |