Index: src/resources/parts.csv =================================================================== diff -u --- src/resources/parts.csv (revision 0) +++ src/resources/parts.csv (revision b7644e82bd0bafac713bbd32cdf553a06bee096b) @@ -0,0 +1,2 @@ +b8es +hf111 \ No newline at end of file Fisheye: Tag b7644e82bd0bafac713bbd32cdf553a06bee096b refers to a dead (removed) revision in file `src/test/groovy/com/lemans/media/MediaApplicationTests.groovy'. Fisheye: No comparison available. Pass `N' to diff? Index: src/test/groovy/com/lemans/media/security/TokenVerifierFuncSpec.groovy =================================================================== diff -u --- src/test/groovy/com/lemans/media/security/TokenVerifierFuncSpec.groovy (revision 0) +++ src/test/groovy/com/lemans/media/security/TokenVerifierFuncSpec.groovy (revision b7644e82bd0bafac713bbd32cdf553a06bee096b) @@ -0,0 +1,35 @@ +package com.lemans.media.security + +import com.lemans.media.testing.MediaFuncSpec + + +class TokenVerifierFuncSpec extends MediaFuncSpec { + + def 'can act with a valid security token'() { + given: + System.setProperty('ignoreToken', 'true') + domain = null + path() + expectedStatusCode = 200 + + when: + get() + + then: + payload.results == 'media-service' + } + + def 'can NOT act without a valid security token'() { + given: + System.setProperty('ignoreToken', '') + domain = null + path() + expectedStatusCode = 401 + + when: + get() + + then: + payload.messages[0].text == 'no credentials' + } +} Index: src/test/groovy/com/lemans/media/temp/TemporaryMediaFunctionalSpec.groovy =================================================================== diff -u --- src/test/groovy/com/lemans/media/temp/TemporaryMediaFunctionalSpec.groovy (revision 0) +++ src/test/groovy/com/lemans/media/temp/TemporaryMediaFunctionalSpec.groovy (revision b7644e82bd0bafac713bbd32cdf553a06bee096b) @@ -0,0 +1,147 @@ +package com.lemans.media.temp + +import com.lemans.media.testing.MediaFuncSpec + +/** + * Created by vramisetti on 6/15/2016. + */ +class TemporaryMediaFunctionalSpec extends MediaFuncSpec { + + @Override + String resourceName() { 'media' } + + private static final String TEMP_FOLDER1 = 'temporaryDocumentPath' + + private static final String TEMP_FOLDER2 = 'temporaryMediaPath' + + def setupSpec() { + new File(TEMP_FOLDER1).mkdir() + new File(TEMP_FOLDER2).mkdir() + } + + def cleanupSpec() { + new File(TEMP_FOLDER1).deleteDir() + new File(TEMP_FOLDER2).deleteDir() + } + + def 'can add a document'() { + given: + ok() + domain = 18 + queryParams.mediaCategoryId = 1 + queryParams.mediaTypeId = 2 + queryParams.description = 'test' + path() + + when: + multiPartPost(['src/resources/parts.csv']) + + then: + payload.results[0].tempId + payload.results[0].mediaCategoryId == 1 + payload.results[0].mediaTypeId == 2 + payload.results[0].fileName == 'parts' + payload.results[0].extension == 'csv' + payload.results[0].prefixUrl == 'dealer/temp/' + payload.results[0].description == 'test' + new File(TEMP_FOLDER1 + "/${payload.results[0].tempId}.csv").exists() + } + + def 'can NOT add a document with out mediaCategoryId'() { + given: + domain = 18 + queryParams.mediaTypeId = 2 + path() + invalid() + + when: + multiPartPost(['src/resources/parts.csv']) + + then: + with(payload) { + with(messages[0]) { + type == 'error' + text == 'Media Category is a required field' + } + } + } + + def 'can NOT add a document with out mediaTypeId'() { + given: + domain = 18 + queryParams.mediaCategoryId = 1 + path() + invalid() + + when: + multiPartPost(['src/resources/parts.csv']) + + then: + with(payload) { + with(messages[0]) { + type == 'error' + text == 'Media Type is a required field' + } + } + } + + def 'can NOT add media with out a file'() { + given: + domain = 18 + queryParams.mediaCategoryId = 1 + queryParams.mediaTypeId = 2 + path() + invalid() + + when: + multiPartPost([]) + + then: + with(payload) { + with(messages[0]) { + type == 'error' + text == 'No files found to upload!' + } + } + } + + def 'can add a temporary media'() { + given: + ok() + domain = 18 + path('temp') + + when: + multiPartPost(['src/resources/parts.csv']) + + then: + with (payload.results) { + tempId + mediaTypeId == 14002 + mimeTypeId == 201 + mediaTypeCode == 'doc' + originalFileName == 'parts' + extension == 'csv' + prefixUrl == 'media/' + new File(TEMP_FOLDER2 + "/${tempId}.csv").exists() + } + } + + def 'can NOT add temporary media with out a file'() { + given: + domain = 18 + path('temp') + invalid() + + when: + multiPartPost([]) + + then: + with(payload) { + with(messages[0]) { + type == 'error' + text == 'No file found to upload!' + } + } + } +} Index: src/test/groovy/com/lemans/media/testing/MediaFuncSpec.groovy =================================================================== diff -u --- src/test/groovy/com/lemans/media/testing/MediaFuncSpec.groovy (revision 0) +++ src/test/groovy/com/lemans/media/testing/MediaFuncSpec.groovy (revision b7644e82bd0bafac713bbd32cdf553a06bee096b) @@ -0,0 +1,23 @@ +package com.lemans.media.testing + +import com.lemans.media.MediaApplication +import com.lemans.testing.LemansApiFunctionalSpec +import groovyx.net.http.HTTPBuilder +import org.springframework.beans.factory.annotation.Value +import org.springframework.boot.test.context.SpringBootTest + +@SpringBootTest(classes = MediaApplication, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +class MediaFuncSpec extends LemansApiFunctionalSpec { + + @Override + final String serviceName() { 'media-service' } + + @Value('${local.server.port}') + Integer serverPort + + def setup() { + port = serverPort + http = new HTTPBuilder(url()) + } +} +