adding AccessMappings SepaMandateDTO with tests + consequences (HOWTO)
This commit is contained in:
		@@ -0,0 +1,189 @@
 | 
			
		||||
package org.hostsharing.hsadminng.service.dto;
 | 
			
		||||
 | 
			
		||||
import com.fasterxml.jackson.core.JsonProcessingException;
 | 
			
		||||
import com.fasterxml.jackson.databind.ObjectMapper;
 | 
			
		||||
import org.apache.commons.lang3.RandomUtils;
 | 
			
		||||
import org.hostsharing.hsadminng.domain.Customer;
 | 
			
		||||
import org.hostsharing.hsadminng.domain.SepaMandate;
 | 
			
		||||
import org.hostsharing.hsadminng.repository.CustomerRepository;
 | 
			
		||||
import org.hostsharing.hsadminng.repository.MembershipRepository;
 | 
			
		||||
import org.hostsharing.hsadminng.repository.SepaMandateRepository;
 | 
			
		||||
import org.hostsharing.hsadminng.service.MembershipValidator;
 | 
			
		||||
import org.hostsharing.hsadminng.service.SepaMandateService;
 | 
			
		||||
import org.hostsharing.hsadminng.service.accessfilter.JSonBuilder;
 | 
			
		||||
import org.hostsharing.hsadminng.service.accessfilter.Role;
 | 
			
		||||
import org.hostsharing.hsadminng.service.mapper.CustomerMapperImpl;
 | 
			
		||||
import org.hostsharing.hsadminng.service.mapper.MembershipMapperImpl;
 | 
			
		||||
import org.hostsharing.hsadminng.service.mapper.SepaMandateMapper;
 | 
			
		||||
import org.hostsharing.hsadminng.service.mapper.SepaMandateMapperImpl;
 | 
			
		||||
import org.hostsharing.hsadminng.web.rest.errors.BadRequestAlertException;
 | 
			
		||||
import org.junit.Before;
 | 
			
		||||
import org.junit.Rule;
 | 
			
		||||
import org.junit.Test;
 | 
			
		||||
import org.junit.runner.RunWith;
 | 
			
		||||
import org.mockito.junit.MockitoJUnit;
 | 
			
		||||
import org.mockito.junit.MockitoRule;
 | 
			
		||||
import org.springframework.beans.factory.annotation.Autowired;
 | 
			
		||||
import org.springframework.boot.test.autoconfigure.json.JsonTest;
 | 
			
		||||
import org.springframework.boot.test.context.SpringBootTest;
 | 
			
		||||
import org.springframework.boot.test.mock.mockito.MockBean;
 | 
			
		||||
import org.springframework.test.context.junit4.SpringRunner;
 | 
			
		||||
 | 
			
		||||
import javax.persistence.EntityManager;
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
import java.util.Objects;
 | 
			
		||||
import java.util.Optional;
 | 
			
		||||
 | 
			
		||||
import static org.assertj.core.api.Assertions.assertThat;
 | 
			
		||||
import static org.assertj.core.api.Assertions.catchThrowable;
 | 
			
		||||
import static org.hostsharing.hsadminng.service.accessfilter.MockSecurityContext.givenAuthenticatedUser;
 | 
			
		||||
import static org.hostsharing.hsadminng.service.accessfilter.MockSecurityContext.givenUserHavingRole;
 | 
			
		||||
import static org.hostsharing.hsadminng.service.dto.SepaMandateDTOUnitTest.createSampleDTO;
 | 
			
		||||
import static org.junit.Assert.assertEquals;
 | 
			
		||||
import static org.mockito.BDDMockito.given;
 | 
			
		||||
 | 
			
		||||
@JsonTest
 | 
			
		||||
@SpringBootTest(classes = {
 | 
			
		||||
    CustomerMapperImpl.class,
 | 
			
		||||
    MembershipMapperImpl.class,
 | 
			
		||||
    SepaMandateMapperImpl.class,
 | 
			
		||||
    SepaMandateDTO.JsonSerializer.class,
 | 
			
		||||
    SepaMandateDTO.JsonDeserializer.class
 | 
			
		||||
})
 | 
			
		||||
@RunWith(SpringRunner.class)
 | 
			
		||||
public class SepaMandateDTOIntTest {
 | 
			
		||||
 | 
			
		||||
    private static final Long SOME_CUSTOMER_ID = RandomUtils.nextLong(100, 199);
 | 
			
		||||
    private static final Integer SOME_CUSTOMER_REFERENCE = 10001;
 | 
			
		||||
    private static final String SOME_CUSTOMER_PREFIX = "abc";
 | 
			
		||||
    private static final String SOME_CUSTOMER_NAME = "Some Customer Name";
 | 
			
		||||
    private static final Customer SOME_CUSTOMER = new Customer().id(SOME_CUSTOMER_ID)
 | 
			
		||||
        .reference(SOME_CUSTOMER_REFERENCE).prefix(SOME_CUSTOMER_PREFIX).name(SOME_CUSTOMER_NAME);
 | 
			
		||||
 | 
			
		||||
    private static final Long SOME_SEPA_MANDATE_ID = RandomUtils.nextLong(300, 399);
 | 
			
		||||
    private static final SepaMandate SOME_SEPA_MANDATE = new SepaMandate().id(SOME_SEPA_MANDATE_ID).customer(SOME_CUSTOMER);
 | 
			
		||||
 | 
			
		||||
    @Rule
 | 
			
		||||
    public MockitoRule mockito = MockitoJUnit.rule();
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private ObjectMapper objectMapper;
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private SepaMandateMapper sepaMandateMapper;
 | 
			
		||||
 | 
			
		||||
    @MockBean
 | 
			
		||||
    private SepaMandateRepository sepaMandateRepository;
 | 
			
		||||
 | 
			
		||||
    @MockBean
 | 
			
		||||
    private CustomerRepository customerRepository;
 | 
			
		||||
 | 
			
		||||
    @MockBean
 | 
			
		||||
    private MembershipRepository membershipRepository;
 | 
			
		||||
 | 
			
		||||
    @MockBean
 | 
			
		||||
    private MembershipValidator membershipValidator;
 | 
			
		||||
 | 
			
		||||
    @MockBean
 | 
			
		||||
    private SepaMandateService sepaMandateService;
 | 
			
		||||
 | 
			
		||||
    @MockBean
 | 
			
		||||
    private EntityManager em;
 | 
			
		||||
 | 
			
		||||
    @Before
 | 
			
		||||
    public void init() {
 | 
			
		||||
        given(customerRepository.findById(SOME_CUSTOMER_ID)).willReturn(Optional.of(SOME_CUSTOMER));
 | 
			
		||||
        given(sepaMandateRepository.findById(SOME_SEPA_MANDATE_ID)).willReturn((Optional.of(SOME_SEPA_MANDATE)));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    public void shouldSerializePartiallyForFinancialCustomerContact() throws JsonProcessingException {
 | 
			
		||||
 | 
			
		||||
        // given
 | 
			
		||||
        givenAuthenticatedUser();
 | 
			
		||||
        givenUserHavingRole(CustomerDTO.class, SOME_CUSTOMER_ID, Role.FINANCIAL_CONTACT);
 | 
			
		||||
        final SepaMandateDTO given = createSampleDTO(SOME_SEPA_MANDATE_ID, SOME_CUSTOMER_ID);
 | 
			
		||||
 | 
			
		||||
        // when
 | 
			
		||||
        final String actual = objectMapper.writeValueAsString(given);
 | 
			
		||||
 | 
			
		||||
        // then
 | 
			
		||||
        given.setRemark(null);
 | 
			
		||||
        assertEquals(createExpectedJSon(given), actual);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    public void shouldSerializeCompletelyForSupporter() throws JsonProcessingException {
 | 
			
		||||
 | 
			
		||||
        // given
 | 
			
		||||
        givenAuthenticatedUser();
 | 
			
		||||
        givenUserHavingRole(Role.SUPPORTER);
 | 
			
		||||
        final SepaMandateDTO given = createSampleDTO(SOME_SEPA_MANDATE_ID, SOME_CUSTOMER_ID);
 | 
			
		||||
 | 
			
		||||
        // when
 | 
			
		||||
        final String actual = objectMapper.writeValueAsString(given);
 | 
			
		||||
 | 
			
		||||
        // then
 | 
			
		||||
        assertEquals(createExpectedJSon(given), actual);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    public void shouldNotDeserializeForContractualCustomerContact() {
 | 
			
		||||
        // given
 | 
			
		||||
        givenAuthenticatedUser();
 | 
			
		||||
        givenUserHavingRole(CustomerDTO.class, SOME_CUSTOMER_ID, Role.CONTRACTUAL_CONTACT);
 | 
			
		||||
        final String json = new JSonBuilder()
 | 
			
		||||
            .withFieldValue("id", SOME_SEPA_MANDATE_ID)
 | 
			
		||||
            .withFieldValue("remark", "Updated Remark")
 | 
			
		||||
            .toString();
 | 
			
		||||
 | 
			
		||||
        // when
 | 
			
		||||
        final Throwable actual = catchThrowable(() -> objectMapper.readValue(json, SepaMandateDTO.class));
 | 
			
		||||
 | 
			
		||||
        // then
 | 
			
		||||
        assertThat(actual).isInstanceOfSatisfying(BadRequestAlertException.class, bre ->
 | 
			
		||||
            assertThat(bre.getMessage()).isEqualTo("Update of field SepaMandateDTO.remark prohibited for current user role CONTRACTUAL_CONTACT")
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    public void shouldDeserializeForAdminIfRemarkIsChanged() throws IOException {
 | 
			
		||||
        // given
 | 
			
		||||
        givenAuthenticatedUser();
 | 
			
		||||
        givenUserHavingRole(Role.ADMIN);
 | 
			
		||||
        final String json = new JSonBuilder()
 | 
			
		||||
            .withFieldValue("id", SOME_SEPA_MANDATE_ID)
 | 
			
		||||
            .withFieldValue("remark", "Updated Remark")
 | 
			
		||||
            .toString();
 | 
			
		||||
 | 
			
		||||
        // when
 | 
			
		||||
        final SepaMandateDTO actual = objectMapper.readValue(json, SepaMandateDTO.class);
 | 
			
		||||
 | 
			
		||||
        // then
 | 
			
		||||
        final SepaMandateDTO expected = new SepaMandateDTO();
 | 
			
		||||
        expected.setId(SOME_SEPA_MANDATE_ID);
 | 
			
		||||
        expected.setCustomerId(SOME_CUSTOMER_ID);
 | 
			
		||||
        expected.setRemark("Updated Remark");
 | 
			
		||||
        expected.setCustomerPrefix(SOME_CUSTOMER_PREFIX);
 | 
			
		||||
        assertThat(actual).isEqualToIgnoringGivenFields(expected, "displayLabel");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // --- only test fixture below ---
 | 
			
		||||
 | 
			
		||||
    private String createExpectedJSon(SepaMandateDTO dto) {
 | 
			
		||||
        return new JSonBuilder()
 | 
			
		||||
            .withFieldValueIfPresent("id", dto.getId())
 | 
			
		||||
            .withFieldValueIfPresent("reference", dto.getReference())
 | 
			
		||||
            .withFieldValueIfPresent("iban", dto.getIban())
 | 
			
		||||
            .withFieldValueIfPresent("bic", dto.getBic())
 | 
			
		||||
            .withFieldValueIfPresent("grantingDocumentDate", Objects.toString(dto.getGrantingDocumentDate()))
 | 
			
		||||
            .withFieldValueIfPresent("revokationDocumentDate", Objects.toString(dto.getRevokationDocumentDate()))
 | 
			
		||||
            .withFieldValueIfPresent("validFromDate", Objects.toString(dto.getValidFromDate()))
 | 
			
		||||
            .withFieldValueIfPresent("validUntilDate", Objects.toString(dto.getValidUntilDate()))
 | 
			
		||||
            .withFieldValueIfPresent("lastUsedDate", Objects.toString(dto.getLastUsedDate()))
 | 
			
		||||
            .withFieldValueIfPresent("remark", dto.getRemark())
 | 
			
		||||
            .withFieldValueIfPresent("customerId", dto.getCustomerId())
 | 
			
		||||
            .withFieldValue("customerPrefix", dto.getCustomerPrefix())
 | 
			
		||||
            .toString();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,96 @@
 | 
			
		||||
package org.hostsharing.hsadminng.service.dto;
 | 
			
		||||
 | 
			
		||||
import org.apache.commons.lang3.RandomStringUtils;
 | 
			
		||||
import org.apache.commons.lang3.RandomUtils;
 | 
			
		||||
import org.hostsharing.hsadminng.service.accessfilter.Role;
 | 
			
		||||
import org.junit.Test;
 | 
			
		||||
 | 
			
		||||
import java.time.LocalDate;
 | 
			
		||||
 | 
			
		||||
public class SepaMandateDTOUnitTest extends AccessMappingsUnitTestBase<SepaMandateDTO> {
 | 
			
		||||
 | 
			
		||||
    public SepaMandateDTOUnitTest() {
 | 
			
		||||
        super(SepaMandateDTO.class, SepaMandateDTOUnitTest::createSampleDTO, SepaMandateDTOUnitTest::createRandomDTO);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    public void shouldHaveProperAccessForAdmin() {
 | 
			
		||||
        initAccessFor(SepaMandateDTO.class, Role.ADMIN).shouldBeExactlyFor(
 | 
			
		||||
            "grantingDocumentDate", "bic", "remark", "validUntilDate", "customerId", "validFromDate",
 | 
			
		||||
            "iban", "revokationDocumentDate", "lastUsedDate", "reference");
 | 
			
		||||
        updateAccessFor(SepaMandateDTO.class, Role.ADMIN).shouldBeExactlyFor(
 | 
			
		||||
            "remark", "validUntilDate", "revokationDocumentDate", "lastUsedDate");
 | 
			
		||||
        readAccessFor(SepaMandateDTO.class, Role.ADMIN).shouldBeForAllFields();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    public void shouldHaveProperAccessForSupporter() {
 | 
			
		||||
        initAccessFor(SepaMandateDTO.class, Role.SUPPORTER).shouldBeExactlyFor(
 | 
			
		||||
            "grantingDocumentDate", "bic", "validUntilDate", "customerId", "validFromDate", "iban", "reference");
 | 
			
		||||
        updateAccessFor(SepaMandateDTO.class, Role.SUPPORTER).shouldBeExactlyFor(
 | 
			
		||||
            "remark", "validUntilDate", "revokationDocumentDate");
 | 
			
		||||
        readAccessFor(SepaMandateDTO.class, Role.SUPPORTER).shouldBeForAllFields();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    public void shouldHaveProperAccessForContractualContact() {
 | 
			
		||||
        initAccessFor(SepaMandateDTO.class, Role.CONTRACTUAL_CONTACT).shouldBeExactlyFor(
 | 
			
		||||
            "grantingDocumentDate", "bic", "validUntilDate", "customerId", "validFromDate", "iban", "reference");
 | 
			
		||||
        updateAccessFor(SepaMandateDTO.class, Role.CONTRACTUAL_CONTACT).shouldBeExactlyFor(
 | 
			
		||||
            "validUntilDate", "revokationDocumentDate");
 | 
			
		||||
        readAccessFor(SepaMandateDTO.class, Role.CONTRACTUAL_CONTACT).shouldBeExactlyFor(
 | 
			
		||||
            "grantingDocumentDate", "bic", "id", "validUntilDate", "customerId", "validFromDate", "iban",
 | 
			
		||||
            "revokationDocumentDate", "customerPrefix", "lastUsedDate", "reference");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    public void shouldHaveNoAccessForTechnicalContact() {
 | 
			
		||||
        initAccessFor(SepaMandateDTO.class, Role.TECHNICAL_CONTACT).shouldBeForNothing();
 | 
			
		||||
        updateAccessFor(SepaMandateDTO.class, Role.TECHNICAL_CONTACT).shouldBeForNothing();
 | 
			
		||||
        readAccessFor(SepaMandateDTO.class, Role.TECHNICAL_CONTACT).shouldBeForNothing();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    public void shouldHaveNoAccessForNormalUsersWithinCustomerRealm() {
 | 
			
		||||
        initAccessFor(SepaMandateDTO.class, Role.ANY_CUSTOMER_USER).shouldBeForNothing();
 | 
			
		||||
        updateAccessFor(SepaMandateDTO.class, Role.ANY_CUSTOMER_USER).shouldBeForNothing();
 | 
			
		||||
        readAccessFor(SepaMandateDTO.class, Role.ANY_CUSTOMER_USER).shouldBeForNothing();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // --- only test fixture below ---
 | 
			
		||||
 | 
			
		||||
    public static SepaMandateDTO createSampleDTO(final Long id, final Long parentId) {
 | 
			
		||||
        final SepaMandateDTO dto = new SepaMandateDTO();
 | 
			
		||||
        dto.setId(id);
 | 
			
		||||
        dto.setReference("Some Reference");
 | 
			
		||||
        dto.setGrantingDocumentDate(LocalDate.parse("2000-12-07"));
 | 
			
		||||
        dto.setRevokationDocumentDate(LocalDate.parse("2019-04-27"));
 | 
			
		||||
        dto.setValidFromDate(LocalDate.parse("2000-12-18"));
 | 
			
		||||
        dto.setValidUntilDate(LocalDate.parse("2019-05-31"));
 | 
			
		||||
        dto.setLastUsedDate(LocalDate.parse("2019-04-04"));
 | 
			
		||||
        dto.setIban("DE1234IBAN");
 | 
			
		||||
        dto.setBic("BIC1234");
 | 
			
		||||
        dto.setRemark("Some Remark");
 | 
			
		||||
        dto.setCustomerId(parentId);
 | 
			
		||||
        dto.setCustomerPrefix("abc");
 | 
			
		||||
        return dto;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static SepaMandateDTO createRandomDTO(final Long id, final Long parentId) {
 | 
			
		||||
        final SepaMandateDTO dto = new SepaMandateDTO();
 | 
			
		||||
        dto.setId(id);
 | 
			
		||||
        dto.setReference(RandomStringUtils.randomAlphanumeric(10));
 | 
			
		||||
        final LocalDate randomDate = LocalDate.parse("2000-12-07").plusDays(RandomUtils.nextInt(1, 999));
 | 
			
		||||
        dto.setGrantingDocumentDate(randomDate);
 | 
			
		||||
        dto.setRevokationDocumentDate(randomDate.plusDays(RandomUtils.nextInt(1100, 2999)));
 | 
			
		||||
        dto.setValidFromDate(randomDate.plusDays(RandomUtils.nextInt(0, 7)));
 | 
			
		||||
        dto.setValidUntilDate(dto.getRevokationDocumentDate().plusDays(7));
 | 
			
		||||
        dto.setLastUsedDate(dto.getRevokationDocumentDate().minusDays(20));
 | 
			
		||||
        dto.setIban(RandomStringUtils.randomAlphanumeric(20).toUpperCase());
 | 
			
		||||
        dto.setBic(RandomStringUtils.randomAlphanumeric(10).toUpperCase());
 | 
			
		||||
        dto.setRemark(RandomStringUtils.randomAlphanumeric(20).toUpperCase());
 | 
			
		||||
        dto.setCustomerId(parentId);
 | 
			
		||||
        dto.setCustomerPrefix(RandomStringUtils.randomAlphabetic(3).toLowerCase());
 | 
			
		||||
        return dto;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -6,6 +6,8 @@ import org.hostsharing.hsadminng.domain.SepaMandate;
 | 
			
		||||
import org.hostsharing.hsadminng.repository.SepaMandateRepository;
 | 
			
		||||
import org.hostsharing.hsadminng.service.SepaMandateQueryService;
 | 
			
		||||
import org.hostsharing.hsadminng.service.SepaMandateService;
 | 
			
		||||
import org.hostsharing.hsadminng.service.accessfilter.MockSecurityContext;
 | 
			
		||||
import org.hostsharing.hsadminng.service.accessfilter.Role;
 | 
			
		||||
import org.hostsharing.hsadminng.service.dto.SepaMandateDTO;
 | 
			
		||||
import org.hostsharing.hsadminng.service.mapper.SepaMandateMapper;
 | 
			
		||||
import org.hostsharing.hsadminng.web.rest.errors.ExceptionTranslator;
 | 
			
		||||
@@ -104,6 +106,9 @@ public class SepaMandateResourceIntTest {
 | 
			
		||||
 | 
			
		||||
    @Before
 | 
			
		||||
    public void setup() {
 | 
			
		||||
        MockSecurityContext.givenAuthenticatedUser();
 | 
			
		||||
        MockSecurityContext.givenUserHavingRole(Role.ADMIN);
 | 
			
		||||
 | 
			
		||||
        MockitoAnnotations.initMocks(this);
 | 
			
		||||
        final SepaMandateResource sepaMandateResource = new SepaMandateResource(sepaMandateService, sepaMandateQueryService);
 | 
			
		||||
        this.restSepaMandateMockMvc = MockMvcBuilders.standaloneSetup(sepaMandateResource)
 | 
			
		||||
@@ -173,6 +178,7 @@ public class SepaMandateResourceIntTest {
 | 
			
		||||
 | 
			
		||||
        // Create the SepaMandate
 | 
			
		||||
        SepaMandateDTO sepaMandateDTO = sepaMandateMapper.toDto(sepaMandate);
 | 
			
		||||
        sepaMandateDTO.setCustomerPrefix(null);
 | 
			
		||||
        restSepaMandateMockMvc.perform(post("/api/sepa-mandates")
 | 
			
		||||
            .contentType(TestUtil.APPLICATION_JSON_UTF8)
 | 
			
		||||
            .content(TestUtil.convertObjectToJsonBytes(sepaMandateDTO)))
 | 
			
		||||
@@ -281,15 +287,15 @@ public class SepaMandateResourceIntTest {
 | 
			
		||||
            .andExpect(status().isOk())
 | 
			
		||||
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
 | 
			
		||||
            .andExpect(jsonPath("$.[*].id").value(hasItem(sepaMandate.getId().intValue())))
 | 
			
		||||
            .andExpect(jsonPath("$.[*].reference").value(hasItem(DEFAULT_REFERENCE.toString())))
 | 
			
		||||
            .andExpect(jsonPath("$.[*].iban").value(hasItem(DEFAULT_IBAN.toString())))
 | 
			
		||||
            .andExpect(jsonPath("$.[*].bic").value(hasItem(DEFAULT_BIC.toString())))
 | 
			
		||||
            .andExpect(jsonPath("$.[*].reference").value(hasItem(DEFAULT_REFERENCE)))
 | 
			
		||||
            .andExpect(jsonPath("$.[*].iban").value(hasItem(DEFAULT_IBAN)))
 | 
			
		||||
            .andExpect(jsonPath("$.[*].bic").value(hasItem(DEFAULT_BIC)))
 | 
			
		||||
            .andExpect(jsonPath("$.[*].grantingDocumentDate").value(hasItem(DEFAULT_GRANTING_DOCUMENT_DATE.toString())))
 | 
			
		||||
            .andExpect(jsonPath("$.[*].revokationDocumentDate").value(hasItem(DEFAULT_REVOKATION_DOCUMENT_DATE.toString())))
 | 
			
		||||
            .andExpect(jsonPath("$.[*].validFromDate").value(hasItem(DEFAULT_VALID_FROM_DATE.toString())))
 | 
			
		||||
            .andExpect(jsonPath("$.[*].validUntilDate").value(hasItem(DEFAULT_VALID_UNTIL_DATE.toString())))
 | 
			
		||||
            .andExpect(jsonPath("$.[*].lastUsedDate").value(hasItem(DEFAULT_LAST_USED_DATE.toString())))
 | 
			
		||||
            .andExpect(jsonPath("$.[*].remark").value(hasItem(DEFAULT_REMARK.toString())));
 | 
			
		||||
            .andExpect(jsonPath("$.[*].remark").value(hasItem(DEFAULT_REMARK)));
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    @Test
 | 
			
		||||
@@ -303,15 +309,15 @@ public class SepaMandateResourceIntTest {
 | 
			
		||||
            .andExpect(status().isOk())
 | 
			
		||||
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
 | 
			
		||||
            .andExpect(jsonPath("$.id").value(sepaMandate.getId().intValue()))
 | 
			
		||||
            .andExpect(jsonPath("$.reference").value(DEFAULT_REFERENCE.toString()))
 | 
			
		||||
            .andExpect(jsonPath("$.iban").value(DEFAULT_IBAN.toString()))
 | 
			
		||||
            .andExpect(jsonPath("$.bic").value(DEFAULT_BIC.toString()))
 | 
			
		||||
            .andExpect(jsonPath("$.reference").value(DEFAULT_REFERENCE))
 | 
			
		||||
            .andExpect(jsonPath("$.iban").value(DEFAULT_IBAN))
 | 
			
		||||
            .andExpect(jsonPath("$.bic").value(DEFAULT_BIC))
 | 
			
		||||
            .andExpect(jsonPath("$.grantingDocumentDate").value(DEFAULT_GRANTING_DOCUMENT_DATE.toString()))
 | 
			
		||||
            .andExpect(jsonPath("$.revokationDocumentDate").value(DEFAULT_REVOKATION_DOCUMENT_DATE.toString()))
 | 
			
		||||
            .andExpect(jsonPath("$.validFromDate").value(DEFAULT_VALID_FROM_DATE.toString()))
 | 
			
		||||
            .andExpect(jsonPath("$.validUntilDate").value(DEFAULT_VALID_UNTIL_DATE.toString()))
 | 
			
		||||
            .andExpect(jsonPath("$.lastUsedDate").value(DEFAULT_LAST_USED_DATE.toString()))
 | 
			
		||||
            .andExpect(jsonPath("$.remark").value(DEFAULT_REMARK.toString()));
 | 
			
		||||
            .andExpect(jsonPath("$.remark").value(DEFAULT_REMARK));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
@@ -880,12 +886,7 @@ public class SepaMandateResourceIntTest {
 | 
			
		||||
        // Disconnect from session so that the updates on updatedSepaMandate are not directly saved in db
 | 
			
		||||
        em.detach(updatedSepaMandate);
 | 
			
		||||
        updatedSepaMandate
 | 
			
		||||
            .reference(UPDATED_REFERENCE)
 | 
			
		||||
            .iban(UPDATED_IBAN)
 | 
			
		||||
            .bic(UPDATED_BIC)
 | 
			
		||||
            .grantingDocumentDate(UPDATED_GRANTING_DOCUMENT_DATE)
 | 
			
		||||
            .revokationDocumentDate(UPDATED_REVOKATION_DOCUMENT_DATE)
 | 
			
		||||
            .validFromDate(UPDATED_VALID_FROM_DATE)
 | 
			
		||||
            .validUntilDate(UPDATED_VALID_UNTIL_DATE)
 | 
			
		||||
            .lastUsedDate(UPDATED_LAST_USED_DATE)
 | 
			
		||||
            .remark(UPDATED_REMARK);
 | 
			
		||||
@@ -900,12 +901,12 @@ public class SepaMandateResourceIntTest {
 | 
			
		||||
        List<SepaMandate> sepaMandateList = sepaMandateRepository.findAll();
 | 
			
		||||
        assertThat(sepaMandateList).hasSize(databaseSizeBeforeUpdate);
 | 
			
		||||
        SepaMandate testSepaMandate = sepaMandateList.get(sepaMandateList.size() - 1);
 | 
			
		||||
        assertThat(testSepaMandate.getReference()).isEqualTo(UPDATED_REFERENCE);
 | 
			
		||||
        assertThat(testSepaMandate.getIban()).isEqualTo(UPDATED_IBAN);
 | 
			
		||||
        assertThat(testSepaMandate.getBic()).isEqualTo(UPDATED_BIC);
 | 
			
		||||
        assertThat(testSepaMandate.getGrantingDocumentDate()).isEqualTo(UPDATED_GRANTING_DOCUMENT_DATE);
 | 
			
		||||
        assertThat(testSepaMandate.getReference()).isEqualTo(DEFAULT_REFERENCE);
 | 
			
		||||
        assertThat(testSepaMandate.getIban()).isEqualTo(DEFAULT_IBAN);
 | 
			
		||||
        assertThat(testSepaMandate.getBic()).isEqualTo(DEFAULT_BIC);
 | 
			
		||||
        assertThat(testSepaMandate.getGrantingDocumentDate()).isEqualTo(DEFAULT_GRANTING_DOCUMENT_DATE);
 | 
			
		||||
        assertThat(testSepaMandate.getRevokationDocumentDate()).isEqualTo(UPDATED_REVOKATION_DOCUMENT_DATE);
 | 
			
		||||
        assertThat(testSepaMandate.getValidFromDate()).isEqualTo(UPDATED_VALID_FROM_DATE);
 | 
			
		||||
        assertThat(testSepaMandate.getValidFromDate()).isEqualTo(DEFAULT_VALID_FROM_DATE);
 | 
			
		||||
        assertThat(testSepaMandate.getValidUntilDate()).isEqualTo(UPDATED_VALID_UNTIL_DATE);
 | 
			
		||||
        assertThat(testSepaMandate.getLastUsedDate()).isEqualTo(UPDATED_LAST_USED_DATE);
 | 
			
		||||
        assertThat(testSepaMandate.getRemark()).isEqualTo(UPDATED_REMARK);
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,56 @@
 | 
			
		||||
package org.hostsharing.hsadminng.web.rest;
 | 
			
		||||
 | 
			
		||||
import org.hostsharing.hsadminng.service.dto.SepaMandateDTO;
 | 
			
		||||
import org.hostsharing.hsadminng.service.dto.SepaMandateDTOUnitTest;
 | 
			
		||||
import org.hostsharing.hsadminng.web.rest.errors.BadRequestAlertException;
 | 
			
		||||
import org.junit.Rule;
 | 
			
		||||
import org.junit.Test;
 | 
			
		||||
import org.mockito.InjectMocks;
 | 
			
		||||
import org.mockito.junit.MockitoJUnit;
 | 
			
		||||
import org.mockito.junit.MockitoRule;
 | 
			
		||||
 | 
			
		||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
 | 
			
		||||
import static org.assertj.core.api.ThrowableAssert.catchThrowable;
 | 
			
		||||
 | 
			
		||||
// Currently this class tests mostly special 'bad paths'
 | 
			
		||||
// which make little sense to test in *ResourceIntTest.
 | 
			
		||||
public class SepaMandateResourceUnitTest {
 | 
			
		||||
 | 
			
		||||
    @Rule
 | 
			
		||||
    public MockitoRule mockitoRule = MockitoJUnit.rule();
 | 
			
		||||
 | 
			
		||||
    @InjectMocks
 | 
			
		||||
    private SepaMandateResource sepaMandateResource;
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    public void createSepaMandateWithoutIdThrowsBadRequestException() {
 | 
			
		||||
 | 
			
		||||
        // given
 | 
			
		||||
        final SepaMandateDTO givenDto = SepaMandateDTOUnitTest.createRandomDTO(null, 1L);
 | 
			
		||||
 | 
			
		||||
        // when
 | 
			
		||||
        final Throwable actual = catchThrowable(() -> sepaMandateResource.updateSepaMandate(givenDto));
 | 
			
		||||
 | 
			
		||||
        // then
 | 
			
		||||
        assertThat(actual).isInstanceOfSatisfying(BadRequestAlertException.class, bre -> {
 | 
			
		||||
            assertThat(bre.getErrorKey()).isEqualTo("idnull");
 | 
			
		||||
            assertThat(bre.getParam()).isEqualTo("sepaMandate");
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    public void createSepaMandateWithIdThrowsBadRequestException() {
 | 
			
		||||
 | 
			
		||||
        // given
 | 
			
		||||
        final SepaMandateDTO givenDto = SepaMandateDTOUnitTest.createRandomDTO(2L, 1L);
 | 
			
		||||
 | 
			
		||||
        // when
 | 
			
		||||
        final Throwable actual = catchThrowable(() -> sepaMandateResource.createSepaMandate(givenDto));
 | 
			
		||||
 | 
			
		||||
        // then
 | 
			
		||||
        assertThat(actual).isInstanceOfSatisfying(BadRequestAlertException.class, bre -> {
 | 
			
		||||
            assertThat(bre.getErrorKey()).isEqualTo("idexists");
 | 
			
		||||
            assertThat(bre.getParam()).isEqualTo("sepaMandate");
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user