-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DATAGO-77217 EMA dynamic configuration for scan jobs (#186)
- Loading branch information
Showing
8 changed files
with
258 additions
and
5 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
63 changes: 63 additions & 0 deletions
63
...va/com/solace/maas/ep/event/management/agent/common/messages/ScanCommandMessageTests.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,63 @@ | ||
package com.solace.maas.ep.event.management.agent.common.messages; | ||
|
||
import com.solace.maas.ep.common.messages.ScanCommandMessage; | ||
import com.solace.maas.ep.common.model.ResourceConfigurationType; | ||
import com.solace.maas.ep.common.model.ScanDestination; | ||
import com.solace.maas.ep.common.model.ScanType; | ||
import com.solace.maas.ep.event.management.agent.plugin.mop.MOPMessageType; | ||
import com.solace.maas.ep.event.management.agent.plugin.mop.MOPProtocol; | ||
import com.solace.maas.ep.event.management.agent.plugin.mop.MOPUHFlag; | ||
import com.solace.maas.ep.event.management.agent.subscriber.messageProcessors.EventBrokerResourceConfigTestHelper; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
|
||
|
||
public class ScanCommandMessageTests { | ||
|
||
private void assertMopMessageProperties(ScanCommandMessage scanCommandMessage) { | ||
assertNotNull(scanCommandMessage); | ||
assertEquals(MOPMessageType.generic, scanCommandMessage.getMopMsgType()); | ||
assertEquals(MOPProtocol.scanDataControl, scanCommandMessage.getMopProtocol()); | ||
assertEquals("1", scanCommandMessage.getMopVer()); | ||
assertEquals(MOPUHFlag.ignore, scanCommandMessage.getMsgUh()); | ||
} | ||
|
||
@Test | ||
void instantiateScanCommandMessage() { | ||
ScanCommandMessage scanCommandMessage = new ScanCommandMessage( | ||
"messagingServiceId1", | ||
"scanId1", | ||
List.of(ScanType.SOLACE_ALL), | ||
List.of(ScanDestination.EVENT_PORTAL, ScanDestination.FILE_WRITER) | ||
); | ||
assertMopMessageProperties(scanCommandMessage); | ||
assertEquals("messagingServiceId1", scanCommandMessage.getMessagingServiceId()); | ||
assertEquals("scanId1", scanCommandMessage.getScanId()); | ||
assertEquals(List.of(ScanType.SOLACE_ALL), scanCommandMessage.getScanTypes()); | ||
assertEquals(List.of(ScanDestination.EVENT_PORTAL, ScanDestination.FILE_WRITER), scanCommandMessage.getDestinations()); | ||
assertNull(scanCommandMessage.getResources()); | ||
} | ||
|
||
@Test | ||
void instantiateScanCommandMessageWithResources() { | ||
ScanCommandMessage scanCommandMessage = new ScanCommandMessage( | ||
"messagingServiceId1", | ||
"scanId1", | ||
List.of(ScanType.SOLACE_ALL), | ||
List.of(ScanDestination.EVENT_PORTAL, ScanDestination.FILE_WRITER), | ||
List.of(EventBrokerResourceConfigTestHelper.buildResourceConfiguration(ResourceConfigurationType.SOLACE)) | ||
); | ||
assertMopMessageProperties(scanCommandMessage); | ||
assertEquals("messagingServiceId1", scanCommandMessage.getMessagingServiceId()); | ||
assertEquals("scanId1", scanCommandMessage.getScanId()); | ||
assertEquals(List.of(ScanType.SOLACE_ALL), scanCommandMessage.getScanTypes()); | ||
assertEquals(List.of(ScanDestination.EVENT_PORTAL, ScanDestination.FILE_WRITER), scanCommandMessage.getDestinations()); | ||
assertNotNull(scanCommandMessage.getResources()); | ||
assertEquals(1, scanCommandMessage.getResources().size()); | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
...ava/com/solace/maas/ep/event/management/agent/scanManager/ScanManagerHandleErrorTest.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,66 @@ | ||
package com.solace.maas.ep.event.management.agent.scanManager; | ||
|
||
import com.solace.maas.ep.common.messages.ScanCommandMessage; | ||
import com.solace.maas.ep.common.model.ScanDestination; | ||
import com.solace.maas.ep.common.model.ScanType; | ||
import com.solace.maas.ep.event.management.agent.TestConfig; | ||
import com.solace.maas.ep.event.management.agent.config.eventPortal.EventPortalProperties; | ||
import com.solace.maas.ep.event.management.agent.publisher.ScanStatusPublisher; | ||
import com.solace.maas.ep.event.management.agent.service.MessagingServiceDelegateServiceImpl; | ||
import com.solace.maas.ep.event.management.agent.service.ScanService; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mock; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.ActiveProfiles; | ||
|
||
import java.util.List; | ||
|
||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
@ActiveProfiles("TEST") | ||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = TestConfig.class) | ||
class ScanManagerHandleErrorTest { | ||
|
||
@Mock | ||
EventPortalProperties eventPortalProperties; | ||
|
||
@Mock | ||
MessagingServiceDelegateServiceImpl messagingServiceDelegateService; | ||
|
||
@Mock | ||
private ScanService scanService; | ||
|
||
@Mock | ||
private ScanStatusPublisher scanStatusPublisher; | ||
|
||
@Test | ||
void testScanManagerHandleError(){ | ||
when(eventPortalProperties.getOrganizationId()).thenReturn("orgId"); | ||
when(eventPortalProperties.getRuntimeAgentId()).thenReturn("runtimeAgentId"); | ||
|
||
RuntimeException mockEx = new RuntimeException("Mock Exception"); | ||
|
||
ScanManager scanManagerUnderTest = new ScanManager( | ||
messagingServiceDelegateService, | ||
scanService, | ||
eventPortalProperties, | ||
scanStatusPublisher | ||
); | ||
scanManagerUnderTest.handleError(mockEx,createScanCommandMessage()); | ||
verify(scanStatusPublisher, times(1)).sendOverallScanStatus(any(),any()); | ||
} | ||
|
||
|
||
|
||
private ScanCommandMessage createScanCommandMessage(){ | ||
return new ScanCommandMessage( | ||
"messageServiceId", | ||
"scanId", | ||
List.of(ScanType.SOLACE_ALL), | ||
List.of(ScanDestination.EVENT_PORTAL), | ||
null); | ||
} | ||
} |
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
63 changes: 63 additions & 0 deletions
63
...event/management/agent/subscriber/messageProcessors/ScanCommandMessageProcessorTests.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,63 @@ | ||
package com.solace.maas.ep.event.management.agent.subscriber.messageProcessors; | ||
|
||
import com.solace.maas.ep.common.messages.ScanCommandMessage; | ||
import com.solace.maas.ep.common.model.EventBrokerResourceConfiguration; | ||
import com.solace.maas.ep.common.model.ResourceConfigurationType; | ||
import com.solace.maas.ep.common.model.ScanDestination; | ||
import com.solace.maas.ep.common.model.ScanType; | ||
import com.solace.maas.ep.event.management.agent.TestConfig; | ||
import com.solace.maas.ep.event.management.agent.scanManager.ScanManager; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.boot.test.mock.mockito.SpyBean; | ||
import org.springframework.test.context.ActiveProfiles; | ||
|
||
import java.util.List; | ||
|
||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.verifyNoInteractions; | ||
|
||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = TestConfig.class) | ||
@ActiveProfiles("TEST") | ||
class ScanCommandMessageProcessorTests { | ||
|
||
@MockBean | ||
private ScanManager scanManager; | ||
|
||
@SpyBean | ||
private ScanCommandMessageProcessor scanCommandMessageProcessor; | ||
|
||
@MockBean | ||
private DynamicResourceConfigurationHelper dynamicResourceConfigurationHelper; | ||
|
||
@Test | ||
void processMessageWithoutResourceConfiguration(){ | ||
ScanCommandMessage message = buildScanCommandMessage(null); | ||
scanCommandMessageProcessor.processMessage(message); | ||
verifyNoInteractions(dynamicResourceConfigurationHelper); | ||
verify(scanManager,times(1)).scan(any()); | ||
} | ||
|
||
@Test | ||
void processMessageWithResourceConfiguration(){ | ||
ScanCommandMessage message = buildScanCommandMessage(List.of( | ||
EventBrokerResourceConfigTestHelper.buildResourceConfiguration(ResourceConfigurationType.SOLACE)) | ||
); | ||
scanCommandMessageProcessor.processMessage(message); | ||
verify(dynamicResourceConfigurationHelper, times(1)).loadSolaceBrokerResourceConfigurations(any()); | ||
verify(scanManager,times(1)).scan(any()); | ||
} | ||
|
||
|
||
private ScanCommandMessage buildScanCommandMessage(List<EventBrokerResourceConfiguration> resources){ | ||
return new ScanCommandMessage( | ||
"messageServiceId", | ||
"scanId", | ||
List.of(ScanType.SOLACE_ALL), | ||
List.of(ScanDestination.EVENT_PORTAL), | ||
resources); | ||
} | ||
} |