Skip to content
Permalink
Browse files
Adding few more tests to JSONProviderTest
git-svn-id: https://svn.apache.org/repos/asf/cxf/trunk@1569056 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Sergey Beryozkin committed Feb 17, 2014
1 parent 14a29e1 commit 951584f43eed901a4425461c673ae5dba677c1f8
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
@@ -73,6 +73,7 @@
import org.apache.cxf.jaxrs.resources.TagVO2;
import org.apache.cxf.jaxrs.resources.Tags;
import org.apache.cxf.jaxrs.resources.jaxb.Book2;
import org.apache.cxf.jaxrs.resources.jaxb.Book2NoRootElement;
import org.apache.cxf.staxutils.DelegatingXMLStreamWriter;
import org.apache.cxf.staxutils.StaxUtils;

@@ -507,6 +508,40 @@ public void testWriteToSingleTag2NoNs() throws Exception {

}

@Test
public void testIgnoreNamespacesPackageInfo() throws Exception {
JSONProvider<Book2> p = new JSONProvider<Book2>();
p.setIgnoreNamespaces(true);
Book2 book = new Book2(123);
book.setName("CXF");

ByteArrayOutputStream os = new ByteArrayOutputStream();

p.writeTo(book, Book2.class, Book2.class, Book2.class.getAnnotations(),
MediaType.APPLICATION_JSON_TYPE, new MetadataMap<String, Object>(), os);

String s = os.toString();
assertEquals("{\"thebook2\":{\"id\":123,\"name\":\"CXF\"}}", s);

}

@Test
public void testIgnoreNamespacesPackageInfo2() throws Exception {
JSONProvider<Book2NoRootElement> p = new JSONProvider<Book2NoRootElement>();
p.setMarshallAsJaxbElement(true);
p.setIgnoreNamespaces(true);
Book2NoRootElement book = new Book2NoRootElement(123);
ByteArrayOutputStream os = new ByteArrayOutputStream();

p.writeTo(book, Book2NoRootElement.class, Book2NoRootElement.class,
Book2NoRootElement.class.getAnnotations(),
MediaType.APPLICATION_JSON_TYPE, new MetadataMap<String, Object>(), os);

String s = os.toString();
assertEquals("{\"book2\":{\"id\":123}}", s);

}

@Test
public void testCopyReaderToDocument() throws Exception {
String s = "{\"tagVO\":{\"group\":\"b\",\"name\":\"a\"}}";
@@ -0,0 +1,42 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.cxf.jaxrs.resources.jaxb;

import javax.xml.bind.annotation.XmlType;

@XmlType(name = "book2")
public class Book2NoRootElement {

private int id;

public Book2NoRootElement() {
}

public Book2NoRootElement(int id) {
this.id = id;
}

public int getId() {
return id;
}

public void setId(int ident) {
id = ident;
}
}

0 comments on commit 951584f

Please sign in to comment.