@Override public Execution getMembersFunctionExecutor(final Set<DistributedMember> members) { assertThat(members).isNotNull(); return this.functionExecutor; } }
@Test public void shouldBeLoaded() { final ServiceLoader<ResponseConverterFunctionProvider> loader = ServiceLoader.load(ResponseConverterFunctionProvider.class, ObservableResponseConverterFunctionProviderTest.class.getClassLoader()); assertThat(loader).isNotNull(); final Iterator<ResponseConverterFunctionProvider> it = loader.iterator(); assertThat(it.hasNext()).isTrue(); assertThat(it.next()).isInstanceOf(ResponseConverterFunctionProvider.class); assertThat(it.hasNext()).isFalse(); }
@Test public void testParameters() { final SpanWrapper span = createTestSpan(1, s -> SpanUtils.setParameters(s, Collections.singletonMap("foo", "bar"))); final ObjectNode jsonSpan = JsonUtils.toObjectNode(span); assertThat(jsonSpan.get("parameters")).isNotNull(); assertThat(jsonSpan.get("parameters").get(0)).isNotNull(); assertThat(jsonSpan.get("parameters").get(0).get("key").asText()).isEqualTo("foo"); assertThat(jsonSpan.get("parameters").get(0).get("value").asText()).isEqualTo("bar"); }
private void validateSpanJson(JsonNode spanJson) { assertThat(spanJson.get("error").booleanValue()).as(spanJson.toString()).isFalse(); assertThat(spanJson.get("foo.bar").asText()).as(spanJson.toString()).isEqualTo("baz"); assertThat(spanJson.get("parameters")).as(spanJson.toString()).isNotNull(); assertThat(spanJson.get("parameters").size()).as(spanJson.toString()).isEqualTo(3); assertThat(spanJson.get("parameters").get(0).get("key")).as(spanJson.toString()).isNotNull(); assertThat(spanJson.get("parameters").get(0).get("value")).as(spanJson.toString()).isNotNull(); }
@Test public void serializeLineGraphics_resultJsonHasUid() throws IOException { //when graphicsSerializer.serialize(line, jgen, new DefaultSerializerProvider.Impl()); jgen.flush(); //then JsonNode actualObj = mapper.readTree(sw.toString()); Assertions.assertThat(actualObj.has("uid")).isTrue(); Assertions.assertThat(actualObj.get("uid")).isNotNull(); }
@Test public void deserializeAnonymousAuthenticationTokenTest() throws IOException { AnonymousAuthenticationToken token = mapper .readValue(ANONYMOUS_JSON, AnonymousAuthenticationToken.class); assertThat(token).isNotNull(); assertThat(token.getKeyHash()).isEqualTo(HASH_KEY.hashCode()); assertThat(token.getAuthorities()).isNotNull().hasSize(1).contains(new SimpleGrantedAuthority("ROLE_USER")); }
@Test public void deserializeUnauthenticatedUsernamePasswordAuthenticationTokenMixinTest() throws IOException, JSONException { UsernamePasswordAuthenticationToken token = mapper .readValue(UNAUTHENTICATED_STRINGPRINCIPAL_JSON, UsernamePasswordAuthenticationToken.class); assertThat(token).isNotNull(); assertThat(token.isAuthenticated()).isEqualTo(false); assertThat(token.getAuthorities()).isNotNull().hasSize(0); }
@Test public void classLevelAttributesAreFound() { Collection<ConfigAttribute> attrs = this.mds.findAttributes( BusinessService.class); assertThat(attrs).isNotNull(); // expect 1 annotation assertThat(attrs).hasSize(1); // should have 1 SecurityConfig SecurityConfig sc = (SecurityConfig) attrs.toArray()[0]; assertThat(sc.getAttribute()).isEqualTo("ROLE_USER"); }
@Test public void reportSpan() throws Exception { reporter.report(mock(SpanContextInformation.class), getSpan(100)); elasticsearchClient.waitForCompletion(); refresh(); final JsonNode hits = elasticsearchClient.getJson("/stagemonitor-spans*/_search").get("hits"); assertThat(hits.get("total").intValue()).as(hits.toString()).isEqualTo(1); final JsonNode spanJson = hits.get("hits").elements().next().get("_source"); assertThat(spanJson.get("type").asText()).as(spanJson.toString()).isEqualTo("jdbc"); assertThat(spanJson.get("method").asText()).as(spanJson.toString()).isEqualTo("SELECT"); assertThat(spanJson.get("db.statement")).as(spanJson.toString()).isNotNull(); assertThat(spanJson.get("db.statement").asText()).as(spanJson.toString()).isEqualTo("SELECT * from STAGEMONITOR where 1 < 2"); assertThat(spanJson.get("duration_ms").asInt()).as(spanJson.toString()).isEqualTo(100); assertThat(spanJson.get("name").asText()).as(spanJson.toString()).isEqualTo("ElasticsearchExternalSpanReporterIntegrationTest#test"); }
@Test public void testAuthenticateSuccess() { OpenIDAuthenticationProvider provider = new OpenIDAuthenticationProvider(); provider.setUserDetailsService(new MockUserDetailsService()); Authentication preAuth = new OpenIDAuthenticationToken( OpenIDAuthenticationStatus.SUCCESS, USERNAME, "", null); assertThat(preAuth.isAuthenticated()).isFalse(); Authentication postAuth = provider.authenticate(preAuth); assertThat(postAuth).isNotNull(); assertThat(postAuth instanceof OpenIDAuthenticationToken).isTrue(); assertThat(postAuth.isAuthenticated()).isTrue(); assertThat(postAuth.getPrincipal()).isNotNull(); assertThat(postAuth.getPrincipal() instanceof UserDetails).isTrue(); assertThat(postAuth.getAuthorities()).isNotNull(); assertThat(postAuth.getAuthorities().size() > 0).isTrue(); assertThat( ((OpenIDAuthenticationToken) postAuth).getStatus() == OpenIDAuthenticationStatus.SUCCESS).isTrue(); assertThat(((OpenIDAuthenticationToken) postAuth).getMessage() == null).isTrue(); }
@Test @SuppressWarnings("unchecked") public void testExecuteWithNoIndexes() throws Throwable { // Prepare Mocks when(mockQueryService.getIndexes()).thenReturn(Collections.emptyList()); // Execute Function and assert results final ListIndexFunction function = new ListIndexFunction(); function.execute(mockFunctionContext); final List<?> results = testResultSender.getResults(); assertThat(results).isNotNull(); assertThat(results.size()).isEqualTo(1); final Set<IndexDetails> actualIndexDetailsSet = (Set<IndexDetails>) results.get(0); assertThat(actualIndexDetailsSet).isNotNull(); assertThat(actualIndexDetailsSet.isEmpty()).isTrue(); }
@Test public void testCreateEmptyIndex() throws Exception { elasticsearchClient.createEmptyIndex("test"); assertThat(elasticsearchClient.getJson("/test").get("test")).isNotNull(); } }
@Test public void deserializeAuthenticatedUsernamePasswordAuthenticationTokenWithUserTest() throws IOException { UsernamePasswordAuthenticationToken token = mapper .readValue(AUTHENTICATED_JSON, UsernamePasswordAuthenticationToken.class); assertThat(token).isNotNull(); assertThat(token.getPrincipal()).isNotNull().isInstanceOf(User.class); assertThat(((User) token.getPrincipal()).getAuthorities()).isNotNull().hasSize(1).contains(new SimpleGrantedAuthority("ROLE_USER")); assertThat(token.isAuthenticated()).isEqualTo(true); assertThat(token.getAuthorities()).hasSize(1).contains(new SimpleGrantedAuthority("ROLE_USER")); }
@Test @SuppressWarnings("unchecked") public void testExecuteOnMemberWithANonGemFireCache() throws Throwable { final TestResultSender testResultSender = new TestResultSender(); final Cache mockNonGemCache = mock(Cache.class, "NonGemCache"); when(mockFunctionContext.getCache()).thenReturn(mockNonGemCache); when(mockFunctionContext.getResultSender()).thenReturn(testResultSender); final ListDiskStoresFunction function = new ListDiskStoresFunction(); function.execute(mockFunctionContext); final List<?> results = testResultSender.getResults(); assertThat(results).isNotNull(); assertThat(results.size()).isEqualTo(1); final Set<DiskStoreDetails> diskStoreDetails = (Set<DiskStoreDetails>) results.get(0); assertThat(diskStoreDetails).isNotNull(); assertThat(diskStoreDetails.isEmpty()).isTrue(); }
@Test public void read_empty_stream() throws Exception { File file = temp.newFile(); CloseableIterator<Fake> it = Protobuf.readStream(file, Fake.parser()); assertThat(it).isNotNull(); assertThat(it.hasNext()).isFalse(); } }
@Test public void testRoleHierarchyWithNullOrEmptyAuthorities() { List<GrantedAuthority> authorities0 = null; List<GrantedAuthority> authorities1 = new ArrayList<>(); RoleHierarchyImpl roleHierarchyImpl = new RoleHierarchyImpl(); roleHierarchyImpl.setHierarchy("ROLE_A > ROLE_B"); assertThat(roleHierarchyImpl.getReachableGrantedAuthorities( authorities0)).isNotNull(); assertThat( roleHierarchyImpl.getReachableGrantedAuthorities(authorities0)).isEmpty(); assertThat(roleHierarchyImpl.getReachableGrantedAuthorities( authorities1)).isNotNull(); assertThat( roleHierarchyImpl.getReachableGrantedAuthorities(authorities1)).isEmpty(); }
@Test public void gatewaySender() { regionAttributes.setGatewaySenderIds(null); assertThat(regionAttributes.getGatewaySenderIdsAsSet()).isNull(); regionAttributes.setGatewaySenderIds(""); assertThat(regionAttributes.getGatewaySenderIdsAsSet()).isNotNull().isEmpty(); regionAttributes.setGatewaySenderIds("abc,def"); assertThat(regionAttributes.getGatewaySenderIdsAsSet()).isNotNull().hasSize(2); }
@Test public void asyncEventQueue() { regionAttributes.setAsyncEventQueueIds(null); assertThat(regionAttributes.getAsyncEventQueueIdsAsSet()).isNull(); regionAttributes.setAsyncEventQueueIds(""); assertThat(regionAttributes.getAsyncEventQueueIdsAsSet()).isNotNull().isEmpty(); regionAttributes.setAsyncEventQueueIds("abc,def"); assertThat(regionAttributes.getAsyncEventQueueIdsAsSet()).isNotNull().hasSize(2); } }
@Test public void alterWithNoAsyncEventQueueIds() { RegionConfig deltaConfig = getDeltaRegionConfig("alter region --name=regionA --async-event-queue-id=''"); assertThat(deltaConfig.getRegionAttributes().getAsyncEventQueueIds()).isEqualTo(""); assertThat(deltaConfig.getRegionAttributes().getGatewaySenderIds()).isNull(); RegionAttributesType existingAttributes = new RegionAttributesType(); existingRegionConfig.setRegionAttributes(existingAttributes); existingAttributes.setAsyncEventQueueIds("xyz"); existingAttributes.setGatewaySenderIds("xyz"); command.updateConfigForGroup("cluster", cacheConfig, deltaConfig); assertThat(existingAttributes.getGatewaySenderIds()).isEqualTo("xyz"); assertThat(existingAttributes.getAsyncEventQueueIds()).isEqualTo(""); assertThat(existingAttributes.getAsyncEventQueueIdsAsSet()).isNotNull().isEmpty(); }