public void testFailQueryByTenantIdNull() { try { managementService.createJobDefinitionQuery() .tenantIdIn((String) null); fail("expected exception"); } catch (NullValueException e) { } }
public void testQueryByTenantIds() { JobDefinitionQuery query = managementService .createJobDefinitionQuery() .tenantIdIn(TENANT_ONE, TENANT_TWO); assertThat(query.count(), is(2L)); }
public void testQueryAuthenticatedTenant() { identityService.setAuthentication("user", null, Arrays.asList(TENANT_ONE)); JobDefinitionQuery query = managementService.createJobDefinitionQuery(); assertThat(query.count(), is(2L)); assertThat(query.tenantIdIn(TENANT_ONE).count(), is(1L)); assertThat(query.tenantIdIn(TENANT_TWO).count(), is(0L)); assertThat(query.tenantIdIn(TENANT_ONE, TENANT_TWO).includeJobDefinitionsWithoutTenantId().count(), is(2L)); }
public void testQueryByTenantId() { JobDefinitionQuery query = managementService .createJobDefinitionQuery() .tenantIdIn(TENANT_ONE); assertThat(query.count(), is(1L)); query = managementService .createJobDefinitionQuery() .tenantIdIn(TENANT_TWO); assertThat(query.count(), is(1L)); }
public void testQueryByNonExistingTenantId() { JobDefinitionQuery query = managementService .createJobDefinitionQuery() .tenantIdIn("nonExisting"); assertThat(query.count(), is(0L)); }
public void testQuerySortingDesc() { // exclude job definitions without tenant id because of database-specific ordering List<JobDefinition> jobDefinitions = managementService.createJobDefinitionQuery() .tenantIdIn(TENANT_ONE, TENANT_TWO) .orderByTenantId() .desc() .list(); assertThat(jobDefinitions.size(), is(2)); assertThat(jobDefinitions.get(0).getTenantId(), is(TENANT_TWO)); assertThat(jobDefinitions.get(1).getTenantId(), is(TENANT_ONE)); }
public void testQueryAuthenticatedTenants() { identityService.setAuthentication("user", null, Arrays.asList(TENANT_ONE, TENANT_TWO)); JobDefinitionQuery query = managementService.createJobDefinitionQuery(); assertThat(query.count(), is(3L)); assertThat(query.tenantIdIn(TENANT_ONE).count(), is(1L)); assertThat(query.tenantIdIn(TENANT_TWO).count(), is(1L)); assertThat(query.withoutTenantId().count(), is(1L)); }
public void testQuerySortingAsc() { // exclude job definitions without tenant id because of database-specific ordering List<JobDefinition> jobDefinitions = managementService.createJobDefinitionQuery() .tenantIdIn(TENANT_ONE, TENANT_TWO) .orderByTenantId() .asc() .list(); assertThat(jobDefinitions.size(), is(2)); assertThat(jobDefinitions.get(0).getTenantId(), is(TENANT_ONE)); assertThat(jobDefinitions.get(1).getTenantId(), is(TENANT_TWO)); }
public void testQueryByTenantIdsIncludeDefinitionsWithoutTenantId() { JobDefinitionQuery query = managementService .createJobDefinitionQuery() .tenantIdIn(TENANT_ONE) .includeJobDefinitionsWithoutTenantId(); assertThat(query.count(), is(2L)); query = managementService .createJobDefinitionQuery() .tenantIdIn(TENANT_TWO) .includeJobDefinitionsWithoutTenantId(); assertThat(query.count(), is(2L)); query = managementService .createJobDefinitionQuery() .tenantIdIn(TENANT_ONE, TENANT_TWO) .includeJobDefinitionsWithoutTenantId(); assertThat(query.count(), is(3L)); }
@Test public void suspendJobDefinitionWithAuthenticatedTenant() { // given activated job definitions JobDefinitionQuery query = engineRule.getManagementService().createJobDefinitionQuery(); assertThat(query.active().count(), is(3L)); assertThat(query.suspended().count(), is(0L)); engineRule.getIdentityService().setAuthentication("user", null, Arrays.asList(TENANT_ONE)); engineRule.getManagementService() .updateJobDefinitionSuspensionState() .byProcessDefinitionKey(PROCESS_DEFINITION_KEY) .suspend(); engineRule.getIdentityService().clearAuthentication(); assertThat(query.active().count(), is(1L)); assertThat(query.suspended().count(), is(2L)); assertThat(query.active().tenantIdIn(TENANT_TWO).count(), is(1L)); assertThat(query.suspended().withoutTenantId().count(), is(1L)); assertThat(query.suspended().tenantIdIn(TENANT_ONE).count(), is(1L)); }
@Test public void suspendJobDefinitionForTenant() { // given activated job definitions JobDefinitionQuery query = engineRule.getManagementService().createJobDefinitionQuery(); assertThat(query.active().count(), is(3L)); assertThat(query.suspended().count(), is(0L)); engineRule.getManagementService() .updateJobDefinitionSuspensionState() .byProcessDefinitionKey(PROCESS_DEFINITION_KEY) .processDefinitionTenantId(TENANT_ONE) .suspend(); assertThat(query.active().count(), is(2L)); assertThat(query.suspended().count(), is(1L)); assertThat(query.suspended().tenantIdIn(TENANT_ONE).count(), is(1L)); }
@Test public void suspendProcessDefinitionIncludingJobDefinitionsForTenant() { // given activated jobs JobDefinitionQuery query = engineRule.getManagementService().createJobDefinitionQuery(); assertThat(query.active().count(), is(3L)); assertThat(query.suspended().count(), is(0L)); engineRule.getRepositoryService() .updateProcessDefinitionSuspensionState() .byProcessDefinitionKey(PROCESS_DEFINITION_KEY) .processDefinitionTenantId(TENANT_ONE) .suspend(); assertThat(query.active().count(), is(2L)); assertThat(query.suspended().count(), is(1L)); assertThat(query.suspended().tenantIdIn(TENANT_ONE).count(), is(1L)); }
@Test public void testTenantIdListPostParameter() { mockQuery = setUpMockJobDefinitionQuery(createMockJobDefinitionsTwoTenants()); Map<String, Object> queryParameters = new HashMap<String, Object>(); queryParameters.put("tenantIdIn", MockProvider.EXAMPLE_TENANT_ID_LIST.split(",")); Response response = given() .contentType(POST_JSON_CONTENT_TYPE) .body(queryParameters) .expect() .statusCode(Status.OK.getStatusCode()) .when() .post(JOB_DEFINITION_RESOURCE_URL); verify(mockQuery).tenantIdIn(MockProvider.EXAMPLE_TENANT_ID, MockProvider.ANOTHER_EXAMPLE_TENANT_ID); verify(mockQuery).list(); String content = response.asString(); List<String> jobDefinitions = from(content).getList(""); assertThat(jobDefinitions).hasSize(2); String returnedTenantId1 = from(content).getString("[0].tenantId"); String returnedTenantId2 = from(content).getString("[1].tenantId"); assertThat(returnedTenantId1).isEqualTo(MockProvider.EXAMPLE_TENANT_ID); assertThat(returnedTenantId2).isEqualTo(MockProvider.ANOTHER_EXAMPLE_TENANT_ID); }
@Test public void suspendJobDefinitionDisabledTenantCheck() { // given activated job definitions JobDefinitionQuery query = engineRule.getManagementService().createJobDefinitionQuery(); assertThat(query.active().count(), is(3L)); assertThat(query.suspended().count(), is(0L)); engineRule.getProcessEngineConfiguration().setTenantCheckEnabled(false); engineRule.getIdentityService().setAuthentication("user", null, null); engineRule.getManagementService() .updateJobDefinitionSuspensionState() .byProcessDefinitionKey(PROCESS_DEFINITION_KEY) .suspend(); assertThat(query.active().count(), is(0L)); assertThat(query.suspended().count(), is(3L)); assertThat(query.suspended().tenantIdIn(TENANT_ONE, TENANT_TWO).includeJobDefinitionsWithoutTenantId().count(), is(3L)); }
@Test public void activateProcessDefinitionIncludingJobDefinitionsForTenant() { // given suspended jobs engineRule.getRepositoryService() .updateProcessDefinitionSuspensionState() .byProcessDefinitionKey(PROCESS_DEFINITION_KEY) .suspend(); JobDefinitionQuery query = engineRule.getManagementService().createJobDefinitionQuery(); assertThat(query.active().count(), is(0L)); assertThat(query.suspended().count(), is(3L)); engineRule.getRepositoryService() .updateProcessDefinitionSuspensionState() .byProcessDefinitionKey(PROCESS_DEFINITION_KEY) .processDefinitionTenantId(TENANT_ONE) .activate(); assertThat(query.suspended().count(), is(2L)); assertThat(query.active().count(), is(1L)); assertThat(query.active().tenantIdIn(TENANT_ONE).count(), is(1L)); }
@Test public void delayedSuspendJobDefinitionsForTenant() { // given activated job definitions engineRule.getManagementService() .updateJobDefinitionSuspensionState() .byProcessDefinitionKey(PROCESS_DEFINITION_KEY) .processDefinitionTenantId(TENANT_ONE) .executionDate(tomorrow()) .suspend(); JobDefinitionQuery query = engineRule.getManagementService().createJobDefinitionQuery(); assertThat(query.active().count(), is(3L)); assertThat(query.suspended().count(), is(0L)); // when execute the job to suspend the job definitions Job job = engineRule.getManagementService().createJobQuery().timers().singleResult(); assertThat(job, is(notNullValue())); engineRule.getManagementService().executeJob(job.getId()); assertThat(query.active().count(), is(2L)); assertThat(query.suspended().count(), is(1L)); assertThat(query.suspended().tenantIdIn(TENANT_ONE).count(), is(1L)); }
@Test public void activateJobDefinitionForTenant() { // given suspend job definitions engineRule.getManagementService() .updateJobDefinitionSuspensionState() .byProcessDefinitionKey(PROCESS_DEFINITION_KEY) .suspend(); JobDefinitionQuery query = engineRule.getManagementService().createJobDefinitionQuery(); assertThat(query.suspended().count(), is(3L)); assertThat(query.active().count(), is(0L)); engineRule.getManagementService() .updateJobDefinitionSuspensionState() .byProcessDefinitionKey(PROCESS_DEFINITION_KEY) .processDefinitionTenantId(TENANT_ONE) .activate(); assertThat(query.suspended().count(), is(2L)); assertThat(query.active().count(), is(1L)); assertThat(query.active().tenantIdIn(TENANT_ONE).count(), is(1L)); }
@Test public void testIncludeJobDefinitionsWithoutTenantIdParameter() { List<JobDefinition> jobDefinitions = Arrays.asList( MockProvider.mockJobDefinition().tenantId(null).build(), MockProvider.mockJobDefinition().tenantId(MockProvider.EXAMPLE_TENANT_ID).build()); mockedQuery = setUpMockDefinitionQuery(jobDefinitions); Response response = given() .queryParam("tenantIdIn", MockProvider.EXAMPLE_TENANT_ID) .queryParam("includeJobDefinitionsWithoutTenantId", true) .then().expect() .statusCode(Status.OK.getStatusCode()) .when() .get(JOB_DEFINITION_QUERY_URL); verify(mockedQuery).tenantIdIn(MockProvider.EXAMPLE_TENANT_ID); verify(mockedQuery).includeJobDefinitionsWithoutTenantId(); verify(mockedQuery).list(); String content = response.asString(); List<String> definitions = from(content).getList(""); assertThat(definitions).hasSize(2); String returnedTenantId1 = from(content).getString("[0].tenantId"); String returnedTenantId2 = from(content).getString("[1].tenantId"); assertThat(returnedTenantId1).isEqualTo(null); assertThat(returnedTenantId2).isEqualTo(MockProvider.EXAMPLE_TENANT_ID); }
@Test public void testTenantIdListParameter() { mockQuery = setUpMockJobDefinitionQuery(createMockJobDefinitionsTwoTenants()); Response response = given() .queryParam("tenantIdIn", MockProvider.EXAMPLE_TENANT_ID_LIST) .then().expect() .statusCode(Status.OK.getStatusCode()) .when() .get(JOB_DEFINITION_RESOURCE_URL); verify(mockQuery).tenantIdIn(MockProvider.EXAMPLE_TENANT_ID, MockProvider.ANOTHER_EXAMPLE_TENANT_ID); verify(mockQuery).list(); String content = response.asString(); List<String> jobDefinitions = from(content).getList(""); assertThat(jobDefinitions).hasSize(2); String returnedTenantId1 = from(content).getString("[0].tenantId"); String returnedTenantId2 = from(content).getString("[1].tenantId"); assertThat(returnedTenantId1).isEqualTo(MockProvider.EXAMPLE_TENANT_ID); assertThat(returnedTenantId2).isEqualTo(MockProvider.ANOTHER_EXAMPLE_TENANT_ID); }
@Test public void testTenantIdListParameter() { mockedQuery = setUpMockDefinitionQuery(createMockJobDefinitionsTwoTenants()); Response response = given() .queryParam("tenantIdIn", MockProvider.EXAMPLE_TENANT_ID_LIST) .then().expect() .statusCode(Status.OK.getStatusCode()) .when() .get(JOB_DEFINITION_QUERY_URL); verify(mockedQuery).tenantIdIn(MockProvider.EXAMPLE_TENANT_ID, MockProvider.ANOTHER_EXAMPLE_TENANT_ID); verify(mockedQuery).list(); String content = response.asString(); List<String> jobs = from(content).getList(""); assertThat(jobs).hasSize(2); String returnedTenantId1 = from(content).getString("[0].tenantId"); String returnedTenantId2 = from(content).getString("[1].tenantId"); assertThat(returnedTenantId1).isEqualTo(MockProvider.EXAMPLE_TENANT_ID); assertThat(returnedTenantId2).isEqualTo(MockProvider.ANOTHER_EXAMPLE_TENANT_ID); }