@Test public void resolveHeadersBehindSymlinkTreesInPreprocessedOutput() throws IOException { BuckConfig buckConfig = new FakeBuckConfig(); CxxPlatform cxxPlatform = DefaultCxxPlatforms.build(new CxxBuckConfig(buckConfig)); ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "resolved", tmp); workspace.setUp(); workspace.writeContentsToPath("", "lib2.h"); BuildTarget target = BuildTargetFactory.newInstance("//:bin"); CxxSourceRuleFactory cxxSourceRuleFactory = CxxSourceRuleFactoryHelper.of(target, cxxPlatform); workspace.runBuckCommand("build", target.toString()).assertSuccess(); // Verify that the preprocessed source contains no references to the symlink tree used to // setup the headers. BuildTarget ppTarget = cxxSourceRuleFactory.createPreprocessBuildTarget( "bin.cpp", CxxSource.Type.CXX, CxxSourceRuleFactory.PicType.PDC); Path output = cxxSourceRuleFactory.getPreprocessOutputPath(ppTarget, CxxSource.Type.CXX, "bin.cpp"); String contents = workspace.getFileContents(output.toString()); assertThat(contents, Matchers.not(Matchers.containsString(BuckConstant.SCRATCH_DIR))); assertThat(contents, Matchers.not(Matchers.containsString(BuckConstant.GEN_DIR))); assertThat(contents, Matchers.containsString("# 1 \"bin.h")); assertThat(contents, Matchers.containsString("# 1 \"lib1.h")); assertThat(contents, Matchers.containsString("# 1 \"lib2.h")); }
@Test @RunAsClient public void testResourceOwnerPasswordFlowWithFormClientCredentials() throws Exception { RestAssured.enableLoggingOfRequestAndResponseIfValidationFails(); Response response = given() .redirects() .follow(false) .contentType("application/x-www-form-urlencoded") .formParam("grant_type", "password") .formParam("username", "jduke") .formParam("password", "1234") .formParam("client_id", "sample") .formParam("client_secret", "password") .when() .post(SampleRequest.TOKEN_ENDPOINT) .then() .statusCode(200) .body("access_token", Matchers.not(Matchers.isEmptyOrNullString())) .body("refresh_token", Matchers.not(Matchers.isEmptyOrNullString())) .body("expires_in", Matchers.not(Matchers.isEmptyOrNullString())) .body("token_type", Matchers.is("Bearer")) .header("Pragma", "no-cache") .header("Cache-Control", "no-store") .extract() .response(); System.out.println(response.asString()); String accessToken = response.jsonPath().getString("access_token"); SampleRequest.verify(accessToken); }
@Test public void testCompareTo() { GcsPath a = GcsPath.fromComponents("bucket", "a"); GcsPath b = GcsPath.fromComponents("bucket", "b"); GcsPath b2 = GcsPath.fromComponents("bucket2", "b"); GcsPath brel = GcsPath.fromComponents(null, "b"); GcsPath a2 = GcsPath.fromComponents("bucket", "a"); GcsPath arel = GcsPath.fromComponents(null, "a"); assertThat(a.compareTo(b), Matchers.lessThan(0)); assertThat(b.compareTo(a), Matchers.greaterThan(0)); assertThat(a.compareTo(a2), Matchers.equalTo(0)); assertThat(a.hashCode(), Matchers.equalTo(a2.hashCode())); assertThat(a.hashCode(), Matchers.not(Matchers.equalTo(b.hashCode()))); assertThat(b.hashCode(), Matchers.not(Matchers.equalTo(brel.hashCode()))); assertThat(brel.compareTo(b), Matchers.lessThan(0)); assertThat(b.compareTo(brel), Matchers.greaterThan(0)); assertThat(arel.compareTo(brel), Matchers.lessThan(0)); assertThat(brel.compareTo(arel), Matchers.greaterThan(0)); assertThat(b.compareTo(b2), Matchers.lessThan(0)); assertThat(b2.compareTo(b), Matchers.greaterThan(0)); }
/** * Issue https://github.com/l0rdn1kk0n/wicket-bootstrap/issues/307 Invisible input should not * render the surrounding markup */ @Test public void invisibleInput() { InputBehaviorPage page = new InputBehaviorPage(); page.textField.setVisible(false); tester().startPage(page); System.err.println("RES:\n\n" + tester().getLastResponseAsString()); assertThat(tester().getLastResponseAsString(), Matchers.not(Matchers.containsString("<div"))); assertThat(tester().getLastResponseAsString(), Matchers.not(Matchers.containsString("</div"))); }
@Test public void ruleKeyChangesIfInputContentsFromPathSourcePathInRuleKeyAppendableChanges() { BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()); SourcePathResolver pathResolver = new SourcePathResolver(resolver); final FakeProjectFilesystem filesystem = new FakeProjectFilesystem(); final Path output = Paths.get("output"); BuildRuleParams params = new FakeBuildRuleParamsBuilder("//:rule").setProjectFilesystem(filesystem).build(); BuildRule rule = new NoopBuildRule(params, pathResolver) { @AddToRuleKey RuleKeyAppendableWithInput input = new RuleKeyAppendableWithInput(new PathSourcePath(filesystem, output)); }; // Build a rule key with a particular hash set for the output for the above rule. FakeFileHashCache hashCache = new FakeFileHashCache(ImmutableMap.of(filesystem.resolve(output), HashCode.fromInt(0))); RuleKey inputKey1 = new InputBasedRuleKeyBuilderFactory(0, hashCache, pathResolver).build(rule); // Now, build a rule key with a different hash for the output for the above rule. hashCache = new FakeFileHashCache(ImmutableMap.of(filesystem.resolve(output), HashCode.fromInt(1))); RuleKey inputKey2 = new InputBasedRuleKeyBuilderFactory(0, hashCache, pathResolver).build(rule); assertThat(inputKey1, Matchers.not(Matchers.equalTo(inputKey2))); }
@Test public void ruleKeyChangesIfInputContentsFromPathSourceChanges() throws Exception { BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()); SourcePathResolver pathResolver = new SourcePathResolver(resolver); FakeProjectFilesystem filesystem = new FakeProjectFilesystem(); Path output = Paths.get("output"); BuildRule rule = ExportFileBuilder.newExportFileBuilder(BuildTargetFactory.newInstance("//:rule")) .setOut("out") .setSrc(new PathSourcePath(filesystem, output)) .build(resolver, filesystem); // Build a rule key with a particular hash set for the output for the above rule. FakeFileHashCache hashCache = new FakeFileHashCache(ImmutableMap.of(filesystem.resolve(output), HashCode.fromInt(0))); RuleKey inputKey1 = new InputBasedRuleKeyBuilderFactory(0, hashCache, pathResolver).build(rule); // Now, build a rule key with a different hash for the output for the above rule. hashCache = new FakeFileHashCache(ImmutableMap.of(filesystem.resolve(output), HashCode.fromInt(1))); RuleKey inputKey2 = new InputBasedRuleKeyBuilderFactory(0, hashCache, pathResolver).build(rule); assertThat(inputKey1, Matchers.not(Matchers.equalTo(inputKey2))); }
/** * Cacheable can clean cache after timeout. * * @throws Exception If something goes wrong */ @Test public void cleansCacheWhenExpired() throws Exception { final CacheableTest.Foo foo = new CacheableTest.Foo(1L); final String first = foo.get().toString(); TimeUnit.SECONDS.sleep((long) Tv.FIVE); MatcherAssert.assertThat(foo.get().toString(), Matchers.not(Matchers.equalTo(first))); }
@Test public void depfileBasedRuleKeyAvoidsRecompilingAfterChangeToUnusedHeader() throws Exception { CxxPlatform cxxPlatform = DefaultCxxPlatforms.build(new CxxBuckConfig(FakeBuckConfig.builder().build())); BuildTarget target = BuildTargetFactory.newInstance("//:binary_with_unused_header"); String unusedHeaderName = "unused_header.h"; String sourceName = "source.cpp"; BuildTarget preprocessTarget = getPreprocessTarget(cxxPlatform, target, sourceName, AbstractCxxSource.Type.CXX); // Run the build and verify that the C++ source was preprocessed. workspace.runBuckBuild("--config", "build.depfiles=true", target.toString()).assertSuccess(); BuckBuildLog.BuildLogEntry firstRunEntry = workspace.getBuildLog().getLogEntry(preprocessTarget); assertThat( firstRunEntry.getSuccessType(), equalTo(Optional.of(BuildRuleSuccessType.BUILT_LOCALLY))); // Now modify the unused header. workspace.writeContentsToPath( "static inline int newFunction() { return 20; }", unusedHeaderName); // Run the build again and verify that got a matching depfile rule key, and therefore // didn't recompile. workspace.runBuckBuild("--config", "build.depfiles=true", target.toString()).assertSuccess(); BuckBuildLog.BuildLogEntry secondRunEntry = workspace.getBuildLog().getLogEntry(preprocessTarget); assertThat( secondRunEntry.getSuccessType(), equalTo(Optional.of(BuildRuleSuccessType.MATCHING_DEP_FILE_RULE_KEY))); // Also, make sure the original rule keys are actually different. assertThat(secondRunEntry.getRuleKey(), Matchers.not(equalTo(firstRunEntry.getRuleKey()))); }
@Test public void depfileBasedRuleKeyRebuildsAfterChangeToUsedHeaderUsingFileRelativeInclusion() throws Exception { CxxPlatform cxxPlatform = DefaultCxxPlatforms.build(new CxxBuckConfig(FakeBuckConfig.builder().build())); BuildTarget target = BuildTargetFactory.newInstance("//:binary_with_used_relative_header"); String usedHeaderName = "source_relative_header.h"; String sourceName = "source_relative_header.cpp"; BuildTarget preprocessTarget = getPreprocessTarget(cxxPlatform, target, sourceName, AbstractCxxSource.Type.CXX); // Run the build and verify that the C++ source was preprocessed. workspace.runBuckBuild("--config", "build.depfiles=true", target.toString()).assertSuccess(); BuckBuildLog.BuildLogEntry firstRunEntry = workspace.getBuildLog().getLogEntry(preprocessTarget); assertThat( firstRunEntry.getSuccessType(), equalTo(Optional.of(BuildRuleSuccessType.BUILT_LOCALLY))); // Modify the used header. workspace.writeContentsToPath("static inline int newFunction() { return 20; }", usedHeaderName); // Run the build again and verify that we recompiled as the header caused the depfile rule key // to change. workspace.runBuckBuild("--config", "build.depfiles=true", target.toString()).assertSuccess(); BuckBuildLog.BuildLogEntry secondRunEntry = workspace.getBuildLog().getLogEntry(preprocessTarget); assertThat( secondRunEntry.getSuccessType(), equalTo(Optional.of(BuildRuleSuccessType.BUILT_LOCALLY))); // Also, make sure all three rule keys are actually different. assertThat(secondRunEntry.getRuleKey(), Matchers.not(equalTo(firstRunEntry.getRuleKey()))); }
/** * Cacheable can cache static calls. * * @throws Exception If something goes wrong */ @Test public void cachesSimpleStaticCall() throws Exception { final String first = CacheableTest.Foo.staticGet(); MatcherAssert.assertThat(first, Matchers.equalTo(CacheableTest.Foo.staticGet())); CacheableTest.Foo.staticFlush(); MatcherAssert.assertThat(CacheableTest.Foo.staticGet(), Matchers.not(Matchers.equalTo(first))); }
@Test public void testGETRequestNoContent() throws Exception { ByteBuffer header = BufferUtil.allocate(2048); HttpGenerator gen = new HttpGenerator(); HttpGenerator.Result result = gen.generateRequest(null, null, null, null, true); Assert.assertEquals(HttpGenerator.Result.NEED_INFO, result); Assert.assertEquals(HttpGenerator.State.START, gen.getState()); Info info = new Info("GET", "/index.html"); info.getFields().add("Host", "something"); info.getFields().add("User-Agent", "test"); Assert.assertTrue(!gen.isChunking()); result = gen.generateRequest(info, null, null, null, true); Assert.assertEquals(HttpGenerator.Result.NEED_HEADER, result); Assert.assertEquals(HttpGenerator.State.START, gen.getState()); result = gen.generateRequest(info, header, null, null, true); Assert.assertEquals(HttpGenerator.Result.FLUSH, result); Assert.assertEquals(HttpGenerator.State.COMPLETING, gen.getState()); Assert.assertTrue(!gen.isChunking()); String out = BufferUtil.toString(header); BufferUtil.clear(header); result = gen.generateResponse(null, null, null, null, false); Assert.assertEquals(HttpGenerator.Result.DONE, result); Assert.assertEquals(HttpGenerator.State.END, gen.getState()); Assert.assertTrue(!gen.isChunking()); Assert.assertEquals(0, gen.getContentPrepared()); Assert.assertThat(out, Matchers.containsString("GET /index.html HTTP/1.1")); Assert.assertThat(out, Matchers.not(Matchers.containsString("Content-Length"))); }
@Test public void testCompareToDifferentDimensionType() { ProductDimension dimension = createOtherProductDimension(); ProductDimension otherTypeOfDimension = dimension instanceof ProductBrand ? ProductDimensions.createOfferId("abc") : ProductDimensions.createBrand("google"); assertThat( "Comparing dimensions of different types should return a non-zero result", comparator.compare(dimension, otherTypeOfDimension), Matchers.not(0)); assertThat( "Comparing dimensions of different types should return a non-zero result", comparator.compare(otherTypeOfDimension, dimension), Matchers.not(0)); }
/** * Cacheable can cache calls. * * @throws Exception If something goes wrong */ @Test public void cachesSimpleCall() throws Exception { final CacheableTest.Foo foo = new CacheableTest.Foo(1L); final String first = foo.get().toString(); MatcherAssert.assertThat(first, Matchers.equalTo(foo.get().toString())); foo.flush(); MatcherAssert.assertThat(foo.get().toString(), Matchers.not(Matchers.equalTo(first))); }
/** * RtReleases can remove a release. * * @throws Exception if any problem inside */ @Test public void canRemoveRelease() throws Exception { final Releases releases = repo.releases(); final Release release = releases.create(RandomStringUtils.randomAlphanumeric(Tv.TEN)); MatcherAssert.assertThat(releases.iterate(), Matchers.hasItem(release)); releases.remove(release.number()); MatcherAssert.assertThat(releases.iterate(), Matchers.not(Matchers.hasItem(release))); }
@Test public void testSimpleCxxBinaryWithHeader() throws IOException { ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "simple", tmp); workspace.setUp(); CxxPlatform cxxPlatform = DefaultCxxPlatforms.build(new CxxBuckConfig(new FakeBuckConfig())); BuildTarget target = BuildTargetFactory.newInstance("//foo:simple_with_header"); CxxSourceRuleFactory cxxSourceRuleFactory = CxxSourceRuleFactoryHelper.of(target, cxxPlatform); BuildTarget binaryTarget = CxxDescriptionEnhancer.createCxxLinkTarget(target); String sourceName = "simple_with_header.cpp"; String headerName = "simple_with_header.h"; String headerFull = "foo/" + headerName; BuildTarget preprocessTarget = cxxSourceRuleFactory.createPreprocessBuildTarget( sourceName, CxxSource.Type.CXX, CxxSourceRuleFactory.PicType.PDC); BuildTarget compileTarget = cxxSourceRuleFactory.createCompileBuildTarget(sourceName, CxxSourceRuleFactory.PicType.PDC); BuildTarget headerSymlinkTreeTarget = CxxDescriptionEnhancer.createHeaderSymlinkTreeTarget( target, cxxPlatform.getFlavor(), HeaderVisibility.PRIVATE); // Do a clean build, verify that it succeeds, and check that all expected targets built // successfully. workspace.runBuckCommand("build", target.toString()).assertSuccess(); BuckBuildLog buildLog = workspace.getBuildLog(); assertEquals( ImmutableSet.of( headerSymlinkTreeTarget, preprocessTarget, compileTarget, binaryTarget, target), buildLog.getAllTargets()); buildLog.assertTargetBuiltLocally(headerSymlinkTreeTarget.toString()); buildLog.assertTargetBuiltLocally(preprocessTarget.toString()); buildLog.assertTargetBuiltLocally(compileTarget.toString()); buildLog.assertTargetBuiltLocally(binaryTarget.toString()); buildLog.assertTargetBuiltLocally(target.toString()); // Clear for new build. workspace.resetBuildLogFile(); // Update the source file. workspace.replaceFileContents(headerFull, "blah = 5", "blah = 6"); // Check that running a build again makes the source get recompiled and the binary // re-linked, but does not cause the header rules to re-run. workspace.runBuckCommand("build", target.toString()).assertSuccess(); buildLog = workspace.getBuildLog(); assertEquals( ImmutableSet.of( headerSymlinkTreeTarget, preprocessTarget, compileTarget, binaryTarget, target), buildLog.getAllTargets()); buildLog.assertTargetHadMatchingRuleKey(headerSymlinkTreeTarget.toString()); buildLog.assertTargetBuiltLocally(preprocessTarget.toString()); buildLog.assertTargetBuiltLocally(compileTarget.toString()); assertThat( buildLog.getLogEntry(binaryTarget).getSuccessType().get(), Matchers.not(Matchers.equalTo(BuildRuleSuccessType.MATCHING_RULE_KEY))); buildLog.assertTargetBuiltLocally(target.toString()); }
@Test public void testDifferByLevel() { ProductType type1 = ProductDimensions.createType(ProductDimensionType.PRODUCT_TYPE_L1, "ABC"); ProductType type2 = ProductDimensions.createType(ProductDimensionType.PRODUCT_TYPE_L2, "AbC"); assertThat( "Attributes that differ in level # should yield compareTo != 0", comparator.compare(type1, type2), Matchers.not(0)); }
@Test public void testReporterNotFound() throws Exception { Optional<ScheduledReporter> reporter; reporter = new MetricReportHandlerConsole() .select(mediator(), provider, URI.create("console://" + anytext(UUID.randomUUID()))); assertThat(reporter.get(), Matchers.instanceOf(ConsoleReporter.class)); assertReporter(reporter.get(), registry, "millisecond", "seconds"); ConsoleReporter console = (ConsoleReporter) reporter.get(); PrintStream stream = field(ConsoleReporter.class, "output", PrintStream.class, console); MatcherAssert.assertThat(stream, Matchers.not(Matchers.equalTo(System.out))); MatcherAssert.assertThat(stream, Matchers.not(Matchers.equalTo(System.err))); MatcherAssert.assertThat(stream, Matchers.notNullValue()); }
/** * Cacheable can Asynchronous update. * * @throws Exception If something goes wrong */ @Test public void asyncUpdateCacheSimpleCall() throws Exception { final CacheableTest.Foo foo = new CacheableTest.Foo(1L); final String first = foo.asyncGet().toString(); MatcherAssert.assertThat(first, Matchers.equalTo(foo.asyncGet().toString())); TimeUnit.SECONDS.sleep(2); MatcherAssert.assertThat(first, Matchers.equalTo(foo.asyncGet().toString())); TimeUnit.SECONDS.sleep(2); MatcherAssert.assertThat(first, Matchers.not(Matchers.equalTo(foo.asyncGet().toString()))); }
/** Test that WindowAndTrigger namespaces are prefixed by the related Window namespace. */ @Test public void testIntervalWindowPrefixing() { StateNamespace window = StateNamespaces.window(intervalCoder, intervalWindow(1000, 87392)); StateNamespace windowAndTrigger = StateNamespaces.windowAndTrigger(intervalCoder, intervalWindow(1000, 87392), 57); assertThat(windowAndTrigger.stringKey(), Matchers.startsWith(window.stringKey())); assertThat( StateNamespaces.global().stringKey(), Matchers.not(Matchers.startsWith(window.stringKey()))); }
/** * RtReleases can iterate releases. * * @throws Exception if something goes wrong */ @Test public void canFetchAllReleases() throws Exception { final Releases releases = repo.releases(); final Release release = releases.create(RandomStringUtils.randomAlphanumeric(Tv.TEN)); try { MatcherAssert.assertThat( releases.iterate(), Matchers.not(Matchers.emptyIterableOf(Release.class))); } finally { releases.remove(release.number()); } }
/** * DyAlias can make an alias. * * @throws Exception If there is some problem inside */ @Test public void makesAlias() throws Exception { final Aliases aliases = new DyBase().user(new URN("urn:test:12")).aliases(); final String name = "walter"; aliases.add(name); MatcherAssert.assertThat(aliases.check(name), Matchers.not(Matchers.isEmptyOrNullString())); final Alias alias = aliases.iterate().iterator().next(); MatcherAssert.assertThat(alias, new Alias.HasName(Matchers.equalTo(name))); alias.photo(new URI("http://localhost#test")); MatcherAssert.assertThat(alias.photo().toString(), Matchers.containsString("#test")); }
/** Test that WindowAndTrigger namespaces are prefixed by the related Window namespace. */ @Test public void testGlobalWindowPrefixing() { StateNamespace window = StateNamespaces.window(GlobalWindow.Coder.INSTANCE, GlobalWindow.INSTANCE); StateNamespace windowAndTrigger = StateNamespaces.windowAndTrigger(GlobalWindow.Coder.INSTANCE, GlobalWindow.INSTANCE, 57); assertThat(windowAndTrigger.stringKey(), Matchers.startsWith(window.stringKey())); assertThat( StateNamespaces.global().stringKey(), Matchers.not(Matchers.startsWith(window.stringKey()))); }
// #6187: if no fields were boosted, we shouldn't use AllTokenStream public void testNoBoost() throws Exception { String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/all/noboost-mapping.json"); DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping); byte[] json = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/all/test1.json"); Document doc = docMapper.parse("test", "person", "1", new BytesArray(json)).rootDoc(); AllField field = (AllField) doc.getField("_all"); // no fields have boost, so we should not see AllTokenStream: assertThat( field.tokenStream(docMapper.mappers().indexAnalyzer(), null), Matchers.not(Matchers.instanceOf(AllTokenStream.class))); }
@Test public void resolveHeadersBehindSymlinkTreesInError() throws IOException { ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "resolved", tmp); workspace.setUp(); workspace.writeContentsToPath("#invalid_pragma", "lib2.h"); BuildTarget target = BuildTargetFactory.newInstance("//:bin"); ProjectWorkspace.ProcessResult result = workspace.runBuckCommand("build", target.toString()); result.assertFailure(); // Verify that the preprocessed source contains no references to the symlink tree used to // setup the headers. String error = result.getStderr(); assertThat(error, Matchers.not(Matchers.containsString(BuckConstant.SCRATCH_DIR))); assertThat(error, Matchers.not(Matchers.containsString(BuckConstant.GEN_DIR))); assertThat(error, Matchers.containsString("In file included from lib1.h:1")); assertThat(error, Matchers.containsString("from bin.h:1")); assertThat(error, Matchers.containsString("from bin.cpp:1:")); assertThat(error, Matchers.containsString("lib2.h:1:2: error: invalid preprocessing")); }
// #6187: if _all doesn't index positions then we never use AllTokenStream, even if some fields // have boost public void testBoostWithOmitPositions() throws Exception { String mapping = copyToStringFromClasspath( "/org/elasticsearch/index/mapper/all/mapping_boost_omit_positions_on_all.json"); DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping); byte[] json = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/all/test1.json"); Document doc = docMapper.parse("test", "person", "1", new BytesArray(json)).rootDoc(); AllField field = (AllField) doc.getField("_all"); // _all field omits positions, so we should not get AllTokenStream even though fields are // boosted assertThat( field.tokenStream(docMapper.mappers().indexAnalyzer(), null), Matchers.not(Matchers.instanceOf(AllTokenStream.class))); }
@Test public void testEquals() { GcsPath a = GcsPath.fromComponents(null, "a/b/c"); GcsPath a2 = GcsPath.fromComponents(null, "a/b/c"); assertFalse(a.isAbsolute()); assertFalse(a2.isAbsolute()); GcsPath b = GcsPath.fromComponents("bucket", "a/b/c"); GcsPath b2 = GcsPath.fromComponents("bucket", "a/b/c"); assertTrue(b.isAbsolute()); assertTrue(b2.isAbsolute()); assertEquals(a, a); assertThat(a, Matchers.not(Matchers.equalTo(b))); assertThat(b, Matchers.not(Matchers.equalTo(a))); assertEquals(a, a2); assertEquals(a2, a); assertEquals(b, b2); assertEquals(b2, b); assertThat(a, Matchers.not(Matchers.equalTo(Paths.get("/tmp/foo")))); assertTrue(a != null); }
@Test public void withHeightSizeWithColumnSize() { InputBehaviorPage page = new InputBehaviorPage(); page.inputBehavior.size(ExtraSmallSpanType.SPAN10); tester().startPage(page); TagTester tagTester = tester().getTagById("input"); String cssClass = tagTester.getAttribute("class"); assertThat(cssClass, Matchers.containsString("form-control")); assertThat(cssClass, Matchers.not(Matchers.containsString("input-lg"))); assertThat( tester().getLastResponseAsString(), Matchers.containsString("<div class=\"col-xs-10\"")); assertThat(tester().getLastResponseAsString(), Matchers.containsString("</div")); }
/** * ArrayMap can make a map fluently. * * @throws Exception If some problem inside */ @Test public void buildsMapFluently() throws Exception { MatcherAssert.assertThat( new ArrayMap<Integer, String>() .with(Tv.FIVE, "four") .with(Tv.FIVE, Integer.toString(Tv.FIVE)) .with(Tv.FORTY, "fourty") .without(Tv.FORTY) .with(Tv.TEN, "ten"), Matchers.allOf( Matchers.not(Matchers.hasKey(Tv.FORTY)), Matchers.hasValue(Integer.toString(Tv.FIVE)), Matchers.hasKey(Tv.FIVE), Matchers.hasEntry(Tv.FIVE, Integer.toString(Tv.FIVE)))); }
@Given("^the user has an SSH key in the key store$") public void theUserHasAnSSHKeyInTheKeyStore() throws Throwable { String contents = IOUtils.toString(UserApiDefinitions.class.getResource("/test_rsa.pub")); KeyHolder keyHolder = new KeyHolder(userModel.getName(), contents); keyStore.put(keyHolder); assertThat(getKeysApi().listSshKeys(), Matchers.not(Matchers.empty())); SshKeyModel sshKeyModel = new SshKeyModel(); sshKeyModel.setContents(contents); sshKeyModel.setName(keyHolder.getName()); Collection<ConstraintViolation<SshKeyModel>> violations = validator.validate(sshKeyModel); assertThat(violations, Matchers.empty()); resetMockCounters(); }
/** * WebLinkingResponse can recognize Links in headers. * * @throws Exception If something goes wrong inside */ @Test @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") public void parsesLinksInHeaders() throws Exception { final String[] headers = { "</hey/foo>; title=\"Hi!\"; rel=foo", "</hey/foo>; title=\"\u20ac\"; rel=\"foo\"; media=\"text/xml\"", }; for (final String header : headers) { final WebLinkingResponse response = new WebLinkingResponse(new FakeRequest().withHeader("Link", header).fetch()); final WebLinkingResponse.Link link = response.links().get("foo"); MatcherAssert.assertThat(link.uri(), Matchers.hasToString("/hey/foo")); MatcherAssert.assertThat(link, Matchers.hasKey("title")); MatcherAssert.assertThat(response.links(), Matchers.not(Matchers.hasKey("something else"))); } }