|
| 1 | +/* |
| 2 | + * Licensed to Elasticsearch under one or more contributor |
| 3 | + * license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright |
| 5 | + * ownership. Elasticsearch licenses this file to you under |
| 6 | + * the Apache License, Version 2.0 (the "License"); you may |
| 7 | + * not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +package org.elasticsearch.client.watcher; |
| 21 | + |
| 22 | +import org.elasticsearch.action.admin.cluster.repositories.verify.VerifyRepositoryResponse; |
| 23 | +import org.elasticsearch.common.xcontent.ToXContent; |
| 24 | +import org.elasticsearch.common.xcontent.XContentBuilder; |
| 25 | +import org.elasticsearch.test.ESTestCase; |
| 26 | + |
| 27 | +import java.io.IOException; |
| 28 | +import java.util.ArrayList; |
| 29 | +import java.util.List; |
| 30 | + |
| 31 | +import static org.elasticsearch.test.AbstractXContentTestCase.xContentTester; |
| 32 | + |
| 33 | +public class VerifyRepositoryResponseTests extends ESTestCase { |
| 34 | + |
| 35 | + public void testFromXContent() throws IOException { |
| 36 | + xContentTester(this::createParser, |
| 37 | + VerifyRepositoryResponseTests::createTestInstance, |
| 38 | + VerifyRepositoryResponseTests::toXContent, |
| 39 | + VerifyRepositoryResponse::fromXContent) |
| 40 | + .supportsUnknownFields(true) |
| 41 | + .shuffleFieldsExceptions(new String[] {"nodes"}) // do not mix up the order of nodes, it will cause the tests to fail |
| 42 | + .randomFieldsExcludeFilter((f) -> f.equals("nodes")) // everything in nodes needs to be a particular parseable object |
| 43 | + .assertToXContentEquivalence(false) |
| 44 | + .test(); |
| 45 | + } |
| 46 | + |
| 47 | + private static VerifyRepositoryResponse createTestInstance() { |
| 48 | + List<VerifyRepositoryResponse.NodeView> nodes = new ArrayList<>(); |
| 49 | + for (int i = 0; i < randomIntBetween(0, 2); i++) { |
| 50 | + nodes.add(new VerifyRepositoryResponse.NodeView(randomAlphaOfLength(5), randomAlphaOfLength(5))); |
| 51 | + } |
| 52 | + |
| 53 | + return new VerifyRepositoryResponse(nodes); |
| 54 | + } |
| 55 | + |
| 56 | + private static XContentBuilder toXContent(VerifyRepositoryResponse response, XContentBuilder builder) throws IOException { |
| 57 | + return response.toXContent(builder, ToXContent.EMPTY_PARAMS); |
| 58 | + } |
| 59 | +} |
0 commit comments