|
| 1 | +/* |
| 2 | + * Copyright 2018 ABSA Group Limited |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package za.co.absa.cobrix.cobol.reader |
| 18 | + |
| 19 | +import org.scalatest.wordspec.AnyWordSpec |
| 20 | +import org.slf4j.LoggerFactory |
| 21 | +import za.co.absa.cobrix.cobol.mock.CustomRecordExtractorMock |
| 22 | +import za.co.absa.cobrix.cobol.reader.extractors.raw.RawRecordContext |
| 23 | +import za.co.absa.cobrix.cobol.reader.memorystream.TestStringStream |
| 24 | + |
| 25 | +class RecordExtractorDebugSpec extends AnyWordSpec { |
| 26 | + private val log = LoggerFactory.getLogger("debug") |
| 27 | + |
| 28 | + private val data = "AABBBCCDDDEEFFF" |
| 29 | + |
| 30 | + // This is a code snippet that can be used to test custom record extractors |
| 31 | + "record extractor data should be extracted as expected" in { |
| 32 | + val dataStream = new TestStringStream(data) |
| 33 | + val headerStream = new TestStringStream(data) |
| 34 | + |
| 35 | + val ctx = RawRecordContext(0, dataStream, headerStream, null, null, null, "") |
| 36 | + val extractor = new CustomRecordExtractorMock(ctx) |
| 37 | + |
| 38 | + var i = 0 |
| 39 | + log.info(s"${headerStream.offset} : headers") |
| 40 | + |
| 41 | + while (extractor.hasNext) { |
| 42 | + val offset = dataStream.offset |
| 43 | + val record = extractor.next() |
| 44 | + val recordHex = record.map(b => f"$b%02X").mkString.take(10) |
| 45 | + log.info(s"$offset : ${record.length} : $recordHex") |
| 46 | + i += 1 |
| 47 | + } |
| 48 | + |
| 49 | + assert(i == 6) |
| 50 | + } |
| 51 | +} |
0 commit comments