private RequestConditionHolder[] wrap(RequestCondition<?>... rawConditions) { RequestConditionHolder[] wrappedConditions = new RequestConditionHolder[rawConditions.length]; for (int i = 0; i < rawConditions.length; i++) { wrappedConditions[i] = new RequestConditionHolder(rawConditions[i]); } return wrappedConditions; }
/** * Get the matching condition for the held request condition wrap it in a * new RequestConditionHolder instance. Or otherwise if this is an empty * holder, return the same holder instance. */ @Override public RequestConditionHolder getMatchingCondition(ServerWebExchange exchange) { if (this.condition == null) { return this; } RequestCondition<?> match = (RequestCondition<?>) this.condition.getMatchingCondition(exchange); return (match != null ? new RequestConditionHolder(match) : null); }
public RequestMappingInfo(@Nullable String name, @Nullable PatternsRequestCondition patterns, @Nullable RequestMethodsRequestCondition methods, @Nullable ParamsRequestCondition params, @Nullable HeadersRequestCondition headers, @Nullable ConsumesRequestCondition consumes, @Nullable ProducesRequestCondition produces, @Nullable RequestCondition<?> custom) { this.name = (StringUtils.hasText(name) ? name : null); this.patternsCondition = (patterns != null ? patterns : new PatternsRequestCondition()); this.methodsCondition = (methods != null ? methods : new RequestMethodsRequestCondition()); this.paramsCondition = (params != null ? params : new ParamsRequestCondition()); this.headersCondition = (headers != null ? headers : new HeadersRequestCondition()); this.consumesCondition = (consumes != null ? consumes : new ConsumesRequestCondition()); this.producesCondition = (produces != null ? produces : new ProducesRequestCondition()); this.customConditionHolder = new RequestConditionHolder(custom); }
/** * Combine the request conditions held by the two RequestConditionHolder * instances after making sure the conditions are of the same type. * Or if one holder is empty, the other holder is returned. */ @Override public RequestConditionHolder combine(RequestConditionHolder other) { if (this.condition == null && other.condition == null) { return this; } else if (this.condition == null) { return other; } else if (other.condition == null) { return this; } else { assertEqualConditionTypes(this.condition, other.condition); RequestCondition<?> combined = (RequestCondition<?>) this.condition.combine(other.condition); return new RequestConditionHolder(combined); } }
@Test public void compareEmpty() { RequestConditionHolder empty = new RequestConditionHolder(null); RequestConditionHolder empty2 = new RequestConditionHolder(null); RequestConditionHolder notEmpty = new RequestConditionHolder(new ParamsRequestCondition("name")); assertEquals(0, empty.compareTo(empty2, this.exchange)); assertEquals(-1, notEmpty.compareTo(empty, this.exchange)); assertEquals(1, empty.compareTo(notEmpty, this.exchange)); }
@Test public void combine() { RequestConditionHolder params1 = new RequestConditionHolder(new ParamsRequestCondition("name1")); RequestConditionHolder params2 = new RequestConditionHolder(new ParamsRequestCondition("name2")); RequestConditionHolder expected = new RequestConditionHolder(new ParamsRequestCondition("name1", "name2")); assertEquals(expected, params1.combine(params2)); }
@Test(expected = ClassCastException.class) public void combineIncompatible() { RequestConditionHolder params = new RequestConditionHolder(new ParamsRequestCondition("name")); RequestConditionHolder headers = new RequestConditionHolder(new HeadersRequestCondition("name")); params.combine(headers); }
@Test public void matchEmpty() { RequestConditionHolder empty = new RequestConditionHolder(null); assertSame(empty, empty.getMatchingCondition(this.exchange)); }
@Test(expected = ClassCastException.class) public void compareIncompatible() { RequestConditionHolder params = new RequestConditionHolder(new ParamsRequestCondition("name")); RequestConditionHolder headers = new RequestConditionHolder(new HeadersRequestCondition("name")); params.compareTo(headers, this.exchange); }
@Test public void noMatch() { RequestMethodsRequestCondition rm = new RequestMethodsRequestCondition(RequestMethod.POST); RequestConditionHolder custom = new RequestConditionHolder(rm); assertNull(custom.getMatchingCondition(this.exchange)); }
@Test public void combineEmpty() { RequestConditionHolder empty = new RequestConditionHolder(null); RequestConditionHolder notEmpty = new RequestConditionHolder(new ParamsRequestCondition("name")); assertSame(empty, empty.combine(empty)); assertSame(notEmpty, notEmpty.combine(empty)); assertSame(notEmpty, empty.combine(notEmpty)); }
@Test public void compare() { RequestConditionHolder params11 = new RequestConditionHolder(new ParamsRequestCondition("1")); RequestConditionHolder params12 = new RequestConditionHolder(new ParamsRequestCondition("1", "2")); assertEquals(1, params11.compareTo(params12, this.exchange)); assertEquals(-1, params12.compareTo(params11, this.exchange)); }
@Test public void match() { RequestMethodsRequestCondition rm = new RequestMethodsRequestCondition(RequestMethod.GET, RequestMethod.POST); RequestConditionHolder custom = new RequestConditionHolder(rm); RequestMethodsRequestCondition expected = new RequestMethodsRequestCondition(RequestMethod.GET); RequestConditionHolder holder = custom.getMatchingCondition(this.exchange); assertNotNull(holder); assertEquals(expected, holder.getCondition()); }
private RequestConditionHolder[] wrap(RequestCondition<?>... rawConditions) { RequestConditionHolder[] wrappedConditions = new RequestConditionHolder[rawConditions.length]; for (int i = 0; i < rawConditions.length; i++) { wrappedConditions[i] = new RequestConditionHolder(rawConditions[i]); } return wrappedConditions; }
/** * Get the matching condition for the held request condition wrap it in a * new RequestConditionHolder instance. Or otherwise if this is an empty * holder, return the same holder instance. */ @Override public RequestConditionHolder getMatchingCondition(ServerWebExchange exchange) { if (this.condition == null) { return this; } RequestCondition<?> match = (RequestCondition<?>) this.condition.getMatchingCondition(exchange); return (match != null ? new RequestConditionHolder(match) : null); }
/** * Combine the request conditions held by the two RequestConditionHolder * instances after making sure the conditions are of the same type. * Or if one holder is empty, the other holder is returned. */ @Override public RequestConditionHolder combine(RequestConditionHolder other) { if (this.condition == null && other.condition == null) { return this; } else if (this.condition == null) { return other; } else if (other.condition == null) { return this; } else { assertEqualConditionTypes(other); RequestCondition<?> combined = (RequestCondition<?>) this.condition.combine(other.condition); return new RequestConditionHolder(combined); } }
public RequestMappingInfo(String name, PatternsRequestCondition patterns, RequestMethodsRequestCondition methods, ParamsRequestCondition params, HeadersRequestCondition headers, ConsumesRequestCondition consumes, ProducesRequestCondition produces, RequestCondition<?> custom) { this.name = (StringUtils.hasText(name) ? name : null); this.patternsCondition = (patterns != null ? patterns : new PatternsRequestCondition()); this.methodsCondition = (methods != null ? methods : new RequestMethodsRequestCondition()); this.paramsCondition = (params != null ? params : new ParamsRequestCondition()); this.headersCondition = (headers != null ? headers : new HeadersRequestCondition()); this.consumesCondition = (consumes != null ? consumes : new ConsumesRequestCondition()); this.producesCondition = (produces != null ? produces : new ProducesRequestCondition()); this.customConditionHolder = new RequestConditionHolder(custom); }