Package br.gov.frameworkdemoiselle

Examples of br.gov.frameworkdemoiselle.HttpViolationException$Violation


  public void insertFailed() throws Exception {
    HttpPost request;
    CloseableHttpResponse response;
    Bookmark bookmark;
    Set<UnprocessableEntityException.Violation> violations;
    HttpViolationException expected;

    bookmark = new Bookmark();
    bookmark.setDescription("Google");
    bookmark.setLink("http://google.com");
    request = new HttpPost(url + "/bookmark");
    request.setEntity(createEntity(bookmark));
    request.addHeader("Content-Type", "application/json");
    response = client.execute(request);
    response.close();
    assertEquals(SC_UNAUTHORIZED, response.getStatusLine().getStatusCode());

    bookmark = new Bookmark();
    request = new HttpPost(url + "/bookmark");
    request.setEntity(createEntity(bookmark));
    request.addHeader("Content-Type", "application/json");
    request.addHeader("Authorization", BASIC_CREDENTIALS);
    response = client.execute(request);
    response.close();
    assertEquals(SC_PRECONDITION_FAILED, response.getStatusLine().getStatusCode());
    violations = mapper.readValue(response.getEntity().getContent(),
        new TypeReference<Set<UnprocessableEntityException.Violation>>() {
        });
    expected = new UnprocessableEntityException();
    expected.addViolation("description", "não pode ser nulo");
    expected.addViolation("link", "não pode ser nulo");
    assertEquals(expected.getViolations(), violations);

    bookmark = new Bookmark();
    bookmark.setDescription("Google");
    bookmark.setLink("http: // google . com");
    request = new HttpPost(url + "/bookmark");
    request.setEntity(createEntity(bookmark));
    request.addHeader("Content-Type", "application/json");
    request.addHeader("Authorization", BASIC_CREDENTIALS);
    response = client.execute(request);
    response.close();
    assertEquals(SC_PRECONDITION_FAILED, response.getStatusLine().getStatusCode());
    violations = mapper.readValue(response.getEntity().getContent(),
        new TypeReference<Set<UnprocessableEntityException.Violation>>() {
        });
    expected = new UnprocessableEntityException().addViolation("link", "formato inválido");
    assertEquals(expected.getViolations(), violations);

    bookmark = new Bookmark();
    bookmark.setId(Long.valueOf(123456789));
    bookmark.setDescription("Test");
    bookmark.setLink("http://test.com");
View Full Code Here


    CloseableHttpResponse response = createSample();
    response.close();
    Long id = parseEntity(response.getEntity(), Long.class);
    Bookmark bookmark;
    Set<UnprocessableEntityException.Violation> violations;
    HttpViolationException expected;

    bookmark = new Bookmark();
    bookmark.setDescription("Google");
    bookmark.setLink("http://google.com");
    request = new HttpPut(url + "/bookmark/" + id);
    request.setEntity(createEntity(bookmark));
    request.addHeader("Content-Type", "application/json");
    response = client.execute(request);
    response.close();
    assertEquals(SC_UNAUTHORIZED, response.getStatusLine().getStatusCode());

    bookmark = new Bookmark();
    request = new HttpPut(url + "/bookmark/" + id);
    request.setEntity(createEntity(bookmark));
    request.addHeader("Content-Type", "application/json");
    request.addHeader("Authorization", BASIC_CREDENTIALS);
    response = client.execute(request);
    response.close();
    assertEquals(SC_PRECONDITION_FAILED, response.getStatusLine().getStatusCode());
    violations = mapper.readValue(response.getEntity().getContent(),
        new TypeReference<Set<UnprocessableEntityException.Violation>>() {
        });
    expected = new UnprocessableEntityException();
    expected.addViolation("description", "não pode ser nulo");
    expected.addViolation("link", "não pode ser nulo");
    assertEquals(expected.getViolations(), violations);

    bookmark = new Bookmark();
    bookmark.setDescription("Google");
    bookmark.setLink("http: // google . com");
    request = new HttpPut(url + "/bookmark/" + id);
    request.setEntity(createEntity(bookmark));
    request.addHeader("Content-Type", "application/json");
    request.addHeader("Authorization", BASIC_CREDENTIALS);
    response = client.execute(request);
    response.close();
    assertEquals(SC_PRECONDITION_FAILED, response.getStatusLine().getStatusCode());
    violations = mapper.readValue(response.getEntity().getContent(),
        new TypeReference<Set<UnprocessableEntityException.Violation>>() {
        });
    expected = new UnprocessableEntityException().addViolation("link", "formato inválido");
    assertEquals(expected.getViolations(), violations);

    bookmark = new Bookmark();
    bookmark.setId(Long.valueOf(123456789));
    bookmark.setDescription("Test");
    bookmark.setLink("http://test.com");
View Full Code Here

TOP

Related Classes of br.gov.frameworkdemoiselle.HttpViolationException$Violation

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.