summaryrefslogtreecommitdiff
path: root/src/test/groovy/org/xapek/yvesf/classifieds/UnitTest.groovy
blob: 6d6f7649a4cfd45ca757dbfe688a6de1ab96fdd5 (plain)
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package org.xapek.yvesf.classifieds

import groovy.transform.CompileStatic
import org.junit.Test
import org.xapek.yvesf.classifieds.util.Success

@CompileStatic
class UnitTest {
  @Test
  void testRead() {
    final data = Main.readInputStream(UnitTest.getResourceAsStream('test.json'))
    assert data instanceof Map
  }

  @Test
  void testParse() {
    final data = Main.handleData(Main.readInputStream(UnitTest.getResourceAsStream('test.json')))
    assert data instanceof Success
    assert data.success
    assert data.value instanceof Model.ClassifiedsList
    assert data.value.totalCount > 0
    assert data.value.size() > 0
  }

  @Test
  void testDump() {
    final os = new ByteArrayOutputStream()
    final list = new Model.ClassifiedsList(totalCount: 100)
    list.add(new Model.Classified([
        'available'  : 'value=available',
        'location'   : 'value=location',
        'city'       : 'value=city',
        'type'       : 'value=type',
        'price'      : 'value=price',
        'currency'   : 'value=currency',
        'views'      : 'value=views',
        'title'      : 'value=title',
        'id'         : 'value=id',
        'mem_name'   : 'value=mem_name',
        'mem_id'     : '0',
        'description': 'value=description',
        'photo1'     : 'asd',
        'photo2'     : 0,
        'photo3'     : 0,
        'photo4'     : 0,
        'date'       : 'Apr 01, 99',
        'rooms'      : '1',
    ]))
    Dumper.dump(list, new PrintWriter(os))
    final output = os.toString()
    assert output.contains("value=city")
    assert output.contains("value=title")
    assert output.contains("value=description")
  }
}