Example usage for org.springframework.util Assert isInstanceOf

List of usage examples for org.springframework.util Assert isInstanceOf

Introduction

In this page you can find the example usage for org.springframework.util Assert isInstanceOf.

Prototype

public static void isInstanceOf(Class<?> type, @Nullable Object obj) 

Source Link

Document

Assert that the provided object is an instance of the provided class.

Usage

From source file:org.LexGrid.LexBIG.caCore.test.rest.RESTTest.java

public void testRESTHTMLWithWrongCodingSchemeAndVersionParameter() throws Exception {
    try {// ww  w.j  a va2 s. c  o m
        callRestfulService(
                "GetHTML?query=org.LexGrid.codingSchemes.CodingScheme&org.LexGrid.codingSchemes.CodingScheme&codingSchemeName="
                        + ServiceTestCase.THES_SCHEME + "&codingSchemeVersion=INVALID_VERSION");
    } catch (Exception e) {
        Assert.isInstanceOf(FileNotFoundException.class, e);
        return;
    }
    fail();
}

From source file:org.LexGrid.LexBIG.caCore.test.rest.RESTTest.java

public void testRESTHTMLWithVersionParameterWithoutCodingScheme() throws Exception {
    try {/*from  ww  w. j ava 2s.  co m*/

        callRestfulService(
                "GetHTML?query=org.LexGrid.codingSchemes.CodingScheme&org.LexGrid.codingSchemes.CodingScheme&codingSchemeVersion="
                        + ServiceTestCase.THES_VERSION);
    } catch (Exception e) {
        Assert.isInstanceOf(IOException.class, e);
        assertTrue(e.getMessage().contains("HTTP response code: 400"));
        return;
    }
    fail();
}

From source file:org.LexGrid.LexBIG.caCore.test.rest.RESTTest.java

public void testXSSAttack() throws Exception {
    try {//from   w ww  . j  av  a  2s. co  m

        callRestfulService(
                "ShowDynamicTree.action;jsessionid=F9623CBA386D7757FD29EA965EB4AE7F/?--></script><script>alert(20787)</script>");
    } catch (Exception e) {
        Assert.isInstanceOf(IOException.class, e);
        assertTrue(
                e.toString().contains("FileNotFoundException") || e.getMessage().contains("Connection reset"));
        return;
    }
    fail();
}

From source file:com.github.hateoas.forms.spring.AffordanceBuilder.java

/**
 * Copy of {@link ServletUriComponentsBuilder#getCurrentRequest()} until SPR-10110 gets fixed.
 *
 * @return request//from  w w w .j a va  2 s . c  o m
 */
private static HttpServletRequest getCurrentRequest() {

    RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
    Assert.state(requestAttributes != null, "Could not find current request via RequestContextHolder");
    Assert.isInstanceOf(ServletRequestAttributes.class, requestAttributes);
    HttpServletRequest servletRequest = ((ServletRequestAttributes) requestAttributes).getRequest();
    Assert.state(servletRequest != null, "Could not find current HttpServletRequest");
    return servletRequest;
}

From source file:de.escalon.hypermedia.spring.AffordanceBuilderFactory.java

@Override
public AffordanceBuilder linkTo(Object invocationValue) {

    Assert.isInstanceOf(DummyInvocationUtils.LastInvocationAware.class, invocationValue);
    DummyInvocationUtils.LastInvocationAware invocations = (DummyInvocationUtils.LastInvocationAware) invocationValue;

    DummyInvocationUtils.MethodInvocation invocation = invocations.getLastInvocation();
    Method invokedMethod = invocation.getMethod();

    String pathMapping = MAPPING_DISCOVERER.getMapping(invokedMethod);

    List<String> params = getRequestParamNames(invokedMethod);
    String query = StringUtils.join(params, ',');
    String mapping = StringUtils.isBlank(query) ? pathMapping : pathMapping + "{?" + query + "}";

    PartialUriTemplate partialUriTemplate = new PartialUriTemplate(
            AffordanceBuilder.getBuilder().build().toString() + mapping);

    Iterator<Object> classMappingParameters = invocations.getObjectParameters();

    Map<String, Object> values = new HashMap<String, Object>();
    Iterator<String> names = partialUriTemplate.getVariableNames().iterator();
    while (classMappingParameters.hasNext()) {
        values.put(names.next(), classMappingParameters.next());
    }//ww w  .  java  2  s .  co  m

    for (Object argument : invocation.getArguments()) {
        if (names.hasNext()) {
            values.put(names.next(), argument);
        }
    }

    ActionDescriptor actionDescriptor = createActionDescriptor(invocation.getMethod(), values,
            invocation.getArguments());

    return new AffordanceBuilder(partialUriTemplate.expand(values),
            Collections.singletonList(actionDescriptor));

}

From source file:nl.ivo2u.tiny.controller.TinyRestController.java

private static HttpServletRequest getCurrentRequest() {
    final RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
    Assert.state(requestAttributes != null, "Could not find current request via RequestContextHolder");
    Assert.isInstanceOf(ServletRequestAttributes.class, requestAttributes);
    final HttpServletRequest servletRequest = ((ServletRequestAttributes) requestAttributes).getRequest();
    Assert.state(servletRequest != null, "Could not find current HttpServletRequest");
    return servletRequest;
}

From source file:org.acegisecurity.ui.switchuser.SwitchUserProcessingFilter.java

/**
 *
 * @see javax.servlet.Filter#doFilter/*from   w ww  .  j av  a 2s .  c o m*/
 */
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    Assert.isInstanceOf(HttpServletRequest.class, request);
    Assert.isInstanceOf(HttpServletResponse.class, response);

    HttpServletRequest httpRequest = (HttpServletRequest) request;
    HttpServletResponse httpResponse = (HttpServletResponse) response;

    // check for switch or exit request
    if (requiresSwitchUser(httpRequest)) {
        // if set, attempt switch and store original
        Authentication targetUser = attemptSwitchUser(httpRequest);

        // update the current context to the new target user
        SecurityContextHolder.getContext().setAuthentication(targetUser);

        // redirect to target url
        httpResponse.sendRedirect(httpResponse.encodeRedirectURL(httpRequest.getContextPath() + targetUrl));

        return;
    } else if (requiresExitUser(httpRequest)) {
        // get the original authentication object (if exists)
        Authentication originalUser = attemptExitUser(httpRequest);

        // update the current context back to the original user
        SecurityContextHolder.getContext().setAuthentication(originalUser);

        // redirect to target url
        httpResponse.sendRedirect(httpResponse.encodeRedirectURL(httpRequest.getContextPath() + targetUrl));

        return;
    }

    chain.doFilter(request, response);
}

From source file:org.apache.camel.dataformat.bindy.csv.BindySimpleCsvMandatoryFieldsUnmarshallTest.java

@DirtiesContext
@Test/*from w  w w  .j av  a  2  s.  c om*/
public void testEmptyRecord() throws Exception {

    String record1 = ""; // empty records

    resultEndpoint1.expectedMessageCount(0);

    try {
        template1.sendBody(record1);
        fail("Should have thrown an exception");
    } catch (CamelExecutionException e) {
        Assert.isInstanceOf(Exception.class, e.getCause());
        // LOG.info(">> Error : " + e);
    }

    resultEndpoint1.assertIsSatisfied();
}

From source file:org.apache.camel.dataformat.bindy.csv.BindySimpleCsvMandatoryFieldsUnmarshallTest.java

@DirtiesContext
@Test//  www. jav  a 2 s .c  o m
public void testTooMuchFields() throws Exception {

    String record6 = ",,,,,,,,,,,,,,"; // too much data in the record (only
    // 11 are accepted by the model

    resultEndpoint1.expectedMessageCount(0);

    try {
        template1.sendBody(record6);
        fail("Should have thrown an exception");
    } catch (CamelExecutionException e) {
        // expected
        Assert.isInstanceOf(IllegalArgumentException.class, e.getCause());
    }

    resultEndpoint1.assertIsSatisfied();
}

From source file:org.apache.servicecomb.demo.springmvc.server.CodeFirstSpringmvc.java

@PostMapping(path = "/holderUser")
public Holder<User> testHolderUser(@RequestBody Holder<User> input) {
    Assert.isInstanceOf(Holder.class, input);
    Assert.isInstanceOf(User.class, input.value);
    return input;
}