Changeset 3449 for ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/CommentValidatorTest.java
- Timestamp:
- 08/20/13 15:32:37 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/CommentValidatorTest.java
r3088 r3449 1 1 package clarin.cmdi.componentregistry.rest; 2 2 3 import clarin.cmdi.componentregistry.BaseUnitTest; 3 4 import clarin.cmdi.componentregistry.MDMarshaller; 4 5 import clarin.cmdi.componentregistry.impl.database.ComponentRegistryTestDatabase; 5 6 import clarin.cmdi.componentregistry.model.AbstractDescription; 6 7 7 import clarin.cmdi.componentregistry.model.ComponentDescription; 8 8 import static org.junit.Assert.assertEquals; 9 9 import static org.junit.Assert.assertFalse; 10 10 import static org.junit.Assert.assertTrue; 11 import clarin.cmdi.componentregistry.model.ProfileDescription; 11 12 12 import clarin.cmdi.componentregistry.model.ProfileDescription;13 13 import java.io.ByteArrayInputStream; 14 14 import java.io.InputStream; 15 15 16 import javax.xml.transform.TransformerException; 17 16 18 import org.junit.Before; 17 19 import org.junit.Test; 18 import org.junit.runner.RunWith;19 20 import org.springframework.beans.factory.annotation.Autowired; 20 21 import org.springframework.jdbc.core.JdbcTemplate; 21 import org.springframework.test.context.ContextConfiguration;22 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;23 22 24 23 /** 25 24 * Test class for CommentValidator 25 * 26 26 * @author jean-charles FerriÚres <jean-charles.ferrieres@mpi.nl> 27 * @author George.Georgovassilis@mpi.nl 27 28 */ 28 @RunWith(SpringJUnit4ClassRunner.class) 29 @ContextConfiguration(locations = {"/applicationContext.xml"}) 30 public class CommentValidatorTest { 29 public class CommentValidatorTest extends BaseUnitTest { 31 30 32 31 @Autowired … … 46 45 @Test 47 46 public void testValidateSucces() { 48 AbstractDescription description = ProfileDescription.createNewDescription(); 47 AbstractDescription description = ProfileDescription 48 .createNewDescription(); 49 49 String comContent = ""; 50 50 comContent += "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"; … … 52 52 comContent += " <comments>myCom</comments>\n"; 53 53 comContent += " <commentDate></commentDate>\n"; 54 comContent += " <profileDescriptionId>" + description.getId() + "</profileDescriptionId>"; 54 comContent += " <profileDescriptionId>" + description.getId() 55 + "</profileDescriptionId>"; 55 56 comContent += " <userId>0</userId>\n"; 56 57 comContent += " <id>1</id>\n"; 57 58 comContent += "</comment>\n"; 58 59 InputStream input = new ByteArrayInputStream(comContent.getBytes()); 59 CommentValidator validator = new CommentValidator(input, description, marshaller); 60 CommentValidator validator = new CommentValidator(input, description, 61 marshaller); 60 62 assertTrue(validator.validate()); 61 63 } … … 77 79 comContent += "</comment>\n"; 78 80 InputStream input = new ByteArrayInputStream(comContent.getBytes()); 79 CommentValidator validator = new CommentValidator(input, desc, marshaller); 80 assertFalse(validator.validate());// missing componentId will return an error 81 CommentValidator validator = new CommentValidator(input, desc, 82 marshaller); 83 assertFalse(validator.validate());// missing componentId will return an 84 // error 81 85 assertEquals(validator.getErrorMessages().size(), 1); 82 assertTrue(validator.getErrorMessages().get(0).startsWith(CommentValidator.COMMENT_SPECIFICATION_ERROR)); 86 assertTrue(validator.getErrorMessages().get(0) 87 .startsWith(CommentValidator.COMMENT_SPECIFICATION_ERROR)); 83 88 84 89 String commentContent = ""; … … 87 92 commentContent += " <comments>myCom</comments>\n"; 88 93 commentContent += " <commentDate></commentDate>\n"; 89 commentContent += " <componentDescriptionId>" + desc.getId() + "</componentDescriptionId>"; 94 commentContent += " <componentDescriptionId>" + desc.getId() 95 + "</componentDescriptionId>"; 90 96 commentContent += " <userId>0</userId>\n"; 91 97 commentContent += " <id>1</id>\n"; … … 93 99 input = new ByteArrayInputStream(commentContent.getBytes()); 94 100 validator = new CommentValidator(input, desc, marshaller); 95 assertTrue(validator.validate()); // componentId valid, validation complete 101 assertTrue(validator.validate()); // componentId valid, validation 102 // complete 96 103 } 97 104 … … 112 119 comContent += "</comment>\n"; 113 120 InputStream input = new ByteArrayInputStream(comContent.getBytes()); 114 CommentValidator validator = new CommentValidator(input, desc, marshaller); 115 assertFalse(validator.validate());// missing profileId will return an error 121 CommentValidator validator = new CommentValidator(input, desc, 122 marshaller); 123 assertFalse(validator.validate());// missing profileId will return an 124 // error 116 125 assertEquals(validator.getErrorMessages().size(), 1); 117 assertTrue(validator.getErrorMessages().get(0).startsWith(CommentValidator.COMMENT_SPECIFICATION_ERROR)); 126 assertTrue(validator.getErrorMessages().get(0) 127 .startsWith(CommentValidator.COMMENT_SPECIFICATION_ERROR)); 118 128 119 129 String commentContent = ""; … … 122 132 commentContent += " <comments>myCom</comments>\n"; 123 133 commentContent += " <commentDate></commentDate>\n"; 124 commentContent += " <profileDescriptionId>" + desc.getId() + "</profileDescriptionId>"; 134 commentContent += " <profileDescriptionId>" + desc.getId() 135 + "</profileDescriptionId>"; 125 136 commentContent += " <userId>0</userId>\n"; 126 137 commentContent += " <id>1</id>\n"; … … 128 139 input = new ByteArrayInputStream(commentContent.getBytes()); 129 140 validator = new CommentValidator(input, desc, marshaller); 130 assertTrue(validator.validate()); // profileId valid, validation complete 141 assertTrue(validator.validate()); // profileId valid, validation 142 // complete 131 143 } 132 144 133 145 /** 134 146 * Test the validation of comment with content comments 135 * @throws Exception 147 * 148 * @throws Exception 136 149 */ 137 150 @Test … … 143 156 commentContent += " <comments></comments>\n"; 144 157 commentContent += " <commentDate></commentDate>\n"; 145 commentContent += " <profileDescriptionId>" + desc.getId() + "</profileDescriptionId>"; 158 commentContent += " <profileDescriptionId>" + desc.getId() 159 + "</profileDescriptionId>"; 146 160 commentContent += " <userId>0</userId>\n"; 147 161 commentContent += " <id>1</id>\n"; 148 162 commentContent += "</comment>\n"; 149 163 InputStream input = new ByteArrayInputStream(commentContent.getBytes()); 150 CommentValidator validator = new CommentValidator(input, desc, marshaller); 151 assertFalse(validator.validate()); // missing content will return an error 152 assertTrue(validator.getErrorMessages().get(0).startsWith(CommentValidator.COMMENT_SPECIFICATION_ERROR)); 164 CommentValidator validator = new CommentValidator(input, desc, 165 marshaller); 166 assertFalse(validator.validate()); // missing content will return an 167 // error 168 assertTrue(validator.getErrorMessages().get(0) 169 .startsWith(CommentValidator.COMMENT_SPECIFICATION_ERROR)); 153 170 154 171 String comContent = ""; … … 157 174 comContent += " <comments>myCom</comments>\n"; 158 175 comContent += " <commentDate></commentDate>\n"; 159 comContent += " <profileDescriptionId>" + desc.getId() + "</profileDescriptionId>"; 176 comContent += " <profileDescriptionId>" + desc.getId() 177 + "</profileDescriptionId>"; 160 178 comContent += " <userId>0</userId>\n"; 161 179 comContent += " <id>1</id>\n"; … … 163 181 input = new ByteArrayInputStream(comContent.getBytes()); 164 182 validator = new CommentValidator(input, desc, marshaller); 165 assertTrue(validator.validate());// content comments is fill in, validation complete 183 assertTrue(validator.validate());// content comments is fill in, 184 // validation complete 166 185 167 186 }
Note: See TracChangeset
for help on using the changeset viewer.