@Test public void testVariableModificationForNonExistingProcessInstance() { doThrow(new ProcessEngineException("expected exception")).when(runtimeServiceMock).updateVariables(anyString(), anyMapOf(String.class, Object.class), anyCollectionOf(String.class)); String variableKey = "aKey"; int variableValue = 123; Map<String, Object> messageBodyJson = new HashMap<String, Object>(); Map<String, Object> modifications = VariablesBuilder.create().variable(variableKey, variableValue).getVariables(); messageBodyJson.put("modifications", modifications); given().pathParam("id", MockProvider.EXAMPLE_PROCESS_INSTANCE_ID).contentType(ContentType.JSON).body(messageBodyJson) .then().expect().statusCode(Status.INTERNAL_SERVER_ERROR.getStatusCode()).contentType(ContentType.JSON) .body("type", equalTo(RestException.class.getSimpleName())) .body("message", equalTo("Cannot modify variables for process instance " + MockProvider.EXAMPLE_PROCESS_INSTANCE_ID + ": expected exception")) .when().post(PROCESS_INSTANCE_VARIABLES_URL); }
@Test public void testVariableModificationThrowsAuthorizationException() { String variableKey = "aKey"; int variableValue = 123; Map<String, Object> messageBodyJson = new HashMap<String, Object>(); Map<String, Object> modifications = VariablesBuilder.create().variable(variableKey, variableValue).getVariables(); messageBodyJson.put("modifications", modifications); String message = "excpected exception"; doThrow(new AuthorizationException(message)).when(runtimeServiceMock).updateVariables(anyString(), anyMapOf(String.class, Object.class), anyCollectionOf(String.class)); given() .pathParam("id", MockProvider.EXAMPLE_PROCESS_INSTANCE_ID) .contentType(ContentType.JSON) .body(messageBodyJson) .then().expect() .statusCode(Status.FORBIDDEN.getStatusCode()) .body("type", is(AuthorizationException.class.getSimpleName())) .body("message", is(message)) .when() .post(PROCESS_INSTANCE_VARIABLES_URL); }
when(subject.isPermitted(any(Permission.class))).thenReturn(Boolean.TRUE); when(subject.isPermitted(any(String.class))).thenReturn(Boolean.TRUE); when(subject.isPermittedAll(anyCollectionOf(Permission.class))).thenReturn( Boolean.TRUE); when(subject.isPermittedAll()).thenReturn(Boolean.TRUE);
@Test public void testOnRefreshProviderTypesWithNOEnabledProviderTypes() { providerTypes.clear(); when(providerTypeService.getEnabledProviderTypes()).thenReturn(providerTypes); presenter.onRefreshProviderTypes(new ProviderTypeListRefreshEvent()); verify(view, times(1)).setEmptyView(providerTypeEmptyPresenterView); verify(providerTypeNavigationPresenter, times(1)).clear(); verify(providerTypeNavigationPresenter, times(0)).setup(any(ProviderType.class), anyCollectionOf(ProviderType.class)); }
@Test public void testOnRefreshProviderTypesWithNOEnabledProviderTypes() { providerTypes.clear(); when(providerTypeService.getEnabledProviderTypes()).thenReturn(providerTypes); presenter.onRefreshProviderTypes(new ProviderTypeListRefreshEvent()); verify(view, times(1)).setEmptyView(providerTypeEmptyPresenterView); verify(providerTypeNavigationPresenter, times(1)).clear(); verify(providerTypeNavigationPresenter, times(0)).setup(any(ProviderType.class), anyCollectionOf(ProviderType.class)); }
@Test public void checkingWillNotDiveIntoUnknownKeywords() throws ProcessingException { final ObjectNode node = FACTORY.objectNode(); node.put(K1, K1); final ObjectNode schema = FACTORY.objectNode(); schema.put("foo", node); final SchemaTree tree = new CanonicalSchemaTree(SchemaKey.anonymousKey(), schema); final ValueHolder<SchemaTree> holder = ValueHolder.hold("schema", tree); processor.process(report, holder); verify(checker, never()).checkSyntax(anyCollectionOf(JsonPointer.class), any(MessageBundle.class), anyReport(), anySchema()); }
@Test public void testOnProviderTypeSelectedWithNOProviders() { //pick an arbitrary element as the selected ProviderType selectedProviderType = providerTypes.iterator().next(); ProviderTypeKey selectedProviderTypeKey = selectedProviderType.getKey(); //the selected provider type don't have providers. List<ProviderKey> providerKeys = new ArrayList<>(); ProvidersInfo providersInfo = mock(ProvidersInfo.class); when(providersInfo.getProviderType()).thenReturn(selectedProviderType); when(providersInfo.getProvidersKey()).thenReturn(providerKeys); when(providerTypeService.getProviderType(selectedProviderTypeKey)).thenReturn(selectedProviderType); when(provisioningScreensService.getProvidersInfo(selectedProviderTypeKey)).thenReturn(providersInfo); presenter.onProviderTypeSelected(new ProviderTypeSelectedEvent(selectedProviderType.getKey())); verify(providerEmptyPresenter, times(1)).setProviderType(selectedProviderType); verify(view, times(1)).setContent(providerEmptyPresenterView); verify(providerTypePresenter, times(1)).setup(any(ProviderType.class), anyCollectionOf(ProviderKey.class), any(ProviderKey.class)); }
@Test public void testOnProviderTypeSelectedWithNOProviders() { //pick an arbitrary element as the selected ProviderType selectedProviderType = providerTypes.iterator().next(); ProviderTypeKey selectedProviderTypeKey = selectedProviderType.getKey(); //the selected provider type don't have providers. List<ProviderKey> providerKeys = new ArrayList<>(); ProvidersInfo providersInfo = mock(ProvidersInfo.class); when(providersInfo.getProviderType()).thenReturn(selectedProviderType); when(providersInfo.getProvidersKey()).thenReturn(providerKeys); when(providerTypeService.getProviderType(selectedProviderTypeKey)).thenReturn(selectedProviderType); when(provisioningScreensService.getProvidersInfo(selectedProviderTypeKey)).thenReturn(providersInfo); presenter.onProviderTypeSelected(new ProviderTypeSelectedEvent(selectedProviderType.getKey())); verify(providerEmptyPresenter, times(1)).setProviderType(selectedProviderType); verify(view, times(1)).setContent(providerEmptyPresenterView); verify(providerTypePresenter, times(1)).setup(any(ProviderType.class), anyCollectionOf(ProviderKey.class), any(ProviderKey.class)); }