@Test public void getParameterNamesOnInterface() { Method method = ReflectionUtils.findMethod(MessageService.class,"sendMessage", String.class); String[] actualParams = parameterNameDiscoverer.getParameterNames(method); assertThat(actualParams, is(new String[]{"message"})); }
@Test(dataProvider = "populated") public void add_whenPopulated(Queue<Integer> queue) { assertThat(queue.add(-1), is(true)); assertThat(queue.peek(), is(not(-1))); assertThat(Iterables.getLast(queue), is(-1)); assertThat(queue, hasSize(POPULATED_SIZE + 1)); assertThat(queue.size(), is(equalTo(Iterables.size(queue)))); }
@Test public void shouldImplementEqualsProperly() { final Collection<ConfigEntry> entries = new ArrayList<>(); entries.add(E1); assertThat(config, is(equalTo(config))); assertThat(config, is(equalTo(new Config(config.entries())))); assertThat(config, is(not(equalTo(new Config(entries))))); assertThat(config, is(not(equalTo((Object) "this")))); }
@Test public void destroy() throws Exception { filter = new PatternMappingFilterProxy(delegate, "/"); filter.destroy(); assertThat(delegate.destroy, is(true)); }
@Test public void shouldProduceBackwardsCompatibleId() { long id = ResourceTypes.indexEntryResourceId( labelId, exact( propertyId, value ) ); assertThat( id, equalTo( 155667838465249649L ) ); }
@Test public void correctRepresentation() { Response resp = jmxService.getServiceDefinition(); assertEquals( 200, resp.getStatus() ); String json = UTF8.decode( (byte[]) resp.getEntity() ); MatcherAssert.assertThat( json, containsString( "resources" ) ); MatcherAssert.assertThat( json, containsString( uri.toString() ) ); MatcherAssert.assertThat( json, containsString( "jmx/domain/{domain}/{objectName}" ) ); }
@Test public void testDefaultFilterLocations() { when(configuration.getStringArray(eq("zuul.filters.locations"))).thenReturn("inbound,outbound,endpoint".split(",")); String[] filterLocations = module.findFilterLocations(configuration); assertThat(filterLocations.length, equalTo(3)); assertThat(filterLocations[1], equalTo("outbound")); }
@Test public void headerContainsWithMissingHeader() throws Exception { AssertionError error = assertThrows(AssertionError.class, () -> MockRestRequestMatchers.header("foo", containsString("baz")).match(this.request)); assertThat(error.getMessage(), containsString("but was null")); }
@Test public void shouldSupportPhpStyleUrlEncodedPostBodiesForAListAndNonListParams() throws Exception { UrlFormFormat format = new UrlFormFormat(); Map<String, Object> map = format.readMap( "var[]=A&var[]=B&foo=bar" ); assertThat( map.size(), is( 2 ) ); assertThat( ( (List<String>) map.get( "var" ) ).get( 0 ), is( "A" ) ); assertThat( ( (List<String>) map.get( "var" ) ).get( 1 ), is( "B" ) ); assertEquals( "bar", map.get( "foo" ) ); }
@Test void invalidExpressionEvaluationType() { String methodName = "nonBooleanOrStringExpression"; IllegalStateException exception = assertThrows(IllegalStateException.class, () -> condition.evaluateExecutionCondition(buildExtensionContext(methodName))); Method method = ReflectionUtils.findMethod(getClass(), methodName); assertThat(exception.getMessage(), is(equalTo("@DisabledIf(\"#{6 * 7}\") on " + method + " must evaluate to a String or a Boolean, not java.lang.Integer"))); }
private void assertFilterNotInvoked(String requestUri, String pattern) throws Exception { request.setRequestURI(request.getContextPath() + requestUri); filter = new PatternMappingFilterProxy(delegate, pattern); filter.doFilter(request, response, filterChain); assertThat(delegate.request, equalTo((ServletRequest) null)); assertThat(delegate.response, equalTo((ServletResponse) null)); assertThat(delegate.chain, equalTo((FilterChain) null)); assertThat(filterChain.getRequest(), equalTo((ServletRequest) request)); assertThat(filterChain.getResponse(), equalTo((ServletResponse) response)); filterChain = new MockFilterChain(); }
private void testTransportUrl(String scheme, String expectedScheme, TransportType transportType) throws Exception { SockJsUrlInfo info = new SockJsUrlInfo(new URI(scheme + "://example.com")); String serverId = info.getServerId(); String sessionId = info.getSessionId(); String transport = transportType.toString().toLowerCase(); URI expected = new URI(expectedScheme + "://example.com/" + serverId + "/" + sessionId + "/" + transport); assertThat(info.getTransportUrl(transportType), equalTo(expected)); }
@Test public void init() throws Exception { FilterConfig config = new MockFilterConfig(); filter = new PatternMappingFilterProxy(delegate, "/"); filter.init(config); assertThat(delegate.filterConfig, is(config)); }
@Test public void testElapsedTime() { final long elapsedTime = new TransactionHolder<>(new Object(), 0) .elapsedTime(Clock.fixed(Instant.ofEpochMilli(1000), ZoneOffset.UTC)); assertThat(elapsedTime, equalTo(1000L)); }
@Test public void shouldRespondWithJMXResources() { String url = functionalTestHelper.managementUri() + "/server/jmx"; JaxRsResponse resp = RestRequest.req().get(url); String json = resp.getEntity(); assertEquals(json, 200, resp.getStatus()); assertThat(json, containsString("resources")); assertThat(json, containsString("jmx/domain/{domain}/{objectName}")); resp.close(); } }
@Test public void testMultiClasses() { Class expectedClass1 = TestZuulFilter.class; Class expectedClass2 = TestZuulFilter2.class; when(configuration.getStringArray(eq("zuul.filters.classes"))).thenReturn(new String[]{"com.netflix.zuul.init.TestZuulFilter", "com.netflix.zuul.init2.TestZuulFilter2"}); when(configuration.getStringArray(eq("zuul.filters.packages"))).thenReturn(new String[0]); String[] classNames = module.findClassNames(configuration); assertThat(classNames.length, equalTo(2)); assertThat(classNames[0], equalTo(expectedClass1.getCanonicalName())); assertThat(classNames[1], equalTo(expectedClass2.getCanonicalName())); }
@Test public void shouldGetEntry() { assertThat(config.get("a"), is(E1)); assertThat(config.get("c"), is(E2)); }
@Test public void getAttributes() { assertThat(SimpAttributesContextHolder.getAttributes(), nullValue()); SimpAttributesContextHolder.setAttributes(this.simpAttributes); assertThat(SimpAttributesContextHolder.getAttributes(), sameInstance(this.simpAttributes)); }
@Test public void testTransformUserEntityHappyCase() { UserEntity userEntity = userEntityJsonMapper.transformUserEntity(JSON_RESPONSE_USER_DETAILS); assertThat(userEntity.getUserId(), is(1)); assertThat(userEntity.getFullname(), is(equalTo("Simon Hill"))); assertThat(userEntity.getEmail(), is(equalTo("jcooper@babbleset.edu"))); }
@Test(dataProvider = "populated") public void size_whenPopulated(Queue<?> queue) { assertThat(queue.size(), is(POPULATED_SIZE)); assertThat(Iterables.size(queue), is(POPULATED_SIZE)); assertThat(queue.size(), is(equalTo(Iterables.size(queue)))); }