2012-01-19 14:38:44 +00:00
|
|
|
/**
|
2014-02-02 19:05:45 -06:00
|
|
|
* Copyright (C) 2009-2014 Typesafe Inc. <http://www.typesafe.com>
|
2012-01-19 14:38:44 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package akka.camel.internal.component
|
|
|
|
|
|
2012-09-19 17:32:54 +02:00
|
|
|
import language.postfixOps
|
|
|
|
|
|
2013-12-17 14:25:56 +01:00
|
|
|
import org.scalatest.Matchers
|
2012-09-21 14:50:06 +02:00
|
|
|
import scala.concurrent.duration._
|
2012-01-19 14:38:44 +00:00
|
|
|
import org.scalatest.WordSpec
|
2012-09-03 12:08:46 +02:00
|
|
|
import org.apache.camel.TypeConversionException
|
2012-01-19 14:38:44 +00:00
|
|
|
|
2013-12-17 14:25:56 +01:00
|
|
|
class DurationConverterSpec extends WordSpec with Matchers {
|
2012-01-19 14:38:44 +00:00
|
|
|
import DurationTypeConverter._
|
|
|
|
|
|
|
|
|
|
"DurationTypeConverter must convert '10 nanos'" in {
|
2013-12-17 14:25:56 +01:00
|
|
|
convertTo(classOf[Duration], "10 nanos") should be(10 nanos)
|
2012-01-19 14:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
"DurationTypeConverter must do the roundtrip" in {
|
2013-12-17 14:25:56 +01:00
|
|
|
convertTo(classOf[Duration], (10 seconds).toString()) should be(10 seconds)
|
2012-01-19 14:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
"DurationTypeConverter must throw if invalid format" in {
|
2014-01-31 11:14:13 +01:00
|
|
|
tryConvertTo(classOf[Duration], "abc nanos") should be(null)
|
2012-05-23 23:59:55 +02:00
|
|
|
|
2012-08-09 19:30:32 +02:00
|
|
|
intercept[TypeConversionException] {
|
2013-12-17 14:25:56 +01:00
|
|
|
mandatoryConvertTo(classOf[Duration], "abc nanos") should be(10 nanos)
|
2014-01-31 11:14:13 +01:00
|
|
|
}.getValue should be("abc nanos")
|
2012-01-19 14:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
2012-05-23 23:59:55 +02:00
|
|
|
"DurationTypeConverter must throw if doesn't end with time unit" in {
|
2014-01-31 11:14:13 +01:00
|
|
|
tryConvertTo(classOf[Duration], "10233") should be(null)
|
2012-05-23 23:59:55 +02:00
|
|
|
|
2012-08-09 19:30:32 +02:00
|
|
|
intercept[TypeConversionException] {
|
2013-12-17 14:25:56 +01:00
|
|
|
mandatoryConvertTo(classOf[Duration], "10233") should be(10 nanos)
|
2014-01-31 11:14:13 +01:00
|
|
|
}.getValue should be("10233")
|
2012-01-19 14:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|