/*
 * Copyright 2014 Cisco Systems, Inc.
 *
 *  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.cisco.oss.foundation.logging;

import org.apache.log4j.Logger;
import org.junit.Test;

import java.lang.reflect.Constructor;

import static org.junit.Assert.*;

/**
 *
 * @author Yair Ogen
 */
public class ApplicationStateTest {
	
	static final Logger logger = Logger.getLogger(ApplicationStateTest.class);
	
	@Test
	public void equalstest(){
		
		logger.info("equalstest");
		
//		ApplicationStateMessage applicationStateMessage = new ApplicationStateMessage(Level.INFO, CategoryTerm.Audit, "my message");
//		ApplicationStateMessage applicationStateMessage1 = new ApplicationStateMessage(Level.ERROR, CategoryTerm.Audit, "my message");
//		ApplicationStateMessage applicationStateMessage2 = new ApplicationStateMessage(Level.INFO, CategoryTerm.Log, "my message");
//		ApplicationStateMessage applicationStateMessage3 = new ApplicationStateMessage(Level.INFO, null, "my message");
//		ApplicationStateMessage applicationStateMessage4 = new ApplicationStateMessage(Level.INFO,  CategoryTerm.Audit, null);
//		ApplicationStateMessage applicationStateMessage5 = new ApplicationStateMessage(null, CategoryTerm.Audit, "my message");
		
		
		ApplicationState.ApplicationStateMessage applicationStateMessage = new ApplicationState.ApplicationStateMessage(FoundationLevel.INFO, "my message");
        ApplicationState.ApplicationStateMessage applicationStateMessage1 = new ApplicationState.ApplicationStateMessage(FoundationLevel.ERROR, "my message");
        ApplicationState.ApplicationStateMessage applicationStateMessage2 = new ApplicationState.ApplicationStateMessage(FoundationLevel.INFO, "my message");
        ApplicationState.ApplicationStateMessage applicationStateMessage3 = new ApplicationState.ApplicationStateMessage(FoundationLevel.INFO, "my message");
        ApplicationState.ApplicationStateMessage applicationStateMessage4 = new ApplicationState.ApplicationStateMessage(FoundationLevel.INFO, null);
        ApplicationState.ApplicationStateMessage applicationStateMessage5 = new ApplicationState.ApplicationStateMessage(null, "my message");
		
		assertFalse(applicationStateMessage.equals(new Object()));
		assertFalse(applicationStateMessage.equals(applicationStateMessage1));
//		assertFalse(applicationStateMessage.equals(applicationStateMessage2));
//		assertFalse(applicationStateMessage3.equals(applicationStateMessage));
		assertFalse(applicationStateMessage4.equals(applicationStateMessage));
		assertFalse(applicationStateMessage5.equals(applicationStateMessage));
		assertFalse(applicationStateMessage.equals(null));// NOPMD
		assertTrue(applicationStateMessage.hashCode() != 0);
		assertTrue(applicationStateMessage3.hashCode() != 0);
		assertTrue(applicationStateMessage4.hashCode() != 0);
		assertTrue(applicationStateMessage5.hashCode() != 0);
		assertEquals(applicationStateMessage, applicationStateMessage);
		
//		Properties log4jConfigProps = FoundationLogger.log4jConfigProps;
//		ApplicationState.logState(null);
//		try {
//			log4jConfigProps.put(ApplicationState.APPSTATE_ENABLED, Boolean.TRUE);
//			ApplicationState.logState(null);
//		} catch (Exception e) {			
//		}
//		
//		log4jConfigProps.put(ApplicationState.APPSTATE_ENABLED, Boolean.FALSE);
//		ApplicationState.logState(null);
		
	}
	
	
	@Test
	public void mockCtor() throws Exception {// NOPMD
		@SuppressWarnings("unchecked")
		Constructor<ApplicationState>[] constructors = (Constructor<ApplicationState>[]) ApplicationState.class.getDeclaredConstructors();
		for (Constructor<ApplicationState> constructor : constructors) {
			constructor.setAccessible(true);
			constructor.newInstance();
		}
	}

}

@@ -717,47 +717,8 @@
 t;%0A%0A
-import java.lang.reflect.Constructor;%0A%0A
 impo
@@ -3825,371 +3825,8 @@
 %09%0A%09%0A
-%09@Test%0A%09public void mockCtor() throws Exception %7B// NOPMD%0A%09%09@SuppressWarnings(%22unchecked%22)%0A%09%09Constructor%3CApplicationState%3E%5B%5D constructors = (Constructor%3CApplicationState%3E%5B%5D) ApplicationState.class.getDeclaredConstructors();%0A%09%09for (Constructor%3CApplicationState%3E constructor : constructors) %7B%0A%09%09%09constructor.setAccessible(true);%0A%09%09%09constructor.newInstance();%0A%09%09%7D%0A%09%7D
 %0A%0A%7D%0A

remove redundant test, now that ApplicationState is an enum-singleton