Java 类io.dropwizard.validation.Validated 实例源码

项目:dropwizard-xml    文件:JacksonXMLMessageBodyProviderTest.java   
@Test
public void returnsPartialValidatedRequestEntities() throws Exception {
    final Validated valid = Mockito.mock(Validated.class);
    Mockito.doReturn(Validated.class).when(valid).annotationType();
    Mockito.when(valid.value()).thenReturn(new Class[] {Partial1.class, Partial2.class});

    final ByteArrayInputStream entity =
            new ByteArrayInputStream("<PartialExample xmlns=\"\"><id>1</id><text>hello Cemo</text></PartialExample>".getBytes());
    final Class<?> klass = PartialExample.class;

    final Object obj = provider.readFrom((Class<Object>) klass,
            PartialExample.class,
            new Annotation[] {valid},
            MediaType.APPLICATION_XML_TYPE,
            new MultivaluedHashMap<>(),
            entity);

    assertThat(obj)
            .isInstanceOf(PartialExample.class);

    assertThat(((PartialExample) obj).id)
            .isEqualTo(1);
}
项目:dropwizard-xml    文件:JacksonXMLMessageBodyProviderTest.java   
@Test
public void returnsPartialValidatedByGroupRequestEntities() throws Exception {
    final Validated valid = Mockito.mock(Validated.class);
    Mockito.doReturn(Validated.class).when(valid).annotationType();
    Mockito.when(valid.value()).thenReturn(new Class[] {Partial1.class});

    final ByteArrayInputStream entity = new ByteArrayInputStream("<Example xmlns=\"\"><id>1</id></Example>".getBytes());
    final Class<?> klass = PartialExample.class;

    final Object obj = provider.readFrom((Class<Object>) klass,
            PartialExample.class,
            new Annotation[] {valid},
            MediaType.APPLICATION_XML_TYPE,
            new MultivaluedHashMap<>(),
            entity);

    assertThat(obj)
            .isInstanceOf(PartialExample.class);

    assertThat(((PartialExample) obj).id)
            .isEqualTo(1);
}
项目:dropwizard-xml    文件:JacksonXMLMessageBodyProviderTest.java   
@Test
public void throwsAnInvalidEntityExceptionForPartialValidatedRequestEntities() throws Exception {
    final Validated valid = Mockito.mock(Validated.class);
    Mockito.doReturn(Validated.class).when(valid).annotationType();
    Mockito.when(valid.value()).thenReturn(new Class[] {Partial1.class, Partial2.class});

    final ByteArrayInputStream entity = new ByteArrayInputStream("<Example xmlns=\"\"><id>1</id></Example>".getBytes());

    try {
        final Class<?> klass = PartialExample.class;
        provider.readFrom((Class<Object>) klass,
                PartialExample.class,
                new Annotation[] {valid},
                MediaType.APPLICATION_XML_TYPE,
                new MultivaluedHashMap<>(),
                entity);
        failBecauseExceptionWasNotThrown(ConstraintViolationException.class);
    } catch (ConstraintViolationException e) {
        assertThat(ConstraintViolations.formatUntyped(e.getConstraintViolations()))
                .containsOnly("text may not be null");
    }
}
项目:dust-api    文件:DeviceResource.java   
@PUT
@Path("/{id:\\d+}")
public Device update(
        @PathParam("id") final Long id,
        @Validated(Validations.Update.class) final Device device
) {
    return deviceRepo.update(device);
}
项目:dust-api    文件:UserResource.java   
@PUT
@Path("/{id}")
public User updateUser(
        @PathParam("id") final long id,
        @Validated(Validations.Update.class) final User user
) {
    return userRepo.update(user);
}
项目:dust-api    文件:ClaimResource.java   
@PUT
@Path("/{id}")
public Claim update(
        @PathParam("id") final Long id,
        @Validated(Validations.Update.class) final Claim claim
) {
    return claimRepo.update(claim);
}
项目:dropwizard-jaxb    文件:JaxbXMLValidatingMessageBodyProvider.java   
private Class<?>[] findValidationGroups(Annotation[] annotations) {
  for (Annotation annotation : annotations) {
    if (annotation.annotationType() == Valid.class) {
      return DEFAULT_GROUP_ARRAY;
    } else if (annotation.annotationType() == Validated.class) {
      return ((Validated) annotation).value();
    }
  }
  return null;
}
项目:dropwizard-xml    文件:JacksonXMLMessageBodyProvider.java   
private Class<?>[] findValidationGroups(Annotation[] annotations) {
    for (Annotation annotation : annotations) {
        if (annotation.annotationType() == Valid.class) {
            return DEFAULT_GROUP_ARRAY;
        } else if (annotation.annotationType() == Validated.class) {
            return  ((Validated) annotation).value();
        }
    }
    return null;
}
项目:dropwizard-jaxws    文件:ValidatingInvoker.java   
/**
 * Copied from com.yammer.dropwizard.jersey.jackson.JacksonMessageBodyProvider#findValidationGroups()
 */
private Class<?>[] findValidationGroups(Annotation[] annotations) {
    for (Annotation annotation : annotations) {
        if (annotation.annotationType() == Valid.class) {
            return DEFAULT_GROUP_ARRAY;
        } else if (annotation.annotationType() == Validated.class) {
            return  ((Validated) annotation).value();
        }
    }
    return null;
}
项目:dust-api    文件:DeviceResource.java   
@POST
public Device create(@Validated(Validations.Create.class) final Device device) {
    return deviceRepo.create(device);
}
项目:dust-api    文件:UserResource.java   
@POST
public User createUser(@Validated(Validations.Create.class) final User device) {
    return userRepo.create(device);
}
项目:dust-api    文件:ClaimResource.java   
@POST
public Claim create(@Validated(Validations.Create.class) final Claim claim) {
    return claimRepo.create(claim);
}
项目:dropwizard-jaxws    文件:ValidatingInvokerTest.java   
public void withDropwizardValidation(@Validated() String foo) {
}