Package org.candlepin.common.exceptions

Examples of org.candlepin.common.exceptions.ExceptionMessage


    @Test
    public void candlepinException() {
        CandlepinException ce = mock(CandlepinException.class);
        when(ce.httpReturnCode()).thenReturn(Status.CONFLICT);
        ExceptionMessage em = new ExceptionMessage().setDisplayMessage("you screwed up");
        when(ce.message()).thenReturn(em);
        when(req.getHeader(HttpHeaderNames.ACCEPT)).thenReturn("application/json");

        assertEquals("you screwed up", em.toString());
        Response r = rem.toResponse(ce);
        assertNotNull(r);
        assertEquals(Status.CONFLICT.getStatusCode(), r.getStatus());
        verifyMessage(r, "you screwed up");
    }
View Full Code Here


    @Test
    public void candlepinExceptionWithChildNotCandleping() {
        CandlepinException ce = mock(CandlepinException.class);
        when(ce.httpReturnCode()).thenReturn(Status.CONFLICT);
        when(ce.message()).thenReturn(
            new ExceptionMessage().setDisplayMessage("you screwed up"));
        when(req.getHeader(HttpHeaderNames.ACCEPT)).thenReturn("application/json");
        when(ce.getCause()).thenReturn(new ConflictException("you screwed up"));
        Response r = rem.toResponse(ce);
        assertNotNull(r);
        assertEquals(Status.CONFLICT.getStatusCode(), r.getStatus());
View Full Code Here

        }

        Map<String, String> map = VersionUtil.getVersionMap();

        return Response.status(status)
            .entity(new ExceptionMessage(message))
            .type(responseMediaType)
            .header(VersionUtil.VERSION_HEADER,
                map.get("version") + "-" + map.get("release"));
    }
View Full Code Here

        if (cause instanceof CandlepinParamterParseException) {
            String msg = i18n.get().tr("Invalid format for query parameter {0}. " +
                "Expected format: {1}",
                ((CandlepinParamterParseException) cause).getParamName(),
                ((CandlepinParamterParseException) cause).getExpectedFormat());
            bldr.entity(new ExceptionMessage(msg));
        }
        else {
            String msg = exception.getMessage();
            if (StringUtils.isNotEmpty(msg)) {
                bldr.entity(new ExceptionMessage(extractIllegalValue(msg)));
            }
        }
        return bldr.build();
    }
View Full Code Here

                ((ConstraintViolationException) exception).getConstraintViolations()) {
                message.append(cv.getPropertyPath().toString());
                message.append(": ");
                message.append(cv.getMessage());
            }
            bldr.entity(new ExceptionMessage(message.toString()));
        }
        else {
            getDefaultBuilder(exception, Response.Status.BAD_REQUEST, determineBestMediaType());
        }
        return bldr.build();
View Full Code Here

        IOException ioe = new IOException("fake io exception");
        RuntimeException re = new RuntimeException("oops", ioe);
        ResponseBuilder bldr = cem.getDefaultBuilder(re, null,
            MediaType.APPLICATION_ATOM_XML_TYPE);
        Response r = bldr.build();
        ExceptionMessage em = (ExceptionMessage) r.getEntity();

        assertEquals(Status.INTERNAL_SERVER_ERROR.getStatusCode(), r.getStatus());
        assertEquals(MediaType.APPLICATION_ATOM_XML_TYPE,
            r.getMetadata().get("Content-Type").get(0));
        assertTrue(em.getDisplayMessage().startsWith("Runtime Error " + re.getMessage()));
    }
View Full Code Here

        // simulate Java 7 on a Java 6 vm
        when(nostack.getStackTrace()).thenReturn(null);

        Response r = cem.getDefaultBuilder(nostack, null,
            MediaType.APPLICATION_JSON_TYPE).build();
        ExceptionMessage em = (ExceptionMessage) r.getEntity();

        assertEquals(Status.INTERNAL_SERVER_ERROR.getStatusCode(), r.getStatus());
        assertEquals("Runtime Error no stack trace", em.getDisplayMessage());
        assertEquals(MediaType.APPLICATION_JSON_TYPE,
            r.getMetadata().get("Content-Type").get(0));
    }
View Full Code Here

    protected String rtmsg(String msg) {
        return "Runtime Error " + msg;
    }

    protected void verifyMessage(Response r, String expectedmsg) {
        ExceptionMessage em = (ExceptionMessage) r.getEntity();

        assertNotNull(em);
        assertTrue(expectedmsg,
            em.getDisplayMessage().startsWith(expectedmsg));
    }
View Full Code Here

TOP

Related Classes of org.candlepin.common.exceptions.ExceptionMessage

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.