@Test void identity_provider_can_not_write() throws Exception { mockMvc.perform( post("/identity-providers") .accept(MediaType.APPLICATION_JSON) .header("Authorization", "bearer " + adminToken)) .andExpect(status().isServiceUnavailable()) .andExpect(jsonPath("error").value(LimitedModeUaaFilter.ERROR_CODE)) .andExpect(jsonPath("error_description").value(LimitedModeUaaFilter.ERROR_MESSAGE)); mockMvc.perform( put("/identity-providers/{id}", "some-invalid-id") .accept(MediaType.APPLICATION_JSON) .header("Authorization", "bearer " + adminToken)) .andExpect(status().isServiceUnavailable()) .andExpect(jsonPath("error").value(LimitedModeUaaFilter.ERROR_CODE)) .andExpect(jsonPath("error_description").value(LimitedModeUaaFilter.ERROR_MESSAGE)); }
@Test void users_can_not_write() throws Exception { mockMvc.perform( post("/Users") .accept(MediaType.APPLICATION_JSON) .header("Authorization", "bearer " + adminToken)) .andExpect(status().isServiceUnavailable()) .andExpect(jsonPath("error").value(LimitedModeUaaFilter.ERROR_CODE)) .andExpect(jsonPath("error_description").value(LimitedModeUaaFilter.ERROR_MESSAGE)); mockMvc.perform( put("/Users/{id}", "some-invalid-id") .accept(MediaType.APPLICATION_JSON) .header("Authorization", "bearer " + adminToken)) .andExpect(status().isServiceUnavailable()) .andExpect(jsonPath("error").value(LimitedModeUaaFilter.ERROR_CODE)) .andExpect(jsonPath("error_description").value(LimitedModeUaaFilter.ERROR_MESSAGE)); }
@Test void groups_can_not_write() throws Exception { mockMvc.perform( post("/Groups") .accept(MediaType.APPLICATION_JSON) .header("Authorization", "bearer " + adminToken)) .andExpect(status().isServiceUnavailable()) .andExpect(jsonPath("error").value(LimitedModeUaaFilter.ERROR_CODE)) .andExpect(jsonPath("error_description").value(LimitedModeUaaFilter.ERROR_MESSAGE)); mockMvc.perform( put("/Groups/{id}", "some-invalid-id") .accept(MediaType.APPLICATION_JSON) .header("Authorization", "bearer " + adminToken)) .andExpect(status().isServiceUnavailable()) .andExpect(jsonPath("error").value(LimitedModeUaaFilter.ERROR_CODE)) .andExpect(jsonPath("error_description").value(LimitedModeUaaFilter.ERROR_MESSAGE)); }
@Test void clients_can_not_write() throws Exception { mockMvc.perform( post("/oauth/clients") .accept(MediaType.APPLICATION_JSON) .header("Authorization", "bearer " + adminToken)) .andExpect(status().isServiceUnavailable()) .andExpect(jsonPath("error").value(LimitedModeUaaFilter.ERROR_CODE)) .andExpect(jsonPath("error_description").value(LimitedModeUaaFilter.ERROR_MESSAGE)); mockMvc.perform( put("/oauth/clients/{id}", "some-invalid-id") .accept(MediaType.APPLICATION_JSON) .header("Authorization", "bearer " + adminToken)) .andExpect(status().isServiceUnavailable()) .andExpect(jsonPath("error").value(LimitedModeUaaFilter.ERROR_CODE)) .andExpect(jsonPath("error_description").value(LimitedModeUaaFilter.ERROR_MESSAGE)); }
@Test void identity_zone_can_not_write() throws Exception { mockMvc.perform( post("/identity-zones") .accept(MediaType.APPLICATION_JSON) .contentType(MediaType.APPLICATION_JSON) .content(JsonUtils.writeValueAsString("")) .header("Authorization", "bearer " + adminToken)) .andExpect(status().isServiceUnavailable()) .andExpect(jsonPath("error").value(LimitedModeUaaFilter.ERROR_CODE)) .andExpect(jsonPath("error_description").value(LimitedModeUaaFilter.ERROR_MESSAGE)); mockMvc.perform( put("/identity-zones/{id}", "some-invalid-id") .accept(MediaType.APPLICATION_JSON) .contentType(MediaType.APPLICATION_JSON) .content(JsonUtils.writeValueAsString("")) .header("Authorization", "bearer " + adminToken)) .andExpect(status().isServiceUnavailable()) .andExpect(jsonPath("error").value(LimitedModeUaaFilter.ERROR_CODE)) .andExpect(jsonPath("error_description").value(LimitedModeUaaFilter.ERROR_MESSAGE)); }
@Test public void whenSubscriptionCreationIsDisabledThenCreationFails() throws Exception { final SubscriptionBase subscriptionBase = builder().buildSubscriptionBase(); when(subscriptionService.getExistingSubscription(any())).thenThrow(new NoSuchSubscriptionException("", null)); when(featureToggleService.isFeatureEnabled(DISABLE_SUBSCRIPTION_CREATION)).thenReturn(true); postSubscription(subscriptionBase).andExpect(status().isServiceUnavailable()); }
@Test public void whenTimelineCreationFailsRemoveEventTypeFromRepositoryAnd500() throws Exception { final EventType et = buildDefaultEventType(); doThrow(TopicCreationException.class).when(timelineService) .createDefaultTimeline(any(), anyInt()); final Problem expectedProblem = Problem.valueOf(SERVICE_UNAVAILABLE); postEventType(et).andExpect(status().isServiceUnavailable()) .andExpect(content().contentType("application/problem+json")).andExpect(content().string( matchesProblem(expectedProblem))); verify(eventTypeRepository, times(1)).saveEventType(any(EventType.class)); verify(timelineService, times(1)).createDefaultTimeline(any(), anyInt()); verify(eventTypeRepository, times(1)).removeEventType(et.getName()); }
@Test public void whenEventPublishTimeoutThen503() throws Exception { when(publisher.publish(any(), any())).thenThrow(new EventTypeTimeoutException("")); postBatch(TOPIC, EVENT_BATCH) .andExpect(content().contentType("application/problem+json")) .andExpect(status().isServiceUnavailable()); }
@Test public void whenListPartitionsAndNakadiExceptionThenServiceUnavaiable() throws Exception { when(timelineService.getActiveTimelinesOrdered(eq(TEST_EVENT_TYPE))) .thenThrow(ServiceTemporarilyUnavailableException.class); final ThrowableProblem expectedProblem = Problem.valueOf(SERVICE_UNAVAILABLE, ""); mockMvc.perform( get(String.format("/event-types/%s/partitions", TEST_EVENT_TYPE))) .andExpect(status().isServiceUnavailable()) .andExpect(content().string(TestUtils.JSON_TEST_HELPER.matchesObject(expectedProblem))); }
@Test public void whenGetPartitionAndNakadiExceptionThenServiceUnavaiable() throws Exception { when(timelineService.getActiveTimelinesOrdered(eq(TEST_EVENT_TYPE))) .thenThrow(ServiceTemporarilyUnavailableException.class); final ThrowableProblem expectedProblem = Problem.valueOf(SERVICE_UNAVAILABLE, ""); mockMvc.perform( get(String.format("/event-types/%s/partitions/%s", TEST_EVENT_TYPE, TEST_PARTITION))) .andExpect(status().isServiceUnavailable()) .andExpect(content().string(TestUtils.JSON_TEST_HELPER.matchesObject(expectedProblem))); }
@Test public void whenUpdateEventTypeAndTimelineWaitTimeoutThen503() throws Exception { when(timelineSync.workWithEventType(any(), anyLong())).thenThrow(new TimeoutException()); final EventType eventType = buildDefaultEventType(); final Problem expectedProblem = Problem.valueOf(SERVICE_UNAVAILABLE, "Event type is currently in maintenance, please repeat request"); putEventType(eventType, eventType.getName(), "nakadi") .andExpect(status().isServiceUnavailable()) .andExpect(content().string(matchesProblem(expectedProblem))); }
@Test public void should_send_service_unavailable_if_application_is_restarting() throws Exception { //GIVEN that we have a map route in database (for started app) when(proxyMap.findOne(HOST_TEST_VALUE)).thenReturn(ProxyMapEntry.builder() .appId(APP_ID) .host(HOST_TEST_VALUE) .build()); when(cfApi.getApplicationState(APP_ID)).thenReturn(CloudFoundryAppState.STARTED); // is app running returns true when(cfApi.isAppRunning(APP_ID)).thenReturn(false); //WHEN an incoming message target this same route this.mockMvc .perform(get("http://localhost/anything") .header(HEADER_HOST, HOST_TEST_VALUE) .header(HEADER_PROTOCOL, PROTOCOL_TEST_VALUE)) //then status code is ok .andExpect(status().isServiceUnavailable()); verify(proxyMap, never()).deleteIfExists(HOST_TEST_VALUE); }
@Test public void whenDeleteEventTypeAndTimelineWaitTimeoutThen503() throws Exception { when(timelineSync.workWithEventType(any(), anyLong())).thenThrow(new TimeoutException()); final EventType eventType = buildDefaultEventType(); final Problem expectedProblem = Problem.valueOf(SERVICE_UNAVAILABLE, "Event type " + eventType.getName() + " is currently in maintenance, please repeat request"); deleteEventType(eventType.getName()) .andExpect(status().isServiceUnavailable()) .andExpect(content().string(matchesProblem(expectedProblem))); }