text:
package com.streamsets.pipeline.stage.processor.fieldtypeconverter;

import com.google.common.collect.ImmutableList;
import com.streamsets.pipeline.api.Field;
import com.streamsets.pipeline.api.Record;
import com.streamsets.pipeline.api.StageException;
import com.streamsets.pipeline.api.base.OnRecordErrorException;
import com.streamsets.pipeline.config.DateFormat;
import com.streamsets.pipeline.sdk.ProcessorRunner;
import com.streamsets.pipeline.sdk.RecordCreator;
import com.streamsets.pipeline.sdk.StageRunner;
import org.junit.Assert;
import org.junit.Test;

import java.math.BigDecimal;
import java.nio.charset.Charset;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.TimeZone;

public class TestFieldTypeConverterProcessorFields {

  @Test
  public void testStringToNonExistentField() throws StageException {
    FieldTypeConverterConfig fieldTypeConverterConfig =
      new FieldTypeConverterConfig();
    fieldTypeConverterConfig.fields = ImmutableList.of("/nonExistent", "/beginner", "/expert", "/skilled");
    fieldTypeConverterConfig.targetType = Field.Type.BOOLEAN;
    fieldTypeConverterConfig.dataLocale = "en";

    ProcessorRunner runner = new ProcessorRunner.Builder(FieldTypeConverterDProcessor.class)
      .addConfiguration("convertBy", ConvertBy.BY_FIELD)
      .addConfiguration("fieldTypeConverterConfigs", ImmutableList.of(fieldTypeConverterConfig))
      .addOutputLane("a").build();
    runner.runInit();

    try {
      Map<String, Field> map = new LinkedHashMap<>();
      map.put("beginner", Field.create("false"));
      map.put("intermediate", Field.create("yes"));
      map.put("advanced", Field.create("no"));
      map.put("expert", Field.create("true"));
      map.put("skilled", Field.create("122345566"));
      map.put("null", Field.create(Field.Type.STRING, null));
            Record record = RecordCreator.create("s", "s:1");
      record.set(Field.create(map));

      StageRunner.Output output = runner.runProcess(ImmutableList.of(record));
      Assert.assertEquals(1, output.getRecords().get("a").size());
      Field field = output.getRecords().get("a").get(0).get();
      Assert.assertTrue(field.getValue() instanceof Map);
      Map<String, Field> result = field.getValueAsMap();
      Assert.assertTrue(result.size() == 6);
      Assert.assertTrue(result.containsKey("beginner"));
      Assert.assertEquals(false, result.get("beginner").getValue());
      Assert.assertTrue(result.containsKey("intermediate"));
      Assert.assertEquals("yes", result.get("intermediate").getValue());
      Assert.assertTrue(result.containsKey("advanced"));
      Assert.assertEquals("no", result.get("advanced").getValue());
      Assert.assertTrue(result.containsKey("expert"));
      Assert.assertEquals(true, result.get("expert").getValue());
      Assert.assertTrue(result.containsKey("skilled"));
      Assert.assertEquals(false, result.get("skilled").getValue());
      Assert.assertTrue(result.containsKey("null"));
      Assert.assertEquals(null, result.get("null").getValue());
    } finally {
      runner.runDestroy();
    }
  }

  @Test
  public void testStringToBoolean() throws StageException {
    FieldTypeConverterConfig fieldTypeConverterConfig =
      new FieldTypeConverterConfig();
    fieldTypeConverterConfig.fields = ImmutableList.of("/beginner", "/intermediate", "/skilled", "/advanced", "/expert"
      , "/null");
    fieldTypeConverterConfig.targetType = Field.Type.BOOLEAN;
    fieldTypeConverterConfig.dataLocale = "en";

    ProcessorRunner runner = new ProcessorRunner.Builder(FieldTypeConverterDProcessor.class)
      .addConfiguration("convertBy", ConvertBy.BY_FIELD)
      .addConfiguration("fieldTypeConverterConfigs", ImmutableList.of(fieldTypeConverterConfig))
      .addOutputLane("a").build();
    runner.runInit();

    try {
      Map<String, Field> map = new LinkedHashMap<>();
      map.put("beginner", Field.create("false"));
      map.put("intermediate", Field.create("yes"));
      map.put("advanced", Field.create("no"));
      map.put("expert", Field.create("true"));
      map.put("skilled", Field.create("122345566"));
      map.put("null", Field.create(Field.Type.STRING, null));
            Record record = RecordCreator.create("s", "s:1");
      record.set(Field.create(map));

      StageRunner.Output output = runner.runProcess(ImmutableList.of(record));
      Assert.assertEquals(1, output.getRecords().get("a").size());
      Field field = output.getRecords().get("a").get(0).get();
      Assert.assertTrue(field.getValue() instanceof Map);
      Map<String, Field> result = field.getValueAsMap();
      Assert.assertTrue(result.size() == 6);
      Assert.assertTrue(result.containsKey("beginner"));
      Assert.assertEquals(false, result.get("beginner").getValue());
      Assert.assertTrue(result.containsKey("intermediate"));
      Assert.assertEquals(false, result.get("intermediate").getValue());
      Assert.assertTrue(result.containsKey("advanced"));
      Assert.assertEquals(false, result.get("advanced").getValue());
      Assert.assertTrue(result.containsKey("expert"));
      Assert.assertEquals(true, result.get("expert").getValue());
      Assert.assertTrue(result.containsKey("skilled"));
      Assert.assertEquals(false, result.get("skilled").getValue());
      Assert.assertTrue(result.containsKey("null"));
      Assert.assertEquals(null, result.get("null").getValue());
    } finally {
      runner.runDestroy();
    }
  }

  @Test
  public void testStringToByte() throws StageException {
    FieldTypeConverterConfig fieldTypeConverterConfig =
      new FieldTypeConverterConfig();
    fieldTypeConverterConfig.fields = ImmutableList.of("/beginner", "/intermediate", "/null");
    fieldTypeConverterConfig.targetType = Field.Type.BYTE;
    fieldTypeConverterConfig.dataLocale = "en";

    ProcessorRunner runner = new ProcessorRunner.Builder(FieldTypeConverterDProcessor.class)
      .addConfiguration("convertBy", ConvertBy.BY_FIELD)
      .addConfiguration("fieldTypeConverterConfigs", ImmutableList.of(fieldTypeConverterConfig))
      .addOutputLane("a").build();
    runner.runInit();

    try {
      Map<String, Field> map = new LinkedHashMap<>();
      map.put("beginner", Field.create("1"));
      map.put("intermediate", Field.create("126"));
      map.put("null", Field.create(Field.Type.STRING, null));
            Record record = RecordCreator.create("s", "s:1");
      record.set(Field.create(map));

      StageRunner.Output output = runner.runProcess(ImmutableList.of(record));
      Assert.assertEquals(1, output.getRecords().get("a").size());
      Field field = output.getRecords().get("a").get(0).get();
      Assert.assertTrue(field.getValue() instanceof Map);
      Map<String, Field> result = field.getValueAsMap();
      Assert.assertTrue(result.size() == 3);
      Assert.assertTrue(result.containsKey("beginner"));
      Assert.assertEquals((byte)1, result.get("beginner").getValue());
      Assert.assertTrue(result.containsKey("intermediate"));
      Assert.assertEquals((byte)126, result.get("intermediate").getValue());
      Assert.assertTrue(result.containsKey("null"));
      Assert.assertEquals(null, result.get("null").getValue());
    } finally {
      runner.runDestroy();
    }
  }

  @Test
  public void testStringToChar() throws StageException {
    FieldTypeConverterConfig fieldTypeConverterConfig =
      new FieldTypeConverterConfig();
    fieldTypeConverterConfig.fields = ImmutableList.of("/beginner", "/intermediate", "/null");
    fieldTypeConverterConfig.targetType = Field.Type.CHAR;
    fieldTypeConverterConfig.dataLocale = "en";

    ProcessorRunner runner = new ProcessorRunner.Builder(FieldTypeConverterDProcessor.class)
      .addConfiguration("convertBy", ConvertBy.BY_FIELD)
      .addConfiguration("fieldTypeConverterConfigs", ImmutableList.of(fieldTypeConverterConfig))
      .addOutputLane("a").build();
    runner.runInit();

    try {
      Map<String, Field> map = new LinkedHashMap<>();
      map.put("beginner", Field.create("a"));
      map.put("intermediate", Field.create("yes"));
      map.put("null", Field.create(Field.Type.STRING, null));
            Record record = RecordCreator.create("s", "s:1");
      record.set(Field.create(map));

      StageRunner.Output output = runner.runProcess(ImmutableList.of(record));
      Assert.assertEquals(1, output.getRecords().get("a").size());
      Field field = output.getRecords().get("a").get(0).get();
      Assert.assertTrue(field.getValue() instanceof Map);
      Map<String, Field> result = field.getValueAsMap();
      Assert.assertTrue(result.size() == 3);
      Assert.assertTrue(result.containsKey("beginner"));
      Assert.assertEquals('a', result.get("beginner").getValue());
      Assert.assertTrue(result.containsKey("intermediate"));
      Assert.assertEquals('y', result.get("intermediate").getValue());
      Assert.assertTrue(result.containsKey("null"));
      Assert.assertEquals(null, result.get("null").getValue());
    } finally {
      runner.runDestroy();
    }
  }

  @Test
  public void testStringToByteArray() throws StageException {
    FieldTypeConverterConfig fieldTypeConverterConfig =
      new FieldTypeConverterConfig();
    fieldTypeConverterConfig.fields = ImmutableList.of("/beginner", "/intermediate", "/null");
    fieldTypeConverterConfig.targetType = Field.Type.BYTE_ARRAY;
    fieldTypeConverterConfig.dataLocale = "en";

    ProcessorRunner runner = new ProcessorRunner.Builder(FieldTypeConverterDProcessor.class)
      .addConfiguration("convertBy", ConvertBy.BY_FIELD)
      .addConfiguration("fieldTypeConverterConfigs", ImmutableList.of(fieldTypeConverterConfig))
      .addOutputLane("a").build();
    runner.runInit();

    try {
      Map<String, Field> map = new LinkedHashMap<>();
      map.put("beginner", Field.create("abc"));
      map.put("intermediate", Field.create("yes"));
      map.put("null", Field.create(Field.Type.STRING, null));
      Record record = RecordCreator.create("s", "s:1");
      record.set(Field.create(map));

      StageRunner.Output output = runner.runProcess(ImmutableList.of(record));
      Assert.assertEquals(1, output.getRecords().get("a").size());
      Field field = output.getRecords().get("a").get(0).get();
      Assert.assertTrue(field.getValue() instanceof Map);
      Map<String, Field> result = field.getValueAsMap();
      Assert.assertTrue(result.size() == 3);
      Assert.assertTrue(result.containsKey("beginner"));
      Assert.assertTrue(Arrays.equals("abc".getBytes(), (byte[]) result.get("beginner").getValue()));
      Assert.assertTrue(result.containsKey("intermediate"));
      Assert.assertTrue(Arrays.equals("yes".getBytes(), (byte[]) result.get("intermediate").getValue()));
      Assert.assertTrue(result.containsKey("null"));
      Assert.assertEquals(null, result.get("null").getValue());
    } finally {
      runner.runDestroy();
    }
  }

  @Test
  public void testStringToDecimalEnglishLocale() throws StageException {
    FieldTypeConverterConfig fieldTypeConverterConfig =
      new FieldTypeConverterConfig();
    fieldTypeConverterConfig.fields = ImmutableList.of("/beginner", "/intermediate", "/advanced", "/expert",
      "/skilled", "/null");
    fieldTypeConverterConfig.targetType = Field.Type.DECIMAL;
    fieldTypeConverterConfig.dataLocale = "en";

    ProcessorRunner runner = new ProcessorRunner.Builder(FieldTypeConverterDProcessor.class)
      .addConfiguration("convertBy", ConvertBy.BY_FIELD)
      .addConfiguration("fieldTypeConverterConfigs", ImmutableList.of(fieldTypeConverterConfig))
      .addOutputLane("a").build();
    runner.runInit();

    try {
      Map<String, Field> map = new LinkedHashMap<>();
      map.put("expert", Field.create("1.234"));
      map.put("advanced", Field.create("1,234"));
      map.put("beginner", Field.create("1,234.56789"));
      map.put("intermediate", Field.create("1.234,56789"));
      map.put("skilled", Field.create("-1.23E-12"));
      map.put("null", Field.create(Field.Type.STRING, null));
            Record record = RecordCreator.create("s", "s:1");
      record.set(Field.create(map));

      StageRunner.Output output = runner.runProcess(ImmutableList.of(record));
      Assert.assertEquals(1, output.getRecords().get("a").size());
      Field field = output.getRecords().get("a").get(0).get();
      Assert.assertTrue(field.getValue() instanceof Map);
      Map<String, Field> result = field.getValueAsMap();
      Assert.assertTrue(result.size() == 6);
      Assert.assertTrue(result.containsKey("beginner"));
      Assert.assertEquals(BigDecimal.valueOf(1234.56789), result.get("beginner").getValue());
      Assert.assertTrue(result.containsKey("intermediate"));
      Assert.assertEquals(BigDecimal.valueOf(1.234), result.get("intermediate").getValue());
      Assert.assertTrue(result.containsKey("null"));
      Assert.assertEquals(null, result.get("null").getValue());
      Assert.assertEquals(BigDecimal.valueOf(1.234), result.get("expert").getValue());
      Assert.assertTrue(result.containsKey("expert"));
      Assert.assertEquals(BigDecimal.valueOf(1234), result.get("advanced").getValue());
      Assert.assertTrue(result.containsKey("advanced"));
      Assert.assertTrue(result.containsKey("skilled"));
      Assert.assertEquals(BigDecimal.valueOf(-1.23E-12), result.get("skilled").getValue());
    } finally {
      runner.runDestroy();
    }
  }

  @Test
  public void testStringToDecimalGermanLocale() throws StageException {
    FieldTypeConverterConfig fieldTypeConverterConfig =
      new FieldTypeConverterConfig();
    fieldTypeConverterConfig.fields = ImmutableList.of("/beginner", "/intermediate", "/advanced", "/expert",
      "/skilled", "/null");
    fieldTypeConverterConfig.targetType = Field.Type.DECIMAL;
    fieldTypeConverterConfig.dataLocale = "de";

    ProcessorRunner runner = new ProcessorRunner.Builder(FieldTypeConverterDProcessor.class)
      .addConfiguration("convertBy", ConvertBy.BY_FIELD)
      .addConfiguration("fieldTypeConverterConfigs", ImmutableList.of(fieldTypeConverterConfig))
      .addOutputLane("a").build();
    runner.runInit();

    try {
      Map<String, Field> map = new LinkedHashMap<>();
      map.put("expert", Field.create("1234.5678"));
      map.put("advanced", Field.create("1234"));
      map.put("beginner", Field.create("1,234.56789"));
      map.put("intermediate", Field.create("1.234,56789"));
      map.put("skilled", Field.create("-1.23E-12"));
      map.put("null", Field.create(Field.Type.STRING, null));
            Record record = RecordCreator.create("s", "s:1");
      record.set(Field.create(map));

      StageRunner.Output output = runner.runProcess(ImmutableList.of(record));
      Assert.assertEquals(1, output.getRecords().get("a").size());
      Field field = output.getRecords().get("a").get(0).get();
      Assert.assertTrue(field.getValue() instanceof Map);
      Map<String, Field> result = field.getValueAsMap();
      Assert.assertTrue(result.size() == 6);
      Assert.assertTrue(result.containsKey("beginner"));
      Assert.assertEquals(BigDecimal.valueOf(1.234), result.get("beginner").getValue());
      Assert.assertTrue(result.containsKey("intermediate"));
      Assert.assertEquals(BigDecimal.valueOf(1234.56789), result.get("intermediate").getValue());
      Assert.assertTrue(result.containsKey("null"));
      Assert.assertEquals(null, result.get("null").getValue());
      Assert.assertTrue(result.containsKey("expert"));
      Assert.assertEquals(BigDecimal.valueOf(12345678), result.get("expert").getValue());
      Assert.assertTrue(result.containsKey("advanced"));
      Assert.assertEquals(BigDecimal.valueOf(1234), result.get("advanced").getValue());
      Assert.assertTrue(result.containsKey("skilled"));
      //FIXME<Hari>: Is this ok?
      Assert.assertEquals(BigDecimal.valueOf(-1.23E-10), result.get("skilled").getValue());
    } finally {
      runner.runDestroy();
    }
  }

  @Test
  public void testStringToDoubleEnglishLocale() throws StageException {
    FieldTypeConverterConfig fieldTypeConverterConfig =
      new FieldTypeConverterConfig();
    fieldTypeConverterConfig.fields = ImmutableList.of("/beginner", "/intermediate", "/advanced", "/expert",
      "/skilled", "/null");
    fieldTypeConverterConfig.targetType = Field.Type.DOUBLE;
    fieldTypeConverterConfig.dataLocale = "en";

    ProcessorRunner runner = new ProcessorRunner.Builder(FieldTypeConverterDProcessor.class)
      .addConfiguration("convertBy", ConvertBy.BY_FIELD)
      .addConfiguration("fieldTypeConverterConfigs", ImmutableList.of(fieldTypeConverterConfig))
      .addOutputLane("a").build();
    runner.runInit();

    try {
      Map<String, Field> map = new LinkedHashMap<>();
      map.put("expert", Field.create("1.234"));
      map.put("advanced", Field.create("1,234"));
      map.put("beginner", Field.create("1,234.56789"));
      map.put("intermediate", Field.create("1.234,56789"));
      map.put("skilled", Field.create("-1.23E-12"));
      map.put("null", Field.create(Field.Type.STRING, null));
            Record record = RecordCreator.create("s", "s:1");
      record.set(Field.create(map));

      StageRunner.Output output = runner.runProcess(ImmutableList.of(record));
      Assert.assertEquals(1, output.getRecords().get("a").size());
      Field field = output.getRecords().get("a").get(0).get();
      Assert.assertTrue(field.getValue() instanceof Map);
      Map<String, Field> result = field.getValueAsMap();
      Assert.assertTrue(result.size() == 6);
      Assert.assertTrue(result.containsKey("beginner"));
      Assert.assertEquals(1234.56789, result.get("beginner").getValue());
      Assert.assertTrue(result.containsKey("intermediate"));
      Assert.assertEquals(1.234, result.get("intermediate").getValue());
      Assert.assertTrue(result.containsKey("null"));
      Assert.assertEquals(null, result.get("null").getValue());
      Assert.assertEquals(1.234, result.get("expert").getValue());
      Assert.assertTrue(result.containsKey("expert"));
      Assert.assertEquals((double) 1234, result.get("advanced").getValue());
      Assert.assertTrue(result.containsKey("advanced"));
      Assert.assertTrue(result.containsKey("skilled"));
      Assert.assertEquals(-1.23E-12, result.get("skilled").getValue());
    } finally {
      runner.runDestroy();
    }
  }

  @Test
  public void testStringToDoubleGermanLocale() throws StageException {
    FieldTypeConverterConfig fieldTypeConverterConfig =
      new FieldTypeConverterConfig();
    fieldTypeConverterConfig.fields = ImmutableList.of("/beginner", "/intermediate", "/advanced", "/expert",
      "/skilled", "/null");
    fieldTypeConverterConfig.targetType = Field.Type.DECIMAL;
    fieldTypeConverterConfig.dataLocale = "de";

    ProcessorRunner runner = new ProcessorRunner.Builder(FieldTypeConverterDProcessor.class)
      .addConfiguration("convertBy", ConvertBy.BY_FIELD)
      .addConfiguration("fieldTypeConverterConfigs", ImmutableList.of(fieldTypeConverterConfig))
      .addOutputLane("a").build();
    runner.runInit();

    try {
      Map<String, Field> map = new LinkedHashMap<>();
      map.put("expert", Field.create("1234.5678"));
      map.put("advanced", Field.create("1234"));
      map.put("beginner", Field.create("1,234.56789"));
      map.put("intermediate", Field.create("1.234,56789"));
      map.put("skilled", Field.create("-1.23E-12"));
      map.put("null", Field.create(Field.Type.STRING, null));
            Record record = RecordCreator.create("s", "s:1");
      record.set(Field.create(map));

      StageRunner.Output output = runner.runProcess(ImmutableList.of(record));
      Assert.assertEquals(1, output.getRecords().get("a").size());
      Field field = output.getRecords().get("a").get(0).get();
      Assert.assertTrue(field.getValue() instanceof Map);
      Map<String, Field> result = field.getValueAsMap();
      Assert.assertTrue(result.size() == 6);
      Assert.assertTrue(result.containsKey("beginner"));
      Assert.assertEquals(BigDecimal.valueOf(1.234), result.get("beginner").getValue());
      Assert.assertTrue(result.containsKey("intermediate"));
      Assert.assertEquals(BigDecimal.valueOf(1234.56789), result.get("intermediate").getValue());
      Assert.assertTrue(result.containsKey("null"));
      Assert.assertEquals(null, result.get("null").getValue());
      Assert.assertTrue(result.containsKey("expert"));
      Assert.assertEquals(BigDecimal.valueOf(12345678), result.get("expert").getValue());
      Assert.assertTrue(result.containsKey("advanced"));
      Assert.assertEquals(BigDecimal.valueOf(1234), result.get("advanced").getValue());
      Assert.assertTrue(result.containsKey("skilled"));
      //FIXME<Hari>: Is this ok?
      Assert.assertEquals(BigDecimal.valueOf(-1.23E-10), result.get("skilled").getValue());
    } finally {
      runner.runDestroy();
    }
  }

  @Test
  public void testStringToIntegerEnglishLocale() throws StageException {
    FieldTypeConverterConfig fieldTypeConverterConfig =
      new FieldTypeConverterConfig();
    fieldTypeConverterConfig.fields = ImmutableList.of("/beginner", "/intermediate", "/skilled", "/advanced",
      "/expert", "/null");
    fieldTypeConverterConfig.targetType = Field.Type.INTEGER;
    fieldTypeConverterConfig.dataLocale = "en";

    ProcessorRunner runner = new ProcessorRunner.Builder(FieldTypeConverterDProcessor.class)
      .addConfiguration("convertBy", ConvertBy.BY_FIELD)
      .addConfiguration("fieldTypeConverterConfigs", ImmutableList.of(fieldTypeConverterConfig))
      .addOutputLane("a").build();
    runner.runInit();

    try {
      Map<String, Field> map = new LinkedHashMap<>();
      map.put("beginner", Field.create("-12234"));
      map.put("intermediate", Field.create("-1,234"));
      map.put("advanced", Field.create("12,567"));
      map.put("expert", Field.create("1.234"));
      map.put("skilled", Field.create("1234"));
      map.put("null", Field.create(Field.Type.STRING, null));
            Record record = RecordCreator.create("s", "s:1");
      record.set(Field.create(map));

      StageRunner.Output output = runner.runProcess(ImmutableList.of(record));
      Assert.assertEquals(1, output.getRecords().get("a").size());
      Field field = output.getRecords().get("a").get(0).get();
      Assert.assertTrue(field.getValue() instanceof Map);
      Map<String, Field> result = field.getValueAsMap();
      Assert.assertTrue(result.size() == 6);
      Assert.assertTrue(result.containsKey("beginner"));
      Assert.assertEquals(-12234, result.get("beginner").getValue());
      Assert.assertTrue(result.containsKey("intermediate"));
      Assert.assertEquals(-1234, result.get("intermediate").getValue());
      Assert.assertTrue(result.containsKey("advanced"));
      Assert.assertEquals(12567, result.get("advanced").getValue());
      Assert.assertTrue(result.containsKey("expert"));
      Assert.assertEquals(1, result.get("expert").getValue());
      Assert.assertTrue(result.containsKey("skilled"));
      Assert.assertEquals(1234, result.get("skilled").getValue());
      Assert.assertTrue(result.containsKey("null"));
      Assert.assertEquals(null, result.get("null").getValue());
    } finally {
      runner.runDestroy();
    }
  }

  @Test
  public void testStringToIntegerGermanLocale() throws StageException {
    FieldTypeConverterConfig fieldTypeConverterConfig =
      new FieldTypeConverterConfig();
    fieldTypeConverterConfig.fields = ImmutableList.of("/beginner", "/intermediate", "/skilled", "/advanced",
      "/expert", "/null");
    fieldTypeConverterConfig.targetType = Field.Type.INTEGER;
    fieldTypeConverterConfig.dataLocale = "de";

    ProcessorRunner runner = new ProcessorRunner.Builder(FieldTypeConverterDProcessor.class)
      .addConfiguration("convertBy", ConvertBy.BY_FIELD)
      .addConfiguration("fieldTypeConverterConfigs", ImmutableList.of(fieldTypeConverterConfig))
      .addOutputLane("a").build();
    runner.runInit();

    try {
      Map<String, Field> map = new LinkedHashMap<>();
      map.put("beginner", Field.create("-12234"));
      map.put("intermediate", Field.create("-1,234"));
      map.put("advanced", Field.create("12,567"));
      map.put("expert", Field.create("1.234"));
      map.put("skilled", Field.create("1234"));
      map.put("null", Field.create(Field.Type.STRING, null));
            Record record = RecordCreator.create("s", "s:1");
      record.set(Field.create(map));

      StageRunner.Output output = runner.runProcess(ImmutableList.of(record));
      Assert.assertEquals(1, output.getRecords().get("a").size());
      Field field = output.getRecords().get("a").get(0).get();
      Assert.assertTrue(field.getValue() instanceof Map);
      Map<String, Field> result = field.getValueAsMap();
      Assert.assertTrue(result.size() == 6);
      Assert.assertTrue(result.containsKey("beginner"));
      Assert.assertEquals(-12234, result.get("beginner").getValue());
      Assert.assertTrue(result.containsKey("intermediate"));
      Assert.assertEquals(-1, result.get("intermediate").getValue());
      Assert.assertTrue(result.containsKey("advanced"));
      Assert.assertEquals(12, result.get("advanced").getValue());
      Assert.assertTrue(result.containsKey("expert"));
      Assert.assertEquals(1234, result.get("expert").getValue());
      Assert.assertTrue(result.containsKey("skilled"));
      Assert.assertEquals(1234, result.get("skilled").getValue());
      Assert.assertTrue(result.containsKey("null"));
      Assert.assertEquals(null, result.get("null").getValue());
    } finally {
      runner.runDestroy();
    }
  }

  @Test
  public void testStringToLongEnglishLocale() throws StageException {
    FieldTypeConverterConfig fieldTypeConverterConfig =
      new FieldTypeConverterConfig();
    fieldTypeConverterConfig.fields = ImmutableList.of("/beginner", "/intermediate", "/skilled", "/advanced",
      "/expert", "/null");
    fieldTypeConverterConfig.targetType = Field.Type.LONG;
    fieldTypeConverterConfig.dataLocale = "en";

    ProcessorRunner runner = new ProcessorRunner.Builder(FieldTypeConverterDProcessor.class)
      .addConfiguration("convertBy", ConvertBy.BY_FIELD)
      .addConfiguration("fieldTypeConverterConfigs", ImmutableList.of(fieldTypeConverterConfig))
      .addOutputLane("a").build();
    runner.runInit();

    try {
      Map<String, Field> map = new LinkedHashMap<>();
      map.put("beginner", Field.create("12345678910"));
      map.put("intermediate", Field.create("10L"));
      map.put("advanced", Field.create("-10L"));
      map.put("expert", Field.create("12,345,678,910"));
      map.put("skilled", Field.create("12.345.678.910"));
      map.put("null", Field.create(Field.Type.STRING, null));
            Record record = RecordCreator.create("s", "s:1");
      record.set(Field.create(map));

      StageRunner.Output output = runner.runProcess(ImmutableList.of(record));
      Assert.assertEquals(1, output.getRecords().get("a").size());
      Field field = output.getRecords().get("a").get(0).get();
      Assert.assertTrue(field.getValue() instanceof Map);
      Map<String, Field> result = field.getValueAsMap();
      Assert.assertTrue(result.size() == 6);
      Assert.assertTrue(result.containsKey("beginner"));
      Assert.assertEquals(12345678910L, result.get("beginner").getValue());
      Assert.assertTrue(result.containsKey("intermediate"));
      Assert.assertEquals(10L, result.get("intermediate").getValue());
      Assert.assertTrue(result.containsKey("skilled"));
      Assert.assertEquals(12L, result.get("skilled").getValue());
      Assert.assertTrue(result.containsKey("expert"));
      Assert.assertEquals(12345678910L, result.get("expert").getValue());
      Assert.assertTrue(result.containsKey("advanced"));
      Assert.assertEquals(-10L, result.get("advanced").getValue());
      Assert.assertTrue(result.containsKey("null"));
      Assert.assertEquals(null, result.get("null").getValue());
    } finally {
      runner.runDestroy();
    }
  }

  @Test
  public void testStringToLongGermanLocale() throws StageException {
    FieldTypeConverterConfig fieldTypeConverterConfig =
      new FieldTypeConverterConfig();
    fieldTypeConverterConfig.fields = ImmutableList.of("/beginner", "/intermediate", "/skilled", "/advanced",
      "/expert", "/null");
    fieldTypeConverterConfig.targetType = Field.Type.LONG;
    fieldTypeConverterConfig.dataLocale = "de";

    ProcessorRunner runner = new ProcessorRunner.Builder(FieldTypeConverterDProcessor.class)
      .addConfiguration("convertBy", ConvertBy.BY_FIELD)
      .addConfiguration("fieldTypeConverterConfigs", ImmutableList.of(fieldTypeConverterConfig))
      .addOutputLane("a").build();
    runner.runInit();

    try {
      Map<String, Field> map = new LinkedHashMap<>();
      map.put("beginner", Field.create("12345678910"));
      map.put("intermediate", Field.create("10L"));
      map.put("advanced", Field.create("-10L"));
      map.put("expert", Field.create("12,345,678,910"));
      map.put("skilled", Field.create("12.345.678.910"));
      map.put("null", Field.create(Field.Type.STRING, null));
            Record record = RecordCreator.create("s", "s:1");
      record.set(Field.create(map));

      StageRunner.Output output = runner.runProcess(ImmutableList.of(record));
      Assert.assertEquals(1, output.getRecords().get("a").size());
      Field field = output.getRecords().get("a").get(0).get();
      Assert.assertTrue(field.getValue() instanceof Map);
      Map<String, Field> result = field.getValueAsMap();
      Assert.assertTrue(result.size() == 6);
      Assert.assertTrue(result.containsKey("beginner"));
      Assert.assertEquals(12345678910L, result.get("beginner").getValue());
      Assert.assertTrue(result.containsKey("intermediate"));
      Assert.assertEquals(10L, result.get("intermediate").getValue());
      Assert.assertTrue(result.containsKey("skilled"));
      Assert.assertEquals(12345678910L, result.get("skilled").getValue());
      Assert.assertTrue(result.containsKey("expert"));
      Assert.assertEquals(12L, result.get("expert").getValue());
      Assert.assertTrue(result.containsKey("advanced"));
      Assert.assertEquals(-10L, result.get("advanced").getValue());
      Assert.assertTrue(result.containsKey("null"));
      Assert.assertEquals(null, result.get("null").getValue());
    } finally {
      runner.runDestroy();
    }
  }

  @Test
  public void testStringToShortEnglishLocale() throws StageException {
    FieldTypeConverterConfig fieldTypeConverterConfig =
      new FieldTypeConverterConfig();
    fieldTypeConverterConfig.fields = ImmutableList.of("/beginner", "/intermediate", "/skilled", "/advanced",
      "/expert", "/null");
    fieldTypeConverterConfig.targetType = Field.Type.SHORT;
    fieldTypeConverterConfig.dataLocale = "en";

    ProcessorRunner runner = new ProcessorRunner.Builder(FieldTypeConverterDProcessor.class)
      .addConfiguration("convertBy", ConvertBy.BY_FIELD)
      .addConfiguration("fieldTypeConverterConfigs", ImmutableList.of(fieldTypeConverterConfig))
      .addOutputLane("a").build();
    runner.runInit();

    try {
      Map<String, Field> map = new LinkedHashMap<>();
      map.put("beginner", Field.create("32768"));
      map.put("intermediate", Field.create("10"));
      map.put("advanced", Field.create("42768"));
      map.put("expert", Field.create("-32,767"));
      map.put("skilled", Field.create("32.767"));
      map.put("null", Field.create(Field.Type.STRING, null));
            Record record = RecordCreator.create("s", "s:1");
      record.set(Field.create(map));

      StageRunner.Output output = runner.runProcess(ImmutableList.of(record));
      Assert.assertEquals(1, output.getRecords().get("a").size());
      Field field = output.getRecords().get("a").get(0).get();
      Assert.assertTrue(field.getValue() instanceof Map);
      Map<String, Field> result = field.getValueAsMap();
      Assert.assertTrue(result.size() == 6);
      Assert.assertTrue(result.containsKey("beginner"));
      Assert.assertEquals((short)32768, result.get("beginner").getValue());
      Assert.assertTrue(result.containsKey("intermediate"));
      Assert.assertEquals((short)10, result.get("intermediate").getValue());
      Assert.assertTrue(result.containsKey("skilled"));
      Assert.assertEquals((short)32, result.get("skilled").getValue());
      Assert.assertTrue(result.containsKey("expert"));
      Assert.assertEquals((short)-32767, result.get("expert").getValue());
      Assert.assertTrue(result.containsKey("advanced"));
      Assert.assertEquals((short)-22768, result.get("advanced").getValue());
      Assert.assertTrue(result.containsKey("null"));
      Assert.assertEquals(null, result.get("null").getValue());
    } finally {
      runner.runDestroy();
    }
  }

  @Test
  public void testStringToShortGermanLocale() throws StageException {
    FieldTypeConverterConfig fieldTypeConverterConfig =
      new FieldTypeConverterConfig();
    fieldTypeConverterConfig.fields = ImmutableList.of("/beginner", "/intermediate", "/skilled", "/advanced",
      "/expert", "/null");
    fieldTypeConverterConfig.targetType = Field.Type.SHORT;
    fieldTypeConverterConfig.dataLocale = "de";

    ProcessorRunner runner = new ProcessorRunner.Builder(FieldTypeConverterDProcessor.class)
      .addConfiguration("convertBy", ConvertBy.BY_FIELD)
      .addConfiguration("fieldTypeConverterConfigs", ImmutableList.of(fieldTypeConverterConfig))
      .addOutputLane("a").build();
    runner.runInit();

    try {
      Map<String, Field> map = new LinkedHashMap<>();
      map.put("beginner", Field.create("32768"));
      map.put("intermediate", Field.create("10"));
      map.put("advanced", Field.create("42768"));
      map.put("expert", Field.create("-32,767"));
      map.put("skilled", Field.create("32.767"));
      map.put("null", Field.create(Field.Type.STRING, null));
            Record record = RecordCreator.create("s", "s:1");
      record.set(Field.create(map));

      StageRunner.Output output = runner.runProcess(ImmutableList.of(record));
      Assert.assertEquals(1, output.getRecords().get("a").size());
      Field field = output.getRecords().get("a").get(0).get();
      Assert.assertTrue(field.getValue() instanceof Map);
      Map<String, Field> result = field.getValueAsMap();
      Assert.assertTrue(result.size() == 6);
      Assert.assertTrue(result.containsKey("beginner"));
      Assert.assertEquals((short)32768, result.get("beginner").getValue());
      Assert.assertTrue(result.containsKey("intermediate"));
      Assert.assertEquals((short)10, result.get("intermediate").getValue());
      Assert.assertTrue(result.containsKey("skilled"));
      Assert.assertEquals((short)32767, result.get("skilled").getValue());
      Assert.assertTrue(result.containsKey("expert"));
      Assert.assertEquals((short)-32, result.get("expert").getValue());
      Assert.assertTrue(result.containsKey("advanced"));
      Assert.assertEquals((short)-22768, result.get("advanced").getValue());
      Assert.assertTrue(result.containsKey("null"));
      Assert.assertEquals(null, result.get("null").getValue());
    } finally {
      runner.runDestroy();
    }
  }

  @Test
  public void testStringToFloatEnglishLocale() throws StageException {
    FieldTypeConverterConfig fieldTypeConverterConfig =
      new FieldTypeConverterConfig();
    fieldTypeConverterConfig.fields = ImmutableList.of("/beginner", "/intermediate", "/skilled", "/advanced",
      "/expert", "/null");
    fieldTypeConverterConfig.targetType = Field.Type.FLOAT;
    fieldTypeConverterConfig.dataLocale = "en";

    ProcessorRunner runner = new ProcessorRunner.Builder(FieldTypeConverterDProcessor.class)
      .addConfiguration("convertBy", ConvertBy.BY_FIELD)
      .addConfiguration("fieldTypeConverterConfigs", ImmutableList.of(fieldTypeConverterConfig))
      .addOutputLane("a").build();
    runner.runInit();

    try {
      Map<String, Field> map = new LinkedHashMap<>();
      map.put("beginner", Field.create("10.4f"));
      map.put("intermediate", Field.create("2.3842e-07f"));
      map.put("advanced", Field.create("3.14157"));
      map.put("expert", Field.create("-3,767.45"));
      map.put("skilled", Field.create("3.767,45"));
      map.put("null", Field.create(Field.Type.STRING, null));
            Record record = RecordCreator.create("s", "s:1");
      record.set(Field.create(map));

      StageRunner.Output output = runner.runProcess(ImmutableList.of(record));
      Assert.assertEquals(1, output.getRecords().get("a").size());
      Field field = output.getRecords().get("a").get(0).get();
      Assert.assertTrue(field.getValue() instanceof Map);
      Map<String, Field> result = field.getValueAsMap();
      Assert.assertTrue(result.size() == 6);
      Assert.assertTrue(result.containsKey("beginner"));
      Assert.assertEquals(10.4f, result.get("beginner").getValue());
      Assert.assertTrue(result.containsKey("intermediate"));
//      Assert.assertEquals(2.3842e-07f, result.get("intermediate").getValue());
      Assert.assertTrue(result.containsKey("skilled"));
      Assert.assertEquals(3.767f, result.get("skilled").getValue());
      Assert.assertTrue(result.containsKey("expert"));
      Assert.assertEquals(-3767.45f, result.get("expert").getValue());
      Assert.assertTrue(result.containsKey("advanced"));
      Assert.assertEquals(3.14157f, result.get("advanced").getValue());
      Assert.assertTrue(result.containsKey("null"));
      Assert.assertEquals(null, result.get("null").getValue());
    } finally {
      runner.runDestroy();
    }
  }

  @Test
  public void testStringToFloatGermanLocale() throws StageException {
    FieldTypeConverterConfig fieldTypeConverterConfig =
      new FieldTypeConverterConfig();
    fieldTypeConverterConfig.fields = ImmutableList.of("/beginner", "/intermediate", "/skilled", "/advanced",
      "/expert", "/null");
    fieldTypeConverterConfig.targetType = Field.Type.FLOAT;
    fieldTypeConverterConfig.dataLocale = "de";

    ProcessorRunner runner = new ProcessorRunner.Builder(FieldTypeConverterDProcessor.class)
      .addConfiguration("convertBy", ConvertBy.BY_FIELD)
      .addConfiguration("fieldTypeConverterConfigs", ImmutableList.of(fieldTypeConverterConfig))
      .addOutputLane("a").build();
    runner.runInit();

    try {
      Map<String, Field> map = new LinkedHashMap<>();
      map.put("beginner", Field.create("10.4f"));
      map.put("intermediate", Field.create("2.3842e-07f"));
      map.put("advanced", Field.create("3.14157"));
      map.put("expert", Field.create("-3,767.45"));
      map.put("skilled", Field.create("3.767,45"));
      map.put("null", Field.create(Field.Type.STRING, null));
            Record record = RecordCreator.create("s", "s:1");
      record.set(Field.create(map));

      StageRunner.Output output = runner.runProcess(ImmutableList.of(record));
      Assert.assertEquals(1, output.getRecords().get("a").size());
      Field field = output.getRecords().get("a").get(0).get();
      Assert.assertTrue(field.getValue() instanceof Map);
      Map<String, Field> result = field.getValueAsMap();
      Assert.assertTrue(result.size() == 6);
      Assert.assertTrue(result.containsKey("beginner"));
      Assert.assertEquals(104f, result.get("beginner").getValue());
      Assert.assertTrue(result.containsKey("intermediate"));
//      Assert.assertEquals(2.3842e-07f, result.get("intermediate").getValue());
      Assert.assertTrue(result.containsKey("skilled"));
      Assert.assertEquals(3767.45f, result.get("skilled").getValue());
      Assert.assertTrue(result.containsKey("expert"));
      Assert.assertEquals(-3.767f, result.get("expert").getValue());
      Assert.assertTrue(result.containsKey("advanced"));
      Assert.assertEquals(314157f, result.get("advanced").getValue());
      Assert.assertTrue(result.containsKey("null"));
      Assert.assertEquals(null, result.get("null").getValue());
    } finally {
      runner.runDestroy();
    }
  }

  public void testStringToDateTimeTypes(Field.Type type) throws Exception {
        FieldTypeConverterConfig beginnerConfig =
      new FieldTypeConverterConfig();
    beginnerConfig.fields = ImmutableList.of("/beginner");
    beginnerConfig.targetType = type;
    beginnerConfig.dataLocale = "en";
    beginnerConfig.dateFormat = DateFormat.OTHER;
    beginnerConfig.otherDateFormat ="yyyy-MM-dd";

    FieldTypeConverterConfig intermediateConfig =
      new FieldTypeConverterConfig();
    intermediateConfig.fields = ImmutableList.of("/intermediate");
    intermediateConfig.targetType = type;
    intermediateConfig.dataLocale = "en";
    intermediateConfig.dateFormat = DateFormat.OTHER;
    intermediateConfig.otherDateFormat = "dd-MM-YYYY";

    FieldTypeConverterConfig skilledConfig =
      new FieldTypeConverterConfig();
    skilledConfig.fields = ImmutableList.of("/skilled");
    skilledConfig.targetType = type;
    skilledConfig.dataLocale = "en";
    skilledConfig.dateFormat = DateFormat.OTHER;
    skilledConfig.otherDateFormat = "yyyy-MM-dd HH:mm:ss";

    FieldTypeConverterConfig advancedConfig =
      new FieldTypeConverterConfig();
    advancedConfig.fields = ImmutableList.of("/advanced");
    advancedConfig.targetType = type;
    advancedConfig.dataLocale = "en";
    advancedConfig.dateFormat = DateFormat.OTHER;
    advancedConfig.otherDateFormat = "yyyy-MM-dd HH:mm:ss.SSS";

    FieldTypeConverterConfig expertConfig =
      new FieldTypeConverterConfig();
    expertConfig.fields = ImmutableList.of("/expert");
    expertConfig.targetType = type;
    expertConfig.dataLocale = "en";
    expertConfig.dateFormat = DateFormat.OTHER;
    expertConfig.otherDateFormat = "yyyy-MM-dd HH:mm:ss.SSS Z";

    ProcessorRunner runner = new ProcessorRunner.Builder(FieldTypeConverterDProcessor.class)
      .addConfiguration("convertBy", ConvertBy.BY_FIELD)
      .addConfiguration("fieldTypeConverterConfigs", ImmutableList.of(beginnerConfig, advancedConfig,
        intermediateConfig, skilledConfig, expertConfig))
      .addOutputLane("a").build();
    runner.runInit();

    try {
      Map<String, Field> map = new LinkedHashMap<>();
      map.put("beginner", Field.create("2015-01-03")); //
      map.put("intermediate", Field.create("03-01-2015"));
      map.put("advanced", Field.create("2015-01-03 21:31:02.777"));//
      map.put("expert", Field.create("2015-01-03 21:32:32.333 PST"));//
      map.put("skilled", Field.create("2015-01-03 21:30:01"));//
      map.put("null", Field.create(Field.Type.STRING, null));
            Record record = RecordCreator.create("s", "s:1");
      record.set(Field.create(map));

      StageRunner.Output output = runner.runProcess(ImmutableList.of(record));
      Assert.assertEquals(1, output.getRecords().get("a").size());
      Field field = output.getRecords().get("a").get(0).get();
      Assert.assertTrue(field.getValue() instanceof Map);
      Map<String, Field> result = field.getValueAsMap();
      Assert.assertTrue(result.size() == 6);

      Assert.assertTrue(result.containsKey("beginner"));
      SimpleDateFormat beginnerDateFormat = new SimpleDateFormat(beginnerConfig.otherDateFormat);
      Assert.assertEquals("2015-01-03", beginnerDateFormat.format(result.get("beginner").getValueAsDate()));

      Assert.assertTrue(result.containsKey("advanced"));
      Assert.assertEquals(type,result.get("advanced").getType());
      SimpleDateFormat advancedDateFormat = new SimpleDateFormat(advancedConfig.otherDateFormat);
      Assert.assertEquals("2015-01-03 21:31:02.777",
        advancedDateFormat.format(result.get("advanced").getValueAsDate()));

      Assert.assertTrue(result.containsKey("expert"));
      Assert.assertEquals(type,result.get("expert").getType());
      SimpleDateFormat expertDateFormat = new SimpleDateFormat(expertConfig.otherDateFormat);
      SimpleDateFormat expertDataSourceFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS z");
      Assert.assertEquals(expertDateFormat.format(expertDataSourceFormat.parse("2015-01-03 21:32:32.333 PST")),
        expertDateFormat.format(result.get("expert").getValueAsDate()));

      Assert.assertTrue(result.containsKey("skilled"));
      Assert.assertEquals(type,result.get("skilled").getType());
      SimpleDateFormat skilledDateFormat = new SimpleDateFormat(skilledConfig.otherDateFormat);
      Assert.assertEquals("2015-01-03 21:30:01", skilledDateFormat.format(result.get("skilled").getValueAsDate()));

      Assert.assertTrue(result.containsKey("null"));
      Assert.assertEquals(Field.Type.STRING, result.get("null").getType());
      Assert.assertEquals(null, result.get("null").getValueAsDate());

    } finally {
      runner.runDestroy();
    }
  }

  @Test
  public void testStringToDateTime() throws Exception {
    testStringToDateTimeTypes(Field.Type.DATETIME);
  }

  @Test
  public void testStringToDate() throws Exception {
    testStringToDateTimeTypes(Field.Type.DATE);
  }

  @Test
  public void testStringToTime() throws Exception {
    testStringToDateTimeTypes(Field.Type.TIME);
  }

  @Test
  public void testDateTimeToLong() throws Exception {
    FieldTypeConverterConfig dtConfig =
      new FieldTypeConverterConfig();
    dtConfig.fields = ImmutableList.of("/dateTime");
    dtConfig.targetType = Field.Type.LONG;
    dtConfig.dataLocale = "en";

    FieldTypeConverterConfig dateConfig =
      new FieldTypeConverterConfig();
    dateConfig.fields = ImmutableList.of("/date");
    dateConfig.targetType = Field.Type.LONG;
    dateConfig.dataLocale = "en";

    ProcessorRunner runner = new ProcessorRunner.Builder(FieldTypeConverterDProcessor.class)
      .addConfiguration("convertBy", ConvertBy.BY_FIELD)
      .addConfiguration("fieldTypeConverterConfigs", ImmutableList.of(dateConfig, dtConfig))
      .addOutputLane("a").build();
    runner.runInit();

    try {
      Map<String, Field> map = new LinkedHashMap<>();
      map.put("date", Field.createDate(new Date(0)));
      map.put("dateTime", Field.createDatetime(new Date(0)));
      Record record = RecordCreator.create("s", "s:1");
      record.set(Field.create(map));
      StageRunner.Output output = runner.runProcess(ImmutableList.of(record));
      Assert.assertEquals(1, output.getRecords().get("a").size());
      Field field = output.getRecords().get("a").get(0).get();
      Assert.assertTrue(field.getValue() instanceof Map);
      Map<String, Field> result = field.getValueAsMap();
      Assert.assertEquals(String.valueOf(result), 0, result.get("date").getValueAsLong());
      Assert.assertEquals(String.valueOf(result), 0, result.get("dateTime").getValueAsLong());
    } finally {
      runner.runDestroy();
    }
  }

  @Test
  public void testDateTimeToString() throws Exception {
    FieldTypeConverterConfig dtConfig =
        new FieldTypeConverterConfig();
    dtConfig.fields = ImmutableList.of("/dateTime");
    dtConfig.targetType = Field.Type.STRING;
    dtConfig.dataLocale = "en";
    dtConfig.dateFormat = DateFormat.DD_MM_YYYY;

    FieldTypeConverterConfig dateConfig =
        new FieldTypeConverterConfig();
    dateConfig.fields = ImmutableList.of("/date");
    dateConfig.targetType = Field.Type.STRING;
    dateConfig.dataLocale = "en";
    dateConfig.dateFormat = DateFormat.OTHER;
    dateConfig.otherDateFormat = "yyyy-MM-dd";

    ProcessorRunner runner = new ProcessorRunner.Builder(FieldTypeConverterDProcessor.class)
        .addConfiguration("convertBy", ConvertBy.BY_FIELD)
        .addConfiguration("fieldTypeConverterConfigs", ImmutableList.of(dateConfig, dtConfig))
        .addOutputLane("a").build();
    runner.runInit();

    try {
      Calendar cal = Calendar.getInstance();
      cal.set(Calendar.DAY_OF_MONTH, 20);
      cal.set(Calendar.MONTH, 1);
      cal.set(Calendar.YEAR, 2015);

      Map<String, Field> map = new LinkedHashMap<>();
      map.put("date", Field.createDate(cal.getTime()));
      map.put("dateTime", Field.createDatetime(cal.getTime()));
      Record record = RecordCreator.create("s", "s:1");
      record.set(Field.create(map));
      StageRunner.Output output = runner.runProcess(ImmutableList.of(record));
      Assert.assertEquals(1, output.getRecords().get("a").size());
      Field field = output.getRecords().get("a").get(0).get();
      Assert.assertTrue(field.getValue() instanceof Map);
      Map<String, Field> result = field.getValueAsMap();
      Assert.assertEquals("20-Feb-2015", result.get("dateTime").getValue());
      Assert.assertEquals("2015-02-20", result.get("date").getValue());
    } finally {
      runner.runDestroy();
    }
  }

  @Test
  public void testInvalidConversionFieldsNumber() throws StageException {
    FieldTypeConverterConfig fieldTypeConverterConfig =
      new FieldTypeConverterConfig();
    fieldTypeConverterConfig.fields = ImmutableList.of("/invalidConversion");
    fieldTypeConverterConfig.targetType = Field.Type.FLOAT;
    fieldTypeConverterConfig.dataLocale = "en";

    ProcessorRunner runner = new ProcessorRunner.Builder(FieldTypeConverterDProcessor.class)
      .addConfiguration("convertBy", ConvertBy.BY_FIELD)
      .addConfiguration("fieldTypeConverterConfigs", ImmutableList.of(fieldTypeConverterConfig))
      .addOutputLane("a").build();
    runner.runInit();

    Map<String, Field> map = new LinkedHashMap<>();
    map.put("invalidConversion", Field.create("float"));
          Record record = RecordCreator.create("s", "s:1");
    record.set(Field.create(map));

    try {
      runner.runProcess(ImmutableList.of(record));
      Assert.fail("Expected OnRecordException");
    } catch(OnRecordErrorException e) {
      //No-op
    } finally {
      runner.runDestroy();
    }
  }

  @Test
  public void testInvalidConversionStringToDate() throws StageException {
    FieldTypeConverterConfig fieldTypeConverterConfig =
      new FieldTypeConverterConfig();
    fieldTypeConverterConfig.fields = ImmutableList.of("/invalidConversion");
    fieldTypeConverterConfig.targetType = Field.Type.DATE;
    fieldTypeConverterConfig.dataLocale = "en";
    fieldTypeConverterConfig.dateFormat = DateFormat.DD_MM_YYYY;

    ProcessorRunner runner = new ProcessorRunner.Builder(FieldTypeConverterDProcessor.class)
      .addConfiguration("convertBy", ConvertBy.BY_FIELD)
      .addConfiguration("fieldTypeConverterConfigs", ImmutableList.of(fieldTypeConverterConfig))
      .addOutputLane("a").build();
    runner.runInit();

    Map<String, Field> map = new LinkedHashMap<>();
    map.put("invalidConversion", Field.create("Hello World"));
          Record record = RecordCreator.create("s", "s:1");
    record.set(Field.create(map));

    try {
      runner.runProcess(ImmutableList.of(record));
      Assert.fail("Expected OnRecordException");
    } catch(OnRecordErrorException e) {
      //No-op
    } finally {
      runner.runDestroy();
    }
  }

  @Test
  public void testInvalidConversionNonStringToDate() throws StageException {
    FieldTypeConverterConfig fieldTypeConverterConfig =
      new FieldTypeConverterConfig();
    fieldTypeConverterConfig.fields = ImmutableList.of("/invalidConversion");
    fieldTypeConverterConfig.targetType = Field.Type.DATE;
    fieldTypeConverterConfig.dataLocale = "en";
    fieldTypeConverterConfig.dateFormat = DateFormat.DD_MM_YYYY;

    ProcessorRunner runner = new ProcessorRunner.Builder(FieldTypeConverterDProcessor.class)
      .addConfiguration("convertBy", ConvertBy.BY_FIELD)
      .addConfiguration("fieldTypeConverterConfigs", ImmutableList.of(fieldTypeConverterConfig))
      .addOutputLane("a").build();
    runner.runInit();

    Map<String, Field> map = new LinkedHashMap<>();
    map.put("invalidConversion", Field.create(1.0));
          Record record = RecordCreator.create("s", "s:1");
    record.set(Field.create(map));

    try {
      runner.runProcess(ImmutableList.of(record));
      Assert.fail("Expected OnRecordException");
    } catch(OnRecordErrorException e) {
      //No-op
    } finally {
      runner.runDestroy();
    }
  }

  @Test
  public void testNonStringFieldToNonStringField() throws StageException {
    FieldTypeConverterConfig decimalToInteger =
      new FieldTypeConverterConfig();
    decimalToInteger.fields = ImmutableList.of("/base");
    decimalToInteger.targetType = Field.Type.INTEGER;

    FieldTypeConverterConfig floatToShort =
      new FieldTypeConverterConfig();
    floatToShort.fields = ImmutableList.of("/bonus");
    floatToShort.targetType = Field.Type.SHORT;

    FieldTypeConverterConfig longToByte =
      new FieldTypeConverterConfig();
    longToByte.fields = ImmutableList.of("/benefits");
    longToByte.targetType = Field.Type.BYTE;

    ProcessorRunner runner = new ProcessorRunner.Builder(FieldTypeConverterDProcessor.class)
      .addConfiguration("convertBy", ConvertBy.BY_FIELD)
      .addConfiguration("fieldTypeConverterConfigs", ImmutableList.of(decimalToInteger, floatToShort, longToByte))
      .addOutputLane("a").build();
    runner.runInit();

    try {
      Map<String, Field> map = new LinkedHashMap<>();
      map.put("base", Field.create(Field.Type.DECIMAL, new BigDecimal(1234.56)));
      map.put("bonus", Field.create(Field.Type.FLOAT, 200.45f));
      map.put("benefits", Field.create(Field.Type.LONG, 123456789L));
            Record record = RecordCreator.create("s", "s:1");
      record.set(Field.create(map));

      StageRunner.Output output = runner.runProcess(ImmutableList.of(record));
      Assert.assertEquals(1, output.getRecords().get("a").size());
      Field field = output.getRecords().get("a").get(0).get();
      Assert.assertTrue(field.getValue() instanceof Map);
      Map<String, Field> result = field.getValueAsMap();
      Assert.assertTrue(result.size() == 3);

      Assert.assertTrue(result.containsKey("base"));
      Assert.assertEquals(Field.Type.INTEGER, result.get("base").getType());
      Assert.assertEquals(1234, result.get("base").getValue());

      Assert.assertTrue(result.containsKey("bonus"));
      Assert.assertEquals(Field.Type.SHORT, result.get("bonus").getType());
      Assert.assertEquals((short)200, result.get("bonus").getValue());

      Assert.assertTrue(result.containsKey("benefits"));
      Assert.assertEquals(Field.Type.BYTE, result.get("benefits").getType());
      Assert.assertEquals((byte)21, result.get("benefits").getValue());

    } finally {
      runner.runDestroy();
    }
  }

  @Test
  public void testWildCardConverter() throws StageException {

    Field name1 = Field.create("1");
    Field name2 = Field.create("2");
    Map<String, Field> nameMap1 = new HashMap<>();
    nameMap1.put("name", name1);
    Map<String, Field> nameMap2 = new HashMap<>();
    nameMap2.put("name", name2);

    Field name3 = Field.create("3");
    Field name4 = Field.create("4");
    Map<String, Field> nameMap3 = new HashMap<>();
    nameMap3.put("name", name3);
    Map<String, Field> nameMap4 = new HashMap<>();
    nameMap4.put("name", name4);

    Field name5 = Field.create("5");
    Field name6 = Field.create("6");
    Map<String, Field> nameMap5 = new HashMap<>();
    nameMap5.put("name", name5);
    Map<String, Field> nameMap6 = new HashMap<>();
    nameMap6.put("name", name6);

    Field first = Field.create(Field.Type.LIST, ImmutableList.of(Field.create(nameMap1), Field.create(nameMap2)));
    Field second = Field.create(Field.Type.LIST, ImmutableList.of(Field.create(nameMap3), Field.create(nameMap4)));
    Field third = Field.create(Field.Type.LIST, ImmutableList.of(Field.create(nameMap5), Field.create(nameMap6)));

    Map<String, Field> noe = new HashMap<>();
    noe.put("streets", Field.create(ImmutableList.of(first, second)));

    Map<String, Field> cole = new HashMap<>();
    cole.put("streets", Field.create(ImmutableList.of(third)));

    Map<String, Field> sfArea = new HashMap<>();
    sfArea.put("noe", Field.create(noe));

    Map<String, Field> utahArea = new HashMap<>();
    utahArea.put("cole", Field.create(cole));

    Map<String, Field> california = new HashMap<>();
    california.put("SanFrancisco", Field.create(sfArea));

    Map<String, Field> utah = new HashMap<>();
    utah.put("SantaMonica", Field.create(utahArea));

    Map<String, Field> map = new LinkedHashMap<>();
    map.put("USA", Field.create(Field.Type.LIST,
      ImmutableList.of(Field.create(california), Field.create(utah))));

    Record record = RecordCreator.create("s", "s:1");
    record.set(Field.create(map));

    Assert.assertEquals(record.get("/USA[0]/SanFrancisco/noe/streets[0][0]/name").getValueAsString(), "1");
    Assert.assertEquals(record.get("/USA[0]/SanFrancisco/noe/streets[0][1]/name").getValueAsString(), "2");
    Assert.assertEquals(record.get("/USA[0]/SanFrancisco/noe/streets[1][0]/name").getValueAsString(), "3");
    Assert.assertEquals(record.get("/USA[0]/SanFrancisco/noe/streets[1][1]/name").getValueAsString(), "4");
    Assert.assertEquals(record.get("/USA[1]/SantaMonica/cole/streets[0][0]/name").getValueAsString(), "5");
    Assert.assertEquals(record.get("/USA[1]/SantaMonica/cole/streets[0][1]/name").getValueAsString(), "6");

    /* All the field Paths in the record are
        /USA
        /USA[0]
        /USA[0]/SantaMonica
        /USA[0]/SantaMonica/noe
        /USA[0]/SantaMonica/noe/streets
        /USA[0]/SantaMonica/noe/streets[0]
        /USA[0]/SantaMonica/noe/streets[0][0]
        /USA[0]/SantaMonica/noe/streets[0][0]/name
        /USA[0]/SantaMonica/noe/streets[0][1]
        /USA[0]/SantaMonica/noe/streets[0][1]/name
        /USA[0]/SantaMonica/noe/streets[1]
        /USA[0]/SantaMonica/noe/streets[1][0]
        /USA[0]/SantaMonica/noe/streets[1][0]/name
        /USA[0]/SantaMonica/noe/streets[1][1]
        /USA[0]/SantaMonica/noe/streets[1][1]/name
        /USA[1]
        /USA[1]/SantaMonica
        /USA[1]/SantaMonica/cole
        /USA[1]/SantaMonica/cole/streets
        /USA[1]/SantaMonica/cole/streets[0]
        /USA[1]/SantaMonica/cole/streets[0][0]
        /USA[1]/SantaMonica/cole/streets[0][0]/name
        /USA[1]/SantaMonica/cole/streets[0][1]
        /USA[1]/SantaMonica/cole/streets[0][1]/name
      */
    FieldTypeConverterConfig stringToInt = new FieldTypeConverterConfig();
    stringToInt.fields = ImmutableList.of("/USA[*]/SanFrancisco/*/streets[*][*]/name");
    stringToInt.targetType = Field.Type.INTEGER;
    stringToInt.dataLocale = "en";

    ProcessorRunner runner = new ProcessorRunner.Builder(FieldTypeConverterDProcessor.class)
      .addConfiguration("convertBy", ConvertBy.BY_FIELD)
      .addConfiguration("fieldTypeConverterConfigs", ImmutableList.of(stringToInt))
      .addOutputLane("a").build();
    runner.runInit();

    try {

      StageRunner.Output output = runner.runProcess(ImmutableList.of(record));
      Assert.assertEquals(1, output.getRecords().get("a").size());

      Record resultRecord = output.getRecords().get("a").get(0);
      Assert.assertEquals(resultRecord.get("/USA[0]/SanFrancisco/noe/streets[0][0]/name").getValueAsInteger(), 1);
      Assert.assertEquals(resultRecord.get("/USA[0]/SanFrancisco/noe/streets[0][1]/name").getValueAsInteger(), 2);
      Assert.assertEquals(resultRecord.get("/USA[0]/SanFrancisco/noe/streets[1][0]/name").getValueAsInteger(), 3);
      Assert.assertEquals(resultRecord.get("/USA[0]/SanFrancisco/noe/streets[1][1]/name").getValueAsInteger(), 4);

      Assert.assertEquals(resultRecord.get("/USA[1]/SantaMonica/cole/streets[0][0]/name").getValueAsString(), "5");
      Assert.assertEquals(resultRecord.get("/USA[1]/SantaMonica/cole/streets[0][1]/name").getValueAsString(), "6");

    } finally {
      runner.runDestroy();
    }
  }

  @Test
  public void testDateConversion() throws StageException {

    FieldTypeConverterConfig date7 = new FieldTypeConverterConfig();
    date7.fields = ImmutableList.of("/date7");
    date7.targetType = Field.Type.DATE;
    date7.dateFormat = DateFormat.YYYY_MM_DD_T_HH_MM_SS_SSS_Z;
    date7.dataLocale = "en";

    FieldTypeConverterConfig date6 = new FieldTypeConverterConfig();
    date6.fields = ImmutableList.of("/date6");
    date6.targetType = Field.Type.DATE;
    date6.dateFormat = DateFormat.YYYY_MM_DD_T_HH_MM_Z;
    date6.dataLocale = "en";

    FieldTypeConverterConfig date5 = new FieldTypeConverterConfig();
    date5.fields = ImmutableList.of("/date5");
    date5.targetType = Field.Type.DATE;
    date5.dateFormat = DateFormat.YYYY_MM_DD_HH_MM_SS_SSS_Z;
    date5.dataLocale = "en";

    FieldTypeConverterConfig date4 = new FieldTypeConverterConfig();
    date4.fields = ImmutableList.of("/date4");
    date4.targetType = Field.Type.DATE;
    date4.dateFormat = DateFormat.YYYY_MM_DD_HH_MM_SS_SSS;
    date4.dataLocale = "en";

    FieldTypeConverterConfig date3 = new FieldTypeConverterConfig();
    date3.fields = ImmutableList.of("/date3");
    date3.targetType = Field.Type.DATE;
    date3.dateFormat = DateFormat.YYYY_MM_DD_HH_MM_SS;
    date3.dataLocale = "en";

    FieldTypeConverterConfig date2 = new FieldTypeConverterConfig();
    date2.fields = ImmutableList.of("/date2");
    date2.targetType = Field.Type.DATE;
    date2.dateFormat = DateFormat.DD_MM_YYYY;
    date2.dataLocale = "en";

    FieldTypeConverterConfig date1 = new FieldTypeConverterConfig();
    date1.fields = ImmutableList.of("/date1");
    date1.targetType = Field.Type.DATE;
    date1.dateFormat = DateFormat.YYYY_MM_DD;
    date1.dataLocale = "en";

    ProcessorRunner runner = new ProcessorRunner.Builder(FieldTypeConverterDProcessor.class)
      .addConfiguration("convertBy", ConvertBy.BY_FIELD)
      .addConfiguration("fieldTypeConverterConfigs", ImmutableList.of(date1, date2, date3, date4, date5, date6, date7))
      .addOutputLane("a").build();
    runner.runInit();

    try {
      Map<String, Field> map = new LinkedHashMap<>();
      map.put("date1", Field.create(Field.Type.STRING, "2016-08-12"));
      map.put("date2", Field.create(Field.Type.STRING, "12-AUG-2016"));
      map.put("date3", Field.create(Field.Type.STRING, "2016-08-12 16:08:12"));
      map.put("date4", Field.create(Field.Type.STRING, "2016-08-12 16:08:12.777"));
      map.put("date5", Field.create(Field.Type.STRING, "2016-08-12 16:08:12.777 -0700"));
      map.put("date6", Field.create(Field.Type.STRING, "2015-08-11T18:32Z"));
      map.put("date7", Field.create(Field.Type.STRING, "2016-08-15T18:32:12.777Z"));
      Record record = RecordCreator.create("s", "s:1");
      record.set(Field.create(map));

      StageRunner.Output output = runner.runProcess(ImmutableList.of(record));

      Assert.assertEquals(1, output.getRecords().get("a").size());
      Field field = output.getRecords().get("a").get(0).get();
      Assert.assertTrue(field.getValue() instanceof Map);
      Map<String, Field> result = field.getValueAsMap();
      Assert.assertTrue(result.size() == 7);

      Assert.assertTrue(result.containsKey("date1"));
      Assert.assertEquals(Field.Type.DATE, result.get("date1").getType());
      SimpleDateFormat date1DateFormat = new SimpleDateFormat(date1.dateFormat.getFormat());
      Assert.assertEquals("2016-08-12", date1DateFormat.format(result.get("date1").getValue()));

      Assert.assertTrue(result.containsKey("date2"));
      Assert.assertEquals(Field.Type.DATE, result.get("date2").getType());
      SimpleDateFormat date2DateFormat = new SimpleDateFormat(date2.dateFormat.getFormat());
      Assert.assertEquals("12-Aug-2016", date2DateFormat.format(result.get("date2").getValue()));

      Assert.assertTrue(result.containsKey("date3"));
      Assert.assertEquals(Field.Type.DATE, result.get("date3").getType());
      SimpleDateFormat date3DateFormat = new SimpleDateFormat(date3.dateFormat.getFormat());
      Assert.assertEquals("2016-08-12 16:08:12", date3DateFormat.format(result.get("date3").getValue()));

      Assert.assertTrue(result.containsKey("date4"));
      Assert.assertEquals(Field.Type.DATE, result.get("date4").getType());
      SimpleDateFormat date4DateFormat = new SimpleDateFormat(date4.dateFormat.getFormat());
      Assert.assertEquals("2016-08-12 16:08:12.777", date4DateFormat.format(result.get("date4").getValue()));

      Assert.assertTrue(result.containsKey("date5"));
      Assert.assertEquals(Field.Type.DATE, result.get("date5").getType());
      SimpleDateFormat date5DateFormat = new SimpleDateFormat(date5.dateFormat.getFormat());
      date5DateFormat.setTimeZone(TimeZone.getTimeZone("MST"));
      Assert.assertEquals("2016-08-12 16:08:12.777 -0700", date5DateFormat.format(result.get("date5").getValue()));

      Assert.assertTrue(result.containsKey("date6"));
      Assert.assertEquals(Field.Type.DATE, result.get("date6").getType());
      SimpleDateFormat date6DateFormat = new SimpleDateFormat(date6.dateFormat.getFormat());
      Assert.assertEquals("2015-08-11T18:32Z", date6DateFormat.format(result.get("date6").getValue()));

      Assert.assertTrue(result.containsKey("date7"));
      Assert.assertEquals(Field.Type.DATE, result.get("date7").getType());
      SimpleDateFormat date7DateFormat = new SimpleDateFormat(date7.dateFormat.getFormat());
      Assert.assertEquals("2016-08-15T18:32:12.777Z", date7DateFormat.format(result.get("date7").getValue()));

    } finally {
      runner.runDestroy();
    }
  }

  @Test
  public void testByteArrayToString() throws StageException {
    FieldTypeConverterConfig converter1 =
        new FieldTypeConverterConfig();
    converter1.fields = ImmutableList.of("/byteUTF8");
    converter1.encoding = "UTF-8";
    converter1.targetType = Field.Type.STRING;
    converter1.dataLocale = "en";

    FieldTypeConverterConfig converter2 =
        new FieldTypeConverterConfig();
    converter2.fields = ImmutableList.of("/byteGBK");
    converter2.encoding = "GBK";
    converter2.targetType = Field.Type.STRING;
    converter2.dataLocale = "en";

    FieldTypeConverterConfig converter3 =
        new FieldTypeConverterConfig();
    converter3.fields = ImmutableList.of("/badEncoding");
    converter3.encoding = "GBK";
    converter3.targetType = Field.Type.STRING;
    converter3.dataLocale = "en";

    ProcessorRunner runner = new ProcessorRunner.Builder(FieldTypeConverterDProcessor.class)
        .addConfiguration("convertBy", ConvertBy.BY_FIELD)
        .addConfiguration("fieldTypeConverterConfigs", ImmutableList.of(converter1, converter2, converter3))
        .addOutputLane("a").build();
    runner.runInit();

    final String someUTF8 = "UTF8: euro: € greek όλα τα ελληνικά σε μένα japanese 天気の良い日 thai วันที่ดี data.";
    final byte [] byteUTF8 = someUTF8.getBytes(Charset.forName("UTF8"));

    try {
      final String x = "GBK: japanese 天気の良い日 trad chinese 傳統 simplified 镕 chinese 中国是美丽的 data.";
      String someGBK = new String(x.getBytes("UTF8"), "GBK");
      final byte[] byteGBK = x.getBytes();

      Map<String, Field> map = new LinkedHashMap<>();
      map.put("byteUTF8", Field.create(Field.Type.BYTE_ARRAY, byteUTF8));
      map.put("byteGBK", Field.create(Field.Type.BYTE_ARRAY, byteGBK));
      map.put("badEncoding", Field.create(Field.Type.BYTE_ARRAY, byteUTF8));
      Record record = RecordCreator.create("s", "s:1");
      record.set(Field.create(map));

      StageRunner.Output output = runner.runProcess(ImmutableList.of(record));
      Assert.assertEquals(1, output.getRecords().get("a").size());
      Field field = output.getRecords().get("a").get(0).get();
      Assert.assertTrue(field.getValue() instanceof Map);
      Map<String, Field> result = field.getValueAsMap();

      Assert.assertTrue(result.size() == 3);
      Assert.assertTrue(result.containsKey("byteUTF8"));
      Assert.assertEquals(someUTF8, result.get("byteUTF8").getValueAsString());

      Assert.assertTrue(result.containsKey("byteGBK"));
      Assert.assertEquals(someGBK, result.get("byteGBK").getValueAsString());

      Assert.assertTrue(result.containsKey("badEncoding"));
      // this is UTF8 data decoded as GBK - which does not work.
      Assert.assertNotEquals(someGBK, result.get("badEncoding").getValueAsString());
    } catch (Exception e) {
      e.printStackTrace();

    } finally {
      runner.runDestroy();
    }
  }
}


text:
utils = {
  startsAtMomentWithOffset: function (game) {
    var offset = game.location.utc_offset;
    if (! Match.test(offset, UTCOffset)) {
      // XXX should account for DST here
      offset = -7; // Default to California
    }
    // UTC offsets returned by Google Places API,
    // which is the source of game.location.utc_offset,
    // differ in sign from what is expected by moment.js
    return moment(game.startsAt).zone(-offset);
  },
  displayTime: function (game) {
    return utils.startsAtMomentWithOffset(game).format('ddd h:mma');
  },
  // Same-day-ness depends on the known timezone of the game,
  // not the timezone of the system executing this function.
  isToday: function (game) {
    var gameWhen = utils.startsAtMomentWithOffset(game);
    var now = utils.startsAtMomentWithOffset(
      // clone of game that starts now
      _.extend({startsAt: new Date()}, _.omit(game, 'startsAt'))
    );
    return gameWhen.isSame(now, 'day');
  },
  // Markdown->HTML
  converter: new Showdown.converter()
};

redpajama_set_name: RedPajamaGithub


text:
namespace crypto {
namespace tink {
namespace {

using ::crypto::tink::BinaryKeysetWriter;
using ::crypto::tink::CleartextKeysetHandle;
using ::crypto::tink::KeysetHandle;
using ::crypto::tink::test::IsOk;
using ::google::crypto::tink::KeyTemplate;
using ::testing::ElementsAre;
using ::testing::Eq;
using ::testing::IsEmpty;
using ::testing::Not;
using ::tink_testing_api::CreationRequest;
using ::tink_testing_api::CreationResponse;
using ::tink_testing_api::JwtFromJwkSetRequest;
using ::tink_testing_api::JwtFromJwkSetResponse;
using ::tink_testing_api::JwtSignRequest;
using ::tink_testing_api::JwtSignResponse;
using ::tink_testing_api::JwtToJwkSetRequest;
using ::tink_testing_api::JwtToJwkSetResponse;
using ::tink_testing_api::JwtToken;
using ::tink_testing_api::JwtValidator;
using ::tink_testing_api::JwtVerifyRequest;
using ::tink_testing_api::JwtVerifyResponse;

std::string ValidKeyset() {
  const KeyTemplate& key_template = ::crypto::tink::JwtHs256Template();
  util::StatusOr<std::unique_ptr<KeysetHandle>> handle =
      KeysetHandle::GenerateNew(key_template);
  EXPECT_THAT(handle.status(), IsOk());

  std::stringbuf keyset;
  util::StatusOr<std::unique_ptr<BinaryKeysetWriter>> writer =
      BinaryKeysetWriter::New(absl::make_unique<std::ostream>(&keyset));
  EXPECT_THAT(writer.status(), IsOk());

  util::Status status = CleartextKeysetHandle::Write((*writer).get(), **handle);
  EXPECT_THAT(status, IsOk());
  return keyset.str();
}

class JwtImplMacTest : public ::testing::Test {
 protected:
  static void SetUpTestSuite() { ASSERT_THAT(JwtMacRegister(), IsOk()); }
};

TEST_F(JwtImplMacTest, CreateJwtMacSuccess) {
  tink_testing_api::JwtImpl jwt;
  std::string keyset = ValidKeyset();
  CreationRequest request;
  request.mutable_annotated_keyset()->set_serialized_keyset(keyset);
  CreationResponse response;

  EXPECT_TRUE(jwt.CreateJwtMac(nullptr, &request, &response).ok());
  EXPECT_THAT(response.err(), IsEmpty());
}

TEST_F(JwtImplMacTest, CreateJwtMacFails) {
  tink_testing_api::JwtImpl jwt;
  CreationRequest request;
  request.mutable_annotated_keyset()->set_serialized_keyset("bad keyset");
  CreationResponse response;

  EXPECT_TRUE(jwt.CreateJwtMac(nullptr, &request, &response).ok());
  EXPECT_THAT(response.err(), Not(IsEmpty()));
}

TEST_F(JwtImplMacTest, MacComputeVerifySuccess) {
  tink_testing_api::JwtImpl jwt;
  std::string keyset = ValidKeyset();
  JwtSignRequest comp_request;
  comp_request.mutable_annotated_keyset()->set_serialized_keyset(keyset);
  JwtToken* raw_jwt = comp_request.mutable_raw_jwt();
  raw_jwt->mutable_type_header()->set_value("type_header");
  raw_jwt->mutable_issuer()->set_value("issuer");
  raw_jwt->mutable_subject()->set_value("subject");
  raw_jwt->mutable_audiences()->Add("audience1");
  raw_jwt->mutable_audiences()->Add("audience2");
  raw_jwt->mutable_jwt_id()->set_value("jwt_id");
  raw_jwt->mutable_not_before()->set_seconds(12345);
  raw_jwt->mutable_not_before()->set_nanos(123000000);
  raw_jwt->mutable_issued_at()->set_seconds(23456);
  raw_jwt->mutable_expiration()->set_seconds(34567);
  auto custom_claims = raw_jwt->mutable_custom_claims();
  (*custom_claims)["null_claim"].set_null_value(
      tink_testing_api::NullValue::NULL_VALUE);
  (*custom_claims)["bool_claim"].set_bool_value(true);
  (*custom_claims)["number_claim"].set_number_value(123.456);
  (*custom_claims)["string_claim"].set_string_value("string_value");
  JwtSignResponse comp_response;
  EXPECT_TRUE(
      jwt.ComputeMacAndEncode(nullptr, &comp_request, &comp_response).ok());
  EXPECT_THAT(comp_response.err(), IsEmpty());

  JwtVerifyRequest verify_request;
  verify_request.mutable_annotated_keyset()->set_serialized_keyset(keyset);
  verify_request.set_signed_compact_jwt(comp_response.signed_compact_jwt());
  JwtValidator* validator = verify_request.mutable_validator();
  validator->mutable_expected_type_header()->set_value("type_header");
  validator->mutable_expected_issuer()->set_value("issuer");
  validator->mutable_expected_audience()->set_value("audience2");
  validator->mutable_now()->set_seconds(23456);
  JwtVerifyResponse verify_response;

  ASSERT_TRUE(
      jwt.VerifyMacAndDecode(nullptr, &verify_request, &verify_response).ok());
  ASSERT_THAT(verify_response.err(), IsEmpty());
  const JwtToken& verified_jwt = verify_response.verified_jwt();
  EXPECT_EQ(verified_jwt.type_header().value(), "type_header");
  EXPECT_THAT(verified_jwt.issuer().value(), Eq("issuer"));
  EXPECT_THAT(verified_jwt.subject().value(), Eq("subject"));
  EXPECT_THAT(verified_jwt.audiences_size(), Eq(2));
  EXPECT_THAT(verified_jwt.audiences(0), Eq("audience1"));
  EXPECT_THAT(verified_jwt.audiences(1), Eq("audience2"));
  EXPECT_THAT(verified_jwt.jwt_id().value(), Eq("jwt_id"));
  EXPECT_THAT(verified_jwt.not_before().seconds(), Eq(12345));
  EXPECT_THAT(verified_jwt.not_before().nanos(), Eq(0));
  EXPECT_THAT(verified_jwt.issued_at().seconds(), Eq(23456));
  EXPECT_THAT(verified_jwt.issued_at().nanos(), Eq(0));
  EXPECT_THAT(verified_jwt.expiration().seconds(), Eq(34567));
  EXPECT_THAT(verified_jwt.expiration().nanos(), Eq(0));
  auto verified_custom_claims = verified_jwt.custom_claims();
  EXPECT_THAT(verified_custom_claims["null_claim"].null_value(),
              Eq(tink_testing_api::NullValue::NULL_VALUE));
  EXPECT_THAT(verified_custom_claims["bool_claim"].bool_value(), Eq(true));
  EXPECT_THAT(verified_custom_claims["number_claim"].number_value(),
              Eq(123.456));
  EXPECT_THAT(verified_custom_claims["string_claim"].string_value(),
              Eq("string_value"));
}

TEST_F(JwtImplMacTest, ComputeBadKeysetFail) {
  tink_testing_api::JwtImpl jwt;
  JwtSignRequest comp_request;
  comp_request.mutable_annotated_keyset()->set_serialized_keyset("bad keyset");
  comp_request.mutable_raw_jwt()->mutable_issuer()->set_value("issuer");
  JwtSignResponse comp_response;

  EXPECT_TRUE(
      jwt.ComputeMacAndEncode(nullptr, &comp_request, &comp_response).ok());
  EXPECT_THAT(comp_response.err(), Not(IsEmpty()));
}

TEST_F(JwtImplMacTest, VerifyWithWrongIssuerFails) {
  tink_testing_api::JwtImpl jwt;
  std::string keyset = ValidKeyset();
  JwtSignRequest comp_request;
  comp_request.mutable_annotated_keyset()->set_serialized_keyset(keyset);
  comp_request.mutable_raw_jwt()->mutable_issuer()->set_value("unknown");
  JwtSignResponse comp_response;
  EXPECT_TRUE(
      jwt.ComputeMacAndEncode(nullptr, &comp_request, &comp_response).ok());
  EXPECT_THAT(comp_response.err(), IsEmpty());

  JwtVerifyRequest verify_request;
  verify_request.mutable_annotated_keyset()->set_serialized_keyset(keyset);
  verify_request.set_signed_compact_jwt(comp_response.signed_compact_jwt());
  verify_request.mutable_validator()->mutable_expected_issuer()->set_value(
      "issuer");
  JwtVerifyResponse verify_response;

  EXPECT_TRUE(
      jwt.VerifyMacAndDecode(nullptr, &verify_request, &verify_response).ok());
  EXPECT_THAT(verify_response.err(), Not(IsEmpty()));
}

class JwtImplSignatureTest : public ::testing::Test {
 protected:
  static void SetUpTestSuite() { ASSERT_THAT(JwtSignatureRegister(), IsOk()); }
  void SetUp() override {
    const KeyTemplate& key_template = ::crypto::tink::JwtEs256Template();
    util::StatusOr<std::unique_ptr<KeysetHandle>> handle =
        KeysetHandle::GenerateNew(key_template);
    EXPECT_THAT(handle.status(), IsOk());

    std::stringbuf keyset;
    util::StatusOr<std::unique_ptr<BinaryKeysetWriter>> writer =
        BinaryKeysetWriter::New(absl::make_unique<std::ostream>(&keyset));
    EXPECT_THAT(writer.status(), IsOk());

    util::Status status =
        CleartextKeysetHandle::Write((*writer).get(), **handle);
    EXPECT_THAT(status, IsOk());
    private_keyset_ = keyset.str();

    util::StatusOr<std::unique_ptr<crypto::tink::KeysetHandle>> pub_handle =
        (*handle)->GetPublicKeysetHandle();
    EXPECT_THAT(pub_handle.status(), IsOk());

    std::stringbuf pub_keyset;
    util::StatusOr<std::unique_ptr<BinaryKeysetWriter>> pub_writer =
        BinaryKeysetWriter::New(absl::make_unique<std::ostream>(&pub_keyset));
    EXPECT_THAT(writer.status(), IsOk());

    util::Status pub_status =
        CleartextKeysetHandle::Write(pub_writer->get(), **pub_handle);
    EXPECT_THAT(pub_status, IsOk());
    public_keyset_ = pub_keyset.str();
  }
  std::string private_keyset_;
  std::string public_keyset_;
};

TEST_F(JwtImplSignatureTest, CreatePublicKeySignSuccess) {
  tink_testing_api::JwtImpl jwt;
  CreationRequest request;
  request.mutable_annotated_keyset()->set_serialized_keyset(private_keyset_);
  CreationResponse response;

  EXPECT_TRUE(jwt.CreateJwtPublicKeySign(nullptr, &request, &response).ok());
  EXPECT_THAT(response.err(), IsEmpty());
}

TEST_F(JwtImplSignatureTest, CreatePublicKeySignFailure) {
  tink_testing_api::JwtImpl jwt;

  CreationRequest request;
  request.mutable_annotated_keyset()->set_serialized_keyset("\x80");
  CreationResponse response;

  EXPECT_TRUE(jwt.CreateJwtPublicKeySign(nullptr, &request, &response).ok());
  EXPECT_THAT(response.err(), Not(IsEmpty()));
}

TEST_F(JwtImplSignatureTest, CreatePublicKeyVerifySuccess) {
  tink_testing_api::JwtImpl jwt;

  CreationRequest request;
  request.mutable_annotated_keyset()->set_serialized_keyset(public_keyset_);
  CreationResponse response;

  EXPECT_TRUE(jwt.CreateJwtPublicKeyVerify(nullptr, &request, &response).ok());
  EXPECT_THAT(response.err(), IsEmpty());
}

TEST_F(JwtImplSignatureTest, CreatePublicKeyVerifyFailure) {
  tink_testing_api::JwtImpl jwt;

  CreationRequest request;
  request.mutable_annotated_keyset()->set_serialized_keyset("\x80");
  CreationResponse response;

  EXPECT_TRUE(jwt.CreateJwtPublicKeyVerify(nullptr, &request, &response).ok());
  EXPECT_THAT(response.err(), Not(IsEmpty()));
}

TEST_F(JwtImplSignatureTest, SignVerifySuccess) {
  tink_testing_api::JwtImpl jwt;
  JwtSignRequest comp_request;
  comp_request.mutable_annotated_keyset()->set_serialized_keyset(
      private_keyset_);
  JwtToken* raw_jwt = comp_request.mutable_raw_jwt();
  raw_jwt->mutable_type_header()->set_value("type_header");
  raw_jwt->mutable_issuer()->set_value("issuer");
  raw_jwt->mutable_subject()->set_value("subject");
  raw_jwt->mutable_audiences()->Add("audience1");
  raw_jwt->mutable_audiences()->Add("audience2");
  raw_jwt->mutable_jwt_id()->set_value("jwt_id");
  raw_jwt->mutable_not_before()->set_seconds(12345);
  raw_jwt->mutable_issued_at()->set_seconds(23456);
  raw_jwt->mutable_expiration()->set_seconds(34567);
  auto custom_claims = raw_jwt->mutable_custom_claims();
  (*custom_claims)["null_claim"].set_null_value(
      tink_testing_api::NullValue::NULL_VALUE);
  (*custom_claims)["bool_claim"].set_bool_value(true);
  (*custom_claims)["number_claim"].set_number_value(123.456);
  (*custom_claims)["string_claim"].set_string_value("string_value");
  JwtSignResponse comp_response;
  EXPECT_TRUE(
      jwt.PublicKeySignAndEncode(nullptr, &comp_request, &comp_response).ok());
  EXPECT_THAT(comp_response.err(), IsEmpty());

  JwtVerifyRequest verify_request;
  verify_request.mutable_annotated_keyset()->set_serialized_keyset(
      public_keyset_);
  verify_request.set_signed_compact_jwt(comp_response.signed_compact_jwt());
  JwtValidator* validator = verify_request.mutable_validator();
  validator->mutable_expected_type_header()->set_value("type_header");
  validator->mutable_expected_issuer()->set_value("issuer");
  validator->mutable_expected_audience()->set_value("audience2");
  validator->mutable_now()->set_seconds(23456);
  JwtVerifyResponse verify_response;

  ASSERT_TRUE(
      jwt.PublicKeyVerifyAndDecode(nullptr, &verify_request, &verify_response)
          .ok());
  ASSERT_THAT(verify_response.err(), IsEmpty());
  const JwtToken& verified_jwt = verify_response.verified_jwt();
  EXPECT_EQ(verified_jwt.type_header().value(), "type_header");
  EXPECT_THAT(verified_jwt.issuer().value(), Eq("issuer"));
  EXPECT_THAT(verified_jwt.subject().value(), Eq("subject"));
  ASSERT_THAT(verified_jwt.audiences(),
              ElementsAre("audience1", "audience2"));
  EXPECT_THAT(verified_jwt.jwt_id().value(), Eq("jwt_id"));
  EXPECT_THAT(verified_jwt.not_before().seconds(), Eq(12345));
  EXPECT_THAT(verified_jwt.issued_at().seconds(), Eq(23456));
  EXPECT_THAT(verified_jwt.expiration().seconds(), Eq(34567));
  auto verified_custom_claims = verified_jwt.custom_claims();
  EXPECT_THAT(verified_custom_claims["null_claim"].null_value(),
              Eq(tink_testing_api::NullValue::NULL_VALUE));
  EXPECT_THAT(verified_custom_claims["bool_claim"].bool_value(), Eq(true));
  EXPECT_THAT(verified_custom_claims["number_claim"].number_value(),
              Eq(123.456));
  EXPECT_THAT(verified_custom_claims["string_claim"].string_value(),
              Eq("string_value"));
}

TEST_F(JwtImplSignatureTest, SignWithBadKeysetFails) {
  tink_testing_api::JwtImpl jwt;
  JwtSignRequest comp_request;
  comp_request.mutable_annotated_keyset()->set_serialized_keyset("bad keyset");
  comp_request.mutable_raw_jwt()->mutable_issuer()->set_value("issuer");
  JwtSignResponse comp_response;

  EXPECT_TRUE(
      jwt.PublicKeySignAndEncode(nullptr, &comp_request, &comp_response).ok());
  EXPECT_THAT(comp_response.err(), Not(IsEmpty()));
}

TEST_F(JwtImplSignatureTest, VerifyWithWrongIssuerFails) {
  tink_testing_api::JwtImpl jwt;
  JwtSignRequest comp_request;
  comp_request.mutable_annotated_keyset()->set_serialized_keyset(
      private_keyset_);
  comp_request.mutable_raw_jwt()->mutable_issuer()->set_value("unknown");
  JwtSignResponse comp_response;
  EXPECT_TRUE(
      jwt.PublicKeySignAndEncode(nullptr, &comp_request, &comp_response).ok());
  EXPECT_THAT(comp_response.err(), IsEmpty());

  JwtVerifyRequest verify_request;
  verify_request.mutable_annotated_keyset()->set_serialized_keyset(
      public_keyset_);
  verify_request.set_signed_compact_jwt(comp_response.signed_compact_jwt());
  verify_request.mutable_validator()->mutable_expected_issuer()->set_value(
      "issuer");
  JwtVerifyResponse verify_response;

  EXPECT_TRUE(
      jwt.PublicKeyVerifyAndDecode(nullptr, &verify_request, &verify_response)
          .ok());
  EXPECT_THAT(verify_response.err(), Not(IsEmpty()));
}

TEST_F(JwtImplSignatureTest, SignConvertToAndFromJwkVerifySuccess) {
  tink_testing_api::JwtImpl jwt;

  // Create a signed token
  JwtSignRequest comp_request;
  comp_request.mutable_annotated_keyset()->set_serialized_keyset(
      private_keyset_);
  JwtToken* raw_jwt = comp_request.mutable_raw_jwt();
  raw_jwt->mutable_issuer()->set_value("issuer");
  raw_jwt->mutable_expiration()->set_seconds(34567);
  JwtSignResponse comp_response;
  ASSERT_TRUE(
      jwt.PublicKeySignAndEncode(nullptr, &comp_request, &comp_response).ok());
  ASSERT_THAT(comp_response.err(), IsEmpty());

  // Generate a JWK set from the public key
  JwtToJwkSetRequest to_jwk_request;
  to_jwk_request.set_keyset(public_keyset_);

  JwtToJwkSetResponse to_jwk_response;
  ASSERT_TRUE(jwt.ToJwkSet(nullptr, &to_jwk_request, &to_jwk_response).ok());
  ASSERT_THAT(to_jwk_response.err(), IsEmpty());

  // Generate a public keyset from the JWK set
  JwtFromJwkSetRequest from_jwk_request;
  from_jwk_request.set_jwk_set(to_jwk_response.jwk_set());

  JwtFromJwkSetResponse from_jwk_response;
  ASSERT_TRUE(
      jwt.FromJwkSet(nullptr, &from_jwk_request, &from_jwk_response).ok());
  ASSERT_THAT(from_jwk_response.err(), IsEmpty());

  // Verify the token using the public keyset
  JwtVerifyRequest verify_request;
  verify_request.mutable_annotated_keyset()->set_serialized_keyset(
      from_jwk_response.keyset());
  verify_request.set_signed_compact_jwt(comp_response.signed_compact_jwt());
  JwtValidator* validator = verify_request.mutable_validator();
  validator->mutable_expected_issuer()->set_value("issuer");
  validator->mutable_now()->set_seconds(23456);
  JwtVerifyResponse verify_response;

  ASSERT_TRUE(
      jwt.PublicKeyVerifyAndDecode(nullptr, &verify_request, &verify_response)
          .ok());
  ASSERT_THAT(verify_response.err(), IsEmpty());
  const JwtToken& verified_jwt = verify_response.verified_jwt();
  EXPECT_THAT(verified_jwt.issuer().value(), Eq("issuer"));
  EXPECT_THAT(verified_jwt.expiration().seconds(), Eq(34567));
}

TEST_F(JwtImplSignatureTest, FromJwkInvalidFails) {
  tink_testing_api::JwtImpl jwt;
  JwtFromJwkSetRequest from_jwk_request;
  from_jwk_request.set_jwk_set("invalid");

  JwtFromJwkSetResponse from_jwk_response;
  ASSERT_TRUE(
      jwt.FromJwkSet(nullptr, &from_jwk_request, &from_jwk_response).ok());
  EXPECT_THAT(from_jwk_response.err(), Not(IsEmpty()));
}

TEST_F(JwtImplSignatureTest, ToJwkInvalidFails) {
  tink_testing_api::JwtImpl jwt;
  JwtToJwkSetRequest to_jwk_request;
  to_jwk_request.set_keyset("invalid");

  JwtToJwkSetResponse to_jwk_response;
  ASSERT_TRUE(jwt.ToJwkSet(nullptr, &to_jwk_request, &to_jwk_response).ok());
  EXPECT_THAT(to_jwk_response.err(), Not(IsEmpty()));
}

}  // namespace
}  // namespace tink
}  // namespace crypto


text:
<!doctype html>

  <meta charset='utf-8'>
  <title>SourceBuffer#abort() for already removed buffer from parent media source</title>


text:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

  <title>VS_KEYWORD — CMake 3.7.2 Documentation</title>

    <link rel="stylesheet" href="../_static/cmake.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />

    <link rel="shortcut icon" href="../_static/cmake-favicon.ico"/>
    <link rel="top" title="CMake 3.7.2 Documentation" href="../index.html" />
    <link rel="up" title="cmake-properties(7)" href="../manual/cmake-properties.7.html" />
    <link rel="next" title="VS_MOBILE_EXTENSIONS_VERSION" href="VS_MOBILE_EXTENSIONS_VERSION.html" />
    <link rel="prev" title="VS_IOT_STARTUP_TASK" href="VS_IOT_STARTUP_TASK.html" />

Navigation

          index

          next |

          previous |

    CMake »

    3.7.2 Documentation »

cmake-properties(7) »

VS_KEYWORD¶

Visual Studio project keyword for VS 9 (2008) and older.

Can be set to change the visual studio keyword, for example Qt
integration works better if this is set to Qt4VSv1.0.

Use the VS_GLOBAL_KEYWORD target property to set the
keyword for Visual Studio 10 (2010) and newer.

Previous topic

VS_IOT_STARTUP_TASK

Next topic

VS_MOBILE_EXTENSIONS_VERSION

This Page

Show Source

Quick search

    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>

    Enter search terms or a module, class or function name.

Navigation

          index

          next |

          previous |

    CMake »

    3.7.2 Documentation »

cmake-properties(7) »

        © Copyright 2000-2016 Kitware, Inc. and Contributors.
      Created using Sphinx 1.4a0+.


text:
package com.google.template.soy.base.internal;

import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.fail;

import com.google.common.base.CharMatcher;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

/** Tests for {@link UniqueNameGenerator} */
@RunWith(JUnit4.class)
public final class UniqueNameGeneratorTest {

  @Test
  public void testFieldNames() {
    UniqueNameGenerator nameSet = new UniqueNameGenerator(CharMatcher.anyOf("<>"), "%");
    try {
      nameSet.claimName("foo<int>");
      fail();
    } catch (IllegalArgumentException expected) {
      assertThat(expected).hasMessageThat().contains("contains dangerous characters!");
    }
    assertThat(nameSet.hasName("foo<int>")).isFalse();

    nameSet.claimName("foo");
    try {
      nameSet.claimName("foo");
      fail();
    } catch (IllegalArgumentException expected) {
      assertThat(expected).hasMessageThat().contains("already claimed!");
    }
    assertThat(nameSet.hasName("foo")).isTrue();
    assertThat(nameSet.generateName("foo")).isEqualTo("foo%1");
    assertThat(nameSet.generateName("foo")).isEqualTo("foo%2");
  }

  @Test
  public void testClassNames() {
    UniqueNameGenerator nameSet = new UniqueNameGenerator(CharMatcher.anyOf("$"), "%");
    try {
      nameSet.claimName("foo$"); // '$' is considered dangerous
      fail();
    } catch (IllegalArgumentException expected) {
      assertThat(expected).hasMessageThat().contains("contains dangerous characters!");
    }
    nameSet.claimName("foo");
  }

  @Test
  public void testHasName() {
    UniqueNameGenerator nameSet = new UniqueNameGenerator(CharMatcher.none(), "%");
    String foo = nameSet.generateName("foo");
    String foo2 = nameSet.generateName("foo");
    String foo3 = nameSet.generateName("foo");
    assertThat(foo).isEqualTo("foo");
    assertThat(foo).isNotEqualTo(foo2);
    assertThat(foo).isNotEqualTo(foo3);
    assertThat(foo2).isNotEqualTo(foo3);
    assertThat(nameSet.hasName("foo")).isTrue();
    assertThat(nameSet.hasName(foo)).isTrue();
    assertThat(nameSet.hasName(foo2)).isTrue();
    assertThat(nameSet.hasName(foo3)).isTrue();
  }
}


text:
		<button class="btn btn-md btn-warning" id="btn_edita_recepcion" title="Editar solicitud"></button>
		<button class="btn btn-md btn-danger" id="btn_elimina_recepcion" title="Eliminar solicitud"></button>
		<button class="btn btn-md btn-primary" id="btn_exporta_recepcion" title="Generar oficio"></button>

			  <input type="text" class="form-control" id="txt_id_solicitud" placeholder="ID de solicitud" >

			  <input type="text" class="form-control" id="txt_dependencia_solicitud" placeholder="Dependencia">

			  <input type="text" class="form-control" id="txt_departamento_solicitud" placeholder="Departamento">

			  <input type="text" class="form-control" id="txt_autor_solicitud" placeholder="Autor">

	    <input type="checkbox" value="" id="chk_por_fechas">
	    Por Fechas

		<button class="btn btn-sm btn-success" id="btn_busqueda_avanzada"> Buscar</button>

				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>

Registro de la obra

							Nombre del autor
							<input type="text" class="form-control">

				<button type="button" class="close" id="cierra_modal_aux_autor" aria-hidden="true">×</button>

Seleccione Autor

							Nombre del autor
							<input type="text" class="form-control">


text:
MenuState::MenuState(Game* game)
    : GameState(game)
    , m_TextureFileName("Textures/menuScreen.png")
{
    m_Game->getShaderManager().useShader("Texture");

    createTexture();
    createVertexBuffer();
    setupVertexAttrib();

    passTextureToShader();
    passMatrixToShader();
}

MenuState::~MenuState()
{
    glDeleteTextures(1, &m_Texture);
}

void MenuState::passMatrixToShader()
{
    auto mvpLocation = m_Game->getShaderManager().getShader("Texture")->getUniformLocation("in_MvpMatrix");
    glUniformMatrix4fv(mvpLocation, 1, GL_FALSE, glm::value_ptr(glm::mat4(1.f)));
}

void MenuState::passTextureToShader()
{
    auto texLocation = m_Game->getShaderManager().getShader("Texture")->getUniformLocation("in_Texture");
    glUniform1i(texLocation, GL_TEXTURE0);
}

void MenuState::setupVertexAttrib()
{
    auto posAttrib = m_Game->getShaderManager().getShader("Texture")->getAttribLocation("in_Position");
    auto texCoordAttrib = m_Game->getShaderManager().getShader("Texture")->getAttribLocation("in_TexCoord");

    glVertexAttribPointer(posAttrib, 2, GL_FLOAT, GL_FALSE, 4*sizeof(float), 0);
    glEnableVertexAttribArray(posAttrib);
    glVertexAttribPointer(texCoordAttrib, 2, GL_FLOAT, GL_FALSE, 4*sizeof(float), (void*)(2*sizeof(float)));
    glEnableVertexAttribArray(texCoordAttrib);
}

void MenuState::createVertexBuffer()
{
    m_VertexBuffer.init();
    m_VertexBuffer.bind();
    m_VertexBuffer.setData(
        {
            -1.f, -1.f, 0.f, 1.f,
            1.f, -1.f, 1.f, 1.f,
            1.f, 1.f, 1.f, 0.f,
            1.f, 1.f, 1.f, 0.f,
            -1.f, 1.f, 0.f, 0.f,
            -1.f, -1.f, 0.f, 1.f
        });
}

void MenuState::createTexture()
{
    glActiveTexture(GL_TEXTURE0);
    glGenTextures(1, &m_Texture);
    glBindTexture(GL_TEXTURE_2D, m_Texture);

    setTextureWrapping();
    setTextureFiltering();

    glGenerateMipmap(GL_TEXTURE_2D);

    auto textureData = loadTextureData();

    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, m_TextureWidth, m_TextureHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, textureData);

    SOIL_free_image_data(textureData);
}

unsigned char* MenuState::loadTextureData()
{
    return SOIL_load_image(m_TextureFileName.c_str(), &m_TextureWidth, &m_TextureHeight, 0, SOIL_LOAD_RGB);
}

void MenuState::setTextureWrapping()
{
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
}

void MenuState::setTextureFiltering()
{
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
}

void MenuState::keyPressed(unsigned char key, int x, int y)
{
    m_Game->startPlaying();
}

void MenuState::update(int delta)
{

}

void MenuState::display()
{
    m_VertexBuffer.bind();
    m_Game->getShaderManager().useShader("Texture");

    setupVertexAttrib();
    passTextureToShader();
    passMatrixToShader();

    glDrawArrays(GL_TRIANGLES, 0, 12);
}


text:
MERGE INTO [dbo].Country AS TargetTable
    USING (VALUES
        ('GB', 'Great Britain'),
        ('US', 'United States')
    ) AS SourceTable (Code, Name)
    ON TargetTable.Code = SourceTable.Code
    WHEN MATCHED THEN
        UPDATE SET
            [Code] = SourceTable.Code,
            [Name] = SourceTable.Name
    WHEN NOT MATCHED BY TARGET THEN
        INSERT (Code, Name)
        VALUES (Code, Name)
    WHEN NOT MATCHED BY SOURCE THEN
        DELETE;


text:
Hi there. If you want to develop on OpenDesk, you've come to the right place.
Documentation now uses Markdown notation for ease of editing. [Learn markdown.](https://help.github.com/articles/basic-writing-and-formatting-syntax/)

* [Getting started guide](/documentation/getting-started-guide.md)

* [Workflow guide](/documentation/workflow-guide.md)

* [Use cases](/documentation/userstories.md)

## Modules

This area contains information specific to the various modules that OpenDesk app is made of.

* [Projects](/app/src/sites/README.md)

* [Chat module (odChat)](/app/src/odChat/README.md)

## Widgets

Custom widgets are listed here along with tips on how to implement them.

* [Dashboard tiles](/documentation/dashboard-tiles.md)

* [Flyout](/documentation/flyout.md)

## Technical info

Here are some technical details for developers.

### Problems with refresh when working with dialogs

We have had problems with refresh of components when working in a dialog. This is a problem caused by not beeing in the same scope.
The solution is to pass on the current scope to the dialog. Your component then has to be a part of the scope
It is illustrated in the following

```
// put your variable in the $scope
$scope.members = [];

// pass the current scope to your component
vm.uploadDocumentsDialog = function (event) {
    $mdDialog.show({
        templateUrl: 'app/src/sites/view/uploadDocuments.tmpl.html',
        parent: angular.element(document.body),
        targetEvent: event,
        scope: $scope,        // use parent scope in template
        preserveScope: true,  // do not forget this if use parent scope
        clickOutsideToClose: true
    });
};

```

**Gotchas**
Don't add the controller again in the template, this will make refresh fail

```
<md-dialog aria-label="New member" ng-controller="SiteController as siteCtrl" ng-cloak>
```

If you do like above, the refresh will fail as the controller is loaded again. You dont need to add the controller, the variables are already available.

### Public site

A publicly facing site running OpenDesk can be found at http://staging.opendesk.dk/#!/login

### Gulp

Gulp is a script handler that helps you build the site on the fly while developing. A complete build can be done by going to your project's dir in a terminal and running
```
$ gulp build
```
The gulp build task both compiles your JS and CSS, and runs a security check for known vunerabilities using Node Security Project.
To have Gulp watch and concatenate your SASS files when you edit them, use
```
$ gulp watch
```

### Git

You can make git remember your username for every push by going to console and entering
```
$ git config credential.username yourusername
```
Read more info on working with git in the workflow guide below and check the [git cheat sheet.](/documentation/git-cheat-sheet.md)

## How to update the staging environment

The staging site can be accessed at http://staging.opendesk.dk/#!/

In order to update its codebase, log on to the server with your user via ssh:
```
ssh my-user@staging.opendesk.dk
```
change to the folder where staging is setup:
```
cd /var/www/staging/OpenDESK-UI/
```

change the user to the magenta user, as it is the owner of code repository:
First:
```
sudo bash
```

You will be prompted for your own user's password after which you can then switch to the magenta user:
```
su magenta
```
You then need to pull down the latest code base and compile and build the code:
To pull from github:
```
git pull
```

now build the project and update any newly added dependencies
```
npm update
npm i  // (You might be prompted to enter which version of a dependency you'd like to use)

gulp build  // (to build the files.)
```

finally exit back to your user shell then restart the apache server
```
exit // exits from the 'magenta' user to the root shell
exit // exits from the 'root' shell you your user shell
sudo service apache2 restart  // (you will be prompted for your own password)
```