+ def 'Failing DMI POST operation.'() {
+ given: 'the rest template returns a valid response entity'
+ def serverResponse = 'server response'.getBytes()
+ def httpServerErrorException = new HttpServerErrorException(HttpStatus.FORBIDDEN, 'status text', serverResponse, null)
+ mockRestTemplate.postForEntity(*_) >> { throw httpServerErrorException }
+ when: 'POST operation is invoked'
+ def result = objectUnderTest.postOperationWithJsonData('some url', 'some json', operation)
+ then: 'a Http Client Exception is thrown'
+ def thrown = thrown(HttpClientRequestException)
+ and: 'the exception has the relevant details from the error response'
+ assert thrown.httpStatus == 403
+ assert thrown.message == "Unable to ${operation} resource data."
+ assert thrown.details == 'server response'
+ where: 'the following operation is executed'
+ operation << [CREATE, READ, PATCH]
+ }
+
+ def 'Basic auth header #scenario'() {
+ when: 'Specific dmi properties are provided'
+ dmiProperties.dmiBasicAuthEnabled = authEnabled
+ objectUnderTest.dmiProperties = dmiProperties
+ then: 'http headers to conditionally have Authorization header'
+ assert (objectUnderTest.configureHttpHeaders(new HttpHeaders()).get('Authorization') != null) == isPresentInHttpHeader
+ where: 'the following configurations are used'
+ scenario | authEnabled || isPresentInHttpHeader
+ 'auth enabled' | true || true
+ 'auth disabled' | false || false
+ }
+