forked from opensearch-project/OpenSearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Peter Nied <[email protected]>
- Loading branch information
Showing
1 changed file
with
97 additions
and
0 deletions.
There are no files selected for viewing
97 changes: 97 additions & 0 deletions
97
server/src/test/java/org/opensearch/cluster/metadata/ViewTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
/* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
package org.opensearch.cluster.metadata; | ||
|
||
import org.opensearch.cluster.metadata.View.Target; | ||
import org.opensearch.common.UUIDs; | ||
import org.opensearch.core.common.io.stream.Writeable; | ||
import org.opensearch.core.index.Index; | ||
import org.opensearch.core.xcontent.XContentParser; | ||
import org.opensearch.test.AbstractSerializingTestCase; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Locale; | ||
|
||
import static org.opensearch.cluster.DataStreamTestHelper.createTimestampField; | ||
import static org.opensearch.cluster.metadata.DataStream.getDefaultBackingIndexName; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.empty; | ||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
public class ViewTests extends AbstractSerializingTestCase<View> { | ||
|
||
private static List<Target> randomTargets() { | ||
int numTargets = randomIntBetween(0, 128); | ||
List<Target> targets = new ArrayList<>(numTargets); | ||
for (int i = 0; i < numTargets; i++) { | ||
targets.add(new Target(randomAlphaOfLength(10).toLowerCase(Locale.ROOT)); | ||
} | ||
return targets; | ||
} | ||
|
||
private static View randomInstance() { | ||
final List<Target> targets = randomTargets(); | ||
final String viewName = randomAlphaOfLength(10).toLowerCase(Locale.ROOT); | ||
final String description = randomAlphaOfLength(100).toLowerCase(Locale.ROOT); | ||
return new View(viewName, description, Math.abs(randomLong()), Math.abs(randomLong()), targets); | ||
} | ||
|
||
@Override | ||
protected View doParseInstance(XContentParser parser) throws IOException { | ||
return View.fromXContent(parser); | ||
} | ||
|
||
@Override | ||
protected Writeable.Reader<View> instanceReader() { | ||
return View::new; | ||
} | ||
|
||
@Override | ||
protected View createTestInstance() { | ||
return randomInstance(); | ||
} | ||
|
||
public void testNullName() { | ||
final NullPointerException npe = assertThrows(NullPointerException.class, () -> new View(null, null, null, null, null)); | ||
|
||
assertThat(npe.getMessage(), equalTo("Name must be provided")); | ||
} | ||
|
||
public void testNullTargets() { | ||
final NullPointerException npe = assertThrows(NullPointerException.class, () -> new View("name", null, null, null, null)); | ||
|
||
assertThat(npe.getMessage(), equalTo("Targets are required on a view")); | ||
} | ||
|
||
public void testNullTargetIndexPattern() { | ||
final NullPointerException npe = assertThrows(NullPointerException.class, () -> new View.Target(null)); | ||
|
||
assertThat(npe.getMessage(), equalTo("IndexPattern is required")); | ||
} | ||
|
||
|
||
public void testDefaultValues() { | ||
final View view = new View("myName", null, null, null, List.of()); | ||
|
||
assertThat(view.name, equalTo("myName")); | ||
assertThat(view.description, equalTo(null)); | ||
assertThat(view.createdAt, equalTo(-1L)); | ||
assertThat(view.modifiedAt, equalTo(-1L)); | ||
assertThat(view.targets, empty()); | ||
} | ||
|
||
|
||
} |