PageRenderTime 8ms CodeModel.GetById 2ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/test/unit/inventario/EntradaControllerTests.groovy

http://github.com/jdmr/mateo
Groovy | 159 lines | 87 code | 65 blank | 7 comment | 31 complexity | f6d7b65281582312b01cdf8a4230aede MD5 | raw file
  1package inventario
  2
  3
  4
  5import org.junit.*
  6import grails.test.mixin.*
  7
  8
  9@TestFor(EntradaController)
 10@Mock(Entrada)
 11class EntradaControllerTests {
 12
 13
 14    @Test
 15    void testIndex() {
 16        controller.index()
 17        assert "/entrada/list" == response.redirectedUrl
 18    }
 19
 20    @Test
 21    void testList() {
 22
 23        def model = controller.list()
 24
 25        assert model.entradaInstanceList.size() == 0
 26        assert model.entradaInstanceTotal == 0
 27
 28    }
 29
 30    @Test
 31    void testCreate() {
 32       def model = controller.create()
 33
 34       assert model.entradaInstance != null
 35
 36
 37    }
 38
 39    @Test
 40    void testSave() {
 41        controller.save()
 42
 43        assert model.entradaInstance != null
 44        assert view == '/entrada/create'
 45
 46        // TODO: Populate valid properties
 47
 48        controller.save()
 49
 50        assert response.redirectedUrl == '/entrada/show/1'
 51        assert controller.flash.message != null
 52        assert Entrada.count() == 1
 53    }
 54
 55
 56    @Test
 57    void testShow() {
 58        controller.show()
 59
 60        assert flash.message != null
 61        assert response.redirectedUrl == '/entrada/list'
 62
 63
 64        def entrada = new Entrada()
 65
 66        // TODO: populate domain properties
 67
 68        assert entrada.save() != null
 69
 70        params.id = entrada.id
 71
 72        def model = controller.show()
 73
 74        assert model.entradaInstance == entrada
 75    }
 76
 77    @Test
 78    void testEdit() {
 79        controller.edit()
 80
 81        assert flash.message != null
 82        assert response.redirectedUrl == '/entrada/list'
 83
 84
 85        def entrada = new Entrada()
 86
 87        // TODO: populate valid domain properties
 88
 89        assert entrada.save() != null
 90
 91        params.id = entrada.id
 92
 93        def model = controller.edit()
 94
 95        assert model.entradaInstance == entrada
 96    }
 97
 98    @Test
 99    void testUpdate() {
100
101        controller.update()
102
103        assert flash.message != null
104        assert response.redirectedUrl == '/entrada/list'
105
106        response.reset()
107
108
109        def entrada = new Entrada()
110
111        // TODO: populate valid domain properties
112
113        assert entrada.save() != null
114
115        // test invalid parameters in update
116        params.id = entrada.id
117
118        controller.update()
119
120        assert view == "/entrada/edit"
121        assert model.entradaInstance != null
122
123        entrada.clearErrors()
124
125        // TODO: populate valid domain form parameter
126        controller.update()
127
128        assert response.redirectedUrl == "/entrada/show/$entrada.id"
129        assert flash.message != null
130    }
131
132    @Test
133    void testDelete() {
134        controller.delete()
135
136        assert flash.message != null
137        assert response.redirectedUrl == '/entrada/list'
138
139        response.reset()
140
141        def entrada = new Entrada()
142
143        // TODO: populate valid domain properties
144        assert entrada.save() != null
145        assert Entrada.count() == 1
146
147        params.id = entrada.id
148
149        controller.delete()
150
151        assert Entrada.count() == 0
152        assert Entrada.get(entrada.id) == null
153        assert response.redirectedUrl == '/entrada/list'
154
155
156    }
157
158
159}