Package br.com.caelum.vraptor.util.test

Examples of br.com.caelum.vraptor.util.test.MockSerializationResult


  public void shouldSerializeErrorMessages() throws Exception {
    Message normal = new ValidationMessage("The message", "category");
    I18nMessage i18ned = new I18nMessage("category", "message");
    i18ned.setBundle(new SingletonResourceBundle("message", "Something else"));
   
    MockSerializationResult result = new MockSerializationResult(XStreamBuilderImpl.cleanInstance(new MessageConverter()));
    DefaultStatus status = new DefaultStatus(response, result, config, new JavassistProxifier(new ObjenesisInstanceCreator()), router);
   
    status.badRequest(Lists.newArrayList(normal, i18ned));
   
    String serialized = result.serializedResult();
    assertThat(serialized, containsString("<message>The message</message>"));
    assertThat(serialized, containsString("<category>category</category>"));
    assertThat(serialized, containsString("<message>Something else</message>"));
    assertThat(serialized, not(containsString("<validationMessage>")));
    assertThat(serialized, not(containsString("<i18nMessage>")));
View Full Code Here


  public void shouldSerializeErrorMessagesInJSON() throws Exception {
    Message normal = new ValidationMessage("The message", "category");
    I18nMessage i18ned = new I18nMessage("category", "message");
    i18ned.setBundle(new SingletonResourceBundle("message", "Something else"));

    MockSerializationResult result = new MockSerializationResult(XStreamBuilderImpl.cleanInstance(new MessageConverter())) {
      @Override
      public <T extends View> T use(Class<T> view) {
        return view.cast(new DefaultRepresentationResult(new FormatResolver() {
          public String getAcceptFormat() {
            return "json";
          }
         
        }, this, Arrays.<Serialization>asList(super.use(JSONSerialization.class)), null));
      }
    };
    DefaultStatus status = new DefaultStatus(response, result, config, new JavassistProxifier(new ObjenesisInstanceCreator()), router);
   
    status.badRequest(Lists.newArrayList(normal, i18ned));
   
    String serialized = result.serializedResult();
    assertThat(serialized, containsString("\"message\": \"The message\""));
    assertThat(serialized, containsString("\"category\": \"category\""));
    assertThat(serialized, containsString("\"message\": \"Something else\""));
    assertThat(serialized, not(containsString("\"validationMessage\"")));
    assertThat(serialized, not(containsString("\"i18nMessage\"")));
View Full Code Here

    Message normal = new SimpleMessage("category", "The message");
    I18nMessage i18ned = new I18nMessage("category", "message");
    i18ned.setBundle(new SingletonResourceBundle("message", "Something else"));

    XStreamBuilder xstreamBuilder = cleanInstance(new MessageConverter());
    MockSerializationResult result = new MockSerializationResult(null, xstreamBuilder, null, null);
    DefaultStatus status = new DefaultStatus(response, result, config, new JavassistProxifier(), router);

    status.badRequest(Arrays.asList(normal, i18ned));

    String serialized = result.serializedResult();
    assertThat(serialized, containsString("<message>The message</message>"));
    assertThat(serialized, containsString("<category>category</category>"));
    assertThat(serialized, containsString("<message>Something else</message>"));
    assertThat(serialized, not(containsString("<validationMessage>")));
    assertThat(serialized, not(containsString("<i18nMessage>")));
View Full Code Here

    List<JsonSerializer<?>> gsonSerializers = new ArrayList<>();
    List<JsonDeserializer<?>> gsonDeserializers = new ArrayList<>();
    gsonSerializers.add(new MessageGsonConverter());

    GsonSerializerBuilder gsonBuilder = new GsonBuilderWrapper(new MockInstanceImpl<>(gsonSerializers), new MockInstanceImpl<>(gsonDeserializers), new Serializee());
    MockSerializationResult result = new MockSerializationResult(null, null, gsonBuilder) {
      @Override
      public <T extends View> T use(Class<T> view) {
        return view.cast(new DefaultRepresentationResult(new FormatResolver() {
          @Override
          public String getAcceptFormat() {
            return "json";
          }

        }, this, new MockInstanceImpl<Serialization>(super.use(JSONSerialization.class))));
      }
    };
    DefaultStatus status = new DefaultStatus(response, result, config, new JavassistProxifier(), router);

    status.badRequest(Arrays.asList(normal, i18ned));

    String serialized = result.serializedResult();
    assertThat(serialized, containsString("\"message\":\"The message\""));
    assertThat(serialized, containsString("\"category\":\"category\""));
    assertThat(serialized, containsString("\"message\":\"Something else\""));
    assertThat(serialized, not(containsString("\"validationMessage\"")));
    assertThat(serialized, not(containsString("\"i18nMessage\"")));
View Full Code Here

 
  @Before
  public void setUp() {
    MockitoAnnotations.initMocks(this);

    result = new MockSerializationResult();
    validator = new MockValidator();
    controller = new MusicController(dao, userInfo, result, validator, musics, userDao);
   
    music = new MusicBuilder().withId(1L).withType(MusicType.ROCK).withTitle("Some Music").withDescription("Some description").build();
    user = new UserBuilder().withName("Renan").withLogin("renanigt").withPassword("1234").build();
View Full Code Here

TOP

Related Classes of br.com.caelum.vraptor.util.test.MockSerializationResult

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.