/*
 * Copyright 2015-2018 the original author or authors.
 *
 * 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.docksidestage.whitebox.lastadi.extctx;

import org.dbflute.utflute.core.PlainTestCase;
import org.lastaflute.core.util.ContainerUtil;
import org.lastaflute.web.util.LaRequestUtil;
import org.lastaflute.web.util.LaResponseUtil;

/**
 * @author jflute
 */
public class WxExternalContextPlainTest extends PlainTestCase {

    public void test_ContainerUtil() throws Exception {
        assertFalse(ContainerUtil.hasExternalContext());
        assertException(IllegalStateException.class, () -> ContainerUtil.retrieveExternalContext());
    }

    public void test_RequestUtil() throws Exception {
        assertException(IllegalStateException.class, () -> LaRequestUtil.getRequest());
        assertNotNull(LaRequestUtil.getOptionalRequest());
        assertFalse(LaRequestUtil.getOptionalRequest().isPresent());
    }

    public void test_ResponseUtil() throws Exception {
        assertException(IllegalStateException.class, () -> LaResponseUtil.getResponse());
        assertNotNull(LaResponseUtil.getOptionalResponse());
        assertFalse(LaResponseUtil.getOptionalResponse().isPresent());
    }
}

@@ -755,24 +755,138 @@
 tainerUtil;%0A
+import org.lastaflute.di.core.ExternalContext;%0Aimport org.lastaflute.di.core.factory.SingletonLaContainerFactory;%0A
 import org.l
@@ -1058,16 +1058,493 @@
 Case %7B%0A%0A
+    private ExternalContext originalContext; // saved, container may be cached%0A%0A    @Override%0A    protected void setUp() throws Exception %7B%0A        originalContext = SingletonLaContainerFactory.getExternalContext();%0A        SingletonLaContainerFactory.setExternalContext(null);%0A        super.setUp();%0A    %7D%0A%0A    @Override%0A    protected void tearDown() throws Exception %7B%0A        super.tearDown();%0A        SingletonLaContainerFactory.setExternalContext(originalContext);%0A    %7D%0A%0A
     publ

save originalContext