This repository has been archived by the owner on May 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
142 additions
and
18 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
18 changes: 18 additions & 0 deletions
18
src/main/java/com/hlag/tools/commvis/analyzer/adapter/IdentityGenerator.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.adapter; | ||
|
||
import com.hlag.tools.commvis.analyzer.port.IIdentityGenerator; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.UUID; | ||
|
||
/** | ||
* Simple class which generates unique ids. As it does not belong to the core competency of the application it has | ||
* been moved to the adapter package to improve the testability. | ||
*/ | ||
@Component | ||
public class IdentityGenerator implements IIdentityGenerator { | ||
@Override | ||
public String generateUniqueId() { | ||
return UUID.randomUUID().toString(); | ||
} | ||
} |
18 changes: 10 additions & 8 deletions
18
src/main/java/com/hlag/tools/commvis/analyzer/model/EndpointFactory.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,21 +1,23 @@ | ||
package com.hlag.tools.commvis.analyzer.model; | ||
|
||
public class EndpointFactory { | ||
private static final EndpointFactory singleton = new EndpointFactory(); | ||
import com.hlag.tools.commvis.analyzer.port.IIdentityGenerator; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
|
||
public static EndpointFactory get() { | ||
return singleton; | ||
} | ||
@Component | ||
@RequiredArgsConstructor | ||
public class EndpointFactory { | ||
private final IIdentityGenerator identityGenerator; | ||
|
||
public HttpConsumer createHttpConsumer(String className, String methodName, String type, String path) { | ||
return new HttpConsumer(className, methodName, type, path); | ||
return new HttpConsumer(className, methodName, type, path, identityGenerator.generateUniqueId()); | ||
} | ||
|
||
public HttpProducer createHttpProducer(String className, String methodName, String type, String path, String destinationProjectId) { | ||
return new HttpProducer(className, methodName, type, path, destinationProjectId); | ||
return new HttpProducer(className, methodName, type, path, destinationProjectId, identityGenerator.generateUniqueId()); | ||
} | ||
|
||
public JmsReceiver createJmsReceiver(String className, String destinationType, String destination) { | ||
return new JmsReceiver(className, destinationType, destination); | ||
return new JmsReceiver(className, destinationType, destination, identityGenerator.generateUniqueId()); | ||
} | ||
} |
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
5 changes: 5 additions & 0 deletions
5
src/main/java/com/hlag/tools/commvis/analyzer/port/IIdentityGenerator.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,5 @@ | ||
package com.hlag.tools.commvis.analyzer.port; | ||
|
||
public interface IIdentityGenerator { | ||
String generateUniqueId(); | ||
} |
28 changes: 28 additions & 0 deletions
28
src/test/java/com/hlag/tools/commvis/analyzer/adapter/IdentityGeneratorTest.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,28 @@ | ||
package com.hlag.tools.commvis.analyzer.adapter; | ||
|
||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
class IdentityGeneratorTest { | ||
private IdentityGenerator identityGenerator; | ||
|
||
@BeforeEach | ||
void init() { | ||
identityGenerator = new IdentityGenerator(); | ||
} | ||
|
||
@Test | ||
void shouldGenerateUniqueIds_whenGenerateUniqueId() { | ||
List<String> actualUniqueIds = new ArrayList<>(); | ||
|
||
for (int i = 0; i < 50; i++) { | ||
actualUniqueIds.add(identityGenerator.generateUniqueId()); | ||
} | ||
|
||
Assertions.assertThat(actualUniqueIds).doesNotHaveDuplicates(); | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
src/test/java/com/hlag/tools/commvis/analyzer/model/EndpointFactoryTest.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,60 @@ | ||
package com.hlag.tools.commvis.analyzer.model; | ||
|
||
import com.hlag.tools.commvis.analyzer.port.IIdentityGenerator; | ||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
import org.mockito.MockitoAnnotations; | ||
|
||
class EndpointFactoryTest { | ||
private static final String FIXED_ID = "MY-UNIQUE-ID"; | ||
|
||
@Mock | ||
private IIdentityGenerator identityGenerator; | ||
@InjectMocks | ||
private EndpointFactory factory; | ||
|
||
@BeforeEach | ||
void init() { | ||
MockitoAnnotations.openMocks(this); | ||
|
||
Mockito.doReturn(FIXED_ID).when(identityGenerator).generateUniqueId(); | ||
} | ||
|
||
@Test | ||
void shouldSetAllFields_whenCreateHttpConsumer() { | ||
HttpConsumer actualHttpConsumer = factory.createHttpConsumer("className", "methodName", "type", "path"); | ||
|
||
Assertions.assertThat(actualHttpConsumer.getClassName()).isEqualTo("className"); | ||
Assertions.assertThat(actualHttpConsumer.getMethodName()).isEqualTo("methodName"); | ||
Assertions.assertThat(actualHttpConsumer.getType()).isEqualTo("type"); | ||
Assertions.assertThat(actualHttpConsumer.getPath()).isEqualTo("path"); | ||
Assertions.assertThat(actualHttpConsumer.getId()).isEqualTo(FIXED_ID); | ||
} | ||
|
||
@Test | ||
void shouldSetAllFields_whenCreateHttpProducer() { | ||
HttpProducer actualHttpProducer = factory.createHttpProducer("className", "methodName", "type", "path", "destinationProjectId"); | ||
|
||
Assertions.assertThat(actualHttpProducer.getClassName()).isEqualTo("className"); | ||
Assertions.assertThat(actualHttpProducer.getMethodName()).isEqualTo("methodName"); | ||
Assertions.assertThat(actualHttpProducer.getType()).isEqualTo("type"); | ||
Assertions.assertThat(actualHttpProducer.getPath()).isEqualTo("path"); | ||
Assertions.assertThat(actualHttpProducer.getDestinationProjectId()).isEqualTo("destinationProjectId"); | ||
Assertions.assertThat(actualHttpProducer.getId()).isEqualTo(FIXED_ID); | ||
|
||
} | ||
|
||
@Test | ||
void createJmsReceiver() { | ||
JmsReceiver actualJmsReceiver = factory.createJmsReceiver("className", "destinationType", "destination"); | ||
|
||
Assertions.assertThat(actualJmsReceiver.getClassName()).isEqualTo("className"); | ||
Assertions.assertThat(actualJmsReceiver.getDestinationType()).isEqualTo("destinationType"); | ||
Assertions.assertThat(actualJmsReceiver.getDestination()).isEqualTo("destination"); | ||
Assertions.assertThat(actualJmsReceiver.getId()).isEqualTo(FIXED_ID); | ||
} | ||
} |