/*******************************************************************************
 * Copyright (c) 2019 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package com.ibm.ws.jaxrs20.fat.json;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;

import com.ibm.websphere.simplicity.ShrinkHelper;
import com.ibm.ws.jaxrs20.fat.AbstractTest;

import componenttest.annotation.Server;
import componenttest.custom.junit.runner.FATRunner;
import componenttest.topology.impl.LibertyServer;

/**
 * The purpose of this test is to work item 88030_PM76009_:
 * INVALID UTF-8 middle byte error WITH DANISH CHARACTER SET
 */
@RunWith(FATRunner.class)
public class UTF8Test extends AbstractTest {

    @Server("com.ibm.ws.jaxrs.fat.json")
    public static LibertyServer server;

    private static final String jsonwar = "json";
    private final String target = jsonwar + "/TestServlet";

    @BeforeClass
    public static void setUp() throws Exception {
        ShrinkHelper.defaultDropinApp(server, jsonwar, "com.ibm.ws.jaxrs.fat.json");

        // Make sure we don't fail because we try to start an
        // already started server
        try {
            server.startServer(true);
        } catch (Exception e) {
            System.out.println(e.toString());
        }
    }

    @AfterClass
    public static void tearDown() throws Exception {
        if (server != null) {
            server.stopServer();
        }
    }

    @Before
    public void preTest() {
        serverRef = server;
    }

    @After
    public void afterTest() {
        serverRef = null;
    }

    @Test
    public void testCountriesUpperCase() throws Exception {
        this.runTestOnServer(target, "testCountriesUpperCase", null, "OK");
    }

    @Test
    public void testCountriesLowerCase() throws Exception {
        this.runTestOnServer(target, "testCountriesLowerCase", null, "OK");
    }

    @Test
    public void testInvalidBody() throws Exception {
        this.runTestOnServer(target, "testInvalidBody", null, "400");
    }
}
