+
+ @Test
+ public void testPushNewModelsBadRequest() {
+ when(config.getAaiBaseUrl()).thenReturn("");
+ when(config.getAaiModelUrl(any())).thenReturn("");
+ when(config.getAaiNamedQueryUrl(any())).thenReturn("");
+
+ ResponseEntity getResult = mock(ResponseEntity.class);
+ when(aaiClient.getResource(any(), any(), any(), any())).thenReturn(getResult);
+ when(getResult.getStatusCode()).thenReturn(HttpStatus.NOT_FOUND);
+
+ ResponseEntity putResult = mock(ResponseEntity.class);
+ when(aaiClient.putResource(any(), any(), any(), any(), any())).thenReturn(putResult);
+ when(putResult.getStatusCode()).thenReturn(HttpStatus.BAD_REQUEST);
+
+ checkRollback(Collections.singletonList(new ModelArtifact()));
+ }
+
+ @Test
+ public void testBadRequestResourceModelResult() {
+ when(config.getAaiBaseUrl()).thenReturn("");
+ when(config.getAaiModelUrl(any())).thenReturn("");
+
+ ResponseEntity operationResult = mock(ResponseEntity.class);
+ when(aaiClient.getResource(any(), any(), any(), any())).thenReturn(operationResult);
+ when(operationResult.getStatusCode()).thenReturn(HttpStatus.BAD_REQUEST);
+
+ checkRollback(Collections.singletonList(new ModelArtifact()));
+ }
+
+ private void checkRollback(List<Artifact> artifacts) {
+ ModelArtifactHandler handler = new ModelArtifactHandler(config);
+ boolean pushed = handler.pushArtifacts(artifacts, "", Collections.emptyList(), aaiClient);
+ assertThat(pushed, is(false));
+ handler.rollback(artifacts, "", aaiClient);
+ }