import com.google.gson.JsonObject;
import java.io.IOException;
+import java.nio.charset.Charset;
import java.util.Optional;
import org.junit.jupiter.api.BeforeEach;
import org.oransc.policyagent.utils.LoggingUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
+import org.springframework.web.reactive.function.client.WebClientResponseException;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
verifyNoMoreInteractions(dmaapClient);
}
+ @Test
+ void exceptionFromAgentWhenGet_thenPostError() throws IOException {
+ String errorBody = "Unavailable";
+ WebClientResponseException webClientResponseException = new WebClientResponseException(
+ HttpStatus.SERVICE_UNAVAILABLE.value(), "", (HttpHeaders) null, errorBody.getBytes(), (Charset) null);
+ doReturn(Mono.error(webClientResponseException)).when(agentClient).getForEntity(anyString());
+ doReturn(Mono.just("OK")).when(dmaapClient).post(anyString(), anyString());
+
+ StepVerifier //
+ .create(testedObject.createTask(dmaapInputMessage(Operation.GET))) //
+ .expectSubscription() //
+ .verifyComplete(); //
+
+ ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
+ verify(dmaapClient).post(anyString(), captor.capture());
+ String actualMessage = captor.getValue();
+ assertThat(actualMessage).contains(HttpStatus.SERVICE_UNAVAILABLE.toString()) //
+ .contains(errorBody);
+ }
+
@Test
void successfulPut() throws IOException {
doReturn(okResponse()).when(agentClient).putForEntity(anyString(), anyString());
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
verify(dmaapClient).post(anyString(), captor.capture());
String actualMessage = captor.getValue();
- assertThat(actualMessage).contains(HttpStatus.BAD_GATEWAY.toString())
- .as("Message \"%s\" sent to DMaaP contains %s", actualMessage, HttpStatus.BAD_GATEWAY);
+ assertThat(actualMessage).as("Message \"%s\" sent to DMaaP contains %s", actualMessage, HttpStatus.BAD_GATEWAY)
+ .contains(HttpStatus.BAD_GATEWAY.toString());
verifyNoMoreInteractions(dmaapClient);
}
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
verify(dmaapClient).post(anyString(), captor.capture());
String actualMessage = captor.getValue();
- assertThat(actualMessage).contains("Not implemented operation");
- assertThat(actualMessage).contains("BAD_REQUEST");
+ assertThat(actualMessage).contains("Not implemented operation") //
+ .contains("BAD_REQUEST");
}
@Test