// Path: src/main/java/com/stackify/api/ErrorItem.java
// @AllArgsConstructor
// @NoArgsConstructor
// @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true)
// @Data
// @JsonInclude(JsonInclude.Include.NON_NULL)
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class ErrorItem {
// 
//     /**
//      * The error message
//      */
//     @Setter
//     @JsonProperty("Message")
//     private String message;
// 
//     /**
//      * The error's class name
//      */
//     @JsonProperty("ErrorType")
//     private String errorType;
// 
//     /**
//      * The error type code
//      */
//     @JsonProperty("ErrorTypeCode")
//     private String errorTypeCode;
// 
//     /**
//      * Custom data for the error
//      */
//     @JsonProperty("Data")
//     private Map<String, String> data;
// 
//     /**
//      * The method name
//      */
//     @JsonProperty("SourceMethod")
//     private String sourceMethod;
// 
//     /**
//      * The stack trace
//      */
//     @JsonProperty("StackTrace")
//     private List<TraceFrame> stackTrace;
// 
//     /**
//      * The cause of this error
//      */
//     @JsonProperty("InnerError")
//     private ErrorItem innerError;
// 
// }
// 
// Path: src/main/java/com/stackify/api/StackifyError.java
// @AllArgsConstructor
// @NoArgsConstructor
// @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true)
// @Data
// @JsonInclude(JsonInclude.Include.NON_NULL)
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class StackifyError {
// 
//     /**
//      * Environment
//      */
//     @JsonProperty("EnvironmentDetail")
//     private EnvironmentDetail environmentDetail;
// 
//     /**
//      * Date/time of the error
//      */
//     @JsonProperty("OccurredEpochMillis")
//     private Long occurredEpochMillis;
// 
//     /**
//      * Error details
//      */
//     @JsonProperty("Error")
//     private ErrorItem error;
// 
//     /**
//      * Details of the web request
//      */
//     @JsonProperty("WebRequestDetail")
//     private WebRequestDetail webRequestDetail;
// 
//     /**
//      * Server variables
//      */
//     @JsonProperty("ServerVariables")
//     private Map<String, String> serverVariables;
// 
//     /**
//      * Customer name
//      */
//     @JsonProperty("CustomerName")
//     private String customerName;
// 
//     /**
//      * User name
//      */
//     @JsonProperty("UserName")
//     private String userName;
// 
// }
// 
// Path: src/main/java/com/stackify/api/common/codec/MessageDigests.java
// public class MessageDigests {
// 
//     /**
//      * Generates an MD5 hash hex string for the input string
//      * @param input The input string
//      * @return MD5 hash hex string
//      */
//     public static String md5Hex(final String input) {
// 		if (input == null) {
// 			throw new NullPointerException("String is null");
// 		}
// 
//     	MessageDigest digest = null;
//     	
//     	try {
//     		digest = MessageDigest.getInstance("MD5");
//     	} catch (NoSuchAlgorithmException e) {
//     		// this should never happen
//     		throw new RuntimeException(e);
//     	}
//         
//         byte[] hash = digest.digest(input.getBytes());
//         
//         return DatatypeConverter.printHexBinary(hash);
//     }
// 	
// 	/**
// 	 * Hidden to prevent construction
// 	 */
// 	private MessageDigests() {
// 		// do nothing
// 	}
// }


import org.junit.Assert;
import org.junit.Test;
import com.stackify.api.ErrorItem;
import com.stackify.api.StackifyError;
import com.stackify.api.common.codec.MessageDigests;
/*
 * Copyright 2013 Stackify
 *
 * 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.stackify.api.common.error;



/**
 * ErrorCounter JUnit Test
 * 
 * @author Eric Martin
 */
public class ErrorCounterTest {

	/**
	 * testGetBaseErrorWithNull
	 */
	@Test(expected = NullPointerException.class)
	public void testGetBaseErrorWithNull() {
		ErrorCounter.getBaseError(null);
	}
	
	/**
	 * testGetBaseError
	 */
	@Test
	public void testGetBaseError() {
		ErrorItem errorDetail = ErrorItem.newBuilder().build();
		
		StackifyError.Builder builder = StackifyError.newBuilder();
		builder.error(errorDetail);
		StackifyError stackifyError = builder.build();
		
		Assert.assertEquals(errorDetail, ErrorCounter.getBaseError(stackifyError));
	}
	
	/**
	 * testGetUniqueKeyWithNull
	 */
	@Test(expected = NullPointerException.class)
	public void testGetUniqueKeyWithNull() {
		ErrorCounter.getUniqueKey(null);
	}
	
	/**
	 * testGetUniqueKey
	 */
	@Test
	public void testGetUniqueKey() {
		ErrorItem.Builder builder = ErrorItem.newBuilder();
		builder.errorType("errorType");
		builder.errorTypeCode("errorTypeCode");
		builder.sourceMethod("sourceMethod");

// Path: src/main/java/com/stackify/api/ErrorItem.java
// @AllArgsConstructor
// @NoArgsConstructor
// @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true)
// @Data
// @JsonInclude(JsonInclude.Include.NON_NULL)
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class ErrorItem {
// 
//     /**
//      * The error message
//      */
//     @Setter
//     @JsonProperty("Message")
//     private String message;
// 
//     /**
//      * The error's class name
//      */
//     @JsonProperty("ErrorType")
//     private String errorType;
// 
//     /**
//      * The error type code
//      */
//     @JsonProperty("ErrorTypeCode")
//     private String errorTypeCode;
// 
//     /**
//      * Custom data for the error
//      */
//     @JsonProperty("Data")
//     private Map<String, String> data;
// 
//     /**
//      * The method name
//      */
//     @JsonProperty("SourceMethod")
//     private String sourceMethod;
// 
//     /**
//      * The stack trace
//      */
//     @JsonProperty("StackTrace")
//     private List<TraceFrame> stackTrace;
// 
//     /**
//      * The cause of this error
//      */
//     @JsonProperty("InnerError")
//     private ErrorItem innerError;
// 
// }
// 
// Path: src/main/java/com/stackify/api/StackifyError.java
// @AllArgsConstructor
// @NoArgsConstructor
// @Builder(builderClassName = "Builder", builderMethodName = "newBuilder", toBuilder = true)
// @Data
// @JsonInclude(JsonInclude.Include.NON_NULL)
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class StackifyError {
// 
//     /**
//      * Environment
//      */
//     @JsonProperty("EnvironmentDetail")
//     private EnvironmentDetail environmentDetail;
// 
//     /**
//      * Date/time of the error
//      */
//     @JsonProperty("OccurredEpochMillis")
//     private Long occurredEpochMillis;
// 
//     /**
//      * Error details
//      */
//     @JsonProperty("Error")
//     private ErrorItem error;
// 
//     /**
//      * Details of the web request
//      */
//     @JsonProperty("WebRequestDetail")
//     private WebRequestDetail webRequestDetail;
// 
//     /**
//      * Server variables
//      */
//     @JsonProperty("ServerVariables")
//     private Map<String, String> serverVariables;
// 
//     /**
//      * Customer name
//      */
//     @JsonProperty("CustomerName")
//     private String customerName;
// 
//     /**
//      * User name
//      */
//     @JsonProperty("UserName")
//     private String userName;
// 
// }
// 
// Path: src/main/java/com/stackify/api/common/codec/MessageDigests.java
// public class MessageDigests {
// 
//     /**
//      * Generates an MD5 hash hex string for the input string
//      * @param input The input string
//      * @return MD5 hash hex string
//      */
//     public static String md5Hex(final String input) {
// 		if (input == null) {
// 			throw new NullPointerException("String is null");
// 		}
// 
//     	MessageDigest digest = null;
//     	
//     	try {
//     		digest = MessageDigest.getInstance("MD5");
//     	} catch (NoSuchAlgorithmException e) {
//     		// this should never happen
//     		throw new RuntimeException(e);
//     	}
//         
//         byte[] hash = digest.digest(input.getBytes());
//         
//         return DatatypeConverter.printHexBinary(hash);
//     }
// 	
// 	/**
// 	 * Hidden to prevent construction
// 	 */
// 	private MessageDigests() {
// 		// do nothing
// 	}
// }


// Path: src/test/java/com/stackify/api/common/error/ErrorCounterTest.java
import org.junit.Assert;
import org.junit.Test;
import com.stackify.api.ErrorItem;
import com.stackify.api.StackifyError;
import com.stackify.api.common.codec.MessageDigests;

/*
 * Copyright 2013 Stackify
 *
 * 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.stackify.api.common.error;



/**
 * ErrorCounter JUnit Test
 * 
 * @author Eric Martin
 */
public class ErrorCounterTest {

	/**
	 * testGetBaseErrorWithNull
	 */
	@Test(expected = NullPointerException.class)
	public void testGetBaseErrorWithNull() {
		ErrorCounter.getBaseError(null);
	}
	
	/**
	 * testGetBaseError
	 */
	@Test
	public void testGetBaseError() {
		ErrorItem errorDetail = ErrorItem.newBuilder().build();
		
		StackifyError.Builder builder = StackifyError.newBuilder();
		builder.error(errorDetail);
		StackifyError stackifyError = builder.build();
		
		Assert.assertEquals(errorDetail, ErrorCounter.getBaseError(stackifyError));
	}
	
	/**
	 * testGetUniqueKeyWithNull
	 */
	@Test(expected = NullPointerException.class)
	public void testGetUniqueKeyWithNull() {
		ErrorCounter.getUniqueKey(null);
	}
	
	/**
	 * testGetUniqueKey
	 */
	@Test
	public void testGetUniqueKey() {
		ErrorItem.Builder builder = ErrorItem.newBuilder();
		builder.errorType("errorType");
		builder.errorTypeCode("errorTypeCode");
		builder.sourceMethod("sourceMethod");

		String expectedHash = MessageDigests.md5Hex("errorType-errorTypeCode-sourceMethod");