@Test public void erase_existing_plugin_if_already_exists() throws Exception { logInAsSystemAdministrator(); File plugin1 = new File(getClass().getResource("UploadActionTest/plugin.jar").getFile()); call(newInputStream(plugin1.toPath()), PLUGIN_NAME); File plugin2 = new File(getClass().getResource("UploadActionTest/anotherPlugin.jar").getFile()); call(newInputStream(plugin2.toPath()), PLUGIN_NAME); File result = new File(pluginDirectory, PLUGIN_NAME); assertThat(result.exists()).isTrue(); assertThat(result.length()).isNotEqualTo(plugin1.length()).isEqualTo(plugin2.length()); }
@Test public void testSelectById() { dbTester.prepareDbUnit(getClass(), "selectForQualityGate.xml"); QualityGateConditionDto selectById = underTest.selectById(1L, dbSession); assertThat(selectById).isNotNull(); assertThat(selectById.getId()).isNotNull().isNotEqualTo(0L); assertThat(selectById.getMetricId()).isEqualTo(2L); assertThat(selectById.getOperator()).isEqualTo("<"); assertThat(selectById.getQualityGateId()).isEqualTo(1L); assertThat(selectById.getErrorThreshold()).isEqualTo("20"); assertThat(underTest.selectById(42L, dbSession)).isNull(); }
@Test public void verifyDeleteWhileOpening() { Context context = RuntimeEnvironment.application; String filePath = getClass().getResource("/databases/corrupted.db").getPath(); final long originalLength = new File(filePath).length(); assertThat(new File(filePath).exists()).isTrue(); JobStorage jobStorage = new JobStorage(context, filePath); SQLiteDatabase database = jobStorage.getDatabase(); assertThat(database).isNotNull(); assertThat(database.isOpen()).isTrue(); assertThat(originalLength).isNotEqualTo(new File(filePath).length()); File databaseFile = new File(database.getPath()); assertThat(databaseFile.exists()).isTrue(); assertThat(databaseFile.isFile()).isTrue(); } }
@Test public void getAndSetDelegate() { Timeout timeout1 = new Timeout(); Timeout timeout2 = new Timeout(); ForwardingTimeout forwardingTimeout = new ForwardingTimeout(timeout1); forwardingTimeout.timeout(5, TimeUnit.SECONDS); assertThat(timeout1.timeoutNanos()).isNotEqualTo(0L); assertThat(timeout2.timeoutNanos()).isEqualTo(0L); forwardingTimeout.clearTimeout(); assertThat(timeout1.timeoutNanos()).isEqualTo(0L); assertThat(timeout2.timeoutNanos()).isEqualTo(0L); assertThat(forwardingTimeout.delegate()).isEqualTo(timeout1); assertThat(forwardingTimeout.setDelegate(timeout2)).isEqualTo(forwardingTimeout); forwardingTimeout.timeout(5, TimeUnit.SECONDS); assertThat(timeout1.timeoutNanos()).isEqualTo(0L); assertThat(timeout2.timeoutNanos()).isNotEqualTo(0L); forwardingTimeout.clearTimeout(); assertThat(timeout1.timeoutNanos()).isEqualTo(0L); assertThat(timeout2.timeoutNanos()).isEqualTo(0L); assertThat(forwardingTimeout.delegate()).isEqualTo(timeout2); } }
private void verifyReset(CeQueueDto original) { CeQueueDto dto = db.getDbClient().ceQueueDao().selectByUuid(db.getSession(), original.getUuid()).get(); // We do not touch CreatedAt assertThat(dto.getCreatedAt()).isEqualTo(original.getCreatedAt()); // Status must have changed to PENDING and must not be equal to previous status assertThat(dto.getStatus()).isEqualTo(CeQueueDto.Status.PENDING).isNotEqualTo(original.getStatus()); // UpdatedAt must have been updated assertThat(dto.getUpdatedAt()).isNotEqualTo(original.getUpdatedAt()); assertThat(dto.getStartedAt()).isEqualTo(original.getStartedAt()); // WorkerUuid must be null assertThat(dto.getWorkerUuid()).isNull(); }
@Test public void prefetchMaxTranslatesToUnboundedRequest() { AtomicLong requested = new AtomicLong(); StepVerifier.create(Flux.just(1, 2, 3).hide() .doOnRequest(requested::set) .concatMap(i -> Flux.range(0, i), Integer.MAX_VALUE)) .expectNext(0, 0, 1, 0, 1, 2) .verifyComplete(); assertThat(requested.get()) .isNotEqualTo(Integer.MAX_VALUE) .isEqualTo(Long.MAX_VALUE); }
@Test public void prefetchMaxTranslatesToUnboundedRequest2() { AtomicLong requested = new AtomicLong(); StepVerifier.create(Flux.just(1, 2, 3).hide() .doOnRequest(requested::set) .concatMapDelayError(i -> Flux.range(0, i), Integer.MAX_VALUE)) .expectNext(0, 0, 1, 0, 1, 2) .verifyComplete(); assertThat(requested.get()) .isNotEqualTo(Integer.MAX_VALUE) .isEqualTo(Long.MAX_VALUE); }
@Test public void response_contains_quality_gate() { userSession.addPermission(ADMINISTER_QUALITY_GATES, defaultOrganizationProvider.get().getUuid()); QualityGateDto qualityGate = db.qualityGates().insertQualityGate(db.getDefaultOrganization()); QualityGate response = ws.newRequest() .setParam(PARAM_ID, qualityGate.getId().toString()) .setParam(PARAM_NAME, "new-name") .executeProtobuf(QualityGate.class); assertThat(response).isNotNull(); assertThat(response.getId()).isNotEqualTo(qualityGate.getId()); assertThat(response.getName()).isEqualTo("new-name"); }
@Test public void delete_custom_rule() { logInAsQProfileAdministrator(); RuleDefinitionDto templateRule = dbTester.rules().insert( r -> r.setIsTemplate(true), r -> r.setCreatedAt(PAST), r -> r.setUpdatedAt(PAST)); RuleDefinitionDto customRule = dbTester.rules().insert( r -> r.setTemplateId(templateRule.getId()), r -> r.setCreatedAt(PAST), r -> r.setUpdatedAt(PAST)); tester.newRequest() .setMethod("POST") .setParam("key", customRule.getKey().toString()) .execute(); verify(ruleIndexer).commitAndIndex(any(), eq(customRule.getId())); // Verify custom rule has status REMOVED RuleDefinitionDto customRuleReloaded = dbClient.ruleDao().selectOrFailDefinitionByKey(dbSession, customRule.getKey()); assertThat(customRuleReloaded).isNotNull(); assertThat(customRuleReloaded.getStatus()).isEqualTo(RuleStatus.REMOVED); assertThat(customRuleReloaded.getUpdatedAt()).isNotEqualTo(PAST); }
@Test public void creating_a_qg_with_a_name_used_in_another_organization_should_work() { OrganizationDto anOrganization = db.organizations().insert(); QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(anOrganization); OrganizationDto anotherOrganization = db.organizations().insert(); userSession.addPermission(ADMINISTER_QUALITY_GATES, anotherOrganization); CreateResponse response = ws.newRequest() .setParam(PARAM_NAME, qualityGate.getName()) .setParam(PARAM_ORGANIZATION, anotherOrganization.getKey()) .executeProtobuf(CreateResponse.class); assertThat(response.getName()).isEqualTo(qualityGate.getName()); assertThat(response.getId()).isNotEqualTo(qualityGate.getId()); }
@Test public void copy() { OrganizationDto organization = db.organizations().insert(); userSession.addPermission(ADMINISTER_QUALITY_GATES, organization); QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization); MetricDto metric = db.measures().insertMetric(); QualityGateConditionDto condition = db.qualityGates().addCondition(qualityGate, metric); ws.newRequest() .setParam(PARAM_ID, qualityGate.getId().toString()) .setParam(PARAM_NAME, "new-name") .setParam(PARAM_ORGANIZATION, organization.getKey()) .execute(); QGateWithOrgDto actual = db.getDbClient().qualityGateDao().selectByOrganizationAndName(dbSession, organization, "new-name"); assertThat(actual).isNotNull(); assertThat(actual.isBuiltIn()).isFalse(); assertThat(actual.getId()).isNotEqualTo(qualityGate.getId()); assertThat(actual.getUuid()).isNotEqualTo(qualityGate.getUuid()); assertThat(db.getDbClient().gateConditionDao().selectForQualityGate(dbSession, qualityGate.getId())) .extracting(c-> (int) c.getMetricId(), QualityGateConditionDto::getErrorThreshold) .containsExactlyInAnyOrder(tuple(metric.getId(), condition.getErrorThreshold())); }
.isNotEqualTo(layoutState2.getMountableOutputAt(1).getId());
@Test public void returnsTimestampAssociatedWithGreatestPunchedTimeEvenIfItIsNotGreatest() { puncherStore = initializePuncherStore(PUNCHER_HISTORY_WITH_CLOCK_DRIFT); assertThat(puncherStore.get(WALL_CLOCK_2)) .isEqualTo(TIMESTAMP_1) .isNotEqualTo(TIMESTAMP_2); // strictly speaking not needed but better for readability }
@Test public void returnsGreatestPunchedTimeBeforeTimestampEvenIfNotAssociatedWithGreatestEligibleTimestamp() { puncherStore = initializePuncherStore(PUNCHER_HISTORY_WITH_CLOCK_DRIFT); assertThat(puncherStore.getMillisForTimestamp(TIMESTAMP_2)) .isEqualTo(WALL_CLOCK_2) .isNotEqualTo(WALL_CLOCK_1); // strictly speaking not needed but better for readability }
@Test public void testEmbedSome() throws Exception { EmbeddedJsonHeadersMessageMapper mapper = new EmbeddedJsonHeadersMessageMapper(MessageHeaders.ID); GenericMessage<String> message = new GenericMessage<>("foo"); byte[] encodedMessage = mapper.fromMessage(message); Message<?> decoded = mapper.toMessage(encodedMessage); assertThat(decoded.getPayload()).isEqualTo(message.getPayload()); assertThat(decoded.getHeaders().getTimestamp()).isNotEqualTo(message.getHeaders().getTimestamp()); ObjectMapper objectMapper = new ObjectMapper(); Map<String, Object> encodedMessageToCheck = objectMapper.readValue(encodedMessage, new TypeReference<Map<String, Object>>() { }); Object headers = encodedMessageToCheck.get("headers"); assertThat(headers).isNotNull(); assertThat(headers).isInstanceOf(Map.class); @SuppressWarnings("unchecked") Map<String, Object> headersToCheck = (Map<String, Object>) headers; assertThat(headersToCheck).doesNotContainKey(MessageHeaders.TIMESTAMP); }
@Test public void shouldReturnNonZeroCoverageIdWhenTestsCoverClass() { final ClassName foo = ClassName.fromString("Foo"); final ClassInfo ci = ClassInfoMother.make(foo); when(this.code.getClassInfo(any(Collection.class))).thenReturn( Collections.singletonList(ci)); final BlockLocationBuilder block = aBlockLocation().withLocation( aLocation().withClass(foo)); final HashMap<BlockLocation, Set<Integer>> map = makeCoverageMapForBlock(block, 42); when(this.lm.mapLines(any(ClassName.class))).thenReturn(map); this.testee.calculateClassCoverage(aCoverageResult().withVisitedBlocks( block.build(1)).build()); assertThat(this.testee.getCoverageIdForClass(foo).longValue()) .isNotEqualTo(0); }
assertThat(stats).isNotNull(); assertThat(stats.getMeasurementsCount()).isEqualTo(1); assertThat(stats.getLatencyScore()).isNotEqualTo(-1); } finally { cluster.close();
assertThat(stats).isNotNull(); assertThat(stats.getMeasurementsCount()).isEqualTo(1); assertThat(stats.getLatencyScore()).isNotEqualTo(-1); } finally { cluster.close();
@Test public void itCancelsExtraQueuedBuildProperly() { BuildTrigger manualTrigger = BuildTrigger.forUser("test"); long newBuildId = repositoryBuildService.enqueue(branchOne, manualTrigger, buildOptionsOne); assertThat(newBuildId).isNotEqualTo(buildIdOne); RepositoryBuild repositoryBuild = repositoryBuildService.get(newBuildId).get(); repositoryBuildService.cancel(repositoryBuild); assertThat(repositoryBuildService.get(newBuildId).isPresent()).isFalse(); BuildNumbers buildNumbers = repositoryBuildService.getBuildNumbers(branchOne.getId().get()); assertThat(buildNumbers.getPendingBuildId().get()).isEqualTo(buildIdOne); assertThat(buildNumbers.getPendingBuildNumber().get()).isEqualTo(1); }
@Test public void testUpdateNonExistingSpot() { final long nonExistingSpotId = 123456L; Spot nonExistingSpot = new Spot(TENANT_ID, "Non-existing spot", Collections.emptySet()); nonExistingSpot.setId(nonExistingSpotId); Spot updatedSpot = spotRestService.updateSpot(TENANT_ID, nonExistingSpot); assertClientResponseOk(); assertThat(updatedSpot.getName()).isEqualTo(nonExistingSpot.getName()); assertThat(updatedSpot.getRequiredSkillSet()).isEqualTo(nonExistingSpot.getRequiredSkillSet()); assertThat(updatedSpot.getId()).isNotNull().isNotEqualTo(nonExistingSpot.getId()); }