// Path: fixb/src/main/java/org/fixb/FixException.java
// public class FixException extends RuntimeException {
//     private static final long serialVersionUID = 1;
// 
//     /**
//      * @param tag the field tag that has not been found
//      * @param fixMessage the FIX message that does not contain the tag
//      * @return an instance of FixException for a field-not-found case.
//      */
//     public static FixException fieldNotFound(int tag, String fixMessage) {
//         return new FixException("Field [" + tag + "] was not found in message: " + fixMessage);
//     }
// 
//     /**
//      * @param message the exception message
//      * @param cause the exception cause
//      */
//     public FixException(final String message, final Throwable cause) {
//         super(message, cause);
//     }
// 
//     /**
//      * @param cause the exception cause
//      */
//     public FixException(final Throwable cause) {
//         super(cause.getMessage(), cause);
//     }
// 
//     /**
//      * @param message the exception message
//      */
//     public FixException(final String message) {
//         super(message);
//     }
// }
// 
// Path: fixb/src/main/java/org/fixb/meta/FixEnumMeta.java
// public class FixEnumMeta<T extends Enum<T>> {
//     private final Class<T> enumClass;
//     private final BiMap<String, T> enumFixValues;
// 
//     public static <T extends Enum<T>> FixEnumMeta<T> forClass(Class<T> type) {
//         if (!type.isEnum()) {
//             throw new FixException("Expected an enum class, but got [" + type.getName() + "].");
//         }
//         return new FixEnumMeta<>(type);
//     }
// 
//     private FixEnumMeta(Class<T> enumType) {
//         try {
//             final ImmutableBiMap.Builder<String, T> mapBuilder = ImmutableBiMap.builder();
// 
//             for (Field field : enumType.getFields()) {
//                 if (field.isEnumConstant()) {
//                     FixValue fixValue = field.getAnnotation(FixValue.class);
//                     if (fixValue == null) {
//                         throw new FixException("Not all enum values of [" + enumType.getName() + "] have @FixValue annotation: " + field.get(null));
//                     }
//                     mapBuilder.put(fixValue.value(), (T) field.get(null));
//                 }
//             }
// 
//             this.enumClass = enumType;
//             this.enumFixValues = mapBuilder.build();
// 
//         } catch (IllegalAccessException e) {
//             throw new FixException("Invalid FIX enum mapping", e);
//         }
//     }
// 
//     public Class<T> getType() {
//         return enumClass;
//     }
// 
//     public Enum<T> enumForFixValue(String fixValue) {
//         return enumFixValues.get(fixValue);
//     }
// 
//     public String fixValueForEnum(Enum<?> enumValue) {
//         return enumFixValues.inverse().get(enumValue);
//     }
// }
// 
// Path: fixb/src/main/java/org/fixb/meta/FixEnumDictionary.java
// public interface FixEnumDictionary {
//     /**
//      * @param enumType the enum type
//      * @param <T>      the enum type
//      * @return FIX enum value bindings for the given enum type.
//      */
//     <T extends Enum<T>> FixEnumMeta<T> getFixEnumMeta(Class<T> enumType);
// 
//     /**
//      * @param enumType the enum type
//      * @return true if there is a meta object for the given enum class in this dictionary, false otherwise.
//      */
//     boolean hasFixEnumMeta(Class<?> enumType);
// }
// 
// Path: fixb/src/main/java/org/fixb/FixConstants.java
// public static final int BEGIN_STRING_TAG = 8;
// 
// Path: fixb/src/test/java/org/fixb/test/TestHelper.java
// public static String fix(String... fields) {
//     StringBuilder result = new StringBuilder();
//     for (String field : fields) {
//         if (result.length() > 0) result.append(SOH);
//         result.append(field);
//     }
// 
//     return result.toString();
// }
// 
// Path: fixb/src/test/java/org/fixb/test/data/SampleQuote.java
// @FixEnum
// public static enum Side {
//     @FixValue("0") BUY,
//     @FixValue("1") SELL;
// }


import static org.mockito.Mockito.when;
import org.fixb.FixException;
import org.fixb.meta.FixEnumMeta;
import org.fixb.meta.FixEnumDictionary;
import org.joda.time.*;
import org.junit.Test;
import java.math.BigDecimal;
import static org.fixb.FixConstants.BEGIN_STRING_TAG;
import static org.fixb.test.TestHelper.fix;
import static org.fixb.test.data.SampleQuote.Side;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
/*
 * Copyright 2013 YTEQ Ltd.
 *
 * 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.fixb.impl;




/**
 */
public class NativeFixMessageBuilderTest {
    private final FixEnumDictionary fixEnumDictionary = mock(FixEnumDictionary.class);
    private final NativeFixMessageBuilder builder = new NativeFixMessageBuilder.Factory(fixEnumDictionary).create();

    {
        when(fixEnumDictionary.getFixEnumMeta(Side.class)).thenReturn(FixEnumMeta.forClass(Side.class));
    }

    @Test
    public void testBuild() throws Exception {
        builder.setField(BEGIN_STRING_TAG, "FIX.5.0");
        builder.setField(11, 'a');
        builder.setField(12, 1);
        builder.setField(13, 11.00);
        builder.setField(14, true);
        builder.setField(15, new BigDecimal("1.23"));
        builder.setField(16, "string");
        builder.setField(17, new LocalDate("2012-02-01").toDateMidnight().toDate());
        builder.setField(18, Side.SELL);

// Path: fixb/src/main/java/org/fixb/FixException.java
// public class FixException extends RuntimeException {
//     private static final long serialVersionUID = 1;
// 
//     /**
//      * @param tag the field tag that has not been found
//      * @param fixMessage the FIX message that does not contain the tag
//      * @return an instance of FixException for a field-not-found case.
//      */
//     public static FixException fieldNotFound(int tag, String fixMessage) {
//         return new FixException("Field [" + tag + "] was not found in message: " + fixMessage);
//     }
// 
//     /**
//      * @param message the exception message
//      * @param cause the exception cause
//      */
//     public FixException(final String message, final Throwable cause) {
//         super(message, cause);
//     }
// 
//     /**
//      * @param cause the exception cause
//      */
//     public FixException(final Throwable cause) {
//         super(cause.getMessage(), cause);
//     }
// 
//     /**
//      * @param message the exception message
//      */
//     public FixException(final String message) {
//         super(message);
//     }
// }
// 
// Path: fixb/src/main/java/org/fixb/meta/FixEnumMeta.java
// public class FixEnumMeta<T extends Enum<T>> {
//     private final Class<T> enumClass;
//     private final BiMap<String, T> enumFixValues;
// 
//     public static <T extends Enum<T>> FixEnumMeta<T> forClass(Class<T> type) {
//         if (!type.isEnum()) {
//             throw new FixException("Expected an enum class, but got [" + type.getName() + "].");
//         }
//         return new FixEnumMeta<>(type);
//     }
// 
//     private FixEnumMeta(Class<T> enumType) {
//         try {
//             final ImmutableBiMap.Builder<String, T> mapBuilder = ImmutableBiMap.builder();
// 
//             for (Field field : enumType.getFields()) {
//                 if (field.isEnumConstant()) {
//                     FixValue fixValue = field.getAnnotation(FixValue.class);
//                     if (fixValue == null) {
//                         throw new FixException("Not all enum values of [" + enumType.getName() + "] have @FixValue annotation: " + field.get(null));
//                     }
//                     mapBuilder.put(fixValue.value(), (T) field.get(null));
//                 }
//             }
// 
//             this.enumClass = enumType;
//             this.enumFixValues = mapBuilder.build();
// 
//         } catch (IllegalAccessException e) {
//             throw new FixException("Invalid FIX enum mapping", e);
//         }
//     }
// 
//     public Class<T> getType() {
//         return enumClass;
//     }
// 
//     public Enum<T> enumForFixValue(String fixValue) {
//         return enumFixValues.get(fixValue);
//     }
// 
//     public String fixValueForEnum(Enum<?> enumValue) {
//         return enumFixValues.inverse().get(enumValue);
//     }
// }
// 
// Path: fixb/src/main/java/org/fixb/meta/FixEnumDictionary.java
// public interface FixEnumDictionary {
//     /**
//      * @param enumType the enum type
//      * @param <T>      the enum type
//      * @return FIX enum value bindings for the given enum type.
//      */
//     <T extends Enum<T>> FixEnumMeta<T> getFixEnumMeta(Class<T> enumType);
// 
//     /**
//      * @param enumType the enum type
//      * @return true if there is a meta object for the given enum class in this dictionary, false otherwise.
//      */
//     boolean hasFixEnumMeta(Class<?> enumType);
// }
// 
// Path: fixb/src/main/java/org/fixb/FixConstants.java
// public static final int BEGIN_STRING_TAG = 8;
// 
// Path: fixb/src/test/java/org/fixb/test/TestHelper.java
// public static String fix(String... fields) {
//     StringBuilder result = new StringBuilder();
//     for (String field : fields) {
//         if (result.length() > 0) result.append(SOH);
//         result.append(field);
//     }
// 
//     return result.toString();
// }
// 
// Path: fixb/src/test/java/org/fixb/test/data/SampleQuote.java
// @FixEnum
// public static enum Side {
//     @FixValue("0") BUY,
//     @FixValue("1") SELL;
// }


// Path: fixb/src/test/java/org/fixb/impl/NativeFixMessageBuilderTest.java
import static org.mockito.Mockito.when;
import org.fixb.FixException;
import org.fixb.meta.FixEnumMeta;
import org.fixb.meta.FixEnumDictionary;
import org.joda.time.*;
import org.junit.Test;
import java.math.BigDecimal;
import static org.fixb.FixConstants.BEGIN_STRING_TAG;
import static org.fixb.test.TestHelper.fix;
import static org.fixb.test.data.SampleQuote.Side;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;

/*
 * Copyright 2013 YTEQ Ltd.
 *
 * 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.fixb.impl;




/**
 */
public class NativeFixMessageBuilderTest {
    private final FixEnumDictionary fixEnumDictionary = mock(FixEnumDictionary.class);
    private final NativeFixMessageBuilder builder = new NativeFixMessageBuilder.Factory(fixEnumDictionary).create();

    {
        when(fixEnumDictionary.getFixEnumMeta(Side.class)).thenReturn(FixEnumMeta.forClass(Side.class));
    }

    @Test
    public void testBuild() throws Exception {
        builder.setField(BEGIN_STRING_TAG, "FIX.5.0");
        builder.setField(11, 'a');
        builder.setField(12, 1);
        builder.setField(13, 11.00);
        builder.setField(14, true);
        builder.setField(15, new BigDecimal("1.23"));
        builder.setField(16, "string");
        builder.setField(17, new LocalDate("2012-02-01").toDateMidnight().toDate());
        builder.setField(18, Side.SELL);

        final String fix = builder.build();