Skip to content

Commit

Permalink
added IT and unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mynecker committed Nov 12, 2024
1 parent e0be1d3 commit 7ea0d89
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public String getValue() {
return value;
}

public SempEntityType fromValue(String value) {
public static SempEntityType fromValue(String value) {
for (SempEntityType entityType : SempEntityType.values()) {
if (entityType.getValue().equals(value)) {
return entityType;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.solace.maas.ep.common.model;

import org.junit.jupiter.api.Test;

public class SempEntityTypeTest {

@Test
void testFromValue() {
SempEntityType entityType = SempEntityType.fromValue("solaceQueue");
assert entityType == SempEntityType.solaceQueue;
}

@Test
void testGetValue() {
SempEntityType entityType = SempEntityType.solaceQueue;
assert entityType.getValue().equals("solaceQueue");
}

@Test
void testUnsupportedEntityType() {
try {
SempEntityType entityType = SempEntityType.fromValue("unsupported");
} catch (IllegalArgumentException e) {
assert e.getMessage().equals("Unsupported entity type: unsupported");
}
}

@Test
void testFromValueNull() {
try {
SempEntityType entityType = SempEntityType.fromValue(null);
} catch (IllegalArgumentException e) {
assert e.getMessage().equals("Unsupported entity type: null");
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.solace.maas.ep.event.management.agent.subscriber;

import org.junit.jupiter.api.Test;

import static org.assertj.core.api.AssertionsForClassTypes.assertThat;

public class EmRestartSimulatingPersistentMessageHandlerObserverTest {

@Test
void testOnPhaseChangeRestartSimulated() {
EmaRestartSimulatingPersistentMessageHandlerObserver emaRestartSimulatingPersistentMessageHandlerObserver = new EmaRestartSimulatingPersistentMessageHandlerObserver();

Check failure on line 11 in service/application/src/test/java/com/solace/maas/ep/event/management/agent/subscriber/EmRestartSimulatingPersistentMessageHandlerObserverTest.java

View workflow job for this annotation

GitHub Actions / Checkstyle

com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck

Line is longer than 160 characters (found 175).
emaRestartSimulatingPersistentMessageHandlerObserver.setRestartSimulated(true);
assertThat(emaRestartSimulatingPersistentMessageHandlerObserver.onPhaseChange(null, PersistentMessageHandlerObserverPhase.PRE_PROCESSOR_EXECUTION)).isFalse();

Check failure on line 13 in service/application/src/test/java/com/solace/maas/ep/event/management/agent/subscriber/EmRestartSimulatingPersistentMessageHandlerObserverTest.java

View workflow job for this annotation

GitHub Actions / Checkstyle

com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck

Line is longer than 160 characters (found 166).
assertThat(emaRestartSimulatingPersistentMessageHandlerObserver.onPhaseChange(null, PersistentMessageHandlerObserverPhase.PRE_ACKNOWLEDGED)).isFalse();
assertThat(emaRestartSimulatingPersistentMessageHandlerObserver.onPhaseChange(null, PersistentMessageHandlerObserverPhase.ACKNOWLEDGED)).isTrue();
assertThat(emaRestartSimulatingPersistentMessageHandlerObserver.onPhaseChange(null, PersistentMessageHandlerObserverPhase.FAILED)).isTrue();
assertThat(emaRestartSimulatingPersistentMessageHandlerObserver.onPhaseChange(null, PersistentMessageHandlerObserverPhase.PROCESSOR_COMPLETED)).isTrue();

Check failure on line 17 in service/application/src/test/java/com/solace/maas/ep/event/management/agent/subscriber/EmRestartSimulatingPersistentMessageHandlerObserverTest.java

View workflow job for this annotation

GitHub Actions / Checkstyle

com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck

Line is longer than 160 characters (found 161).
assertThat(emaRestartSimulatingPersistentMessageHandlerObserver.onPhaseChange(null, PersistentMessageHandlerObserverPhase.PROCESSING_INITIATED)).isTrue();

Check failure on line 18 in service/application/src/test/java/com/solace/maas/ep/event/management/agent/subscriber/EmRestartSimulatingPersistentMessageHandlerObserverTest.java

View workflow job for this annotation

GitHub Actions / Checkstyle

com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck

Line is longer than 160 characters (found 162).
assertThat(emaRestartSimulatingPersistentMessageHandlerObserver.onPhaseChange(null, PersistentMessageHandlerObserverPhase.RECEIVED)).isTrue();
}

@Test
void testOnPhaseChangeRestartNotSimulated() {
EmaRestartSimulatingPersistentMessageHandlerObserver emaRestartSimulatingPersistentMessageHandlerObserver = new EmaRestartSimulatingPersistentMessageHandlerObserver();

Check failure on line 24 in service/application/src/test/java/com/solace/maas/ep/event/management/agent/subscriber/EmRestartSimulatingPersistentMessageHandlerObserverTest.java

View workflow job for this annotation

GitHub Actions / Checkstyle

com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck

Line is longer than 160 characters (found 175).
emaRestartSimulatingPersistentMessageHandlerObserver.setRestartSimulated(false);
assertThat(emaRestartSimulatingPersistentMessageHandlerObserver.onPhaseChange(null, PersistentMessageHandlerObserverPhase.PRE_PROCESSOR_EXECUTION)).isTrue();

Check failure on line 26 in service/application/src/test/java/com/solace/maas/ep/event/management/agent/subscriber/EmRestartSimulatingPersistentMessageHandlerObserverTest.java

View workflow job for this annotation

GitHub Actions / Checkstyle

com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck

Line is longer than 160 characters (found 165).
assertThat(emaRestartSimulatingPersistentMessageHandlerObserver.onPhaseChange(null, PersistentMessageHandlerObserverPhase.PRE_ACKNOWLEDGED)).isTrue();
assertThat(emaRestartSimulatingPersistentMessageHandlerObserver.onPhaseChange(null, PersistentMessageHandlerObserverPhase.ACKNOWLEDGED)).isTrue();
assertThat(emaRestartSimulatingPersistentMessageHandlerObserver.onPhaseChange(null, PersistentMessageHandlerObserverPhase.FAILED)).isTrue();
assertThat(emaRestartSimulatingPersistentMessageHandlerObserver.onPhaseChange(null, PersistentMessageHandlerObserverPhase.PROCESSOR_COMPLETED)).isTrue();

Check failure on line 30 in service/application/src/test/java/com/solace/maas/ep/event/management/agent/subscriber/EmRestartSimulatingPersistentMessageHandlerObserverTest.java

View workflow job for this annotation

GitHub Actions / Checkstyle

com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck

Line is longer than 160 characters (found 161).
assertThat(emaRestartSimulatingPersistentMessageHandlerObserver.onPhaseChange(null, PersistentMessageHandlerObserverPhase.PROCESSING_INITIATED)).isTrue();

Check failure on line 31 in service/application/src/test/java/com/solace/maas/ep/event/management/agent/subscriber/EmRestartSimulatingPersistentMessageHandlerObserverTest.java

View workflow job for this annotation

GitHub Actions / Checkstyle

com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck

Line is longer than 160 characters (found 162).
assertThat(emaRestartSimulatingPersistentMessageHandlerObserver.onPhaseChange(null, PersistentMessageHandlerObserverPhase.RECEIVED)).isTrue();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public void reset_mocks() {
Mockito.reset(terraformClient);
}


@Test
public void testWriteHCLWithDefaultFile() throws IOException {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.solace.maas.ep.event.management.agent.plugin.terraform;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.solace.maas.ep.event.management.agent.plugin.command.model.CommandResult;
import com.solace.maas.ep.event.management.agent.plugin.command.model.JobStatus;
import com.solace.maas.ep.event.management.agent.plugin.terraform.manager.TerraformLogProcessingService;
import org.junit.jupiter.api.Test;

import java.util.Map;

import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;


public class TerraformLogProcessingServiceTest {


@Test
void testBuildTfStateFileDeletionFailureResult(){
RuntimeException rootCause = new RuntimeException("rootCause");
ObjectMapper objectMapper = new ObjectMapper();
TerraformLogProcessingService terraformLogProcessingService = new TerraformLogProcessingService(objectMapper);
CommandResult result = terraformLogProcessingService.buildTfStateFileDeletionFailureResult(rootCause);
assertThat(result.getStatus()).isEqualTo(JobStatus.error);
assertThat(result.getLogs().size()).isEqualTo(1);
Map<String, Object> log = result.getLogs().get(0);
assertThat(log.get("message")).isEqualTo("Failed removing Terraform state: rootCause");
assertThat(log.get("level")).isEqualTo("ERROR");
assertThat(log.get("timestamp")).isNotNull();
}
}

0 comments on commit 7ea0d89

Please sign in to comment.