org.xlcloud.service.transformer.VcDefinitionTransformerTest.java Source code

Java tutorial

Introduction

Here is the source code for org.xlcloud.service.transformer.VcDefinitionTransformerTest.java

Source

/*
 * Copyright 2012 AMG.lab, a Bull Group Company
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *    http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.xlcloud.service.transformer;

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

import java.util.List;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.apache.log4j.Logger;
import org.junit.Before;
import org.junit.Test;

import org.xlcloud.service.VirtualClusterDefinition;
import org.xlcloud.service.model.VirtualClusterDefinitionModel;

/**
 * JUnit test suite for testing dozer transformations between
 * {@link VirtualClusterDefinition} and {@link VirtualClusterDefinitionModel}.
 * 
 * @author Maciej Osyda, AMG.net
 */
public class VcDefinitionTransformerTest extends TransformerTestSupport {

    private static final Logger LOG = Logger.getLogger(VcDefinitionTransformerTest.class);

    private Transformer<VirtualClusterDefinitionModel, VirtualClusterDefinition> vcDefTransformer;

    @Before
    public void initTransformer() {
        this.vcDefTransformer = new DozerTransformer<VirtualClusterDefinitionModel, VirtualClusterDefinition>(
                VirtualClusterDefinitionModel.class, VirtualClusterDefinition.class);
    }

    @Test
    public void testTwoWayTransform() {
        VirtualClusterDefinition dto = randomVClusterDefinition(Mode.FULL);

        LOG.info("dto: " + ToStringBuilder.reflectionToString(dto, ToStringStyle.MULTI_LINE_STYLE));
        VirtualClusterDefinitionModel modelFromDto = vcDefTransformer.transformFromDto(dto);
        LOG.info("model: " + ToStringBuilder.reflectionToString(modelFromDto, ToStringStyle.MULTI_LINE_STYLE));
        VirtualClusterDefinition dtoFromModel = vcDefTransformer.transformFromModel(modelFromDto);
        LOG.info("dtoFromModel: "
                + ToStringBuilder.reflectionToString(dtoFromModel, ToStringStyle.MULTI_LINE_STYLE));

        assertEquals(dto.getId(), dtoFromModel.getId());
        assertEquals(dto.getName(), dtoFromModel.getName());
        assertEquals(dto.getDescription(), dtoFromModel.getDescription());
        assertEquals(dto.getType(), dtoFromModel.getType());
        assertEquals(dto.getHref(), dtoFromModel.getHref());
        assertTags(dto.getTag(), dtoFromModel.getTag());
    }

    private void assertTags(List<String> expList, List<String> actList) {
        assertEquals(expList.size(), actList.size());
        assertTrue(expList.containsAll(actList));
    }
}