Skip to content

Commit

Permalink
feat(simulator-ui): visual improvements
Browse files Browse the repository at this point in the history
* configurable page-size per table
* refresh button on results (landing page)
* possibility to reset test-results (landing page)
  • Loading branch information
bbortt committed Nov 17, 2023
1 parent 3303611 commit 58157fb
Show file tree
Hide file tree
Showing 55 changed files with 609 additions and 133 deletions.
8 changes: 4 additions & 4 deletions simulator-samples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@

<modules>
<module>sample-bank-service</module>
<module>sample-combined</module>
<module>sample-jms</module>
<module>sample-jms-fax</module>
<module>sample-mail</module>
<module>sample-rest</module>
<module>sample-swagger</module>
<module>sample-ws</module>
<module>sample-ws-client</module>
<module>sample-wsdl</module>
<module>sample-mail</module>
<module>sample-combined</module>
<module>sample-jms</module>
<module>sample-jms-fax</module>
</modules>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.citrusframework.simulator.model;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
Expand Down Expand Up @@ -81,7 +82,7 @@ public class TestResult extends AbstractAuditingEntity<TestResult, Long> impleme
/**
* Optional test parameters
*/
@OneToMany(fetch = FetchType.LAZY, mappedBy = "testResult")
@OneToMany(fetch = FetchType.LAZY, mappedBy = "testResult", cascade = {CascadeType.REMOVE})
@JsonIgnoreProperties(value = { "testResult" }, allowSetters = true)
private final Set<TestParameter> testParameters = new HashSet<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,9 @@ public interface TestResultService {
* @return the TestResult count.
*/
TestResultByStatus countByStatus();

/**
* Delete all testResults
*/
void deleteAll();
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,13 @@ public Optional<TestResult> findOne(Long id) {
@Override
@Transactional(readOnly = true)
public TestResultByStatus countByStatus() {
logger.debug("count total by status");
logger.debug("Request to count TestResults by status");
return testResultRepository.countByStatus();
}

@Override
public void deleteAll() {
logger.debug("Request to delete all TestResults");
testResultRepository.deleteAll();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
Expand Down Expand Up @@ -75,6 +76,18 @@ public ResponseEntity<List<TestResult>> getAllTestResults(
return ResponseEntity.ok().headers(headers).body(page.getContent());
}

/**
* {@code DELETE /test-results} : delete all the testResults.
*
* @return the {@link ResponseEntity} with status {@code 201 (NO CONTENT)}.
*/
@DeleteMapping("/test-results")
public ResponseEntity<Void> deleteAllTestResults() {
logger.debug("REST request to delete all TestResults");
testResultService.deleteAll();
return ResponseEntity.noContent().build();
}

/**
* {@code GET /test-results/count} : count all the testResults.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,27 @@
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

@ExtendWith(MockitoExtension.class)
class TestResultServiceImplTest {

@Mock
private TestResultRepository testResultRepository;
private TestResultRepository testResultRepositoryMock;

private TestResultServiceImpl fixture;

@BeforeEach
void beforeEachSetup() {
fixture = new TestResultServiceImpl(testResultRepository);
fixture = new TestResultServiceImpl(testResultRepositoryMock);
}

@Test
void testTransformAndSave() {
org.citrusframework.TestResult citrusTestResult = org.citrusframework.TestResult.success("TestResult", TestResultServiceImpl.class.getSimpleName());

TestResult testResult = new TestResult(citrusTestResult);
doReturn(testResult).when(testResultRepository).save(any(TestResult.class));
doReturn(testResult).when(testResultRepositoryMock).save(any(TestResult.class));

TestResult result = fixture.transformAndSave(citrusTestResult);

Expand All @@ -47,7 +48,7 @@ void testTransformAndSave() {
@Test
void testSave() {
TestResult testResult = new TestResult();
doReturn(testResult).when(testResultRepository).save(testResult);
doReturn(testResult).when(testResultRepositoryMock).save(testResult);

TestResult result = fixture.save(testResult);

Expand All @@ -58,7 +59,7 @@ void testSave() {
void testFindAll() {
Pageable pageable = mock(Pageable.class);
Page<TestResult> mockPage = mock(Page.class);
doReturn(mockPage).when(testResultRepository).findAll(pageable);
doReturn(mockPage).when(testResultRepositoryMock).findAll(pageable);

Page<TestResult> result = fixture.findAll(pageable);

Expand All @@ -71,7 +72,7 @@ void testFindOne() {

TestResult testResult = new TestResult();
Optional<TestResult> optionalTestResult = Optional.of(testResult);
doReturn(optionalTestResult).when(testResultRepository).findById(id);
doReturn(optionalTestResult).when(testResultRepositoryMock).findById(id);

Optional<TestResult> maybeTestResult = fixture.findOne(id);

Expand All @@ -82,9 +83,15 @@ void testFindOne() {
@Test
void testCountByStatus() {
TestResultByStatus testResultByStatus = new TestResultByStatus(1L, 1L);
doReturn(testResultByStatus).when(testResultRepository).countByStatus();
doReturn(testResultByStatus).when(testResultRepositoryMock).countByStatus();

TestResultByStatus result = fixture.countByStatus();
assertEquals(testResultByStatus, result);
}

@Test
void delete() {
fixture.deleteAll();
verify(testResultRepositoryMock).deleteAll();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.citrusframework.simulator.web.rest.TestUtil.sameInstant;
import static org.hamcrest.Matchers.hasItem;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
Expand Down Expand Up @@ -726,6 +729,32 @@ void getAllTestResultsByLastModifiedDateIsGreaterThanSomething() throws Exceptio
@Test
@Transactional
void getAllTestResultsByTestParameterIsEqualToSomething() throws Exception {
TestParameter testParameter = getOrCreateTestParameterWithTestResult();

String testParameterKey = testParameter.getKey();
// Get all the testResultList where testParameter equals to testParameterKey
defaultTestResultShouldBeFound("testParameterKey.equals=" + testParameterKey);

// Get all the testResultList where testParameter equals to (testParameterKey + 1)
defaultTestResultShouldNotBeFound("testParameterKey.equals=" + (testParameterKey + 1));
}

@Test
@Transactional
void deleteAllTestResults() throws Exception {
TestParameter testParameter = getOrCreateTestParameterWithTestResult();

int databaseSizeBeforeDelete = testResultRepository.findAll().size();

mockMvc
.perform(delete(ENTITY_API_URL).accept(MediaType.APPLICATION_JSON))
.andExpect(status().isNoContent());

List<TestResult> eventList = testResultRepository.findAll();
assertThat(eventList).hasSize(databaseSizeBeforeDelete - 1);
}

private TestParameter getOrCreateTestParameterWithTestResult() {
TestParameter testParameter;
if (TestUtil.findAll(entityManager, TestParameter.class).isEmpty()) {
testResultRepository.saveAndFlush(testResult);
Expand All @@ -737,12 +766,7 @@ void getAllTestResultsByTestParameterIsEqualToSomething() throws Exception {
entityManager.flush();
testResult.addTestParameter(testParameter);
testResultRepository.saveAndFlush(testResult);
String testParameterKey = testParameter.getKey();
// Get all the testResultList where testParameter equals to testParameterKey
defaultTestResultShouldBeFound("testParameterKey.equals=" + testParameterKey);

// Get all the testResultList where testParameter equals to (testParameterKey + 1)
defaultTestResultShouldNotBeFound("testParameterKey.equals=" + (testParameterKey + 1));
return testParameter;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { TestBed } from '@angular/core/testing';

import { ITEMS_PER_PAGE } from 'app/config/pagination.constants';

import { UserPreferenceService } from './user-preference.service';

type Mock = jest.Mock;

describe('UserPreferenceService', () => {
let service: UserPreferenceService;
let mockLocalStorage: Partial<Storage> & {
setItem: Mock;
getItem: Mock;
removeItem: Mock;
};

beforeEach(() => {
mockLocalStorage = {
setItem: jest.fn(),
getItem: jest.fn(),
removeItem: jest.fn(),
};

Object.defineProperty(window, 'localStorage', { value: mockLocalStorage, writable: true });

TestBed.configureTestingModule({
providers: [UserPreferenceService],
});

service = TestBed.inject(UserPreferenceService);
});

describe('setPreferredPageSize', () => {
it('should return known item from localStorage', () => {
mockLocalStorage.getItem.mockReturnValueOnce('1234');

const preferredPageSize = service.getPreferredPageSize('key');

expect(preferredPageSize).toEqual(1234);
expect(mockLocalStorage.getItem).toHaveBeenCalledWith('psize-key');
});

it('should return default page size if item is not in localStorage', () => {
mockLocalStorage.getItem.mockReturnValueOnce(null);

const preferredPageSize = service.getPreferredPageSize('key');

expect(preferredPageSize).toEqual(ITEMS_PER_PAGE);
expect(mockLocalStorage.getItem).toHaveBeenCalledWith('psize-key');
});
});

describe('setPreferredPageSize', () => {
it('should save item in localStorage', () => {
service.setPreferredPageSize('key', 1234);

expect(mockLocalStorage.setItem).toHaveBeenCalledWith('psize-key', '1234');
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Injectable } from '@angular/core';

import { ITEMS_PER_PAGE } from 'app/config/pagination.constants';

@Injectable({ providedIn: 'root' })
export class UserPreferenceService {
private paginationPrefix = 'psize';

public getPreferredPageSize(key: string): number {
return Number(localStorage.getItem(this.paginationId(key)) ?? ITEMS_PER_PAGE);
}

public setPreferredPageSize(key: string, size: number): void {
localStorage.setItem(this.paginationId(key), size.toString());
}

private paginationId(key: string): string {
return `${this.paginationPrefix}-${key}`;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('MessageHeader Management Detail Component', () => {
});

describe('OnInit', () => {
it('Should load messageHeader on init', async () => {
it('should load messageHeader on init', async () => {
const harness = await RouterTestingHarness.create();
const instance = await harness.navigateByUrl('/', MessageHeaderDetailComponent);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe('MessageHeader Table Component', () => {
});

describe('trackId', () => {
it('Should forward to messageHeaderService', () => {
it('should forward to messageHeaderService', () => {
const entity = { headerId: 123 };
jest.spyOn(service, 'getMessageHeaderIdentifier');
const headerId = component.trackId(0, entity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe('MessageHeader Management Component', () => {
);
});

it('Should call load all on init', () => {
it('should call load all on init', () => {
// WHEN
component.ngOnInit();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ describe('MessageHeader Service', () => {
});

describe('compareMessageHeader', () => {
it('Should return true if both entities are null', () => {
it('should return true if both entities are null', () => {
const entity1 = null;
const entity2 = null;

Expand All @@ -119,7 +119,7 @@ describe('MessageHeader Service', () => {
expect(compareResult).toEqual(true);
});

it('Should return false if one entity is null', () => {
it('should return false if one entity is null', () => {
const entity1 = { headerId: 123 };
const entity2 = null;

Expand All @@ -130,7 +130,7 @@ describe('MessageHeader Service', () => {
expect(compareResult2).toEqual(false);
});

it('Should return false if primaryKey differs', () => {
it('should return false if primaryKey differs', () => {
const entity1 = { headerId: 123 };
const entity2 = { headerId: 456 };

Expand All @@ -141,7 +141,7 @@ describe('MessageHeader Service', () => {
expect(compareResult2).toEqual(false);
});

it('Should return false if primaryKey matches', () => {
it('should return false if primaryKey matches', () => {
const entity1 = { headerId: 123 };
const entity2 = { headerId: 123 };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('Message Management Detail Component', () => {
});

describe('OnInit', () => {
it('Should load message on init', async () => {
it('should load message on init', async () => {
const harness = await RouterTestingHarness.create();
const instance = await harness.navigateByUrl('/', MessageDetailComponent);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('Message Management Component', () => {
);
});

it('Should call load all on init', () => {
it('should call load all on init', () => {
// WHEN
comp.ngOnInit();

Expand All @@ -72,7 +72,7 @@ describe('Message Management Component', () => {
});

describe('trackId', () => {
it('Should forward to messageService', () => {
it('should forward to messageService', () => {
const entity = { messageId: 123 };
jest.spyOn(service, 'getMessageIdentifier');
const messageId = comp.trackId(0, entity);
Expand Down
Loading

0 comments on commit 58157fb

Please sign in to comment.