Search in sources :

Example 1 with AuthenticationRequest

use of com.salesmanager.shop.store.security.AuthenticationRequest in project shopizer by shopizer-ecommerce.

the class ServicesTestSupport method getHeader.

protected HttpHeaders getHeader(final String userName, final String password) {
    final ResponseEntity<AuthenticationResponse> response = testRestTemplate.postForEntity("/api/v1/private/login", new HttpEntity<>(new AuthenticationRequest(userName, password)), AuthenticationResponse.class);
    final HttpHeaders headers = new HttpHeaders();
    headers.setContentType(new MediaType("application", "json", Charset.forName("UTF-8")));
    headers.add("Authorization", "Bearer " + response.getBody().getToken());
    return headers;
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) MediaType(org.springframework.http.MediaType) AuthenticationRequest(com.salesmanager.shop.store.security.AuthenticationRequest) AuthenticationResponse(com.salesmanager.shop.store.security.AuthenticationResponse)

Example 2 with AuthenticationRequest

use of com.salesmanager.shop.store.security.AuthenticationRequest in project shopizer by shopizer-ecommerce.

the class CustomerRegistrationIntegrationTest method registerCustomer.

@Test
public void registerCustomer() {
    final PersistableCustomer testCustomer = new PersistableCustomer();
    testCustomer.setEmailAddress("customer1@test.com");
    testCustomer.setPassword("clear123");
    testCustomer.setGender(CustomerGender.M.name());
    testCustomer.setLanguage("en");
    final Address billing = new Address();
    billing.setFirstName("customer1");
    billing.setLastName("ccstomer1");
    billing.setCountry("BE");
    testCustomer.setBilling(billing);
    testCustomer.setStoreCode(Constants.DEFAULT_STORE);
    final HttpEntity<PersistableCustomer> entity = new HttpEntity<>(testCustomer, getHeader());
    final ResponseEntity<PersistableCustomer> response = testRestTemplate.postForEntity("/api/v1/customer/register", entity, PersistableCustomer.class);
    assertThat(response.getStatusCode(), is(OK));
    // created customer can login
    final ResponseEntity<AuthenticationResponse> loginResponse = testRestTemplate.postForEntity("/api/v1/customer/login", new HttpEntity<>(new AuthenticationRequest("customer1@test.com", "clear123")), AuthenticationResponse.class);
    assertThat(loginResponse.getStatusCode(), is(OK));
    assertNotNull(loginResponse.getBody().getToken());
}
Also used : Address(com.salesmanager.shop.model.customer.address.Address) HttpEntity(org.springframework.http.HttpEntity) PersistableCustomer(com.salesmanager.shop.model.customer.PersistableCustomer) AuthenticationRequest(com.salesmanager.shop.store.security.AuthenticationRequest) AuthenticationResponse(com.salesmanager.shop.store.security.AuthenticationResponse) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

AuthenticationRequest (com.salesmanager.shop.store.security.AuthenticationRequest)2 AuthenticationResponse (com.salesmanager.shop.store.security.AuthenticationResponse)2 PersistableCustomer (com.salesmanager.shop.model.customer.PersistableCustomer)1 Address (com.salesmanager.shop.model.customer.address.Address)1 Test (org.junit.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 HttpEntity (org.springframework.http.HttpEntity)1 HttpHeaders (org.springframework.http.HttpHeaders)1 MediaType (org.springframework.http.MediaType)1