Java Code Examples for org.simpleframework.xml.Serializer#validate()

The following examples show how to use org.simpleframework.xml.Serializer#validate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MixTest.java    From simplexml with Apache License 2.0 5 votes vote down vote up
public void testMix() throws Exception {
   Serializer serializer = new Persister();
   MixExample example = new MixExample();
   StringWriter source = new StringWriter();
   
   example.setTime(new Date());
  // example.add("text");
  // example.add(1);
  // example.add(true);
  // example.add(new Entry("1", "example 1"));
  // example.add(new Entry("2", "example 2"));
  // example.put(new Entry("1", "key 1"), new Entry("1", "value 1"));
  // example.put("key 2", "value 2");
  // example.put("key 3", 3);
  // example.put("key 4", new Entry("4", "value 4"));
   
   serializer.write(example, System.out);
   serializer.write(example, source);   
   serializer.validate(MixExample.class, source.toString());
   
   MixExample other = serializer.read(MixExample.class, source.toString());
   
   serializer.write(other, System.out);
   
  // assertEquals(example.get(0), "text");
  // assertEquals(example.get(1), 1);      
  // assertEquals(example.get(2), true);
   
   validate(example, serializer);
}
 
Example 2
Source File: ValidateTest.java    From simplexml with Apache License 2.0 5 votes vote down vote up
public void testVersionMissing() throws Exception {
   Serializer persister = new Persister();
   boolean success = false;
   
   try {
      success = persister.validate(TextList.class, VERSION_MISSING);
   } catch(Exception e) {
      e.printStackTrace();
      success = true;
   }
   assertTrue(success);
}
 
Example 3
Source File: ValidateTest.java    From simplexml with Apache License 2.0 5 votes vote down vote up
public void testNameMissing() throws Exception {
   Serializer persister = new Persister();
   boolean success = false;
   
   try {
      success = persister.validate(TextList.class, NAME_MISSING);
   } catch(Exception e) {
      e.printStackTrace();
      success = true;
   }
   assertTrue(success);
}
 
Example 4
Source File: ValidateTest.java    From simplexml with Apache License 2.0 5 votes vote down vote up
public void testTextMissing() throws Exception {
   Serializer persister = new Persister();
   boolean success = false;
   
   try {
      success = persister.validate(TextList.class, TEXT_MISSING);
   } catch(Exception e) {
      e.printStackTrace();
      success = true;
   }
   assertTrue(success);
}
 
Example 5
Source File: ValidateTest.java    From simplexml with Apache License 2.0 5 votes vote down vote up
public void testExtraElement() throws Exception {
   Serializer persister = new Persister();
   boolean success = false;
   
   try {
      success = persister.validate(TextList.class, EXTRA_ELEMENT);
   } catch(Exception e) {
      e.printStackTrace();
      success = true;
   }
   assertTrue(success);
}
 
Example 6
Source File: MapNullTest.java    From simplexml with Apache License 2.0 5 votes vote down vote up
public void testEmptyCompositeValue() throws Exception {
   Serializer serializer = new Persister();
   ComplexMap value = serializer.read(ComplexMap.class, EMPTY_COMPOSITE_VALUE);
   boolean valid = serializer.validate(ComplexMap.class, EMPTY_COMPOSITE_VALUE);
   
   assertTrue(valid);
   
   validate(value, serializer);
}
 
Example 7
Source File: MapNullTest.java    From simplexml with Apache License 2.0 5 votes vote down vote up
public void testEmptyCompositeBlankValue() throws Exception {
   Serializer serializer = new Persister();
   ComplexMap value = serializer.read(ComplexMap.class, EMPTY_COMPOSITE_BLANK_VALUE);
   boolean valid = serializer.validate(ComplexMap.class, EMPTY_COMPOSITE_BLANK_VALUE);
   
   assertTrue(valid);
   
   validate(value, serializer);
}
 
Example 8
Source File: MapNullTest.java    From simplexml with Apache License 2.0 5 votes vote down vote up
public void testEmptyCompositeKey() throws Exception {
   Serializer serializer = new Persister();
   ComplexMap value = serializer.read(ComplexMap.class, EMPTY_COMPOSITE_KEY);
   boolean valid = serializer.validate(ComplexMap.class, EMPTY_COMPOSITE_KEY);
   
   assertTrue(valid);
   
   validate(value, serializer);      
}
 
Example 9
Source File: MapNullTest.java    From simplexml with Apache License 2.0 5 votes vote down vote up
public void testEmptyCompositeBlankKey() throws Exception {
   Serializer serializer = new Persister();
   ComplexMap value = serializer.read(ComplexMap.class, EMPTY_COMPOSITE_BLANK_KEY);     
   boolean valid = serializer.validate(ComplexMap.class, EMPTY_COMPOSITE_BLANK_KEY);
   
   assertTrue(valid);
   
   validate(value, serializer);      
}
 
Example 10
Source File: MapNullTest.java    From simplexml with Apache License 2.0 5 votes vote down vote up
public void testEmptyPrimitiveValue() throws Exception {
   Serializer serializer = new Persister();
   PrimitiveMap value = serializer.read(PrimitiveMap.class, EMPTY_PRIMITIVE_VALUE);     
   boolean valid = serializer.validate(PrimitiveMap.class, EMPTY_PRIMITIVE_VALUE);
   
   assertTrue(valid);
   
   validate(value, serializer);      
}
 
Example 11
Source File: MapNullTest.java    From simplexml with Apache License 2.0 5 votes vote down vote up
public void testEmptyPrimitiveBlankValue() throws Exception {
   Serializer serializer = new Persister();
   PrimitiveMap value = serializer.read(PrimitiveMap.class, EMPTY_PRIMITIVE_BLANK_VALUE);     
   boolean valid = serializer.validate(PrimitiveMap.class, EMPTY_PRIMITIVE_BLANK_VALUE);
   
   assertTrue(valid);
   
   validate(value, serializer);      
}
 
Example 12
Source File: MapNullTest.java    From simplexml with Apache License 2.0 5 votes vote down vote up
public void testEmptyPrimitiveKey() throws Exception {
   Serializer serializer = new Persister();
   PrimitiveMap value = serializer.read(PrimitiveMap.class, EMPTY_PRIMITIVE_KEY);     
   boolean valid = serializer.validate(PrimitiveMap.class, EMPTY_PRIMITIVE_KEY);
   
   assertTrue(valid);
   
   validate(value, serializer);      
}
 
Example 13
Source File: MapNullTest.java    From simplexml with Apache License 2.0 5 votes vote down vote up
public void testEmptyPrimitiveBlankKey() throws Exception {
   Serializer serializer = new Persister();
   PrimitiveMap value = serializer.read(PrimitiveMap.class, EMPTY_PRIMITIVE_BLANK_KEY);     
   boolean valid = serializer.validate(PrimitiveMap.class, EMPTY_PRIMITIVE_BLANK_KEY);
   
   assertTrue(valid);
   
   validate(value, serializer);      
}