diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/protocol/AbstractHlrcStreamableXContentTestCase.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/AbstractHlrcStreamableXContentTestCase.java similarity index 67% rename from x-pack/plugin/core/src/test/java/org/elasticsearch/protocol/AbstractHlrcStreamableXContentTestCase.java rename to client/rest-high-level/src/test/java/org/elasticsearch/client/AbstractHlrcStreamableXContentTestCase.java index d471a1a03f8..1bf78c26a37 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/protocol/AbstractHlrcStreamableXContentTestCase.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/AbstractHlrcStreamableXContentTestCase.java @@ -1,9 +1,22 @@ /* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ -package org.elasticsearch.protocol; +package org.elasticsearch.client; import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.xcontent.ToXContent; @@ -14,6 +27,11 @@ import java.io.IOException; import static org.elasticsearch.test.AbstractXContentTestCase.xContentTester; +/** + * @deprecated Use {@link AbstractResponseTestCase} instead of this class. + */ +// TODO: Remove and change subclasses to use AbstractResponseTestCase instead +@Deprecated public abstract class AbstractHlrcStreamableXContentTestCase extends AbstractStreamableXContentTestCase { diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/protocol/AbstractHlrcXContentTestCase.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/AbstractHlrcXContentTestCase.java similarity index 56% rename from x-pack/plugin/core/src/test/java/org/elasticsearch/protocol/AbstractHlrcXContentTestCase.java rename to client/rest-high-level/src/test/java/org/elasticsearch/client/AbstractHlrcXContentTestCase.java index dfe81ab79ce..62e03e6934a 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/protocol/AbstractHlrcXContentTestCase.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/AbstractHlrcXContentTestCase.java @@ -1,9 +1,22 @@ /* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ -package org.elasticsearch.protocol; +package org.elasticsearch.client; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentParser; @@ -11,6 +24,11 @@ import org.elasticsearch.test.AbstractXContentTestCase; import java.io.IOException; +/** + * @deprecated Use {@link AbstractResponseTestCase} instead of this class. + */ +// TODO: Remove and change subclasses to use AbstractResponseTestCase instead +@Deprecated public abstract class AbstractHlrcXContentTestCase extends AbstractXContentTestCase { /** diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/protocol/xpack/XPackInfoResponseTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/XPackInfoResponseTests.java similarity index 87% rename from x-pack/plugin/core/src/test/java/org/elasticsearch/protocol/xpack/XPackInfoResponseTests.java rename to client/rest-high-level/src/test/java/org/elasticsearch/client/XPackInfoResponseTests.java index 8ddc98544a8..052e700a59f 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/protocol/xpack/XPackInfoResponseTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/XPackInfoResponseTests.java @@ -1,13 +1,26 @@ /* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ -package org.elasticsearch.protocol.xpack; +package org.elasticsearch.client; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.protocol.AbstractHlrcStreamableXContentTestCase; +import org.elasticsearch.protocol.xpack.XPackInfoResponse; import org.elasticsearch.protocol.xpack.XPackInfoResponse.BuildInfo; import org.elasticsearch.protocol.xpack.XPackInfoResponse.LicenseInfo; import org.elasticsearch.protocol.xpack.XPackInfoResponse.FeatureSetsInfo; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/dataframe/transforms/hlrc/DataFrameIndexerTransformStatsHlrcTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/dataframe/transforms/hlrc/DataFrameIndexerTransformStatsTests.java similarity index 61% rename from x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/dataframe/transforms/hlrc/DataFrameIndexerTransformStatsHlrcTests.java rename to client/rest-high-level/src/test/java/org/elasticsearch/client/dataframe/transforms/hlrc/DataFrameIndexerTransformStatsTests.java index 9dd4bdbdbbd..cb4b9e42838 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/dataframe/transforms/hlrc/DataFrameIndexerTransformStatsHlrcTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/dataframe/transforms/hlrc/DataFrameIndexerTransformStatsTests.java @@ -1,19 +1,31 @@ /* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ -package org.elasticsearch.xpack.core.dataframe.transforms.hlrc; +package org.elasticsearch.client.dataframe.transforms.hlrc; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.protocol.AbstractHlrcXContentTestCase; +import org.elasticsearch.client.AbstractHlrcXContentTestCase; import org.elasticsearch.xpack.core.dataframe.transforms.DataFrameIndexerTransformStats; -import org.elasticsearch.xpack.core.dataframe.transforms.DataFrameIndexerTransformStatsTests; import java.io.IOException; -public class DataFrameIndexerTransformStatsHlrcTests extends AbstractHlrcXContentTestCase< +public class DataFrameIndexerTransformStatsTests extends AbstractHlrcXContentTestCase< DataFrameIndexerTransformStats, org.elasticsearch.client.dataframe.transforms.DataFrameIndexerTransformStats> { @@ -38,7 +50,7 @@ public class DataFrameIndexerTransformStatsHlrcTests extends AbstractHlrcXConten @Override protected DataFrameIndexerTransformStats createTestInstance() { - return DataFrameIndexerTransformStatsTests.randomStats(DataFrameIndexerTransformStats.DEFAULT_TRANSFORM_ID); + return DataFrameTransformStateTests.randomStats(DataFrameIndexerTransformStats.DEFAULT_TRANSFORM_ID); } @Override diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/dataframe/transforms/hlrc/DataFrameTransformCheckpointStatsHlrcTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/dataframe/transforms/hlrc/DataFrameTransformCheckpointStatsTests.java similarity index 58% rename from x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/dataframe/transforms/hlrc/DataFrameTransformCheckpointStatsHlrcTests.java rename to client/rest-high-level/src/test/java/org/elasticsearch/client/dataframe/transforms/hlrc/DataFrameTransformCheckpointStatsTests.java index d29cfa2784f..9762aa4ab02 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/dataframe/transforms/hlrc/DataFrameTransformCheckpointStatsHlrcTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/dataframe/transforms/hlrc/DataFrameTransformCheckpointStatsTests.java @@ -1,19 +1,31 @@ /* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ -package org.elasticsearch.xpack.core.dataframe.transforms.hlrc; +package org.elasticsearch.client.dataframe.transforms.hlrc; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.protocol.AbstractHlrcXContentTestCase; +import org.elasticsearch.client.AbstractHlrcXContentTestCase; import org.elasticsearch.xpack.core.dataframe.transforms.DataFrameTransformCheckpointStats; -import org.elasticsearch.xpack.core.dataframe.transforms.DataFrameTransformCheckpointStatsTests; import java.io.IOException; -public class DataFrameTransformCheckpointStatsHlrcTests extends AbstractHlrcXContentTestCase< +public class DataFrameTransformCheckpointStatsTests extends AbstractHlrcXContentTestCase< DataFrameTransformCheckpointStats, org.elasticsearch.client.dataframe.transforms.DataFrameTransformCheckpointStats> { @@ -36,7 +48,7 @@ public class DataFrameTransformCheckpointStatsHlrcTests extends AbstractHlrcXCon @Override protected DataFrameTransformCheckpointStats createTestInstance() { - return DataFrameTransformCheckpointStatsTests.randomDataFrameTransformCheckpointStats(); + return DataFrameTransformStateTests.randomDataFrameTransformCheckpointStats(); } @Override diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/dataframe/transforms/hlrc/DataFrameTransformCheckpointingInfoHlrcTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/dataframe/transforms/hlrc/DataFrameTransformCheckpointingInfoTests.java similarity index 54% rename from x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/dataframe/transforms/hlrc/DataFrameTransformCheckpointingInfoHlrcTests.java rename to client/rest-high-level/src/test/java/org/elasticsearch/client/dataframe/transforms/hlrc/DataFrameTransformCheckpointingInfoTests.java index 10f0bf5f2b7..a461d277c19 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/dataframe/transforms/hlrc/DataFrameTransformCheckpointingInfoHlrcTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/dataframe/transforms/hlrc/DataFrameTransformCheckpointingInfoTests.java @@ -1,27 +1,39 @@ /* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ -package org.elasticsearch.xpack.core.dataframe.transforms.hlrc; +package org.elasticsearch.client.dataframe.transforms.hlrc; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.protocol.AbstractHlrcXContentTestCase; +import org.elasticsearch.client.AbstractHlrcXContentTestCase; import org.elasticsearch.xpack.core.dataframe.transforms.DataFrameTransformCheckpointingInfo; -import org.elasticsearch.xpack.core.dataframe.transforms.DataFrameTransformCheckpointingInfoTests; import java.io.IOException; -public class DataFrameTransformCheckpointingInfoHlrcTests extends AbstractHlrcXContentTestCase< +public class DataFrameTransformCheckpointingInfoTests extends AbstractHlrcXContentTestCase< DataFrameTransformCheckpointingInfo, org.elasticsearch.client.dataframe.transforms.DataFrameTransformCheckpointingInfo> { public static DataFrameTransformCheckpointingInfo fromHlrc( org.elasticsearch.client.dataframe.transforms.DataFrameTransformCheckpointingInfo instance) { return new DataFrameTransformCheckpointingInfo( - DataFrameTransformCheckpointStatsHlrcTests.fromHlrc(instance.getCurrent()), - DataFrameTransformCheckpointStatsHlrcTests.fromHlrc(instance.getInProgress()), + DataFrameTransformCheckpointStatsTests.fromHlrc(instance.getCurrent()), + DataFrameTransformCheckpointStatsTests.fromHlrc(instance.getInProgress()), instance.getOperationsBehind()); } @@ -39,7 +51,7 @@ public class DataFrameTransformCheckpointingInfoHlrcTests extends AbstractHlrcX @Override protected DataFrameTransformCheckpointingInfo createTestInstance() { - return DataFrameTransformCheckpointingInfoTests.randomDataFrameTransformCheckpointingInfo(); + return DataFrameTransformStateTests.randomDataFrameTransformCheckpointingInfo(); } @Override @@ -52,4 +64,4 @@ public class DataFrameTransformCheckpointingInfoHlrcTests extends AbstractHlrcX return true; } -} \ No newline at end of file +} diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/dataframe/transforms/hlrc/DataFrameTransformStateAndStatsHlrcTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/dataframe/transforms/hlrc/DataFrameTransformStateAndStatsTests.java similarity index 56% rename from x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/dataframe/transforms/hlrc/DataFrameTransformStateAndStatsHlrcTests.java rename to client/rest-high-level/src/test/java/org/elasticsearch/client/dataframe/transforms/hlrc/DataFrameTransformStateAndStatsTests.java index 6ef473cfb95..ad08881fb56 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/dataframe/transforms/hlrc/DataFrameTransformStateAndStatsHlrcTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/dataframe/transforms/hlrc/DataFrameTransformStateAndStatsTests.java @@ -1,21 +1,33 @@ /* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ -package org.elasticsearch.xpack.core.dataframe.transforms.hlrc; +package org.elasticsearch.client.dataframe.transforms.hlrc; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.protocol.AbstractHlrcXContentTestCase; +import org.elasticsearch.client.AbstractHlrcXContentTestCase; import org.elasticsearch.xpack.core.dataframe.transforms.DataFrameIndexerTransformStats; import org.elasticsearch.xpack.core.dataframe.transforms.DataFrameTransformStateAndStats; -import org.elasticsearch.xpack.core.dataframe.transforms.DataFrameTransformStateAndStatsTests; import java.io.IOException; import java.util.function.Predicate; -public class DataFrameTransformStateAndStatsHlrcTests extends AbstractHlrcXContentTestCase { @Override @@ -28,15 +40,15 @@ public class DataFrameTransformStateAndStatsHlrcTests extends AbstractHlrcXConte public DataFrameTransformStateAndStats convertHlrcToInternal( org.elasticsearch.client.dataframe.transforms.DataFrameTransformStateAndStats instance) { return new DataFrameTransformStateAndStats(instance.getId(), - DataFrameTransformStateHlrcTests.fromHlrc(instance.getTransformState()), - DataFrameIndexerTransformStatsHlrcTests.fromHlrc(instance.getTransformStats()), - DataFrameTransformCheckpointingInfoHlrcTests.fromHlrc(instance.getCheckpointingInfo())); + DataFrameTransformStateTests.fromHlrc(instance.getTransformState()), + DataFrameIndexerTransformStatsTests.fromHlrc(instance.getTransformStats()), + DataFrameTransformCheckpointingInfoTests.fromHlrc(instance.getCheckpointingInfo())); } @Override protected DataFrameTransformStateAndStats createTestInstance() { // the transform id is not part of HLRC as it's only to a field for internal storage, therefore use a default id - return DataFrameTransformStateAndStatsTests + return DataFrameTransformStateTests .randomDataFrameTransformStateAndStats(DataFrameIndexerTransformStats.DEFAULT_TRANSFORM_ID); } diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/dataframe/transforms/hlrc/DataFrameTransformStateTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/dataframe/transforms/hlrc/DataFrameTransformStateTests.java new file mode 100644 index 00000000000..457c68d593e --- /dev/null +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/dataframe/transforms/hlrc/DataFrameTransformStateTests.java @@ -0,0 +1,125 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.client.dataframe.transforms.hlrc; + +import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.client.AbstractHlrcXContentTestCase; +import org.elasticsearch.xpack.core.dataframe.transforms.DataFrameIndexerTransformStats; +import org.elasticsearch.xpack.core.dataframe.transforms.DataFrameTransformCheckpointStats; +import org.elasticsearch.xpack.core.dataframe.transforms.DataFrameTransformCheckpointingInfo; +import org.elasticsearch.xpack.core.dataframe.transforms.DataFrameTransformState; +import org.elasticsearch.xpack.core.dataframe.transforms.DataFrameTransformStateAndStats; +import org.elasticsearch.xpack.core.dataframe.transforms.DataFrameTransformTaskState; +import org.elasticsearch.xpack.core.indexing.IndexerState; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.function.Predicate; + +public class DataFrameTransformStateTests extends AbstractHlrcXContentTestCase { + + public static DataFrameTransformState fromHlrc(org.elasticsearch.client.dataframe.transforms.DataFrameTransformState instance) { + return new DataFrameTransformState(DataFrameTransformTaskState.fromString(instance.getTaskState().value()), + IndexerState.fromString(instance.getIndexerState().value()), instance.getPosition(), instance.getCheckpoint(), + instance.getReason()); + } + + @Override + public org.elasticsearch.client.dataframe.transforms.DataFrameTransformState doHlrcParseInstance(XContentParser parser) + throws IOException { + return org.elasticsearch.client.dataframe.transforms.DataFrameTransformState.fromXContent(parser); + } + + @Override + public DataFrameTransformState convertHlrcToInternal(org.elasticsearch.client.dataframe.transforms.DataFrameTransformState instance) { + return fromHlrc(instance); + } + + @Override + protected DataFrameTransformState createTestInstance() { + return randomDataFrameTransformState(); + } + + @Override + protected DataFrameTransformState doParseInstance(XContentParser parser) throws IOException { + return DataFrameTransformState.fromXContent(parser); + } + + @Override + protected boolean supportsUnknownFields() { + return true; + } + + @Override + protected Predicate getRandomFieldsExcludeFilter() { + return field -> field.equals("current_position"); + } + + public static DataFrameTransformStateAndStats randomDataFrameTransformStateAndStats(String id) { + return new DataFrameTransformStateAndStats(id, + randomDataFrameTransformState(), + randomStats(id), + randomDataFrameTransformCheckpointingInfo()); + } + + public static DataFrameTransformCheckpointingInfo randomDataFrameTransformCheckpointingInfo() { + return new DataFrameTransformCheckpointingInfo(randomDataFrameTransformCheckpointStats(), + randomDataFrameTransformCheckpointStats(), randomNonNegativeLong()); + } + + public static DataFrameTransformCheckpointStats randomDataFrameTransformCheckpointStats() { + return new DataFrameTransformCheckpointStats(randomNonNegativeLong(), randomNonNegativeLong()); + } + + public static DataFrameIndexerTransformStats randomStats(String transformId) { + return new DataFrameIndexerTransformStats(transformId, randomLongBetween(10L, 10000L), + randomLongBetween(0L, 10000L), randomLongBetween(0L, 10000L), randomLongBetween(0L, 10000L), randomLongBetween(0L, 10000L), + randomLongBetween(0L, 10000L), randomLongBetween(0L, 10000L), randomLongBetween(0L, 10000L), randomLongBetween(0L, 10000L), + randomLongBetween(0L, 10000L)); + } + + public static DataFrameTransformState randomDataFrameTransformState() { + return new DataFrameTransformState(randomFrom(DataFrameTransformTaskState.values()), + randomFrom(IndexerState.values()), + randomPosition(), + randomLongBetween(0,10), + randomBoolean() ? null : randomAlphaOfLength(10)); + } + + private static Map randomPosition() { + if (randomBoolean()) { + return null; + } + int numFields = randomIntBetween(1, 5); + Map position = new HashMap<>(); + for (int i = 0; i < numFields; i++) { + Object value; + if (randomBoolean()) { + value = randomLong(); + } else { + value = randomAlphaOfLengthBetween(1, 10); + } + position.put(randomAlphaOfLengthBetween(3, 10), value); + } + return position; + } +} diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/graph/hlrc/GraphExploreResponseTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/graph/hlrc/GraphExploreResponseTests.java new file mode 100644 index 00000000000..919f85f01d8 --- /dev/null +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/graph/hlrc/GraphExploreResponseTests.java @@ -0,0 +1,222 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.elasticsearch.client.graph.hlrc; + +import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.action.ShardOperationFailedException; +import org.elasticsearch.action.search.ShardSearchFailure; +import org.elasticsearch.client.graph.Connection; +import org.elasticsearch.client.graph.GraphExploreResponse; +import org.elasticsearch.client.graph.Vertex; +import org.elasticsearch.common.xcontent.ToXContent; +import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.client.AbstractHlrcXContentTestCase; +import org.elasticsearch.protocol.xpack.graph.Connection.ConnectionId; +import org.elasticsearch.test.AbstractXContentTestCase; +import org.junit.Assert; + +import java.io.IOException; +import java.util.Arrays; +import java.util.Collection; +import java.util.Comparator; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.function.Function; +import java.util.function.Predicate; +import java.util.function.Supplier; + +import static org.hamcrest.Matchers.equalTo; + +public class GraphExploreResponseTests extends AbstractHlrcXContentTestCase< + org.elasticsearch.protocol.xpack.graph.GraphExploreResponse, + GraphExploreResponse> { + + static final Function VERTEX_ID_FUNCTION = + vId -> new org.elasticsearch.protocol.xpack.graph.Vertex.VertexId(vId.getField(), vId.getTerm()); + static final Function VERTEX_FUNCTION = + v -> new org.elasticsearch.protocol.xpack.graph.Vertex(v.getField(), v.getTerm(), v.getWeight(), + v.getHopDepth(), v.getBg(), v.getFg()); + + @Override + public GraphExploreResponse doHlrcParseInstance(XContentParser parser) throws IOException { + return GraphExploreResponse.fromXContent(parser); + } + + @Override + public org.elasticsearch.protocol.xpack.graph.GraphExploreResponse convertHlrcToInternal(GraphExploreResponse instance) { + return new org.elasticsearch.protocol.xpack.graph.GraphExploreResponse(instance.getTookInMillis(), instance.isTimedOut(), + instance.getShardFailures(), convertVertices(instance), convertConnections(instance), instance.isReturnDetailedInfo()); + } + + public Map convertVertices( + GraphExploreResponse instance) { + final Collection vertexIds = instance.getVertexIds(); + final Map vertexMap = + new LinkedHashMap<>(vertexIds.size()); + + for (Vertex.VertexId vertexId : vertexIds) { + final Vertex vertex = instance.getVertex(vertexId); + + vertexMap.put(VERTEX_ID_FUNCTION.apply(vertexId), VERTEX_FUNCTION.apply(vertex)); + } + return vertexMap; + } + + public Map convertConnections(GraphExploreResponse instance) { + final Collection connectionIds = instance.getConnectionIds(); + final Map connectionMap= new LinkedHashMap<>(connectionIds.size()); + for (Connection.ConnectionId connectionId : connectionIds) { + final Connection connection = instance.getConnection(connectionId); + final ConnectionId connectionId1 = new ConnectionId(VERTEX_ID_FUNCTION.apply(connectionId.getSource()), + VERTEX_ID_FUNCTION.apply(connectionId.getTarget())); + final org.elasticsearch.protocol.xpack.graph.Connection connection1 = new org.elasticsearch.protocol.xpack.graph.Connection( + VERTEX_FUNCTION.apply(connection.getFrom()), VERTEX_FUNCTION.apply(connection.getTo()), connection.getWeight(), + connection.getDocCount()); + connectionMap.put(connectionId1, connection1); + } + return connectionMap; + } + + @Override + protected org.elasticsearch.protocol.xpack.graph.GraphExploreResponse createTestInstance() { + return createInstance(0); + } + + private static org.elasticsearch.protocol.xpack.graph.GraphExploreResponse createInstance(int numFailures) { + int numItems = randomIntBetween(4, 128); + boolean timedOut = randomBoolean(); + boolean showDetails = randomBoolean(); + long overallTookInMillis = randomNonNegativeLong(); + Map vertices = + new HashMap<>(); + Map connections = new HashMap<>(); + ShardOperationFailedException [] failures = new ShardOperationFailedException [numFailures]; + for (int i = 0; i < failures.length; i++) { + failures[i] = new ShardSearchFailure(new ElasticsearchException("an error")); + } + + //Create random set of vertices + for (int i = 0; i < numItems; i++) { + org.elasticsearch.protocol.xpack.graph.Vertex v = new org.elasticsearch.protocol.xpack.graph.Vertex("field1", + randomAlphaOfLength(5), randomDouble(), 0, + showDetails? randomIntBetween(100, 200):0, + showDetails? randomIntBetween(1, 100):0); + vertices.put(v.getId(), v); + } + + //Wire up half the vertices randomly + org.elasticsearch.protocol.xpack.graph.Vertex[] vs = + vertices.values().toArray(new org.elasticsearch.protocol.xpack.graph.Vertex[vertices.size()]); + for (int i = 0; i < numItems/2; i++) { + org.elasticsearch.protocol.xpack.graph.Vertex v1 = vs[randomIntBetween(0, vs.length-1)]; + org.elasticsearch.protocol.xpack.graph.Vertex v2 = vs[randomIntBetween(0, vs.length-1)]; + if(v1 != v2) { + org.elasticsearch.protocol.xpack.graph.Connection conn = new org.elasticsearch.protocol.xpack.graph.Connection(v1, v2, + randomDouble(), randomLongBetween(1, 10)); + connections.put(conn.getId(), conn); + } + } + return new org.elasticsearch.protocol.xpack.graph.GraphExploreResponse(overallTookInMillis, timedOut, failures, + vertices, connections, showDetails); + } + + + private static org.elasticsearch.protocol.xpack.graph.GraphExploreResponse createTestInstanceWithFailures() { + return createInstance(randomIntBetween(1, 128)); + } + + @Override + protected org.elasticsearch.protocol.xpack.graph.GraphExploreResponse doParseInstance(XContentParser parser) throws IOException { + return org.elasticsearch.protocol.xpack.graph.GraphExploreResponse.fromXContent(parser); + } + + @Override + protected boolean supportsUnknownFields() { + return true; + } + + @Override + protected boolean assertToXContentEquivalence() { + return false; + } + + @Override + protected String[] getShuffleFieldsExceptions() { + return new String[]{"vertices", "connections"}; + } + + protected Predicate getRandomFieldsExcludeFilterWhenResultHasErrors() { + return field -> field.startsWith("responses"); + } + + @Override + protected void assertEqualInstances(org.elasticsearch.protocol.xpack.graph.GraphExploreResponse expectedInstance, + org.elasticsearch.protocol.xpack.graph.GraphExploreResponse newInstance) { + Assert.assertThat(newInstance.getTook(), equalTo(expectedInstance.getTook())); + Assert.assertThat(newInstance.isTimedOut(), equalTo(expectedInstance.isTimedOut())); + + Comparator connComparator = + Comparator.comparing(o -> o.getId().toString()); + org.elasticsearch.protocol.xpack.graph.Connection[] newConns = + newInstance.getConnections().toArray(new org.elasticsearch.protocol.xpack.graph.Connection[0]); + org.elasticsearch.protocol.xpack.graph.Connection[] expectedConns = + expectedInstance.getConnections().toArray(new org.elasticsearch.protocol.xpack.graph.Connection[0]); + Arrays.sort(newConns, connComparator); + Arrays.sort(expectedConns, connComparator); + Assert.assertArrayEquals(expectedConns, newConns); + + //Sort the vertices lists before equality test (map insertion sequences can cause order differences) + Comparator comparator = Comparator.comparing(o -> o.getId().toString()); + org.elasticsearch.protocol.xpack.graph.Vertex[] newVertices = + newInstance.getVertices().toArray(new org.elasticsearch.protocol.xpack.graph.Vertex[0]); + org.elasticsearch.protocol.xpack.graph.Vertex[] expectedVertices = + expectedInstance.getVertices().toArray(new org.elasticsearch.protocol.xpack.graph.Vertex[0]); + Arrays.sort(newVertices, comparator); + Arrays.sort(expectedVertices, comparator); + Assert.assertArrayEquals(expectedVertices, newVertices); + + ShardOperationFailedException[] newFailures = newInstance.getShardFailures(); + ShardOperationFailedException[] expectedFailures = expectedInstance.getShardFailures(); + Assert.assertEquals(expectedFailures.length, newFailures.length); + + } + + /** + * Test parsing {@link org.elasticsearch.protocol.xpack.graph.GraphExploreResponse} with inner failures as they + * don't support asserting on xcontent equivalence, given exceptions are not parsed back as the same original class. + * We run the usual {@link AbstractXContentTestCase#testFromXContent()} without failures, and this other test with + * failures where we disable asserting on xcontent equivalence at the end. + */ + public void testFromXContentWithFailures() throws IOException { + Supplier instanceSupplier = + GraphExploreResponseTests::createTestInstanceWithFailures; + //with random fields insertion in the inner exceptions, some random stuff may be parsed back as metadata, + //but that does not bother our assertions, as we only want to test that we don't break. + boolean supportsUnknownFields = true; + //exceptions are not of the same type whenever parsed back + boolean assertToXContentEquivalence = false; + AbstractXContentTestCase.testFromXContent( + AbstractXContentTestCase.NUMBER_OF_TEST_RUNS, instanceSupplier, supportsUnknownFields, getShuffleFieldsExceptions(), + getRandomFieldsExcludeFilterWhenResultHasErrors(), this::createParser, this::doParseInstance, + this::assertEqualInstances, assertToXContentEquivalence, ToXContent.EMPTY_PARAMS); + } + +} diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/protocol/xpack/license/GetBasicStatusResponseTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/license/GetBasicStatusResponseTests.java similarity index 53% rename from x-pack/plugin/core/src/test/java/org/elasticsearch/protocol/xpack/license/GetBasicStatusResponseTests.java rename to client/rest-high-level/src/test/java/org/elasticsearch/client/license/GetBasicStatusResponseTests.java index b746359d51a..fd2b6925888 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/protocol/xpack/license/GetBasicStatusResponseTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/license/GetBasicStatusResponseTests.java @@ -1,14 +1,25 @@ /* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ -package org.elasticsearch.protocol.xpack.license; +package org.elasticsearch.client.license; - -import org.elasticsearch.client.license.GetBasicStatusResponse; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.protocol.AbstractHlrcStreamableXContentTestCase; +import org.elasticsearch.client.AbstractHlrcStreamableXContentTestCase; public class GetBasicStatusResponseTests extends AbstractHlrcStreamableXContentTestCase { diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/protocol/xpack/license/GetTrialStatusResponseTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/license/GetTrialStatusResponseTests.java similarity index 53% rename from x-pack/plugin/core/src/test/java/org/elasticsearch/protocol/xpack/license/GetTrialStatusResponseTests.java rename to client/rest-high-level/src/test/java/org/elasticsearch/client/license/GetTrialStatusResponseTests.java index 504f5f83b51..36a38c40b8b 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/protocol/xpack/license/GetTrialStatusResponseTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/license/GetTrialStatusResponseTests.java @@ -1,13 +1,25 @@ /* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ -package org.elasticsearch.protocol.xpack.license; +package org.elasticsearch.client.license; -import org.elasticsearch.client.license.GetTrialStatusResponse; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.protocol.AbstractHlrcStreamableXContentTestCase; +import org.elasticsearch.client.AbstractHlrcStreamableXContentTestCase; public class GetTrialStatusResponseTests extends AbstractHlrcStreamableXContentTestCase { diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/license/LicenseStatusTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/license/LicenseStatusTests.java new file mode 100644 index 00000000000..06e90da8a87 --- /dev/null +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/license/LicenseStatusTests.java @@ -0,0 +1,38 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.elasticsearch.client.license; + +import org.elasticsearch.test.ESTestCase; + +import static org.hamcrest.CoreMatchers.equalTo; + +public class LicenseStatusTests extends ESTestCase { + + public void testCompatibility() { + final LicenseStatus[] values = LicenseStatus.values(); + final LicenseStatus[] hlrcValues = LicenseStatus.values(); + + assertThat(values.length, equalTo(hlrcValues.length)); + + for (LicenseStatus value : values) { + final LicenseStatus licenseStatus = LicenseStatus.fromString(value.label()); + assertThat(licenseStatus.label(), equalTo(value.label())); + } + } +} diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/license/PutLicenseResponseTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/license/PutLicenseResponseTests.java new file mode 100644 index 00000000000..efb7ed98b36 --- /dev/null +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/license/PutLicenseResponseTests.java @@ -0,0 +1,140 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.elasticsearch.client.license; + +import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.client.AbstractHlrcStreamableXContentTestCase; +import org.elasticsearch.protocol.xpack.license.LicensesStatus; + +import java.io.IOException; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.function.Function; +import java.util.function.Predicate; + +public class PutLicenseResponseTests extends AbstractHlrcStreamableXContentTestCase< + org.elasticsearch.protocol.xpack.license.PutLicenseResponse, org.elasticsearch.client.license.PutLicenseResponse> { + + @Override + public org.elasticsearch.client.license.PutLicenseResponse doHlrcParseInstance(XContentParser parser) throws IOException { + return org.elasticsearch.client.license.PutLicenseResponse.fromXContent(parser); + } + + @Override + public org.elasticsearch.protocol.xpack.license.PutLicenseResponse convertHlrcToInternal( + org.elasticsearch.client.license.PutLicenseResponse instance) { + return new org.elasticsearch.protocol.xpack.license.PutLicenseResponse(instance.isAcknowledged(), + org.elasticsearch.protocol.xpack.license.LicensesStatus.valueOf(instance.status().name()), + instance.acknowledgeHeader(), instance.acknowledgeMessages()); + } + + @Override + protected boolean supportsUnknownFields() { + return true; + } + + @Override + protected Predicate getRandomFieldsExcludeFilter() { + // The structure of the response is such that unknown fields inside acknowledge cannot be supported since they + // are treated as messages from new services + return p -> p.startsWith("acknowledge"); + } + + @Override + protected org.elasticsearch.protocol.xpack.license.PutLicenseResponse createTestInstance() { + boolean acknowledged = randomBoolean(); + org.elasticsearch.protocol.xpack.license.LicensesStatus status = + randomFrom(org.elasticsearch.protocol.xpack.license.LicensesStatus.VALID, + org.elasticsearch.protocol.xpack.license.LicensesStatus.INVALID, + org.elasticsearch.protocol.xpack.license.LicensesStatus.EXPIRED); + String messageHeader; + Map ackMessages; + if (randomBoolean()) { + messageHeader = randomAlphaOfLength(10); + ackMessages = randomAckMessages(); + } else { + messageHeader = null; + ackMessages = Collections.emptyMap(); + } + + return new org.elasticsearch.protocol.xpack.license.PutLicenseResponse(acknowledged, status, messageHeader, ackMessages); + } + + private static Map randomAckMessages() { + int nFeatures = randomIntBetween(1, 5); + + Map ackMessages = new HashMap<>(); + + for (int i = 0; i < nFeatures; i++) { + String feature = randomAlphaOfLengthBetween(9, 15); + int nMessages = randomIntBetween(1, 5); + String[] messages = new String[nMessages]; + for (int j = 0; j < nMessages; j++) { + messages[j] = randomAlphaOfLengthBetween(10, 30); + } + ackMessages.put(feature, messages); + } + + return ackMessages; + } + + @Override + protected org.elasticsearch.protocol.xpack.license.PutLicenseResponse createBlankInstance() { + return new org.elasticsearch.protocol.xpack.license.PutLicenseResponse(); + } + + @Override + protected org.elasticsearch.protocol.xpack.license.PutLicenseResponse mutateInstance( + org.elasticsearch.protocol.xpack.license.PutLicenseResponse response) { + @SuppressWarnings("unchecked") + Function mutator = randomFrom( + r -> new org.elasticsearch.protocol.xpack.license.PutLicenseResponse( + r.isAcknowledged() == false, + r.status(), + r.acknowledgeHeader(), + r.acknowledgeMessages()), + r -> new org.elasticsearch.protocol.xpack.license.PutLicenseResponse( + r.isAcknowledged(), + mutateStatus(r.status()), + r.acknowledgeHeader(), + r.acknowledgeMessages()), + r -> { + if (r.acknowledgeMessages().isEmpty()) { + return new org.elasticsearch.protocol.xpack.license.PutLicenseResponse( + r.isAcknowledged(), + r.status(), + randomAlphaOfLength(10), + randomAckMessages() + ); + } else { + return new org.elasticsearch.protocol.xpack.license.PutLicenseResponse(r.isAcknowledged(), r.status()); + } + } + + ); + return mutator.apply(response); + } + + private org.elasticsearch.protocol.xpack.license.LicensesStatus mutateStatus( + org.elasticsearch.protocol.xpack.license.LicensesStatus status) { + return randomValueOtherThan(status, () -> randomFrom(LicensesStatus.values())); + } +} diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/protocol/xpack/license/StartBasicResponseTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/license/StartBasicResponseTests.java similarity index 76% rename from x-pack/plugin/core/src/test/java/org/elasticsearch/protocol/xpack/license/StartBasicResponseTests.java rename to client/rest-high-level/src/test/java/org/elasticsearch/client/license/StartBasicResponseTests.java index 8f8a40f0894..69f831cff18 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/protocol/xpack/license/StartBasicResponseTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/license/StartBasicResponseTests.java @@ -1,14 +1,27 @@ /* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ -package org.elasticsearch.protocol.xpack.license; +package org.elasticsearch.client.license; import org.elasticsearch.common.Strings; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.license.PostStartBasicResponse; -import org.elasticsearch.protocol.AbstractHlrcStreamableXContentTestCase; +import org.elasticsearch.client.AbstractHlrcStreamableXContentTestCase; import java.io.IOException; import java.util.Collections; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/MlInfoActionResponseTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/ml/MlInfoActionResponseTests.java similarity index 57% rename from x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/MlInfoActionResponseTests.java rename to client/rest-high-level/src/test/java/org/elasticsearch/client/ml/MlInfoActionResponseTests.java index fe59810b595..2ffb7744a3b 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/MlInfoActionResponseTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/ml/MlInfoActionResponseTests.java @@ -1,13 +1,25 @@ /* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ -package org.elasticsearch.xpack.core.ml.action; +package org.elasticsearch.client.ml; -import org.elasticsearch.client.ml.MlInfoResponse; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.protocol.AbstractHlrcStreamableXContentTestCase; +import org.elasticsearch.client.AbstractHlrcStreamableXContentTestCase; import org.elasticsearch.xpack.core.ml.action.MlInfoAction.Response; import java.io.IOException; diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/ml/PutCalendarActionResponseTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/ml/PutCalendarActionResponseTests.java new file mode 100644 index 00000000000..fd2b019c613 --- /dev/null +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/ml/PutCalendarActionResponseTests.java @@ -0,0 +1,82 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.elasticsearch.client.ml; + +import com.carrotsearch.randomizedtesting.generators.CodepointSetGenerator; +import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.client.AbstractHlrcStreamableXContentTestCase; +import org.elasticsearch.xpack.core.ml.action.PutCalendarAction; +import org.elasticsearch.xpack.core.ml.calendars.Calendar; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +public class PutCalendarActionResponseTests + extends AbstractHlrcStreamableXContentTestCase { + + @Override + protected PutCalendarAction.Response createTestInstance() { + return new PutCalendarAction.Response(testInstance()); + } + + @Override + protected PutCalendarAction.Response doParseInstance(XContentParser parser) throws IOException { + return new PutCalendarAction.Response(Calendar.LENIENT_PARSER.parse(parser, null).build()); + } + + @Override + protected boolean supportsUnknownFields() { + return true; + } + + @Override + public PutCalendarResponse doHlrcParseInstance(XContentParser parser) throws IOException { + return PutCalendarResponse.fromXContent(parser); + } + + @Override + public PutCalendarAction.Response convertHlrcToInternal(PutCalendarResponse instance) { + org.elasticsearch.client.ml.calendars.Calendar hlrcCalendar = instance.getCalendar(); + Calendar internalCalendar = new Calendar(hlrcCalendar.getId(), hlrcCalendar.getJobIds(), hlrcCalendar.getDescription()); + return new PutCalendarAction.Response(internalCalendar); + } + + @Override + protected PutCalendarAction.Response createBlankInstance() { + return new PutCalendarAction.Response(); + } + + public static Calendar testInstance() { + return testInstance(new CodepointSetGenerator("abcdefghijklmnopqrstuvwxyz".toCharArray()).ofCodePointsLength(random(), 10, 10)); + } + + public static Calendar testInstance(String calendarId) { + int size = randomInt(10); + List items = new ArrayList<>(size); + for (int i = 0; i < size; i++) { + items.add(randomAlphaOfLengthBetween(1, 20)); + } + String description = null; + if (randomBoolean()) { + description = randomAlphaOfLength(20); + } + return new Calendar(calendarId, items, description); + } +} diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/action/user/HasPrivilegesResponseTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/security/hlrc/HasPrivilegesResponseTests.java similarity index 54% rename from x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/action/user/HasPrivilegesResponseTests.java rename to client/rest-high-level/src/test/java/org/elasticsearch/client/security/hlrc/HasPrivilegesResponseTests.java index a605917f01c..bb748a71f42 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/action/user/HasPrivilegesResponseTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/security/hlrc/HasPrivilegesResponseTests.java @@ -1,12 +1,27 @@ /* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ -package org.elasticsearch.xpack.core.security.action.user; +package org.elasticsearch.client.security.hlrc; +import org.apache.lucene.util.LuceneTestCase; import org.elasticsearch.Version; +import org.elasticsearch.client.security.HasPrivilegesResponse; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.collect.MapBuilder; import org.elasticsearch.common.io.stream.BytesStreamOutput; @@ -16,10 +31,11 @@ import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentType; -import org.elasticsearch.protocol.AbstractHlrcStreamableXContentTestCase; +import org.elasticsearch.client.AbstractHlrcStreamableXContentTestCase; import org.elasticsearch.test.VersionUtils; import org.elasticsearch.xpack.core.security.authz.permission.ResourcePrivileges; import org.hamcrest.Matchers; +import org.junit.Assert; import java.io.IOException; import java.util.ArrayList; @@ -35,32 +51,36 @@ import java.util.stream.Collectors; import static org.hamcrest.Matchers.equalTo; -public class HasPrivilegesResponseTests - extends AbstractHlrcStreamableXContentTestCase { +public class HasPrivilegesResponseTests extends AbstractHlrcStreamableXContentTestCase< + org.elasticsearch.xpack.core.security.action.user.HasPrivilegesResponse, + HasPrivilegesResponse> { public void testSerializationV64OrV65() throws IOException { - final HasPrivilegesResponse original = randomResponse(); - final Version version = VersionUtils.randomVersionBetween(random(), Version.V_6_4_0, Version.V_6_5_1); - final HasPrivilegesResponse copy = serializeAndDeserialize(original, version); + final org.elasticsearch.xpack.core.security.action.user.HasPrivilegesResponse original = randomResponse(); + final Version version = VersionUtils.randomVersionBetween(LuceneTestCase.random(), Version.V_6_4_0, Version.V_6_5_1); + final org.elasticsearch.xpack.core.security.action.user.HasPrivilegesResponse copy = serializeAndDeserialize(original, version); - assertThat(copy.isCompleteMatch(), equalTo(original.isCompleteMatch())); - assertThat(copy.getClusterPrivileges().entrySet(), Matchers.emptyIterable()); - assertThat(copy.getIndexPrivileges(), equalTo(original.getIndexPrivileges())); - assertThat(copy.getApplicationPrivileges(), equalTo(original.getApplicationPrivileges())); + Assert.assertThat(copy.isCompleteMatch(), equalTo(original.isCompleteMatch())); + Assert.assertThat(copy.getClusterPrivileges().entrySet(), Matchers.emptyIterable()); + Assert.assertThat(copy.getIndexPrivileges(), equalTo(original.getIndexPrivileges())); + Assert.assertThat(copy.getApplicationPrivileges(), equalTo(original.getApplicationPrivileges())); } public void testSerializationV63() throws IOException { - final HasPrivilegesResponse original = randomResponse(); - final HasPrivilegesResponse copy = serializeAndDeserialize(original, Version.V_6_3_0); + final org.elasticsearch.xpack.core.security.action.user.HasPrivilegesResponse original = randomResponse(); + final org.elasticsearch.xpack.core.security.action.user.HasPrivilegesResponse copy = + serializeAndDeserialize(original, Version.V_6_3_0); - assertThat(copy.isCompleteMatch(), equalTo(original.isCompleteMatch())); - assertThat(copy.getClusterPrivileges().entrySet(), Matchers.emptyIterable()); - assertThat(copy.getIndexPrivileges(), equalTo(original.getIndexPrivileges())); - assertThat(copy.getApplicationPrivileges(), equalTo(Collections.emptyMap())); + Assert.assertThat(copy.isCompleteMatch(), equalTo(original.isCompleteMatch())); + Assert.assertThat(copy.getClusterPrivileges().entrySet(), Matchers.emptyIterable()); + Assert.assertThat(copy.getIndexPrivileges(), equalTo(original.getIndexPrivileges())); + Assert.assertThat(copy.getApplicationPrivileges(), equalTo(Collections.emptyMap())); } public void testToXContent() throws Exception { - final HasPrivilegesResponse response = new HasPrivilegesResponse("daredevil", false, Collections.singletonMap("manage", true), + final org.elasticsearch.xpack.core.security.action.user.HasPrivilegesResponse response = + new org.elasticsearch.xpack.core.security.action.user.HasPrivilegesResponse("daredevil", + false, Collections.singletonMap("manage", true), Arrays.asList( ResourcePrivileges.builder("staff") .addPrivileges(MapBuilder.newMapBuilder(new LinkedHashMap<>()).put("read", true) @@ -77,7 +97,7 @@ public class HasPrivilegesResponseTests BytesReference bytes = BytesReference.bytes(builder); final String json = bytes.utf8ToString(); - assertThat(json, equalTo("{" + + Assert.assertThat(json, equalTo("{" + "\"username\":\"daredevil\"," + "\"has_all_requested\":false," + "\"cluster\":{\"manage\":true}," + @@ -96,23 +116,23 @@ public class HasPrivilegesResponseTests } @Override - protected HasPrivilegesResponse createBlankInstance() { - return new HasPrivilegesResponse(); + protected org.elasticsearch.xpack.core.security.action.user.HasPrivilegesResponse createBlankInstance() { + return new org.elasticsearch.xpack.core.security.action.user.HasPrivilegesResponse(); } @Override - protected HasPrivilegesResponse createTestInstance() { + protected org.elasticsearch.xpack.core.security.action.user.HasPrivilegesResponse createTestInstance() { return randomResponse(); } @Override - public org.elasticsearch.client.security.HasPrivilegesResponse doHlrcParseInstance(XContentParser parser) throws IOException { - return org.elasticsearch.client.security.HasPrivilegesResponse.fromXContent(parser); + public HasPrivilegesResponse doHlrcParseInstance(XContentParser parser) throws IOException { + return HasPrivilegesResponse.fromXContent(parser); } @Override - public HasPrivilegesResponse convertHlrcToInternal(org.elasticsearch.client.security.HasPrivilegesResponse hlrc) { - return new HasPrivilegesResponse( + public org.elasticsearch.xpack.core.security.action.user.HasPrivilegesResponse convertHlrcToInternal(HasPrivilegesResponse hlrc) { + return new org.elasticsearch.xpack.core.security.action.user.HasPrivilegesResponse( hlrc.getUsername(), hlrc.hasAllRequested(), hlrc.getClusterPrivileges(), @@ -128,21 +148,23 @@ public class HasPrivilegesResponseTests .collect(Collectors.toList()); } - private HasPrivilegesResponse serializeAndDeserialize(HasPrivilegesResponse original, Version version) throws IOException { + private org.elasticsearch.xpack.core.security.action.user.HasPrivilegesResponse serializeAndDeserialize( + org.elasticsearch.xpack.core.security.action.user.HasPrivilegesResponse original, Version version) throws IOException { logger.info("Test serialize/deserialize with version {}", version); final BytesStreamOutput out = new BytesStreamOutput(); out.setVersion(version); original.writeTo(out); - final HasPrivilegesResponse copy = new HasPrivilegesResponse(); + final org.elasticsearch.xpack.core.security.action.user.HasPrivilegesResponse copy = + new org.elasticsearch.xpack.core.security.action.user.HasPrivilegesResponse(); final StreamInput in = out.bytes().streamInput(); in.setVersion(version); copy.readFrom(in); - assertThat(in.read(), equalTo(-1)); + Assert.assertThat(in.read(), equalTo(-1)); return copy; } - private HasPrivilegesResponse randomResponse() { + private org.elasticsearch.xpack.core.security.action.user.HasPrivilegesResponse randomResponse() { final String username = randomAlphaOfLengthBetween(4, 12); final Map cluster = new HashMap<>(); for (String priv : randomArray(1, 6, String[]::new, () -> randomAlphaOfLengthBetween(3, 12))) { @@ -150,16 +172,19 @@ public class HasPrivilegesResponseTests } final Collection index = randomResourcePrivileges(); final Map> application = new HashMap<>(); - for (String app : randomArray(1, 3, String[]::new, () -> randomAlphaOfLengthBetween(3, 6).toLowerCase(Locale.ROOT))) { + for (String app : randomArray(1, 3, String[]::new, + () -> randomAlphaOfLengthBetween(3, 6).toLowerCase(Locale.ROOT))) { application.put(app, randomResourcePrivileges()); } - return new HasPrivilegesResponse(username, randomBoolean(), cluster, index, application); + return new org.elasticsearch.xpack.core.security.action.user.HasPrivilegesResponse(username, randomBoolean(), + cluster, index, application); } private Collection randomResourcePrivileges() { final Collection list = new ArrayList<>(); // Use hash set to force a unique set of resources - for (String resource : Sets.newHashSet(randomArray(1, 3, String[]::new, () -> randomAlphaOfLengthBetween(2, 6)))) { + for (String resource : Sets.newHashSet(randomArray(1, 3, String[]::new, + () -> randomAlphaOfLengthBetween(2, 6)))) { final Map privileges = new HashMap<>(); for (String priv : randomArray(1, 5, String[]::new, () -> randomAlphaOfLengthBetween(3, 8))) { privileges.put(priv, randomBoolean()); diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/protocol/xpack/watcher/GetWatchResponseTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/watcher/GetWatchResponseTests.java similarity index 90% rename from x-pack/plugin/core/src/test/java/org/elasticsearch/protocol/xpack/watcher/GetWatchResponseTests.java rename to client/rest-high-level/src/test/java/org/elasticsearch/client/watcher/GetWatchResponseTests.java index 9b71079a6e5..9ab115371a0 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/protocol/xpack/watcher/GetWatchResponseTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/watcher/GetWatchResponseTests.java @@ -1,10 +1,24 @@ /* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ -package org.elasticsearch.protocol.xpack.watcher; +package org.elasticsearch.client.watcher; +import org.apache.lucene.util.LuceneTestCase; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.xcontent.DeprecationHandler; import org.elasticsearch.common.xcontent.NamedXContentRegistry; @@ -14,7 +28,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentType; -import org.elasticsearch.protocol.AbstractHlrcStreamableXContentTestCase; +import org.elasticsearch.client.AbstractHlrcStreamableXContentTestCase; import org.elasticsearch.xpack.core.watcher.actions.ActionStatus; import org.elasticsearch.xpack.core.watcher.execution.ExecutionState; import org.elasticsearch.xpack.core.watcher.support.xcontent.XContentSource; @@ -90,7 +104,7 @@ public class GetWatchResponseTests extends @Override protected GetWatchResponse createTestInstance() { String id = randomAlphaOfLength(10); - if (rarely()) { + if (LuceneTestCase.rarely()) { return new GetWatchResponse(id); } long version = randomLongBetween(0, 10); @@ -128,8 +142,8 @@ public class GetWatchResponseTests extends long version = randomLongBetween(-1, Long.MAX_VALUE); WatchStatus.State state = new WatchStatus.State(randomBoolean(), nowWithMillisResolution()); ExecutionState executionState = randomFrom(ExecutionState.values()); - ZonedDateTime lastChecked = rarely() ? null : nowWithMillisResolution(); - ZonedDateTime lastMetCondition = rarely() ? null : nowWithMillisResolution(); + ZonedDateTime lastChecked = LuceneTestCase.rarely() ? null : nowWithMillisResolution(); + ZonedDateTime lastMetCondition = LuceneTestCase.rarely() ? null : nowWithMillisResolution(); int size = randomIntBetween(0, 5); Map actionMap = new HashMap<>(); for (int i = 0; i < size; i++) { diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/watcher/hlrc/DeleteWatchResponseTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/watcher/hlrc/DeleteWatchResponseTests.java new file mode 100644 index 00000000000..eebf2c9cef1 --- /dev/null +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/watcher/hlrc/DeleteWatchResponseTests.java @@ -0,0 +1,58 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.elasticsearch.client.watcher.hlrc; + +import org.elasticsearch.client.watcher.DeleteWatchResponse; +import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.client.AbstractHlrcXContentTestCase; + +import java.io.IOException; + +public class DeleteWatchResponseTests extends AbstractHlrcXContentTestCase< + org.elasticsearch.protocol.xpack.watcher.DeleteWatchResponse, DeleteWatchResponse> { + + @Override + protected org.elasticsearch.protocol.xpack.watcher.DeleteWatchResponse createTestInstance() { + String id = randomAlphaOfLength(10); + long version = randomLongBetween(1, 10); + boolean found = randomBoolean(); + return new org.elasticsearch.protocol.xpack.watcher.DeleteWatchResponse(id, version, found); + } + + @Override + protected org.elasticsearch.protocol.xpack.watcher.DeleteWatchResponse doParseInstance(XContentParser parser) throws IOException { + return org.elasticsearch.protocol.xpack.watcher.DeleteWatchResponse.fromXContent(parser); + } + + @Override + public DeleteWatchResponse doHlrcParseInstance(XContentParser parser) throws IOException { + return DeleteWatchResponse.fromXContent(parser); + } + + @Override + public org.elasticsearch.protocol.xpack.watcher.DeleteWatchResponse convertHlrcToInternal(DeleteWatchResponse instance) { + return new org.elasticsearch.protocol.xpack.watcher.DeleteWatchResponse(instance.getId(), instance.getVersion(), + instance.isFound()); + } + + @Override + protected boolean supportsUnknownFields() { + return false; + } +} diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/protocol/xpack/watcher/ExecuteWatchResponseTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/watcher/hlrc/ExecuteWatchResponseTests.java similarity index 71% rename from x-pack/plugin/core/src/test/java/org/elasticsearch/protocol/xpack/watcher/ExecuteWatchResponseTests.java rename to client/rest-high-level/src/test/java/org/elasticsearch/client/watcher/hlrc/ExecuteWatchResponseTests.java index 47fd4a33dc9..ace75517a93 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/protocol/xpack/watcher/ExecuteWatchResponseTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/watcher/hlrc/ExecuteWatchResponseTests.java @@ -1,17 +1,30 @@ /* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ -package org.elasticsearch.protocol.xpack.watcher; +package org.elasticsearch.client.watcher.hlrc; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentType; -import org.elasticsearch.protocol.AbstractHlrcXContentTestCase; +import org.elasticsearch.client.AbstractHlrcXContentTestCase; import org.elasticsearch.xpack.core.watcher.transport.actions.execute.ExecuteWatchResponse; import java.io.IOException; diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/watcher/hlrc/PutWatchResponseTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/watcher/hlrc/PutWatchResponseTests.java new file mode 100644 index 00000000000..9b65618cafc --- /dev/null +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/watcher/hlrc/PutWatchResponseTests.java @@ -0,0 +1,60 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.elasticsearch.client.watcher.hlrc; + +import org.elasticsearch.client.watcher.PutWatchResponse; +import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.client.AbstractHlrcXContentTestCase; + +import java.io.IOException; + +public class PutWatchResponseTests extends AbstractHlrcXContentTestCase< + org.elasticsearch.protocol.xpack.watcher.PutWatchResponse, PutWatchResponse> { + + @Override + protected org.elasticsearch.protocol.xpack.watcher.PutWatchResponse createTestInstance() { + String id = randomAlphaOfLength(10); + long seqNo = randomNonNegativeLong(); + long primaryTerm = randomLongBetween(1, 20); + long version = randomLongBetween(1, 10); + boolean created = randomBoolean(); + return new org.elasticsearch.protocol.xpack.watcher.PutWatchResponse(id, version, seqNo, primaryTerm, created); + } + + @Override + protected org.elasticsearch.protocol.xpack.watcher.PutWatchResponse doParseInstance(XContentParser parser) throws IOException { + return org.elasticsearch.protocol.xpack.watcher.PutWatchResponse.fromXContent(parser); + } + + @Override + public PutWatchResponse doHlrcParseInstance(XContentParser parser) throws IOException { + return org.elasticsearch.client.watcher.PutWatchResponse.fromXContent(parser); + } + + @Override + public org.elasticsearch.protocol.xpack.watcher.PutWatchResponse convertHlrcToInternal(PutWatchResponse instance) { + return new org.elasticsearch.protocol.xpack.watcher.PutWatchResponse(instance.getId(), instance.getVersion(), + instance.getSeqNo(), instance.getPrimaryTerm(), instance.isCreated()); + } + + @Override + protected boolean supportsUnknownFields() { + return false; + } +} diff --git a/x-pack/plugin/core/build.gradle b/x-pack/plugin/core/build.gradle index 337bd26f37d..a25c53506fb 100644 --- a/x-pack/plugin/core/build.gradle +++ b/x-pack/plugin/core/build.gradle @@ -46,11 +46,11 @@ dependencies { testCompile "org.slf4j:slf4j-api:${versions.slf4j}" testCompile project(path: ':modules:reindex', configuration: 'runtime') testCompile project(path: ':modules:parent-join', configuration: 'runtime') + testCompile project(path: ':modules:lang-mustache', configuration: 'runtime') testCompile project(path: ':modules:analysis-common', configuration: 'runtime') testCompile(project(':x-pack:license-tools')) { transitive = false } - testCompile ("org.elasticsearch.client:elasticsearch-rest-high-level-client:${version}") } ext.expansions = [ diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/protocol/xpack/graph/GraphExploreResponseTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/protocol/xpack/graph/GraphExploreResponseTests.java deleted file mode 100644 index 3235f62b3e4..00000000000 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/protocol/xpack/graph/GraphExploreResponseTests.java +++ /dev/null @@ -1,197 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ -package org.elasticsearch.protocol.xpack.graph; - -import org.elasticsearch.ElasticsearchException; -import org.elasticsearch.action.ShardOperationFailedException; -import org.elasticsearch.action.search.ShardSearchFailure; -import org.elasticsearch.common.xcontent.ToXContent; -import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.protocol.AbstractHlrcXContentTestCase; -import org.elasticsearch.test.AbstractXContentTestCase; - -import java.io.IOException; -import java.util.Arrays; -import java.util.Collection; -import java.util.Comparator; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.function.Function; -import java.util.function.Predicate; -import java.util.function.Supplier; - -import static org.hamcrest.Matchers.equalTo; - -public class GraphExploreResponseTests extends - AbstractHlrcXContentTestCase { - - static final Function VERTEX_ID_FUNCTION = - vId -> new Vertex.VertexId(vId.getField(), vId.getTerm()); - static final Function VERTEX_FUNCTION = - v -> new Vertex(v.getField(), v.getTerm(), v.getWeight(), v.getHopDepth(), v.getBg(), v.getFg()); - - @Override - public org.elasticsearch.client.graph.GraphExploreResponse doHlrcParseInstance(XContentParser parser) throws IOException { - return org.elasticsearch.client.graph.GraphExploreResponse.fromXContent(parser); - } - - @Override - public GraphExploreResponse convertHlrcToInternal(org.elasticsearch.client.graph.GraphExploreResponse instance) { - return new GraphExploreResponse(instance.getTookInMillis(), instance.isTimedOut(), - instance.getShardFailures(), convertVertices(instance), convertConnections(instance), instance.isReturnDetailedInfo()); - } - - public Map convertVertices(org.elasticsearch.client.graph.GraphExploreResponse instance) { - final Collection vertexIds = instance.getVertexIds(); - final Map vertexMap = new LinkedHashMap<>(vertexIds.size()); - - for (org.elasticsearch.client.graph.Vertex.VertexId vertexId : vertexIds) { - final org.elasticsearch.client.graph.Vertex vertex = instance.getVertex(vertexId); - - vertexMap.put(VERTEX_ID_FUNCTION.apply(vertexId), VERTEX_FUNCTION.apply(vertex)); - } - return vertexMap; - } - - public Map convertConnections(org.elasticsearch.client.graph.GraphExploreResponse instance) { - final Collection connectionIds = instance.getConnectionIds(); - final Map connectionMap = new LinkedHashMap<>(connectionIds.size()); - for (org.elasticsearch.client.graph.Connection.ConnectionId connectionId : connectionIds) { - final org.elasticsearch.client.graph.Connection connection = instance.getConnection(connectionId); - final Connection.ConnectionId connectionId1 = - new Connection.ConnectionId(VERTEX_ID_FUNCTION.apply(connectionId.getSource()), - VERTEX_ID_FUNCTION.apply(connectionId.getTarget())); - final Connection connection1 = new Connection(VERTEX_FUNCTION.apply(connection.getFrom()), - VERTEX_FUNCTION.apply(connection.getTo()), - connection.getWeight(), connection.getDocCount()); - connectionMap.put(connectionId1, connection1); - } - return connectionMap; - } - - @Override - protected GraphExploreResponse createTestInstance() { - return createInstance(0); - } - - private static GraphExploreResponse createInstance(int numFailures) { - int numItems = randomIntBetween(4, 128); - boolean timedOut = randomBoolean(); - boolean showDetails = randomBoolean(); - long overallTookInMillis = randomNonNegativeLong(); - Map vertices = new HashMap<>(); - Map connections = new HashMap<>(); - ShardOperationFailedException [] failures = new ShardOperationFailedException [numFailures]; - for (int i = 0; i < failures.length; i++) { - failures[i] = new ShardSearchFailure(new ElasticsearchException("an error")); - } - - //Create random set of vertices - for (int i = 0; i < numItems; i++) { - Vertex v = new Vertex("field1", randomAlphaOfLength(5), randomDouble(), 0, - showDetails?randomIntBetween(100, 200):0, - showDetails?randomIntBetween(1, 100):0); - vertices.put(v.getId(), v); - } - - //Wire up half the vertices randomly - Vertex[] vs = vertices.values().toArray(new Vertex[vertices.size()]); - for (int i = 0; i < numItems/2; i++) { - Vertex v1 = vs[randomIntBetween(0, vs.length-1)]; - Vertex v2 = vs[randomIntBetween(0, vs.length-1)]; - if(v1 != v2) { - Connection conn = new Connection(v1, v2, randomDouble(), randomLongBetween(1, 10)); - connections.put(conn.getId(), conn); - } - } - return new GraphExploreResponse(overallTookInMillis, timedOut, failures, vertices, connections, showDetails); - } - - - private static GraphExploreResponse createTestInstanceWithFailures() { - return createInstance(randomIntBetween(1, 128)); - } - - @Override - protected GraphExploreResponse doParseInstance(XContentParser parser) throws IOException { - return GraphExploreResponse.fromXContent(parser); - } - - @Override - protected boolean supportsUnknownFields() { - return true; - } - - @Override - protected boolean assertToXContentEquivalence() { - return false; - } - - @Override - protected String[] getShuffleFieldsExceptions() { - return new String[]{"vertices", "connections"}; - } - - protected Predicate getRandomFieldsExcludeFilterWhenResultHasErrors() { - return field -> field.startsWith("responses"); - } - - @Override - protected void assertEqualInstances( GraphExploreResponse expectedInstance, GraphExploreResponse newInstance) { - assertThat(newInstance.getTook(), equalTo(expectedInstance.getTook())); - assertThat(newInstance.isTimedOut(), equalTo(expectedInstance.isTimedOut())); - - Comparator connComparator = new Comparator() { - @Override - public int compare(Connection o1, Connection o2) { - return o1.getId().toString().compareTo(o2.getId().toString()); - } - }; - Connection[] newConns = newInstance.getConnections().toArray(new Connection[0]); - Connection[] expectedConns = expectedInstance.getConnections().toArray(new Connection[0]); - Arrays.sort(newConns, connComparator); - Arrays.sort(expectedConns, connComparator); - assertArrayEquals(expectedConns, newConns); - - //Sort the vertices lists before equality test (map insertion sequences can cause order differences) - Comparator comparator = new Comparator() { - @Override - public int compare(Vertex o1, Vertex o2) { - return o1.getId().toString().compareTo(o2.getId().toString()); - } - }; - Vertex[] newVertices = newInstance.getVertices().toArray(new Vertex[0]); - Vertex[] expectedVertices = expectedInstance.getVertices().toArray(new Vertex[0]); - Arrays.sort(newVertices, comparator); - Arrays.sort(expectedVertices, comparator); - assertArrayEquals(expectedVertices, newVertices); - - ShardOperationFailedException[] newFailures = newInstance.getShardFailures(); - ShardOperationFailedException[] expectedFailures = expectedInstance.getShardFailures(); - assertEquals(expectedFailures.length, newFailures.length); - - } - - /** - * Test parsing {@link GraphExploreResponse} with inner failures as they don't support asserting on xcontent equivalence, given - * exceptions are not parsed back as the same original class. We run the usual {@link AbstractXContentTestCase#testFromXContent()} - * without failures, and this other test with failures where we disable asserting on xcontent equivalence at the end. - */ - public void testFromXContentWithFailures() throws IOException { - Supplier< GraphExploreResponse> instanceSupplier = GraphExploreResponseTests::createTestInstanceWithFailures; - //with random fields insertion in the inner exceptions, some random stuff may be parsed back as metadata, - //but that does not bother our assertions, as we only want to test that we don't break. - boolean supportsUnknownFields = true; - //exceptions are not of the same type whenever parsed back - boolean assertToXContentEquivalence = false; - AbstractXContentTestCase.testFromXContent( - NUMBER_OF_TEST_RUNS, instanceSupplier, supportsUnknownFields, getShuffleFieldsExceptions(), - getRandomFieldsExcludeFilterWhenResultHasErrors(), this::createParser, this::doParseInstance, - this::assertEqualInstances, assertToXContentEquivalence, ToXContent.EMPTY_PARAMS); - } - -} diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/protocol/xpack/license/LicenseStatusTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/protocol/xpack/license/LicenseStatusTests.java index 0b73850c5e6..a0649d1e7f4 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/protocol/xpack/license/LicenseStatusTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/protocol/xpack/license/LicenseStatusTests.java @@ -9,25 +9,10 @@ import java.io.IOException; import org.elasticsearch.test.ESTestCase; -import static org.hamcrest.CoreMatchers.equalTo; - public class LicenseStatusTests extends ESTestCase { public void testSerialization() throws IOException { LicenseStatus status = randomFrom(LicenseStatus.values()); assertSame(status, copyWriteable(status, writableRegistry(), LicenseStatus::readFrom)); } - public void testCompatibility() { - final LicenseStatus[] values = LicenseStatus.values(); - final org.elasticsearch.client.license.LicenseStatus[] hlrcValues = - org.elasticsearch.client.license.LicenseStatus.values(); - - assertThat(values.length, equalTo(hlrcValues.length)); - - for (LicenseStatus value : values) { - final org.elasticsearch.client.license.LicenseStatus licenseStatus = - org.elasticsearch.client.license.LicenseStatus.fromString(value.label()); - assertThat(licenseStatus.label(), equalTo(value.label())); - } - } } diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/protocol/xpack/license/PutLicenseResponseTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/protocol/xpack/license/PutLicenseResponseTests.java deleted file mode 100644 index 4480d925bed..00000000000 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/protocol/xpack/license/PutLicenseResponseTests.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ -package org.elasticsearch.protocol.xpack.license; - -import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.protocol.AbstractHlrcStreamableXContentTestCase; - -import java.io.IOException; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.function.Function; -import java.util.function.Predicate; - -public class PutLicenseResponseTests extends - AbstractHlrcStreamableXContentTestCase { - - @Override - public org.elasticsearch.client.license.PutLicenseResponse doHlrcParseInstance(XContentParser parser) throws IOException { - return org.elasticsearch.client.license.PutLicenseResponse.fromXContent(parser); - } - - @Override - public PutLicenseResponse convertHlrcToInternal(org.elasticsearch.client.license.PutLicenseResponse instance) { - return new PutLicenseResponse(instance.isAcknowledged(), LicensesStatus.valueOf(instance.status().name()), - instance.acknowledgeHeader(), instance.acknowledgeMessages()); - } - - @Override - protected boolean supportsUnknownFields() { - return true; - } - - @Override - protected Predicate getRandomFieldsExcludeFilter() { - // The structure of the response is such that unknown fields inside acknowledge cannot be supported since they - // are treated as messages from new services - return p -> p.startsWith("acknowledge"); - } - - @Override - protected PutLicenseResponse createTestInstance() { - boolean acknowledged = randomBoolean(); - LicensesStatus status = randomFrom(LicensesStatus.VALID, LicensesStatus.INVALID, LicensesStatus.EXPIRED); - String messageHeader; - Map ackMessages; - if (randomBoolean()) { - messageHeader = randomAlphaOfLength(10); - ackMessages = randomAckMessages(); - } else { - messageHeader = null; - ackMessages = Collections.emptyMap(); - } - - return new PutLicenseResponse(acknowledged, status, messageHeader, ackMessages); - } - - private static Map randomAckMessages() { - int nFeatures = randomIntBetween(1, 5); - - Map ackMessages = new HashMap<>(); - - for (int i = 0; i < nFeatures; i++) { - String feature = randomAlphaOfLengthBetween(9, 15); - int nMessages = randomIntBetween(1, 5); - String[] messages = new String[nMessages]; - for (int j = 0; j < nMessages; j++) { - messages[j] = randomAlphaOfLengthBetween(10, 30); - } - ackMessages.put(feature, messages); - } - - return ackMessages; - } - - @Override - protected PutLicenseResponse createBlankInstance() { - return new PutLicenseResponse(); - } - - @Override - protected PutLicenseResponse mutateInstance(PutLicenseResponse response) { - @SuppressWarnings("unchecked") - Function mutator = randomFrom( - r -> new PutLicenseResponse( - r.isAcknowledged() == false, - r.status(), - r.acknowledgeHeader(), - r.acknowledgeMessages()), - r -> new PutLicenseResponse( - r.isAcknowledged(), - mutateStatus(r.status()), - r.acknowledgeHeader(), - r.acknowledgeMessages()), - r -> { - if (r.acknowledgeMessages().isEmpty()) { - return new PutLicenseResponse( - r.isAcknowledged(), - r.status(), - randomAlphaOfLength(10), - randomAckMessages() - ); - } else { - return new PutLicenseResponse(r.isAcknowledged(), r.status()); - } - } - - ); - return mutator.apply(response); - } - - private LicensesStatus mutateStatus(LicensesStatus status) { - return randomValueOtherThan(status, () -> randomFrom(LicensesStatus.values())); - } -} diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/protocol/xpack/watcher/DeleteWatchResponseTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/protocol/xpack/watcher/DeleteWatchResponseTests.java deleted file mode 100644 index 7486252f538..00000000000 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/protocol/xpack/watcher/DeleteWatchResponseTests.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ -package org.elasticsearch.protocol.xpack.watcher; - -import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.protocol.AbstractHlrcXContentTestCase; - -import java.io.IOException; - -public class DeleteWatchResponseTests extends - AbstractHlrcXContentTestCase { - - @Override - protected DeleteWatchResponse createTestInstance() { - String id = randomAlphaOfLength(10); - long version = randomLongBetween(1, 10); - boolean found = randomBoolean(); - return new DeleteWatchResponse(id, version, found); - } - - @Override - protected DeleteWatchResponse doParseInstance(XContentParser parser) throws IOException { - return DeleteWatchResponse.fromXContent(parser); - } - - @Override - public org.elasticsearch.client.watcher.DeleteWatchResponse doHlrcParseInstance(XContentParser parser) throws IOException { - return org.elasticsearch.client.watcher.DeleteWatchResponse.fromXContent(parser); - } - - @Override - public DeleteWatchResponse convertHlrcToInternal(org.elasticsearch.client.watcher.DeleteWatchResponse instance) { - return new DeleteWatchResponse(instance.getId(), instance.getVersion(), instance.isFound()); - } - - @Override - protected boolean supportsUnknownFields() { - return false; - } -} diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/protocol/xpack/watcher/PutWatchResponseTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/protocol/xpack/watcher/PutWatchResponseTests.java deleted file mode 100644 index 975d842b795..00000000000 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/protocol/xpack/watcher/PutWatchResponseTests.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ -package org.elasticsearch.protocol.xpack.watcher; - -import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.protocol.AbstractHlrcXContentTestCase; - -import java.io.IOException; - -public class PutWatchResponseTests extends - AbstractHlrcXContentTestCase { - - @Override - protected PutWatchResponse createTestInstance() { - String id = randomAlphaOfLength(10); - long seqNo = randomNonNegativeLong(); - long primaryTerm = randomLongBetween(1, 20); - long version = randomLongBetween(1, 10); - boolean created = randomBoolean(); - return new PutWatchResponse(id, version, seqNo, primaryTerm, created); - } - - @Override - protected PutWatchResponse doParseInstance(XContentParser parser) throws IOException { - return PutWatchResponse.fromXContent(parser); - } - - @Override - public org.elasticsearch.client.watcher.PutWatchResponse doHlrcParseInstance(XContentParser parser) throws IOException { - return org.elasticsearch.client.watcher.PutWatchResponse.fromXContent(parser); - } - - @Override - public PutWatchResponse convertHlrcToInternal(org.elasticsearch.client.watcher.PutWatchResponse instance) { - return new PutWatchResponse(instance.getId(), instance.getVersion(), instance.getSeqNo(), instance.getPrimaryTerm(), - instance.isCreated()); - } - - @Override - protected boolean supportsUnknownFields() { - return false; - } -} diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/dataframe/transforms/hlrc/DataFrameTransformStateHlrcTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/dataframe/transforms/hlrc/DataFrameTransformStateHlrcTests.java deleted file mode 100644 index 5b2fa6ec33d..00000000000 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/dataframe/transforms/hlrc/DataFrameTransformStateHlrcTests.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -package org.elasticsearch.xpack.core.dataframe.transforms.hlrc; - -import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.protocol.AbstractHlrcXContentTestCase; -import org.elasticsearch.xpack.core.dataframe.transforms.DataFrameTransformState; -import org.elasticsearch.xpack.core.dataframe.transforms.DataFrameTransformStateTests; -import org.elasticsearch.xpack.core.dataframe.transforms.DataFrameTransformTaskState; -import org.elasticsearch.xpack.core.indexing.IndexerState; - -import java.io.IOException; -import java.util.function.Predicate; - -public class DataFrameTransformStateHlrcTests extends AbstractHlrcXContentTestCase { - - public static DataFrameTransformState fromHlrc(org.elasticsearch.client.dataframe.transforms.DataFrameTransformState instance) { - return new DataFrameTransformState(DataFrameTransformTaskState.fromString(instance.getTaskState().value()), - IndexerState.fromString(instance.getIndexerState().value()), instance.getPosition(), instance.getCheckpoint(), - instance.getReason()); - } - - @Override - public org.elasticsearch.client.dataframe.transforms.DataFrameTransformState doHlrcParseInstance(XContentParser parser) - throws IOException { - return org.elasticsearch.client.dataframe.transforms.DataFrameTransformState.fromXContent(parser); - } - - @Override - public DataFrameTransformState convertHlrcToInternal(org.elasticsearch.client.dataframe.transforms.DataFrameTransformState instance) { - return fromHlrc(instance); - } - - @Override - protected DataFrameTransformState createTestInstance() { - return DataFrameTransformStateTests.randomDataFrameTransformState(); - } - - @Override - protected DataFrameTransformState doParseInstance(XContentParser parser) throws IOException { - return DataFrameTransformState.fromXContent(parser); - } - - @Override - protected boolean supportsUnknownFields() { - return true; - } - - @Override - protected Predicate getRandomFieldsExcludeFilter() { - return field -> field.equals("current_position"); - } -} diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/PutCalendarActionResponseTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/PutCalendarActionResponseTests.java deleted file mode 100644 index 7f486698231..00000000000 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/PutCalendarActionResponseTests.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ -package org.elasticsearch.xpack.core.ml.action; - -import org.elasticsearch.client.ml.PutCalendarResponse; -import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.protocol.AbstractHlrcStreamableXContentTestCase; -import org.elasticsearch.xpack.core.ml.calendars.Calendar; -import org.elasticsearch.xpack.core.ml.calendars.CalendarTests; - -import java.io.IOException; - -public class PutCalendarActionResponseTests - extends AbstractHlrcStreamableXContentTestCase { - - @Override - protected PutCalendarAction.Response createTestInstance() { - return new PutCalendarAction.Response(CalendarTests.testInstance()); - } - - @Override - protected PutCalendarAction.Response doParseInstance(XContentParser parser) throws IOException { - return new PutCalendarAction.Response(Calendar.LENIENT_PARSER.parse(parser, null).build()); - } - - @Override - protected boolean supportsUnknownFields() { - return true; - } - - @Override - public PutCalendarResponse doHlrcParseInstance(XContentParser parser) throws IOException { - return PutCalendarResponse.fromXContent(parser); - } - - @Override - public PutCalendarAction.Response convertHlrcToInternal(PutCalendarResponse instance) { - org.elasticsearch.client.ml.calendars.Calendar hlrcCalendar = instance.getCalendar(); - Calendar internalCalendar = new Calendar(hlrcCalendar.getId(), hlrcCalendar.getJobIds(), hlrcCalendar.getDescription()); - return new PutCalendarAction.Response(internalCalendar); - } - - @Override - protected PutCalendarAction.Response createBlankInstance() { - return new PutCalendarAction.Response(); - } -} diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/authz/permission/LimitedRoleTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/authz/permission/LimitedRoleTests.java index 56807d23913..121f40c44d9 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/authz/permission/LimitedRoleTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/authz/permission/LimitedRoleTests.java @@ -10,7 +10,6 @@ import org.elasticsearch.Version; import org.elasticsearch.action.admin.indices.create.CreateIndexAction; import org.elasticsearch.action.admin.indices.delete.DeleteIndexAction; import org.elasticsearch.action.search.SearchAction; -import org.elasticsearch.client.security.user.privileges.Role.ClusterPrivilegeName; import org.elasticsearch.cluster.metadata.AliasMetaData; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.MetaData; @@ -66,7 +65,7 @@ public class LimitedRoleTests extends ESTestCase { .putAlias(AliasMetaData.builder("_alias1")); MetaData md = MetaData.builder().put(imbBuilder).put(imbBuilder1).build(); FieldPermissionsCache fieldPermissionsCache = new FieldPermissionsCache(Settings.EMPTY); - Role fromRole = Role.builder("a-role").cluster(Collections.singleton(ClusterPrivilegeName.MANAGE_SECURITY), Collections.emptyList()) + Role fromRole = Role.builder("a-role").cluster(Collections.singleton("manage_security"), Collections.emptyList()) .add(IndexPrivilege.ALL, "_index").add(IndexPrivilege.CREATE_INDEX, "_index1").build(); IndicesAccessControl iac = fromRole.authorize(SearchAction.NAME, Sets.newHashSet("_index", "_alias1"), md.getAliasAndIndexLookup(), @@ -84,7 +83,7 @@ public class LimitedRoleTests extends ESTestCase { { Role limitedByRole = Role.builder("limited-role") - .cluster(Collections.singleton(ClusterPrivilegeName.ALL), Collections.emptyList()).add(IndexPrivilege.READ, "_index") + .cluster(Collections.singleton("all"), Collections.emptyList()).add(IndexPrivilege.READ, "_index") .add(IndexPrivilege.NONE, "_index1").build(); iac = limitedByRole.authorize(SearchAction.NAME, Sets.newHashSet("_index", "_alias1"), md.getAliasAndIndexLookup(), fieldPermissionsCache); @@ -128,12 +127,12 @@ public class LimitedRoleTests extends ESTestCase { } public void testCheckClusterAction() { - Role fromRole = Role.builder("a-role").cluster(Collections.singleton(ClusterPrivilegeName.MANAGE_SECURITY), Collections.emptyList()) + Role fromRole = Role.builder("a-role").cluster(Collections.singleton("manage_security"), Collections.emptyList()) .build(); assertThat(fromRole.checkClusterAction("cluster:admin/xpack/security/x", mock(TransportRequest.class)), is(true)); { Role limitedByRole = Role.builder("limited-role") - .cluster(Collections.singleton(ClusterPrivilegeName.ALL), Collections.emptyList()).build(); + .cluster(Collections.singleton("all"), Collections.emptyList()).build(); assertThat(limitedByRole.checkClusterAction("cluster:admin/xpack/security/x", mock(TransportRequest.class)), is(true)); assertThat(limitedByRole.checkClusterAction("cluster:other-action", mock(TransportRequest.class)), is(true)); Role role = LimitedRole.createLimitedRole(fromRole, limitedByRole); @@ -142,7 +141,7 @@ public class LimitedRoleTests extends ESTestCase { } { Role limitedByRole = Role.builder("limited-role") - .cluster(Collections.singleton(ClusterPrivilegeName.MONITOR), Collections.emptyList()).build(); + .cluster(Collections.singleton("monitor"), Collections.emptyList()).build(); assertThat(limitedByRole.checkClusterAction("cluster:monitor/me", mock(TransportRequest.class)), is(true)); Role role = LimitedRole.createLimitedRole(fromRole, limitedByRole); assertThat(role.checkClusterAction("cluster:monitor/me", mock(TransportRequest.class)), is(false)); @@ -199,14 +198,14 @@ public class LimitedRoleTests extends ESTestCase { } public void testCheckClusterPrivilege() { - Role fromRole = Role.builder("a-role").cluster(Collections.singleton(ClusterPrivilegeName.MANAGE_SECURITY), Collections.emptyList()) + Role fromRole = Role.builder("a-role").cluster(Collections.singleton("manage_security"), Collections.emptyList()) .build(); assertThat(fromRole.grants(ClusterPrivilege.ALL), is(false)); assertThat(fromRole.grants(ClusterPrivilege.MANAGE_SECURITY), is(true)); { Role limitedByRole = Role.builder("scoped-role") - .cluster(Collections.singleton(ClusterPrivilegeName.ALL), Collections.emptyList()).build(); + .cluster(Collections.singleton("all"), Collections.emptyList()).build(); assertThat(limitedByRole.grants(ClusterPrivilege.ALL), is(true)); assertThat(limitedByRole.grants(ClusterPrivilege.MANAGE_SECURITY), is(true)); Role role = LimitedRole.createLimitedRole(fromRole, limitedByRole); @@ -215,7 +214,7 @@ public class LimitedRoleTests extends ESTestCase { } { Role limitedByRole = Role.builder("scoped-role") - .cluster(Collections.singleton(ClusterPrivilegeName.MONITOR), Collections.emptyList()).build(); + .cluster(Collections.singleton("monitor"), Collections.emptyList()).build(); assertThat(limitedByRole.grants(ClusterPrivilege.ALL), is(false)); assertThat(limitedByRole.grants(ClusterPrivilege.MONITOR), is(true)); Role role = LimitedRole.createLimitedRole(fromRole, limitedByRole); diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/store/CompositeRolesStoreTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/store/CompositeRolesStoreTests.java index 2278f27a6df..ba2ba455a50 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/store/CompositeRolesStoreTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/store/CompositeRolesStoreTests.java @@ -12,7 +12,6 @@ import org.elasticsearch.action.admin.cluster.state.ClusterStateAction; import org.elasticsearch.action.get.GetAction; import org.elasticsearch.action.index.IndexAction; import org.elasticsearch.action.support.PlainActionFuture; -import org.elasticsearch.client.security.user.privileges.Role.ClusterPrivilegeName; import org.elasticsearch.cluster.health.ClusterHealthStatus; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.MetaData; @@ -1049,9 +1048,9 @@ public class CompositeRolesStoreTests extends ESTestCase { doAnswer(invocationOnMock -> { ActionListener listener = (ActionListener) invocationOnMock.getArguments()[1]; listener.onResponse(new ApiKeyRoleDescriptors("keyId", - Collections.singletonList(new RoleDescriptor("a-role", new String[] { ClusterPrivilegeName.ALL }, null, null)), + Collections.singletonList(new RoleDescriptor("a-role", new String[] {"all"}, null, null)), Collections.singletonList( - new RoleDescriptor("scoped-role", new String[] { ClusterPrivilegeName.MANAGE_SECURITY }, null, null)))); + new RoleDescriptor("scoped-role", new String[] {"manage_security"}, null, null)))); return Void.TYPE; }).when(apiKeyService).getRoleForApiKey(eq(authentication), any(ActionListener.class)); diff --git a/x-pack/qa/rolling-upgrade/build.gradle b/x-pack/qa/rolling-upgrade/build.gradle index ba9e1ae2ff9..a29cbe00ffd 100644 --- a/x-pack/qa/rolling-upgrade/build.gradle +++ b/x-pack/qa/rolling-upgrade/build.gradle @@ -14,6 +14,7 @@ dependencies { testCompile project(path: xpackModule('core'), configuration: 'default') testCompile project(path: xpackModule('security'), configuration: 'runtime') testCompile project(path: xpackModule('core'), configuration: 'testArtifacts') // to be moved in a later commit + testCompile ("org.elasticsearch.client:elasticsearch-rest-high-level-client:${version}") } Closure waitWithAuth = { NodeInfo node, AntBuilder ant ->