-
Notifications
You must be signed in to change notification settings - Fork 46
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
8 changed files
with
295 additions
and
27 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
22 changes: 21 additions & 1 deletion
22
...r/src/main/java/org/citrusframework/simulator/repository/ScenarioExecutionRepository.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,12 +1,32 @@ | ||
package org.citrusframework.simulator.repository; | ||
|
||
import org.citrusframework.simulator.model.ScenarioExecution; | ||
import org.citrusframework.simulator.model.TestResult; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.jpa.domain.Specification; | ||
import org.springframework.data.jpa.repository.EntityGraph; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.Optional; | ||
|
||
/** | ||
* Spring Data JPA repository for the {@link ScenarioExecution} entity. | ||
*/ | ||
@Repository | ||
public interface ScenarioExecutionRepository extends JpaRepository<ScenarioExecution, Long>, JpaSpecificationExecutor<ScenarioExecution> {} | ||
public interface ScenarioExecutionRepository extends JpaRepository<ScenarioExecution, Long>, JpaSpecificationExecutor<ScenarioExecution> { | ||
|
||
@Override | ||
@EntityGraph(attributePaths = {"scenarioParameters", "scenarioActions", "scenarioMessages"}) | ||
Page<ScenarioExecution> findAll(Pageable pageable); | ||
|
||
@Override | ||
@EntityGraph(attributePaths = {"scenarioParameters", "scenarioActions", "scenarioMessages"}) | ||
Page<ScenarioExecution> findAll(Specification<ScenarioExecution> spec, Pageable pageable); | ||
|
||
@Override | ||
@EntityGraph(attributePaths = {"scenarioParameters", "scenarioActions", "scenarioMessages"}) | ||
Optional<ScenarioExecution> findById(Long id); | ||
} |
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
147 changes: 147 additions & 0 deletions
147
...st/java/org/citrusframework/simulator/service/criteria/ScenarioExecutionCriteriaTest.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,147 @@ | ||
package org.citrusframework.simulator.service.criteria; | ||
|
||
import org.citrusframework.simulator.service.filter.InstantFilter; | ||
import org.citrusframework.simulator.service.filter.IntegerFilter; | ||
import org.citrusframework.simulator.service.filter.LongFilter; | ||
import org.citrusframework.simulator.service.filter.StringFilter; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertNotSame; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
import static org.junit.jupiter.api.Assertions.assertSame; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.mockito.Mockito.mock; | ||
|
||
class ScenarioExecutionCriteriaTest { | ||
|
||
private ScenarioExecutionCriteria fixture; | ||
|
||
@BeforeEach | ||
void beforeEachSetup() { | ||
fixture = new ScenarioExecutionCriteria(); | ||
} | ||
|
||
@Test | ||
void testExecutionId() { | ||
assertNull(fixture.getExecutionId()); | ||
|
||
LongFilter executionIdFilter = fixture.id(); | ||
assertNotNull(executionIdFilter); | ||
assertSame(executionIdFilter, fixture.getExecutionId()); | ||
|
||
LongFilter mockExecutionIdFilter = mock(LongFilter.class); | ||
fixture.setExecutionId(mockExecutionIdFilter); | ||
assertSame(mockExecutionIdFilter, fixture.id()); | ||
} | ||
|
||
@Test | ||
void testStartDate() { | ||
assertNull(fixture.getStartDate()); | ||
|
||
InstantFilter startDateFilter = fixture.startDate(); | ||
assertNotNull(startDateFilter); | ||
assertSame(startDateFilter, fixture.getStartDate()); | ||
|
||
InstantFilter mockStartDateFilter = mock(InstantFilter.class); | ||
fixture.setStartDate(mockStartDateFilter); | ||
assertSame(mockStartDateFilter, fixture.startDate()); | ||
} | ||
|
||
// Add more test methods following the same pattern for all the other attributes... | ||
|
||
@Test | ||
void testScenarioName() { | ||
assertNull(fixture.getScenarioName()); | ||
|
||
StringFilter scenarioNameFilter = fixture.scenarioName(); | ||
assertNotNull(scenarioNameFilter); | ||
assertSame(scenarioNameFilter, fixture.getScenarioName()); | ||
|
||
StringFilter mockScenarioNameFilter = mock(StringFilter.class); | ||
fixture.setScenarioName(mockScenarioNameFilter); | ||
assertSame(mockScenarioNameFilter, fixture.scenarioName()); | ||
} | ||
|
||
@Test | ||
void testStatus() { | ||
assertNull(fixture.getStatus()); | ||
|
||
IntegerFilter statusFilter = fixture.status(); | ||
assertNotNull(statusFilter); | ||
assertSame(statusFilter, fixture.getStatus()); | ||
|
||
IntegerFilter mockStatusFilter = mock(IntegerFilter.class); | ||
fixture.setStatus(mockStatusFilter); | ||
assertSame(mockStatusFilter, fixture.status()); | ||
} | ||
|
||
@Test | ||
void testErrorMessage() { | ||
assertNull(fixture.getErrorMessage()); | ||
|
||
StringFilter errorMessageFilter = fixture.errorMessage(); | ||
assertNotNull(errorMessageFilter); | ||
assertSame(errorMessageFilter, fixture.getErrorMessage()); | ||
|
||
StringFilter mockErrorMessageFilter = mock(StringFilter.class); | ||
fixture.setErrorMessage(mockErrorMessageFilter); | ||
assertSame(mockErrorMessageFilter, fixture.errorMessage()); | ||
} | ||
|
||
@Test | ||
void testScenarioActionsId() { | ||
assertNull(fixture.getScenarioActionsId()); | ||
|
||
LongFilter scenarioActionsIdFilter = fixture.scenarioActionsId(); | ||
assertNotNull(scenarioActionsIdFilter); | ||
assertSame(scenarioActionsIdFilter, fixture.getScenarioActionsId()); | ||
|
||
LongFilter mockScenarioActionsIdFilter = mock(LongFilter.class); | ||
fixture.setScenarioActionsId(mockScenarioActionsIdFilter); | ||
assertSame(mockScenarioActionsIdFilter, fixture.scenarioActionsId()); | ||
} | ||
|
||
@Test | ||
void testScenarioMessagesId() { | ||
assertNull(fixture.getScenarioMessagesId()); | ||
|
||
LongFilter scenarioMessagesIdFilter = fixture.scenarioMessagesId(); | ||
assertNotNull(scenarioMessagesIdFilter); | ||
assertSame(scenarioMessagesIdFilter, fixture.getScenarioMessagesId()); | ||
|
||
LongFilter mockScenarioMessagesIdFilter = mock(LongFilter.class); | ||
fixture.setScenarioMessagesId(mockScenarioMessagesIdFilter); | ||
assertSame(mockScenarioMessagesIdFilter, fixture.scenarioMessagesId()); | ||
} | ||
|
||
@Test | ||
void testScenarioParametersId() { | ||
assertNull(fixture.getScenarioParametersId()); | ||
|
||
LongFilter scenarioParametersIdFilter = fixture.scenarioParametersId(); | ||
assertNotNull(scenarioParametersIdFilter); | ||
assertSame(scenarioParametersIdFilter, fixture.getScenarioParametersId()); | ||
|
||
LongFilter mockScenarioParametersIdFilter = mock(LongFilter.class); | ||
fixture.setScenarioParametersId(mockScenarioParametersIdFilter); | ||
assertSame(mockScenarioParametersIdFilter, fixture.scenarioParametersId()); | ||
} | ||
|
||
@Test | ||
void testDistinct() { | ||
assertNull(fixture.getDistinct()); | ||
|
||
fixture.setDistinct(true); | ||
assertTrue(fixture.getDistinct()); | ||
} | ||
|
||
@Test | ||
void testCopy() { | ||
ScenarioExecutionCriteria copiedCriteria = fixture.copy(); | ||
assertNotSame(copiedCriteria, fixture); | ||
assertEquals(copiedCriteria, fixture); | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
...est/java/org/citrusframework/simulator/service/impl/ScenarioExecutionServiceImplTest.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,69 @@ | ||
package org.citrusframework.simulator.service.impl; | ||
|
||
import org.citrusframework.simulator.model.ScenarioExecution; | ||
import org.citrusframework.simulator.repository.ScenarioExecutionRepository; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.PageImpl; | ||
import org.springframework.data.domain.Pageable; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.mockito.Mockito.when; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class ScenarioExecutionServiceImplTest { | ||
|
||
@Mock | ||
private ScenarioExecutionRepository scenarioExecutionRepositoryMock; | ||
|
||
private ScenarioExecution sampleScenarioExecution; | ||
|
||
private ScenarioExecutionServiceImpl fixture; | ||
|
||
@BeforeEach | ||
void beforeEachSetup() { | ||
sampleScenarioExecution = new ScenarioExecution(); | ||
|
||
fixture = new ScenarioExecutionServiceImpl(scenarioExecutionRepositoryMock); | ||
} | ||
|
||
@Test | ||
void testSave() { | ||
when(scenarioExecutionRepositoryMock.save(sampleScenarioExecution)).thenReturn(sampleScenarioExecution); | ||
|
||
ScenarioExecution savedScenarioExecution = fixture.save(sampleScenarioExecution); | ||
assertEquals(sampleScenarioExecution, savedScenarioExecution); | ||
} | ||
|
||
@Test | ||
void testFindAll() { | ||
Pageable pageable = Pageable.unpaged(); | ||
Page<ScenarioExecution> page = new PageImpl<>(List.of(sampleScenarioExecution)); | ||
|
||
when(scenarioExecutionRepositoryMock.findAll(pageable)).thenReturn(page); | ||
|
||
Page<ScenarioExecution> result = fixture.findAll(pageable); | ||
|
||
assertEquals(page, result); | ||
} | ||
|
||
@Test | ||
void testFindOne() { | ||
Long scenarioExecutionId = 1L; | ||
|
||
when(scenarioExecutionRepositoryMock.findById(scenarioExecutionId)).thenReturn(Optional.of(sampleScenarioExecution)); | ||
|
||
Optional<ScenarioExecution> maybeScenarioExecution = fixture.findOne(scenarioExecutionId); | ||
|
||
assertTrue(maybeScenarioExecution.isPresent()); | ||
assertEquals(sampleScenarioExecution, maybeScenarioExecution.get()); | ||
} | ||
} |
Oops, something went wrong.