/**
 * Copyright (C) 2010 hprange <hprange@gmail.com>
 * 
 * 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.woinject;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertThat;
import javassist.CannotCompileException;
import javassist.NotFoundException;

import org.junit.After;
import org.junit.Test;

import com.google.inject.Injector;
import com.google.inject.Stage;
import com.webobjects.foundation._NSUtilities;

import er.extensions.foundation.ERXProperties;

/**
 * @author <a href="mailto:hprange@gmail.com">Henrique Prange</a>
 */
public class TestInjectableApplication extends AbstractInjectableTestCase {
    private static final String DEVELOPMENT_MODE_KEY = "er.extensions.ERXApplication.developmentMode";

    @Test
    public void aaaa() throws NotFoundException, CannotCompileException {
	Object result = _NSUtilities.instantiateObject(Stage.class, null, null, false, false);

	System.out.println(result);
    }

    @Test
    public void appendAndLoadStubModuleOnInjectorInitialization() throws Exception {
	assertThat(((StubApplication) application).stubModuleWasLoaded(), is(true));
    }

    @Test
    public void createAnInjectorOnApplicationInitialization() throws Exception {
	assertThat(application.injector(), notNullValue());
    }

    @Test
    public void injectApplicationFields() throws Exception {
	assertThat(((StubApplication) application).getInjectableField(), is("fieldInjected"));
    }

    @Test
    public void injectApplicationMethods() throws Exception {
	assertThat(((StubApplication) application).getInjectableMethod(), is("methodInjected"));
    }

    @Test
    public void loadWOInjectModuleAutomatically() throws Exception {
	Injector injector = application.injector();

	assertThat(injector.getScopeBindings().get(WOSessionScoped.class), notNullValue());
    }

    @Test
    public void setStageForDevelomentMode() throws Exception {
	ERXProperties.setStringForKey("true", DEVELOPMENT_MODE_KEY);

	application = new StubApplication();

	Stage stage = application.injector().getInstance(Stage.class);

	assertThat(stage, is(Stage.DEVELOPMENT));
    }

    @Test
    public void setStageForProductionMode() throws Exception {
	ERXProperties.setStringForKey("false", DEVELOPMENT_MODE_KEY);

	application = new StubApplication();

	Stage stage = application.injector().getInstance(Stage.class);

	assertThat(stage, is(Stage.PRODUCTION));
    }

    @Override
    @After
    public void tearDown() {
	super.tearDown();

	ERXProperties.removeKey(DEVELOPMENT_MODE_KEY);
    }
}

@@ -49,18 +49,17 @@
 .com%3E%0A *
- 
 %0A
+
  * Licen
@@ -230,17 +230,16 @@
 se at%0A *
- 
 %0A * http
@@ -279,17 +279,16 @@
 E-2.0%0A *
- 
 %0A * Unle
@@ -773,85 +773,8 @@
 hat;
-%0Aimport javassist.CannotCompileException;%0Aimport javassist.NotFoundException;
 %0A%0Aim
@@ -889,55 +889,8 @@
 age;
-%0Aimport com.webobjects.foundation._NSUtilities;
 %0A%0Aim
@@ -1085,16 +1085,16 @@
 tCase %7B%0A
+
     priv
@@ -1193,217 +1193,8 @@
 %22;%0A%0A
-    @Test%0A    public void aaaa() throws NotFoundException, CannotCompileException %7B%0A%09Object result = _NSUtilities.instantiateObject(Stage.class, null, null, false, false);%0A%0A%09System.out.println(result);%0A    %7D%0A%0A
     

Remove experimental test case