test.pl.chilldev.web.spring.config.MetaHttpEquivBeanDefinitionParserTest.java Source code

Java tutorial

Introduction

Here is the source code for test.pl.chilldev.web.spring.config.MetaHttpEquivBeanDefinitionParserTest.java

Source

/**
 * This file is part of the ChillDev-Web.
 *
 * @license http://mit-license.org/ The MIT license
 * @copyright 2014  by Rafa Wrzeszcz - Wrzasq.pl.
 */

package test.pl.chilldev.web.spring.config;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;

import java.util.Map;

import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import static org.mockito.Mockito.*;

import org.springframework.beans.factory.support.GenericBeanDefinition;

import org.w3c.dom.CharacterData;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

import pl.chilldev.web.spring.config.MetaHttpEquivBeanDefinitionParser;

@RunWith(MockitoJUnitRunner.class)
public class MetaHttpEquivBeanDefinitionParserTest {
    @Mock
    private Element element;

    @Mock
    private CharacterData data;

    @Mock
    private NodeList dataContainer;

    private String value = "value";

    @Before
    public void setUp() {
        when(this.element.getChildNodes()).thenReturn(this.dataContainer);
        when(this.data.getNodeValue()).thenReturn(this.value);
        when(this.dataContainer.getLength()).thenReturn(1);
        when(this.dataContainer.item(0)).thenReturn(this.data);
    }

    @Test
    public void parse() {
        GenericBeanDefinition bean = new GenericBeanDefinition();
        MetaHttpEquivBeanDefinitionParser parser = new MetaHttpEquivBeanDefinitionParser(bean);

        String key = "key";

        when(this.element.getAttribute("key")).thenReturn(key);

        parser.parse(this.element, null);

        Map<String, String> metaData = (Map<String, String>) bean.getPropertyValues()
                .getPropertyValue(MetaHttpEquivBeanDefinitionParser.PROPERTY_METAHTTPEQUIV).getValue();

        assertTrue("MetaHttpEquivBeanDefinitionParser.parse() should register all meta data.",
                metaData.containsKey(key));
        assertEquals("MetaHttpEquivBeanDefinitionParser.parse() should register all meta data.", this.value,
                metaData.get(key));
    }
}