/**
 * @copyright (c) 2014, by Vitaliy Tsutsman
 *
 * @author Vitaliy Tsutsman <vtsutsman@softjourn.com>
 */

package com.coffeine.virtuoso.module.user.model.entity;

import com.coffeine.virtuoso.module.model.AbstractModel;
import org.hibernate.validator.constraints.NotEmpty;
import org.junit.Test;

import javax.validation.ConstraintViolation;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.Set;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

/**
 * Tests for VideoType
 * @see com.coffeine.virtuoso.module.user.model.entity.VideoType
 *
 * @version 1.0
 */
public class VideoTypeTest extends AbstractModel {

    /**
     * Test field validation for entity
     */
    @Test
    public void testVideoTypeFields() {

        Set < ConstraintViolation < VideoType > > constraintViolationSet;

        //- Success -//
        //- Create entity -//
        VideoType videoTypeSuccess = new VideoType(
            "POLKA",
            "Polka",
            "Ukrainian polka"
        );

        //- Validate -//
        constraintViolationSet = validator.validate( videoTypeSuccess );

        assertEquals(0, constraintViolationSet.size());


        //- Failure -//
        //- Create entity -//
        VideoType videoTypeFailure = new VideoType(
            null,
            "Polka",
            "Ukrainian polka"
        );

        //- Validate -//
        constraintViolationSet = validator.validate( videoTypeFailure );

        assertEquals( 2, constraintViolationSet.size() );
        for ( ConstraintViolation<VideoType> constraintViolation : constraintViolationSet ) {
            //- Property name -//
            assertEquals(
                "code",
                this.getPropertyName(
                    constraintViolation.getPropertyPath()
                )
            );
            //- Annotation type -//
            assertTrue(
                new ArrayList<Class>() {{
                    add(NotNull.class);
                    add(NotEmpty.class);
                }}.contains(
                    constraintViolation.getConstraintDescriptor().getAnnotation().annotationType()
                )
            );
            //- Message -//
            assertTrue(
                new ArrayList < String >() {{
                    add( "may not be null" );
                    add( "may not be empty" );
                }}.contains( constraintViolation.getMessage() )
            );
        }
    }
}

@@ -1348,39 +1348,36 @@
 ll,%0A            
-%22Polka%22
+null
 ,%0A            %22U
@@ -1525,17 +1525,17 @@
 Equals( 
-2
+4
 , constr
@@ -1711,40 +1711,164 @@
 sert
-Equals(%0A                %22code%22,%0A
+True(%0A                new ArrayList %3C String %3E() %7B%7B%0A                    add( %22code%22 );%0A                    add( %22title%22 );%0A                %7D%7D.contains(%0A    
     
@@ -1901,16 +1901,20 @@
 tyName(%0A
+    
         
@@ -1963,16 +1963,38 @@
 yPath()%0A
+                    )%0A
         
@@ -2111,14 +2111,17 @@
 List
-%3C
+ %3C 
 Class
+ 
 %3E() 
@@ -2147,16 +2147,17 @@
     add(
+ 
 NotNull.
@@ -2157,24 +2157,25 @@
 otNull.class
+ 
 );%0A         
@@ -2189,16 +2189,17 @@
     add(
+ 
 NotEmpty
@@ -2204,16 +2204,17 @@
 ty.class
+ 
 );%0A     

Update unit test for VideoType