@Test public void customerByIdShouldReturnACustomer() { WireMock.stubFor(WireMock.get(WireMock.urlMatching("/customers/1")) .willReturn( WireMock.aResponse() .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE) .withStatus(HttpStatus.OK.value()) .withBody(asJson(customerById)) )); Customer customer = client.getCustomerById(1L); BDDAssertions.then(customer.getFirstName()).isEqualToIgnoringCase("first"); BDDAssertions.then(customer.getLastName()).isEqualToIgnoringCase("last"); BDDAssertions.then(customer.getEmail()).isEqualToIgnoringCase("email"); BDDAssertions.then(customer.getId()).isEqualTo(1L); }
@Test @SuppressWarnings("unchecked") public void should_create_a_valid_span_from_custom_headers() { final Span newSpan = this.tracer.createSpan("new_span"); ResponseEntity<Map> responseEntity = null; try { RequestEntity<?> requestEntity = RequestEntity .get(URI.create("http://localhost:" + this.config.port + "/headers")) .build(); responseEntity = this.restTemplate.exchange(requestEntity, Map.class); } finally { this.tracer.close(newSpan); } await().atMost(5, SECONDS).untilAsserted(() -> { then(this.accumulator.getSpans().stream().filter( span -> span.getSpanId() == newSpan.getSpanId()).findFirst().get()) .hasTraceIdEqualTo(newSpan.getTraceId()); }); BDDAssertions.then(responseEntity.getBody()) .containsEntry("correlationid", Span.idToHex(newSpan.getTraceId())) .containsKey("myspanid") .as("input request headers"); }
@Test public void should_close_span_upon_failure_callback() throws ExecutionException, InterruptedException { ListenableFuture<ResponseEntity<String>> future; try { future = this.asyncRestTemplate .getForEntity("http://localhost:" + port() + "/blowsup", String.class); future.get(); BDDAssertions.fail("should throw an exception from the controller"); } catch (Exception e) { } Awaitility.await().untilAsserted(() -> { then(new ArrayList<>(this.accumulator.getSpans()).stream() .filter(span -> span.logs().stream().filter(log -> Span.CLIENT_RECV.equals(log.getEvent())) .findFirst().isPresent()).findFirst().get()).matches( span -> span.getAccumulatedMicros() >= TimeUnit.MILLISECONDS.toMicros(100)) .hasATagWithKey(Span.SPAN_ERROR_TAG_NAME); then(this.tracer.getCurrentSpan()).isNull(); then(ExceptionUtils.getLastException()).isNull(); }); }
public void test() { final SQSProjectSettings holder = new SQSProjectSettings(); BDDAssertions.then(holder.getInfo("serverId")).isNull(); holder.setInfo("serverId", XMLBasedSQSInfoHelper.createServerInfo("serverId")); BDDAssertions.then(holder.getInfo("serverId")).isNotNull(); BDDAssertions.then(holder.getInfo("serverId2")).isNull(); holder.setInfo("serverId2", XMLBasedSQSInfoHelper.createServerInfo("serverId2")); BDDAssertions.then(holder.getInfo("serverId")).isNotNull(); BDDAssertions.then(holder.getInfo("serverId2")).isNotNull(); holder.remove("serverId"); holder.remove("serverId2"); BDDAssertions.then(holder.getInfo("serverId")).isNull(); BDDAssertions.then(holder.getInfo("serverId2")).isNull(); }
public void should_remove_from_both() throws IOException { final SQSManagerImpl sqsManager = mock(SQSManagerImpl.class); final SQSManagerProjectFeatures sqsManagerProjectFeatures = mock(SQSManagerProjectFeatures.class); final MigratingSQSManager migratingSQSManager = new MigratingSQSManager(sqsManager, sqsManagerProjectFeatures, mock(ConfigActionFactory.class)); final BaseSQSInfo any = new BaseSQSInfo("any"); when(sqsManagerProjectFeatures.removeServer(any(), any())).thenReturn(new SQSManager.SQSActionResult(any, null, "")); when(sqsManager.removeServer(any(), any())).thenReturn(new SQSManager.SQSActionResult(any, null, "")); final SQSManager.SQSActionResult result = migratingSQSManager.removeServer(myProject, "any"); verify(sqsManagerProjectFeatures, times(1)).removeServer(myProject, "any"); verify(sqsManager, times(1)).removeServer(myProject, "any"); BDDAssertions.then(result.getBeforeAction()).isNotNull(); BDDAssertions.then(result.isError()).isFalse(); reset(sqsManagerProjectFeatures, sqsManager); when(sqsManagerProjectFeatures.removeServer(any(), any())).thenReturn(new SQSManager.SQSActionResult(null, null, "", true)); when(sqsManager.removeServer(any(), any())).thenReturn(new SQSManager.SQSActionResult(null, null, "", true)); final SQSManager.SQSActionResult result2 = migratingSQSManager.removeServer(myProject, "any"); verify(sqsManagerProjectFeatures, times(1)).removeServer(myProject, "any"); verify(sqsManager, times(1)).removeServer(myProject, "any"); BDDAssertions.then(result2.getBeforeAction()).isNull(); BDDAssertions.then(result2.isError()).isTrue(); }
@Test public void should_first_fail_then_succeed_to_process_tax_factor_for_person() throws ConnectException { // given willThrow(new ConnectException()).willNothing().given(taxFactorService).updateMeanTaxFactor(any(Person.class), anyDouble()); // when when(systemUnderTest).processTaxDataFor(new Person()); // then then(caughtException()).hasCauseInstanceOf(ConnectException.class); // when boolean success = systemUnderTest.processTaxDataFor(new Person()); // then BDDAssertions.then(success).isTrue(); }
@Test public void customerByIdShouldReturnACustomer() { Customer customer = client.getCustomerById(1L); BDDAssertions.then(customer.getFirstName()).isEqualToIgnoringCase("first"); BDDAssertions.then(customer.getLastName()).isEqualToIgnoringCase("last"); BDDAssertions.then(customer.getEmail()).isEqualToIgnoringCase("email"); BDDAssertions.then(customer.getId()).isEqualTo(1L); }
@Test public void customerByIdShouldReturnACustomer() { this.mockRestServiceServer .expect(ExpectedCount.manyTimes(), requestTo("http://localhost:8080/customers/1")) .andExpect(method(HttpMethod.GET)) .andRespond(withSuccess(this.customerById, MediaType.APPLICATION_JSON_UTF8)); Customer customer = client.getCustomerById(1L); BDDAssertions.then(customer.getFirstName()).isEqualToIgnoringCase("first"); BDDAssertions.then(customer.getLastName()).isEqualToIgnoringCase("last"); BDDAssertions.then(customer.getEmail()).isEqualToIgnoringCase("email"); BDDAssertions.then(customer.getId()).isEqualTo(1L); this.mockRestServiceServer.verify(); }
@Test public void should_return_charge_collection() { Charges charges = manager.listAllCharges("foo"); BDDAssertions.then(charges.getCharges()) .hasSize(25); }
@Test public void should_return_charge_collection() { String object = new RestTemplate() .getForObject("http://localhost:7654/", String.class); BDDAssertions.then(object).contains("dsyer"); }
@Test public void should_return_charge_collection() { Charges charges = manager.listAllCharges("foo"); BDDAssertions.then(charges.getCharges()) .extracting("customer") .containsExactly("a", "b", "c"); }
@Test public void should_not_update_pom_when_project_is_not_on_the_versions_list() throws Exception { File springCloudReleasePom = file("/projects/spring-cloud-release"); BDDAssertions .then(this.pomUpdater.shouldProjectBeUpdated(springCloudReleasePom, this.versions)).isFalse(); }
@Test public void should_update_pom_when_project_is_not_on_the_versions_list() throws Exception { File springCloudSleuthPom = file("/projects/spring-cloud-sleuth"); BDDAssertions .then(this.pomUpdater.shouldProjectBeUpdated(springCloudSleuthPom, this.versions)).isTrue(); }
@Test public void should_not_update_child_pom_when_project_is_not_on_the_versions_list() throws Exception { File springCloudReleasePom = file("/projects/spring-cloud-release"); BDDAssertions .then(this.pomUpdater.shouldProjectBeUpdated(springCloudReleasePom, this.versions)).isFalse(); }
@Test public void should_update_child_pom_when_project_is_not_on_the_versions_list() throws Exception { File springCloudSleuthPom = file("/projects/spring-cloud-sleuth"); BDDAssertions .then(this.pomUpdater.shouldProjectBeUpdated(springCloudSleuthPom, this.versions)).isTrue(); }
@Test public void should_override_a_pom_when_there_was_a_change_in_the_model() throws Exception { File beforeProcessing = pom("/projects/project/children", "pom_matching_properties.xml"); File afterProcessing = tmpFile("/project/children/pom_matching_properties.xml"); ModelWrapper model = this.pomUpdater.updateModel(model("spring-cloud-sleuth"), afterProcessing, this.versions); File processedPom = this.pomUpdater.overwritePomIfDirty(model, Versions.EMPTY_VERSION, afterProcessing); String processedPomText = asString(processedPom); String beforeProcessingText = asString(beforeProcessing); BDDAssertions.then(processedPomText).isNotEqualTo(beforeProcessingText); }
@Test public void should_not_override_a_pom_when_there_was_no_change_in_the_model() throws Exception { File beforeProcessing = pom("/projects/project/"); File afterProcessing = tmpFile("/project/pom.xml"); ModelWrapper model = this.pomUpdater.updateModel(model("foo"), afterProcessing, this.versions); File processedPom = this.pomUpdater.overwritePomIfDirty(model, Versions.EMPTY_VERSION, afterProcessing); BDDAssertions.then(asString(processedPom)).isEqualTo(asString(beforeProcessing)); }
@Test public void should_not_revert_changes_when_commit_message_is_not_related_to_updating_snapshots() throws Exception { File project = this.gitRepo.cloneProject(this.springCloudReleaseProject.toURI()); BDDAssertions.thenThrownBy( () -> this.gitRepo.revert(project, "some message")) .hasMessageContaining("Won't revert the commit with id"); }
@Test public void should_update_fail_when_after_updating_a_release_version_there_still_is_a_snapshot_version() throws Exception { ReleaserProperties releaserProperties = branchReleaserProperties(); ProjectPomUpdater projectPomUpdater = new ProjectPomUpdater(releaserProperties); Projects projects = projectPomUpdater.retrieveVersionsFromSCRelease(); File project = new File(this.temporaryFolder, "/spring-cloud-sleuth-with-unmatched-property"); BDDAssertions.thenThrownBy(() -> projectPomUpdater .updateProjectFromSCRelease(project, projects, projects.forFile(project), true) ).hasMessageContaining("<spring-cloud-unmatched.version>0.6.0.BUILD-SNAPSHOT</spring-cloud-unmatched.version>"); }
@Test public void should_update_fail_when_after_updating_a_release_version_there_still_is_a_snapshot_version_for_boot_snapshot_version() throws Exception { ReleaserProperties releaserProperties = branchReleaserProperties(); ProjectPomUpdater projectPomUpdater = new ProjectPomUpdater(releaserProperties); Projects projects = projectPomUpdater.retrieveVersionsFromSCRelease(); projects.removeIf(projectVersion -> projectVersion.projectName.contains("spring-cloud-build")); projects.add(new ProjectVersion("spring-cloud-build", "1.4.2.BUILD-SNAPSHOT")); File project = new File(this.temporaryFolder, "/spring-cloud-sleuth"); BDDAssertions.thenThrownBy(() -> projectPomUpdater .updateProjectFromSCRelease(project, projects, projects.forFile(project), true) ).hasMessageContaining("<version>1.4.2.BUILD-SNAPSHOT</version>"); }
@Test public void should_not_bump_versions_for_original_release_project() throws Exception { releaser(() -> new ProjectVersion("original", "1.0.0.RELEASE")) .rollbackReleaseVersion(this.pom, new Projects(new ProjectVersion("changed", "1.0.0.RELEASE")), new ProjectVersion("changed", "1.0.0.RELEASE")); BDDAssertions.then(this.outputCapture.toString()).contains("Successfully reverted the commit and came back to snapshot versions"); then(this.projectGitHandler).should(never()).commitAfterBumpingVersions(any(File.class), any(ProjectVersion.class)); }
@Test public void should_not_bump_versions_for_original_snapshot_project_and_current_snapshot() throws Exception { releaser(() -> new ProjectVersion("original", "1.0.0.BUILD-SNAPSHOT")) .rollbackReleaseVersion(this.pom, new Projects(new ProjectVersion("changed", "1.0.0.BUILD-SNAPSHOT")), new ProjectVersion("changed", "1.0.0.BUILD-SNAPSHOT")); BDDAssertions.then(this.outputCapture.toString()).contains("Won't rollback a snapshot version"); then(this.projectGitHandler).should(never()).commitAfterBumpingVersions(any(File.class), any(ProjectVersion.class)); }
@Test public void should_bump_versions_for_original_snapshot_project() throws Exception { ProjectVersion scReleaseVersion = new ProjectVersion("changed", "1.0.0.RELEASE"); releaser(() -> new ProjectVersion("original", "1.0.0.BUILD-SNAPSHOT")) .rollbackReleaseVersion(this.pom, new Projects(new ProjectVersion("changed", "1.0.0.RELEASE")), scReleaseVersion); BDDAssertions.then(this.outputCapture.toString()) .contains("Project was successfully updated") .contains("Successfully reverted the commit and bumped snapshot versions"); }
@Test public void should_fail_to_perform_a_release_of_consul_when_sc_release_contains_snapshots() throws Exception { File origin = GitTestUtils.clonedProject(this.tmp.newFolder(), this.springCloudConsulProject); pomVersionIsEqualTo(origin, "1.2.0.BUILD-SNAPSHOT"); pomParentVersionIsEqualTo(origin, "1.2.0.BUILD-SNAPSHOT"); File project = GitTestUtils.clonedProject(this.tmp.newFolder(), tmpFile("spring-cloud-consul")); GitTestUtils.setOriginOnProjectToTmp(origin, project); SpringReleaser releaser = releaserWithSnapshotScRelease(project, "vCamden.SR5.BROKEN", "1.1.2.RELEASE"); BDDAssertions.thenThrownBy(releaser::release) .hasMessageContaining("there is at least one SNAPSHOT library version in the Spring Cloud Release project"); }
@Before public void setupPort() { // either one or the other option //tag::portfinder[] int portFromStubFinder = stubFinder.findStubUrl("beer-api-producer-advanced").getPort(); //end::portfinder[] int port2 = producerPort; BDDAssertions.then(portFromStubFinder).isEqualTo(port2); controller.port = portFromStubFinder; }
@Test public void executableSpanCreation() throws Exception { this.executorChannel.send(MessageBuilder.withPayload("hi") .setHeader(TraceMessageHeaders.SAMPLED_NAME, Span.SPAN_NOT_SAMPLED).build()); Awaitility.await() .untilAsserted(() -> BDDAssertions.assertThat(this.message).isNotNull()); String spanId = this.message.getHeaders().get(TraceMessageHeaders.SPAN_ID_NAME, String.class); then(spanId).isNotNull(); then(TestSpanContextHolder.getCurrentSpan()).isNull(); then(this.span.isExportable()).isFalse(); }
@Test public void should_rename_a_span() { Span span = Span.builder().name("foo").build(); InternalApi.renameSpan(span, "bar"); BDDAssertions.then(span.getName()).isEqualTo("bar"); }
private Callable<Boolean> applicationHasStartedOnANewPort( final ConfigurableApplicationContext clientContext, final Integer serverPortBeforeDying) { return new Callable<Boolean>() { @Override public Boolean call() throws Exception { try { BDDAssertions.then(callServiceAtPortEndpoint(clientContext)).isNotEqualTo(serverPortBeforeDying); } catch (Exception e) { log.error("Exception occurred while trying to call the server", e); return false; } return true; } }; }
@Test public void customersShouldReturnAllCustomers() { Collection<Customer> customers = client.getCustomers(); BDDAssertions.then(customers.size()).isEqualTo(2); }