/* Copyright (c) 2016 Stéphane GRILLON https://github.com/sgrillon14/flags-rest-service
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the <organization> nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package com.sgrillon.flags.service.impl;

import static org.assertj.core.api.Assertions.assertThat;

import java.io.IOException;

import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.http.HttpStatus;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.Test;

import com.sgrillon.flags.service.FlagService;
import com.sgrillon.flags.service.PngContainer;

/**
 * Basic unit tests for FlagService.
 * 
 * @author sgrillon
 *
 */
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@DirtiesContext
public class FlagServiceImplTests  extends AbstractTestNGSpringContextTests {

    @Autowired
    private FlagService flagService;

    @Test
    public void testGetSvgContentWithFr() {
        String expectedSvgContent = "<svg xmlns=\"http://www.w3.org/2000/svg\" height=\"480\" width=\"640\" version=\"1\">\r\n  <g fill-rule=\"evenodd\" stroke-width=\"1pt\">\r\n    <path fill=\"#fff\" d=\"M0 0h640v480H0z\"/>\r\n    <path fill=\"#00267f\" d=\"M0 0h213.337v480H0z\"/>\r\n    <path fill=\"#f31830\" d=\"M426.662 0H640v480H426.662z\"/>\r\n  </g>\r\n</svg>\r\n";
        String actualSvgContent = flagService.getSvgFlag("fr");
        assertThat(actualSvgContent).isEqualTo(expectedSvgContent);
    }
    
    @Test
    public void testGetPngContentWithFr() throws IOException {
        byte[] expectedPngContent = IOUtils.toByteArray(getClass().getClassLoader().getResourceAsStream("flags/fr_40_40.png"));
        PngContainer actualPngContent = flagService.getPngFlag("fr", 40, 40);
        System.out.println("sgr code " + actualPngContent.getErrorCode());
        assertThat(actualPngContent.getErrorCode()).isEqualTo(HttpStatus.OK);
        assertThat(actualPngContent.getPngContent()).isEqualTo(expectedPngContent);
    }
    
}

@@ -2763,18 +2763,16 @@
 =%5C%221%5C%22%3E%5C
-r%5C
 n  %3Cg fi
@@ -2813,18 +2813,16 @@
 %221pt%5C%22%3E%5C
-r%5C
 n    %3Cpa
@@ -2854,34 +2854,32 @@
 h640v480H0z%5C%22/%3E%5C
-r%5C
 n    %3Cpath fill=
@@ -2918,18 +2918,16 @@
 H0z%5C%22/%3E%5C
-r%5C
 n    %3Cpa
@@ -2986,18 +2986,16 @@
 %22/%3E%5C
-r%5C
 n  %3C/g%3E%5C
 r%5Cn%3C
@@ -2994,18 +2994,16 @@
 /g%3E%5C
-r%5C
 n%3C/svg%3E%5C
 r%5Cn%22
@@ -3002,10 +3002,8 @@
 vg%3E%5C
-r%5C
 n%22;%0A

revert for Jenkins