Search in sources :

Example 1 with Contact

use of org.jboss.quickstarts.contact.Contact in project quickstart by wildfly.

the class ContactRegistrationIT method testInvalidRegister.

@SuppressWarnings("unchecked")
@Test
@InSequence(2)
public void testInvalidRegister() throws Exception {
    Contact contact = createContactInstance("", "", "", "", date);
    Response response = contactRESTService.createContact(contact);
    assertEquals("Unexpected response status", 400, response.getStatus());
    assertNotNull("response.getEntity() should not be null", response.getEntity());
    assertEquals("Unexpected response.getEntity(). It contains " + response.getEntity(), 3, ((Map<String, String>) response.getEntity()).size());
    log.info("Invalid contact register attempt failed with return code " + response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) Contact(org.jboss.quickstarts.contact.Contact) Test(org.junit.Test) InSequence(org.jboss.arquillian.junit.InSequence)

Example 2 with Contact

use of org.jboss.quickstarts.contact.Contact in project quickstart by wildfly.

the class ContactRegistrationIT method shouldCreateAndDeleteAContact.

@Test
@RunAsClient
@InSequence(6)
public void shouldCreateAndDeleteAContact(@ArquillianResource URL contextPath) throws JAXBException {
    Contact contact = createContactInstance("Jason", "Smith", "jason@mailinator.com", "2125551234", date);
    // POSTs a Contact
    Client client = ClientBuilder.newClient();
    URI uri = UriBuilder.fromUri(contextPath + REST_ROOT).port(8080).build();
    Response response = client.target(uri).request().post(Entity.entity(contact, MediaType.APPLICATION_JSON));
    assertEquals(Response.Status.CREATED, response.getStatusInfo());
    URI contactURI = response.getLocation();
    // With the location, GETs the Contact
    client.close();
    client = ClientBuilder.newClient();
    response = client.target(contactURI).request().get();
    contact = response.readEntity(Contact.class);
    assertEquals(Response.Status.OK, response.getStatusInfo());
    assertEquals("Jason", contact.getFirstName());
    // GETs the Contact ID and DELETEs it
    String contactID = contactURI.toString().split("/")[6];
    response = client.target(uri).path(contactID).request().delete();
    assertEquals(Response.Status.NO_CONTENT, response.getStatusInfo());
    // GETs the Contact and checks if it has been deleted
    client.close();
    client = ClientBuilder.newClient();
    response = client.target(uri).path(contactID).request().get();
    assertEquals(Response.Status.NOT_FOUND, response.getStatusInfo());
    client.close();
}
Also used : Response(javax.ws.rs.core.Response) Client(javax.ws.rs.client.Client) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) URI(java.net.URI) Contact(org.jboss.quickstarts.contact.Contact) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) Test(org.junit.Test) InSequence(org.jboss.arquillian.junit.InSequence)

Example 3 with Contact

use of org.jboss.quickstarts.contact.Contact in project quickstart by wildfly.

the class ContactRegistrationIT method createContactInstance.

private Contact createContactInstance(String firstName, String lastName, String email, String phone, Date birthDate) {
    Contact contact = new Contact();
    contact.setFirstName(firstName);
    contact.setLastName(lastName);
    contact.setEmail(email);
    contact.setPhoneNumber(phone);
    contact.setBirthDate(birthDate);
    return contact;
}
Also used : Contact(org.jboss.quickstarts.contact.Contact)

Example 4 with Contact

use of org.jboss.quickstarts.contact.Contact in project quickstart by wildfly.

the class ContactRegistrationIT method testRegister.

@Test
@InSequence(1)
public void testRegister() throws Exception {
    Contact contact = createContactInstance("Jack", "Doe", "jack@mailinator.com", "2125551234", date);
    Response response = contactRESTService.createContact(contact);
    assertEquals("Unexpected response status", 201, response.getStatus());
    log.info(" New contact was persisted and returned status " + response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) Contact(org.jboss.quickstarts.contact.Contact) Test(org.junit.Test) InSequence(org.jboss.arquillian.junit.InSequence)

Example 5 with Contact

use of org.jboss.quickstarts.contact.Contact in project quickstart by wildfly.

the class ContactRegistrationIT method testDuplicateEmail.

@SuppressWarnings("unchecked")
@Test
@InSequence(3)
public void testDuplicateEmail() throws Exception {
    // Register an initial user
    Contact contact = createContactInstance("Jane", "Doe", "jane@mailinator.com", "2125551234", date);
    contactRESTService.createContact(contact);
    // Register a different user with the same email
    Contact anotherContact = createContactInstance("John", "Doe", "jane@mailinator.com", "2133551234", date);
    Response response = contactRESTService.createContact(anotherContact);
    assertEquals("Unexpected response status", 409, response.getStatus());
    assertNotNull("response.getEntity() should not be null", response.getEntity());
    assertEquals("Unexpected response.getEntity(). It contains" + response.getEntity(), 1, ((Map<String, String>) response.getEntity()).size());
    log.info("Duplicate contact register attempt failed with return code " + response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) Contact(org.jboss.quickstarts.contact.Contact) Test(org.junit.Test) InSequence(org.jboss.arquillian.junit.InSequence)

Aggregations

Contact (org.jboss.quickstarts.contact.Contact)5 Response (javax.ws.rs.core.Response)4 InSequence (org.jboss.arquillian.junit.InSequence)4 Test (org.junit.Test)4 URI (java.net.URI)1 Client (javax.ws.rs.client.Client)1 RunAsClient (org.jboss.arquillian.container.test.api.RunAsClient)1