/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 ~ Copyright 2019 Adobe
 ~
 ~ 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 com.adobe.cq.wcm.core.components.internal.models.v1;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import com.adobe.cq.wcm.core.components.Utils;
import com.adobe.cq.wcm.core.components.context.CoreComponentTestContext;
import com.adobe.cq.wcm.core.components.models.Separator;
import io.wcm.testing.mock.aem.junit5.AemContext;
import io.wcm.testing.mock.aem.junit5.AemContextExtension;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

@ExtendWith(AemContextExtension.class)
class SeparatorImplTest {

    private static final String TEST_BASE = "/separator";
    private static final String CONTENT_ROOT = "/content";
    private static final String CONTEXT_PATH = "/core";
    private static final String TEST_ROOT_PAGE = "/content/separator";
    private static final String TEST_ROOT_PAGE_GRID = "/jcr:content/root/responsivegrid";
    private static final String SEPARATOR_1 = TEST_ROOT_PAGE + TEST_ROOT_PAGE_GRID + "/separator-1";
    private static final String SEPARATOR_2 = TEST_ROOT_PAGE + TEST_ROOT_PAGE_GRID + "/separator-2";

    private final AemContext context = CoreComponentTestContext.newAemContext();

    @BeforeEach
    void setUp() {
        context.load().json(TEST_BASE + CoreComponentTestContext.TEST_CONTENT_JSON, CONTENT_ROOT);
    }

    @Test
    void testStandard() {
        Separator separator = getSeparatorUnderTest(SEPARATOR_1);
        assertFalse(separator.isDecorative());
    }

    @Test
    void testDecorative() {
        Separator separator = getSeparatorUnderTest(SEPARATOR_2);
        assertTrue(separator.isDecorative());
    }

    @Test
    void testExportedType() {
        Separator separator = getSeparatorUnderTest(SEPARATOR_1);
        assertEquals(SeparatorImpl.RESOURCE_TYPE_V1, ((SeparatorImpl) separator).getExportedType());
        Utils.testJSONExport(separator, Utils.getTestExporterJSONPath(TEST_BASE, "separator1"));
    }

    private Separator getSeparatorUnderTest(String path) {
        context.currentResource(path);
        context.request().setContextPath(CONTEXT_PATH);
        return context.request().adaptTo(Separator.class);
    }
}
