Ignore:
Timestamp:
08/20/13 15:32:37 (11 years ago)
Author:
George.Georgovassilis@mpi.nl
Message:

#360 Refactoring of transaction handling, tests and application context

File:
1 edited

Legend:

Unmodified
Added
Removed
  • ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/CommentValidatorTest.java

    r3088 r3449  
    11package clarin.cmdi.componentregistry.rest;
    22
     3import clarin.cmdi.componentregistry.BaseUnitTest;
    34import clarin.cmdi.componentregistry.MDMarshaller;
    45import clarin.cmdi.componentregistry.impl.database.ComponentRegistryTestDatabase;
    56import clarin.cmdi.componentregistry.model.AbstractDescription;
    6 
    77import clarin.cmdi.componentregistry.model.ComponentDescription;
    88import static org.junit.Assert.assertEquals;
    99import static org.junit.Assert.assertFalse;
    1010import static org.junit.Assert.assertTrue;
     11import clarin.cmdi.componentregistry.model.ProfileDescription;
    1112
    12 import clarin.cmdi.componentregistry.model.ProfileDescription;
    1313import java.io.ByteArrayInputStream;
    1414import java.io.InputStream;
     15
    1516import javax.xml.transform.TransformerException;
     17
    1618import org.junit.Before;
    1719import org.junit.Test;
    18 import org.junit.runner.RunWith;
    1920import org.springframework.beans.factory.annotation.Autowired;
    2021import org.springframework.jdbc.core.JdbcTemplate;
    21 import org.springframework.test.context.ContextConfiguration;
    22 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
    2322
    2423/**
    2524 * Test class for CommentValidator
     25 *
    2626 * @author jean-charles FerriÚres <jean-charles.ferrieres@mpi.nl>
     27 * @author George.Georgovassilis@mpi.nl
    2728 */
    28 @RunWith(SpringJUnit4ClassRunner.class)
    29 @ContextConfiguration(locations = {"/applicationContext.xml"})
    30 public class CommentValidatorTest {
     29public class CommentValidatorTest extends BaseUnitTest {
    3130
    3231    @Autowired
     
    4645    @Test
    4746    public void testValidateSucces() {
    48         AbstractDescription description = ProfileDescription.createNewDescription();
     47        AbstractDescription description = ProfileDescription
     48                .createNewDescription();
    4949        String comContent = "";
    5050        comContent += "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n";
     
    5252        comContent += "    <comments>myCom</comments>\n";
    5353        comContent += "    <commentDate></commentDate>\n";
    54         comContent += "     <profileDescriptionId>" + description.getId() + "</profileDescriptionId>";
     54        comContent += "     <profileDescriptionId>" + description.getId()
     55                + "</profileDescriptionId>";
    5556        comContent += "    <userId>0</userId>\n";
    5657        comContent += "    <id>1</id>\n";
    5758        comContent += "</comment>\n";
    5859        InputStream input = new ByteArrayInputStream(comContent.getBytes());
    59         CommentValidator validator = new CommentValidator(input, description, marshaller);
     60        CommentValidator validator = new CommentValidator(input, description,
     61                marshaller);
    6062        assertTrue(validator.validate());
    6163    }
     
    7779        comContent += "</comment>\n";
    7880        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
    8185        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));
    8388
    8489        String commentContent = "";
     
    8792        commentContent += "    <comments>myCom</comments>\n";
    8893        commentContent += "    <commentDate></commentDate>\n";
    89         commentContent += "     <componentDescriptionId>" + desc.getId() + "</componentDescriptionId>";
     94        commentContent += "     <componentDescriptionId>" + desc.getId()
     95                + "</componentDescriptionId>";
    9096        commentContent += "    <userId>0</userId>\n";
    9197        commentContent += "    <id>1</id>\n";
     
    9399        input = new ByteArrayInputStream(commentContent.getBytes());
    94100        validator = new CommentValidator(input, desc, marshaller);
    95         assertTrue(validator.validate()); // componentId valid, validation complete
     101        assertTrue(validator.validate()); // componentId valid, validation
     102                                          // complete
    96103    }
    97104
     
    112119        comContent += "</comment>\n";
    113120        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
    116125        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));
    118128
    119129        String commentContent = "";
     
    122132        commentContent += "    <comments>myCom</comments>\n";
    123133        commentContent += "    <commentDate></commentDate>\n";
    124         commentContent += "     <profileDescriptionId>" + desc.getId() + "</profileDescriptionId>";
     134        commentContent += "     <profileDescriptionId>" + desc.getId()
     135                + "</profileDescriptionId>";
    125136        commentContent += "    <userId>0</userId>\n";
    126137        commentContent += "    <id>1</id>\n";
     
    128139        input = new ByteArrayInputStream(commentContent.getBytes());
    129140        validator = new CommentValidator(input, desc, marshaller);
    130         assertTrue(validator.validate()); // profileId valid, validation complete
     141        assertTrue(validator.validate()); // profileId valid, validation
     142                                          // complete
    131143    }
    132144
    133145    /**
    134146     * Test the validation of comment with content comments
    135      * @throws Exception
     147     *
     148     * @throws Exception
    136149     */
    137150    @Test
     
    143156        commentContent += "    <comments></comments>\n";
    144157        commentContent += "    <commentDate></commentDate>\n";
    145         commentContent += "     <profileDescriptionId>" + desc.getId() + "</profileDescriptionId>";
     158        commentContent += "     <profileDescriptionId>" + desc.getId()
     159                + "</profileDescriptionId>";
    146160        commentContent += "    <userId>0</userId>\n";
    147161        commentContent += "    <id>1</id>\n";
    148162        commentContent += "</comment>\n";
    149163        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));
    153170
    154171        String comContent = "";
     
    157174        comContent += "    <comments>myCom</comments>\n";
    158175        comContent += "    <commentDate></commentDate>\n";
    159         comContent += "     <profileDescriptionId>" + desc.getId() + "</profileDescriptionId>";
     176        comContent += "     <profileDescriptionId>" + desc.getId()
     177                + "</profileDescriptionId>";
    160178        comContent += "    <userId>0</userId>\n";
    161179        comContent += "    <id>1</id>\n";
     
    163181        input = new ByteArrayInputStream(comContent.getBytes());
    164182        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
    166185
    167186    }
Note: See TracChangeset for help on using the changeset viewer.