Search in sources :

Example 1 with Collections2

use of org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.Collections2 in project beam by apache.

the class PipelineOptionsFactoryTest method testDescribe.

@Test
public void testDescribe() {
    List<PipelineOptionDescriptor> described = PipelineOptionsFactory.describe(Sets.newHashSet(PipelineOptions.class, TestDescribeOptions.class));
    Map<String, PipelineOptionDescriptor> mapped = uniqueIndex(described, input -> input.getName());
    assertEquals("no duplicates", described.size(), mapped.size());
    Collection<PipelineOptionDescriptor> filtered = Collections2.filter(described, input -> input.getGroup().equals(TestDescribeOptions.class.getName()));
    assertEquals(6, filtered.size());
    mapped = uniqueIndex(filtered, input -> input.getName());
    PipelineOptionDescriptor listDesc = mapped.get("list");
    assertThat(listDesc, notNullValue());
    assertThat(listDesc.getDescription(), isEmptyString());
    assertEquals(PipelineOptionType.Enum.ARRAY, listDesc.getType());
    assertThat(listDesc.getDefaultValue(), isEmptyString());
    PipelineOptionDescriptor stringDesc = mapped.get("string");
    assertThat(stringDesc, notNullValue());
    assertThat(stringDesc.getDescription(), isEmptyString());
    assertEquals(PipelineOptionType.Enum.STRING, stringDesc.getType());
    assertThat(stringDesc.getDefaultValue(), isEmptyString());
    PipelineOptionDescriptor integerDesc = mapped.get("integer");
    assertThat(integerDesc, notNullValue());
    assertEquals("integer property", integerDesc.getDescription());
    assertEquals(PipelineOptionType.Enum.INTEGER, integerDesc.getType());
    assertThat(integerDesc.getDefaultValue(), isEmptyString());
    PipelineOptionDescriptor floatDesc = mapped.get("float");
    assertThat(integerDesc, notNullValue());
    assertEquals("float number property", floatDesc.getDescription());
    assertEquals(PipelineOptionType.Enum.NUMBER, floatDesc.getType());
    assertThat(floatDesc.getDefaultValue(), isEmptyString());
    PipelineOptionDescriptor booleanSimpleDesc = mapped.get("boolean_simple");
    assertThat(booleanSimpleDesc, notNullValue());
    assertEquals("simple boolean property", booleanSimpleDesc.getDescription());
    assertEquals(PipelineOptionType.Enum.BOOLEAN, booleanSimpleDesc.getType());
    assertThat(booleanSimpleDesc.getDefaultValue(), equalTo("true"));
    PipelineOptionDescriptor booleanWrapperDesc = mapped.get("boolean_wrapper");
    assertThat(booleanWrapperDesc, notNullValue());
    assertThat(booleanWrapperDesc.getDescription(), isEmptyString());
    assertEquals(PipelineOptionType.Enum.BOOLEAN, booleanWrapperDesc.getType());
    assertThat(booleanWrapperDesc.getDefaultValue(), equalTo("false"));
}
Also used : Module(com.fasterxml.jackson.databind.Module) JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) ExpectedLogs(org.apache.beam.sdk.testing.ExpectedLogs) PipelineResult(org.apache.beam.sdk.PipelineResult) Matchers.not(org.hamcrest.Matchers.not) PipelineOptionDescriptor(org.apache.beam.model.jobmanagement.v1.JobApi.PipelineOptionDescriptor) ImmutableMap(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableMap) StdDeserializer(com.fasterxml.jackson.databind.deser.std.StdDeserializer) Sets(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.Sets) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) Matchers.nullValue(org.hamcrest.Matchers.nullValue) Map(java.util.Map) JsonSerializer(com.fasterxml.jackson.databind.JsonSerializer) ArrayListMultimap(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ArrayListMultimap) JsonDeserializer(com.fasterxml.jackson.databind.JsonDeserializer) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) Collection(java.util.Collection) Set(java.util.Set) InterceptingUrlClassLoader(org.apache.beam.sdk.testing.InterceptingUrlClassLoader) List(java.util.List) JsonTypeInfo(com.fasterxml.jackson.annotation.JsonTypeInfo) RestoreSystemProperties(org.apache.beam.sdk.testing.RestoreSystemProperties) Assert.assertFalse(org.junit.Assert.assertFalse) Matchers.equalTo(org.hamcrest.Matchers.equalTo) ReflectHelpers(org.apache.beam.sdk.util.common.ReflectHelpers) ListMultimap(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ListMultimap) ImmutableList(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableList) Matchers.anyOf(org.hamcrest.Matchers.anyOf) Matchers.containsString(org.hamcrest.Matchers.containsString) JsonDeserialize(com.fasterxml.jackson.databind.annotation.JsonDeserialize) ByteArrayOutputStream(java.io.ByteArrayOutputStream) TestRule(org.junit.rules.TestRule) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) Assert.assertThrows(org.junit.Assert.assertThrows) Assume.assumeFalse(org.junit.Assume.assumeFalse) RunWith(org.junit.runner.RunWith) Maps.uniqueIndex(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.Maps.uniqueIndex) Assert.assertSame(org.junit.Assert.assertSame) Collections2(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.Collections2) PipelineRunner(org.apache.beam.sdk.PipelineRunner) JsonSerialize(com.fasterxml.jackson.databind.annotation.JsonSerialize) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) PipelineOptionType(org.apache.beam.model.jobmanagement.v1.JobApi.PipelineOptionType) JsonIgnore(com.fasterxml.jackson.annotation.JsonIgnore) ROOT(java.util.Locale.ROOT) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) SerializerProvider(com.fasterxml.jackson.databind.SerializerProvider) Pipeline(org.apache.beam.sdk.Pipeline) ExpectedException(org.junit.rules.ExpectedException) StdSerializer(com.fasterxml.jackson.databind.ser.std.StdSerializer) PrintStream(java.io.PrintStream) JsonSubTypes(com.fasterxml.jackson.annotation.JsonSubTypes) DeserializationContext(com.fasterxml.jackson.databind.DeserializationContext) JsonParser(com.fasterxml.jackson.core.JsonParser) PipelineRunnerRegistrar(org.apache.beam.sdk.runners.PipelineRunnerRegistrar) SystemUtils(org.apache.commons.lang3.SystemUtils) Charsets(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Charsets) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Assert.assertTrue(org.junit.Assert.assertTrue) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) CrashingRunner(org.apache.beam.sdk.testing.CrashingRunner) Matchers.hasItem(org.hamcrest.Matchers.hasItem) Assert.assertNull(org.junit.Assert.assertNull) Rule(org.junit.Rule) AutoService(com.google.auto.service.AutoService) Assert.assertEquals(org.junit.Assert.assertEquals) PipelineOptionDescriptor(org.apache.beam.model.jobmanagement.v1.JobApi.PipelineOptionDescriptor) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) Test(org.junit.Test)

Aggregations

JsonIgnore (com.fasterxml.jackson.annotation.JsonIgnore)1 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)1 JsonSubTypes (com.fasterxml.jackson.annotation.JsonSubTypes)1 JsonTypeInfo (com.fasterxml.jackson.annotation.JsonTypeInfo)1 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)1 JsonParser (com.fasterxml.jackson.core.JsonParser)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 DeserializationContext (com.fasterxml.jackson.databind.DeserializationContext)1 JsonDeserializer (com.fasterxml.jackson.databind.JsonDeserializer)1 JsonSerializer (com.fasterxml.jackson.databind.JsonSerializer)1 Module (com.fasterxml.jackson.databind.Module)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 SerializerProvider (com.fasterxml.jackson.databind.SerializerProvider)1 JsonDeserialize (com.fasterxml.jackson.databind.annotation.JsonDeserialize)1 JsonSerialize (com.fasterxml.jackson.databind.annotation.JsonSerialize)1 StdDeserializer (com.fasterxml.jackson.databind.deser.std.StdDeserializer)1 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)1 StdSerializer (com.fasterxml.jackson.databind.ser.std.StdSerializer)1 AutoService (com.google.auto.service.AutoService)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1