TxnFilterTxnTSEndTest.scala 4.79 KB
Newer Older
35V LG84's avatar
35V LG84 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
/*
 * Copyright 2018 E257.FI
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
package fi.e257.tackler.filter

import java.time.{ZoneId, ZonedDateTime}

import org.scalatest.FlatSpecLike

import fi.e257.tackler.api.{TxnFilterDefinition, TxnFilterTxnTSEnd}
import fi.e257.tackler.core.Settings
import fi.e257.tackler.parser.TacklerTxns

class TxnFilterTxnTSEndTest extends TxnFilterSpec with FlatSpecLike{

  val tt = new TacklerTxns(Settings())

  val uuidTSDate01 = "22e17bf5-3da5-404d-aaff-e3cc668191ee"
  val uuidTSDate02 = "a88f4981-ebe7-4287-a59c-d444e3bd579a"
  val uuidTSDate03 = "16cf7363-45d2-480c-ac49-c710f4ea5f0d"

  val txnStrTSDate =
    s"""2018-01-01
37
       | # uuid: ${uuidTSDate01}
35V LG84's avatar
35V LG84 committed
38 39 40 41
       | e  1
       | a
       |
       |2018-02-01
42
       | # uuid: ${uuidTSDate02}
35V LG84's avatar
35V LG84 committed
43 44 45 46
       | e  1
       | a
       |
       |2018-03-01
47
       | # uuid: ${uuidTSDate03}
35V LG84's avatar
35V LG84 committed
48 49 50 51 52 53 54 55 56 57 58 59
       | e  1
       | a
       |
       |""".stripMargin

  val txnsTSDate = tt.string2Txns(txnStrTSDate)
  val uuidTSTime01 = "ec1b0e67-f990-4761-9667-239a5a6cd46b"
  val uuidTSTime02 = "080ee755-04cf-44d8-94db-e89ca7b9cd13"
  val uuidTSTime03 = "03b13353-ee04-4faa-b139-d5b097f6b9b5"

  val txnStrTSTime =
    s"""2018-01-01T11:00:00
60
       | # uuid: ${uuidTSTime01}
35V LG84's avatar
35V LG84 committed
61 62 63 64
       | e  1
       | a
       |
       |2018-01-01T23:00:00
65
       | # uuid: ${uuidTSTime02}
35V LG84's avatar
35V LG84 committed
66 67 68 69
       | e  1
       | a
       |
       |2018-01-02T00:00:00
70
       | # uuid: ${uuidTSTime03}
35V LG84's avatar
35V LG84 committed
71 72 73 74 75 76 77 78 79 80 81 82 83 84
       | e  1
       | a
       |
       |""".stripMargin

  val txnsTSTime = tt.string2Txns(txnStrTSTime)


  val uuidTSNano01 = "faeda0cf-2db2-4d91-9d85-8eb31c4cf598"
  val uuidTSNano02 = "7202f635-61d1-41a5-9b2b-d5a9e2ab6f9b"
  val uuidTSNano03 = "520345ad-b06f-4717-b2aa-5f79daf5c44d"

  val txnStrTSNano =
    s"""2018-01-01T14:00:00.123456787
85
       | # uuid: ${uuidTSNano01}
35V LG84's avatar
35V LG84 committed
86 87 88 89
       | e  1
       | a
       |
       |2018-01-01T14:00:00.123456788
90
       | # uuid: ${uuidTSNano02}
35V LG84's avatar
35V LG84 committed
91 92 93 94
       | e  1
       | a
       |
       |2018-01-01T14:00:00.123456789
95
       | # uuid: ${uuidTSNano03}
35V LG84's avatar
35V LG84 committed
96 97 98 99 100 101 102 103 104 105 106 107 108
       | e  1
       | a
       |
       |""".stripMargin

  val txnsTSTNano = tt.string2Txns(txnStrTSNano)

  val uuidTSZone01 = "e06360fd-526e-4725-8d9f-d4aae8f84ad1"
  val uuidTSZone02 = "605fb2eb-def5-41dd-b885-950602685bb4"
  val uuidTSZone03 = "55455800-1aad-4ef4-9795-235eb082f4ea"

  val txnStrTSZone =
    s"""2018-01-04T09:00:00+10:00
109
       | # uuid: ${uuidTSZone01}
35V LG84's avatar
35V LG84 committed
110 111 112 113
       | e  1
       | a
       |
       |2018-01-03T18:00:00-06:00
114
       | # uuid: ${uuidTSZone02}
35V LG84's avatar
35V LG84 committed
115 116 117 118 119
       | ; Zone support must be tested with offsets which cancel each others (e.g. result is same time in UTC)
       | e  1
       | a
       |
       |2018-01-04T00:00:00
120
       | # uuid: ${uuidTSZone03}
35V LG84's avatar
35V LG84 committed
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
       | e  1
       | a
       |
       |""".stripMargin

  val txnsTSZone = tt.string2Txns(txnStrTSZone)

  behavior of "Timestamp filter: End"
  /**
   * test: 42a42f07-dea5-45ee-b563-187f9121e1e1
   */
  it must "filter by date" in {
    val txnFilter = TxnFilterTxnTSEnd(
      ZonedDateTime.of(
        2018, 2, 1,
        0, 0, 0, 0,
        ZoneId.of("UTC")))

    val txnData = txnsTSDate.filter(TxnFilterDefinition(txnFilter))

    assert(txnData.txns.size === 1)
    assert(checkUUID(txnData, uuidTSDate01))
  }

  /**
   * test: 4e566d2b-da32-4336-9b7f-d7c4a59658d2
   */
  it must "filter by time" in {
    val txnFilter = TxnFilterTxnTSEnd(
      ZonedDateTime.of(
        2018, 1, 1,
        23, 0, 0, 0,
        ZoneId.of("UTC")))

    val txnData = txnsTSTime.filter(TxnFilterDefinition(txnFilter))

    assert(txnData.txns.size === 1)
    assert(checkUUID(txnData, uuidTSTime01))
  }

  /**
   * test: f6081a60-92a9-4051-85d7-c993e3cc03be
   */
  it must "filter by nanoseconds" in {
    val txnFilter = TxnFilterTxnTSEnd(
      ZonedDateTime.of(
        2018, 1, 1,
        14, 0, 0, 123456788,
        ZoneId.of("UTC")))

    val txnData = txnsTSTNano.filter(TxnFilterDefinition(txnFilter))

    assert(txnData.txns.size === 1)
    assert(checkUUID(txnData, uuidTSNano01))
  }

  /**
   * test: ab53df34-d22a-4256-9c4d-6d1ccf0ef32e
   */
  it must "filter by timezone" in {
    val txnFilter = TxnFilterTxnTSEnd(
      ZonedDateTime.of(
        2018, 1, 4,
        0, 0, 0, 0,
        ZoneId.of("UTC")))

    val txnData = txnsTSZone.filter(TxnFilterDefinition(txnFilter))

    assert(txnData.txns.size === 1)
    assert(checkUUID(txnData, uuidTSZone01))
  }
}